-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite radio group and select templates with jsx (#4697)
- got rid of variables and expressions in template, both use defaultValue - returned back radix label in checkbox template
- Loading branch information
Showing
6 changed files
with
246 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/sdk-components-react-radix/src/radio-group.template.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
$, | ||
css, | ||
PlaceholderValue, | ||
type TemplateMeta, | ||
} from "@webstudio-is/template"; | ||
import { DotIcon } from "@webstudio-is/icons/svg"; | ||
import { radix } from "./shared/proxy"; | ||
import { | ||
borderRadius, | ||
borderWidth, | ||
boxShadow, | ||
colors, | ||
height, | ||
opacity, | ||
spacing, | ||
width, | ||
} from "./shared/theme"; | ||
|
||
const createRadioGroupItem = ({ | ||
value, | ||
label, | ||
}: { | ||
value: string; | ||
label: string; | ||
}) => ( | ||
<radix.Label | ||
// flex items-center space-x-2 | ||
ws:style={css` | ||
display: flex; | ||
align-items: center; | ||
gap: ${spacing[2]}; | ||
`} | ||
> | ||
<radix.RadioGroupItem | ||
value={value} | ||
// aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background | ||
// focus:outline-none | ||
// focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 | ||
// disabled:cursor-not-allowed disabled:opacity-50 | ||
ws:style={css` | ||
aspect-ratio: 1 / 1; | ||
height: ${height[4]}; | ||
width: ${width[4]}; | ||
border-radius: ${borderRadius.full}; | ||
border: ${borderWidth.DEFAULT} solid ${colors.primary}; | ||
color: ${colors.primary}; | ||
&:focus-visible { | ||
outline: none; | ||
box-shadow: ${boxShadow.ring}; | ||
} | ||
&:disabled { | ||
cursor: not-allowed; | ||
opacity: ${opacity[50]}; | ||
} | ||
`} | ||
> | ||
<radix.RadioGroupIndicator> | ||
<$.HtmlEmbed ws:label="Indicator Icon" code={DotIcon} /> | ||
</radix.RadioGroupIndicator> | ||
</radix.RadioGroupItem> | ||
<$.Text>{new PlaceholderValue(label)}</$.Text> | ||
</radix.Label> | ||
); | ||
|
||
export const meta: TemplateMeta = { | ||
category: "radix", | ||
order: 100, | ||
description: | ||
"A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.", | ||
template: ( | ||
<radix.RadioGroup | ||
// grid gap-2 | ||
ws:style={css` | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${spacing[2]}; | ||
`} | ||
> | ||
{createRadioGroupItem({ value: "default", label: "Default" })} | ||
{createRadioGroupItem({ value: "comfortable", label: "Comfortable" })} | ||
{createRadioGroupItem({ value: "compact", label: "Compact" })} | ||
</radix.RadioGroup> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.