Skip to content

Commit dce2b99

Browse files
authored
Merge pull request #68 from buildo/radio-without-svg
2 parents 732b078 + c881a63 commit dce2b99

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

Diff for: src/RadioGroupField/Radio.css.ts

+23-29
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,57 @@
1+
import { style } from "@vanilla-extract/css";
12
import { bentoSprinkles } from "../internal";
23
import { strictRecipe } from "../util/strictRecipe";
34
import { vars } from "../vars.css";
45
import { radioOption } from "./RadioGroupField.css";
56

6-
export const radio = bentoSprinkles({ width: 24, height: 24 });
7-
87
export const outerRadioCircleRecipe = strictRecipe({
8+
base: bentoSprinkles({
9+
display: "flex",
10+
justifyContent: "center",
11+
alignItems: "center",
12+
width: 24,
13+
height: 24,
14+
borderRadius: "circled",
15+
}),
916
variants: {
1017
selected: {
1118
false: [
12-
bentoSprinkles({ fill: "outlineInputEnabled" }),
19+
bentoSprinkles({ boxShadow: "outlineInputEnabled" }),
1320
{
1421
selectors: {
1522
[`${radioOption}:hover:not([disabled]) &`]: {
16-
fill: vars.outlineColor.outlineInputHover,
23+
boxShadow: vars.boxShadow.outlineInputHover,
1724
},
1825
[`${radioOption}[disabled] &`]: {
19-
fill: vars.outlineColor.outlineInputDisabled,
26+
boxShadow: vars.boxShadow.outlineInputDisabled,
2027
},
2128
},
2229
},
2330
],
2431
true: [
25-
bentoSprinkles({ fill: "primarySolidEnabledBackground" }),
32+
bentoSprinkles({ background: "primarySolidEnabledBackground" }),
2633
{
2734
selectors: {
2835
[`${radioOption}:hover:not([disabled]) &`]: {
29-
fill: vars.interactiveBackgroundColor.primarySolidHoverBackground,
36+
background: vars.interactiveBackgroundColor.primarySolidHoverBackground,
3037
},
3138
[`${radioOption}[disabled] &`]: {
32-
fill: vars.interactiveBackgroundColor.disabledSolidBackground,
39+
background: vars.interactiveBackgroundColor.disabledSolidBackground,
3340
},
3441
},
3542
},
3643
],
3744
},
3845
focused: {
39-
true: { fill: vars.interactiveBackgroundColor.primarySolidFocusBackground },
46+
true: { background: vars.interactiveBackgroundColor.primarySolidFocusBackground },
4047
},
4148
},
4249
});
4350

44-
export const innerRadioCircleRecipe = strictRecipe({
45-
base: bentoSprinkles({ fill: "backgroundPrimary" }),
46-
variants: {
47-
selected: {
48-
false: {
49-
r: "11",
50-
},
51-
true: { r: "5" },
52-
},
53-
focused: {
54-
true: {},
55-
},
56-
},
57-
compoundVariants: [
58-
{
59-
variants: { selected: false, focused: true },
60-
style: { r: "10" },
61-
},
62-
],
63-
});
51+
export const innerRadioCircle = [
52+
bentoSprinkles({
53+
background: "backgroundPrimary",
54+
borderRadius: "circled",
55+
}),
56+
style({ width: 10, height: 10 }),
57+
];

Diff for: src/RadioGroupField/Radio.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { innerRadioCircleRecipe, outerRadioCircleRecipe, radio } from "./Radio.css";
1+
import { innerRadioCircle, outerRadioCircleRecipe } from "./Radio.css";
2+
import { Box } from "../internal";
23

34
export function Radio({ selected, focused }: { selected: boolean; focused: boolean }) {
45
// NOTE(gabro): we can't draw svg strokes "inside" the container, so instead of modelling the radio
56
// as a circle with a stroke, we model it as two overlapping circles (one outer larger circle, which
67
// we use to draw the radio "border", and one smaller inner circle)
78
return (
8-
<svg aria-hidden="true" viewBox="0 0 24 24" className={radio}>
9-
<circle cx="12" cy="12" r="12" className={outerRadioCircleRecipe({ selected, focused })} />
10-
<circle cx="12" cy="12" className={innerRadioCircleRecipe({ selected, focused })} />
11-
</svg>
9+
<Box className={outerRadioCircleRecipe({ selected, focused })}>
10+
{selected && <Box className={innerRadioCircle} />}
11+
</Box>
1212
);
1313
}

0 commit comments

Comments
 (0)