Skip to content

Commit 0377bcc

Browse files
authored
fix(theme): making all component tokens optional (#3129)
1 parent 24d40f0 commit 0377bcc

File tree

15 files changed

+185
-48
lines changed

15 files changed

+185
-48
lines changed

.changeset/pretty-crews-repeat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aws-amplify/ui": patch
3+
"@aws-amplify/ui-react": patch
4+
---
5+
6+
fix(theme): making all component tokens optional
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Theme } from '../index';
2+
3+
describe('Amplify UI Theme', () => {
4+
describe('components', () => {
5+
it('should allow empty components', () => {
6+
const theme: Theme = {
7+
name: 'test',
8+
tokens: {
9+
components: {
10+
alert: {},
11+
authenticator: {},
12+
autocomplete: {},
13+
badge: {},
14+
button: {},
15+
card: {},
16+
checkbox: {},
17+
checkboxfield: {},
18+
collection: {},
19+
copy: {},
20+
divider: {},
21+
expander: {},
22+
field: {},
23+
fieldcontrol: {},
24+
fieldgroup: {},
25+
fieldmessages: {},
26+
fileuploader: {},
27+
flex: {},
28+
heading: {},
29+
highlightmatch: {},
30+
icon: {},
31+
image: {},
32+
inappmessaging: {},
33+
link: {},
34+
loader: {},
35+
menu: {},
36+
pagination: {},
37+
passwordfield: {},
38+
phonenumberfield: {},
39+
placeholder: {},
40+
radio: {},
41+
radiogroup: {},
42+
rating: {},
43+
searchfield: {},
44+
select: {},
45+
selectfield: {},
46+
sliderfield: {},
47+
stepperfield: {},
48+
switchfield: {},
49+
table: {},
50+
tabs: {},
51+
text: {},
52+
textareafield: {},
53+
textfield: {},
54+
togglebutton: {},
55+
togglebuttongroup: {},
56+
},
57+
},
58+
};
59+
// This test doesn't test anything, but
60+
// if there is a TS error it will fail
61+
expect(theme).toMatchInlineSnapshot(`
62+
Object {
63+
"name": "test",
64+
"tokens": Object {
65+
"components": Object {
66+
"alert": Object {},
67+
"authenticator": Object {},
68+
"autocomplete": Object {},
69+
"badge": Object {},
70+
"button": Object {},
71+
"card": Object {},
72+
"checkbox": Object {},
73+
"checkboxfield": Object {},
74+
"collection": Object {},
75+
"copy": Object {},
76+
"divider": Object {},
77+
"expander": Object {},
78+
"field": Object {},
79+
"fieldcontrol": Object {},
80+
"fieldgroup": Object {},
81+
"fieldmessages": Object {},
82+
"fileuploader": Object {},
83+
"flex": Object {},
84+
"heading": Object {},
85+
"highlightmatch": Object {},
86+
"icon": Object {},
87+
"image": Object {},
88+
"inappmessaging": Object {},
89+
"link": Object {},
90+
"loader": Object {},
91+
"menu": Object {},
92+
"pagination": Object {},
93+
"passwordfield": Object {},
94+
"phonenumberfield": Object {},
95+
"placeholder": Object {},
96+
"radio": Object {},
97+
"radiogroup": Object {},
98+
"rating": Object {},
99+
"searchfield": Object {},
100+
"select": Object {},
101+
"selectfield": Object {},
102+
"sliderfield": Object {},
103+
"stepperfield": Object {},
104+
"switchfield": Object {},
105+
"table": Object {},
106+
"tabs": Object {},
107+
"text": Object {},
108+
"textareafield": Object {},
109+
"textfield": Object {},
110+
"togglebutton": Object {},
111+
"togglebuttongroup": Object {},
112+
},
113+
},
114+
}
115+
`);
116+
});
117+
});
118+
});

packages/ui/src/theme/tokens/components/button.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export type ButtonTokens<Output extends OutputVariantKey> =
6363
| 'borderWidth'
6464
| 'borderStyle'
6565
| 'borderRadius'
66-
| 'color'
66+
| 'color',
67+
Output
6768
> & {
6869
_hover?: StateTokens<Output>;
6970
_focus?: StateWithShadowTokens<Output>;
@@ -75,7 +76,7 @@ export type ButtonTokens<Output extends OutputVariantKey> =
7576
link?: LinkVariationTokens<Output>;
7677
small?: ButtonSizeTokens<Output>;
7778
large?: ButtonSizeTokens<Output>;
78-
loaderWrapper: DesignTokenProperties<'alignItems' | 'gap', Output>;
79+
loaderWrapper?: DesignTokenProperties<'alignItems' | 'gap', Output>;
7980
};
8081

8182
export const button: Required<ButtonTokens<'default'>> = {

packages/ui/src/theme/tokens/components/collection.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ type PaginationTokens<Output> = {
1414
};
1515

1616
type SearchTokens<Output> = {
17-
input: DesignTokenProperties<'color', Output>;
18-
button: DesignTokenProperties<'color', Output> & {
19-
_active: StateTokens<Output>;
20-
_disabled: StateTokens<Output>;
21-
_focus: StateTokens<Output>;
22-
_hover: StateTokens<Output>;
17+
input?: DesignTokenProperties<'color', Output>;
18+
button?: DesignTokenProperties<'color', Output> & {
19+
_active?: StateTokens<Output>;
20+
_disabled?: StateTokens<Output>;
21+
_focus?: StateTokens<Output>;
22+
_hover?: StateTokens<Output>;
2323
};
2424
};
2525

2626
export interface CollectionTokens<Output extends OutputVariantKey> {
27-
pagination: PaginationTokens<Output>;
28-
search: SearchTokens<Output>;
27+
pagination?: PaginationTokens<Output>;
28+
search?: SearchTokens<Output>;
2929
}
3030

3131
//we are reusing the types from the nested components but new tokens need to be created that reference the previous tokens so that they can inherit the needed values but can be overwritten and only effect the collection component.

packages/ui/src/theme/tokens/components/fileUploader.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ type BaseDropZoneTokens<OutputType> = DesignTokenProperties<
1111
>;
1212

1313
export interface FileUploaderTokens<OutputType extends OutputVariantKey> {
14-
dropzone: DesignTokenProperties<
14+
dropzone?: DesignTokenProperties<
1515
'gap' | 'paddingBlock' | 'paddingInline' | 'textAlign'
1616
> &
1717
BaseDropZoneTokens<OutputType> & {
18-
_active: BaseDropZoneTokens<OutputType>;
18+
_active?: BaseDropZoneTokens<OutputType>;
1919

20-
icon: DesignTokenProperties<'fontSize' | 'color', OutputType>;
20+
icon?: DesignTokenProperties<'fontSize' | 'color', OutputType>;
2121

22-
text: TypographyTokens<OutputType>;
22+
text?: TypographyTokens<OutputType>;
2323
};
2424

25-
file: DesignTokenProperties<
25+
file?: DesignTokenProperties<
2626
| 'alignItems'
2727
| 'backgroundColor'
2828
| 'borderColor'
@@ -34,18 +34,18 @@ export interface FileUploaderTokens<OutputType extends OutputVariantKey> {
3434
| 'paddingInline',
3535
OutputType
3636
> & {
37-
name: TypographyTokens<OutputType>;
38-
size: TypographyTokens<OutputType>;
39-
image: DesignTokenProperties<
37+
name?: TypographyTokens<OutputType>;
38+
size?: TypographyTokens<OutputType>;
39+
image?: DesignTokenProperties<
4040
'backgroundColor' | 'borderRadius' | 'color' | 'height' | 'width',
4141
OutputType
4242
>;
4343
};
44-
loader: DesignTokenProperties<
44+
loader?: DesignTokenProperties<
4545
'strokeWidth' | 'strokeFilled' | 'strokeEmpty' | 'strokeLinecap',
4646
OutputType
4747
>;
48-
previewer: DesignTokenProperties<
48+
previewer?: DesignTokenProperties<
4949
| 'backgroundColor'
5050
| 'borderColor'
5151
| 'borderRadius'
@@ -57,14 +57,14 @@ export interface FileUploaderTokens<OutputType extends OutputVariantKey> {
5757
| 'paddingInline',
5858
OutputType
5959
> & {
60-
text: TypographyTokens<OutputType>;
60+
text?: TypographyTokens<OutputType>;
6161

62-
body: DesignTokenProperties<
62+
body?: DesignTokenProperties<
6363
'gap' | 'paddingInline' | 'paddingBlock',
6464
OutputType
6565
>;
6666

67-
footer: DesignTokenProperties<
67+
footer?: DesignTokenProperties<
6868
| 'borderColor'
6969
| 'borderStyle'
7070
| 'borderWidth'

packages/ui/src/theme/tokens/components/heading.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type HeadingLevelTokens<Output> = DesignTokenProperties<
88
type Level = 1 | 2 | 3 | 4 | 5 | 6;
99

1010
export type HeadingTokens<Output extends OutputVariantKey> =
11-
DesignTokenProperties<'color' | 'lineHeight'> &
12-
Record<Level, HeadingLevelTokens<Output>>;
11+
DesignTokenProperties<'color' | 'lineHeight', Output> &
12+
Partial<Record<Level, HeadingLevelTokens<Output>>>;
1313

1414
export const heading: Required<HeadingTokens<'default'>> = {
1515
color: { value: '{colors.font.primary.value}' },

packages/ui/src/theme/tokens/components/link.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { DesignTokenProperties, OutputVariantKey } from '../types/designToken';
22

33
type LinkState = 'active' | 'focus' | 'hover' | 'visited';
44

5-
export type LinkTokens<Output extends OutputVariantKey> =
6-
DesignTokenProperties<'color'> &
7-
Record<LinkState, DesignTokenProperties<'color', Output>>;
5+
export type LinkTokens<Output extends OutputVariantKey> = DesignTokenProperties<
6+
'color',
7+
Output
8+
> &
9+
Partial<Record<LinkState, DesignTokenProperties<'color', Output>>>;
810

911
export const link: Required<LinkTokens<'default'>> = {
1012
active: { color: { value: '{colors.font.active.value}' } },

packages/ui/src/theme/tokens/components/rating.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { DesignTokenProperties, OutputVariantKey } from '../types/designToken';
22

33
export type RatingTokens<Output extends OutputVariantKey> = {
4-
large: DesignTokenProperties<'size', Output>;
5-
default: DesignTokenProperties<'size', Output>;
6-
small: DesignTokenProperties<'size', Output>;
4+
large?: DesignTokenProperties<'size', Output>;
5+
default?: DesignTokenProperties<'size', Output>;
6+
small?: DesignTokenProperties<'size', Output>;
77
filled?: DesignTokenProperties<'color', Output>;
88
empty?: DesignTokenProperties<'color', Output>;
99
};

packages/ui/src/theme/tokens/components/select.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import { DesignTokenProperties, OutputVariantKey } from '../types/designToken';
33
type SelectSizeTokens<Output> = DesignTokenProperties<'minWidth', Output>;
44

55
export type SelectTokens<Output extends OutputVariantKey> =
6-
DesignTokenProperties<'paddingInlineEnd' | 'whiteSpace' | 'minWidth'> & {
7-
wrapper?: DesignTokenProperties<'cursor' | 'display' | 'flex' | 'position'>;
6+
DesignTokenProperties<
7+
'paddingInlineEnd' | 'whiteSpace' | 'minWidth',
8+
Output
9+
> & {
10+
wrapper?: DesignTokenProperties<
11+
'cursor' | 'display' | 'flex' | 'position',
12+
Output
13+
>;
814
iconWrapper?: DesignTokenProperties<
915
| 'alignItems'
1016
| 'position'
1117
| 'top'
1218
| 'right'
1319
| 'transform'
14-
| 'pointerEvents'
20+
| 'pointerEvents',
21+
Output
1522
>;
16-
option?: DesignTokenProperties<'backgroundColor' | 'color'> & {
17-
_disabled?: DesignTokenProperties<'color'>;
23+
option?: DesignTokenProperties<'backgroundColor' | 'color', Output> & {
24+
_disabled?: DesignTokenProperties<'color', Output>;
1825
};
1926
small?: SelectSizeTokens<Output>;
2027
large?: SelectSizeTokens<Output>;

packages/ui/src/theme/tokens/components/stepperField.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type ButtonStateColorTokens<Output> = DesignTokenProperties<
66
>;
77

88
export type StepperFieldTokens<Output extends OutputVariantKey> =
9-
DesignTokenProperties<'borderColor' | 'flexDirection'> & {
9+
DesignTokenProperties<'borderColor' | 'flexDirection', Output> & {
1010
input?: DesignTokenProperties<'textAlign' | 'color' | 'fontSize', Output>;
1111
button?: DesignTokenProperties<'backgroundColor' | 'color', Output> & {
1212
_active?: ButtonStateColorTokens<Output>;

0 commit comments

Comments
 (0)