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