Skip to content

Commit a38f904

Browse files
authored
Merge pull request #47 from buildo/3171075-add_button_icons_and
2 parents 24308fc + 39e99ab commit a38f904

File tree

9 files changed

+181
-15
lines changed

9 files changed

+181
-15
lines changed

src/Button/Button.css.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ export const buttonRecipe = strictRecipe({
1616
solid: bentoSprinkles({
1717
background: { disabled: "disabledSolidBackground" },
1818
color: { disabled: "disabledSolidForeground" },
19+
fill: { disabled: "disabledSolidForeground" },
1920
}),
2021
transparent: bentoSprinkles({
2122
background: { disabled: "disabledTransparentBackground" },
2223
color: { disabled: "disabledTransparentForeground" },
2324
}),
25+
outline: bentoSprinkles({
26+
background: { disabled: "disabledTransparentBackground" },
27+
color: { disabled: "disabledTransparentForeground" },
28+
fill: { disabled: "disabledTransparentForeground" },
29+
}),
2430
},
2531
hierarchy: {
2632
primary: {},
@@ -45,6 +51,11 @@ export const buttonRecipe = strictRecipe({
4551
hover: "primarySolidHoverForeground",
4652
focus: "primarySolidFocusForeground",
4753
},
54+
fill: {
55+
default: "primarySolidEnabledForeground",
56+
hover: "primarySolidHoverForeground",
57+
focus: "primarySolidFocusForeground",
58+
},
4859
background: {
4960
default: "primarySolidEnabledBackground",
5061
hover: "primarySolidHoverBackground",
@@ -63,6 +74,11 @@ export const buttonRecipe = strictRecipe({
6374
hover: "secondarySolidHoverForeground",
6475
focus: "secondarySolidFocusForeground",
6576
},
77+
fill: {
78+
default: "secondarySolidEnabledForeground",
79+
hover: "secondarySolidHoverForeground",
80+
focus: "secondarySolidFocusForeground",
81+
},
6682
background: {
6783
default: "secondarySolidEnabledBackground",
6884
hover: "secondarySolidHoverBackground",
@@ -81,6 +97,11 @@ export const buttonRecipe = strictRecipe({
8197
hover: "dangerSolidHoverForeground",
8298
focus: "dangerSolidFocusForeground",
8399
},
100+
fill: {
101+
default: "dangerSolidEnabledForeground",
102+
hover: "dangerSolidHoverForeground",
103+
focus: "dangerSolidFocusForeground",
104+
},
84105
background: {
85106
default: "dangerSolidEnabledBackground",
86107
hover: "dangerSolidHoverBackground",
@@ -99,6 +120,11 @@ export const buttonRecipe = strictRecipe({
99120
hover: "primaryTransparentHoverForeground",
100121
focus: "primaryTransparentFocusForeground",
101122
},
123+
fill: {
124+
default: "primaryTransparentEnabledForeground",
125+
hover: "primaryTransparentHoverForeground",
126+
focus: "primaryTransparentFocusForeground",
127+
},
102128
background: {
103129
default: "primaryTransparentEnabledBackground",
104130
hover: "primaryTransparentHoverBackground",
@@ -117,6 +143,11 @@ export const buttonRecipe = strictRecipe({
117143
hover: "secondaryTransparentHoverForeground",
118144
focus: "secondaryTransparentFocusForeground",
119145
},
146+
fill: {
147+
default: "secondaryTransparentEnabledForeground",
148+
hover: "secondaryTransparentHoverForeground",
149+
focus: "secondaryTransparentFocusForeground",
150+
},
120151
background: {
121152
default: "secondaryTransparentEnabledBackground",
122153
hover: "secondaryTransparentHoverBackground",
@@ -135,11 +166,88 @@ export const buttonRecipe = strictRecipe({
135166
hover: "dangerTransparentHoverForeground",
136167
focus: "dangerTransparentFocusForeground",
137168
},
169+
fill: {
170+
default: "dangerTransparentEnabledForeground",
171+
hover: "dangerTransparentHoverForeground",
172+
focus: "dangerTransparentFocusForeground",
173+
},
174+
background: {
175+
default: "dangerTransparentEnabledBackground",
176+
hover: "dangerTransparentHoverBackground",
177+
focus: "dangerTransparentFocusBackground",
178+
},
179+
}),
180+
},
181+
{
182+
variants: {
183+
kind: "outline",
184+
hierarchy: "primary",
185+
},
186+
style: bentoSprinkles({
187+
color: {
188+
default: "primaryTransparentEnabledForeground",
189+
hover: "primaryTransparentHoverForeground",
190+
focus: "primaryTransparentFocusForeground",
191+
},
192+
fill: {
193+
default: "primaryTransparentEnabledForeground",
194+
hover: "primaryTransparentHoverForeground",
195+
focus: "primaryTransparentFocusForeground",
196+
},
197+
background: {
198+
default: "primaryTransparentEnabledBackground",
199+
hover: "primaryTransparentHoverBackground",
200+
focus: "primaryTransparentFocusBackground",
201+
},
202+
boxShadow: "inherit",
203+
}),
204+
},
205+
{
206+
variants: {
207+
kind: "outline",
208+
hierarchy: "secondary",
209+
},
210+
style: bentoSprinkles({
211+
color: {
212+
default: "secondaryTransparentEnabledForeground",
213+
hover: "secondaryTransparentHoverForeground",
214+
focus: "secondaryTransparentFocusForeground",
215+
},
216+
fill: {
217+
default: "secondaryTransparentEnabledForeground",
218+
hover: "secondaryTransparentHoverForeground",
219+
focus: "secondaryTransparentFocusForeground",
220+
},
221+
background: {
222+
default: "secondaryTransparentEnabledBackground",
223+
hover: "secondaryTransparentHoverBackground",
224+
focus: "secondaryTransparentFocusBackground",
225+
},
226+
boxShadow: "inherit",
227+
}),
228+
},
229+
{
230+
variants: {
231+
kind: "outline",
232+
hierarchy: "danger",
233+
},
234+
style: bentoSprinkles({
235+
color: {
236+
default: "dangerTransparentEnabledForeground",
237+
hover: "dangerTransparentHoverForeground",
238+
focus: "dangerTransparentFocusForeground",
239+
},
240+
fill: {
241+
default: "dangerTransparentEnabledForeground",
242+
hover: "dangerTransparentHoverForeground",
243+
focus: "dangerTransparentFocusForeground",
244+
},
138245
background: {
139246
default: "dangerTransparentEnabledBackground",
140247
hover: "dangerTransparentHoverBackground",
141248
focus: "dangerTransparentFocusBackground",
142249
},
250+
boxShadow: "inherit",
143251
}),
144252
},
145253
],

src/Button/createButton.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import { ComponentProps, useRef } from "react";
55
import { AriaButtonProps } from "@react-types/button";
66
import { useButton } from "@react-aria/button";
77
import { Label } from "../Typography/Label/Label";
8-
import { BentoSprinkles } from "../internal";
8+
import { BentoSprinkles, Column, Columns } from "../internal";
9+
import { IconProps } from "src";
910

1011
type Size = "small" | "medium" | "large";
1112
export type ButtonProps = {
1213
label: LocalizedString;
1314
onPress: () => void;
14-
kind: "solid" | "transparent";
15+
kind: "solid" | "transparent" | "outline";
1516
hierarchy: "primary" | "secondary" | "danger";
1617
isDisabled?: boolean;
1718
size?: Size;
19+
icon?: (props: IconProps) => JSX.Element;
1820
} & AriaButtonProps<"button">;
1921

2022
type SizeConfig<T> = {
@@ -26,6 +28,9 @@ export type ButtonConfig = {
2628
paddingY: SizeConfig<BentoSprinkles["paddingY"]>;
2729
labelSize: ComponentProps<typeof Label>["size"];
2830
radius: BentoSprinkles["borderRadius"];
31+
internalSpacing: BentoSprinkles["gap"];
32+
iconSize: SizeConfig<IconProps["size"]>;
33+
uppercaseLabel: boolean;
2934
};
3035

3136
export const defaultButtonConfig: ButtonConfig = {
@@ -41,6 +46,13 @@ export const defaultButtonConfig: ButtonConfig = {
4146
},
4247
labelSize: "large",
4348
radius: 8,
49+
internalSpacing: 8,
50+
iconSize: {
51+
small: 12,
52+
medium: 12,
53+
large: 16,
54+
},
55+
uppercaseLabel: true,
4456
};
4557

4658
export function createButton(config: ButtonConfig = defaultButtonConfig) {
@@ -67,7 +79,19 @@ export function createButton(config: ButtonConfig = defaultButtonConfig) {
6779
paddingY={config.paddingY[size]}
6880
borderRadius={config.radius}
6981
>
70-
<Label size={config.labelSize}>{props.label}</Label>
82+
<Columns space={config.internalSpacing} alignY="center">
83+
{props.icon && (
84+
<Column width="content">
85+
{props.icon({
86+
size: config.iconSize[size],
87+
color: "inherit",
88+
})}
89+
</Column>
90+
)}
91+
<Label size={config.labelSize} uppercase={config.uppercaseLabel}>
92+
{props.label}
93+
</Label>
94+
</Columns>
7195
</Box>
7296
);
7397
};

src/CheckboxField/createCheckboxField.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export function createCheckboxField(
3535
const { fieldProps, errorMessageProps } = useField(checkboxProps);
3636
const inputProps = { ..._inputProps, "aria-describedby": fieldProps["aria-describedby"] };
3737

38-
console.log(errorMessageProps);
39-
4038
return (
4139
<Field
4240
{...props}

src/Icons/Icon.css.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import { style } from "@vanilla-extract/css";
12
import { recipe } from "@vanilla-extract/recipes";
23
import { bentoSprinkles } from "../internal";
34

45
export const iconRecipe = recipe({
56
variants: {
67
width: {
78
8: bentoSprinkles({ width: 8 }),
9+
12: style({ width: "12px" }),
810
16: bentoSprinkles({ width: 16 }),
911
24: bentoSprinkles({ width: 24 }),
1012
},
1113
height: {
1214
8: bentoSprinkles({ height: 8 }),
15+
12: style({ height: "12px" }),
1316
16: bentoSprinkles({ height: 16 }),
1417
24: bentoSprinkles({ height: 24 }),
1518
},
@@ -22,6 +25,7 @@ export const iconRecipe = recipe({
2225
warning: bentoSprinkles({ fill: "foregroundWarning" }),
2326
negative: bentoSprinkles({ fill: "foregroundNegative" }),
2427
disabled: bentoSprinkles({ fill: "foregroundDisabled" }),
28+
inherit: bentoSprinkles({ fill: "inherit" }),
2529
},
2630
},
2731
});

src/Icons/IconProps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { vars } from "../vars.css";
22

33
export type IconProps = {
4-
size: Extract<keyof typeof vars.space, 8 | 12 | 16 | 24>;
4+
size: Extract<keyof typeof vars.space, 8 | 16 | 24> | 12;
55
color?:
66
| "default"
77
| "primary"
@@ -10,6 +10,7 @@ export type IconProps = {
1010
| "positive"
1111
| "warning"
1212
| "negative"
13-
| "disabled";
13+
| "disabled"
14+
| "inherit";
1415
className?: string;
1516
};

src/util/atoms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ export const statusProperties = {
9999
default: "default",
100100
notAllowed: "not-allowed",
101101
},
102-
boxShadow: { ...vars.boxShadow, none: "none" },
102+
boxShadow: { ...vars.boxShadow, none: "none", inherit: "inset 0px 0px 0px 1px" },
103103
outline: { ...vars.outlineColor, none: "none" },
104104
stroke: color,
105105
textDecoration: ["none", "underline"],
106-
fill: { ...color, ...background },
106+
fill: { ...color, ...background, inherit: "inherit" },
107107
} as const;

stories/Components/Button.stories.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createComponentStories, formatMessage, textArgType } from "../util";
2-
import { Button } from "../";
2+
import { Button, IconCheck } from "../";
33

44
const { defaultExport, createStory } = createComponentStories({
55
component: Button,
@@ -43,6 +43,21 @@ export const DangerTransparent = createStory({
4343
hierarchy: "danger",
4444
});
4545

46+
export const PrimaryOutline = createStory({
47+
kind: "outline",
48+
hierarchy: "primary",
49+
});
50+
51+
export const SecondaryOutline = createStory({
52+
kind: "outline",
53+
hierarchy: "secondary",
54+
});
55+
56+
export const DangerOutline = createStory({
57+
kind: "outline",
58+
hierarchy: "danger",
59+
});
60+
4661
export const SolidDisabled = createStory({
4762
kind: "solid",
4863
hierarchy: "primary",
@@ -55,6 +70,12 @@ export const TransparentDisabled = createStory({
5570
isDisabled: true,
5671
});
5772

73+
export const OutlineDisabled = createStory({
74+
kind: "outline",
75+
hierarchy: "primary",
76+
isDisabled: true,
77+
});
78+
5879
export const PrimarySmall = createStory({
5980
kind: "solid",
6081
hierarchy: "primary",
@@ -66,3 +87,9 @@ export const PrimaryLarge = createStory({
6687
hierarchy: "primary",
6788
size: "large",
6889
});
90+
91+
export const WithIcon = createStory({
92+
kind: "solid",
93+
hierarchy: "primary",
94+
icon: IconCheck,
95+
});

stories/Foundations/Icons.stories.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { Box, Inline, Stack } from "../../src/internal";
33
import { Body } from "../../src";
44
import * as icons from "../../src/Icons";
55
import { IconProps } from "../../src/Icons/IconProps";
6-
import { vars } from "../../src/vars.css";
76
import { formatMessage } from "../util";
87

98
const meta = {
109
args: {
11-
size: "24",
10+
size: 24,
1211
},
1312
argTypes: {
1413
size: {
15-
options: ["8", "16", "24"],
14+
options: [8, 12, 16, 24],
1615
control: { type: "select" },
1716
},
1817
color: {
@@ -31,7 +30,7 @@ export const Icons = (args: IconProps) => {
3130
{Object.entries(icons).map(([name, Icon]) => (
3231
<Box padding={16} alignItems="center" justifyContent="center" style={{ width: 100 }}>
3332
<Stack space={8} align="center">
34-
<Box display="flex" alignItems="center" style={{ height: vars.space[args.size] }}>
33+
<Box display="flex" alignItems="center" style={{ height: 24 }}>
3534
<Icon size={args.size} color={args.color} />
3635
</Box>
3736
<Body size="small">{formatMessage(name.replace(/^Icon/g, ""))}</Body>

stories/atoms.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const color = {
1111
...vars.color,
1212
};
1313

14+
const fill = {
15+
...bentoAtoms.statusProperties.fill,
16+
...vars.color,
17+
};
18+
1419
export const unconditionalProperties = {
1520
...bentoAtoms.unconditionalProperties,
1621
fontFamily: {
@@ -31,6 +36,6 @@ export const responsiveProperties = {
3136
export const statusProperties = {
3237
...bentoAtoms.statusProperties,
3338
color,
34-
fill: { ...color, ...bentoAtoms.statusProperties.background },
39+
fill,
3540
stroke: color,
3641
};

0 commit comments

Comments
 (0)