@tamagui/core 1.0.1-rc.9 → 1.0.2
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/config.js +3 -5
- package/dist/cjs/config.js.map +2 -2
- package/dist/cjs/constants/constants.js.map +2 -2
- package/dist/cjs/createComponent.js +25 -27
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createFont.js.map +2 -2
- package/dist/cjs/createTamagui.js +2 -1
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +7 -17
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/Unwrap.js +29 -0
- package/dist/cjs/helpers/Unwrap.js.map +7 -0
- package/dist/cjs/helpers/cache.js +9 -13
- package/dist/cjs/helpers/cache.js.map +2 -2
- package/dist/cjs/helpers/expandStyle.js +29 -41
- package/dist/cjs/helpers/expandStyle.js.map +2 -2
- package/dist/cjs/helpers/getBoundingClientRect.js +3 -6
- package/dist/cjs/helpers/getBoundingClientRect.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +8 -14
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +12 -18
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +0 -2
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/isTamaguiComponent.js +2 -7
- package/dist/cjs/helpers/isTamaguiComponent.js.map +2 -2
- package/dist/cjs/helpers/mergeProps.js +1 -1
- package/dist/cjs/helpers/mergeProps.js.map +2 -2
- package/dist/cjs/hooks/getThemeUnwrapped.js +1 -4
- package/dist/cjs/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +45 -50
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/views/FontLanguage.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js +3 -0
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/Text.js +0 -5
- package/dist/cjs/views/Text.js.map +2 -2
- package/dist/cjs/views/Theme.js +15 -21
- package/dist/cjs/views/Theme.js.map +3 -3
- package/dist/cjs/views/ThemeProvider.js +5 -6
- package/dist/cjs/views/ThemeProvider.js.map +2 -2
- package/dist/esm/config.js +3 -5
- package/dist/esm/config.js.map +2 -2
- package/dist/esm/constants/constants.js.map +2 -2
- package/dist/esm/createComponent.js +26 -28
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createFont.js.map +2 -2
- package/dist/esm/createTamagui.js +2 -1
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +7 -17
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/Unwrap.js +5 -0
- package/dist/esm/helpers/Unwrap.js.map +7 -0
- package/dist/esm/helpers/cache.js +9 -12
- package/dist/esm/helpers/cache.js.map +2 -2
- package/dist/esm/helpers/expandStyle.js +26 -38
- package/dist/esm/helpers/expandStyle.js.map +2 -2
- package/dist/esm/helpers/getBoundingClientRect.js +3 -6
- package/dist/esm/helpers/getBoundingClientRect.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +8 -14
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +12 -18
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +0 -2
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/isTamaguiComponent.js +2 -7
- package/dist/esm/helpers/isTamaguiComponent.js.map +2 -2
- package/dist/esm/helpers/mergeProps.js +1 -1
- package/dist/esm/helpers/mergeProps.js.map +2 -2
- package/dist/esm/hooks/getThemeUnwrapped.js +1 -4
- package/dist/esm/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +45 -50
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/FontLanguage.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +3 -0
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/Text.js +0 -5
- package/dist/esm/views/Text.js.map +2 -2
- package/dist/esm/views/Theme.js +14 -14
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +5 -6
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +13 -13
- package/src/config.ts +4 -6
- package/src/constants/constants.ts +0 -2
- package/src/createComponent.tsx +47 -43
- package/src/createFont.ts +0 -2
- package/src/createTamagui.ts +2 -1
- package/src/helpers/ThemeManager.tsx +10 -21
- package/src/helpers/cache.ts +8 -13
- package/src/helpers/expandStyle.ts +27 -41
- package/src/helpers/getBoundingClientRect.tsx +2 -5
- package/src/helpers/getSplitStyles.tsx +23 -14
- package/src/helpers/getStylesAtomic.ts +16 -24
- package/src/helpers/insertStyleRule.tsx +0 -2
- package/src/helpers/isTamaguiComponent.tsx +2 -6
- package/src/helpers/mergeProps.ts +1 -1
- package/src/hooks/getThemeUnwrapped.tsx +1 -3
- package/src/hooks/useTheme.tsx +67 -48
- package/src/styled.tsx +1 -1
- package/src/views/FontLanguage.tsx +0 -2
- package/src/views/TamaguiProvider.tsx +6 -0
- package/src/views/Text.tsx +0 -6
- package/src/views/Theme.tsx +15 -22
- package/src/views/ThemeProvider.tsx +8 -8
- package/types/createComponent.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/cache.d.ts +4 -6
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/views/Theme.d.ts +1 -1
|
@@ -56,16 +56,8 @@ export function getAtomicStyle(
|
|
|
56
56
|
if (!style || typeof style !== 'object') {
|
|
57
57
|
throw new Error(`Wrong style type: "${typeof style}": ${style}`)
|
|
58
58
|
}
|
|
59
|
-
} else {
|
|
60
|
-
if (!style) {
|
|
61
|
-
if (process.env.NODE_ENV === 'development') {
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.warn('Invalid style')
|
|
64
|
-
}
|
|
65
|
-
return []
|
|
66
|
-
}
|
|
67
59
|
}
|
|
68
|
-
|
|
60
|
+
if (!style) return []
|
|
69
61
|
return generateAtomicStyles(style, pseudo)
|
|
70
62
|
}
|
|
71
63
|
|
|
@@ -82,7 +74,21 @@ const generateAtomicStyles = (
|
|
|
82
74
|
|
|
83
75
|
// transform
|
|
84
76
|
if (style.transform && Array.isArray(style.transform)) {
|
|
85
|
-
style.transform = style.transform
|
|
77
|
+
style.transform = style.transform
|
|
78
|
+
.map(
|
|
79
|
+
// { scale: 2 } => 'scale(2)'
|
|
80
|
+
// { translateX: 20 } => 'translateX(20px)'
|
|
81
|
+
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
|
82
|
+
(transform) => {
|
|
83
|
+
const type = Object.keys(transform)[0]
|
|
84
|
+
const value = transform[type]
|
|
85
|
+
if (type === 'matrix' || type === 'matrix3d') {
|
|
86
|
+
return `${type}(${value.join(',')})`
|
|
87
|
+
}
|
|
88
|
+
return `${type}(${normalizeValueWithProperty(value, type)})`
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
.join(' ')
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
styleToCSS(style)
|
|
@@ -160,20 +166,6 @@ export function styleToCSS(style: Record<string, any>) {
|
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
168
|
|
|
163
|
-
// { scale: 2 } => 'scale(2)'
|
|
164
|
-
// { translateX: 20 } => 'translateX(20px)'
|
|
165
|
-
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
|
166
|
-
const mapTransform = (transform) => {
|
|
167
|
-
const type = Object.keys(transform)[0]
|
|
168
|
-
const value = transform[type]
|
|
169
|
-
if (type === 'matrix' || type === 'matrix3d') {
|
|
170
|
-
return `${type}(${value.join(',')})`
|
|
171
|
-
} else {
|
|
172
|
-
const normalizedValue = normalizeValueWithProperty(value, type)
|
|
173
|
-
return `${type}(${normalizedValue})`
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
169
|
function createDeclarationBlock(style: Style, important = false) {
|
|
178
170
|
let next = ''
|
|
179
171
|
for (const key in style) {
|
|
@@ -40,13 +40,11 @@ const isClient = typeof document !== 'undefined'
|
|
|
40
40
|
|
|
41
41
|
const scannedNum = new WeakMap<CSSStyleSheet, number>()
|
|
42
42
|
const totalSheetSelectors = new Map<string, number>()
|
|
43
|
-
const referencesInSheet = new WeakMap<CSSStyleSheet>()
|
|
44
43
|
|
|
45
44
|
export function listenForSheetChanges() {
|
|
46
45
|
if (!isClient) return
|
|
47
46
|
function handleNode(node: Node, remove = false) {
|
|
48
47
|
if (node instanceof HTMLStyleElement && node.sheet) {
|
|
49
|
-
console.warn('update', node.sheet)
|
|
50
48
|
updateSheetStyles(node.sheet, remove)
|
|
51
49
|
}
|
|
52
50
|
}
|
|
@@ -6,10 +6,6 @@ export function isTamaguiComponent<A>(
|
|
|
6
6
|
): comp is A & {
|
|
7
7
|
staticConfig: StaticConfig
|
|
8
8
|
} {
|
|
9
|
-
const config = comp
|
|
10
|
-
|
|
11
|
-
if (name) {
|
|
12
|
-
return name === config.componentName
|
|
13
|
-
}
|
|
14
|
-
return true
|
|
9
|
+
const config = comp?.['staticConfig'] as StaticConfigParsed | undefined
|
|
10
|
+
return (config?.parsed && (name ? name === config.componentName : true)) || false
|
|
15
11
|
}
|
|
@@ -41,7 +41,7 @@ function mergeProp(
|
|
|
41
41
|
inverseShorthands?: AnyRecord
|
|
42
42
|
) {
|
|
43
43
|
const val = a[key]
|
|
44
|
-
const shorthand = inverseShorthands
|
|
44
|
+
const shorthand = inverseShorthands?.[key] || null
|
|
45
45
|
if (b && (key in b || (shorthand && shorthand in b))) {
|
|
46
46
|
return
|
|
47
47
|
}
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'
|
|
3
|
-
import { useContext, useEffect,
|
|
3
|
+
import { useContext, useEffect, useMemo, useState } from 'react'
|
|
4
4
|
|
|
5
5
|
import { getConfig } from '../config'
|
|
6
6
|
import { isDevTools } from '../constants/isDevTools'
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { ThemeManagerContext } from '../helpers/ThemeManagerContext'
|
|
14
14
|
import { ThemeParsed, ThemeProps } from '../types'
|
|
15
15
|
import { GetThemeUnwrapped } from './getThemeUnwrapped'
|
|
16
|
+
import { useServerRef } from './useServerHooks'
|
|
16
17
|
|
|
17
18
|
export type ChangedThemeResponse = {
|
|
18
19
|
themeManager: ThemeManager | null
|
|
@@ -33,12 +34,28 @@ function getDefaultThemeProxied() {
|
|
|
33
34
|
})
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
interface UseThemeState {
|
|
38
|
+
keys: Set<string>
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
export const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {
|
|
37
42
|
if (isRSC) {
|
|
38
43
|
return getDefaultThemeProxied()
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
const
|
|
46
|
+
const state = useServerRef() as React.MutableRefObject<UseThemeState>
|
|
47
|
+
if (isClient && !state.current) {
|
|
48
|
+
state.current = {
|
|
49
|
+
keys: new Set(),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
state.current?.keys.clear()
|
|
53
|
+
|
|
54
|
+
const { name, theme, themeManager, className, isNewTheme } = useChangeThemeEffect(
|
|
55
|
+
props,
|
|
56
|
+
false,
|
|
57
|
+
isClient ? () => state.current.keys.size === 0 : undefined
|
|
58
|
+
)
|
|
42
59
|
|
|
43
60
|
if (process.env.NODE_ENV === 'development') {
|
|
44
61
|
// ensure we aren't creating too many ThemeManagers
|
|
@@ -73,6 +90,7 @@ export const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {
|
|
|
73
90
|
name,
|
|
74
91
|
className,
|
|
75
92
|
themeManager,
|
|
93
|
+
state,
|
|
76
94
|
})
|
|
77
95
|
}, [theme, isNewTheme, name, className, themeManager])
|
|
78
96
|
}
|
|
@@ -83,12 +101,14 @@ function getThemeProxied({
|
|
|
83
101
|
className,
|
|
84
102
|
themeManager,
|
|
85
103
|
isNewTheme,
|
|
104
|
+
state,
|
|
86
105
|
}: {
|
|
87
106
|
theme: any
|
|
88
107
|
name: string
|
|
89
108
|
className?: string
|
|
90
109
|
themeManager?: ThemeManager | null
|
|
91
110
|
isNewTheme?: boolean
|
|
111
|
+
state?: React.RefObject<UseThemeState>
|
|
92
112
|
}) {
|
|
93
113
|
return createProxy(theme, {
|
|
94
114
|
has(_, key) {
|
|
@@ -122,7 +142,20 @@ function getThemeProxied({
|
|
|
122
142
|
if (!themeManager) {
|
|
123
143
|
return theme[key]
|
|
124
144
|
}
|
|
125
|
-
|
|
145
|
+
const val = themeManager.getValue(key)
|
|
146
|
+
if (val && state) {
|
|
147
|
+
if (isClient) {
|
|
148
|
+
return new Proxy(val as any, {
|
|
149
|
+
get(_, subkey) {
|
|
150
|
+
if (subkey === 'val') {
|
|
151
|
+
state.current!.keys.add(key as any)
|
|
152
|
+
}
|
|
153
|
+
return Reflect.get(val, subkey)
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return val
|
|
126
159
|
},
|
|
127
160
|
})
|
|
128
161
|
}
|
|
@@ -139,7 +172,8 @@ export const activeThemeManagers = new Set<ThemeManager>()
|
|
|
139
172
|
|
|
140
173
|
export const useChangeThemeEffect = (
|
|
141
174
|
props: ThemeProps,
|
|
142
|
-
root = false
|
|
175
|
+
root = false,
|
|
176
|
+
disableUpdate?: () => boolean
|
|
143
177
|
): ChangedThemeResponse => {
|
|
144
178
|
if (isRSC) {
|
|
145
179
|
// we need context working for this to work well
|
|
@@ -186,20 +220,16 @@ export const useChangeThemeEffect = (
|
|
|
186
220
|
return
|
|
187
221
|
}
|
|
188
222
|
activeThemeManagers.add(themeManager)
|
|
189
|
-
const disposeChangeListener = parentManager?.onChangeTheme(() => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} else {
|
|
197
|
-
updateState()
|
|
198
|
-
}
|
|
199
|
-
})
|
|
223
|
+
// const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {
|
|
224
|
+
// // console.log('hi', props, state, name, manager)
|
|
225
|
+
// if (state.theme !== manager.state.theme) {
|
|
226
|
+
// console.warn('now update to', manager.state.name)
|
|
227
|
+
// updateState(manager)
|
|
228
|
+
// }
|
|
229
|
+
// })
|
|
200
230
|
return () => {
|
|
201
231
|
activeThemeManagers.delete(themeManager)
|
|
202
|
-
disposeChangeListener?.()
|
|
232
|
+
// disposeChangeListener?.()
|
|
203
233
|
}
|
|
204
234
|
}, [disable, state, isNewTheme, debug])
|
|
205
235
|
}
|
|
@@ -209,13 +239,8 @@ export const useChangeThemeEffect = (
|
|
|
209
239
|
|
|
210
240
|
if (shouldReturnParentState) {
|
|
211
241
|
if (!parentManager) throw 'impossible'
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
'useTheme hasNoThemeUpdatingProps',
|
|
215
|
-
parentManager.state.name,
|
|
216
|
-
'isInversingOnMount',
|
|
217
|
-
isInversingOnMount
|
|
218
|
-
)
|
|
242
|
+
// prettier-ignore
|
|
243
|
+
if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('useTheme hasNoThemeUpdatingProps', parentManager.state.name, 'isInversingOnMount', isInversingOnMount)
|
|
219
244
|
return {
|
|
220
245
|
...parentManager.state,
|
|
221
246
|
className: isInversingOnMount ? '' : parentManager.state.className,
|
|
@@ -234,27 +259,19 @@ export const useChangeThemeEffect = (
|
|
|
234
259
|
}
|
|
235
260
|
|
|
236
261
|
function createState(prev?: State) {
|
|
262
|
+
if (prev && disableUpdate?.()) {
|
|
263
|
+
return prev
|
|
264
|
+
}
|
|
265
|
+
// returns previous theme manager if no change
|
|
237
266
|
const _ = new ThemeManager(props, root ? 'root' : parentManager)
|
|
238
267
|
const isNewTheme = _ !== parentManager
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
'props',
|
|
247
|
-
props,
|
|
248
|
-
'\n',
|
|
249
|
-
isClient ? parentManager : '',
|
|
250
|
-
'getState',
|
|
251
|
-
isNewTheme && isClient ? _.getState(props) : '',
|
|
252
|
-
'\n',
|
|
253
|
-
'state',
|
|
254
|
-
isClient ? { ..._.state } : ''
|
|
255
|
-
),
|
|
256
|
-
console.groupEnd(),
|
|
257
|
-
]
|
|
268
|
+
// prettier-ignore
|
|
269
|
+
|
|
270
|
+
// if (prev?.isNewTheme && _.state.theme !== parentManager?.state.theme) {
|
|
271
|
+
// console.warn('notify')
|
|
272
|
+
// _.notify()
|
|
273
|
+
// }
|
|
274
|
+
|
|
258
275
|
// only inverse relies on this for ssr
|
|
259
276
|
const mounted = !props.inverse ? true : root || prev?.mounted
|
|
260
277
|
return {
|
|
@@ -266,12 +283,14 @@ export const useChangeThemeEffect = (
|
|
|
266
283
|
}
|
|
267
284
|
}
|
|
268
285
|
|
|
269
|
-
function updateState() {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
286
|
+
function updateState(updatingManager?: ThemeManager) {
|
|
287
|
+
if (disableUpdate?.()) {
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
const manager = updatingManager ?? themeManager
|
|
291
|
+
const next = manager.getState(props, parentManager)
|
|
292
|
+
const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null)
|
|
293
|
+
// console.log(`got it`, next, isNewTheme, shouldChange, { ...updatingManager?.state })
|
|
275
294
|
if (shouldChange) {
|
|
276
295
|
setThemeState(createState)
|
|
277
296
|
} else {
|
package/src/styled.tsx
CHANGED
|
@@ -32,6 +32,12 @@ export function TamaguiProvider({
|
|
|
32
32
|
// inject CSS if asked to (not SSR compliant)
|
|
33
33
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
34
34
|
React.useLayoutEffect(() => {
|
|
35
|
+
// for easier support of hidden-until-js mount animations
|
|
36
|
+
// user must set t_unmounted on documentElement from SSR
|
|
37
|
+
if (document.documentElement.classList.contains('t_unmounted')) {
|
|
38
|
+
document.documentElement.classList.remove('t_unmounted')
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
if (disableInjectCSS) return
|
|
36
42
|
const style = document.createElement('style')
|
|
37
43
|
style.appendChild(document.createTextNode(config.getCSS()))
|
package/src/views/Text.tsx
CHANGED
package/src/views/Theme.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isWeb } from '@tamagui/constants'
|
|
2
|
-
import React, { useMemo } from 'react'
|
|
2
|
+
import React, { Children, cloneElement, useMemo } from 'react'
|
|
3
3
|
|
|
4
4
|
import { variableToString } from '../createVariable'
|
|
5
5
|
import { ThemeManager } from '../helpers/ThemeManager'
|
|
@@ -14,23 +14,20 @@ export function Theme(props: ThemeProps) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const isRoot = !!props['_isRoot']
|
|
17
|
-
const { name, theme, themeManager,
|
|
18
|
-
props,
|
|
19
|
-
isRoot
|
|
20
|
-
)
|
|
21
|
-
|
|
17
|
+
const { name, theme, themeManager, className } = useChangeThemeEffect(props, isRoot)
|
|
22
18
|
const disableThemeClass = props.disableThemeClass
|
|
23
19
|
const missingTheme = !(name && theme)
|
|
24
20
|
|
|
25
21
|
// memo here, changing theme without re-rendering all children is a critical optimization
|
|
26
22
|
// may require some effort of end user to memoize but without this memo they'd have no option
|
|
27
|
-
let contents =
|
|
28
|
-
|
|
29
|
-
?
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
let contents = useThemeManagerContext(
|
|
24
|
+
props['data-themeable']
|
|
25
|
+
? Children.map(props.children, (child) =>
|
|
26
|
+
cloneElement(child, { ['data-themeable']: true })
|
|
27
|
+
)
|
|
28
|
+
: props.children,
|
|
29
|
+
themeManager
|
|
30
|
+
)
|
|
34
31
|
|
|
35
32
|
if (process.env.NODE_ENV === 'development' && missingTheme) {
|
|
36
33
|
// eslint-disable-next-line no-console
|
|
@@ -60,15 +57,15 @@ export function Theme(props: ThemeProps) {
|
|
|
60
57
|
return contents
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
export function
|
|
60
|
+
export function useThemeManagerContext(
|
|
64
61
|
children: any,
|
|
65
62
|
themeManager?: ThemeManager | null,
|
|
66
63
|
shouldReset?: boolean
|
|
67
64
|
) {
|
|
65
|
+
// disabled super memoize it - listener first strategy
|
|
66
|
+
const value = themeManager // useMemo(() => themeManager, [!!themeManager])
|
|
68
67
|
// be sure to memoize themeManager to avoid reparenting
|
|
69
|
-
if (!
|
|
70
|
-
return children
|
|
71
|
-
}
|
|
68
|
+
if (!value) return children
|
|
72
69
|
// be sure to memoize shouldReset to avoid reparenting
|
|
73
70
|
let next = children
|
|
74
71
|
// TODO likely not necessary if we do reset logic now in useTheme?
|
|
@@ -76,9 +73,5 @@ export function wrapThemeManagerContext(
|
|
|
76
73
|
if (shouldReset && themeManager) {
|
|
77
74
|
next = <Theme name={themeManager.state.parentName}>{next}</Theme>
|
|
78
75
|
}
|
|
79
|
-
return
|
|
80
|
-
<ThemeManagerContext.Provider value={themeManager}>
|
|
81
|
-
{next}
|
|
82
|
-
</ThemeManagerContext.Provider>
|
|
83
|
-
)
|
|
76
|
+
return <ThemeManagerContext.Provider value={value}>{next}</ThemeManagerContext.Provider>
|
|
84
77
|
}
|
|
@@ -32,15 +32,15 @@ export const ThemeProvider = (props: ThemeProviderProps) => {
|
|
|
32
32
|
}, [props.defaultTheme, props.disableRootThemeClass, props.themeClassNameOnRoot])
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const value = useMemo(() => {
|
|
36
|
-
return {
|
|
37
|
-
defaultTheme: props.defaultTheme,
|
|
38
|
-
}
|
|
39
|
-
// NOTE DON'T CHANGE THIS ITS ONLY USED BY useThemeName for SSR safety for now...
|
|
40
|
-
}, [])
|
|
41
|
-
|
|
42
35
|
return (
|
|
43
|
-
<ThemeProviderRootContext.Provider
|
|
36
|
+
<ThemeProviderRootContext.Provider
|
|
37
|
+
value={useMemo(() => {
|
|
38
|
+
return {
|
|
39
|
+
defaultTheme: props.defaultTheme,
|
|
40
|
+
}
|
|
41
|
+
// NOTE DON'T CHANGE THIS ITS ONLY USED BY useThemeName for SSR safety for now...
|
|
42
|
+
}, [])}
|
|
43
|
+
>
|
|
44
44
|
<Theme
|
|
45
45
|
className={props.className}
|
|
46
46
|
name={props.defaultTheme}
|
|
@@ -17,5 +17,5 @@ export type SpacedChildrenProps = {
|
|
|
17
17
|
direction?: SpaceDirection;
|
|
18
18
|
separator?: React.ReactNode;
|
|
19
19
|
};
|
|
20
|
-
export declare function spacedChildren(
|
|
20
|
+
export declare function spacedChildren(props: SpacedChildrenProps): React.ReactNode;
|
|
21
21
|
//# sourceMappingURL=createComponent.d.ts.map
|
|
@@ -25,7 +25,7 @@ export declare class ThemeManager {
|
|
|
25
25
|
forceTheme?: ThemeParsed;
|
|
26
26
|
}, notify?: boolean): ThemeManagerState | undefined;
|
|
27
27
|
getStateIfChanged(props?: ThemeProps, state?: ThemeManagerState | null, parentManager?: ThemeManager | null): ThemeManagerState | null | undefined;
|
|
28
|
-
getStateShouldChange(nextState: ThemeManagerState | null, state?: ThemeManagerState | null):
|
|
28
|
+
getStateShouldChange(nextState: ThemeManagerState | null, state?: ThemeManagerState | null): boolean;
|
|
29
29
|
getState(props?: ThemeProps, parentManager?: ThemeManager | null): ThemeManagerState | null;
|
|
30
30
|
get allKeys(): Set<string>;
|
|
31
31
|
getValue(key: string, state?: ThemeManagerState): import("..").Variable<any> | undefined;
|
package/types/helpers/cache.d.ts
CHANGED
|
@@ -2,11 +2,9 @@ type Value = Object | Array<any> | string | number;
|
|
|
2
2
|
export type Style = {
|
|
3
3
|
[key: string]: Value;
|
|
4
4
|
};
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export declare const cache: Cache;
|
|
5
|
+
export declare const cache: {
|
|
6
|
+
get: (key: string, valStr: string) => any;
|
|
7
|
+
set: (key: string, valStr: string, object: any) => void;
|
|
8
|
+
};
|
|
11
9
|
export {};
|
|
12
10
|
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -11,5 +11,5 @@ export declare const useTheme: (props?: ThemeProps) => ThemeParsed;
|
|
|
11
11
|
export declare const getThemeManager: (theme: any) => ThemeManager | undefined;
|
|
12
12
|
export declare const getThemeIsNewTheme: (theme: any) => ThemeManager | undefined;
|
|
13
13
|
export declare const activeThemeManagers: Set<ThemeManager>;
|
|
14
|
-
export declare const useChangeThemeEffect: (props: ThemeProps, root?: boolean) => ChangedThemeResponse;
|
|
14
|
+
export declare const useChangeThemeEffect: (props: ThemeProps, root?: boolean, disableUpdate?: () => boolean) => ChangedThemeResponse;
|
|
15
15
|
//# sourceMappingURL=useTheme.d.ts.map
|
package/types/views/Theme.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ThemeManager } from '../helpers/ThemeManager';
|
|
2
2
|
import { ThemeProps } from '../types';
|
|
3
3
|
export declare function Theme(props: ThemeProps): any;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function useThemeManagerContext(children: any, themeManager?: ThemeManager | null, shouldReset?: boolean): any;
|
|
5
5
|
//# sourceMappingURL=Theme.d.ts.map
|