@tamagui/core 1.0.0-alpha.4 → 1.0.0-alpha.8
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/dist/cjs/constants/constants.js +50 -0
- package/{_ → dist/cjs}/constants/constants.js.map +2 -2
- package/dist/cjs/constants/platform.js +43 -0
- package/dist/cjs/constants/platform.js.map +7 -0
- package/dist/cjs/constants/pseudos.js +25 -0
- package/{_ → dist/cjs}/constants/pseudos.js.map +2 -2
- package/{_ → dist/cjs}/constants/rnw.js +9 -3
- package/{_ → dist/cjs}/constants/rnw.js.map +2 -2
- package/dist/cjs/createComponent.js +531 -0
- package/dist/cjs/createComponent.js.map +7 -0
- package/dist/cjs/createFont.js +50 -0
- package/dist/cjs/createFont.js.map +7 -0
- package/{_ → dist/cjs}/createShorthands.js +9 -3
- package/{_ → dist/cjs}/createShorthands.js.map +2 -2
- package/dist/cjs/createTamagui.js +206 -0
- package/dist/cjs/createTamagui.js.map +7 -0
- package/dist/cjs/createTheme.js +42 -0
- package/{_ → dist/cjs}/createTheme.js.map +2 -2
- package/dist/cjs/createTokens.js +55 -0
- package/dist/cjs/createTokens.js.map +7 -0
- package/dist/cjs/createVariable.js +47 -0
- package/dist/cjs/createVariable.js.map +7 -0
- package/dist/cjs/helpers/addStylesUsingClassname.js +79 -0
- package/dist/cjs/helpers/addStylesUsingClassname.js.map +7 -0
- package/dist/cjs/helpers/createMediaStyle.js +56 -0
- package/{_ → dist/cjs}/helpers/createMediaStyle.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +190 -0
- package/dist/cjs/helpers/createPropMapper.js.map +7 -0
- package/dist/cjs/helpers/createTamaguiProvider.js +74 -0
- package/dist/cjs/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/cjs/helpers/extendStaticConfig.js +82 -0
- package/dist/cjs/helpers/extendStaticConfig.js.map +7 -0
- package/dist/cjs/helpers/fixNativeShadow.js +14 -0
- package/dist/cjs/helpers/fixNativeShadow.js.map +7 -0
- package/{_ → dist/cjs}/helpers/fixNativeShadow.native.js +9 -3
- package/{_ → dist/cjs}/helpers/fixNativeShadow.native.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +180 -0
- package/dist/cjs/helpers/getSplitStyles.js.map +7 -0
- package/dist/cjs/helpers/getStylesAtomic.js +117 -0
- package/{_ → dist/cjs}/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js +16 -0
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +7 -0
- package/dist/cjs/helpers/insertStyleRule.js +46 -0
- package/{_ → dist/cjs}/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/isObj.js +13 -0
- package/dist/cjs/helpers/isObj.js.map +7 -0
- package/dist/cjs/helpers/isTamaguiElement.js +33 -0
- package/dist/cjs/helpers/isTamaguiElement.js.map +7 -0
- package/dist/cjs/helpers/matchMedia.js +24 -0
- package/dist/cjs/helpers/matchMedia.js.map +7 -0
- package/dist/cjs/helpers/matchMedia.native.js +31 -0
- package/dist/cjs/helpers/matchMedia.native.js.map +7 -0
- package/dist/cjs/helpers/themeable.js +78 -0
- package/{_ → dist/cjs}/helpers/themeable.js.map +2 -2
- package/dist/cjs/helpers/validate.js +82 -0
- package/dist/cjs/helpers/validate.js.map +7 -0
- package/dist/cjs/hooks/useConstant.js +37 -0
- package/{_ → dist/cjs}/hooks/useConstant.js.map +2 -2
- package/dist/cjs/hooks/useFeatures.js +100 -0
- package/dist/cjs/hooks/useFeatures.js.map +7 -0
- package/{_ → dist/cjs}/hooks/useMedia.js +59 -28
- package/dist/cjs/hooks/useMedia.js.map +7 -0
- package/dist/cjs/hooks/usePressable.js +50 -0
- package/{_ → dist/cjs}/hooks/usePressable.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +111 -0
- package/dist/cjs/hooks/useTheme.js.map +7 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/static/postProcessStyles.js +40 -0
- package/{_ → dist/cjs}/static/postProcessStyles.js.map +2 -2
- package/dist/cjs/static.js +34 -0
- package/dist/cjs/static.js.map +7 -0
- package/dist/cjs/styled.js +72 -0
- package/dist/cjs/styled.js.map +7 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/views/Animated.js +129 -0
- package/{_ → dist/cjs}/views/Animated.js.map +2 -2
- package/dist/cjs/views/Stack.js +51 -0
- package/{_ → dist/cjs}/views/Stack.js.map +2 -2
- package/dist/cjs/views/Text.js +93 -0
- package/{_ → dist/cjs}/views/Text.js.map +2 -2
- package/dist/cjs/views/TextAncestorContext.js +41 -0
- package/{_ → dist/cjs}/views/TextAncestorContext.js.map +2 -2
- package/dist/cjs/views/Theme.js +88 -0
- package/dist/cjs/views/Theme.js.map +7 -0
- package/dist/cjs/views/ThemeContext.js +29 -0
- package/{_ → dist/cjs}/views/ThemeContext.js.map +2 -2
- package/dist/cjs/views/ThemeInverse.js +48 -0
- package/{_ → dist/cjs}/views/ThemeInverse.js.map +3 -3
- package/dist/cjs/views/ThemeManagerContext.js +84 -0
- package/dist/cjs/views/ThemeManagerContext.js.map +7 -0
- package/dist/cjs/views/ThemeProvider.js +67 -0
- package/{_ → dist/cjs}/views/ThemeProvider.js.map +2 -2
- package/dist/createComponent.js +49 -31
- package/dist/createComponent.js.map +2 -2
- package/dist/createFont.js +4 -0
- package/dist/createFont.js.map +2 -2
- package/dist/createTamagui.js +11 -2
- package/dist/createTamagui.js.map +2 -2
- package/dist/createTokens.js +4 -0
- package/dist/createTokens.js.map +2 -2
- package/dist/createVariable.js +3 -0
- package/dist/createVariable.js.map +2 -2
- package/dist/helpers/createPropMapper.js +2 -2
- package/dist/helpers/createPropMapper.js.map +1 -1
- package/dist/helpers/getSplitStyles.js +13 -23
- package/dist/helpers/getSplitStyles.js.map +2 -2
- package/dist/helpers/isComponent.js +10 -0
- package/dist/helpers/isComponent.js.map +7 -0
- package/dist/helpers/isTamaguiComponent.js +10 -0
- package/dist/helpers/isTamaguiComponent.js.map +7 -0
- package/dist/helpers/isTamaguiElement.js +10 -0
- package/dist/helpers/isTamaguiElement.js.map +7 -0
- package/dist/helpers/matchMedia.js +3 -0
- package/dist/helpers/matchMedia.js.map +2 -2
- package/dist/helpers/matchMedia.native.js +1 -0
- package/dist/helpers/matchMedia.native.js.map +2 -2
- package/dist/helpers/validate.js +60 -0
- package/dist/helpers/validate.js.map +7 -0
- package/dist/helpers/validateConfig.js +46 -0
- package/dist/helpers/validateConfig.js.map +7 -0
- package/dist/helpers/validateTokens.js +29 -0
- package/dist/helpers/validateTokens.js.map +7 -0
- package/dist/hooks/useFeatures.js +39 -51
- package/dist/hooks/useFeatures.js.map +2 -2
- package/dist/hooks/useMedia.js.map +1 -1
- package/dist/hooks/useTheme.js +5 -9
- package/dist/hooks/useTheme.js.map +2 -2
- package/dist/index.cjs +234 -135
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/views/Theme.js +16 -7
- package/dist/views/Theme.js.map +2 -2
- package/dist/views/ThemeInverse.js +0 -1
- package/dist/views/ThemeInverse.js.map +2 -2
- package/dist/views/ThemeManagerContext.js +11 -5
- package/dist/views/ThemeManagerContext.js.map +2 -2
- package/package.json +18 -12
- package/src/createComponent.tsx +55 -40
- package/src/createFont.ts +5 -0
- package/src/createTamagui.ts +11 -1
- package/src/createTokens.ts +6 -1
- package/src/createVariable.ts +4 -0
- package/src/helpers/createPropMapper.ts +2 -2
- package/src/helpers/getSplitStyles.tsx +16 -26
- package/src/helpers/isTamaguiElement.tsx +5 -0
- package/src/helpers/matchMedia.native.ts +3 -0
- package/src/helpers/matchMedia.ts +9 -1
- package/src/helpers/validate.ts +59 -0
- package/src/hooks/useFeatures.tsx +54 -53
- package/src/hooks/useMedia.tsx +1 -1
- package/src/hooks/useTheme.tsx +7 -8
- package/src/index.ts +1 -1
- package/src/types.tsx +3 -2
- package/src/views/Theme.tsx +26 -9
- package/src/views/ThemeInverse.tsx +0 -1
- package/src/views/ThemeManagerContext.tsx +18 -6
- package/types.d.ts +10 -8
- package/.ultra.cache.json +0 -1
- package/_/constants/constants.js +0 -14
- package/_/constants/platform.js +0 -20
- package/_/constants/platform.js.map +0 -7
- package/_/constants/pseudos.js +0 -18
- package/_/createComponent.js +0 -427
- package/_/createComponent.js.map +0 -7
- package/_/createTamagui.js +0 -122
- package/_/createTamagui.js.map +0 -7
- package/_/createTheme.js +0 -20
- package/_/createTokens.js +0 -29
- package/_/createTokens.js.map +0 -7
- package/_/createVariable.js +0 -22
- package/_/createVariable.js.map +0 -7
- package/_/helpers/addStylesUsingClassname.js +0 -32
- package/_/helpers/addStylesUsingClassname.js.map +0 -7
- package/_/helpers/createMediaStyle.js +0 -34
- package/_/helpers/createTamaguiProvider.js +0 -42
- package/_/helpers/createTamaguiProvider.js.map +0 -7
- package/_/helpers/extendStaticConfig.js +0 -176
- package/_/helpers/extendStaticConfig.js.map +0 -7
- package/_/helpers/fixNativeShadow.js +0 -8
- package/_/helpers/fixNativeShadow.js.map +0 -7
- package/_/helpers/getSplitStyles.js +0 -160
- package/_/helpers/getSplitStyles.js.map +0 -7
- package/_/helpers/getStylesAtomic.js +0 -84
- package/_/helpers/getStylesAtomic.native.js +0 -10
- package/_/helpers/getStylesAtomic.native.js.map +0 -7
- package/_/helpers/insertStyleRule.js +0 -24
- package/_/helpers/matchMedia.js +0 -15
- package/_/helpers/matchMedia.js.map +0 -7
- package/_/helpers/matchMedia.native.js +0 -8
- package/_/helpers/matchMedia.native.js.map +0 -7
- package/_/helpers/themeable.js +0 -26
- package/_/hooks/useConstant.js +0 -15
- package/_/hooks/useFeatures.js +0 -75
- package/_/hooks/useFeatures.js.map +0 -7
- package/_/hooks/useForceUpdate.js +0 -28
- package/_/hooks/useForceUpdate.js.map +0 -7
- package/_/hooks/useMedia.js.map +0 -7
- package/_/hooks/usePressable.js +0 -14
- package/_/hooks/useTheme.js +0 -94
- package/_/hooks/useTheme.js.map +0 -7
- package/_/index.js +0 -30
- package/_/index.js.map +0 -7
- package/_/static/postProcessStyles.js +0 -18
- package/_/static.js +0 -12
- package/_/static.js.map +0 -7
- package/_/styled.js +0 -21
- package/_/styled.js.map +0 -7
- package/_/types.js +0 -1
- package/_/types.js.map +0 -7
- package/_/views/Animated.js +0 -79
- package/_/views/Stack.js +0 -12
- package/_/views/Text.js +0 -60
- package/_/views/TextAncestorContext.js +0 -19
- package/_/views/Theme.js +0 -57
- package/_/views/Theme.js.map +0 -7
- package/_/views/ThemeContext.js +0 -6
- package/_/views/ThemeInverse.js +0 -27
- package/_/views/ThemeManagerContext.js +0 -56
- package/_/views/ThemeManagerContext.js.map +0 -7
- package/_/views/ThemeProvider.js +0 -45
- package/src/views/SafeAreaProvider.tsx +0 -33
- package/tsconfig.json +0 -8
|
@@ -1,51 +1,66 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
|
|
3
3
|
import { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
|
-
import { addMediaQueryListener, removeMediaQueryListener } from './useMedia'
|
|
4
|
+
import { addMediaQueryListener, mediaState, removeMediaQueryListener } from './useMedia'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type FeatureDefinition = {
|
|
7
|
+
isEnabled: (props: any) => boolean
|
|
8
|
+
Component: any
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
const createDefinition = ({
|
|
11
|
+
const createDefinition = ({
|
|
12
|
+
Component,
|
|
13
|
+
propNames,
|
|
14
|
+
}: {
|
|
15
|
+
Component: any
|
|
16
|
+
propNames: string[]
|
|
17
|
+
}): FeatureDefinition => ({
|
|
10
18
|
isEnabled: (props: any) => propNames.some((name) => !!props[name]),
|
|
11
19
|
Component,
|
|
12
20
|
})
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
'$xs',
|
|
16
|
-
'$sm',
|
|
17
|
-
'$md',
|
|
18
|
-
'$lg',
|
|
19
|
-
'$xl',
|
|
20
|
-
'$xxl',
|
|
21
|
-
'$pointerCoarse',
|
|
22
|
-
'$hoverNone',
|
|
23
|
-
'$tall',
|
|
24
|
-
'$short',
|
|
25
|
-
'$gtSm',
|
|
26
|
-
'$notXs',
|
|
27
|
-
'$gtMd',
|
|
28
|
-
'$gtLg',
|
|
29
|
-
]
|
|
22
|
+
let featureDefinitions: Record<string, FeatureDefinition> | null = null
|
|
30
23
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
export const useFeatures = (props: any, utils?: { forceUpdate?: Function }) => {
|
|
25
|
+
if (!featureDefinitions) {
|
|
26
|
+
featureDefinitions = loadFeatures()
|
|
27
|
+
}
|
|
28
|
+
const features: JSX.Element[] = []
|
|
29
|
+
for (const name in featureDefinitions) {
|
|
30
|
+
const { isEnabled, Component } = featureDefinitions[name]
|
|
31
|
+
if (isEnabled(props) && Component) {
|
|
32
|
+
features.push(<Component key={name} {...props} _utils={utils} />)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return features
|
|
36
|
+
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
function loadFeatures(): Record<string, FeatureDefinition> {
|
|
39
|
+
return {
|
|
40
|
+
// TODO
|
|
41
|
+
// measureLayout: createDefinition({
|
|
42
|
+
// Component: (props) => {
|
|
43
|
+
// console.log('measure', props)
|
|
44
|
+
// return null
|
|
45
|
+
// },
|
|
46
|
+
// propNames: ['onLayout'],
|
|
47
|
+
// }),
|
|
48
|
+
|
|
49
|
+
// will update the parent whenever media query changes
|
|
50
|
+
// no need on web, media queries are inserted and run in css
|
|
51
|
+
...(!isWeb && {
|
|
52
|
+
mediaQuery: loadMediaQueryFeature(),
|
|
53
|
+
}),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function loadMediaQueryFeature() {
|
|
58
|
+
const mediaPropNames = Object.keys(mediaState)
|
|
59
|
+
|
|
60
|
+
return createDefinition({
|
|
61
|
+
Component: (props: any) => {
|
|
62
|
+
const keys = mediaPropNames.flatMap((x) => (x in props ? x.slice(1) : []))
|
|
47
63
|
|
|
48
|
-
const keys = mediaQueryPropNames.flatMap((x) => (x in props ? x.slice(1) : []))
|
|
49
64
|
useIsomorphicLayoutEffect(() => {
|
|
50
65
|
for (const key of keys) {
|
|
51
66
|
addMediaQueryListener(key, props._utils.forceUpdate)
|
|
@@ -56,23 +71,9 @@ const featureDefinitions = {
|
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
}, [keys.join(',')])
|
|
74
|
+
|
|
59
75
|
return null
|
|
60
76
|
},
|
|
61
|
-
propNames:
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const featureNames = Object.keys(featureDefinitions)
|
|
66
|
-
const numFeatures = featureNames.length
|
|
67
|
-
|
|
68
|
-
export const useFeatures = (props: any, utils?: { forceUpdate?: Function }) => {
|
|
69
|
-
const features: JSX.Element[] = []
|
|
70
|
-
for (let i = 0; i < numFeatures; i++) {
|
|
71
|
-
const name = featureNames[i]
|
|
72
|
-
const { isEnabled, Component } = featureDefinitions[name] as any //FeatureDefinition
|
|
73
|
-
if (isEnabled(props) && Component) {
|
|
74
|
-
features.push(<Component key={name} {...props} _utils={utils} />)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return features
|
|
77
|
+
propNames: mediaPropNames,
|
|
78
|
+
})
|
|
78
79
|
}
|
package/src/hooks/useMedia.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
2
|
import { useRef } from 'react'
|
|
3
3
|
|
|
4
|
-
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
|
+
import { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
5
5
|
import { matchMedia } from '../helpers/matchMedia'
|
|
6
6
|
import {
|
|
7
7
|
ConfigureMediaQueryOptions,
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
|
-
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
3
3
|
|
|
4
4
|
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
5
5
|
import { Variable } from '../createVariable'
|
|
@@ -24,17 +24,16 @@ const areEqualSets = (a: Set<string>, b: Set<string>) => {
|
|
|
24
24
|
return true
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const useThemeName = () => {
|
|
27
|
+
export const useThemeName = (opts?: { parent?: true }) => {
|
|
28
28
|
const parent = useContext(ThemeManagerContext)
|
|
29
29
|
const [name, setName] = useState(parent.name)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return next
|
|
35
|
-
})
|
|
30
|
+
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
return parent.onChangeTheme((next, manager) => {
|
|
33
|
+
setName(opts?.parent ? manager.parentName : next)
|
|
36
34
|
})
|
|
37
35
|
}, [parent])
|
|
36
|
+
|
|
38
37
|
return name || 'light'
|
|
39
38
|
}
|
|
40
39
|
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './helpers/isObj'
|
|
|
17
17
|
export * from './helpers/getStylesAtomic'
|
|
18
18
|
export * from './helpers/matchMedia'
|
|
19
19
|
export * from './helpers/themeable'
|
|
20
|
+
export * from './helpers/isTamaguiElement'
|
|
20
21
|
|
|
21
22
|
export * from './hooks/useConstant'
|
|
22
23
|
export * from './hooks/useMedia'
|
|
@@ -29,4 +30,3 @@ export * from './views/Theme'
|
|
|
29
30
|
export * from './views/ThemeInverse'
|
|
30
31
|
export * from './views/ThemeProvider'
|
|
31
32
|
export * from './views/TextAncestorContext'
|
|
32
|
-
export * from './views/SafeAreaProvider'
|
package/src/types.tsx
CHANGED
|
@@ -88,7 +88,7 @@ export type Shorthands = TamaguiConfig['shorthands']
|
|
|
88
88
|
export type Media = TamaguiConfig['media']
|
|
89
89
|
export type Themes = TamaguiConfig['themes']
|
|
90
90
|
// themes
|
|
91
|
-
export type ThemeName = keyof Themes extends `${infer Prefix}
|
|
91
|
+
export type ThemeName = keyof Themes extends `${infer Prefix}-${string}`
|
|
92
92
|
? Prefix | keyof Themes
|
|
93
93
|
: keyof Themes
|
|
94
94
|
export type ThemeKeys = keyof ThemeObject
|
|
@@ -110,6 +110,7 @@ export type TamaguiInternalConfig<
|
|
|
110
110
|
tokensParsed: CreateTokens<Variable>
|
|
111
111
|
themeConfig: any
|
|
112
112
|
getCSS: () => string
|
|
113
|
+
parsed: boolean
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
// prevents const intersections from being clobbered into string, keeping the consts
|
|
@@ -319,7 +320,7 @@ export type StaticComponent<
|
|
|
319
320
|
* If you create a styled frame component this is a HoC to extract
|
|
320
321
|
* styles from all parents.
|
|
321
322
|
*/
|
|
322
|
-
extractable: <X>(a: X) => X
|
|
323
|
+
extractable: <X>(a: X, opts?: StaticConfig) => X
|
|
323
324
|
}
|
|
324
325
|
|
|
325
326
|
export type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, 'children'>> & {
|
package/src/views/Theme.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useContext, useState } from 'react'
|
|
|
3
3
|
import { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
4
|
import { getThemeParentClassName } from '../createTamagui'
|
|
5
5
|
import { useConstant } from '../hooks/useConstant'
|
|
6
|
-
import { ThemeName
|
|
6
|
+
import { ThemeName } from '../types'
|
|
7
7
|
import { ThemeContext } from './ThemeContext'
|
|
8
8
|
import { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'
|
|
9
9
|
|
|
@@ -18,30 +18,47 @@ export const Theme = (props: ThemeProps) => {
|
|
|
18
18
|
const themes = useContext(ThemeContext)
|
|
19
19
|
const [parentName, setParentName] = useState(parent.name || 'light')
|
|
20
20
|
if (!themes) {
|
|
21
|
-
console.warn('no themes
|
|
21
|
+
console.warn('Error, no themes in context', props)
|
|
22
22
|
return props.children
|
|
23
23
|
}
|
|
24
24
|
const name = props.name as string
|
|
25
|
-
const
|
|
26
|
-
const
|
|
25
|
+
const nextNameParent = `${name}-${parentName}`
|
|
26
|
+
const nextNameParentParent = `${name}-${parent.parentName}`
|
|
27
|
+
const activeName = !name
|
|
28
|
+
? null
|
|
29
|
+
: name in themes
|
|
30
|
+
? name
|
|
31
|
+
: nextNameParent in themes
|
|
32
|
+
? nextNameParent
|
|
33
|
+
: nextNameParentParent in themes
|
|
34
|
+
? nextNameParentParent
|
|
35
|
+
: null
|
|
36
|
+
const theme = activeName ? themes[activeName] : null
|
|
37
|
+
const themeManager = useConstant<ThemeManager | null>(() => {
|
|
38
|
+
if (!theme) {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
27
41
|
const manager = new ThemeManager()
|
|
28
42
|
if (name) {
|
|
29
|
-
manager.setActiveTheme(name, themes[name])
|
|
43
|
+
manager.setActiveTheme({ name, theme: themes[name], parentName })
|
|
30
44
|
}
|
|
31
45
|
return manager
|
|
32
46
|
})
|
|
33
47
|
|
|
34
48
|
useIsomorphicLayoutEffect(() => {
|
|
35
|
-
themeManager
|
|
49
|
+
if (!themeManager) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
themeManager.setActiveTheme({ name: activeName, theme, parentName })
|
|
36
53
|
return parent.onChangeTheme((next) => {
|
|
37
54
|
if (next) {
|
|
38
|
-
themeManager.setActiveTheme(next, themes[next])
|
|
55
|
+
themeManager.setActiveTheme({ name: next, theme: themes[next], parentName })
|
|
39
56
|
setParentName(next)
|
|
40
57
|
}
|
|
41
58
|
})
|
|
42
|
-
}, [themes,
|
|
59
|
+
}, [themes, activeName, parentName])
|
|
43
60
|
|
|
44
|
-
if (!name) {
|
|
61
|
+
if (!name || !theme) {
|
|
45
62
|
return props.children
|
|
46
63
|
}
|
|
47
64
|
|
|
@@ -18,6 +18,5 @@ export const ThemeInverse = (props: { children: any }) => {
|
|
|
18
18
|
const themeName = useThemeName()
|
|
19
19
|
const defaultTheme = useDefaultThemeName()
|
|
20
20
|
const name = inversions[themeName] || inversions[defaultTheme] || null
|
|
21
|
-
console.log('todo fixme invert', { themeName, defaultTheme, next: name })
|
|
22
21
|
return <Theme name={name}>{props.children}</Theme>
|
|
23
22
|
}
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { createContext } from 'react'
|
|
2
2
|
|
|
3
|
+
type ThemeListener = (name: string | null, themeManager: ThemeManager) => void
|
|
4
|
+
|
|
3
5
|
export class ThemeManager {
|
|
4
6
|
name: string | null = 'light'
|
|
7
|
+
parentName: string | null = null
|
|
5
8
|
keys = new Map<any, Set<string>>()
|
|
6
9
|
listeners = new Map<any, Function>()
|
|
7
|
-
|
|
10
|
+
themeListeners = new Set<ThemeListener>()
|
|
8
11
|
theme = null
|
|
9
12
|
|
|
10
|
-
setActiveTheme(
|
|
13
|
+
setActiveTheme({
|
|
14
|
+
name,
|
|
15
|
+
theme,
|
|
16
|
+
parentName,
|
|
17
|
+
}: {
|
|
18
|
+
parentName?: string | null
|
|
19
|
+
name: string | null
|
|
20
|
+
theme?: any
|
|
21
|
+
}) {
|
|
11
22
|
if (name === this.name) return
|
|
12
23
|
this.name = name
|
|
13
24
|
this.theme = theme
|
|
25
|
+
this.parentName = parentName || null
|
|
14
26
|
this.update()
|
|
15
27
|
}
|
|
16
28
|
|
|
@@ -28,13 +40,13 @@ export class ThemeManager {
|
|
|
28
40
|
this.listeners.get(uuid)?.()
|
|
29
41
|
}
|
|
30
42
|
}
|
|
31
|
-
this.
|
|
43
|
+
this.themeListeners.forEach((cb) => cb(this.name, this))
|
|
32
44
|
}
|
|
33
45
|
|
|
34
|
-
onChangeTheme(cb:
|
|
35
|
-
this.
|
|
46
|
+
onChangeTheme(cb: ThemeListener) {
|
|
47
|
+
this.themeListeners.add(cb)
|
|
36
48
|
return () => {
|
|
37
|
-
this.
|
|
49
|
+
this.themeListeners.delete(cb)
|
|
38
50
|
}
|
|
39
51
|
}
|
|
40
52
|
|
package/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class Variable {
|
|
|
11
11
|
val: string | number;
|
|
12
12
|
variable: string | number;
|
|
13
13
|
constructor({ val, name }: VariableIn);
|
|
14
|
+
toString(): string | number;
|
|
14
15
|
}
|
|
15
16
|
export declare type VariableIn = {
|
|
16
17
|
val: string | number;
|
|
@@ -85,7 +86,7 @@ export declare type Tokens = TamaguiConfig["tokens"];
|
|
|
85
86
|
export declare type Shorthands = TamaguiConfig["shorthands"];
|
|
86
87
|
export declare type Media = TamaguiConfig["media"];
|
|
87
88
|
export declare type Themes = TamaguiConfig["themes"];
|
|
88
|
-
export declare type ThemeName = keyof Themes extends `${infer Prefix}
|
|
89
|
+
export declare type ThemeName = keyof Themes extends `${infer Prefix}-${string}` ? Prefix | keyof Themes : keyof Themes;
|
|
89
90
|
export declare type ThemeKeys = keyof ThemeObject;
|
|
90
91
|
export declare type ThemeKeyVariables = `$${ThemeKeys}`;
|
|
91
92
|
export declare type TamaguiInternalConfig<A extends GenericTokens = GenericTokens, B extends GenericThemes = GenericThemes, C extends GenericShorthands = GenericShorthands, D extends GenericMedia = GenericMedia> = CreateTamaguiConfig<A, B, C, D> & {
|
|
@@ -96,6 +97,7 @@ export declare type TamaguiInternalConfig<A extends GenericTokens = GenericToken
|
|
|
96
97
|
tokensParsed: CreateTokens<Variable>;
|
|
97
98
|
themeConfig: any;
|
|
98
99
|
getCSS: () => string;
|
|
100
|
+
parsed: boolean;
|
|
99
101
|
};
|
|
100
102
|
export declare type UnionableString = string & {};
|
|
101
103
|
export declare type UnionableNumber = number & {};
|
|
@@ -197,7 +199,7 @@ export declare type TextProps = Omit<ReactTextProps, "style"> & TextStyleProps &
|
|
|
197
199
|
export declare type StaticComponent<Props = any, VariantProps = any, StaticConfParsed = StaticConfigParsed, ParentVariantProps = any> = React.FunctionComponent<Props> & {
|
|
198
200
|
staticConfig: StaticConfParsed;
|
|
199
201
|
variantProps?: VariantProps;
|
|
200
|
-
extractable: <X>(a: X) => X;
|
|
202
|
+
extractable: <X>(a: X, opts?: StaticConfig) => X;
|
|
201
203
|
};
|
|
202
204
|
export declare type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, "children">> & {
|
|
203
205
|
initialWindowMetrics?: any;
|
|
@@ -351,7 +353,7 @@ export declare type CreateTamaguiProps = TamaguiProviderProps & Omit<GenericTama
|
|
|
351
353
|
mediaQueryDefaultActive?: MediaQueryKey[];
|
|
352
354
|
};
|
|
353
355
|
export declare const getHasConfigured: () => boolean;
|
|
354
|
-
export declare const
|
|
356
|
+
export declare const getTamagui: () => TamaguiInternalConfig<CreateTokens, {
|
|
355
357
|
[key: string]: {
|
|
356
358
|
bg: string | Variable;
|
|
357
359
|
bg2: string | Variable;
|
|
@@ -371,6 +373,7 @@ export declare const getTamaguiConfig: () => TamaguiInternalConfig<CreateTokens,
|
|
|
371
373
|
[key: string]: string | number;
|
|
372
374
|
};
|
|
373
375
|
}>;
|
|
376
|
+
export declare const getTokens: () => CreateTokens;
|
|
374
377
|
export declare type ConfigListener = (conf: TamaguiInternalConfig) => void;
|
|
375
378
|
export declare const onConfiguredOnce: (cb: ConfigListener) => void;
|
|
376
379
|
export declare function createTamagui<Conf extends CreateTamaguiProps>(config: Conf): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D> ? TamaguiInternalConfig<A, B, C, D> : unknown;
|
|
@@ -491,6 +494,7 @@ export declare const themeable: ThemeableHOC;
|
|
|
491
494
|
export interface ThemeableHOC {
|
|
492
495
|
<R extends ReactElement<any, any> | null, P extends ThemeableProps = {}>(component: (props: P) => R): (props: P) => R;
|
|
493
496
|
}
|
|
497
|
+
export declare const isTamaguiElement: (child: any) => child is React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
494
498
|
export declare function useConstant<T>(fn: () => T): T;
|
|
495
499
|
export declare const mediaState: {
|
|
496
500
|
[key in keyof MediaQueryState]: boolean;
|
|
@@ -506,7 +510,9 @@ export declare const useMedia: () => {
|
|
|
506
510
|
[x: string]: boolean;
|
|
507
511
|
};
|
|
508
512
|
export declare function mediaObjectToString(query: string | MediaQueryObject): string;
|
|
509
|
-
export declare const useThemeName: (
|
|
513
|
+
export declare const useThemeName: (opts?: {
|
|
514
|
+
parent?: true | undefined;
|
|
515
|
+
} | undefined) => string;
|
|
510
516
|
export declare const useDefaultThemeName: () => string | number;
|
|
511
517
|
export declare const useTheme: () => {
|
|
512
518
|
bg: string | Variable;
|
|
@@ -549,9 +555,5 @@ export declare const ThemeInverse: (props: {
|
|
|
549
555
|
}) => JSX.Element;
|
|
550
556
|
export declare const TextAncestorContext: any;
|
|
551
557
|
export declare const TextAncestorProvider: (props: any) => any;
|
|
552
|
-
export declare const SafeAreaProvider: ({ initialWindowMetrics, children, }: {
|
|
553
|
-
children?: any;
|
|
554
|
-
initialWindowMetrics?: any;
|
|
555
|
-
}) => JSX.Element;
|
|
556
558
|
|
|
557
559
|
export {};
|
package/.ultra.cache.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"files":{"_":"1637340237894.082","dist":"1637479554052.672",".npmignore":"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391","package.json":"283138775b709bff32530d60d6fbe362223dbac3.1637715076897.096","src/constants/constants.ts":"557e9930ddfa8fad6d74219ae7245c80551b8794","src/constants/platform.ts":"3cd2086a6748b8b59258e2a6885d5f50e2349415","src/constants/pseudos.ts":"52c7655f92eaa265601eaf4a31b6db1688875321","src/constants/rnw.tsx":"ebc4ce292c30d344945b75e151a272023461f784","src/createComponent.tsx":"ee4ac47abc4cce2e59dc5b8438531e48b21395d1.1637715058902.1707","src/createFont.ts":"819966bc37e24da3fe2d8c06a68520f0fe5d125e","src/createShorthands.ts":"7b5ce250bc5d049fcf9f5898efc60fdc91f2988d","src/createTamagui.ts":"6e79d67d36eac7a4f5edc8b97e3914eea89ee593","src/createTheme.ts":"aa9b7c08901c1dff621a371912f3cbf1c2507301","src/createTokens.ts":"e5b1ac5cc0a68ca0ec3753a1a0bd5a4af9b825b3","src/createVariable.ts":"da248891d943b04d940205762b1239751af6c7cc","src/helpers/addStylesUsingClassname.tsx":"eab83e8172210b5cea57a408f13cd20e6152d752","src/helpers/createMediaStyle.ts":"3c5ff33628b5cc8de55bdcedc3133b968b5fb210","src/helpers/createPropMapper.ts":"8c4cad2720fd04054a1bea055b674017ba4b0a22","src/helpers/createTamaguiProvider.tsx":"2b6006e2bf3140184789a8f13d3e138ebc22d7b7","src/helpers/extendStaticConfig.ts":"7402dca37f1de440471e3ac83ca6ab8eb4373dc3","src/helpers/fixNativeShadow.native.tsx":"ff1ed30ed9ace81433046e719939a04190b477cc","src/helpers/fixNativeShadow.tsx":"7fb6e7d9604025d2023469f23aab7280244bbb03","src/helpers/getSplitStyles.tsx":"fa6ce2cb0449918a575f02ac179d83de3637c0c6","src/helpers/getStylesAtomic.native.ts":"9054085df65d873432d974b369ac9dcb80f387ff","src/helpers/getStylesAtomic.ts":"e85e8ae07227d5b05f0f1aad7fae77b40e30c09d","src/helpers/insertStyleRule.tsx":"2fe177cb7efe1b2fb5b38c57835a6a3ea5e35443","src/helpers/isObj.ts":"8243865ff1705b549e1a10b398f45048709e2360","src/helpers/matchMedia.native.ts":"7e28a480a564ba5d341d5d559cf1ddcaf5f0b76b","src/helpers/matchMedia.ts":"071b4358b4a141c8f55645e478af1e2527e88b67","src/helpers/themeable.tsx":"16e605a7ae27cec3e4d725817370ac3c250c52a4","src/hooks/useConstant.tsx":"f23ca6031dd13f73f4c5eb7089b5745dc2cdaedd","src/hooks/useFeatures.tsx":"3b917df55d6478ef6f3b9c21d7bef3e5bdcefe1b","src/hooks/useForceUpdate.tsx":"bd991b41de300151e93b2d7e8cdca6a0accefacc.del","src/hooks/useMedia.tsx":"c50e9180f17ef1839875869eef071bf8a7965dae.1637715114550.5386","src/hooks/usePressable.tsx":"4f55bdca7250e2d22d88f3578d8c8e62ce5c8453","src/hooks/useTheme.tsx":"9c11c3a5da0844cfb93ccbbfa861aedbe10b2552.1637715119545.828","src/index.ts":"9799059148a6bf1c14fd61120145f10cc40b1fcd.1637715104671.6792","src/static.ts":"8023a4f2d9ee432df4084cc69260c01892f6dff8","src/static/postProcessStyles.tsx":"5e5579249eb99caab9f406af6ec801b7ff1db830","src/styled.ts":"6ccd48505b8118ac393344f475084c528ab83c94","src/types.tsx":"a80d45d21a1b69e54d00226b8f9f1f5de945f1cd","src/views/Animated.tsx":"eac498149091b087c84a5d92c4a9b57bafd6c149","src/views/SafeAreaProvider.tsx":"501c04bc1cb00c2a70ab4f13c5d9510b1f9245b8","src/views/Stack.tsx":"62ef6b9307bb434ad08f4ab7f3f6d0ccb975a359","src/views/Text.tsx":"476bdde93a89840681bf981cfc06e10fc0bc837d","src/views/TextAncestorContext.tsx":"73b13b84778bddb2b4198d32daf1de668132b0bb","src/views/Theme.tsx":"4e9357aac5fc201f2dc359a8f6fd4a8581ceb9bf","src/views/ThemeContext.tsx":"788e2d26d8727dd9493944b5ae9c7ea241fd7ed4","src/views/ThemeInverse.tsx":"614b626451a57955e896cc709d28043bc9bbf391","src/views/ThemeManagerContext.tsx":"30f5f195c2d4b326c5b44f587ff88a1dd1a848ff","src/views/ThemeProvider.tsx":"dcdd80d625e61e9598baf4cb10fc7921962efb50","tsconfig.json":"d3effa0a1380f9664793b92aefd77a1bc96ce071","types.d.ts":"ae74d3379aca7fc09fafc830bdbbc644fb099553.1637715149729.388"},"deps":{"@tamagui/helpers":1637715147144.1548,"@tamagui/use-debounce":1637715147093.4219,"@tamagui/use-force-update":1637715147090.168,"@tamagui/build":1637715143424.1582}}
|
package/_/constants/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isWeb } from "./platform";
|
|
2
|
-
const stackDefaultStyles = {
|
|
3
|
-
alignItems: "stretch",
|
|
4
|
-
flexShrink: 0,
|
|
5
|
-
...isWeb && {
|
|
6
|
-
display: "flex",
|
|
7
|
-
flexBasis: "auto",
|
|
8
|
-
boxSizing: "border-box"
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
stackDefaultStyles
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=constants.js.map
|
package/_/constants/platform.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import { useEffect, useLayoutEffect } from "react";
|
|
3
|
-
import { Platform } from "react-native";
|
|
4
|
-
const isWeb = process.env.TAMAGUI_TARGET === "web" || ((_a = Platform) == null ? void 0 : _a.OS) === "web";
|
|
5
|
-
const isSSR = isWeb && typeof window === "undefined";
|
|
6
|
-
const useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect;
|
|
7
|
-
const isChrome = typeof navigator !== "undefined" && /Chrome/.test(navigator.userAgent || "");
|
|
8
|
-
const supportsTouchWeb = typeof window !== "undefined" && "ontouchstart" in window;
|
|
9
|
-
const isTouchDevice = !isWeb || supportsTouchWeb;
|
|
10
|
-
const isWebIOS = isWeb && typeof navigator !== "undefined" && (/iPad|iPhone|iPod/.test(navigator.platform) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) && !window["MSStream"];
|
|
11
|
-
export {
|
|
12
|
-
isChrome,
|
|
13
|
-
isSSR,
|
|
14
|
-
isTouchDevice,
|
|
15
|
-
isWeb,
|
|
16
|
-
isWebIOS,
|
|
17
|
-
supportsTouchWeb,
|
|
18
|
-
useIsomorphicLayoutEffect
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=platform.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/constants/platform.ts"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useLayoutEffect } from 'react'\nimport { Platform } from 'react-native'\n\nexport const isWeb = process.env.TAMAGUI_TARGET === 'web' || Platform?.OS === 'web'\nexport const isSSR = isWeb && typeof window === 'undefined'\nexport const useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect\nexport const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent || '')\nexport const supportsTouchWeb = typeof window !== 'undefined' && 'ontouchstart' in window\nexport const isTouchDevice = !isWeb || supportsTouchWeb\nexport const isWebIOS =\n isWeb &&\n typeof navigator !== 'undefined' &&\n (/iPad|iPhone|iPod/.test(navigator.platform) ||\n (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&\n !window['MSStream']\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA;AACA;AAEO,MAAM,QAAQ,QAAQ,IAAI,mBAAmB,SAAS,uCAAU,QAAO;AACvE,MAAM,QAAQ,SAAS,OAAO,WAAW;AACzC,MAAM,4BAA4B,QAAQ,YAAY;AACtD,MAAM,WAAW,OAAO,cAAc,eAAe,SAAS,KAAK,UAAU,aAAa;AAC1F,MAAM,mBAAmB,OAAO,WAAW,eAAe,kBAAkB;AAC5E,MAAM,gBAAgB,CAAC,SAAS;AAChC,MAAM,WACX,SACA,OAAO,cAAc,eACpB,oBAAmB,KAAK,UAAU,aAChC,UAAU,aAAa,cAAc,UAAU,iBAAiB,MACnE,CAAC,OAAO;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/_/constants/pseudos.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const pseudos = {
|
|
2
|
-
focusStyle: {
|
|
3
|
-
name: "focus",
|
|
4
|
-
priority: 3
|
|
5
|
-
},
|
|
6
|
-
pressStyle: {
|
|
7
|
-
name: "active",
|
|
8
|
-
priority: 2
|
|
9
|
-
},
|
|
10
|
-
hoverStyle: {
|
|
11
|
-
name: "hover",
|
|
12
|
-
priority: 1
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export {
|
|
16
|
-
pseudos
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=pseudos.js.map
|