@tamagui/themes 1.14.9 → 1.15.0
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/index.js.map +2 -2
- package/dist/cjs/themes.js +94 -74
- package/dist/cjs/themes.js.map +3 -3
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs.map +2 -2
- package/dist/esm/themes.js +96 -75
- package/dist/esm/themes.js.map +3 -3
- package/dist/esm/themes.mjs +96 -75
- package/dist/esm/themes.mjs.map +3 -3
- package/package.json +13 -7
- package/src/generate.ts +25 -0
- package/src/generated.js +23954 -0
- package/src/index.tsx +8 -0
- package/src/themes.tsx +117 -82
- package/types/generate.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/themes.d.ts +7460 -7460
- package/types/themes.d.ts.map +1 -1
package/src/index.tsx
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// import generatedThemes from './generated'
|
|
2
|
+
// import { themes as runtimeThemes } from './themes'
|
|
3
|
+
|
|
4
|
+
// export const themes =
|
|
5
|
+
// process.env.NODE_ENV === 'development'
|
|
6
|
+
// ? runtimeThemes
|
|
7
|
+
// : (generatedThemes as typeof runtimeThemes)
|
|
8
|
+
|
|
1
9
|
export * from './themes'
|
|
2
10
|
export * from './tokens'
|
|
3
11
|
export * from '@tamagui/colors'
|
package/src/themes.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
createStrengthenMask,
|
|
6
6
|
createTheme,
|
|
7
7
|
createWeakenMask,
|
|
8
|
+
skipMask,
|
|
8
9
|
} from '@tamagui/create-theme'
|
|
9
10
|
|
|
10
11
|
import { colorTokens, darkColors, lightColors } from './tokens'
|
|
@@ -72,16 +73,29 @@ const templateShadows = {
|
|
|
72
73
|
shadowColorFocus: 2,
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
// we can use subset of our template as a "
|
|
76
|
-
|
|
76
|
+
// we can use subset of our template as a "override" so it doesn't get adjusted with masks
|
|
77
|
+
// we want to skip over templateColor + templateShadows
|
|
78
|
+
const toSkip = {
|
|
77
79
|
...templateColors,
|
|
78
80
|
...templateShadows,
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
const override = Object.fromEntries(Object.entries(toSkip).map(([k]) => [k, 0]))
|
|
84
|
+
const overrideShadows = Object.fromEntries(
|
|
85
|
+
Object.entries(templateShadows).map(([k]) => [k, 0])
|
|
86
|
+
)
|
|
87
|
+
const overrideWithColors = {
|
|
88
|
+
...override,
|
|
89
|
+
color: 0,
|
|
90
|
+
colorHover: 0,
|
|
91
|
+
colorFocus: 0,
|
|
92
|
+
colorPress: 0,
|
|
93
|
+
}
|
|
94
|
+
|
|
81
95
|
// templates use the palette and specify index
|
|
82
96
|
// negative goes backwards from end so -1 is the last item
|
|
83
97
|
const template = {
|
|
84
|
-
...
|
|
98
|
+
...toSkip,
|
|
85
99
|
// the background, color, etc keys here work like generics - they make it so you
|
|
86
100
|
// can publish components for others to use without mandating a specific color scale
|
|
87
101
|
// the @tamagui/button Button component looks for `$background`, so you set the
|
|
@@ -149,30 +163,29 @@ const baseThemes: {
|
|
|
149
163
|
}
|
|
150
164
|
|
|
151
165
|
const masks = {
|
|
166
|
+
skip: skipMask,
|
|
152
167
|
weaker: createWeakenMask(),
|
|
153
168
|
stronger: createStrengthenMask(),
|
|
154
169
|
}
|
|
155
170
|
|
|
156
171
|
// default mask options for most uses
|
|
157
172
|
const maskOptions: MaskOptions = {
|
|
158
|
-
|
|
173
|
+
override,
|
|
174
|
+
skip: toSkip,
|
|
159
175
|
// avoids the transparent ends
|
|
160
176
|
max: palettes.light.length - 2,
|
|
161
177
|
min: 1,
|
|
162
178
|
}
|
|
163
179
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
colorTokens[name],
|
|
174
|
-
colorTokens[inverseName],
|
|
175
|
-
].map((colorSet) => {
|
|
180
|
+
const transparent = (hsl: string, opacity = 0) =>
|
|
181
|
+
hsl.replace(`%)`, `%, ${opacity})`).replace(`hsl(`, `hsla(`)
|
|
182
|
+
|
|
183
|
+
// setup colorThemes and their inverses
|
|
184
|
+
const [lightColorThemes, darkColorThemes] = [colorTokens.light, colorTokens.dark].map(
|
|
185
|
+
(colorSet, i) => {
|
|
186
|
+
const isLight = i === 0
|
|
187
|
+
const theme = baseThemes[isLight ? 'light' : 'dark']
|
|
188
|
+
|
|
176
189
|
return Object.fromEntries(
|
|
177
190
|
Object.keys(colorSet).map((color) => {
|
|
178
191
|
const colorPalette = Object.values(colorSet[color]) as string[]
|
|
@@ -191,6 +204,7 @@ const allThemes = addChildren(baseThemes, (name, theme) => {
|
|
|
191
204
|
theme.color,
|
|
192
205
|
transparent(colorPalette[colorPalette.length - 1]),
|
|
193
206
|
]
|
|
207
|
+
|
|
194
208
|
const colorTheme = createTheme(
|
|
195
209
|
palette,
|
|
196
210
|
isLight
|
|
@@ -204,93 +218,114 @@ const allThemes = addChildren(baseThemes, (name, theme) => {
|
|
|
204
218
|
}
|
|
205
219
|
: darkTemplate
|
|
206
220
|
)
|
|
221
|
+
|
|
207
222
|
return [color, colorTheme]
|
|
208
223
|
})
|
|
209
224
|
) as Record<ColorName, SubTheme>
|
|
210
|
-
}
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
const allThemes = addChildren(baseThemes, (name, theme) => {
|
|
229
|
+
const isLight = name === 'light'
|
|
230
|
+
const inverseName = isLight ? 'dark' : 'light'
|
|
231
|
+
const inverseTheme = baseThemes[inverseName]
|
|
232
|
+
const colorThemes = isLight ? lightColorThemes : darkColorThemes
|
|
233
|
+
const inverseColorThemes = isLight ? darkColorThemes : lightColorThemes
|
|
211
234
|
|
|
212
235
|
const allColorThemes = addChildren(colorThemes, (colorName, colorTheme) => {
|
|
213
236
|
const inverse = inverseColorThemes[colorName]
|
|
214
237
|
return {
|
|
215
|
-
...getAltThemes(colorTheme, inverse),
|
|
216
|
-
...getComponentThemes(colorTheme, inverse),
|
|
238
|
+
...getAltThemes(colorTheme, inverse, isLight),
|
|
239
|
+
...getComponentThemes(colorTheme, inverse, isLight),
|
|
217
240
|
}
|
|
218
241
|
})
|
|
219
242
|
|
|
220
|
-
const baseActiveTheme = applyMask(colorThemes.blue, masks.weaker, {
|
|
221
|
-
...maskOptions,
|
|
222
|
-
strength: 4,
|
|
223
|
-
})
|
|
224
|
-
|
|
225
243
|
const baseSubThemes = {
|
|
226
|
-
...getAltThemes(
|
|
227
|
-
|
|
244
|
+
...getAltThemes(
|
|
245
|
+
theme,
|
|
246
|
+
inverseTheme,
|
|
247
|
+
isLight,
|
|
248
|
+
process.env.ACTIVE_THEME_INVERSE ? inverseTheme : undefined
|
|
249
|
+
),
|
|
250
|
+
...getComponentThemes(theme, inverseTheme, isLight),
|
|
228
251
|
}
|
|
229
252
|
|
|
230
253
|
return {
|
|
231
254
|
...baseSubThemes,
|
|
232
255
|
...allColorThemes,
|
|
233
256
|
}
|
|
257
|
+
})
|
|
234
258
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
applyMask(theme, masks.weaker, {
|
|
245
|
-
...maskOptions,
|
|
246
|
-
strength: 4,
|
|
247
|
-
})
|
|
248
|
-
return addChildren({ alt1, alt2, active }, (_, subTheme) => {
|
|
249
|
-
return getComponentThemes(subTheme, subTheme === inverse ? theme : inverse)
|
|
250
|
-
})
|
|
259
|
+
function getAltThemes(
|
|
260
|
+
theme: SubTheme,
|
|
261
|
+
inverse: SubTheme,
|
|
262
|
+
isLight: boolean,
|
|
263
|
+
activeTheme?: SubTheme
|
|
264
|
+
) {
|
|
265
|
+
const maskOptionsAlt = {
|
|
266
|
+
...maskOptions,
|
|
267
|
+
override: overrideShadows,
|
|
251
268
|
}
|
|
269
|
+
const alt1 = applyMask(theme, masks.weaker, maskOptionsAlt)
|
|
270
|
+
const alt2 = applyMask(alt1, masks.weaker, maskOptionsAlt)
|
|
271
|
+
const active =
|
|
272
|
+
activeTheme ??
|
|
273
|
+
(process.env.ACTIVE_THEME_INVERSE
|
|
274
|
+
? inverse
|
|
275
|
+
: applyMask(theme, masks.weaker, {
|
|
276
|
+
...maskOptions,
|
|
277
|
+
strength: 4,
|
|
278
|
+
}))
|
|
252
279
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
280
|
+
return addChildren({ alt1, alt2, active }, (_, subTheme) => {
|
|
281
|
+
return getComponentThemes(subTheme, subTheme === inverse ? theme : inverse, isLight)
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getComponentThemes(theme: SubTheme, inverse: SubTheme, isLight: boolean) {
|
|
286
|
+
const weaker1 = applyMask(theme, masks.weaker, maskOptions)
|
|
287
|
+
const weaker2 = applyMask(weaker1, masks.weaker, {
|
|
288
|
+
...maskOptions,
|
|
289
|
+
override: overrideWithColors,
|
|
290
|
+
})
|
|
291
|
+
const stronger1 = applyMask(theme, masks.stronger, maskOptions)
|
|
292
|
+
const inverse1 = applyMask(inverse, masks.weaker, maskOptions)
|
|
293
|
+
const inverse2 = applyMask(inverse1, masks.weaker, maskOptions)
|
|
294
|
+
const strongerBorderLighterBackground: SubTheme = isLight
|
|
295
|
+
? {
|
|
296
|
+
...stronger1,
|
|
297
|
+
borderColor: weaker1.borderColor,
|
|
298
|
+
borderColorHover: weaker1.borderColorHover,
|
|
299
|
+
borderColorPress: weaker1.borderColorPress,
|
|
300
|
+
borderColorFocus: weaker1.borderColorFocus,
|
|
301
|
+
}
|
|
302
|
+
: {
|
|
303
|
+
...applyMask(theme, masks.skip, maskOptions),
|
|
304
|
+
borderColor: weaker1.borderColor,
|
|
305
|
+
borderColorHover: weaker1.borderColorHover,
|
|
306
|
+
borderColorPress: weaker1.borderColorPress,
|
|
307
|
+
borderColorFocus: weaker1.borderColorFocus,
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
Card: weaker1,
|
|
312
|
+
Button: weaker2,
|
|
313
|
+
Checkbox: weaker2,
|
|
314
|
+
DrawerFrame: weaker1,
|
|
315
|
+
SliderTrack: stronger1,
|
|
316
|
+
SliderTrackActive: weaker2,
|
|
317
|
+
SliderThumb: inverse1,
|
|
318
|
+
Progress: weaker1,
|
|
319
|
+
ProgressIndicator: inverse,
|
|
320
|
+
Switch: weaker2,
|
|
321
|
+
SwitchThumb: inverse2,
|
|
322
|
+
TooltipArrow: weaker1,
|
|
323
|
+
TooltipContent: weaker2,
|
|
324
|
+
Input: strongerBorderLighterBackground,
|
|
325
|
+
TextArea: strongerBorderLighterBackground,
|
|
326
|
+
Tooltip: inverse1,
|
|
292
327
|
}
|
|
293
|
-
}
|
|
328
|
+
}
|
|
294
329
|
|
|
295
330
|
export const themes = {
|
|
296
331
|
...allThemes,
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAQA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA"}
|