@tamagui/theme-base 1.0.0-beta.8 → 1.0.1-beta.100
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/colorUtils.js +9 -10
- package/dist/cjs/colorUtils.js.map +1 -1
- package/dist/cjs/themes.js +162 -113
- package/dist/cjs/themes.js.map +2 -2
- package/dist/cjs/tokens.js +97 -26
- package/dist/cjs/tokens.js.map +2 -2
- package/dist/esm/colorUtils.js +10 -13
- package/dist/esm/colorUtils.js.map +1 -1
- package/dist/esm/themes.js +189 -129
- package/dist/esm/themes.js.map +2 -2
- package/dist/esm/tokens.js +130 -23
- package/dist/esm/tokens.js.map +2 -2
- package/dist/jsx/colorUtils.js +10 -11
- package/dist/jsx/colorUtils.js.map +7 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/themes.js +170 -116
- package/dist/jsx/themes.js.map +7 -0
- package/dist/jsx/tokens.js +145 -23
- package/dist/jsx/tokens.js.map +7 -0
- package/package.json +8 -5
- package/src/colorUtils.tsx +42 -0
- package/src/index.tsx +3 -0
- package/src/themes.tsx +401 -0
- package/src/tokens.tsx +195 -0
- package/types/colorUtils.d.ts +0 -0
- package/types/colorUtils.d.ts.map +0 -0
- package/types/index.d.ts +0 -0
- package/types/index.d.ts.map +0 -0
- package/types/themes.d.ts +2071 -3328
- package/types/themes.d.ts.map +1 -1
- package/types/tokens.d.ts +531 -186
- package/types/tokens.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/theme-base",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.1-beta.100",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
7
7
|
"module:jsx": "dist/jsx",
|
|
8
8
|
"files": [
|
|
9
|
+
"src",
|
|
9
10
|
"types",
|
|
10
11
|
"dist"
|
|
11
12
|
],
|
|
@@ -15,10 +16,12 @@
|
|
|
15
16
|
"clean": "tamagui-build clean",
|
|
16
17
|
"clean:build": "tamagui-build clean:build"
|
|
17
18
|
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@tamagui/colors": "^1.0.1-beta.100",
|
|
21
|
+
"@tamagui/core": "^1.0.1-beta.100"
|
|
22
|
+
},
|
|
18
23
|
"devDependencies": {
|
|
19
|
-
"@tamagui/build": "^1.0.
|
|
20
|
-
"@tamagui/colors": "^1.0.0-beta.8",
|
|
21
|
-
"@tamagui/core": "^1.0.0-beta.8"
|
|
24
|
+
"@tamagui/build": "^1.0.1-beta.100"
|
|
22
25
|
},
|
|
23
26
|
"publishConfig": {
|
|
24
27
|
"access": "public"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Variable, getVariableValue } from '@tamagui/core'
|
|
2
|
+
|
|
3
|
+
export const hexToRGBA = (hex: string, alpha = 1) => {
|
|
4
|
+
if (!isValidHex(hex)) {
|
|
5
|
+
throw new Error('Invalid HEX')
|
|
6
|
+
}
|
|
7
|
+
const chunkSize = Math.floor((hex.length - 1) / 3)
|
|
8
|
+
const hexArr = getChunksFromString(hex.slice(1), chunkSize)
|
|
9
|
+
const [r, g, b, a] = hexArr?.map(convertHexUnitTo256) ?? []
|
|
10
|
+
return `rgba(${r}, ${g}, ${b}, ${getAlphaFloat(a, alpha)})`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const setColorAlpha = (colorIn: string | Variable, alpha = 1) => {
|
|
14
|
+
let color = `${getVariableValue(colorIn)}`
|
|
15
|
+
if (color.startsWith('hsl(')) {
|
|
16
|
+
return color.replace('hsl', 'hsla').replace(')', `, ${alpha})`)
|
|
17
|
+
}
|
|
18
|
+
if (color.startsWith('#')) {
|
|
19
|
+
return hexToRGBA(color, alpha)
|
|
20
|
+
}
|
|
21
|
+
if (color.startsWith('rgb(')) {
|
|
22
|
+
return color.replace('rgb', 'rgba').replace(')', `, ${alpha})`)
|
|
23
|
+
}
|
|
24
|
+
return color
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isValidHex = (hex: string) => /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex)
|
|
28
|
+
|
|
29
|
+
const getChunksFromString = (st: string, chunkSize = 0) =>
|
|
30
|
+
st.match(new RegExp(`.{${chunkSize}}`, 'g'))
|
|
31
|
+
|
|
32
|
+
const convertHexUnitTo256 = (hexStr: string) => parseInt(hexStr.repeat(2 / hexStr.length), 16)
|
|
33
|
+
|
|
34
|
+
const getAlphaFloat = (a: any, alpha = 1) => {
|
|
35
|
+
if (a !== undefined) {
|
|
36
|
+
return a / 255
|
|
37
|
+
}
|
|
38
|
+
if (typeof alpha != 'number' || alpha < 0 || alpha > 1) {
|
|
39
|
+
return 1
|
|
40
|
+
}
|
|
41
|
+
return alpha
|
|
42
|
+
}
|
package/src/index.tsx
ADDED
package/src/themes.tsx
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { Variable, createTheme, getVariableValue, isWeb } from '@tamagui/core'
|
|
2
|
+
|
|
3
|
+
import { setColorAlpha } from './colorUtils'
|
|
4
|
+
import { darkColors, lightColors, tokens } from './tokens'
|
|
5
|
+
|
|
6
|
+
const { color } = tokens
|
|
7
|
+
|
|
8
|
+
// spaghetti ahead
|
|
9
|
+
|
|
10
|
+
type ThemeCreatorProps = {
|
|
11
|
+
shift?: number
|
|
12
|
+
backgrounds: (string | Variable)[]
|
|
13
|
+
backgroundStrong?: string | Variable
|
|
14
|
+
borderColors?: (string | Variable)[]
|
|
15
|
+
colors?: (string | Variable)[]
|
|
16
|
+
offsets?: {
|
|
17
|
+
color?: number[] | null
|
|
18
|
+
background?: number[] | null
|
|
19
|
+
borderColor?: number[] | null
|
|
20
|
+
}
|
|
21
|
+
isLight?: boolean
|
|
22
|
+
isBase?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// helpers
|
|
26
|
+
|
|
27
|
+
const alternates = [1, 2, 3, 4] as const
|
|
28
|
+
const alts = [1, 2, 3] as const
|
|
29
|
+
type AltKeys = 1 | 2 | 3
|
|
30
|
+
type AltName<Name extends string, Keys extends string | number> = `${Name}_alt${Keys}`
|
|
31
|
+
type ThemeCreator<A = any> = (str: number, props: ThemeCreatorProps) => A
|
|
32
|
+
|
|
33
|
+
function createThemesFrom<Name extends string, GetTheme extends ThemeCreator = ThemeCreator>(
|
|
34
|
+
name: Name,
|
|
35
|
+
getTheme: GetTheme,
|
|
36
|
+
props: ThemeCreatorProps
|
|
37
|
+
): {
|
|
38
|
+
[key in `${Name}_alt${AltKeys}` | `${Name}` | `${Name}_darker`]: GetTheme extends ThemeCreator<
|
|
39
|
+
infer Theme
|
|
40
|
+
>
|
|
41
|
+
? Theme
|
|
42
|
+
: never
|
|
43
|
+
} {
|
|
44
|
+
const { shift = 0 } = props
|
|
45
|
+
const theme = getTheme(0 + shift, props)
|
|
46
|
+
let themeEntries: any[] = [[name, theme]]
|
|
47
|
+
|
|
48
|
+
// generate alternates (for use in other themes), but keep just alts
|
|
49
|
+
const altThemes: any[] = alternates.map((alt) => [
|
|
50
|
+
`${name}_alt${alt}`,
|
|
51
|
+
getTheme(alt + (props.isLight ? 0 : 0) + shift, props),
|
|
52
|
+
])
|
|
53
|
+
const altThemes2: any[] = alternates.map((alt) => [
|
|
54
|
+
`${name}_alt${alt}`,
|
|
55
|
+
getTheme(alt + shift, props),
|
|
56
|
+
])
|
|
57
|
+
const altButtonThemes: any[] = alternates.map((_, i) => {
|
|
58
|
+
const [bName, bTheme] = [altThemes2[i][0], (altThemes2[i + 1] || altThemes2[i])[1]]
|
|
59
|
+
return [`${bName}_Button` as any, bTheme]
|
|
60
|
+
})
|
|
61
|
+
// add these after alts since we rely on positioning
|
|
62
|
+
const darkerTheme = getTheme(Math.max(0, shift + (props.isLight ? 1 : -1)), props)
|
|
63
|
+
const activeTheme = makeActiveTheme(theme)
|
|
64
|
+
|
|
65
|
+
// TODO can be de-duped
|
|
66
|
+
const inverted = altThemes.map(([_name, theme]) => {
|
|
67
|
+
return {
|
|
68
|
+
...theme,
|
|
69
|
+
background: theme.color,
|
|
70
|
+
backgroundHover: theme.colorHover,
|
|
71
|
+
backgroundFocus: theme.colorFocus,
|
|
72
|
+
backgroundPress: theme.colorPress,
|
|
73
|
+
color: theme.background,
|
|
74
|
+
colorHover: theme.backgroundHover,
|
|
75
|
+
colorFocus: theme.backgroundFocus,
|
|
76
|
+
colorPress: theme.backgroundPress,
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
themeEntries = [
|
|
81
|
+
...themeEntries,
|
|
82
|
+
// keep just alts
|
|
83
|
+
...altThemes.slice(0, alts.length),
|
|
84
|
+
...altButtonThemes.slice(0, alts.length),
|
|
85
|
+
[`${name}_Button`, altThemes2[1][1]],
|
|
86
|
+
[`${name}_DrawerFrame`, altThemes2[1][1]],
|
|
87
|
+
[`${name}_SliderTrack`, altThemes[0][1]],
|
|
88
|
+
[`${name}_SliderTrackActive`, altThemes[3][1]],
|
|
89
|
+
[`${name}_SliderThumb`, inverted[2]],
|
|
90
|
+
[`${name}_Progress`, altThemes[2][1]],
|
|
91
|
+
[`${name}_ProgressIndicator`, inverted[2]],
|
|
92
|
+
[`${name}_Switch`, altThemes[0][1]],
|
|
93
|
+
[`${name}_SwitchThumb`, inverted[2]],
|
|
94
|
+
[`${name}_TooltipArrow`, altThemes[1][1]],
|
|
95
|
+
[`${name}_TooltipContent`, altThemes[1][1]],
|
|
96
|
+
[`${name}_darker`, darkerTheme],
|
|
97
|
+
[`${name}_active`, activeTheme],
|
|
98
|
+
]
|
|
99
|
+
const themes = Object.fromEntries(themeEntries)
|
|
100
|
+
// if (props.isLight) {
|
|
101
|
+
// console.log('themes', themes)
|
|
102
|
+
// }
|
|
103
|
+
return themes as any
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const themeCreator = (
|
|
107
|
+
str = 1,
|
|
108
|
+
{
|
|
109
|
+
backgrounds,
|
|
110
|
+
isLight = true,
|
|
111
|
+
isBase = false,
|
|
112
|
+
colors = [...backgrounds].reverse(),
|
|
113
|
+
borderColors = isLight ? colors : backgrounds,
|
|
114
|
+
backgroundStrong,
|
|
115
|
+
offsets: offsetsProp,
|
|
116
|
+
}: ThemeCreatorProps
|
|
117
|
+
) => {
|
|
118
|
+
const offsets = {
|
|
119
|
+
borderColor: offsetsProp?.borderColor ?? offsetsProp?.background ?? [0, 0, 0, 0],
|
|
120
|
+
background: offsetsProp?.background ?? [0, 0, 0, 0],
|
|
121
|
+
color: offsetsProp?.color ?? [0, 0, 0, 0],
|
|
122
|
+
}
|
|
123
|
+
const darkColors = isLight ? colors : backgrounds
|
|
124
|
+
const lighterDir = isLight ? -1 : 1
|
|
125
|
+
const darkerDir = -lighterDir
|
|
126
|
+
const strongerDir = isLight ? darkerDir : lighterDir
|
|
127
|
+
const softerDir = -strongerDir
|
|
128
|
+
const get = (arr: any[], index: number, name = 'background') => {
|
|
129
|
+
return arr[Math.max(0, Math.min(index + (offsets[name][str] || 0), arr.length - 1))]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const colorTranslucent = setColorAlpha(getVariableValue(get(colors, 0 + str, 'color')), 0.5)
|
|
133
|
+
|
|
134
|
+
let theme = {
|
|
135
|
+
background: get(backgrounds, str),
|
|
136
|
+
backgroundStrong: backgroundStrong || get(backgrounds, str + strongerDir * 2),
|
|
137
|
+
backgroundSoft: get(backgrounds, str + softerDir * 2),
|
|
138
|
+
backgroundHover: get(backgrounds, str + lighterDir),
|
|
139
|
+
backgroundPress: get(backgrounds, str + darkerDir),
|
|
140
|
+
backgroundFocus: get(backgrounds, str + darkerDir * 2),
|
|
141
|
+
backgroundTransparent: color.grayA1Light,
|
|
142
|
+
color: get(colors, 0 + str, 'color'),
|
|
143
|
+
colorHover: get(colors, 1 + str, 'color'),
|
|
144
|
+
colorPress: get(colors, 2 + str, 'color'),
|
|
145
|
+
colorFocus: get(colors, 3 + str, 'color'),
|
|
146
|
+
colorTranslucent,
|
|
147
|
+
colorMid: (isLight ? colors : backgrounds)[Math.floor(colors.length / 2)],
|
|
148
|
+
shadowColor: isLight ? color.grayA2Light : color.grayA8Light,
|
|
149
|
+
shadowColorHover: darkColors[!isLight ? 1 : 8],
|
|
150
|
+
shadowColorPress: darkColors[!isLight ? 1 : 8],
|
|
151
|
+
shadowColorFocus: darkColors[!isLight ? 1 : 8],
|
|
152
|
+
borderColor: null as any as string | Variable,
|
|
153
|
+
borderColorHover: null as any as string | Variable,
|
|
154
|
+
borderColorPress: null as any as string | Variable,
|
|
155
|
+
borderColorFocus: null as any as string | Variable,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (process.env.ENABLE_STEPS) {
|
|
159
|
+
Object.assign(theme, {
|
|
160
|
+
step1: backgrounds[0],
|
|
161
|
+
step2: backgrounds[1],
|
|
162
|
+
step3: backgrounds[2],
|
|
163
|
+
step4: backgrounds[3],
|
|
164
|
+
step5: backgrounds[4],
|
|
165
|
+
step6: backgrounds[5],
|
|
166
|
+
step7: backgrounds[6],
|
|
167
|
+
step8: backgrounds[7],
|
|
168
|
+
step9: backgrounds[8],
|
|
169
|
+
step10: backgrounds[9],
|
|
170
|
+
step11: backgrounds[10],
|
|
171
|
+
step12: backgrounds[11],
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (isBase) {
|
|
176
|
+
Object.assign(theme, {
|
|
177
|
+
borderColor: isLight
|
|
178
|
+
? get(colors, 8 - str, 'borderColor')
|
|
179
|
+
: get(backgrounds, 2 + str, 'borderColor'),
|
|
180
|
+
borderColorHover: isLight
|
|
181
|
+
? get(colors, 6 - str, 'borderColor')
|
|
182
|
+
: get(backgrounds, 3 + str, 'borderColor'),
|
|
183
|
+
borderColorPress: isLight
|
|
184
|
+
? get(colors, 5 - str, 'borderColor')
|
|
185
|
+
: get(backgrounds, 1 + str, 'borderColor'),
|
|
186
|
+
borderColorFocus: isLight
|
|
187
|
+
? get(colors, 4 - str, 'borderColor')
|
|
188
|
+
: get(backgrounds, 3 + str, 'borderColor'),
|
|
189
|
+
})
|
|
190
|
+
} else {
|
|
191
|
+
Object.assign(theme, {
|
|
192
|
+
borderColor: get(borderColors, 1 + strongerDir, 'borderColor'),
|
|
193
|
+
borderColorHover: get(borderColors, 2 + strongerDir, 'borderColor'),
|
|
194
|
+
borderColorPress: get(borderColors, 3 + strongerDir, 'borderColor'),
|
|
195
|
+
borderColorFocus: get(borderColors, 4 + strongerDir, 'borderColor'),
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return theme
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const themeColors = {
|
|
203
|
+
light: [
|
|
204
|
+
'#fff',
|
|
205
|
+
'#f4f4f4',
|
|
206
|
+
color.gray1Light,
|
|
207
|
+
color.gray2Light,
|
|
208
|
+
color.gray3Light,
|
|
209
|
+
color.gray4Light,
|
|
210
|
+
color.gray5Light,
|
|
211
|
+
color.gray6Light,
|
|
212
|
+
color.gray7Light,
|
|
213
|
+
color.gray8Light,
|
|
214
|
+
color.gray9Light,
|
|
215
|
+
color.gray10Light,
|
|
216
|
+
color.gray11Light,
|
|
217
|
+
color.gray12Light,
|
|
218
|
+
],
|
|
219
|
+
dark: [
|
|
220
|
+
'#111111',
|
|
221
|
+
'#151515',
|
|
222
|
+
'#191919',
|
|
223
|
+
'#232323',
|
|
224
|
+
'#282828',
|
|
225
|
+
'#323232',
|
|
226
|
+
'#383838',
|
|
227
|
+
'#424242',
|
|
228
|
+
'#494949',
|
|
229
|
+
'#545454',
|
|
230
|
+
'#626262',
|
|
231
|
+
'#777777',
|
|
232
|
+
],
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const lightThemes = createThemesFrom('light', themeCreator, {
|
|
236
|
+
backgrounds: themeColors.light,
|
|
237
|
+
// for now web non-ios style native is...
|
|
238
|
+
backgroundStrong: isWeb ? '#fefefe' : '#f2f2f2',
|
|
239
|
+
borderColors: themeColors.light.slice(2),
|
|
240
|
+
isLight: true,
|
|
241
|
+
offsets: {
|
|
242
|
+
background: [2, 2, 2, 2, 2, 2],
|
|
243
|
+
},
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const darkThemes = createThemesFrom('dark', themeCreator, {
|
|
247
|
+
backgrounds: themeColors.dark,
|
|
248
|
+
colors: themeColors.light.slice(2),
|
|
249
|
+
backgroundStrong: '#070707',
|
|
250
|
+
isBase: true,
|
|
251
|
+
isLight: false,
|
|
252
|
+
shift: 1,
|
|
253
|
+
offsets: {
|
|
254
|
+
color: [0, 4, 5, 5, 5, 5],
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
darkThemes.dark_darker.background = '#030303'
|
|
259
|
+
darkThemes.dark_darker.backgroundStrong = '#000'
|
|
260
|
+
|
|
261
|
+
const light = createTheme({
|
|
262
|
+
...lightColors,
|
|
263
|
+
...lightThemes.light,
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
const dark = createTheme({
|
|
267
|
+
...darkColors,
|
|
268
|
+
...darkThemes.dark,
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
type ThemeBase = {
|
|
272
|
+
[Key in keyof typeof dark]: string
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const baseThemes = {
|
|
276
|
+
// light
|
|
277
|
+
...lightThemes,
|
|
278
|
+
light,
|
|
279
|
+
light_active: makeActiveTheme(lightThemes.light),
|
|
280
|
+
light_Card: lightThemes.light,
|
|
281
|
+
light_SliderTrack: lightThemes.light_alt2,
|
|
282
|
+
light_SliderTrackActive: lightThemes.light_alt3,
|
|
283
|
+
light_Switch: lightThemes.light_alt1,
|
|
284
|
+
light_SwitchThumb: darkThemes.dark,
|
|
285
|
+
light_DrawerFrame: lightThemes.light_alt1,
|
|
286
|
+
|
|
287
|
+
// dark
|
|
288
|
+
...darkThemes,
|
|
289
|
+
dark,
|
|
290
|
+
dark_active: makeActiveTheme(darkThemes.dark),
|
|
291
|
+
dark_Card: darkThemes.dark,
|
|
292
|
+
dark_DrawerFrame: darkThemes.dark_alt2,
|
|
293
|
+
dark_SliderTrack: darkThemes.dark_darker,
|
|
294
|
+
dark_SliderTrackActive: darkThemes.dark_alt3,
|
|
295
|
+
dark_Switch: darkThemes.dark_darker,
|
|
296
|
+
dark_SwitchThumb: lightThemes.light_alt3,
|
|
297
|
+
dark_Button: darkThemes.dark_alt1,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function makeActiveTheme(theme: any) {
|
|
301
|
+
const res = { ...theme }
|
|
302
|
+
res.backgroundHover = res.background
|
|
303
|
+
res.colorHover = res.color
|
|
304
|
+
res.backgroundPress = res.background
|
|
305
|
+
res.colorPress = res.color
|
|
306
|
+
return res
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const darkEntries = Object.entries(dark)
|
|
310
|
+
const lightEntries = Object.entries(light)
|
|
311
|
+
function findColors(prefix: string, dark = false): ThemeBase {
|
|
312
|
+
return Object.fromEntries(
|
|
313
|
+
(dark ? darkEntries : lightEntries).filter(([k]) => k.startsWith(prefix))
|
|
314
|
+
) as any
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export const colorSchemes = [
|
|
318
|
+
{ name: 'blue', colors: findColors('blue'), darkColors: findColors('blue', true) },
|
|
319
|
+
{ name: 'gray', colors: findColors('gray'), darkColors: findColors('gray', true) },
|
|
320
|
+
{ name: 'green', colors: findColors('green'), darkColors: findColors('green', true) },
|
|
321
|
+
{ name: 'orange', colors: findColors('orange'), darkColors: findColors('orange', true) },
|
|
322
|
+
{ name: 'pink', colors: findColors('pink'), darkColors: findColors('pink', true) },
|
|
323
|
+
{ name: 'purple', colors: findColors('purple'), darkColors: findColors('purple', true) },
|
|
324
|
+
{ name: 'red', colors: findColors('red'), darkColors: findColors('red', true) },
|
|
325
|
+
{ name: 'yellow', colors: findColors('yellow'), darkColors: findColors('yellow', true) },
|
|
326
|
+
{ name: 'teal', colors: findColors('teal'), darkColors: findColors('teal', true) },
|
|
327
|
+
] as const
|
|
328
|
+
|
|
329
|
+
export type ColorNames = typeof colorSchemes[number]['name']
|
|
330
|
+
|
|
331
|
+
// nice and flat
|
|
332
|
+
export const colorNames: ColorNames[] = [
|
|
333
|
+
'blue',
|
|
334
|
+
'gray',
|
|
335
|
+
'green',
|
|
336
|
+
'orange',
|
|
337
|
+
'pink',
|
|
338
|
+
'purple',
|
|
339
|
+
'red',
|
|
340
|
+
'yellow',
|
|
341
|
+
'teal',
|
|
342
|
+
]
|
|
343
|
+
|
|
344
|
+
type ColorThemeNames =
|
|
345
|
+
| ColorNames
|
|
346
|
+
| AltName<`light_${ColorNames}`, AltKeys>
|
|
347
|
+
| AltName<`dark_${ColorNames}`, AltKeys>
|
|
348
|
+
|
|
349
|
+
const colorThemeEntries = colorSchemes.flatMap(({ name, colors, darkColors }) => {
|
|
350
|
+
const [altLightThemes, altDarkThemes] = [
|
|
351
|
+
{ colors: darkColors, backgrounds: colors },
|
|
352
|
+
{ colors, backgrounds: darkColors },
|
|
353
|
+
].map((props, i) => {
|
|
354
|
+
const isLight = i === 0
|
|
355
|
+
const colorsBase = Object.values(props.colors).slice(2)
|
|
356
|
+
const [backgrounds, colors] = [
|
|
357
|
+
Object.values(props.backgrounds),
|
|
358
|
+
isLight ? colorsBase : [colorsBase[0], '#ccc', ...colorsBase.slice(1)],
|
|
359
|
+
] as const
|
|
360
|
+
|
|
361
|
+
const scheme = isLight ? 'light' : 'dark'
|
|
362
|
+
const shift = isLight ? 0 : 1
|
|
363
|
+
|
|
364
|
+
// if (!isLight) {
|
|
365
|
+
// const [_, h, sp, lp] = backgrounds[0].match(/hsl\(([0-9\.]+), ([0-9\.]+)\%, ([0-9\.]+)\%\)/)!
|
|
366
|
+
// backgrounds.unshift(`hsl(${h}, ${sp}%, ${parseFloat(lp) / 2}%)`)
|
|
367
|
+
// }
|
|
368
|
+
|
|
369
|
+
const themeWithAlts = createThemesFrom(name, themeCreator, {
|
|
370
|
+
colors,
|
|
371
|
+
backgrounds,
|
|
372
|
+
borderColors: backgrounds,
|
|
373
|
+
isLight,
|
|
374
|
+
shift,
|
|
375
|
+
isBase: false,
|
|
376
|
+
offsets: {
|
|
377
|
+
background: isLight ? [2, 2, 2, 2, 2, 2] : null,
|
|
378
|
+
borderColor: isLight ? [2, 2, 2, 3, 2] : null,
|
|
379
|
+
color: isLight ? [0, 0, -1, -2, -3, -3, -4] : [-1, -1, -1, -1, -1, -1],
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
return Object.entries(themeWithAlts).map(([k, v]) => [`${scheme}_${k}`, v])
|
|
384
|
+
})
|
|
385
|
+
return [...altLightThemes, ...altDarkThemes]
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
type MyThemeBase = typeof baseThemes['light_alt1']
|
|
389
|
+
|
|
390
|
+
const colorThemes: {
|
|
391
|
+
[key in ColorThemeNames]: MyThemeBase
|
|
392
|
+
} = Object.fromEntries(colorThemeEntries) as any
|
|
393
|
+
|
|
394
|
+
const allThemes = {
|
|
395
|
+
...baseThemes,
|
|
396
|
+
...colorThemes,
|
|
397
|
+
} as const
|
|
398
|
+
|
|
399
|
+
export const themes: {
|
|
400
|
+
[key in keyof typeof allThemes]: typeof baseThemes['light']
|
|
401
|
+
} = allThemes as any
|
package/src/tokens.tsx
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
blue,
|
|
3
|
+
blueDark,
|
|
4
|
+
gray,
|
|
5
|
+
grayA,
|
|
6
|
+
grayDark,
|
|
7
|
+
grayDarkA,
|
|
8
|
+
green,
|
|
9
|
+
greenDark,
|
|
10
|
+
orange,
|
|
11
|
+
orangeDark,
|
|
12
|
+
pink,
|
|
13
|
+
pinkDark,
|
|
14
|
+
purple,
|
|
15
|
+
purpleDark,
|
|
16
|
+
red,
|
|
17
|
+
redDark,
|
|
18
|
+
teal,
|
|
19
|
+
tealDark,
|
|
20
|
+
violet,
|
|
21
|
+
violetDark,
|
|
22
|
+
yellow,
|
|
23
|
+
yellowDark,
|
|
24
|
+
} from '@tamagui/colors'
|
|
25
|
+
import { Variable, createTokens } from '@tamagui/core'
|
|
26
|
+
|
|
27
|
+
// should roughly map to button/input etc height at each level
|
|
28
|
+
// fonts should match that height/lineHeight at each stop
|
|
29
|
+
// so these are really non-linear on purpose
|
|
30
|
+
// why?
|
|
31
|
+
// - at sizes <1, used for fine grained things (borders, smallest paddingY)
|
|
32
|
+
// - so smallest padY should be roughly 1-4px so it can join with lineHeight
|
|
33
|
+
// - at sizes >=1, have to consider "pressability" (jumps up)
|
|
34
|
+
// - after that it should go upwards somewhat naturally
|
|
35
|
+
// - H1 / headings top out at 10 naturally, so after 10 we can go upwards faster
|
|
36
|
+
// but also one more wrinkle...
|
|
37
|
+
// space is used in conjunction with size
|
|
38
|
+
// i'm setting space to generally just a fixed fraction of size (~1/3-2/3 still fine tuning)
|
|
39
|
+
const size = {
|
|
40
|
+
0: 0,
|
|
41
|
+
0.25: 2,
|
|
42
|
+
0.5: 4,
|
|
43
|
+
0.75: 8,
|
|
44
|
+
1: 20,
|
|
45
|
+
1.5: 24,
|
|
46
|
+
2: 28,
|
|
47
|
+
2.5: 32,
|
|
48
|
+
3: 36,
|
|
49
|
+
3.5: 40,
|
|
50
|
+
4: 44,
|
|
51
|
+
true: 44,
|
|
52
|
+
4.5: 48,
|
|
53
|
+
5: 52,
|
|
54
|
+
5.5: 59,
|
|
55
|
+
6: 64,
|
|
56
|
+
6.5: 69,
|
|
57
|
+
7: 74,
|
|
58
|
+
7.6: 79,
|
|
59
|
+
8: 84,
|
|
60
|
+
8.5: 89,
|
|
61
|
+
9: 94,
|
|
62
|
+
9.5: 99,
|
|
63
|
+
10: 104,
|
|
64
|
+
11: 124,
|
|
65
|
+
12: 144,
|
|
66
|
+
13: 164,
|
|
67
|
+
14: 184,
|
|
68
|
+
15: 204,
|
|
69
|
+
16: 224,
|
|
70
|
+
17: 224,
|
|
71
|
+
18: 244,
|
|
72
|
+
19: 264,
|
|
73
|
+
20: 284,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type Sizes = typeof size
|
|
77
|
+
type SizeKeys = `${keyof Sizes}`
|
|
78
|
+
|
|
79
|
+
const spaces = Object.entries(size).map(([k, v]) => [
|
|
80
|
+
k,
|
|
81
|
+
Math.max(0, v <= 16 ? Math.round(v * 0.333) : Math.floor(v * 0.7 - 12)),
|
|
82
|
+
])
|
|
83
|
+
|
|
84
|
+
const spacesNegative = spaces.map(([k, v]) => [`-${k}`, -v])
|
|
85
|
+
|
|
86
|
+
const space: {
|
|
87
|
+
[Key in `-${SizeKeys}` | SizeKeys]: Key extends keyof Sizes ? Sizes[Key] : number
|
|
88
|
+
} = {
|
|
89
|
+
...Object.fromEntries(spaces),
|
|
90
|
+
...Object.fromEntries(spacesNegative),
|
|
91
|
+
} as any
|
|
92
|
+
|
|
93
|
+
const zIndex = {
|
|
94
|
+
0: 0,
|
|
95
|
+
1: 100,
|
|
96
|
+
2: 200,
|
|
97
|
+
3: 300,
|
|
98
|
+
4: 400,
|
|
99
|
+
5: 500,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const colorTokens = {
|
|
103
|
+
light: {
|
|
104
|
+
blue: blue,
|
|
105
|
+
gray: gray,
|
|
106
|
+
grayA: grayA,
|
|
107
|
+
green: green,
|
|
108
|
+
orange: orange,
|
|
109
|
+
pink: pink,
|
|
110
|
+
purple: purple,
|
|
111
|
+
red: red,
|
|
112
|
+
violet: violet,
|
|
113
|
+
yellow: yellow,
|
|
114
|
+
teal: teal,
|
|
115
|
+
},
|
|
116
|
+
dark: {
|
|
117
|
+
blue: blueDark,
|
|
118
|
+
gray: grayDark,
|
|
119
|
+
grayA: grayDarkA,
|
|
120
|
+
green: greenDark,
|
|
121
|
+
orange: orangeDark,
|
|
122
|
+
pink: pinkDark,
|
|
123
|
+
purple: purpleDark,
|
|
124
|
+
red: redDark,
|
|
125
|
+
violet: violetDark,
|
|
126
|
+
yellow: yellowDark,
|
|
127
|
+
teal: tealDark,
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const darkColors = {
|
|
132
|
+
...colorTokens.dark.blue,
|
|
133
|
+
...colorTokens.dark.gray,
|
|
134
|
+
...colorTokens.dark.grayA,
|
|
135
|
+
...colorTokens.dark.green,
|
|
136
|
+
...colorTokens.dark.orange,
|
|
137
|
+
...colorTokens.dark.pink,
|
|
138
|
+
...colorTokens.dark.purple,
|
|
139
|
+
...colorTokens.dark.red,
|
|
140
|
+
...colorTokens.dark.violet,
|
|
141
|
+
...colorTokens.dark.yellow,
|
|
142
|
+
...colorTokens.dark.teal,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const lightColors = {
|
|
146
|
+
...colorTokens.light.blue,
|
|
147
|
+
...colorTokens.light.gray,
|
|
148
|
+
...colorTokens.light.grayA,
|
|
149
|
+
...colorTokens.light.green,
|
|
150
|
+
...colorTokens.light.orange,
|
|
151
|
+
...colorTokens.light.pink,
|
|
152
|
+
...colorTokens.light.purple,
|
|
153
|
+
...colorTokens.light.red,
|
|
154
|
+
...colorTokens.light.violet,
|
|
155
|
+
...colorTokens.light.yellow,
|
|
156
|
+
...colorTokens.light.teal,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const allColors = {
|
|
160
|
+
...postfixObjKeys(lightColors, 'Light'),
|
|
161
|
+
...postfixObjKeys(darkColors, 'Dark'),
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function postfixObjKeys<A extends { [key: string]: Variable<string> | string }, B extends string>(
|
|
165
|
+
obj: A,
|
|
166
|
+
postfix: B
|
|
167
|
+
): {
|
|
168
|
+
[Key in `${keyof A extends string ? keyof A : never}${B}`]: Variable<string> | string
|
|
169
|
+
} {
|
|
170
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [`${k}${postfix}`, v])) as any
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const radius = {
|
|
174
|
+
0: 0,
|
|
175
|
+
1: 3,
|
|
176
|
+
2: 5,
|
|
177
|
+
3: 7,
|
|
178
|
+
4: 9,
|
|
179
|
+
5: 10,
|
|
180
|
+
6: 16,
|
|
181
|
+
7: 19,
|
|
182
|
+
8: 22,
|
|
183
|
+
9: 26,
|
|
184
|
+
10: 34,
|
|
185
|
+
11: 42,
|
|
186
|
+
12: 50,
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const tokens = createTokens({
|
|
190
|
+
color: allColors,
|
|
191
|
+
radius,
|
|
192
|
+
zIndex,
|
|
193
|
+
space,
|
|
194
|
+
size,
|
|
195
|
+
})
|
package/types/colorUtils.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/types/index.d.ts
CHANGED
|
File without changes
|
package/types/index.d.ts.map
CHANGED
|
File without changes
|