@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,194 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
|
+
import { matchMedia } from '../helpers/matchMedia'
|
|
5
|
+
import {
|
|
6
|
+
ConfigureMediaQueryOptions,
|
|
7
|
+
MediaQueries,
|
|
8
|
+
MediaQueryObject,
|
|
9
|
+
MediaQueryState,
|
|
10
|
+
} from '../types'
|
|
11
|
+
import { useConstant } from './useConstant'
|
|
12
|
+
import { useForceUpdate } from './useForceUpdate'
|
|
13
|
+
|
|
14
|
+
export const mediaState: { [key in keyof MediaQueryState]: boolean } = {} as any
|
|
15
|
+
const mediaQueryListeners: { [key: string]: Set<Function> } = {}
|
|
16
|
+
|
|
17
|
+
export const addMediaQueryListener = (key: string, cb: any) => {
|
|
18
|
+
mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()
|
|
19
|
+
mediaQueryListeners[key].add(cb)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const removeMediaQueryListener = (key: string, cb: any) => {
|
|
23
|
+
mediaQueryListeners[key].delete(cb)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let conf: MediaQueries | null = null
|
|
27
|
+
|
|
28
|
+
export const mediaQueryConfig = new Proxy<MediaQueries>({} as any, {
|
|
29
|
+
get(target, key) {
|
|
30
|
+
if (!conf) {
|
|
31
|
+
throw new Error(`Be sure to run configureMedia before accessing mediaQueryConfig`)
|
|
32
|
+
}
|
|
33
|
+
return Reflect.get(conf, key)
|
|
34
|
+
},
|
|
35
|
+
ownKeys() {
|
|
36
|
+
if (!conf) {
|
|
37
|
+
throw new Error(`Be sure to run configureMedia before accessing mediaQueryConfig`)
|
|
38
|
+
}
|
|
39
|
+
return Object.keys(conf)
|
|
40
|
+
},
|
|
41
|
+
getOwnPropertyDescriptor() {
|
|
42
|
+
return {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
export const getMedia = () => {
|
|
50
|
+
if (!conf) {
|
|
51
|
+
throw new Error(`not configured yet`)
|
|
52
|
+
}
|
|
53
|
+
return mediaState
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const configureMedia = ({
|
|
57
|
+
queries,
|
|
58
|
+
defaultActive = ['sm', 'xs'],
|
|
59
|
+
}: ConfigureMediaQueryOptions = {}) => {
|
|
60
|
+
if (conf) {
|
|
61
|
+
console.warn(
|
|
62
|
+
`Already configured mediaQueries once (you may have called getMedia() before configureMedia())`
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (queries) {
|
|
67
|
+
conf = queries
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// setup
|
|
71
|
+
for (const key in queries) {
|
|
72
|
+
const str = mediaObjectToString(queries[key])
|
|
73
|
+
try {
|
|
74
|
+
const getMatch = () => matchMedia(str)
|
|
75
|
+
const match = getMatch()
|
|
76
|
+
if (!match || typeof match.addListener !== 'function') {
|
|
77
|
+
// caught below
|
|
78
|
+
throw new Error('⚠️ No match (seeing this in RN sometimes)')
|
|
79
|
+
}
|
|
80
|
+
mediaState[key] = !!match.matches
|
|
81
|
+
match.addListener(() => {
|
|
82
|
+
const next = !!getMatch().matches
|
|
83
|
+
if (next === mediaState[key]) return
|
|
84
|
+
mediaState[key] = next
|
|
85
|
+
const listeners = mediaQueryListeners[key]
|
|
86
|
+
if (listeners?.size) {
|
|
87
|
+
for (const cb of [...listeners]) {
|
|
88
|
+
cb()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
} catch (err: any) {
|
|
93
|
+
console.error('Error running media query', str, err.message, err.stack)
|
|
94
|
+
const isDefaultActive = defaultActive?.includes(key as any) ?? true
|
|
95
|
+
mediaState[key] = isDefaultActive
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type UseMediaState = {
|
|
101
|
+
selections: { [key: string]: boolean }
|
|
102
|
+
nextSelections: { [key: string]: boolean }
|
|
103
|
+
isRendering: boolean
|
|
104
|
+
isUnmounted: boolean
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const useMedia = () => {
|
|
108
|
+
const forceUpdate = useForceUpdate()
|
|
109
|
+
const state = useRef() as React.MutableRefObject<UseMediaState>
|
|
110
|
+
if (!state.current) {
|
|
111
|
+
state.current = {
|
|
112
|
+
selections: {},
|
|
113
|
+
nextSelections: {},
|
|
114
|
+
isUnmounted: false,
|
|
115
|
+
isRendering: true,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
state.current.isRendering = true
|
|
119
|
+
|
|
120
|
+
// track usage
|
|
121
|
+
useIsomorphicLayoutEffect(() => {
|
|
122
|
+
const st = state.current
|
|
123
|
+
st.isRendering = false
|
|
124
|
+
// delete old
|
|
125
|
+
for (const key in st.selections) {
|
|
126
|
+
if (!(key in st.nextSelections)) {
|
|
127
|
+
removeMediaQueryListener(key, forceUpdate)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// add new
|
|
131
|
+
for (const key in st.nextSelections) {
|
|
132
|
+
if (!(key in st.selections)) {
|
|
133
|
+
addMediaQueryListener(key, forceUpdate)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// unmount
|
|
139
|
+
useIsomorphicLayoutEffect(() => {
|
|
140
|
+
return () => {
|
|
141
|
+
const st = state.current
|
|
142
|
+
st.isUnmounted = true
|
|
143
|
+
const allKeys = {
|
|
144
|
+
...st.selections,
|
|
145
|
+
...st.nextSelections,
|
|
146
|
+
}
|
|
147
|
+
for (const key in allKeys) {
|
|
148
|
+
removeMediaQueryListener(key, forceUpdate)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, [])
|
|
152
|
+
|
|
153
|
+
return useConstant(() => {
|
|
154
|
+
const st = state.current
|
|
155
|
+
return new Proxy(mediaState, {
|
|
156
|
+
get(target, key: string) {
|
|
157
|
+
if (!(key in mediaState)) {
|
|
158
|
+
return Reflect.get(target, key)
|
|
159
|
+
}
|
|
160
|
+
if (!st.isUnmounted) {
|
|
161
|
+
if (st.isRendering) {
|
|
162
|
+
st.nextSelections[key] = true
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (key in mediaState) {
|
|
166
|
+
return mediaState[key]
|
|
167
|
+
}
|
|
168
|
+
return Reflect.get(mediaState, key)
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function camelToHyphen(str: string) {
|
|
175
|
+
return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function mediaObjectToString(query: string | MediaQueryObject) {
|
|
179
|
+
if (typeof query === 'string') {
|
|
180
|
+
return query
|
|
181
|
+
}
|
|
182
|
+
return Object.entries(query)
|
|
183
|
+
.map(([feature, value]) => {
|
|
184
|
+
feature = camelToHyphen(feature)
|
|
185
|
+
if (typeof value === 'string') {
|
|
186
|
+
return `(${feature}: ${value})`
|
|
187
|
+
}
|
|
188
|
+
if (typeof value === 'number' && /[height|width]$/.test(feature)) {
|
|
189
|
+
value = `${value}px`
|
|
190
|
+
}
|
|
191
|
+
return `(${feature}: ${value})`
|
|
192
|
+
})
|
|
193
|
+
.join(' and ')
|
|
194
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Pressable, PressableProps } from 'react-native'
|
|
2
|
+
|
|
3
|
+
const getPressable = Pressable?.['type']?.['render']
|
|
4
|
+
|
|
5
|
+
export const usePressable = (props: PressableProps) => {
|
|
6
|
+
const out = getPressable(props)
|
|
7
|
+
const { children, style, ...pressableProps } = out.props
|
|
8
|
+
return [pressableProps, style] as const
|
|
9
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
|
+
import { Variable } from '../createVariable'
|
|
5
|
+
import { ThemeName } from '../types'
|
|
6
|
+
import { ThemeContext } from '../views/ThemeContext'
|
|
7
|
+
import { ThemeManagerContext } from '../views/ThemeManagerContext'
|
|
8
|
+
import { GET_DEFAULT_THEME } from '../views/ThemeProvider'
|
|
9
|
+
import { useForceUpdate } from './useForceUpdate'
|
|
10
|
+
|
|
11
|
+
type UseThemeState = {
|
|
12
|
+
uuid: Object
|
|
13
|
+
keys: Set<string>
|
|
14
|
+
isRendering: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const areEqualSets = (a: Set<string>, b: Set<string>) => {
|
|
18
|
+
if (a.size !== b.size) return false
|
|
19
|
+
for (const val in a) {
|
|
20
|
+
if (!b.has(val)) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const useThemeName = () => {
|
|
28
|
+
const parent = useContext(ThemeManagerContext)
|
|
29
|
+
const [name, setName] = useState(parent.name)
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
return parent.onChangeTheme((next) => {
|
|
32
|
+
setName((prev) => {
|
|
33
|
+
if (prev === next) return prev
|
|
34
|
+
return next
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}, [parent])
|
|
38
|
+
return name || 'light'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const useDefaultThemeName = () => {
|
|
42
|
+
return useContext(ThemeContext)[GET_DEFAULT_THEME] as any as ThemeName
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const useTheme = () => {
|
|
46
|
+
const forceUpdate = useForceUpdate()
|
|
47
|
+
const manager = useContext(ThemeManagerContext)
|
|
48
|
+
const themes = useContext(ThemeContext)
|
|
49
|
+
const state = useRef() as React.MutableRefObject<UseThemeState>
|
|
50
|
+
if (!state.current) {
|
|
51
|
+
state.current = {
|
|
52
|
+
uuid: {},
|
|
53
|
+
keys: new Set(),
|
|
54
|
+
isRendering: true,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
state.current.isRendering = true
|
|
58
|
+
|
|
59
|
+
// track usage
|
|
60
|
+
useIsomorphicLayoutEffect(() => {
|
|
61
|
+
const st = state.current
|
|
62
|
+
st.isRendering = false
|
|
63
|
+
const cur = manager.keys.get(st.uuid)
|
|
64
|
+
if (!cur || !areEqualSets(st.keys, cur)) {
|
|
65
|
+
manager.track(st.uuid, st.keys)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
return manager.onUpdate(state.current.uuid, forceUpdate)
|
|
71
|
+
}, [])
|
|
72
|
+
|
|
73
|
+
const theme = (manager.name ? themes[manager.name] : themes.light) ?? themes.light
|
|
74
|
+
|
|
75
|
+
return useMemo(
|
|
76
|
+
() => {
|
|
77
|
+
return new Proxy(theme, {
|
|
78
|
+
get(_, key: string) {
|
|
79
|
+
const name = manager.name
|
|
80
|
+
if (!name) {
|
|
81
|
+
return Reflect.get(_, key)
|
|
82
|
+
}
|
|
83
|
+
let activeTheme = themes[name]
|
|
84
|
+
if (!activeTheme) {
|
|
85
|
+
console.error('No theme by name', name, 'only:', themes, 'keeping current theme')
|
|
86
|
+
activeTheme = theme
|
|
87
|
+
}
|
|
88
|
+
const val = activeTheme[key]
|
|
89
|
+
if (process.env.NODE_ENV === 'development') {
|
|
90
|
+
if (typeof val === 'undefined') {
|
|
91
|
+
throw new Error(`No theme value "${String(key)}" in: ${Object.keys(activeTheme)}`)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (state.current.isRendering) {
|
|
95
|
+
state.current.keys.add(key)
|
|
96
|
+
}
|
|
97
|
+
// TODO costly, can make faster (we need name mapping to og name, but val pointing to new val)
|
|
98
|
+
// console.log('returning new variable', val, key)
|
|
99
|
+
return new Variable({ val: val.val, name: key })
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
[
|
|
104
|
+
/* if concurrent mode wanted put manager.name here */
|
|
105
|
+
]
|
|
106
|
+
)
|
|
107
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './createComponent'
|
|
2
|
+
export * from './createShorthands'
|
|
3
|
+
export * from './createTheme'
|
|
4
|
+
export * from './createTamagui'
|
|
5
|
+
export * from './createFont'
|
|
6
|
+
export { createTokens } from './createTokens'
|
|
7
|
+
export * from './createVariable'
|
|
8
|
+
export * from './styled'
|
|
9
|
+
export * from './types'
|
|
10
|
+
|
|
11
|
+
export * from './constants/pseudos'
|
|
12
|
+
export * from './constants/constants'
|
|
13
|
+
export * from './constants/platform'
|
|
14
|
+
export * from './constants/rnw'
|
|
15
|
+
|
|
16
|
+
export * from './helpers/isObj'
|
|
17
|
+
export * from './helpers/getStylesAtomic'
|
|
18
|
+
export * from './helpers/matchMedia'
|
|
19
|
+
export * from './helpers/themeable'
|
|
20
|
+
|
|
21
|
+
export * from './hooks/useConstant'
|
|
22
|
+
export * from './hooks/useForceUpdate'
|
|
23
|
+
export * from './hooks/useMedia'
|
|
24
|
+
export * from './hooks/useTheme'
|
|
25
|
+
|
|
26
|
+
export * from './views/Animated'
|
|
27
|
+
export * from './views/Stack'
|
|
28
|
+
export * from './views/Text'
|
|
29
|
+
export * from './views/Theme'
|
|
30
|
+
export * from './views/ThemeInverse'
|
|
31
|
+
export * from './views/ThemeProvider'
|
|
32
|
+
export * from './views/TextAncestorContext'
|
|
33
|
+
export * from './views/SafeAreaProvider'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getSplitStyles } from '../helpers/getSplitStyles'
|
|
2
|
+
import { StaticConfigParsed, TamaguiInternalConfig, ThemeObject } from '../types'
|
|
3
|
+
|
|
4
|
+
// used only by static extractor
|
|
5
|
+
|
|
6
|
+
export const postProcessStyles = (
|
|
7
|
+
inStyles: any,
|
|
8
|
+
staticConfig: StaticConfigParsed,
|
|
9
|
+
theme: ThemeObject
|
|
10
|
+
) => {
|
|
11
|
+
const { style, viewProps, pseudos, classNames } = getSplitStyles(inStyles, staticConfig, theme)
|
|
12
|
+
// flattening
|
|
13
|
+
const next = {}
|
|
14
|
+
for (const s of style) {
|
|
15
|
+
if (!s) continue
|
|
16
|
+
Object.assign(next, s)
|
|
17
|
+
}
|
|
18
|
+
Object.assign(next, pseudos)
|
|
19
|
+
return { style: next, viewProps, classNames }
|
|
20
|
+
}
|
package/src/static.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// only stuff that gets extracted or needed by tamagui-static
|
|
2
|
+
|
|
3
|
+
export * from './styled'
|
|
4
|
+
export * from './createComponent'
|
|
5
|
+
export * from './createFont'
|
|
6
|
+
export * from './createTokens'
|
|
7
|
+
export * from './createTamagui'
|
|
8
|
+
export * from './constants/constants'
|
|
9
|
+
|
|
10
|
+
export * from './hooks/useMedia'
|
|
11
|
+
export * from './hooks/useTheme'
|
|
12
|
+
|
|
13
|
+
export * from './helpers/isObj'
|
|
14
|
+
export * from './helpers/getStylesAtomic'
|
|
15
|
+
export * from './helpers/getSplitStyles'
|
|
16
|
+
export * from '@tamagui/helpers'
|
|
17
|
+
|
|
18
|
+
export * from './constants/pseudos'
|
|
19
|
+
|
|
20
|
+
// -- below exports are only bundled compile-time --
|
|
21
|
+
|
|
22
|
+
export * from './static/postProcessStyles'
|
package/src/styled.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { createComponent } from './createComponent'
|
|
4
|
+
import { extendStaticConfig } from './helpers/extendStaticConfig'
|
|
5
|
+
import { MediaProps, StaticComponent, StaticConfig, TamaguiConfig, Themes, Tokens } from './types'
|
|
6
|
+
|
|
7
|
+
export function styled<
|
|
8
|
+
ParentComponent extends StaticComponent | React.Component<any>,
|
|
9
|
+
Variants extends GetVariants<ParentComponent>
|
|
10
|
+
>(
|
|
11
|
+
Component: ParentComponent,
|
|
12
|
+
options?: GetProps<ParentComponent> & {
|
|
13
|
+
variants?: Variants
|
|
14
|
+
},
|
|
15
|
+
staticExtractionOptions?: StaticConfig
|
|
16
|
+
) {
|
|
17
|
+
const staticConfigProps: StaticConfig = (() => {
|
|
18
|
+
if (options) {
|
|
19
|
+
const { variants, ...defaultProps } = options
|
|
20
|
+
return { ...staticExtractionOptions, variants, defaultProps }
|
|
21
|
+
}
|
|
22
|
+
return {}
|
|
23
|
+
})()
|
|
24
|
+
const config = extendStaticConfig(Component, staticConfigProps)
|
|
25
|
+
const component = createComponent(config!) // error is good here its on init
|
|
26
|
+
type VariantProps = GetVariantProps<Variants>
|
|
27
|
+
return component as StaticComponent<
|
|
28
|
+
Omit<GetProps<ParentComponent>, keyof VariantProps> & VariantProps & MediaProps<VariantProps>
|
|
29
|
+
// leave this out it was causing infinite recursion type issues
|
|
30
|
+
// VariantProps
|
|
31
|
+
>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// type ParentVariants = A extends StaticComponent<any, infer Variants> ? Variants : {}
|
|
35
|
+
|
|
36
|
+
export type GetProps<A> = A extends StaticComponent<infer Props>
|
|
37
|
+
? Props
|
|
38
|
+
: A extends React.Component<infer Props>
|
|
39
|
+
? Props
|
|
40
|
+
: {}
|
|
41
|
+
|
|
42
|
+
export type GetVariants<ParentComponent extends StaticComponent | React.Component<any>> = void | {
|
|
43
|
+
[key: string]: {
|
|
44
|
+
[key: string]:
|
|
45
|
+
| Partial<GetProps<ParentComponent>>
|
|
46
|
+
| ((
|
|
47
|
+
val: any,
|
|
48
|
+
config: {
|
|
49
|
+
tokens: TamaguiConfig['tokens']
|
|
50
|
+
theme: Themes extends { [key: string]: infer B } ? B : unknown
|
|
51
|
+
props: GetProps<ParentComponent>
|
|
52
|
+
}
|
|
53
|
+
) => Partial<GetProps<ParentComponent>>)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type GetVariantProps<Variants> = Variants extends void
|
|
58
|
+
? {}
|
|
59
|
+
: {
|
|
60
|
+
// ensure variants actually defined
|
|
61
|
+
[Key in keyof Variants]?: keyof Variants[Key] extends `...${infer VariantSpread}`
|
|
62
|
+
? VariantSpread extends keyof Tokens
|
|
63
|
+
? keyof Tokens[VariantSpread] extends string | number
|
|
64
|
+
? `$${keyof Tokens[VariantSpread]}`
|
|
65
|
+
: unknown
|
|
66
|
+
: unknown
|
|
67
|
+
: keyof Variants[Key] extends 'true'
|
|
68
|
+
? boolean
|
|
69
|
+
: keyof Exclude<Variants[Key], undefined>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// type X = { ok: 1 }
|
|
73
|
+
// type Y = { okk: 2; ok: 3 }
|
|
74
|
+
// type Z = X & Y
|
|
75
|
+
// type Z2 = Z
|
|
76
|
+
|
|
77
|
+
// TODO get name
|
|
78
|
+
// const displayName = `styled(Component)`
|
|
79
|
+
// Object.defineProperty(component, 'name', {
|
|
80
|
+
// value: displayName,
|
|
81
|
+
// writable: false,
|
|
82
|
+
// })
|