@tamagui/core 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ultra.cache.json +1 -0
- package/_/constants/constants.js +14 -0
- package/_/constants/constants.js.map +7 -0
- package/_/constants/platform.js +20 -0
- package/_/constants/platform.js.map +7 -0
- package/_/constants/pseudos.js +18 -0
- package/_/constants/pseudos.js.map +7 -0
- package/_/constants/rnw.js +22 -0
- package/_/constants/rnw.js.map +7 -0
- package/_/createComponent.js +427 -0
- package/_/createComponent.js.map +7 -0
- package/_/createShorthands.js +10 -0
- package/_/createShorthands.js.map +7 -0
- package/_/createTamagui.js +122 -0
- package/_/createTamagui.js.map +7 -0
- package/_/createTheme.js +20 -0
- package/_/createTheme.js.map +7 -0
- package/_/createTokens.js +29 -0
- package/_/createTokens.js.map +7 -0
- package/_/createVariable.js +22 -0
- package/_/createVariable.js.map +7 -0
- package/_/helpers/addStylesUsingClassname.js +32 -0
- package/_/helpers/addStylesUsingClassname.js.map +7 -0
- package/_/helpers/createMediaStyle.js +34 -0
- package/_/helpers/createMediaStyle.js.map +7 -0
- package/_/helpers/createTamaguiProvider.js +42 -0
- package/_/helpers/createTamaguiProvider.js.map +7 -0
- package/_/helpers/extendStaticConfig.js +176 -0
- package/_/helpers/extendStaticConfig.js.map +7 -0
- package/_/helpers/fixNativeShadow.js +8 -0
- package/_/helpers/fixNativeShadow.js.map +7 -0
- package/_/helpers/fixNativeShadow.native.js +30 -0
- package/_/helpers/fixNativeShadow.native.js.map +7 -0
- package/_/helpers/getSplitStyles.js +160 -0
- package/_/helpers/getSplitStyles.js.map +7 -0
- package/_/helpers/getStylesAtomic.js +84 -0
- package/_/helpers/getStylesAtomic.js.map +7 -0
- package/_/helpers/getStylesAtomic.native.js +10 -0
- package/_/helpers/getStylesAtomic.native.js.map +7 -0
- package/_/helpers/insertStyleRule.js +24 -0
- package/_/helpers/insertStyleRule.js.map +7 -0
- package/_/helpers/matchMedia.js +15 -0
- package/_/helpers/matchMedia.js.map +7 -0
- package/_/helpers/matchMedia.native.js +8 -0
- package/_/helpers/matchMedia.native.js.map +7 -0
- package/_/helpers/themeable.js +26 -0
- package/_/helpers/themeable.js.map +7 -0
- package/_/hooks/useConstant.js +15 -0
- package/_/hooks/useConstant.js.map +7 -0
- package/_/hooks/useFeatures.js +75 -0
- package/_/hooks/useFeatures.js.map +7 -0
- package/_/hooks/useForceUpdate.js +28 -0
- package/_/hooks/useForceUpdate.js.map +7 -0
- package/_/hooks/useMedia.js +173 -0
- package/_/hooks/useMedia.js.map +7 -0
- package/_/hooks/usePressable.js +14 -0
- package/_/hooks/usePressable.js.map +7 -0
- package/_/hooks/useTheme.js +94 -0
- package/_/hooks/useTheme.js.map +7 -0
- package/_/index.js +30 -0
- package/_/index.js.map +7 -0
- package/_/static/postProcessStyles.js +18 -0
- package/_/static/postProcessStyles.js.map +7 -0
- package/_/static.js +12 -0
- package/_/static.js.map +7 -0
- package/_/styled.js +21 -0
- package/_/styled.js.map +7 -0
- package/_/types.js +1 -0
- package/_/types.js.map +7 -0
- package/_/views/Animated.js +79 -0
- package/_/views/Animated.js.map +7 -0
- package/_/views/Stack.js +12 -0
- package/_/views/Stack.js.map +7 -0
- package/_/views/Text.js +60 -0
- package/_/views/Text.js.map +7 -0
- package/_/views/TextAncestorContext.js +19 -0
- package/_/views/TextAncestorContext.js.map +7 -0
- package/_/views/Theme.js +57 -0
- package/_/views/Theme.js.map +7 -0
- package/_/views/ThemeContext.js +6 -0
- package/_/views/ThemeContext.js.map +7 -0
- package/_/views/ThemeInverse.js +27 -0
- package/_/views/ThemeInverse.js.map +7 -0
- package/_/views/ThemeManagerContext.js +56 -0
- package/_/views/ThemeManagerContext.js.map +7 -0
- package/_/views/ThemeProvider.js +45 -0
- package/_/views/ThemeProvider.js.map +7 -0
- package/dist/constants/constants.js +14 -0
- package/dist/constants/constants.js.map +7 -0
- package/dist/constants/platform.js +19 -0
- package/dist/constants/platform.js.map +7 -0
- package/dist/constants/pseudos.js +18 -0
- package/dist/constants/pseudos.js.map +7 -0
- package/dist/constants/rnw.js +22 -0
- package/dist/constants/rnw.js.map +7 -0
- package/dist/constants/styleConstants.js +46 -0
- package/dist/constants/styleConstants.js.map +7 -0
- package/dist/createComponent.js +445 -0
- package/dist/createComponent.js.map +7 -0
- package/dist/createFont.js +24 -0
- package/dist/createFont.js.map +7 -0
- package/dist/createShorthands.js +10 -0
- package/dist/createShorthands.js.map +7 -0
- package/dist/createTamagui.js +159 -0
- package/dist/createTamagui.js.map +7 -0
- package/dist/createTheme.js +20 -0
- package/dist/createTheme.js.map +7 -0
- package/dist/createTokens.js +29 -0
- package/dist/createTokens.js.map +7 -0
- package/dist/createVariable.js +22 -0
- package/dist/createVariable.js.map +7 -0
- package/dist/helpers/addStylesUsingClassname.js +57 -0
- package/dist/helpers/addStylesUsingClassname.js.map +7 -0
- package/dist/helpers/createMediaStyle.js +34 -0
- package/dist/helpers/createMediaStyle.js.map +7 -0
- package/dist/helpers/createPropMapper.js +153 -0
- package/dist/helpers/createPropMapper.js.map +7 -0
- package/dist/helpers/createTamaguiProvider.js +25 -0
- package/dist/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/helpers/extendStaticConfig.js +59 -0
- package/dist/helpers/extendStaticConfig.js.map +7 -0
- package/dist/helpers/fixNativeShadow.js +8 -0
- package/dist/helpers/fixNativeShadow.js.map +7 -0
- package/dist/helpers/fixNativeShadow.native.js +30 -0
- package/dist/helpers/fixNativeShadow.native.js.map +7 -0
- package/dist/helpers/getSplitStyles.js +160 -0
- package/dist/helpers/getSplitStyles.js.map +7 -0
- package/dist/helpers/getStylesAtomic.js +83 -0
- package/dist/helpers/getStylesAtomic.js.map +7 -0
- package/dist/helpers/getStylesAtomic.native.js +10 -0
- package/dist/helpers/getStylesAtomic.native.js.map +7 -0
- package/dist/helpers/insertStyleRule.js +24 -0
- package/dist/helpers/insertStyleRule.js.map +7 -0
- package/dist/helpers/isObj.js +7 -0
- package/dist/helpers/isObj.js.map +7 -0
- package/dist/helpers/matchMedia.js +15 -0
- package/dist/helpers/matchMedia.js.map +7 -0
- package/dist/helpers/matchMedia.native.js +8 -0
- package/dist/helpers/matchMedia.native.js.map +7 -0
- package/dist/helpers/pseudos.js +1 -0
- package/dist/helpers/pseudos.js.map +7 -0
- package/dist/helpers/themeable.js +26 -0
- package/dist/helpers/themeable.js.map +7 -0
- package/dist/hooks/useConstant.js +15 -0
- package/dist/hooks/useConstant.js.map +7 -0
- package/dist/hooks/useFeatures.js +75 -0
- package/dist/hooks/useFeatures.js.map +7 -0
- package/dist/hooks/useForceUpdate.js +28 -0
- package/dist/hooks/useForceUpdate.js.map +7 -0
- package/dist/hooks/useMedia.js +171 -0
- package/dist/hooks/useMedia.js.map +7 -0
- package/dist/hooks/usePressable.js +13 -0
- package/dist/hooks/usePressable.js.map +7 -0
- package/dist/hooks/useTheme.js +93 -0
- package/dist/hooks/useTheme.js.map +7 -0
- package/dist/index.cjs +2125 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +7 -0
- package/dist/packages/core/src/constants/constants.d.ts +8 -0
- package/dist/packages/core/src/constants/constants.d.ts.map +1 -0
- package/dist/packages/core/src/constants/platform.d.ts +9 -0
- package/dist/packages/core/src/constants/platform.d.ts.map +1 -0
- package/dist/packages/core/src/constants/pseudos.d.ts +15 -0
- package/dist/packages/core/src/constants/pseudos.d.ts.map +1 -0
- package/dist/packages/core/src/constants/rnw.d.ts +2 -0
- package/dist/packages/core/src/constants/rnw.d.ts.map +1 -0
- package/dist/packages/core/src/createComponent.d.ts +16 -0
- package/dist/packages/core/src/createComponent.d.ts.map +1 -0
- package/dist/packages/core/src/createShorthands.d.ts +2 -0
- package/dist/packages/core/src/createShorthands.d.ts.map +1 -0
- package/dist/packages/core/src/createTamagui.d.ts +37 -0
- package/dist/packages/core/src/createTamagui.d.ts.map +1 -0
- package/dist/packages/core/src/createTheme.d.ts +5 -0
- package/dist/packages/core/src/createTheme.d.ts.map +1 -0
- package/dist/packages/core/src/createTokens.d.ts +45 -0
- package/dist/packages/core/src/createTokens.d.ts.map +1 -0
- package/dist/packages/core/src/createVariable.d.ts +14 -0
- package/dist/packages/core/src/createVariable.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts +2 -0
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts +8 -0
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts +5 -0
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts +5 -0
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts +2 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts +2 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts +15 -0
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts +3 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts +2 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts +2 -0
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/matchMedia.d.ts +2 -0
- package/dist/packages/core/src/helpers/matchMedia.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts +3 -0
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/themeable.d.ts +10 -0
- package/dist/packages/core/src/helpers/themeable.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useConstant.d.ts +2 -0
- package/dist/packages/core/src/hooks/useConstant.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useFeatures.d.ts +5 -0
- package/dist/packages/core/src/hooks/useFeatures.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts +2 -0
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useMedia.d.ts +16 -0
- package/dist/packages/core/src/hooks/useMedia.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/usePressable.d.ts +3 -0
- package/dist/packages/core/src/hooks/usePressable.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useTheme.d.ts +18 -0
- package/dist/packages/core/src/hooks/useTheme.d.ts.map +1 -0
- package/dist/packages/core/src/index.d.ts +27 -0
- package/dist/packages/core/src/index.d.ts.map +1 -0
- package/dist/packages/core/src/static/postProcessStyles.d.ts +7 -0
- package/dist/packages/core/src/static/postProcessStyles.d.ts.map +1 -0
- package/dist/packages/core/src/static.d.ts +12 -0
- package/dist/packages/core/src/static.d.ts.map +1 -0
- package/dist/packages/core/src/styled.d.ts +16 -0
- package/dist/packages/core/src/styled.d.ts.map +1 -0
- package/dist/packages/core/src/types.d.ts +305 -0
- package/dist/packages/core/src/types.d.ts.map +1 -0
- package/dist/packages/core/src/views/Animated.d.ts +15 -0
- package/dist/packages/core/src/views/Animated.d.ts.map +1 -0
- package/dist/packages/core/src/views/Stack.d.ts +3 -0
- package/dist/packages/core/src/views/Stack.d.ts.map +1 -0
- package/dist/packages/core/src/views/Text.d.ts +3 -0
- package/dist/packages/core/src/views/Text.d.ts.map +1 -0
- package/dist/packages/core/src/views/TextAncestorContext.d.ts +3 -0
- package/dist/packages/core/src/views/TextAncestorContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/Theme.d.ts +8 -0
- package/dist/packages/core/src/views/Theme.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeContext.d.ts +18 -0
- package/dist/packages/core/src/views/ThemeContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeInverse.d.ts +10 -0
- package/dist/packages/core/src/views/ThemeInverse.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts +15 -0
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeProvider.d.ts +10 -0
- package/dist/packages/core/src/views/ThemeProvider.d.ts.map +1 -0
- package/dist/packages/helpers/src/AllRules.d.ts +3 -0
- package/dist/packages/helpers/src/AllRules.d.ts.map +1 -0
- package/dist/packages/helpers/src/concatClassName.d.ts +2 -0
- package/dist/packages/helpers/src/concatClassName.d.ts.map +1 -0
- package/dist/packages/helpers/src/index.d.ts +5 -0
- package/dist/packages/helpers/src/index.d.ts.map +1 -0
- package/dist/packages/helpers/src/types.d.ts +8 -0
- package/dist/packages/helpers/src/types.d.ts.map +1 -0
- package/dist/packages/helpers/src/validStyleProps.d.ts +475 -0
- package/dist/packages/helpers/src/validStyleProps.d.ts.map +1 -0
- package/dist/static/postProcessStyles.js +18 -0
- package/dist/static/postProcessStyles.js.map +7 -0
- package/dist/static.js +15 -0
- package/dist/static.js.map +7 -0
- package/dist/styled.js +21 -0
- package/dist/styled.js.map +7 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/dist/views/Animated.js +79 -0
- package/dist/views/Animated.js.map +7 -0
- package/dist/views/SafeAreaProvider.js +30 -0
- package/dist/views/SafeAreaProvider.js.map +7 -0
- package/dist/views/Stack.js +12 -0
- package/dist/views/Stack.js.map +7 -0
- package/dist/views/Text.js +60 -0
- package/dist/views/Text.js.map +7 -0
- package/dist/views/TextAncestorContext.js +18 -0
- package/dist/views/TextAncestorContext.js.map +7 -0
- package/dist/views/Theme.js +56 -0
- package/dist/views/Theme.js.map +7 -0
- package/dist/views/ThemeContext.js +6 -0
- package/dist/views/ThemeContext.js.map +7 -0
- package/dist/views/ThemeInverse.js +27 -0
- package/dist/views/ThemeInverse.js.map +7 -0
- package/dist/views/ThemeManagerContext.js +55 -0
- package/dist/views/ThemeManagerContext.js.map +7 -0
- package/dist/views/ThemeProvider.js +45 -0
- package/dist/views/ThemeProvider.js.map +7 -0
- package/package.json +33 -0
- package/src/constants/constants.ts +12 -0
- package/src/constants/platform.ts +15 -0
- package/src/constants/pseudos.ts +14 -0
- package/src/constants/rnw.tsx +20 -0
- package/src/createComponent.tsx +596 -0
- package/src/createFont.ts +26 -0
- package/src/createShorthands.ts +5 -0
- package/src/createTamagui.ts +207 -0
- package/src/createTheme.ts +19 -0
- package/src/createTokens.ts +83 -0
- package/src/createVariable.ts +22 -0
- package/src/helpers/addStylesUsingClassname.tsx +60 -0
- package/src/helpers/createMediaStyle.ts +46 -0
- package/src/helpers/createPropMapper.ts +184 -0
- package/src/helpers/createTamaguiProvider.tsx +22 -0
- package/src/helpers/extendStaticConfig.ts +68 -0
- package/src/helpers/fixNativeShadow.native.tsx +27 -0
- package/src/helpers/fixNativeShadow.tsx +2 -0
- package/src/helpers/getSplitStyles.tsx +210 -0
- package/src/helpers/getStylesAtomic.native.ts +3 -0
- package/src/helpers/getStylesAtomic.ts +103 -0
- package/src/helpers/insertStyleRule.tsx +18 -0
- package/src/helpers/isObj.ts +1 -0
- package/src/helpers/matchMedia.native.ts +3 -0
- package/src/helpers/matchMedia.ts +9 -0
- package/src/helpers/themeable.tsx +42 -0
- package/src/hooks/useConstant.tsx +10 -0
- package/src/hooks/useFeatures.tsx +78 -0
- package/src/hooks/useForceUpdate.tsx +26 -0
- package/src/hooks/useMedia.tsx +194 -0
- package/src/hooks/usePressable.tsx +9 -0
- package/src/hooks/useTheme.tsx +107 -0
- package/src/index.ts +33 -0
- package/src/static/postProcessStyles.tsx +20 -0
- package/src/static.ts +22 -0
- package/src/styled.ts +82 -0
- package/src/types.tsx +561 -0
- package/src/views/Animated.tsx +121 -0
- package/src/views/SafeAreaProvider.tsx +33 -0
- package/src/views/Stack.tsx +21 -0
- package/src/views/Text.tsx +66 -0
- package/src/views/TextAncestorContext.tsx +12 -0
- package/src/views/Theme.tsx +73 -0
- package/src/views/ThemeContext.tsx +5 -0
- package/src/views/ThemeInverse.tsx +23 -0
- package/src/views/ThemeManagerContext.tsx +50 -0
- package/src/views/ThemeProvider.tsx +52 -0
- package/tsconfig.json +8 -0
- package/types.d.ts +558 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { getStyleRules } from '@tamagui/helpers'
|
|
2
|
+
|
|
3
|
+
import { Variable, createVariable, isVariable } from './createVariable'
|
|
4
|
+
import { createTamaguiProvider } from './helpers/createTamaguiProvider'
|
|
5
|
+
import { configureMedia } from './hooks/useMedia'
|
|
6
|
+
import {
|
|
7
|
+
CreateTamaguiConfig,
|
|
8
|
+
GenericTamaguiConfig,
|
|
9
|
+
MediaQueryKey,
|
|
10
|
+
TamaguiInternalConfig,
|
|
11
|
+
TamaguiProviderProps,
|
|
12
|
+
} from './types'
|
|
13
|
+
|
|
14
|
+
export type CreateTamaguiProps = TamaguiProviderProps &
|
|
15
|
+
// we omit and re-declare it because we need to allow instantation types to be flexible
|
|
16
|
+
// user then re-defines the types after createTamagui returns the typed object they want
|
|
17
|
+
Omit<GenericTamaguiConfig, 'themes'> & {
|
|
18
|
+
themes: {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
[key: string]: string | number | Variable
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// for ssr/native, will default to active
|
|
24
|
+
mediaQueryDefaultActive?: MediaQueryKey[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let conf: TamaguiInternalConfig | null
|
|
28
|
+
|
|
29
|
+
export const getHasConfigured = () => !!conf
|
|
30
|
+
export const getTamaguiConfig = () => conf!
|
|
31
|
+
|
|
32
|
+
type ConfigListener = (conf: TamaguiInternalConfig) => void
|
|
33
|
+
const configListeners = new Set<ConfigListener>()
|
|
34
|
+
export const onConfiguredOnce = (cb: ConfigListener) => {
|
|
35
|
+
if (conf) {
|
|
36
|
+
cb(conf)
|
|
37
|
+
} else {
|
|
38
|
+
configListeners.add(cb)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const PREFIX = `theme--`
|
|
43
|
+
|
|
44
|
+
export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
45
|
+
config: Conf
|
|
46
|
+
): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>
|
|
47
|
+
? TamaguiInternalConfig<A, B, C, D>
|
|
48
|
+
: unknown {
|
|
49
|
+
// test env loads a few times as it runs diff tests
|
|
50
|
+
if (conf) {
|
|
51
|
+
console.warn('Called createTamagui twice! Should never do so')
|
|
52
|
+
// throw new Error(`#000 createTamagui called twice`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
configureMedia({
|
|
56
|
+
queries: config.media as any,
|
|
57
|
+
defaultActive: config.mediaQueryDefaultActive,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// TODO can avoid some of this CSS creation on native
|
|
61
|
+
const themeConfig = (() => {
|
|
62
|
+
let cssRules: string[] = []
|
|
63
|
+
|
|
64
|
+
// tokens
|
|
65
|
+
let tokenRule = `:root {`
|
|
66
|
+
const varsByValue = new Map<string, Variable>()
|
|
67
|
+
const addVar = (v: Variable) => {
|
|
68
|
+
varsByValue[v.val] = v
|
|
69
|
+
const rule = `--${v.name}:${typeof v.val === 'number' ? `${v.val}px` : v.val};`
|
|
70
|
+
tokenRule += rule
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const key in config.tokens) {
|
|
74
|
+
for (const skey in config.tokens[key]) {
|
|
75
|
+
const val = config.tokens[key][skey]
|
|
76
|
+
if (key === 'font') {
|
|
77
|
+
for (const fkey in val) {
|
|
78
|
+
if (fkey === 'family') {
|
|
79
|
+
addVar(val[fkey])
|
|
80
|
+
} else {
|
|
81
|
+
for (const fskey in val[fkey]) {
|
|
82
|
+
addVar(val[fkey][fskey])
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
addVar(val)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
cssRules.push(`${tokenRule}\n}`)
|
|
92
|
+
|
|
93
|
+
// themes
|
|
94
|
+
for (const themeName in config.themes) {
|
|
95
|
+
// to allow using the same theme with diff names, be sure we don't mutate!
|
|
96
|
+
config.themes[themeName] = { ...config.themes[themeName] }
|
|
97
|
+
const theme = config.themes[themeName]
|
|
98
|
+
let vars = ''
|
|
99
|
+
for (const themeKey in theme) {
|
|
100
|
+
const val = theme[themeKey]
|
|
101
|
+
const getVariableCSS = (inv: any) => {
|
|
102
|
+
const v = varsByValue[inv] ?? inv
|
|
103
|
+
return isVariable(v) ? `--${themeKey}:var(--${v.name});` : `--${themeKey}:${v};`
|
|
104
|
+
}
|
|
105
|
+
vars += getVariableCSS(val)
|
|
106
|
+
// TODO sanity check is necessary
|
|
107
|
+
// make everything a variable that gets put into css
|
|
108
|
+
if (!isVariable(val)) {
|
|
109
|
+
theme[themeKey] = createVariable({
|
|
110
|
+
name: themeKey,
|
|
111
|
+
val,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const [themeClassName, parentName] = themeName.includes('-')
|
|
117
|
+
? themeName.split('-')
|
|
118
|
+
: [themeName, '']
|
|
119
|
+
// tiny hack for now assuming light/dark are typical parentName
|
|
120
|
+
const oppositeName = parentName === 'dark' ? 'light' : 'dark'
|
|
121
|
+
const cssParentSel = parentName ? `.${PREFIX}${parentName}` : ''
|
|
122
|
+
const cssChildSel = `.${PREFIX}${themeClassName}`
|
|
123
|
+
const cssSel = `${cssParentSel} ${cssChildSel}`
|
|
124
|
+
// we need to force specificity
|
|
125
|
+
const cssRule = `${cssSel}, .${PREFIX}${oppositeName} ${cssSel} {\n${vars}\n}`
|
|
126
|
+
cssRules.push(cssRule)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Object.freeze(cssRules)
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
cssRules,
|
|
133
|
+
css: cssRules.join('\n'),
|
|
134
|
+
}
|
|
135
|
+
})()
|
|
136
|
+
|
|
137
|
+
// faster lookups token keys become $keys to match input
|
|
138
|
+
const tokensParsed: any = parseTokens(config.tokens)
|
|
139
|
+
// all themes should match key and we just need variable name
|
|
140
|
+
// TODO once w react native we'd want to have a reverse lookup back to value
|
|
141
|
+
const themeParsed: any = {}
|
|
142
|
+
const firstKey = Object.keys(config.themes)[0]
|
|
143
|
+
for (const key in config.themes[firstKey]) {
|
|
144
|
+
// themeParsed[`$${key}`] = config.themes[firstKey][key]
|
|
145
|
+
const val = config.themes[firstKey][key].val
|
|
146
|
+
themeParsed[`$${key}`] = new Variable({ val, name: key })
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const next: TamaguiInternalConfig = {
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
shorthands: {},
|
|
152
|
+
...config,
|
|
153
|
+
Provider: createTamaguiProvider({
|
|
154
|
+
defaultTheme: 'light',
|
|
155
|
+
...config,
|
|
156
|
+
}),
|
|
157
|
+
themeConfig,
|
|
158
|
+
themeParsed,
|
|
159
|
+
tokensParsed,
|
|
160
|
+
getCSS() {
|
|
161
|
+
return `${themeConfig.css}\n${[...getStyleRules()].join('\n')}`
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
conf = next
|
|
165
|
+
|
|
166
|
+
if (configListeners.size) {
|
|
167
|
+
configListeners.forEach((cb) => cb(next))
|
|
168
|
+
configListeners.clear()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// @ts-expect-error
|
|
172
|
+
return next
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function getThemeParentClassName(themeName?: string | null) {
|
|
176
|
+
return `theme-parent ${themeName ? `${PREFIX}${themeName}` : ''}`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const parseTokens = (tokens: any) => {
|
|
180
|
+
const res: any = {}
|
|
181
|
+
for (const key in tokens) {
|
|
182
|
+
res[key] = {}
|
|
183
|
+
if (key === 'font') {
|
|
184
|
+
for (const family in tokens.font) {
|
|
185
|
+
const obj = {}
|
|
186
|
+
res.font[`$${family}`] = obj
|
|
187
|
+
for (const attrKey in tokens.font[family]) {
|
|
188
|
+
const attr = tokens.font[family][attrKey]
|
|
189
|
+
if (attrKey === 'family') {
|
|
190
|
+
obj[attrKey] = attr
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
obj[attrKey] = Object.keys(attr).reduce((acc, cur) => {
|
|
194
|
+
acc[`$${cur}`] = attr[cur]
|
|
195
|
+
return acc
|
|
196
|
+
}, {})
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
continue
|
|
200
|
+
}
|
|
201
|
+
for (const skey in tokens[key]) {
|
|
202
|
+
res[key][`$${skey}`] = tokens[key][skey]
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return res
|
|
207
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Variable, createVariable } from './createVariable'
|
|
2
|
+
|
|
3
|
+
export const createTheme = <Theme extends { [key: string]: string | Variable }>(
|
|
4
|
+
theme: Theme
|
|
5
|
+
): {
|
|
6
|
+
[key in keyof Theme]: Variable
|
|
7
|
+
} => {
|
|
8
|
+
const res = {} as any
|
|
9
|
+
for (const key in theme) {
|
|
10
|
+
const val = theme[key]
|
|
11
|
+
if (!(val instanceof Variable)) {
|
|
12
|
+
res[key] = createVariable({
|
|
13
|
+
name: key,
|
|
14
|
+
val,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return res
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Variable, createVariable } from './createVariable'
|
|
2
|
+
import { CreateTokens } from './types'
|
|
3
|
+
|
|
4
|
+
// tokens.color.dark.red ===>{ var: `color-dark-red`, val: '' }
|
|
5
|
+
|
|
6
|
+
export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
|
|
7
|
+
return setupTokens(tokens) as any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function setupTokens(tokens: any) {
|
|
11
|
+
return mapTokensToVariables(tokens)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const mapTokensToVariables = (
|
|
15
|
+
tokens: CreateTokens,
|
|
16
|
+
parentPath = ''
|
|
17
|
+
): CreateTokens<Variable> => {
|
|
18
|
+
const res = {}
|
|
19
|
+
for (const key in tokens) {
|
|
20
|
+
const val = tokens[key]
|
|
21
|
+
const name = parentPath ? `${parentPath}-${key}` : key
|
|
22
|
+
if (val && typeof val === 'object') {
|
|
23
|
+
res[key] = mapTokensToVariables(tokens[key], name)
|
|
24
|
+
} else {
|
|
25
|
+
res[key] = createVariable({ val, name })
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
return res
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// verbose but gives us nice types...
|
|
33
|
+
type MakeTokens<T> = T extends {
|
|
34
|
+
font: {
|
|
35
|
+
[key in infer A]: {
|
|
36
|
+
size: infer B
|
|
37
|
+
lineHeight: infer C
|
|
38
|
+
letterSpacing: infer D
|
|
39
|
+
weight: infer Z
|
|
40
|
+
family: infer Y
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
color: infer E
|
|
44
|
+
space: infer F
|
|
45
|
+
size: infer G
|
|
46
|
+
radius: infer H
|
|
47
|
+
zIndex: infer J
|
|
48
|
+
}
|
|
49
|
+
? {
|
|
50
|
+
font: {
|
|
51
|
+
[key in A]: {
|
|
52
|
+
size: {
|
|
53
|
+
[key in keyof B]: Variable
|
|
54
|
+
}
|
|
55
|
+
lineHeight: {
|
|
56
|
+
[key in keyof C]: Variable
|
|
57
|
+
}
|
|
58
|
+
letterSpacing: {
|
|
59
|
+
[key in keyof D]: Variable
|
|
60
|
+
}
|
|
61
|
+
weight: {
|
|
62
|
+
[key in keyof Z]: Variable
|
|
63
|
+
}
|
|
64
|
+
family: Y
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
color: {
|
|
68
|
+
[key in keyof E]: Variable
|
|
69
|
+
}
|
|
70
|
+
space: {
|
|
71
|
+
[key in keyof F]: Variable
|
|
72
|
+
}
|
|
73
|
+
size: {
|
|
74
|
+
[key in keyof G]: Variable
|
|
75
|
+
}
|
|
76
|
+
radius: {
|
|
77
|
+
[key in keyof H]: Variable
|
|
78
|
+
}
|
|
79
|
+
zIndex: {
|
|
80
|
+
[key in keyof J]: Variable
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
: never
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isWeb } from './constants/platform'
|
|
2
|
+
|
|
3
|
+
export class Variable {
|
|
4
|
+
name: string
|
|
5
|
+
val: string | number
|
|
6
|
+
variable: string | number
|
|
7
|
+
|
|
8
|
+
constructor({ val, name }: VariableIn) {
|
|
9
|
+
// converting to px breaks rn
|
|
10
|
+
this.val = val //typeof val === 'string' ? val : `${val}px`
|
|
11
|
+
this.name = name
|
|
12
|
+
this.variable = isWeb ? `var(--${name})` : this.val
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type VariableIn = { val: string | number; name: string }
|
|
17
|
+
|
|
18
|
+
export const createVariable = (props: VariableIn) => new Variable(props)
|
|
19
|
+
|
|
20
|
+
export function isVariable(v: Variable | any): v is Variable {
|
|
21
|
+
return v instanceof Variable
|
|
22
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { useInsertionEffect } from 'react'
|
|
3
|
+
|
|
4
|
+
import { getStylesAtomic } from './getStylesAtomic'
|
|
5
|
+
import { insertStyleRule } from './insertStyleRule'
|
|
6
|
+
|
|
7
|
+
// uses new useInsertionEffect for better perf if available
|
|
8
|
+
|
|
9
|
+
// could be cleared occasionally
|
|
10
|
+
let added = new Set<string>()
|
|
11
|
+
|
|
12
|
+
export function useStylesAsClassname(styles: any[]) {
|
|
13
|
+
if (!useInsertionEffect) {
|
|
14
|
+
return addStylesUsingClassname(styles)
|
|
15
|
+
} else {
|
|
16
|
+
const insertions: any[] = []
|
|
17
|
+
const className = addStylesUsingClassname(styles, (_, rules) => {
|
|
18
|
+
for (const rule of rules) {
|
|
19
|
+
insertions.push(rule)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
useInsertionEffect(() => {
|
|
24
|
+
for (const ruleset of insertions) {
|
|
25
|
+
insertStyleRule(ruleset)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return className
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function addStylesUsingClassname(
|
|
34
|
+
styles: any[],
|
|
35
|
+
onAdd?: (identifier: string, rules: string[]) => any
|
|
36
|
+
) {
|
|
37
|
+
let className = ''
|
|
38
|
+
for (const style of styles) {
|
|
39
|
+
if (!style) continue
|
|
40
|
+
if (Array.isArray(style)) {
|
|
41
|
+
className += ' ' + addStylesUsingClassname(style)
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
for (const { identifier, rules } of getStylesAtomic(style)) {
|
|
45
|
+
className += ` ${identifier}`
|
|
46
|
+
if (added.has(identifier)) {
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
added.add(identifier)
|
|
50
|
+
if (onAdd) {
|
|
51
|
+
onAdd(identifier, rules)
|
|
52
|
+
} else {
|
|
53
|
+
for (const rule of rules) {
|
|
54
|
+
insertStyleRule(rule)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return className
|
|
60
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { StyleObject } from '@tamagui/helpers'
|
|
2
|
+
|
|
3
|
+
import { mediaObjectToString } from '../hooks/useMedia'
|
|
4
|
+
import { MediaQueries } from '../types'
|
|
5
|
+
|
|
6
|
+
// TODO have this be used by extractMediaStyle in tamagui static
|
|
7
|
+
|
|
8
|
+
// not synced to static/constants for now
|
|
9
|
+
export const MEDIA_SEP = '_'
|
|
10
|
+
|
|
11
|
+
export const createMediaStyle = (
|
|
12
|
+
{ identifier, rules }: StyleObject,
|
|
13
|
+
mediaKey: string,
|
|
14
|
+
mediaQueries: MediaQueries,
|
|
15
|
+
negate?: boolean,
|
|
16
|
+
importance = 0
|
|
17
|
+
) => {
|
|
18
|
+
const mediaKeys = Object.keys(mediaQueries)
|
|
19
|
+
const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
|
|
20
|
+
acc[cur] = new Array(importance + 1).fill(':root').join('')
|
|
21
|
+
return acc
|
|
22
|
+
}, {})
|
|
23
|
+
const negKey = negate ? '0' : ''
|
|
24
|
+
const ogPrefix = identifier.slice(0, identifier.indexOf('-') + 1)
|
|
25
|
+
const nextIdentifier = `${identifier.replace(
|
|
26
|
+
ogPrefix,
|
|
27
|
+
`${ogPrefix}${MEDIA_SEP}${mediaKey}${negKey}${MEDIA_SEP}`
|
|
28
|
+
)}`
|
|
29
|
+
const screenStr = negate ? 'not all' : 'screen'
|
|
30
|
+
const mediaSelector = mediaObjectToString(mediaQueries[mediaKey])
|
|
31
|
+
const mediaQuery = `${screenStr} and ${mediaSelector}`
|
|
32
|
+
const precendencePrefix = mediaKeyPrecendence[mediaKey]
|
|
33
|
+
const styleInner = rules[0].replace(identifier, nextIdentifier)
|
|
34
|
+
// combines media queries if they already exist
|
|
35
|
+
let styleRule = ''
|
|
36
|
+
if (styleInner.includes('@media')) {
|
|
37
|
+
// combine
|
|
38
|
+
styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)
|
|
39
|
+
} else {
|
|
40
|
+
styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
styleRule,
|
|
44
|
+
identifier: nextIdentifier,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { getTamaguiConfig } from '../createTamagui'
|
|
2
|
+
import { Variable } from '../createVariable'
|
|
3
|
+
import { StaticConfig, TamaguiInternalConfig } from '../types'
|
|
4
|
+
import { isObj } from './isObj'
|
|
5
|
+
|
|
6
|
+
export const createPropMapper = (c: StaticConfig) => {
|
|
7
|
+
const variants = c.variants
|
|
8
|
+
let variantsParsed
|
|
9
|
+
const defaultProps = c.defaultProps || {}
|
|
10
|
+
|
|
11
|
+
return (key: string, value: any, theme: any, props: any) => {
|
|
12
|
+
const conf = getTamaguiConfig()
|
|
13
|
+
if (!conf) {
|
|
14
|
+
console.trace('no conf! err')
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
if (variants && !variantsParsed) {
|
|
18
|
+
variantsParsed = parseVariants(variants, conf)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// handled here because we need to resolve this off tokens, its the only one-off like this
|
|
22
|
+
let fontFamily = props.fontFamily || defaultProps.fontFamily || '$body'
|
|
23
|
+
|
|
24
|
+
// expand variants
|
|
25
|
+
const variant = variantsParsed?.[key]
|
|
26
|
+
if (variant && typeof value !== 'undefined') {
|
|
27
|
+
const val =
|
|
28
|
+
value === true
|
|
29
|
+
? variant['$true'] || variant['true']
|
|
30
|
+
: variant[value] ?? variant['...'] ?? value
|
|
31
|
+
|
|
32
|
+
const res =
|
|
33
|
+
typeof val === 'function'
|
|
34
|
+
? val(value, { tokens: conf.tokensParsed, theme, props })
|
|
35
|
+
: isObj(val)
|
|
36
|
+
? { ...val }
|
|
37
|
+
: val
|
|
38
|
+
|
|
39
|
+
if (isObj(res)) {
|
|
40
|
+
resolveTokens(res, conf, fontFamily)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return res
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let shouldReturn = false
|
|
47
|
+
|
|
48
|
+
// handle shorthands
|
|
49
|
+
if (conf.shorthands[key]) {
|
|
50
|
+
shouldReturn = true
|
|
51
|
+
key = conf.shorthands[key]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (value && value[0] === '$') {
|
|
55
|
+
shouldReturn = true
|
|
56
|
+
value = getToken(key, value, conf, fontFamily)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (value instanceof Variable) {
|
|
60
|
+
shouldReturn = true
|
|
61
|
+
value = value.variable
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (shouldReturn) {
|
|
65
|
+
return {
|
|
66
|
+
[key]: value,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const resolveTokens = (res: any, conf: TamaguiInternalConfig, fontFamily: any) => {
|
|
73
|
+
for (const rKey in res) {
|
|
74
|
+
const fKey = conf.shorthands[rKey] || rKey
|
|
75
|
+
const val = res[rKey]
|
|
76
|
+
if (val instanceof Variable) {
|
|
77
|
+
res[fKey] = val.variable
|
|
78
|
+
} else if (typeof val === 'string') {
|
|
79
|
+
const fVal = val[0] === '$' ? getToken(fKey, val, conf, fontFamily) : val
|
|
80
|
+
res[fKey] = fVal
|
|
81
|
+
} else {
|
|
82
|
+
if (isObj(val)) {
|
|
83
|
+
// for things like shadowOffset which is a sub-object
|
|
84
|
+
resolveTokens(val, conf, fontFamily)
|
|
85
|
+
}
|
|
86
|
+
// nullish values cant be tokens so need no exrta parsing
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const getToken = (
|
|
92
|
+
key: string,
|
|
93
|
+
value: string,
|
|
94
|
+
{ tokensParsed, themeParsed }: TamaguiInternalConfig,
|
|
95
|
+
fontFamily: string | undefined = '$body'
|
|
96
|
+
) => {
|
|
97
|
+
if (themeParsed[value]) {
|
|
98
|
+
return themeParsed[value].variable
|
|
99
|
+
}
|
|
100
|
+
let valOrVar: any
|
|
101
|
+
if (key === 'fontFamily') {
|
|
102
|
+
valOrVar = tokensParsed.font[value]?.family || value
|
|
103
|
+
}
|
|
104
|
+
if (key === 'fontSize') {
|
|
105
|
+
valOrVar = tokensParsed.font[fontFamily]?.size[value] || value
|
|
106
|
+
}
|
|
107
|
+
if (key === 'lineHeight') {
|
|
108
|
+
valOrVar = tokensParsed.font[fontFamily]?.lineHeight[value] || value
|
|
109
|
+
}
|
|
110
|
+
if (key === 'letterSpacing') {
|
|
111
|
+
valOrVar = tokensParsed.font[fontFamily]?.letterSpacing[value] || value
|
|
112
|
+
}
|
|
113
|
+
if (key === 'fontWeight') {
|
|
114
|
+
valOrVar = tokensParsed.font[fontFamily]?.weight[value] || value
|
|
115
|
+
}
|
|
116
|
+
if (typeof valOrVar !== 'undefined') {
|
|
117
|
+
if (valOrVar instanceof Variable) {
|
|
118
|
+
return valOrVar.variable
|
|
119
|
+
} else {
|
|
120
|
+
return valOrVar
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const cat in tokenCategories) {
|
|
124
|
+
if (tokenCategories[cat][key]) {
|
|
125
|
+
const res = tokensParsed[cat][value]
|
|
126
|
+
if (res) {
|
|
127
|
+
return res.variable
|
|
128
|
+
} else {
|
|
129
|
+
const themeVar = themeParsed[value]
|
|
130
|
+
if (themeVar) {
|
|
131
|
+
return themeVar.variable
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const spaceVar = tokensParsed.space[value]
|
|
137
|
+
if (spaceVar) {
|
|
138
|
+
return spaceVar.variable
|
|
139
|
+
}
|
|
140
|
+
return value
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// just specificy the least costly, all else go to `space` (most keys - we can exclude)
|
|
144
|
+
const tokenCategories = {
|
|
145
|
+
size: {
|
|
146
|
+
width: true,
|
|
147
|
+
height: true,
|
|
148
|
+
minWidth: true,
|
|
149
|
+
minHeight: true,
|
|
150
|
+
maxWidth: true,
|
|
151
|
+
maxHeight: true,
|
|
152
|
+
},
|
|
153
|
+
color: {
|
|
154
|
+
color: true,
|
|
155
|
+
backgroundColor: true,
|
|
156
|
+
borderColor: true,
|
|
157
|
+
borderBottomColor: true,
|
|
158
|
+
borderTopColor: true,
|
|
159
|
+
borderLeftColor: true,
|
|
160
|
+
borderRightColor: true,
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// turns variant spreads into individual lookups
|
|
165
|
+
function parseVariants(variants: any, conf: TamaguiInternalConfig) {
|
|
166
|
+
return Object.keys(variants).reduce((acc, key) => {
|
|
167
|
+
acc[key] = Object.keys(variants[key]).reduce((vacc, vkey) => {
|
|
168
|
+
const variantVal = variants[key][vkey]
|
|
169
|
+
if (vkey.startsWith('...')) {
|
|
170
|
+
// set the default one at '...' for easy fallback on non-exact-variant-match
|
|
171
|
+
vacc['...'] = variantVal
|
|
172
|
+
const tokenKey = vkey.slice(3)
|
|
173
|
+
const tokens = conf.tokens[tokenKey]
|
|
174
|
+
for (const tkey in tokens) {
|
|
175
|
+
vacc[`$${tkey}`] = variantVal
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
vacc[vkey] = variantVal
|
|
179
|
+
}
|
|
180
|
+
return vacc
|
|
181
|
+
}, {})
|
|
182
|
+
return acc
|
|
183
|
+
}, {})
|
|
184
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import { TamaguiProviderProps } from '../types'
|
|
4
|
+
import { TextAncestorProvider } from '../views/TextAncestorContext'
|
|
5
|
+
import { ThemeProvider, ThemeProviderProps } from '../views/ThemeProvider'
|
|
6
|
+
|
|
7
|
+
export function createTamaguiProvider(themeProps: ThemeProviderProps) {
|
|
8
|
+
return function TamaguiProvider({
|
|
9
|
+
initialWindowMetrics,
|
|
10
|
+
fallback,
|
|
11
|
+
children,
|
|
12
|
+
...themePropsProvider
|
|
13
|
+
}: TamaguiProviderProps) {
|
|
14
|
+
return (
|
|
15
|
+
<TextAncestorProvider>
|
|
16
|
+
<ThemeProvider {...themeProps} {...themePropsProvider}>
|
|
17
|
+
<React.Suspense fallback={fallback || null}>{children}</React.Suspense>
|
|
18
|
+
</ThemeProvider>
|
|
19
|
+
</TextAncestorProvider>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|