Skip to content

Commit 684d341

Browse files
committed
refactor(emotion): add new way of using parent tokens
1 parent 75c8743 commit 684d341

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/__docs__/webpack.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const config = merge(baseConfig, {
5959
directory: outputPath,
6060
},
6161
host: '0.0.0.0',
62+
historyApiFallback: true,
6263
client: {
6364
overlay: false,
6465
},

packages/emotion/src/useStyle.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type UseStyleParamsWithTheme<
4848
generateComponentTheme: GenerateComponentTheme
4949
componentId: string
5050
displayName?: string
51+
useTokensFrom?: string
5152
}
5253

5354
// TODO this is only used by the old themes, remove when everything uses the new
@@ -60,6 +61,7 @@ type UseStyleParamsWithoutTheme<
6061
generateComponentTheme?: undefined
6162
componentId?: undefined
6263
displayName?: undefined
64+
useTokensFrom?: undefined
6365
}
6466

6567
// new useStyle syntax, use this with new themes
@@ -74,6 +76,8 @@ type UseStyleParamsNew<
7476
params?: SecondParameter<P>
7577
componentId: keyof NewComponentTypes
7678
displayName?: string
79+
//in case of a child component needed to use it's parent's tokens, provide parent's name
80+
useTokensFrom?: keyof NewComponentTypes
7781
}
7882

7983
const isNewThemeObject = (obj: BaseThemeOrOverride): obj is Theme => {
@@ -88,7 +92,7 @@ const useStyle = <
8892
| UseStyleParamsWithoutTheme<P>
8993
| UseStyleParamsNew<P>
9094
): ReturnType<P> => {
91-
const { generateStyle, params, componentId, displayName } = useStyleParams
95+
const { generateStyle, params, componentId, useTokensFrom } = useStyleParams
9296
const generateComponentTheme: GenerateComponentTheme = (
9397
useStyleParams as UseStyleParamsWithTheme<P>
9498
)?.generateComponentTheme
@@ -98,18 +102,21 @@ const useStyle = <
98102
typeof generateComponentTheme === 'function'
99103
? generateComponentTheme(theme as Theme)
100104
: {}
105+
const componentWithTokensId = useTokensFrom ?? componentId
101106

102107
if (
103108
isNewThemeObject(theme) &&
104-
theme.newTheme.components[componentId as keyof NewComponentTypes]
109+
theme.newTheme.components[componentWithTokensId as keyof NewComponentTypes]
105110
) {
106111
baseComponentTheme =
107-
theme.newTheme.components[componentId as keyof NewComponentTypes]
112+
theme.newTheme.components[
113+
componentWithTokensId as keyof NewComponentTypes
114+
]
108115
}
109116
const themeOverride = getComponentThemeOverride(
110117
theme,
111-
displayName ? displayName : componentId || '',
112-
componentId,
118+
componentWithTokensId as keyof NewComponentTypes,
119+
componentWithTokensId,
113120
params,
114121
baseComponentTheme
115122
)

0 commit comments

Comments
 (0)