@tamagui/core 1.0.1-beta.167 → 1.0.1-beta.168
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/addTheme.js.map +1 -1
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/constants/platform.js +4 -4
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/platform.native.js +3 -3
- package/dist/cjs/constants/platform.native.js.map +2 -2
- package/dist/cjs/createComponent.js +4 -2
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +1 -4
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +16 -9
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getThemeCSSRules.js.map +1 -1
- package/dist/cjs/hooks/useIsSSR.js +8 -4
- package/dist/cjs/hooks/useIsSSR.js.map +2 -2
- package/dist/cjs/hooks/useIsTouchDevice.js +1 -1
- package/dist/cjs/hooks/useIsTouchDevice.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +48 -29
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +1 -1
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/styled.js +11 -8
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/updateTheme.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js +2 -2
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/addTheme.js.map +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/constants/platform.js +3 -3
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/platform.native.js +2 -2
- package/dist/esm/constants/platform.native.js.map +2 -2
- package/dist/esm/createComponent.js +4 -2
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +1 -4
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +16 -9
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getThemeCSSRules.js.map +1 -1
- package/dist/esm/hooks/useIsSSR.js +9 -5
- package/dist/esm/hooks/useIsSSR.js.map +2 -2
- package/dist/esm/hooks/useIsTouchDevice.js +2 -2
- package/dist/esm/hooks/useIsTouchDevice.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +49 -30
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +2 -2
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/styled.js +11 -8
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/updateTheme.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +3 -3
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/package.json +10 -10
- package/src/addTheme.ts +3 -3
- package/src/config.ts +1 -1
- package/src/constants/platform.native.ts +1 -1
- package/src/constants/platform.ts +2 -2
- package/src/createComponent.tsx +10 -2
- package/src/createTamagui.ts +7 -10
- package/src/helpers/ThemeManager.tsx +4 -4
- package/src/helpers/getSplitStyles.tsx +25 -12
- package/src/helpers/getThemeCSSRules.ts +2 -2
- package/src/hooks/useIsSSR.tsx +10 -5
- package/src/hooks/useIsTouchDevice.tsx +2 -2
- package/src/hooks/useMedia.tsx +65 -36
- package/src/hooks/useTheme.tsx +6 -6
- package/src/styled.tsx +14 -8
- package/src/types.tsx +40 -12
- package/src/updateTheme.ts +2 -2
- package/src/views/TamaguiProvider.tsx +3 -4
- package/types/addTheme.d.ts +2 -2
- package/types/config.d.ts +18 -2
- package/types/constants/platform.d.ts +1 -1
- package/types/constants/platform.native.d.ts +1 -1
- package/types/createVariable.d.ts +4 -0
- package/types/helpers/ThemeManager.d.ts +5 -5
- package/types/helpers/calc.d.ts +5 -0
- package/types/helpers/expandStyle.d.ts +4 -0
- package/types/helpers/expandStyles.d.ts +7 -0
- package/types/helpers/getSplitStyles.d.ts +3 -3
- package/types/helpers/getStylesAtomic.d.ts +4 -0
- package/types/helpers/getThemeCSSRules.d.ts +2 -2
- package/types/helpers/mergeProps.d.ts +13 -0
- package/types/helpers/normalizeValueWithProperty.d.ts +4 -0
- package/types/hooks/useIsSSR.d.ts +3 -1
- package/types/hooks/useMedia.d.ts +3 -3
- package/types/hooks/useTheme.d.ts +4 -4
- package/types/insertFont.d.ts +3 -0
- package/types/styled.d.ts +1 -0
- package/types/types.d.ts +110 -11
- package/types/updateTheme.d.ts +2 -2
package/src/hooks/useMedia.tsx
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
4
4
|
import { matchMedia } from '../helpers/matchMedia'
|
|
5
5
|
import {
|
|
6
|
-
ConfigureMediaQueryOptions,
|
|
7
6
|
MediaQueries,
|
|
8
7
|
MediaQueryKey,
|
|
9
8
|
MediaQueryObject,
|
|
10
9
|
MediaQueryState,
|
|
10
|
+
TamaguiInternalConfig,
|
|
11
11
|
} from '../types'
|
|
12
12
|
import { useSafeRef } from './useSafeRef'
|
|
13
13
|
|
|
14
|
-
export const mediaState: MediaQueryState =
|
|
14
|
+
export const mediaState: MediaQueryState =
|
|
15
|
+
// development time safeguard
|
|
16
|
+
process.env.NODE_ENV === 'development'
|
|
17
|
+
? new Proxy(
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
get(target, key) {
|
|
21
|
+
if (typeof key === 'string' && key[0] === '$') {
|
|
22
|
+
throw new Error(`Access of mediaState should never include $`)
|
|
23
|
+
}
|
|
24
|
+
return Reflect.get(target, key)
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
: ({} as any)
|
|
29
|
+
|
|
15
30
|
const mediaQueryListeners: { [key: string]: Set<Function> } = {}
|
|
16
31
|
|
|
17
32
|
export function addMediaQueryListener(key: MediaQueryKey, cb: any) {
|
|
33
|
+
if (process.env.NODE_ENV === 'development' && key[0] === '$') {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.warn(`Warning, listening to media queries shouldn't use the "$" prefix`)
|
|
36
|
+
}
|
|
18
37
|
mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()
|
|
19
38
|
mediaQueryListeners[key].add(cb)
|
|
20
39
|
return () => removeMediaQueryListener(key, cb)
|
|
@@ -35,29 +54,17 @@ const dispose = new Set<Function>()
|
|
|
35
54
|
// for SSR capture it at time of startup
|
|
36
55
|
let initialMediaState: MediaQueryState | null
|
|
37
56
|
|
|
38
|
-
export const configureMedia = ({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// support hot reload
|
|
45
|
-
if (initialMediaState) {
|
|
46
|
-
if (process.env.NODE_ENV === 'development') {
|
|
47
|
-
if (JSON.stringify(queries) === JSON.stringify(mediaQueryConfig)) {
|
|
48
|
-
// hmr avoid update
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
setupMediaListeners()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
Object.assign(mediaQueryConfig, queries)
|
|
56
|
-
// start in the initial state
|
|
57
|
-
for (const key in queries) {
|
|
58
|
-
mediaState[key] = defaultActive[key] || false
|
|
57
|
+
export const configureMedia = (config: TamaguiInternalConfig) => {
|
|
58
|
+
const { media, mediaQueryDefaultActive } = config
|
|
59
|
+
if (!media) return
|
|
60
|
+
for (const key in media) {
|
|
61
|
+
mediaState[key] = mediaQueryDefaultActive?.[key] || false
|
|
59
62
|
}
|
|
63
|
+
Object.assign(mediaQueryConfig, media)
|
|
60
64
|
initialMediaState = { ...mediaState }
|
|
65
|
+
if (config.disableSSR) {
|
|
66
|
+
setupMediaListeners()
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
function unlisten() {
|
|
@@ -65,7 +72,20 @@ function unlisten() {
|
|
|
65
72
|
dispose.clear()
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Note: This should *not* set the state on the first render!
|
|
77
|
+
* Because to avoid hydration issues SSR must match the server
|
|
78
|
+
* *and then* re-render with the actual media query state.
|
|
79
|
+
*/
|
|
80
|
+
let configuredKey = ''
|
|
68
81
|
function setupMediaListeners() {
|
|
82
|
+
// avoid setting up more than once per config
|
|
83
|
+
const nextKey = JSON.stringify(mediaQueryConfig)
|
|
84
|
+
if (nextKey === configuredKey) {
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
configuredKey = nextKey
|
|
88
|
+
|
|
69
89
|
// hmr, undo existing before re-binding
|
|
70
90
|
unlisten()
|
|
71
91
|
|
|
@@ -79,6 +99,7 @@ function setupMediaListeners() {
|
|
|
79
99
|
// react native needs these deprecated apis for now
|
|
80
100
|
match.addListener(update)
|
|
81
101
|
dispose.add(() => match.removeListener(update))
|
|
102
|
+
|
|
82
103
|
update()
|
|
83
104
|
|
|
84
105
|
function update() {
|
|
@@ -87,16 +108,18 @@ function setupMediaListeners() {
|
|
|
87
108
|
mediaState[key] = next
|
|
88
109
|
const listeners = mediaQueryListeners[key]
|
|
89
110
|
if (listeners?.size) {
|
|
90
|
-
|
|
91
|
-
cb()
|
|
92
|
-
}
|
|
111
|
+
listeners.forEach((cb) => cb())
|
|
93
112
|
}
|
|
94
113
|
}
|
|
95
114
|
}
|
|
96
115
|
}
|
|
97
116
|
|
|
98
|
-
export function useMediaQueryListeners() {
|
|
99
|
-
|
|
117
|
+
export function useMediaQueryListeners(config: TamaguiInternalConfig) {
|
|
118
|
+
if (config.disableSSR) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
100
123
|
setupMediaListeners()
|
|
101
124
|
return unlisten
|
|
102
125
|
}, [])
|
|
@@ -105,7 +128,7 @@ export function useMediaQueryListeners() {
|
|
|
105
128
|
export function useMedia(): {
|
|
106
129
|
[key in MediaQueryKey]: boolean
|
|
107
130
|
} {
|
|
108
|
-
const [state, setState] = useState(initialMediaState
|
|
131
|
+
const [state, setState] = useState(initialMediaState || {})
|
|
109
132
|
const keys = useSafeRef({} as Record<string, boolean>)
|
|
110
133
|
|
|
111
134
|
function updateState() {
|
|
@@ -120,13 +143,12 @@ export function useMedia(): {
|
|
|
120
143
|
}
|
|
121
144
|
|
|
122
145
|
useIsomorphicLayoutEffect(() => {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
146
|
+
const disposes: Function[] = Object.keys(keys.current).map((key) =>
|
|
147
|
+
addMediaQueryListener(key, updateState)
|
|
148
|
+
)
|
|
127
149
|
updateState()
|
|
128
150
|
return () => {
|
|
129
|
-
|
|
151
|
+
disposes.forEach((cb) => cb())
|
|
130
152
|
}
|
|
131
153
|
})
|
|
132
154
|
|
|
@@ -134,8 +156,15 @@ export function useMedia(): {
|
|
|
134
156
|
() =>
|
|
135
157
|
new Proxy(state, {
|
|
136
158
|
get(_, key: string) {
|
|
159
|
+
if (process.env.NODE_ENV === 'development') {
|
|
160
|
+
if (!initialMediaState) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`To use useMedia() you must pass in media configuration to createTamagui, none was found.`
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
137
166
|
if (!keys.current[key]) {
|
|
138
|
-
keys.current
|
|
167
|
+
keys.current[key] = true
|
|
139
168
|
}
|
|
140
169
|
return Reflect.get(state, key)
|
|
141
170
|
},
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'r
|
|
|
3
3
|
|
|
4
4
|
import { getConfig } from '../config'
|
|
5
5
|
import { isDevTools } from '../constants/isDevTools'
|
|
6
|
-
import { isRSC,
|
|
6
|
+
import { isRSC, isServer, useIsomorphicLayoutEffect } from '../constants/platform'
|
|
7
7
|
import { ThemeContext } from '../contexts/ThemeContext'
|
|
8
8
|
import { areEqualSets } from '../helpers/areEqualSets'
|
|
9
9
|
import {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
ThemeManagerContext,
|
|
13
13
|
emptyManager,
|
|
14
14
|
} from '../helpers/ThemeManager'
|
|
15
|
-
import { ThemeName,
|
|
15
|
+
import { ThemeName, ThemeParsed } from '../types'
|
|
16
16
|
import { GetThemeUnwrapped } from './getThemeUnwrapped'
|
|
17
17
|
import { useConstant } from './useConstant'
|
|
18
18
|
import { useServerRef } from './useServerHooks'
|
|
@@ -38,7 +38,7 @@ export const useTheme = (
|
|
|
38
38
|
componentName?: string,
|
|
39
39
|
props?: ThemeProps,
|
|
40
40
|
forceUpdate?: any
|
|
41
|
-
):
|
|
41
|
+
): ThemeParsed => {
|
|
42
42
|
// TODO this can use useChangeThemeEffect almost ready
|
|
43
43
|
if (isRSC) {
|
|
44
44
|
const config = getConfig()
|
|
@@ -195,10 +195,10 @@ export const useChangeThemeEffect = (
|
|
|
195
195
|
forceUpdateProp?: any,
|
|
196
196
|
uuid?: Object
|
|
197
197
|
): {
|
|
198
|
-
themes: Record<string,
|
|
198
|
+
themes: Record<string, ThemeParsed>
|
|
199
199
|
themeManager: ThemeManager | null
|
|
200
200
|
name: string
|
|
201
|
-
theme:
|
|
201
|
+
theme: ThemeParsed | null
|
|
202
202
|
className?: string
|
|
203
203
|
} => {
|
|
204
204
|
const { themes } = getConfig()
|
|
@@ -236,7 +236,7 @@ export const useChangeThemeEffect = (
|
|
|
236
236
|
return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)
|
|
237
237
|
})
|
|
238
238
|
|
|
239
|
-
if (!
|
|
239
|
+
if (!isServer) {
|
|
240
240
|
useLayoutEffect(() => {
|
|
241
241
|
themeManager.update(next)
|
|
242
242
|
|
package/src/styled.tsx
CHANGED
|
@@ -48,6 +48,7 @@ export function styled<
|
|
|
48
48
|
variants?: Variants | undefined
|
|
49
49
|
// thought i had this typed, but can't get it linked
|
|
50
50
|
defaultVariants?: { [key: string]: any }
|
|
51
|
+
acceptsClassName?: boolean
|
|
51
52
|
},
|
|
52
53
|
staticExtractionOptions?: Partial<StaticConfig>
|
|
53
54
|
) {
|
|
@@ -73,7 +74,13 @@ export function styled<
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
if (options) {
|
|
76
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
variants,
|
|
79
|
+
name,
|
|
80
|
+
defaultVariants,
|
|
81
|
+
acceptsClassName: acceptsClassNameProp,
|
|
82
|
+
...defaultProps
|
|
83
|
+
} = options
|
|
77
84
|
if (defaultVariants) {
|
|
78
85
|
Object.assign(defaultProps, defaultVariants)
|
|
79
86
|
}
|
|
@@ -84,12 +91,7 @@ export function styled<
|
|
|
84
91
|
RNComponents.add(Component)
|
|
85
92
|
isReactNativeWeb = true
|
|
86
93
|
} else {
|
|
87
|
-
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
console.warn(
|
|
90
|
-
`Invalid styled() component: Tamagui only accepts react-native Text, View, Image, TextInput, or another styled Tamagui view`
|
|
91
|
-
)
|
|
92
|
-
}
|
|
94
|
+
// assuming some sort of non-tamagui non-rn view, will always use style={}
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
const reactNativeWebComponent = isReactNativeWeb
|
|
@@ -107,6 +109,8 @@ export function styled<
|
|
|
107
109
|
isInput || staticExtractionOptions?.isText || parentStaticConfig?.isText || Comp === Text
|
|
108
110
|
)
|
|
109
111
|
|
|
112
|
+
const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNativeWeb)
|
|
113
|
+
|
|
110
114
|
const conf: Partial<StaticConfig> = {
|
|
111
115
|
...staticExtractionOptions,
|
|
112
116
|
...(!isTamagui && {
|
|
@@ -125,10 +129,12 @@ export function styled<
|
|
|
125
129
|
isInput,
|
|
126
130
|
isText,
|
|
127
131
|
isImage,
|
|
132
|
+
acceptsClassName,
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
// TODO compiler doesn't have logic to include children, de-opt (see EnsureFlexed for test usage)
|
|
131
|
-
|
|
136
|
+
// bail on non className views as well
|
|
137
|
+
if (defaultProps.children || !acceptsClassName) {
|
|
132
138
|
conf.neverFlatten = true
|
|
133
139
|
}
|
|
134
140
|
|
package/src/types.tsx
CHANGED
|
@@ -162,7 +162,12 @@ export type CreateTamaguiConfig<
|
|
|
162
162
|
fonts: RemoveLanguagePostfixes<F>
|
|
163
163
|
fontLanguages: GetLanguagePostfixes<F> extends never ? string[] : GetLanguagePostfixes<F>[]
|
|
164
164
|
tokens: A
|
|
165
|
-
|
|
165
|
+
// parsed
|
|
166
|
+
themes: {
|
|
167
|
+
[Name in keyof B]: {
|
|
168
|
+
[Key in keyof B[Name]]: Variable
|
|
169
|
+
}
|
|
170
|
+
}
|
|
166
171
|
shorthands: C
|
|
167
172
|
media: D
|
|
168
173
|
animations: AnimationDriver<E>
|
|
@@ -230,13 +235,16 @@ export type GenericTamaguiConfig = CreateTamaguiConfig<
|
|
|
230
235
|
>
|
|
231
236
|
|
|
232
237
|
// since TamaguiConfig will be re-declared, these will all be typed globally
|
|
233
|
-
export type
|
|
238
|
+
export type ThemeDefinition = TamaguiConfig['themes'][keyof TamaguiConfig['themes']]
|
|
239
|
+
export type ThemeKeys = keyof ThemeDefinition
|
|
240
|
+
export type ThemeParsed = {
|
|
241
|
+
[key in ThemeKeys]: Variable
|
|
242
|
+
}
|
|
234
243
|
export type Tokens = TamaguiConfig['tokens']
|
|
235
244
|
export type Shorthands = TamaguiConfig['shorthands']
|
|
236
245
|
export type Media = TamaguiConfig['media']
|
|
237
246
|
export type Themes = TamaguiConfig['themes']
|
|
238
247
|
export type ThemeName = GetAltThemeNames<keyof Themes>
|
|
239
|
-
export type ThemeKeys = keyof ThemeObject
|
|
240
248
|
export type ThemeTokens = `$${ThemeKeys}`
|
|
241
249
|
export type AnimationKeys = Omit<GetAnimationKeys<TamaguiConfig>, number>
|
|
242
250
|
export type FontLanguages = ArrayIntersection<TamaguiConfig['fontLanguages']>
|
|
@@ -264,6 +272,26 @@ export type CreateTamaguiProps = {
|
|
|
264
272
|
}
|
|
265
273
|
|
|
266
274
|
defaultTheme?: string
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* *Advanced use case* For all CSS extracted views, this has no effect.
|
|
278
|
+
*
|
|
279
|
+
* For SSR compatibility on the web, Tamagui will render once with the settings
|
|
280
|
+
* from `mediaQueryDefaultActive` set for all media queries. Then, it will render
|
|
281
|
+
* again after the initial render using the proper media query values. This is so that
|
|
282
|
+
* hydration will match perfectly with the server.
|
|
283
|
+
*
|
|
284
|
+
* Setting disableSSR will avoid this second render by setting the media query state
|
|
285
|
+
* to the actual browser dimensions on initial load. This is only useful for client-only
|
|
286
|
+
* apps.
|
|
287
|
+
*
|
|
288
|
+
*/
|
|
289
|
+
disableSSR?: boolean
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Disable inserting a theme class in the DOM or context, allowing you to manually place it higher.
|
|
293
|
+
* For custom use cases like integration with next-theme.
|
|
294
|
+
*/
|
|
267
295
|
disableRootThemeClass?: boolean
|
|
268
296
|
|
|
269
297
|
defaultProps?: Record<string, any> & {
|
|
@@ -314,9 +342,6 @@ export type TamaguiInternalConfig<
|
|
|
314
342
|
getCSS: () => string
|
|
315
343
|
parsed: boolean
|
|
316
344
|
inverseShorthands: Record<string, string>
|
|
317
|
-
|
|
318
|
-
// just passed in from CreateTamaguiProps
|
|
319
|
-
themeClassNameOnRoot?: boolean
|
|
320
345
|
}
|
|
321
346
|
|
|
322
347
|
export type GetAnimationKeys<A extends GenericTamaguiConfig> = keyof A['animations']['animations']
|
|
@@ -352,10 +377,6 @@ export type MediaProps<A> = {
|
|
|
352
377
|
export type MediaQueries = {
|
|
353
378
|
[key in MediaQueryKey]: MediaQueryObject
|
|
354
379
|
}
|
|
355
|
-
export type ConfigureMediaQueryOptions = {
|
|
356
|
-
queries?: MediaQueries
|
|
357
|
-
defaultActive?: Record<MediaQueryKey, boolean>
|
|
358
|
-
}
|
|
359
380
|
|
|
360
381
|
export type TransformStyleProps = {
|
|
361
382
|
x?: number
|
|
@@ -423,7 +444,7 @@ export type SizeTokens = GetTokenString<keyof Tokens['size']> | number
|
|
|
423
444
|
export type SpaceTokens = GetTokenString<keyof Tokens['space']> | number | boolean
|
|
424
445
|
export type ColorTokens =
|
|
425
446
|
| GetTokenString<keyof Tokens['color']>
|
|
426
|
-
| GetTokenString<keyof
|
|
447
|
+
| GetTokenString<keyof ThemeParsed>
|
|
427
448
|
| CSSColorNames
|
|
428
449
|
export type ZIndexTokens = GetTokenString<keyof Tokens['zIndex']> | number
|
|
429
450
|
export type RadiusTokens = GetTokenString<keyof Tokens['radius']> | number
|
|
@@ -640,7 +661,7 @@ export type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, 'children'>>
|
|
|
640
661
|
export type PropMapper = (
|
|
641
662
|
key: string,
|
|
642
663
|
value: any,
|
|
643
|
-
theme:
|
|
664
|
+
theme: ThemeParsed,
|
|
644
665
|
props: Record<string, any>,
|
|
645
666
|
state: Partial<SplitStyleState>,
|
|
646
667
|
languageContext?: FontLanguageProps,
|
|
@@ -773,6 +794,13 @@ export type StaticConfig = {
|
|
|
773
794
|
* Used insternally to attach default props to names
|
|
774
795
|
*/
|
|
775
796
|
parentNames?: string[]
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* By default if styled() doesn't recognize a parent Tamagui compoent or specific react-native views,
|
|
800
|
+
* it will assume the passed in component only accepts style={} for react-native compatibility.
|
|
801
|
+
* Setting `acceptsClassName: true` indicates Tamagui can pass in className props.
|
|
802
|
+
*/
|
|
803
|
+
acceptsClassName?: boolean
|
|
776
804
|
}
|
|
777
805
|
|
|
778
806
|
/**
|
package/src/updateTheme.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { addTheme } from './addTheme'
|
|
2
2
|
import { activeThemeManagers } from './hooks/useTheme'
|
|
3
|
-
import {
|
|
3
|
+
import { ThemeDefinition } from './types'
|
|
4
4
|
|
|
5
|
-
export function updateTheme({ name, theme }: { name: string; theme:
|
|
5
|
+
export function updateTheme({ name, theme }: { name: string; theme: ThemeDefinition }) {
|
|
6
6
|
const next = addTheme({ name, theme, insertCSS: true, update: true })
|
|
7
7
|
|
|
8
8
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
1
|
import * as React from 'react'
|
|
3
2
|
|
|
4
|
-
import { isClient, isRSC,
|
|
3
|
+
import { isClient, isRSC, isServer } from '../constants/platform'
|
|
5
4
|
import { ButtonInsideButtonContext } from '../contexts/ButtonInsideButtonContext'
|
|
6
5
|
import { TextAncestorProvider } from '../contexts/TextAncestorContext'
|
|
7
6
|
import { useMediaQueryListeners } from '../hooks/useMedia'
|
|
@@ -22,8 +21,8 @@ export function TamaguiProvider({
|
|
|
22
21
|
)
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
if (!
|
|
26
|
-
useMediaQueryListeners()
|
|
24
|
+
if (!isServer) {
|
|
25
|
+
useMediaQueryListeners(config)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
if (isClient) {
|
package/types/addTheme.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeDefinition } from './types';
|
|
2
2
|
export declare function addTheme({ name: themeName, theme: themeIn, insertCSS, update, }: {
|
|
3
3
|
name: string;
|
|
4
|
-
theme:
|
|
4
|
+
theme: ThemeDefinition;
|
|
5
5
|
insertCSS?: boolean;
|
|
6
6
|
update?: boolean;
|
|
7
7
|
}): {
|
package/types/config.d.ts
CHANGED
|
@@ -17,8 +17,24 @@ export declare const getConfig: () => TamaguiInternalConfig<import("./types").Cr
|
|
|
17
17
|
}, import("./types").GenericFonts>;
|
|
18
18
|
export declare const getTokens: () => import("./types").CreateTokens<import("./createVariable").Variable<import("./createVariable").VariableValue>>;
|
|
19
19
|
export declare const getThemes: () => {
|
|
20
|
-
[
|
|
21
|
-
[
|
|
20
|
+
[x: string]: {
|
|
21
|
+
[x: string]: import("./createVariable").Variable<import("./createVariable").VariableValue>;
|
|
22
|
+
background?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
23
|
+
backgroundHover?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
24
|
+
backgroundPress?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
25
|
+
backgroundFocus?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
26
|
+
color?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
27
|
+
colorHover?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
28
|
+
colorPress?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
29
|
+
colorFocus?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
30
|
+
borderColor?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
31
|
+
borderColorHover?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
32
|
+
borderColorPress?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
33
|
+
borderColorFocus?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
34
|
+
shadowColor?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
35
|
+
shadowColorHover?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
36
|
+
shadowColorPress?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
37
|
+
shadowColorFocus?: import("./createVariable").Variable<import("./createVariable").VariableValue> | undefined;
|
|
22
38
|
};
|
|
23
39
|
};
|
|
24
40
|
export declare const configListeners: Set<ConfigListener>;
|
|
@@ -3,7 +3,7 @@ export declare const isAndroid: boolean;
|
|
|
3
3
|
export declare const isIOS: boolean;
|
|
4
4
|
export declare const isWeb: boolean;
|
|
5
5
|
export declare const isWindowDefined: boolean;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const isServer: boolean;
|
|
7
7
|
export declare const isClient: boolean;
|
|
8
8
|
export declare const isRSC: any;
|
|
9
9
|
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
@@ -3,7 +3,7 @@ export declare const isAndroid: boolean;
|
|
|
3
3
|
export declare const isIOS: boolean;
|
|
4
4
|
export declare const isWeb = false;
|
|
5
5
|
export declare const isWindowDefined = false;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const isServer = false;
|
|
7
7
|
export declare const isClient = false;
|
|
8
8
|
export declare const isRSC = false;
|
|
9
9
|
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ThemeParsed, Themes } from '../types';
|
|
3
3
|
declare type ThemeListener = (name: string | null, themeManager: ThemeManager) => void;
|
|
4
4
|
export declare type SetActiveThemeProps = {
|
|
5
5
|
className?: string;
|
|
@@ -16,22 +16,22 @@ export declare type GetNextThemeProps = {
|
|
|
16
16
|
export declare class ThemeManager {
|
|
17
17
|
name: string;
|
|
18
18
|
className: string;
|
|
19
|
-
theme:
|
|
19
|
+
theme: ThemeParsed | null;
|
|
20
20
|
parentManager: ThemeManager | null;
|
|
21
21
|
reset: boolean;
|
|
22
22
|
keys: Map<any, Set<string>>;
|
|
23
23
|
listeners: Map<any, Function>;
|
|
24
24
|
themeListeners: Set<ThemeListener>;
|
|
25
|
-
constructor(name?: string, className?: string, theme?:
|
|
25
|
+
constructor(name?: string, className?: string, theme?: ThemeParsed | null, parentManager?: ThemeManager | null, reset?: boolean);
|
|
26
26
|
get didChangeTheme(): boolean | null;
|
|
27
27
|
get parentName(): string | null;
|
|
28
28
|
get fullName(): string;
|
|
29
|
-
getValue(key: string): import("
|
|
29
|
+
getValue(key: string): import("..").Variable<import("..").VariableValue> | undefined;
|
|
30
30
|
isTracking(uuid: Object): boolean;
|
|
31
31
|
update({ name, theme, className }?: SetActiveThemeProps, force?: boolean): boolean;
|
|
32
32
|
getNextTheme(props?: GetNextThemeProps, debug?: any): {
|
|
33
33
|
name: string;
|
|
34
|
-
theme:
|
|
34
|
+
theme: ThemeParsed | null;
|
|
35
35
|
className: string | undefined;
|
|
36
36
|
};
|
|
37
37
|
getClassName(name: string): string;
|
package/types/helpers/calc.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { FontLineHeightTokens, FontSizeTokens, SizeTokens, SpaceTokens } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Simple calc() that handles native + web
|
|
4
|
+
* on web: outputs a calc() string
|
|
5
|
+
* on native: outputs a plain number
|
|
6
|
+
*/
|
|
2
7
|
export declare type CalcVal = string | number | SizeTokens | SpaceTokens | FontSizeTokens | FontLineHeightTokens;
|
|
3
8
|
declare const operators: {
|
|
4
9
|
'+': (a: number, b: number) => number;
|
|
@@ -2,6 +2,13 @@ export declare const defaultOffset: {
|
|
|
2
2
|
height: number;
|
|
3
3
|
width: number;
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* This is what you want to run before Object.assign() a style onto another.
|
|
7
|
+
* It does the following:
|
|
8
|
+
* 1. Turns user shorthands into longhands, ie px = paddingHorizontal
|
|
9
|
+
* 2. Normalizes various inconsistent styles to be more consistent
|
|
10
|
+
* 3. Expands react-native shorthands, ie paddingHorizontal => paddingLeft, paddingRight
|
|
11
|
+
*/
|
|
5
12
|
export declare function expandStyles(style: Record<string, any>, config?: import("..").TamaguiInternalConfig<import("..").CreateTokens<import("..").VariableVal>, {
|
|
6
13
|
[key: string]: Partial<import("..").TamaguiBaseTheme> & {
|
|
7
14
|
[key: string]: import("..").VariableVal;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViewStyle } from 'react-native';
|
|
2
|
-
import type { DebugProp, MediaQueryKey, PseudoStyles, SplitStyleState, StackProps, StaticConfigParsed, TamaguiInternalConfig,
|
|
2
|
+
import type { DebugProp, MediaQueryKey, PseudoStyles, SplitStyleState, StackProps, StaticConfigParsed, TamaguiInternalConfig, ThemeParsed } from '../types';
|
|
3
3
|
import { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types';
|
|
4
4
|
import { RulesToInsert } from './insertStyleRule';
|
|
5
5
|
export declare type SplitStyles = ReturnType<typeof getSplitStyles>;
|
|
@@ -7,7 +7,7 @@ export declare type ClassNamesObject = Record<string, string>;
|
|
|
7
7
|
export declare type SplitStyleResult = ReturnType<typeof getSplitStyles>;
|
|
8
8
|
declare type StyleSplitter = (props: {
|
|
9
9
|
[key: string]: any;
|
|
10
|
-
}, staticConfig: StaticConfigParsed, theme:
|
|
10
|
+
}, staticConfig: StaticConfigParsed, theme: ThemeParsed, state: SplitStyleState, defaultClassNames?: any, languageContext?: LanguageContextType, debug?: DebugProp) => {
|
|
11
11
|
pseudos: PseudoStyles;
|
|
12
12
|
medias: Record<MediaQueryKey, ViewStyle>;
|
|
13
13
|
style: ViewStyle;
|
|
@@ -24,7 +24,7 @@ export declare const pseudoCNInverse: {
|
|
|
24
24
|
press: string;
|
|
25
25
|
};
|
|
26
26
|
export declare const getSplitStyles: StyleSplitter;
|
|
27
|
-
export declare const getSubStyle: (subKey: string, styleIn: Object, staticConfig: StaticConfigParsed, theme:
|
|
27
|
+
export declare const getSubStyle: (subKey: string, styleIn: Object, staticConfig: StaticConfigParsed, theme: ThemeParsed, props: any, state: SplitStyleState, conf: TamaguiInternalConfig, languageContext?: FontLanguageProps, avoidDefaultProps?: boolean) => ViewStyle;
|
|
28
28
|
export declare const insertSplitStyles: StyleSplitter;
|
|
29
29
|
export declare const useSplitStyles: StyleSplitter;
|
|
30
30
|
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Some parts adapted from react-native-web
|
|
3
|
+
* Copyright (c) Nicolas Gallagher licensed under the MIT license.
|
|
4
|
+
*/
|
|
1
5
|
import { StyleObject } from '@tamagui/helpers';
|
|
2
6
|
import type { TextStyle, ViewStyle } from 'react-native';
|
|
3
7
|
import { PseudoDescriptor } from './pseudoDescriptors';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CreateTamaguiProps,
|
|
1
|
+
import { CreateTamaguiProps, ThemeParsed } from '../types';
|
|
2
2
|
export declare function getThemeCSSRules({ config, themeName, theme, names, }: {
|
|
3
3
|
config: CreateTamaguiProps;
|
|
4
4
|
themeName: string;
|
|
5
|
-
theme:
|
|
5
|
+
theme: ThemeParsed;
|
|
6
6
|
names: string[];
|
|
7
7
|
}): string[];
|
|
8
8
|
//# sourceMappingURL=getThemeCSSRules.d.ts.map
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preserves prop ordering, so that the order most closely matches the last spread objects
|
|
3
|
+
* Useful for having { ...defaultProps, ...props } that ensure props ordering is always kept
|
|
4
|
+
*
|
|
5
|
+
* Given:
|
|
6
|
+
* mergeProps({ a: 1, b: 2 }, { b: 1, a: 2 })
|
|
7
|
+
* The final key order will be:
|
|
8
|
+
* b, a
|
|
9
|
+
*
|
|
10
|
+
* Handles a couple special tamagui cases
|
|
11
|
+
* - classNames can be extracted out separately
|
|
12
|
+
* - shorthands can be expanded before merging
|
|
13
|
+
*/
|
|
1
14
|
declare type StringRecord = Record<string, string>;
|
|
2
15
|
export declare const mergeProps: (a: Object, b: Object, leaveOutClassNames?: boolean, inverseShorthands?: StringRecord) => readonly [StringRecord, StringRecord];
|
|
3
16
|
export {};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Some parts adapted from react-native-web
|
|
3
|
+
* Copyright (c) Nicolas Gallagher licensed under the MIT license.
|
|
4
|
+
*/
|
|
1
5
|
export declare function normalizeValueWithProperty(value: any, property?: string): any;
|
|
2
6
|
//# sourceMappingURL=normalizeValueWithProperty.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MediaQueries, MediaQueryKey, MediaQueryObject, MediaQueryState, TamaguiInternalConfig } from '../types';
|
|
2
2
|
export declare const mediaState: MediaQueryState;
|
|
3
3
|
export declare function addMediaQueryListener(key: MediaQueryKey, cb: any): () => void;
|
|
4
4
|
export declare function removeMediaQueryListener(key: MediaQueryKey, cb: any): void;
|
|
5
5
|
export declare const mediaQueryConfig: MediaQueries;
|
|
6
6
|
export declare const getMedia: () => MediaQueryState;
|
|
7
|
-
export declare const configureMedia: (
|
|
8
|
-
export declare function useMediaQueryListeners(): void;
|
|
7
|
+
export declare const configureMedia: (config: TamaguiInternalConfig) => void;
|
|
8
|
+
export declare function useMediaQueryListeners(config: TamaguiInternalConfig): void;
|
|
9
9
|
export declare function useMedia(): {
|
|
10
10
|
[key in MediaQueryKey]: boolean;
|
|
11
11
|
};
|