@tamagui/core 1.0.2 → 1.0.4
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 +1 -1
- package/dist/cjs/config.js.map +2 -2
- package/dist/cjs/createComponent.js +51 -95
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +7 -4
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +1 -1
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +12 -3
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +12 -2
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/getSize.js +9 -5
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +39 -45
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +32 -26
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js +6 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +12 -1
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +8 -7
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +37 -36
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +28 -42
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/styled.js +4 -1
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/Slot.js +1 -33
- package/dist/cjs/views/Slot.js.map +3 -3
- package/dist/cjs/views/Stack.test.js +4 -6
- package/dist/cjs/views/Stack.test.js.map +2 -2
- package/dist/cjs/views/Theme.js +45 -41
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +1 -1
- package/dist/cjs/views/ThemeProvider.js.map +2 -2
- package/dist/esm/config.js +1 -1
- package/dist/esm/config.js.map +2 -2
- package/dist/esm/createComponent.js +53 -97
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +8 -5
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +1 -1
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +10 -2
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +13 -3
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/getSize.js +9 -5
- package/dist/esm/helpers/getSize.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +39 -45
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +31 -26
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.native.js +4 -1
- package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +12 -1
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/normalizeColor.js +8 -7
- package/dist/esm/helpers/normalizeColor.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +37 -37
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +25 -39
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/styled.js +4 -1
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/Slot.js +1 -33
- package/dist/esm/views/Slot.js.map +3 -3
- package/dist/esm/views/Stack.test.js +1 -3
- package/dist/esm/views/Stack.test.js.map +2 -2
- package/dist/esm/views/Theme.js +44 -40
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +1 -1
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +11 -11
- package/reset.css +4 -0
- package/src/__snapshots__/createTokens.test.ts.snap +90 -195
- package/src/config.ts +1 -1
- package/src/createComponent.tsx +72 -152
- package/src/createTamagui.ts +8 -5
- package/src/createVariable.ts +2 -1
- package/src/createVariables.ts +14 -1
- package/src/helpers/ThemeManager.tsx +13 -3
- package/src/helpers/getSplitStyles.tsx +43 -53
- package/src/helpers/getStylesAtomic.native.ts +2 -0
- package/src/helpers/getStylesAtomic.ts +36 -31
- package/src/helpers/insertStyleRule.tsx +12 -2
- package/src/helpers/normalizeColor.ts +8 -7
- package/src/hooks/useMedia.tsx +53 -48
- package/src/hooks/useTheme.tsx +37 -56
- package/src/index.ts +0 -1
- package/src/styled.tsx +4 -1
- package/src/types.tsx +7 -3
- package/src/views/Slot.tsx +3 -59
- package/src/views/Stack.test.tsx +1 -4
- package/src/views/Theme.tsx +60 -54
- package/src/views/ThemeProvider.tsx +1 -1
- package/types/createVariables.d.ts +1 -0
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/getSplitStyles.d.ts +2 -3
- package/types/helpers/getStylesAtomic.d.ts +1 -0
- package/types/helpers/getStylesAtomic.native.d.ts +1 -0
- package/types/hooks/useMedia.d.ts +8 -4
- package/types/hooks/useTheme.d.ts +16 -2
- package/types/index.d.ts +0 -1
- package/types/types.d.ts +3 -2
- package/types/views/Slot.d.ts +5 -4
- package/types/views/Theme.d.ts +5 -2
- package/src/helpers/cache.ts +0 -13
- package/src/helpers/getSize.ts +0 -23
package/src/styled.tsx
CHANGED
|
@@ -63,7 +63,10 @@ export function styled<
|
|
|
63
63
|
// }
|
|
64
64
|
|
|
65
65
|
// validate not using a variant over an existing valid style
|
|
66
|
-
if (process.env.NODE_ENV
|
|
66
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
+
if (!Component) {
|
|
68
|
+
throw new Error(`No component given to styled()`)
|
|
69
|
+
}
|
|
67
70
|
if (options?.variants) {
|
|
68
71
|
for (const key in options.variants) {
|
|
69
72
|
if (key in stylePropsAll) {
|
package/src/types.tsx
CHANGED
|
@@ -241,7 +241,7 @@ export type InferTamaguiConfig<Conf> = Conf extends ConfProps<
|
|
|
241
241
|
? TamaguiInternalConfig<A, B, C, D, E, F>
|
|
242
242
|
: unknown
|
|
243
243
|
|
|
244
|
-
// for use in creation functions so it doesnt get
|
|
244
|
+
// for use in creation functions so it doesnt get overwritten
|
|
245
245
|
export type GenericTamaguiConfig = CreateTamaguiConfig<
|
|
246
246
|
GenericTokens,
|
|
247
247
|
GenericThemes,
|
|
@@ -272,13 +272,16 @@ export type FontLanguages = ArrayIntersection<TamaguiConfig['fontLanguages']>
|
|
|
272
272
|
|
|
273
273
|
export interface ThemeProps {
|
|
274
274
|
className?: string
|
|
275
|
-
disableThemeClass?: boolean
|
|
276
275
|
name?: Exclude<ThemeName, number> | null
|
|
277
276
|
componentName?: string
|
|
278
277
|
children?: any
|
|
279
278
|
reset?: boolean
|
|
280
279
|
debug?: boolean | 'verbose'
|
|
281
280
|
inverse?: boolean
|
|
281
|
+
// on the web, for portals we need to re-insert className
|
|
282
|
+
forceClassName?: boolean
|
|
283
|
+
// allows for disabling the auto-update behavior
|
|
284
|
+
shouldUpdate?: () => boolean
|
|
282
285
|
}
|
|
283
286
|
|
|
284
287
|
type ArrayIntersection<A extends any[]> = A[keyof A]
|
|
@@ -495,6 +498,7 @@ type GetTokenString<A> = A extends string | number ? `$${A}` : `$${string}`
|
|
|
495
498
|
// base tokens
|
|
496
499
|
export type SizeTokens = GetTokenString<keyof Tokens['size']> | number
|
|
497
500
|
export type SpaceTokens = GetTokenString<keyof Tokens['space']> | number | boolean
|
|
501
|
+
|
|
498
502
|
export type ColorTokens =
|
|
499
503
|
| GetTokenString<keyof Tokens['color']>
|
|
500
504
|
| GetTokenString<keyof ThemeParsed>
|
|
@@ -1372,7 +1376,7 @@ export type UseAnimationHook = (props: {
|
|
|
1372
1376
|
hostRef: RefObject<HTMLElement | View>
|
|
1373
1377
|
staticConfig: StaticConfigParsed
|
|
1374
1378
|
state: SplitStyleState
|
|
1375
|
-
pseudos: PseudoProps<ViewStyle>
|
|
1379
|
+
pseudos: PseudoProps<ViewStyle> | null
|
|
1376
1380
|
onDidAnimate?: any
|
|
1377
1381
|
delay?: number
|
|
1378
1382
|
}) => null | {
|
package/src/views/Slot.tsx
CHANGED
|
@@ -15,59 +15,11 @@ import {
|
|
|
15
15
|
* Slot
|
|
16
16
|
* -----------------------------------------------------------------------------------------------*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
children?: ReactNode
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const Slot = forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {
|
|
23
|
-
const { children, ...slotProps } = props
|
|
24
|
-
const childrenArray = Children.toArray(children)
|
|
25
|
-
const slottable = childrenArray.find(isSlottable)
|
|
26
|
-
|
|
27
|
-
if (slottable) {
|
|
28
|
-
// the new element to render is the one passed as a child of `Slottable`
|
|
29
|
-
const newElement = slottable.props.children as ReactNode
|
|
30
|
-
|
|
31
|
-
const newChildren = childrenArray.map((child) => {
|
|
32
|
-
if (child === slottable) {
|
|
33
|
-
// because the new element will be the one rendered, we are only interested
|
|
34
|
-
// in grabbing its children (`newElement.props.children`)
|
|
35
|
-
if (Children.count(newElement) > 1) return Children.only(null)
|
|
36
|
-
return isValidElement(newElement)
|
|
37
|
-
? (newElement.props.children as ReactNode)
|
|
38
|
-
: null
|
|
39
|
-
} else {
|
|
40
|
-
return child
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<SlotClone {...slotProps} ref={forwardedRef}>
|
|
46
|
-
{isValidElement(newElement)
|
|
47
|
-
? cloneElement(newElement, undefined, newChildren)
|
|
48
|
-
: null}
|
|
49
|
-
</SlotClone>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<SlotClone {...slotProps} ref={forwardedRef}>
|
|
55
|
-
{children}
|
|
56
|
-
</SlotClone>
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
Slot.displayName = 'Slot'
|
|
61
|
-
|
|
62
|
-
/* -------------------------------------------------------------------------------------------------
|
|
63
|
-
* SlotClone
|
|
64
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
65
|
-
|
|
66
|
-
interface SlotCloneProps {
|
|
18
|
+
interface SlotProps {
|
|
67
19
|
children: ReactNode
|
|
68
20
|
}
|
|
69
21
|
|
|
70
|
-
const
|
|
22
|
+
export const Slot = forwardRef<any, SlotProps>(function Slot(props, forwardedRef) {
|
|
71
23
|
const { children, ...slotProps } = props
|
|
72
24
|
|
|
73
25
|
if (isValidElement(children)) {
|
|
@@ -81,8 +33,6 @@ const SlotClone = forwardRef<any, SlotCloneProps>((props, forwardedRef) => {
|
|
|
81
33
|
return Children.count(children) > 1 ? Children.only(null) : null
|
|
82
34
|
})
|
|
83
35
|
|
|
84
|
-
SlotClone.displayName = 'SlotClone'
|
|
85
|
-
|
|
86
36
|
/* -------------------------------------------------------------------------------------------------
|
|
87
37
|
* Slottable
|
|
88
38
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -93,12 +43,6 @@ export const Slottable = ({ children }: { children: ReactNode }) => {
|
|
|
93
43
|
|
|
94
44
|
/* ---------------------------------------------------------------------------------------------- */
|
|
95
45
|
|
|
96
|
-
type AnyProps = Record<string, any>
|
|
97
|
-
|
|
98
|
-
function isSlottable(child: ReactNode): child is ReactElement {
|
|
99
|
-
return isValidElement(child) && child.type === Slottable
|
|
100
|
-
}
|
|
101
|
-
|
|
102
46
|
const pressMap = isWeb
|
|
103
47
|
? {
|
|
104
48
|
onPress: 'onClick',
|
|
@@ -107,7 +51,7 @@ const pressMap = isWeb
|
|
|
107
51
|
}
|
|
108
52
|
: {}
|
|
109
53
|
|
|
110
|
-
function mergeSlotProps(child: any, slotProps:
|
|
54
|
+
function mergeSlotProps(child: any, slotProps: Record<string, any>) {
|
|
111
55
|
const childProps = child.props
|
|
112
56
|
|
|
113
57
|
// all child props should override
|
package/src/views/Stack.test.tsx
CHANGED
|
@@ -4,10 +4,7 @@ import { getDefaultTamaguiConfig } from '@tamagui/config-default-node'
|
|
|
4
4
|
import { render } from '@testing-library/react'
|
|
5
5
|
import { describe, expect, test } from 'vitest'
|
|
6
6
|
|
|
7
|
-
import { createTamagui } from '
|
|
8
|
-
import { Stack } from './Stack'
|
|
9
|
-
import { TamaguiProvider } from './TamaguiProvider'
|
|
10
|
-
import { StackProps, configureMedia } from '..'
|
|
7
|
+
import { Stack, StackProps, TamaguiProvider, createTamagui } from '..'
|
|
11
8
|
|
|
12
9
|
const conf = createTamagui(getDefaultTamaguiConfig())
|
|
13
10
|
|
package/src/views/Theme.tsx
CHANGED
|
@@ -1,77 +1,83 @@
|
|
|
1
1
|
import { isWeb } from '@tamagui/constants'
|
|
2
|
-
import
|
|
2
|
+
import { Children, cloneElement } from 'react'
|
|
3
3
|
|
|
4
4
|
import { variableToString } from '../createVariable'
|
|
5
|
-
import { ThemeManager } from '../helpers/ThemeManager'
|
|
6
5
|
import { ThemeManagerContext } from '../helpers/ThemeManagerContext'
|
|
7
|
-
import {
|
|
6
|
+
import { useServerRef } from '../hooks/useServerHooks'
|
|
7
|
+
import { ChangedThemeResponse, useChangeThemeEffect } from '../hooks/useTheme'
|
|
8
8
|
import { ThemeProps } from '../types'
|
|
9
9
|
|
|
10
10
|
export function Theme(props: ThemeProps) {
|
|
11
11
|
// @ts-expect-error only for internal views
|
|
12
|
-
if (props.disable)
|
|
13
|
-
return props.children
|
|
14
|
-
}
|
|
15
|
-
|
|
12
|
+
if (props.disable) return props.children
|
|
16
13
|
const isRoot = !!props['_isRoot']
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
14
|
+
const themeState = useChangeThemeEffect(props, isRoot)
|
|
15
|
+
const children = props['data-themeable']
|
|
16
|
+
? Children.map(props.children, (child) =>
|
|
17
|
+
cloneElement(child, { ['data-themeable']: true })
|
|
18
|
+
)
|
|
19
|
+
: props.children
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
)
|
|
21
|
+
return useThemedChildren(themeState, children, props)
|
|
22
|
+
}
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
export function useThemedChildren(
|
|
25
|
+
themeState: ChangedThemeResponse,
|
|
26
|
+
children: any,
|
|
27
|
+
options: { forceClassName?: boolean; shallow?: boolean }
|
|
28
|
+
) {
|
|
29
|
+
const { themeManager, isNewTheme, className, theme } = themeState
|
|
30
|
+
const { shallow, forceClassName } = options
|
|
31
|
+
|
|
32
|
+
const hasEverThemed = useServerRef(false)
|
|
33
|
+
if (isNewTheme) {
|
|
34
|
+
hasEverThemed.current = true
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// once a theme is set it always passes the context to avoid reparenting
|
|
38
|
+
// until then no context to avoid lots of context
|
|
39
|
+
if (!isNewTheme && !hasEverThemed.current && !forceClassName && !shallow) {
|
|
40
|
+
return children
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// be sure to memoize shouldReset to avoid reparenting
|
|
44
|
+
let next = children
|
|
45
|
+
|
|
46
|
+
if (shallow && themeManager) {
|
|
47
|
+
next = Children.map(next, (child) => {
|
|
48
|
+
return cloneElement(
|
|
49
|
+
child,
|
|
50
|
+
undefined,
|
|
51
|
+
<Theme name={themeManager.state.parentName}>{child.props.children}</Theme>
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
next = (
|
|
57
|
+
<ThemeManagerContext.Provider value={themeManager}>
|
|
58
|
+
{next}
|
|
59
|
+
</ThemeManagerContext.Provider>
|
|
60
|
+
)
|
|
61
|
+
|
|
42
62
|
if (isWeb) {
|
|
43
|
-
const
|
|
44
|
-
|
|
63
|
+
const enableClassName =
|
|
64
|
+
forceClassName === true || (forceClassName !== false && isNewTheme)
|
|
65
|
+
return (
|
|
45
66
|
<span
|
|
46
|
-
className=
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
className="_dsp_contents"
|
|
68
|
+
{...(theme &&
|
|
69
|
+
enableClassName && {
|
|
70
|
+
className: `${className} ${forceClassName ? 'forced1' : ''} _dsp_contents`,
|
|
71
|
+
style: {
|
|
72
|
+
// in order to provide currentColor, set color by default
|
|
73
|
+
color: variableToString(theme.color),
|
|
74
|
+
},
|
|
75
|
+
})}
|
|
51
76
|
>
|
|
52
|
-
{
|
|
77
|
+
{next}
|
|
53
78
|
</span>
|
|
54
79
|
)
|
|
55
80
|
}
|
|
56
81
|
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function useThemeManagerContext(
|
|
61
|
-
children: any,
|
|
62
|
-
themeManager?: ThemeManager | null,
|
|
63
|
-
shouldReset?: boolean
|
|
64
|
-
) {
|
|
65
|
-
// disabled super memoize it - listener first strategy
|
|
66
|
-
const value = themeManager // useMemo(() => themeManager, [!!themeManager])
|
|
67
|
-
// be sure to memoize themeManager to avoid reparenting
|
|
68
|
-
if (!value) return children
|
|
69
|
-
// be sure to memoize shouldReset to avoid reparenting
|
|
70
|
-
let next = children
|
|
71
|
-
// TODO likely not necessary if we do reset logic now in useTheme?
|
|
72
|
-
// reset to parent theme
|
|
73
|
-
if (shouldReset && themeManager) {
|
|
74
|
-
next = <Theme name={themeManager.state.parentName}>{next}</Theme>
|
|
75
|
-
}
|
|
76
|
-
return <ThemeManagerContext.Provider value={value}>{next}</ThemeManagerContext.Provider>
|
|
82
|
+
return next
|
|
77
83
|
}
|
|
@@ -44,7 +44,7 @@ export const ThemeProvider = (props: ThemeProviderProps) => {
|
|
|
44
44
|
<Theme
|
|
45
45
|
className={props.className}
|
|
46
46
|
name={props.defaultTheme}
|
|
47
|
-
|
|
47
|
+
forceClassName={props.disableRootThemeClass ? false : undefined}
|
|
48
48
|
// @ts-expect-error
|
|
49
49
|
_isRoot
|
|
50
50
|
>
|
|
@@ -5,6 +5,7 @@ type DeepTokenObject<Val extends string | number = any> = {
|
|
|
5
5
|
export type DeepVariableObject<A extends DeepTokenObject> = {
|
|
6
6
|
[Key in keyof A]: A[Key] extends string | number ? Variable<A[Key]> : A[Key] extends DeepTokenObject ? DeepVariableObject<A[Key]> : never;
|
|
7
7
|
};
|
|
8
|
+
export declare const tokensKeysOrdered: WeakMap<object, any>;
|
|
8
9
|
export declare const createVariables: <A extends DeepTokenObject<any>>(tokens: A, parentPath?: string, isFont?: boolean) => DeepVariableObject<A>;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=createVariables.d.ts.map
|
|
@@ -28,7 +28,7 @@ export declare class ThemeManager {
|
|
|
28
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
|
-
getValue(key: string, state?: ThemeManagerState): import("
|
|
31
|
+
getValue(key: string, state?: ThemeManagerState): import("../types").VariableVal | undefined;
|
|
32
32
|
notify(): void;
|
|
33
33
|
onChangeTheme(cb: ThemeListener): () => void;
|
|
34
34
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ViewStyle } from 'react-native';
|
|
2
|
-
import type { DebugProp,
|
|
2
|
+
import type { DebugProp, 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
|
import { FlatTransforms } from './mergeTransform';
|
|
6
6
|
type GetStyleResult = {
|
|
7
|
-
pseudos
|
|
8
|
-
medias: Record<MediaQueryKey, ViewStyle>;
|
|
7
|
+
pseudos?: PseudoStyles;
|
|
9
8
|
style: ViewStyle;
|
|
10
9
|
classNames: ClassNamesObject;
|
|
11
10
|
rulesToInsert: RulesToInsert;
|
|
@@ -12,6 +12,7 @@ export type ViewStyleWithPseudos = ViewOrTextStyle & {
|
|
|
12
12
|
focusStyle?: ViewOrTextStyle;
|
|
13
13
|
};
|
|
14
14
|
export declare function getStylesAtomic(stylesIn: ViewStyleWithPseudos): StyleObject[];
|
|
15
|
+
export declare const startClearStyleCacheInterval: () => void;
|
|
15
16
|
export declare function getAtomicStyle(style: ViewOrTextStyle, pseudo?: PseudoDescriptor): StyleObject[];
|
|
16
17
|
export declare function styleToCSS(style: Record<string, any>): void;
|
|
17
18
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MediaQueries, MediaQueryKey, MediaQueryObject, MediaQueryState, TamaguiInternalConfig } from '../types';
|
|
2
|
-
export declare
|
|
2
|
+
export declare let mediaState: MediaQueryState;
|
|
3
3
|
export declare const mediaQueryConfig: MediaQueries;
|
|
4
4
|
export declare const getMedia: () => MediaQueryState;
|
|
5
5
|
export declare const mediaKeysWithAndWithout$: Set<string>;
|
|
@@ -10,13 +10,17 @@ export declare function useMediaListeners(config: TamaguiInternalConfig): void;
|
|
|
10
10
|
type UseMediaState = {
|
|
11
11
|
[key in MediaQueryKey]: boolean;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
type UpdateState = {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
keys: MediaQueryKey[];
|
|
16
|
+
};
|
|
17
|
+
export declare function setMediaShouldUpdate(ref: any, props: UpdateState): WeakMap<any, UpdateState>;
|
|
18
|
+
export declare function useMedia(uid?: any, debug?: any): UseMediaState;
|
|
15
19
|
/**
|
|
16
20
|
* Useful for more complex components that need access to the currently active props,
|
|
17
21
|
* accounting for the currently active media queries.
|
|
18
22
|
*
|
|
19
|
-
* Use sparingly,
|
|
23
|
+
* Use sparingly, it will loop props and trigger re-render on all media queries.
|
|
20
24
|
*
|
|
21
25
|
* */
|
|
22
26
|
export declare function useMediaPropsActive<A extends Object>(props: A): {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ThemeManager } from '../helpers/ThemeManager';
|
|
2
3
|
import { ThemeParsed, ThemeProps } from '../types';
|
|
3
4
|
export type ChangedThemeResponse = {
|
|
@@ -7,9 +8,22 @@ export type ChangedThemeResponse = {
|
|
|
7
8
|
theme?: ThemeParsed | null;
|
|
8
9
|
className?: string;
|
|
9
10
|
};
|
|
11
|
+
interface UseThemeState {
|
|
12
|
+
keys: Set<string>;
|
|
13
|
+
}
|
|
10
14
|
export declare const useTheme: (props?: ThemeProps) => ThemeParsed;
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
15
|
+
export declare const useThemeWithState: (props: ThemeProps) => {
|
|
16
|
+
theme: ThemeParsed;
|
|
17
|
+
themeManager: ThemeManager | null;
|
|
18
|
+
name: string;
|
|
19
|
+
isNewTheme?: boolean | undefined;
|
|
20
|
+
className?: string | undefined;
|
|
21
|
+
} | null;
|
|
22
|
+
export declare function getThemeProxied({ theme, themeManager, state, }: Partial<ChangedThemeResponse> & {
|
|
23
|
+
theme: ThemeParsed;
|
|
24
|
+
state?: React.RefObject<UseThemeState>;
|
|
25
|
+
}): ThemeParsed;
|
|
13
26
|
export declare const activeThemeManagers: Set<ThemeManager>;
|
|
14
27
|
export declare const useChangeThemeEffect: (props: ThemeProps, root?: boolean, disableUpdate?: () => boolean) => ChangedThemeResponse;
|
|
28
|
+
export {};
|
|
15
29
|
//# sourceMappingURL=useTheme.d.ts.map
|
package/types/index.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export * from './helpers/useShallowSetState';
|
|
|
20
20
|
export * from './helpers/getVariantExtras';
|
|
21
21
|
export * from './helpers/getAnimationDriver';
|
|
22
22
|
export * from './helpers/getExpandedShorthands';
|
|
23
|
-
export * from './helpers/getSize';
|
|
24
23
|
export * from './helpers/getSplitStyles';
|
|
25
24
|
export * from './helpers/getStylesAtomic';
|
|
26
25
|
export * from './helpers/pseudoDescriptors';
|
package/types/types.d.ts
CHANGED
|
@@ -154,13 +154,14 @@ export type AnimationKeys = TamaguiConfig['animations'] extends AnimationDriver<
|
|
|
154
154
|
export type FontLanguages = ArrayIntersection<TamaguiConfig['fontLanguages']>;
|
|
155
155
|
export interface ThemeProps {
|
|
156
156
|
className?: string;
|
|
157
|
-
disableThemeClass?: boolean;
|
|
158
157
|
name?: Exclude<ThemeName, number> | null;
|
|
159
158
|
componentName?: string;
|
|
160
159
|
children?: any;
|
|
161
160
|
reset?: boolean;
|
|
162
161
|
debug?: boolean | 'verbose';
|
|
163
162
|
inverse?: boolean;
|
|
163
|
+
forceClassName?: boolean;
|
|
164
|
+
shouldUpdate?: () => boolean;
|
|
164
165
|
}
|
|
165
166
|
type ArrayIntersection<A extends any[]> = A[keyof A];
|
|
166
167
|
type GetAltThemeNames<S> = (S extends `${string}_${infer Alt}` ? GetAltThemeNames<Alt> : S) | S;
|
|
@@ -649,7 +650,7 @@ export type UseAnimationHook = (props: {
|
|
|
649
650
|
hostRef: RefObject<HTMLElement | View>;
|
|
650
651
|
staticConfig: StaticConfigParsed;
|
|
651
652
|
state: SplitStyleState;
|
|
652
|
-
pseudos: PseudoProps<ViewStyle
|
|
653
|
+
pseudos: PseudoProps<ViewStyle> | null;
|
|
653
654
|
onDidAnimate?: any;
|
|
654
655
|
delay?: number;
|
|
655
656
|
}) => null | {
|
package/types/views/Slot.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
children
|
|
4
|
-
}
|
|
5
|
-
export declare const Slot: import("react").ForwardRefExoticComponent<SlotProps & import("react").RefAttributes<
|
|
2
|
+
interface SlotProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const Slot: import("react").ForwardRefExoticComponent<SlotProps & import("react").RefAttributes<any>>;
|
|
6
6
|
export declare const Slottable: ({ children }: {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
}) => JSX.Element;
|
|
9
9
|
export declare function mergeEvent(a?: Function, b?: Function): (...args: unknown[]) => void;
|
|
10
|
+
export {};
|
|
10
11
|
//# sourceMappingURL=Slot.d.ts.map
|
package/types/views/Theme.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChangedThemeResponse } from '../hooks/useTheme';
|
|
2
2
|
import { ThemeProps } from '../types';
|
|
3
3
|
export declare function Theme(props: ThemeProps): any;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function useThemedChildren(themeState: ChangedThemeResponse, children: any, options: {
|
|
5
|
+
forceClassName?: boolean;
|
|
6
|
+
shallow?: boolean;
|
|
7
|
+
}): any;
|
|
5
8
|
//# sourceMappingURL=Theme.d.ts.map
|
package/src/helpers/cache.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type Value = Object | Array<any> | string | number
|
|
2
|
-
|
|
3
|
-
export type Style = { [key: string]: Value }
|
|
4
|
-
|
|
5
|
-
const v: Record<string, any> = {}
|
|
6
|
-
|
|
7
|
-
export const cache = {
|
|
8
|
-
get: (key: string, valStr: string) => v[key]?.[valStr],
|
|
9
|
-
set: (key: string, valStr: string, object: any) => {
|
|
10
|
-
v[key] ??= {}
|
|
11
|
-
v[key][valStr] = object
|
|
12
|
-
},
|
|
13
|
-
}
|
package/src/helpers/getSize.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getTokens } from '../config'
|
|
2
|
-
import { SizeTokens, SpaceTokens } from '../types'
|
|
3
|
-
|
|
4
|
-
export const getSize = (size?: SizeTokens | undefined, shift = 0, bounds = [0]) => {
|
|
5
|
-
return stepTokenUpOrDown(getTokens(true).size, size, shift, bounds)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const stepTokenUpOrDown = (
|
|
9
|
-
tokens: Object,
|
|
10
|
-
current?: SizeTokens | SpaceTokens | string,
|
|
11
|
-
shift = 0,
|
|
12
|
-
bounds = [0]
|
|
13
|
-
) => {
|
|
14
|
-
const sizeNames = Object.keys(tokens)
|
|
15
|
-
const currentKeyNum =
|
|
16
|
-
(typeof current === 'string' ? current.replace('$', '') : current) || '4'
|
|
17
|
-
const nextKeyName = `$${+currentKeyNum + shift}`
|
|
18
|
-
const min = bounds[0] ?? 0
|
|
19
|
-
const max = bounds[1] ?? sizeNames.length - 1
|
|
20
|
-
const index = Math.min(max, Math.max(min, sizeNames.indexOf(nextKeyName)))
|
|
21
|
-
const key = sizeNames[index]
|
|
22
|
-
return tokens[key] || tokens['$4']
|
|
23
|
-
}
|