Skip to content

Commit 736cfe7

Browse files
authored
feat(style): adding theme key support on more style props (#2077)
* feat(style): adding theme key support on more style props * chore: fix style types * chore: fix duplicate type * Create little-hotels-hunt.md * Update little-hotels-hunt.md
1 parent d6128f0 commit 736cfe7

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

.changeset/little-hotels-hunt.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@aws-amplify/ui-react": minor
3+
"@aws-amplify/ui": patch
4+
---
5+
6+
feat(style): adding theme key support on more style props(`font-family`, `line-height`, `opacity`, `box-shadow` and `transform`)

packages/react/src/primitives/types/style.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { Property } from 'csstype';
22
import { WebDesignToken } from '@aws-amplify/ui';
33

44
import type {
5+
BoxShadowKeys,
56
ColorKeys,
7+
FontFamilyKeys,
68
FontSizeKeys,
79
FontWeightKeys,
10+
LineHeightKeys,
11+
OpacityKeys,
812
RadiiKeys,
913
SpaceKeys,
14+
TransformKeys,
1015
} from './theme';
1116
import { FlexItemStyleProps, FlexContainerStyleProps } from './flex';
1217
import { GridItemStyleProps, GridContainerStyleProps } from './grid';
@@ -55,10 +60,10 @@ export interface BaseStyleProps extends FlexItemStyleProps, GridItemStyleProps {
5560
border?: ResponsiveStyle<StyleToken<Property.Border>>;
5661
borderRadius?: ResponsiveStyle<RadiiKeys<StyleToken<Property.BorderRadius>>>;
5762
bottom?: ResponsiveStyle<SpaceKeys<StyleToken<Property.Bottom>>>;
58-
boxShadow?: ResponsiveStyle<StyleToken<Property.BoxShadow>>;
63+
boxShadow?: ResponsiveStyle<BoxShadowKeys<StyleToken<Property.BoxShadow>>>;
5964
color?: ResponsiveStyle<ColorKeys<StyleToken<Property.Color>>>;
6065
display?: ResponsiveStyle<StyleToken<Property.Display>>;
61-
fontFamily?: ResponsiveStyle<StyleToken<Property.FontFamily>>;
66+
fontFamily?: ResponsiveStyle<FontFamilyKeys<StyleToken<Property.FontFamily>>>;
6267
fontSize?: ResponsiveStyle<FontSizeKeys<StyleToken<Property.FontSize>>>;
6368
fontStyle?: ResponsiveStyle<StyleToken<Property.FontStyle>>;
6469
fontWeight?: ResponsiveStyle<FontWeightKeys<StyleToken<Property.FontWeight>>>;
@@ -67,7 +72,7 @@ export interface BaseStyleProps extends FlexItemStyleProps, GridItemStyleProps {
6772
letterSpacing?: ResponsiveStyle<
6873
SpaceKeys<StyleToken<Property.LetterSpacing>>
6974
>;
70-
lineHeight?: ResponsiveStyle<StyleToken<Property.LineHeight>>;
75+
lineHeight?: ResponsiveStyle<LineHeightKeys<StyleToken<Property.LineHeight>>>;
7176
margin?: ResponsiveStyle<StyleToken<Property.Margin>>;
7277
marginBlockEnd?: ResponsiveStyle<
7378
SpaceKeys<StyleToken<Property.MarginBlockEnd>>
@@ -89,7 +94,7 @@ export interface BaseStyleProps extends FlexItemStyleProps, GridItemStyleProps {
8994
maxWidth?: ResponsiveStyle<SpaceKeys<StyleToken<Property.MaxWidth>>>;
9095
minHeight?: ResponsiveStyle<SpaceKeys<StyleToken<Property.MinHeight>>>;
9196
minWidth?: ResponsiveStyle<SpaceKeys<StyleToken<Property.MinWidth>>>;
92-
opacity?: ResponsiveStyle<StyleToken<Property.Opacity>>;
97+
opacity?: ResponsiveStyle<OpacityKeys<StyleToken<Property.Opacity>>>;
9398
overflow?: ResponsiveStyle<StyleToken<Property.Overflow>>;
9499
padding?: ResponsiveStyle<StyleToken<Property.Padding>>;
95100
paddingBlockEnd?: ResponsiveStyle<
@@ -116,7 +121,7 @@ export interface BaseStyleProps extends FlexItemStyleProps, GridItemStyleProps {
116121
textDecoration?: ResponsiveStyle<StyleToken<Property.TextDecoration>>;
117122
textTransform?: ResponsiveStyle<StyleToken<Property.TextTransform>>;
118123
top?: ResponsiveStyle<SpaceKeys<StyleToken<Property.Top>>>;
119-
transform?: ResponsiveStyle<StyleToken<Property.Transform>>;
124+
transform?: ResponsiveStyle<TransformKeys<StyleToken<Property.Transform>>>;
120125
transformOrigin?: ResponsiveStyle<StyleToken<Property.TransformOrigin>>;
121126
width?: ResponsiveStyle<SpaceKeys<StyleToken<Property.Width>>>;
122127
whiteSpace?: ResponsiveStyle<StyleToken<Property.WhiteSpace>>;

packages/react/src/primitives/types/theme.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type {
22
FontSizes,
33
FontWeights,
4-
SpaceSizes,
4+
LineHeights,
55
Radii,
6+
Shadows,
7+
SpaceSizes,
68
} from '@aws-amplify/ui';
79

810
/**
@@ -184,10 +186,35 @@ export type ColorKeys<PropertyType> =
184186
| BorderColorKeys
185187
| ShadowColorKeys;
186188

189+
export type BoxShadowKeys<PropertyType> = PropertyType | keyof Shadows;
190+
187191
export type FontSizeKeys<PropertyType> = PropertyType | keyof FontSizes;
188192

189193
export type FontWeightKeys<PropertyType> = PropertyType | keyof FontWeights;
190194

195+
export type FontFamilyKeys<PropertyType> =
196+
| PropertyType
197+
| 'default.variable'
198+
| 'default.static';
199+
200+
export type LineHeightKeys<PropertyType> = PropertyType | keyof LineHeights;
201+
202+
// Note: we cannot use keyof Opacities
203+
// because the return type will be number union and no intellisense
204+
export type OpacityKeys<PropertyType> =
205+
| PropertyType
206+
| '0'
207+
| '10'
208+
| '20'
209+
| '30'
210+
| '40'
211+
| '50'
212+
| '60'
213+
| '70'
214+
| '80'
215+
| '90'
216+
| '100';
217+
191218
export type RadiiKeys<PropertyType> = PropertyType | keyof Radii;
192219

193220
// Theme keys for space
@@ -206,9 +233,23 @@ export type SpaceKeys<PropertyType> =
206233
| 'relative.xxxl'
207234
| 'relative.full';
208235

236+
export type TransformKeys<PropertyType> =
237+
| PropertyType
238+
| 'slideX.small'
239+
| 'slideX.medium'
240+
| 'slideX.large';
241+
209242
export const stylePropsToThemeKeys = {
210243
backgroundColor: 'colors',
211244
color: 'colors',
245+
borderRadius: 'radii',
246+
fontSize: 'fontSizes',
247+
fontWeight: 'fontWeights',
248+
fontFamily: 'fonts',
249+
lineHeight: 'lineHeights',
250+
opacity: 'opacities',
251+
boxShadow: 'shadows',
252+
transform: 'transforms',
212253
left: 'space',
213254
right: 'space',
214255
top: 'space',
@@ -239,7 +280,4 @@ export const stylePropsToThemeKeys = {
239280
gap: 'space',
240281
columnGap: 'space',
241282
rowGap: 'space',
242-
borderRadius: 'radii',
243-
fontSize: 'fontSizes',
244-
fontWeight: 'fontWeights',
245283
};

packages/ui/src/theme/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { Breakpoints } from './breakpoints';
55
export * from './tokens/types/designToken';
66
export type { FontSizes } from './tokens/fontSizes';
77
export type { FontWeights } from './tokens/fontWeights';
8-
export type { SpaceSizes } from './tokens/space';
8+
export type { LineHeights } from './tokens/lineHeights';
99
export type { Radii } from './tokens/radii';
10+
export type { Shadows } from './tokens/shadows';
11+
export type { SpaceSizes } from './tokens/space';
1012

1113
/**
1214
* An override is a set of tokens that override others

0 commit comments

Comments
 (0)