@tamagui/themes 1.101.6 → 1.102.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.
@@ -83,7 +83,7 @@ const colorTokens = {
83
83
  ...postfixObjKeys(lightColors, "Light"),
84
84
  ...postfixObjKeys(darkColors, "Dark")
85
85
  },
86
- palettes = (() => {
86
+ defaultPalettes = (() => {
87
87
  const transparent = (hsl, opacity = 0) => hsl.replace("%)", `%, ${opacity})`).replace("hsl(", "hsla("),
88
88
  getColorPalette = (colors, accentColors) => {
89
89
  const colorPalette = Object.values(colors),
@@ -113,156 +113,159 @@ const colorTokens = {
113
113
  ...colorPalettes
114
114
  };
115
115
  })(),
116
- getTemplates = scheme => {
117
- const isLight = scheme === "light",
118
- bgIndex = 5,
119
- lighten = isLight ? -1 : 1,
120
- darken = -lighten,
121
- borderColor = bgIndex + 3,
122
- base = {
123
- accentBackground: 0,
124
- accentColor: -0,
125
- background0: 1,
126
- background025: 2,
127
- background05: 3,
128
- background075: 4,
129
- color1: bgIndex,
130
- color2: bgIndex + 1,
131
- color3: bgIndex + 2,
132
- color4: bgIndex + 3,
133
- color5: bgIndex + 4,
134
- color6: bgIndex + 5,
135
- color7: bgIndex + 6,
136
- color8: bgIndex + 7,
137
- color9: bgIndex + 8,
138
- color10: bgIndex + 9,
139
- color11: bgIndex + 10,
140
- color12: bgIndex + 11,
141
- color0: -1,
142
- color025: -2,
143
- color05: -3,
144
- color075: -4,
145
- // the background, color, etc keys here work like generics - they make it so you
146
- // can publish components for others to use without mandating a specific color scale
147
- // the @tamagui/button Button component looks for `$background`, so you set the
148
- // dark_red_Button theme to have a stronger background than the dark_red theme.
149
- background: bgIndex,
150
- backgroundHover: bgIndex + lighten,
151
- // always lighten on hover no matter the scheme
152
- backgroundPress: bgIndex + darken,
153
- // always darken on press no matter the theme
154
- backgroundFocus: bgIndex + darken,
155
- borderColor,
156
- borderColorHover: borderColor + lighten,
157
- borderColorPress: borderColor + darken,
158
- borderColorFocus: borderColor,
159
- color: -bgIndex,
160
- colorHover: -bgIndex - 1,
161
- colorPress: -bgIndex,
162
- colorFocus: -bgIndex - 1,
163
- colorTransparent: -1,
164
- placeholderColor: -bgIndex - 3,
165
- outlineColor: -2
116
+ getTemplates = () => {
117
+ const getBaseTemplates = scheme => {
118
+ const isLight = scheme === "light",
119
+ bgIndex = 5,
120
+ lighten = isLight ? -1 : 1,
121
+ darken = -lighten,
122
+ borderColor = bgIndex + 3,
123
+ base = {
124
+ accentBackground: 0,
125
+ accentColor: -0,
126
+ background0: 1,
127
+ background025: 2,
128
+ background05: 3,
129
+ background075: 4,
130
+ color1: bgIndex,
131
+ color2: bgIndex + 1,
132
+ color3: bgIndex + 2,
133
+ color4: bgIndex + 3,
134
+ color5: bgIndex + 4,
135
+ color6: bgIndex + 5,
136
+ color7: bgIndex + 6,
137
+ color8: bgIndex + 7,
138
+ color9: bgIndex + 8,
139
+ color10: bgIndex + 9,
140
+ color11: bgIndex + 10,
141
+ color12: bgIndex + 11,
142
+ color0: -1,
143
+ color025: -2,
144
+ color05: -3,
145
+ color075: -4,
146
+ // the background, color, etc keys here work like generics - they make it so you
147
+ // can publish components for others to use without mandating a specific color scale
148
+ // the @tamagui/button Button component looks for `$background`, so you set the
149
+ // dark_red_Button theme to have a stronger background than the dark_red theme.
150
+ background: bgIndex,
151
+ backgroundHover: bgIndex + lighten,
152
+ // always lighten on hover no matter the scheme
153
+ backgroundPress: bgIndex + darken,
154
+ // always darken on press no matter the theme
155
+ backgroundFocus: bgIndex + darken,
156
+ borderColor,
157
+ borderColorHover: borderColor + lighten,
158
+ borderColorPress: borderColor + darken,
159
+ borderColorFocus: borderColor,
160
+ color: -bgIndex,
161
+ colorHover: -bgIndex - 1,
162
+ colorPress: -bgIndex,
163
+ colorFocus: -bgIndex - 1,
164
+ colorTransparent: -1,
165
+ placeholderColor: -bgIndex - 3,
166
+ outlineColor: -2
167
+ },
168
+ surface12 = {
169
+ background: base.background + 1,
170
+ backgroundHover: base.backgroundHover + 1,
171
+ backgroundPress: base.backgroundPress + 1,
172
+ backgroundFocus: base.backgroundFocus + 1,
173
+ borderColor: base.borderColor + 1,
174
+ borderColorHover: base.borderColorHover + 1,
175
+ borderColorFocus: base.borderColorFocus + 1,
176
+ borderColorPress: base.borderColorPress + 1
177
+ },
178
+ surface22 = {
179
+ background: base.background + 2,
180
+ backgroundHover: base.backgroundHover + 2,
181
+ backgroundPress: base.backgroundPress + 2,
182
+ backgroundFocus: base.backgroundFocus + 2,
183
+ borderColor: base.borderColor + 2,
184
+ borderColorHover: base.borderColorHover + 2,
185
+ borderColorFocus: base.borderColorFocus + 2,
186
+ borderColorPress: base.borderColorPress + 2
187
+ },
188
+ surface32 = {
189
+ background: base.background + 3,
190
+ backgroundHover: base.backgroundHover + 3,
191
+ backgroundPress: base.backgroundPress + 3,
192
+ backgroundFocus: base.backgroundFocus + 3,
193
+ borderColor: base.borderColor + 3,
194
+ borderColorHover: base.borderColorHover + 3,
195
+ borderColorFocus: base.borderColorFocus + 3,
196
+ borderColorPress: base.borderColorPress + 3
197
+ },
198
+ surfaceActiveBg = {
199
+ background: base.background + 5,
200
+ backgroundHover: base.background + 5,
201
+ backgroundPress: base.backgroundPress + 5,
202
+ backgroundFocus: base.backgroundFocus + 5
203
+ },
204
+ surfaceActive = {
205
+ ...surfaceActiveBg,
206
+ // match border to background when active
207
+ borderColor: surfaceActiveBg.background,
208
+ borderColorHover: surfaceActiveBg.backgroundHover,
209
+ borderColorFocus: surfaceActiveBg.backgroundFocus,
210
+ borderColorPress: surfaceActiveBg.backgroundPress
211
+ },
212
+ inverseSurface12 = {
213
+ color: surface12.background,
214
+ colorHover: surface12.backgroundHover,
215
+ colorPress: surface12.backgroundPress,
216
+ colorFocus: surface12.backgroundFocus,
217
+ background: base.color,
218
+ backgroundHover: base.colorHover,
219
+ backgroundPress: base.colorPress,
220
+ backgroundFocus: base.colorFocus,
221
+ borderColor: base.color - 2,
222
+ borderColorHover: base.color - 3,
223
+ borderColorFocus: base.color - 4,
224
+ borderColorPress: base.color - 5
225
+ },
226
+ inverseActive = {
227
+ ...inverseSurface12,
228
+ background: base.color - 2,
229
+ backgroundHover: base.colorHover - 2,
230
+ backgroundPress: base.colorPress - 2,
231
+ backgroundFocus: base.colorFocus - 2,
232
+ borderColor: base.color - 2 - 2,
233
+ borderColorHover: base.color - 3 - 2,
234
+ borderColorFocus: base.color - 4 - 2,
235
+ borderColorPress: base.color - 5 - 2
236
+ },
237
+ alt1 = {
238
+ color: base.color - 1,
239
+ colorHover: base.colorHover - 1,
240
+ colorPress: base.colorPress - 1,
241
+ colorFocus: base.colorFocus - 1
242
+ },
243
+ alt2 = {
244
+ color: base.color - 2,
245
+ colorHover: base.colorHover - 2,
246
+ colorPress: base.colorPress - 2,
247
+ colorFocus: base.colorFocus - 2
248
+ };
249
+ return {
250
+ base,
251
+ alt1,
252
+ alt2,
253
+ surface1: surface12,
254
+ surface2: surface22,
255
+ surface3: surface32,
256
+ inverseSurface1: inverseSurface12,
257
+ inverseActive,
258
+ surfaceActive
259
+ };
166
260
  },
167
- surface12 = {
168
- background: base.background + 1,
169
- backgroundHover: base.backgroundHover + 1,
170
- backgroundPress: base.backgroundPress + 1,
171
- backgroundFocus: base.backgroundFocus + 1,
172
- borderColor: base.borderColor + 1,
173
- borderColorHover: base.borderColorHover + 1,
174
- borderColorFocus: base.borderColorFocus + 1,
175
- borderColorPress: base.borderColorPress + 1
176
- },
177
- surface22 = {
178
- background: base.background + 2,
179
- backgroundHover: base.backgroundHover + 2,
180
- backgroundPress: base.backgroundPress + 2,
181
- backgroundFocus: base.backgroundFocus + 2,
182
- borderColor: base.borderColor + 2,
183
- borderColorHover: base.borderColorHover + 2,
184
- borderColorFocus: base.borderColorFocus + 2,
185
- borderColorPress: base.borderColorPress + 2
186
- },
187
- surface32 = {
188
- background: base.background + 3,
189
- backgroundHover: base.backgroundHover + 3,
190
- backgroundPress: base.backgroundPress + 3,
191
- backgroundFocus: base.backgroundFocus + 3,
192
- borderColor: base.borderColor + 3,
193
- borderColorHover: base.borderColorHover + 3,
194
- borderColorFocus: base.borderColorFocus + 3,
195
- borderColorPress: base.borderColorPress + 3
196
- },
197
- surfaceActiveBg = {
198
- background: base.background + 5,
199
- backgroundHover: base.background + 5,
200
- backgroundPress: base.backgroundPress + 5,
201
- backgroundFocus: base.backgroundFocus + 5
202
- },
203
- surfaceActive = {
204
- ...surfaceActiveBg,
205
- // match border to background when active
206
- borderColor: surfaceActiveBg.background,
207
- borderColorHover: surfaceActiveBg.backgroundHover,
208
- borderColorFocus: surfaceActiveBg.backgroundFocus,
209
- borderColorPress: surfaceActiveBg.backgroundPress
210
- },
211
- inverseSurface12 = {
212
- color: surface12.background,
213
- colorHover: surface12.backgroundHover,
214
- colorPress: surface12.backgroundPress,
215
- colorFocus: surface12.backgroundFocus,
216
- background: base.color,
217
- backgroundHover: base.colorHover,
218
- backgroundPress: base.colorPress,
219
- backgroundFocus: base.colorFocus,
220
- borderColor: base.color - 2,
221
- borderColorHover: base.color - 3,
222
- borderColorFocus: base.color - 4,
223
- borderColorPress: base.color - 5
224
- },
225
- inverseActive = {
226
- ...inverseSurface12,
227
- background: base.color - 2,
228
- backgroundHover: base.colorHover - 2,
229
- backgroundPress: base.colorPress - 2,
230
- backgroundFocus: base.colorFocus - 2,
231
- borderColor: base.color - 2 - 2,
232
- borderColorHover: base.color - 3 - 2,
233
- borderColorFocus: base.color - 4 - 2,
234
- borderColorPress: base.color - 5 - 2
235
- },
236
- alt1 = {
237
- color: base.color - 1,
238
- colorHover: base.colorHover - 1,
239
- colorPress: base.colorPress - 1,
240
- colorFocus: base.colorFocus - 1
241
- },
242
- alt2 = {
243
- color: base.color - 2,
244
- colorHover: base.colorHover - 2,
245
- colorPress: base.colorPress - 2,
246
- colorFocus: base.colorFocus - 2
247
- };
261
+ lightTemplates = getBaseTemplates("light"),
262
+ darkTemplates = getBaseTemplates("dark");
248
263
  return {
249
- base,
250
- alt1,
251
- alt2,
252
- surface1: surface12,
253
- surface2: surface22,
254
- surface3: surface32,
255
- inverseSurface1: inverseSurface12,
256
- inverseActive,
257
- surfaceActive
264
+ ...objectFromEntries(objectKeys(lightTemplates).map(name => [`light_${name}`, lightTemplates[name]])),
265
+ ...objectFromEntries(objectKeys(darkTemplates).map(name => [`dark_${name}`, darkTemplates[name]]))
258
266
  };
259
267
  },
260
- lightTemplates = getTemplates("light"),
261
- darkTemplates = getTemplates("dark"),
262
- templates = {
263
- ...objectFromEntries(objectKeys(lightTemplates).map(name => [`light_${name}`, lightTemplates[name]])),
264
- ...objectFromEntries(objectKeys(darkTemplates).map(name => [`dark_${name}`, darkTemplates[name]]))
265
- },
268
+ defaultTemplates = getTemplates(),
266
269
  shadows = {
267
270
  light: {
268
271
  shadowColor: lightShadowColorStrong,
@@ -326,7 +329,63 @@ const colorTokens = {
326
329
  parent: "",
327
330
  template: "surface3"
328
331
  }],
329
- themeBuilder = createThemeBuilder().addPalettes(palettes).addTemplates(templates).addThemes({
332
+ componentThemes = {
333
+ ListItem: {
334
+ template: "surface1"
335
+ },
336
+ SelectTrigger: surface1,
337
+ Card: surface1,
338
+ Button: surface3,
339
+ Checkbox: surface2,
340
+ Switch: surface2,
341
+ SwitchThumb: inverseSurface1,
342
+ TooltipContent: surface2,
343
+ Progress: {
344
+ template: "surface1"
345
+ },
346
+ RadioGroupItem: surface2,
347
+ TooltipArrow: {
348
+ template: "surface1"
349
+ },
350
+ SliderTrackActive: {
351
+ template: "surface3"
352
+ },
353
+ SliderTrack: {
354
+ template: "surface1"
355
+ },
356
+ SliderThumb: inverseSurface1,
357
+ Tooltip: inverseSurface1,
358
+ ProgressIndicator: inverseSurface1,
359
+ SheetOverlay: overlayThemeDefinitions,
360
+ DialogOverlay: overlayThemeDefinitions,
361
+ ModalOverlay: overlayThemeDefinitions,
362
+ Input: surface1,
363
+ TextArea: surface1
364
+ },
365
+ defaultSubThemes = {
366
+ alt1: {
367
+ template: "alt1"
368
+ },
369
+ alt2: {
370
+ template: "alt2"
371
+ },
372
+ active: {
373
+ template: "surface3"
374
+ },
375
+ surface1: {
376
+ template: "surface1"
377
+ },
378
+ surface2: {
379
+ template: "surface2"
380
+ },
381
+ surface3: {
382
+ template: "surface3"
383
+ },
384
+ surface4: {
385
+ template: "surfaceActive"
386
+ }
387
+ },
388
+ themeBuilder = createThemeBuilder().addPalettes(defaultPalettes).addTemplates(defaultTemplates).addThemes({
330
389
  light: {
331
390
  template: "base",
332
391
  palette: "light",
@@ -370,61 +429,7 @@ const colorTokens = {
370
429
  palette: "gray",
371
430
  template: "base"
372
431
  }
373
- }).addChildThemes({
374
- alt1: {
375
- template: "alt1"
376
- },
377
- alt2: {
378
- template: "alt2"
379
- },
380
- active: {
381
- template: "surface3"
382
- },
383
- surface1: {
384
- template: "surface1"
385
- },
386
- surface2: {
387
- template: "surface2"
388
- },
389
- surface3: {
390
- template: "surface3"
391
- },
392
- surface4: {
393
- template: "surfaceActive"
394
- }
395
- }).addComponentThemes({
396
- ListItem: {
397
- template: "surface1"
398
- },
399
- SelectTrigger: surface1,
400
- Card: surface1,
401
- Button: surface3,
402
- Checkbox: surface2,
403
- Switch: surface2,
404
- SwitchThumb: inverseSurface1,
405
- TooltipContent: surface2,
406
- Progress: {
407
- template: "surface1"
408
- },
409
- RadioGroupItem: surface2,
410
- TooltipArrow: {
411
- template: "surface1"
412
- },
413
- SliderTrackActive: {
414
- template: "surface3"
415
- },
416
- SliderTrack: {
417
- template: "surface1"
418
- },
419
- SliderThumb: inverseSurface1,
420
- Tooltip: inverseSurface1,
421
- ProgressIndicator: inverseSurface1,
422
- SheetOverlay: overlayThemeDefinitions,
423
- DialogOverlay: overlayThemeDefinitions,
424
- ModalOverlay: overlayThemeDefinitions,
425
- Input: surface1,
426
- TextArea: surface1
427
- }, {
432
+ }).addChildThemes(defaultSubThemes).addComponentThemes(componentThemes, {
428
433
  avoidNestingWithin: ["alt1", "alt2", "surface1", "surface2", "surface3", "surface4"]
429
434
  }),
430
435
  themesIn = themeBuilder.build(),
@@ -509,4 +514,4 @@ function objectFromEntries(arr) {
509
514
  function objectKeys(obj) {
510
515
  return Object.keys(obj);
511
516
  }
512
- export { getTemplates, objectFromEntries, objectKeys, palettes, postfixObjKeys, radius, size, sizeToSpace, space, spaces, spacesNegative, themes, tokens, zIndex };
517
+ export { componentThemes, defaultPalettes, defaultSubThemes, defaultTemplates, objectFromEntries, objectKeys, postfixObjKeys, radius, size, sizeToSpace, space, spaces, spacesNegative, themes, tokens, zIndex };