@sanity/ui 3.0.0-static.35 → 3.0.0-static.36

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.
@@ -302,7 +302,7 @@ export type FontTextSize = (typeof FONT_TEXT_SIZE)[number]
302
302
  export type Shadow = (typeof SHADOW)[number]
303
303
 
304
304
  /** @public */
305
- export interface Options {
305
+ export interface ThemeOptions {
306
306
  tokens?: PartialTokens<Tokens>
307
307
  }
308
308
 
@@ -1,520 +0,0 @@
1
- import {black, hues, white} from '@sanity/color'
2
- import {
3
- _parseColorToken,
4
- AVATAR_COLORS,
5
- AVATAR_SIZE,
6
- buildTheme,
7
- CARD_TONES,
8
- type CardColorTokens,
9
- type CardTone,
10
- COLOR_VARIANTS,
11
- type ColorScheme,
12
- type ColorValue,
13
- type ColorVariant,
14
- CONTAINER_SCALE,
15
- ELEMENT_TONES,
16
- type ElementTone,
17
- FONT_CODE_SIZE,
18
- FONT_HEADING_SIZE,
19
- FONT_LABEL_SIZE,
20
- FONT_TEXT_SIZE,
21
- type Hue,
22
- HUES,
23
- RADIUS,
24
- SHADOW,
25
- SPACE,
26
- TINTS,
27
- } from '@sanity/ui/theme'
28
- import {createTheme, globalFontFace} from '@vanilla-extract/css'
29
-
30
- import {_fromEntries} from './_fromEntries'
31
- import {layers} from './layers.css'
32
- import type {
33
- CSSCardColorTokens,
34
- ElementColorTokens,
35
- RootThemeTokens,
36
- SchemeColorTokens,
37
- VariantColorTokens,
38
- } from './types'
39
- import {px, toBoxShadow} from './util'
40
- import {paletteVars, themeVars} from './vars.css'
41
-
42
- const fontDisplay: FontDisplay = 'swap'
43
-
44
- globalFontFace('Inter', [
45
- {
46
- src: `url('https://studio-static.sanity.io/Inter-Regular.woff2') format('woff2')`,
47
- fontDisplay,
48
- fontStyle: 'normal',
49
- fontWeight: '400',
50
- },
51
- {
52
- src: `url('https://studio-static.sanity.io/Inter-Italic.woff2') format('woff2')`,
53
- fontDisplay,
54
- fontStyle: 'italic',
55
- fontWeight: '400',
56
- },
57
- {
58
- src: `url('https://studio-static.sanity.io/Inter-Medium.woff2') format('woff2')`,
59
- fontDisplay,
60
- fontStyle: 'normal',
61
- fontWeight: '500',
62
- },
63
- {
64
- src: `url('https://studio-static.sanity.io/Inter-MediumItalic.woff2') format('woff2')`,
65
- fontDisplay,
66
- fontStyle: 'italic',
67
- fontWeight: '500',
68
- },
69
- {
70
- src: `url('https://studio-static.sanity.io/Inter-SemiBold.woff2') format('woff2')`,
71
- fontDisplay,
72
- fontStyle: 'normal',
73
- fontWeight: '600',
74
- },
75
- {
76
- src: `url('https://studio-static.sanity.io/Inter-SemiBoldItalic.woff2') format('woff2')`,
77
- fontDisplay,
78
- fontStyle: 'italic',
79
- fontWeight: '600',
80
- },
81
- {
82
- src: `url('https://studio-static.sanity.io/Inter-Bold.woff2') format('woff2')`,
83
- fontDisplay,
84
- fontStyle: 'normal',
85
- fontWeight: '700',
86
- },
87
- {
88
- src: `url('https://studio-static.sanity.io/Inter-BoldItalic.woff2') format('woff2')`,
89
- fontDisplay,
90
- fontStyle: 'italic',
91
- fontWeight: '700',
92
- },
93
- ])
94
-
95
- const theme = buildTheme()
96
-
97
- const themeValue: RootThemeTokens = {
98
- avatar: {
99
- focusRing: {
100
- offset: px(theme.avatar.focusRing.offset),
101
- width: px(theme.avatar.focusRing.width),
102
- },
103
- scale: {
104
- ..._fromEntries(
105
- AVATAR_SIZE.map((s) => [
106
- s,
107
- {
108
- distance: px(theme.avatar.sizes[s].distance),
109
- size: px(theme.avatar.sizes[s].size),
110
- },
111
- ]),
112
- ),
113
- },
114
- },
115
- button: {
116
- border: {
117
- width: px(theme.button.border.width),
118
- },
119
- focusRing: {
120
- offset: px(theme.button.focusRing.offset),
121
- width: px(theme.button.focusRing.width),
122
- },
123
- },
124
- card: {
125
- shadow: {
126
- outline: px(theme.card.shadow.outline),
127
- },
128
- },
129
- container: {
130
- ..._fromEntries(CONTAINER_SCALE.map((s) => [s, rem(theme.container[s])])),
131
- },
132
- color: {
133
- palette: {
134
- black: black.hex,
135
- white: white.hex,
136
- ..._fromEntries(
137
- HUES.map((h) => [h, {..._fromEntries(TINTS.map((t) => [t, hues[h][t].hex]))}]),
138
- ),
139
- },
140
-
141
- light: renderColorScheme({scheme: 'light'}),
142
- dark: renderColorScheme({scheme: 'dark'}),
143
- },
144
- font: {
145
- code: {
146
- family: theme.font.code.family,
147
- featureSettings: theme.font.code.featureSettings || 'normal',
148
- weight: {
149
- regular: theme.font.code.weight.regular.toString(),
150
- medium: theme.font.code.weight.medium.toString(),
151
- semibold: theme.font.code.weight.semibold.toString(),
152
- bold: theme.font.code.weight.bold.toString(),
153
- },
154
- scale: {
155
- ..._fromEntries(
156
- FONT_CODE_SIZE.map((s) => [
157
- s,
158
- {
159
- fontSize: rem(theme.font.code.scale[s].fontSize),
160
- lineHeight: rem(theme.font.code.scale[s].lineHeight),
161
- letterSpacing: rem(theme.font.code.scale[s].letterSpacing),
162
- ascenderHeight: rem(theme.font.code.scale[s].ascenderHeight),
163
- descenderHeight: rem(theme.font.code.scale[s].descenderHeight),
164
- iconSize: rem(theme.font.code.scale[s].iconSize),
165
- customIconSize: rem(theme.font.code.scale[s].customIconSize),
166
- },
167
- ]),
168
- ),
169
- },
170
- },
171
-
172
- heading: {
173
- family: theme.font.heading.family,
174
- featureSettings: theme.font.heading.featureSettings || 'normal',
175
- weight: {
176
- regular: theme.font.heading.weight.regular.toString(),
177
- medium: theme.font.heading.weight.medium.toString(),
178
- semibold: theme.font.heading.weight.semibold.toString(),
179
- bold: theme.font.heading.weight.bold.toString(),
180
- },
181
- scale: {
182
- ..._fromEntries(
183
- FONT_HEADING_SIZE.map((s) => [
184
- s,
185
- {
186
- fontSize: rem(theme.font.heading.scale[s].fontSize),
187
- lineHeight: rem(theme.font.heading.scale[s].lineHeight),
188
- letterSpacing: rem(theme.font.heading.scale[s].letterSpacing),
189
- ascenderHeight: rem(theme.font.heading.scale[s].ascenderHeight),
190
- descenderHeight: rem(theme.font.heading.scale[s].descenderHeight),
191
- iconSize: rem(theme.font.heading.scale[s].iconSize),
192
- customIconSize: rem(theme.font.heading.scale[s].customIconSize),
193
- },
194
- ]),
195
- ),
196
- },
197
- },
198
-
199
- label: {
200
- family: theme.font.label.family,
201
- featureSettings: theme.font.label.featureSettings || 'normal',
202
- weight: {
203
- regular: theme.font.label.weight.regular.toString(),
204
- medium: theme.font.label.weight.medium.toString(),
205
- semibold: theme.font.label.weight.semibold.toString(),
206
- bold: theme.font.label.weight.bold.toString(),
207
- },
208
- scale: {
209
- ..._fromEntries(
210
- FONT_LABEL_SIZE.map((s) => [
211
- s,
212
- {
213
- fontSize: rem(theme.font.label.scale[s].fontSize),
214
- lineHeight: rem(theme.font.label.scale[s].lineHeight),
215
- letterSpacing: rem(theme.font.label.scale[s].letterSpacing),
216
- ascenderHeight: rem(theme.font.label.scale[s].ascenderHeight),
217
- descenderHeight: rem(theme.font.label.scale[s].descenderHeight),
218
- iconSize: rem(theme.font.label.scale[s].iconSize),
219
- customIconSize: rem(theme.font.label.scale[s].customIconSize),
220
- },
221
- ]),
222
- ),
223
- },
224
- },
225
-
226
- text: {
227
- family: theme.font.text.family,
228
- featureSettings: theme.font.text.featureSettings || 'normal',
229
- weight: {
230
- regular: theme.font.text.weight.regular.toString(),
231
- medium: theme.font.text.weight.medium.toString(),
232
- semibold: theme.font.text.weight.semibold.toString(),
233
- bold: theme.font.text.weight.bold.toString(),
234
- },
235
- scale: {
236
- ..._fromEntries(
237
- FONT_TEXT_SIZE.map((s) => [
238
- s,
239
- {
240
- fontSize: rem(theme.font.text.scale[s].fontSize),
241
- lineHeight: rem(theme.font.text.scale[s].lineHeight),
242
- letterSpacing: rem(theme.font.text.scale[s].letterSpacing),
243
- ascenderHeight: rem(theme.font.text.scale[s].ascenderHeight),
244
- descenderHeight: rem(theme.font.text.scale[s].descenderHeight),
245
- iconSize: rem(theme.font.text.scale[s].iconSize),
246
- customIconSize: rem(theme.font.text.scale[s].customIconSize),
247
- },
248
- ]),
249
- ),
250
- },
251
- },
252
- },
253
- input: {
254
- border: {
255
- width: px(theme.input.border.width),
256
- },
257
- checkbox: {
258
- size: rem(theme.input.checkbox.size),
259
- focusRing: {
260
- offset: px(theme.input.checkbox.focusRing.offset),
261
- width: px(theme.input.checkbox.focusRing.width),
262
- },
263
- },
264
- radio: {
265
- size: rem(theme.input.radio.size),
266
- markSize: rem(theme.input.radio.markSize),
267
- focusRing: {
268
- offset: px(theme.input.radio.focusRing.offset),
269
- width: px(theme.input.radio.focusRing.width),
270
- },
271
- },
272
- select: {
273
- focusRing: {
274
- offset: px(theme.input.select.focusRing.offset),
275
- width: px(theme.input.select.focusRing.width),
276
- },
277
- },
278
- switch: {
279
- width: rem(theme.input.switch.width),
280
- height: rem(theme.input.switch.height),
281
- focusRing: {
282
- offset: px(theme.input.switch.focusRing.offset),
283
- width: px(theme.input.switch.focusRing.width),
284
- },
285
- padding: rem(theme.input.switch.padding),
286
- transitionDurationMs: `${theme.input.switch.transitionDurationMs}ms`,
287
- transitionTimingFunction: theme.input.switch.transitionTimingFunction,
288
- },
289
- text: {
290
- focusRing: {
291
- offset: px(theme.input.text.focusRing.offset),
292
- width: px(theme.input.text.focusRing.width),
293
- },
294
- },
295
- },
296
- radius: _fromEntries(RADIUS.map((key) => [key, `${theme.radius[key]}px`])),
297
- shadow: _fromEntries(
298
- SHADOW.map((s) => [
299
- s,
300
- {
301
- umbra: toBoxShadow(theme.shadow[s]?.umbra),
302
- penumbra: toBoxShadow(theme.shadow[s]?.penumbra),
303
- ambient: toBoxShadow(theme.shadow[s]?.ambient),
304
- },
305
- ]),
306
- ),
307
- space: _fromEntries(SPACE.map((key) => [key, `${theme.space[key]}px`])),
308
- } as const
309
-
310
- /** @public */
311
- export const themeClassName: string = createTheme(themeVars, {
312
- '@layer': layers.theme,
313
- ...themeValue,
314
- })
315
-
316
- function renderColorScheme(options: {scheme: ColorScheme}): SchemeColorTokens {
317
- const {scheme} = options
318
-
319
- const defaultCardColor = renderCardColor({
320
- tone: 'default',
321
- scheme,
322
- })
323
-
324
- return {
325
- ..._fromEntries(
326
- CARD_TONES.map((key) => {
327
- if (key === 'default') {
328
- return [key, defaultCardColor]
329
- }
330
-
331
- return [
332
- key,
333
- renderCardColor({
334
- bgValue: defaultCardColor.tinted.default.bg[0],
335
- tone: key,
336
- scheme,
337
- }),
338
- ]
339
- }),
340
- ),
341
- }
342
- }
343
-
344
- function renderCardColor(options: {
345
- bgValue?: string
346
- tone: CardTone
347
- scheme: 'light' | 'dark'
348
- }): CSSCardColorTokens {
349
- const {bgValue, tone: t, scheme} = options
350
-
351
- const tokens = theme.color[t]
352
-
353
- const tintedDefaultVariant = renderColorElement(tokens, {
354
- bgValue,
355
- variant: 'tinted',
356
- scheme,
357
- tone: 'default',
358
- })
359
-
360
- const colorOptions = {
361
- bgValue: tintedDefaultVariant.bg[0],
362
- defaultHue: tokens._hue ?? 'gray',
363
- scheme,
364
- } as const
365
-
366
- return {
367
- avatar: {
368
- ..._fromEntries(
369
- AVATAR_COLORS.map((c) => [
370
- c,
371
- {
372
- bg: renderColor(tokens.avatar[c].bg, {...colorOptions, defaultHue: c}),
373
- fg: renderColor(tokens.avatar[c].fg, {...colorOptions, defaultHue: c}),
374
- },
375
- ]),
376
- ),
377
- },
378
- backdrop: renderColor(tokens.backdrop, colorOptions),
379
- code: {
380
- bg: renderColor(tokens.code.bg, colorOptions),
381
- fg: renderColor(tokens.code.fg, colorOptions),
382
-
383
- token: {
384
- atrule: renderColor(tokens.code.token.atrule, colorOptions),
385
- attrName: renderColor(tokens.code.token.attrName, colorOptions),
386
- attrValue: renderColor(tokens.code.token.attrValue, colorOptions),
387
- attribute: renderColor(tokens.code.token.attribute, colorOptions),
388
- boolean: renderColor(tokens.code.token.boolean, colorOptions),
389
- builtin: renderColor(tokens.code.token.builtin, colorOptions),
390
- cdata: renderColor(tokens.code.token.cdata, colorOptions),
391
- char: renderColor(tokens.code.token.char, colorOptions),
392
- class: renderColor(tokens.code.token.class, colorOptions),
393
- className: renderColor(tokens.code.token.className, colorOptions),
394
- comment: renderColor(tokens.code.token.comment, colorOptions),
395
- constant: renderColor(tokens.code.token.constant, colorOptions),
396
- deleted: renderColor(tokens.code.token.deleted, colorOptions),
397
- doctype: renderColor(tokens.code.token.doctype, colorOptions),
398
- entity: renderColor(tokens.code.token.entity, colorOptions),
399
- function: renderColor(tokens.code.token.function, colorOptions),
400
- hexcode: renderColor(tokens.code.token.hexcode, colorOptions),
401
- id: renderColor(tokens.code.token.id, colorOptions),
402
- important: renderColor(tokens.code.token.important, colorOptions),
403
- inserted: renderColor(tokens.code.token.inserted, colorOptions),
404
- keyword: renderColor(tokens.code.token.keyword, colorOptions),
405
- number: renderColor(tokens.code.token.number, colorOptions),
406
- operator: renderColor(tokens.code.token.operator, colorOptions),
407
- prolog: renderColor(tokens.code.token.prolog, colorOptions),
408
- property: renderColor(tokens.code.token.property, colorOptions),
409
- pseudoClass: renderColor(tokens.code.token.pseudoClass, colorOptions),
410
- pseudoElement: renderColor(tokens.code.token.pseudoElement, colorOptions),
411
- punctuation: renderColor(tokens.code.token.punctuation, colorOptions),
412
- regex: renderColor(tokens.code.token.regex, colorOptions),
413
- selector: renderColor(tokens.code.token.selector, colorOptions),
414
- string: renderColor(tokens.code.token.string, colorOptions),
415
- symbol: renderColor(tokens.code.token.symbol, colorOptions),
416
- tag: renderColor(tokens.code.token.tag, colorOptions),
417
- unit: renderColor(tokens.code.token.unit, colorOptions),
418
- url: renderColor(tokens.code.token.url, colorOptions),
419
- variable: renderColor(tokens.code.token.variable, colorOptions),
420
- },
421
- },
422
- focusRing: renderColor(tokens.focusRing, colorOptions),
423
- link: {
424
- fg: renderColor(tokens.link.fg, colorOptions),
425
- },
426
- shadow: {
427
- outline: renderColor(tokens.shadow.outline, colorOptions),
428
- umbra: renderColor(tokens.shadow.umbra, colorOptions),
429
- penumbra: renderColor(tokens.shadow.penumbra, colorOptions),
430
- ambient: renderColor(tokens.shadow.ambient, colorOptions),
431
- },
432
- skeleton: {
433
- from: renderColor(tokens.skeleton.from, colorOptions),
434
- to: renderColor(tokens.skeleton.to, colorOptions),
435
- },
436
- // variants
437
- ..._fromEntries(
438
- COLOR_VARIANTS.map((v) => [
439
- v,
440
- {
441
- ..._fromEntries(
442
- ELEMENT_TONES.map((t) => {
443
- if (v === 'tinted' && t === 'default') {
444
- return [t, tintedDefaultVariant]
445
- }
446
-
447
- return [t, renderColorElement(tokens, {scheme, variant: v, tone: t})]
448
- }),
449
- ),
450
- } satisfies VariantColorTokens,
451
- ]),
452
- ),
453
- }
454
- }
455
-
456
- function renderColorElement(
457
- tokens: CardColorTokens,
458
- options: {
459
- bgValue?: string
460
- scheme: ColorScheme
461
- variant: ColorVariant
462
- tone: ElementTone
463
- },
464
- ): ElementColorTokens {
465
- const {bgValue, scheme, variant: v, tone: t} = options
466
-
467
- const elementColorOptions = {bgValue, defaultHue: tokens.variant[v][t]._hue, scheme}
468
-
469
- return {
470
- bg: {
471
- 0: renderColor(tokens.variant[v][t].bg[0], elementColorOptions),
472
- 4: renderColor(tokens.variant[v][t].bg[4], elementColorOptions),
473
- },
474
- border: {
475
- 0: renderColor(tokens.variant[v][t].border[0], elementColorOptions),
476
- 4: renderColor(tokens.variant[v][t].border[4], elementColorOptions),
477
- },
478
- fg: {
479
- 0: renderColor(tokens.variant[v][t].fg[0], elementColorOptions),
480
- 4: renderColor(tokens.variant[v][t].fg[4], elementColorOptions),
481
- },
482
- }
483
- }
484
-
485
- function renderColor(
486
- value: ColorValue,
487
- context: {bgValue?: string; defaultHue: Hue; scheme: 'light' | 'dark'},
488
- ): string {
489
- const {bgValue = 'transparent', defaultHue, scheme} = context
490
-
491
- const expr = _parseColorToken(value[scheme === 'light' ? 0 : 1], {defaultHue})
492
-
493
- if (expr.type === 'inherit') {
494
- return bgValue
495
- }
496
-
497
- let v = bgValue
498
-
499
- if (expr.type === 'color') {
500
- v = paletteVars[expr.name]
501
- }
502
-
503
- if (expr.type === 'tint') {
504
- v = paletteVars[expr.hue][expr.tint]
505
- }
506
-
507
- if (expr.mix < 1) {
508
- v = `color-mix(in srgb, ${bgValue}, ${v} ${expr.mix * 100}%)`
509
- }
510
-
511
- if (expr.opacity < 1) {
512
- v = `color-mix(in srgb, transparent, ${v} ${expr.opacity * 100}%)`
513
- }
514
-
515
- return v
516
- }
517
-
518
- function rem(value: number) {
519
- return `${value / 16}rem`
520
- }
package/src/css/util.ts DELETED
@@ -1,22 +0,0 @@
1
- import type {BoxShadow} from '@sanity/ui/theme'
2
-
3
- /** @internal */
4
- export function rem(value: number): string {
5
- if (value === 0) return '0'
6
-
7
- return `${value / 16}rem`
8
- }
9
-
10
- /** @internal */
11
- export function px(value: number): string {
12
- if (value === 0) return '0'
13
-
14
- return `${value}px`
15
- }
16
-
17
- /** @internal */
18
- export function toBoxShadow(value: BoxShadow | undefined): string {
19
- if (!value) return 'none'
20
-
21
- return value.map((n) => px(n)).join(' ')
22
- }