@sanity/ui 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (59) hide show
  1. package/dist/index.cjs.mjs +10 -36
  2. package/dist/index.d.ts +179 -238
  3. package/dist/index.esm.js +18 -5
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +26 -218
  6. package/dist/index.js.map +1 -1
  7. package/dist/theme.cjs.mjs +1 -1
  8. package/dist/theme.d.ts +75 -111
  9. package/dist/theme.esm.js +154 -92
  10. package/dist/theme.esm.js.map +1 -1
  11. package/dist/theme.js +154 -92
  12. package/dist/theme.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/core/_compat.ts +236 -87
  15. package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
  16. package/src/core/components/menu/menuButton.tsx +12 -1
  17. package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
  18. package/src/core/primitives/kbd/kbd.tsx +2 -0
  19. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  20. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  21. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  22. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  23. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  24. package/src/core/theme/__workshop__/debug/story.tsx +159 -0
  25. package/src/core/theme/__workshop__/index.ts +5 -0
  26. package/src/core/theme/theme.test.tsx +2 -2
  27. package/src/core/types/button.ts +1 -2
  28. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  29. package/src/theme/build/buildColorTheme.ts +16 -16
  30. package/src/theme/build/colorToken/colorToken.ts +19 -0
  31. package/src/theme/build/colorToken/compileColorToken.ts +17 -0
  32. package/src/theme/build/colorToken/index.ts +2 -0
  33. package/src/theme/build/colorToken/types.ts +6 -0
  34. package/src/theme/build/renderColorTheme.ts +14 -15
  35. package/src/theme/build/renderColorValue.ts +1 -1
  36. package/src/theme/config/system.ts +9 -9
  37. package/src/theme/config/tokens/color/types.ts +12 -1
  38. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  39. package/src/theme/config/tokens/parseTokenValue.ts +1 -0
  40. package/src/theme/defaults/colorTokens.ts +127 -66
  41. package/src/theme/index.ts +0 -7
  42. package/src/theme/system/color/_constants.ts +5 -2
  43. package/src/theme/system/color/_system.ts +2 -1
  44. package/src/theme/system/color/avatar.ts +2 -12
  45. package/src/theme/system/color/button.ts +4 -20
  46. package/src/theme/system/color/input.ts +3 -11
  47. package/src/theme/system/color/selectable.ts +3 -14
  48. package/src/theme/system/shadow.ts +0 -6
  49. package/src/theme/system/styles.ts +0 -6
  50. package/src/theme/system/theme.ts +2 -0
  51. package/src/theme/system/v0/avatar.ts +1 -1
  52. package/src/theme/system/v0/color/button.ts +4 -4
  53. package/src/theme/system/v0/color/card.ts +2 -2
  54. package/src/theme/system/v0/color/input.ts +3 -3
  55. package/src/theme/system/v0/color/muted.ts +2 -2
  56. package/src/theme/system/v0/color/solid.ts +2 -2
  57. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  58. package/src/theme/versioning/v2_v0.ts +2 -2
  59. package/src/theme/build/colorToken.ts +0 -39
package/dist/theme.js CHANGED
@@ -1921,13 +1921,10 @@ function inputStateThemeColor_v2_v0(t) {
1921
1921
  placeholder: t.placeholder
1922
1922
  };
1923
1923
  }
1924
+ const THEME_COLOR_SCHEMES = ["light", "dark"];
1924
1925
  const THEME_COLOR_BLEND_MODES = ["multiply", "screen"];
1925
- const THEME_COLOR_CARD_TONES = ["transparent", "default", "primary",
1926
- // todo: rename to `accent` in the next breaking major version
1927
- "positive", "caution", "critical"];
1928
- const THEME_COLOR_STATE_TONES = ["default", "primary",
1929
- // todo: rename to `accent` in the next breaking major version
1930
- "positive", "caution", "critical"];
1926
+ const THEME_COLOR_CARD_TONES = ["transparent", "default", "primary", "positive", "caution", "critical"];
1927
+ const THEME_COLOR_STATE_TONES = ["default", "primary", "positive", "caution", "critical"];
1931
1928
  const THEME_COLOR_STATES = ["enabled", "hovered", "pressed", "selected", "disabled"];
1932
1929
  const THEME_COLOR_BUTTON_MODES = ["default", "ghost", "bleed"];
1933
1930
  const THEME_COLOR_INPUT_MODES = ["default", "invalid"];
@@ -2105,6 +2102,18 @@ function isColorValue(str) {
2105
2102
  function isColorOpacityValue(str) {
2106
2103
  return str === "0" || /^0\.[0-9]+$/.test(str) || str === "1";
2107
2104
  }
2105
+ function compileColorTokenValue(node) {
2106
+ let key = "";
2107
+ if (node.key === "black" || node.key === "white") {
2108
+ key = node.key;
2109
+ } else {
2110
+ key = "".concat(node.hue, "/").concat(node.tint);
2111
+ }
2112
+ if (node.opacity !== void 0) {
2113
+ key += "/".concat(node.opacity);
2114
+ }
2115
+ return key;
2116
+ }
2108
2117
  const DEFAULT_COLOR_TOKEN_VALUE = ["500", "500"];
2109
2118
  function resolveColorTokenValue(context) {
2110
2119
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COLOR_TOKEN_VALUE;
@@ -2121,22 +2130,13 @@ function resolveColorTokenValue(context) {
2121
2130
  hue: node.hue || hue
2122
2131
  });
2123
2132
  }
2124
- function compileColorTokenValue(node) {
2125
- let key = "";
2126
- if (node.key === "black" || node.key === "white") {
2127
- key = node.key;
2128
- } else {
2129
- key = "".concat(node.hue, "/").concat(node.tint);
2130
- }
2131
- if (node.opacity !== void 0) {
2132
- key += "/".concat(node.opacity);
2133
- }
2134
- return key;
2135
- }
2136
2133
  const defaultColorTokens = {
2137
2134
  base: {
2138
2135
  "*": {
2139
2136
  _blend: ["multiply", "screen"],
2137
+ accent: {
2138
+ fg: ["purple/600", "purple/400"]
2139
+ },
2140
2140
  avatar: {
2141
2141
  "*": {
2142
2142
  _blend: ["screen", "multiply"],
@@ -2157,7 +2157,9 @@ const defaultColorTokens = {
2157
2157
  badge: {
2158
2158
  "*": {
2159
2159
  bg: ["100", "900"],
2160
- fg: ["600", "400"]
2160
+ fg: ["600", "400"],
2161
+ icon: ["500", "500"],
2162
+ dot: ["500", "500"]
2161
2163
  },
2162
2164
  positive: {
2163
2165
  bg: ["200/0.6", "900"],
@@ -2172,7 +2174,7 @@ const defaultColorTokens = {
2172
2174
  border: ["200", "800"],
2173
2175
  code: {
2174
2176
  bg: ["50", "950"],
2175
- fg: ["600", "400"]
2177
+ fg: ["700", "300"]
2176
2178
  },
2177
2179
  fg: ["800", "200"],
2178
2180
  focusRing: ["blue/500", "blue/500"],
@@ -2182,7 +2184,7 @@ const defaultColorTokens = {
2182
2184
  border: ["200", "800"]
2183
2185
  },
2184
2186
  link: {
2185
- fg: ["blue/600", "blue/400"]
2187
+ fg: ["blue/700", "blue/300"]
2186
2188
  },
2187
2189
  muted: {
2188
2190
  bg: ["50", "950"],
@@ -2239,8 +2241,10 @@ const defaultColorTokens = {
2239
2241
  },
2240
2242
  badge: {
2241
2243
  "*": {
2242
- dot: ["300", "700"],
2243
- icon: ["600", "400"]
2244
+ bg: ["900", "100"],
2245
+ fg: ["400", "600"],
2246
+ dot: ["500", "500"],
2247
+ icon: ["500", "500"]
2244
2248
  }
2245
2249
  },
2246
2250
  bg: ["500", "400"],
@@ -2252,8 +2256,8 @@ const defaultColorTokens = {
2252
2256
  fg: ["white", "black"],
2253
2257
  icon: ["200", "800"],
2254
2258
  kbd: {
2255
- bg: ["900", "50"],
2256
- fg: ["white", "black"],
2259
+ bg: ["black", "white"],
2260
+ fg: ["200", "800"],
2257
2261
  border: ["800", "200"]
2258
2262
  },
2259
2263
  link: {
@@ -2280,8 +2284,21 @@ const defaultColorTokens = {
2280
2284
  },
2281
2285
  disabled: {
2282
2286
  _hue: "gray",
2287
+ badge: {
2288
+ "*": {
2289
+ bg: ["gray/700", "gray/300"],
2290
+ fg: ["white", "black"],
2291
+ dot: ["white", "black"],
2292
+ icon: ["white", "black"]
2293
+ }
2294
+ },
2283
2295
  bg: ["200", "800"],
2284
- icon: ["white", "black"]
2296
+ icon: ["white", "black"],
2297
+ kbd: {
2298
+ bg: ["black", "white"],
2299
+ fg: ["white", "black"],
2300
+ border: ["700", "300"]
2301
+ }
2285
2302
  }
2286
2303
  },
2287
2304
  default: {
@@ -2331,12 +2348,29 @@ const defaultColorTokens = {
2331
2348
  "*": {
2332
2349
  "*": {
2333
2350
  _blend: ["multiply", "screen"],
2351
+ accent: {
2352
+ fg: ["purple/700/0.6", "purple/400/0.8"]
2353
+ },
2354
+ badge: {
2355
+ "*": {
2356
+ bg: ["100", "900"],
2357
+ fg: ["600", "400"],
2358
+ dot: ["500", "500"],
2359
+ icon: ["500", "500"]
2360
+ }
2361
+ },
2334
2362
  bg: ["50", "950"],
2363
+ border: ["100", "900"],
2364
+ code: {
2365
+ bg: ["500/0.1", "400/0.1"],
2366
+ fg: ["700/0.6", "400/0.6"]
2367
+ },
2335
2368
  fg: ["700", "400"],
2336
2369
  icon: ["600", "500"],
2337
- border: ["100", "900"],
2338
- accent: {
2339
- fg: ["purple/700/0.6", "purple/400/0.8"]
2370
+ kbd: {
2371
+ bg: ["white", "black"],
2372
+ fg: ["600", "400"],
2373
+ border: ["200", "800"]
2340
2374
  },
2341
2375
  link: {
2342
2376
  fg: ["blue/700/0.6", "blue/400/0.8"]
@@ -2345,19 +2379,9 @@ const defaultColorTokens = {
2345
2379
  bg: ["100", "950"],
2346
2380
  fg: ["700/0.6", "400/0.6"]
2347
2381
  },
2348
- code: {
2349
- bg: ["500/0.1", "400/0.1"],
2350
- fg: ["700/0.6", "400/0.6"]
2351
- },
2352
2382
  skeleton: {
2353
2383
  from: ["100", "900"],
2354
2384
  to: ["100/0.5", "900/0.5"]
2355
- },
2356
- badge: {
2357
- "*": {
2358
- dot: ["300", "700"],
2359
- icon: ["600", "400"]
2360
- }
2361
2385
  }
2362
2386
  },
2363
2387
  hovered: {
@@ -2374,21 +2398,35 @@ const defaultColorTokens = {
2374
2398
  },
2375
2399
  disabled: {
2376
2400
  _hue: "gray",
2377
- fg: ["200", "800"],
2378
- icon: ["200", "800"],
2401
+ accent: {
2402
+ fg: ["200", "800"]
2403
+ },
2404
+ badge: {
2405
+ "*": {
2406
+ _hue: "gray",
2407
+ bg: ["50", "950"],
2408
+ fg: ["gray/200", "gray/800"],
2409
+ dot: ["gray/200", "gray/800"],
2410
+ icon: ["gray/200", "gray/800"]
2411
+ }
2412
+ },
2379
2413
  border: ["100", "900"],
2380
- muted: {
2381
- fg: ["200/0.6", "900/0.6"]
2414
+ code: {
2415
+ bg: ["50", "950"],
2416
+ fg: ["200", "800"]
2382
2417
  },
2383
- accent: {
2384
- fg: ["200/0.6", "900/0.6"]
2418
+ fg: ["200", "800"],
2419
+ icon: ["200", "800"],
2420
+ kbd: {
2421
+ bg: ["white", "black"],
2422
+ fg: ["200", "800"],
2423
+ border: ["100", "900"]
2385
2424
  },
2386
2425
  link: {
2387
- fg: ["200/0.6", "900/0.6"]
2426
+ fg: ["200", "800"]
2388
2427
  },
2389
- code: {
2390
- bg: ["50/0.5", "950/0.5"],
2391
- fg: ["200/0.6", "900/0.6"]
2428
+ muted: {
2429
+ fg: ["200", "800"]
2392
2430
  }
2393
2431
  }
2394
2432
  },
@@ -2407,33 +2445,40 @@ const defaultColorTokens = {
2407
2445
  "*": {
2408
2446
  "*": {
2409
2447
  _blend: ["multiply", "screen"],
2448
+ accent: {
2449
+ fg: ["purple/700/0.7", "purple/300/0.7"]
2450
+ },
2451
+ badge: {
2452
+ "*": {
2453
+ bg: ["100", "900"],
2454
+ fg: ["600", "400"],
2455
+ dot: ["500", "500"],
2456
+ icon: ["500", "500"]
2457
+ }
2458
+ },
2410
2459
  bg: ["white", "black"],
2411
- fg: ["700", "300"],
2412
- icon: ["700/0.7", "300/0.7"],
2413
2460
  border: ["white/0", "black/0"],
2414
- muted: {
2461
+ code: {
2415
2462
  bg: ["100", "950"],
2416
- fg: ["700/0.7", "300/0.7"]
2463
+ fg: ["600", "300"]
2417
2464
  },
2418
- accent: {
2419
- fg: ["purple/700/0.7", "purple/300/0.7"]
2465
+ fg: ["700", "300"],
2466
+ icon: ["700/0.7", "300/0.7"],
2467
+ kbd: {
2468
+ bg: ["white", "black"],
2469
+ fg: ["600", "400"],
2470
+ border: ["200", "800"]
2420
2471
  },
2421
2472
  link: {
2422
2473
  fg: ["blue/700/0.7", "blue/300/0.7"]
2423
2474
  },
2424
- code: {
2475
+ muted: {
2425
2476
  bg: ["100", "950"],
2426
- fg: ["600", "300"]
2477
+ fg: ["700/0.7", "300/0.7"]
2427
2478
  },
2428
2479
  skeleton: {
2429
2480
  from: ["100", "900"],
2430
2481
  to: ["100/0.5", "900/0.5"]
2431
- },
2432
- badge: {
2433
- "*": {
2434
- dot: ["300", "700"],
2435
- icon: ["600", "400"]
2436
- }
2437
2482
  }
2438
2483
  },
2439
2484
  hovered: {
@@ -2453,19 +2498,33 @@ const defaultColorTokens = {
2453
2498
  },
2454
2499
  disabled: {
2455
2500
  _hue: "gray",
2501
+ badge: {
2502
+ "*": {
2503
+ _hue: "gray",
2504
+ bg: ["50", "950"],
2505
+ fg: ["gray/200", "gray/800"],
2506
+ dot: ["gray/200", "gray/800"],
2507
+ icon: ["gray/200", "gray/800"]
2508
+ }
2509
+ },
2456
2510
  fg: ["200", "800"],
2457
2511
  muted: {
2458
- fg: ["200/0.6", "900/0.6"]
2512
+ fg: ["200", "800"]
2459
2513
  },
2460
2514
  accent: {
2461
- fg: ["200/0.6", "900/0.6"]
2515
+ fg: ["200", "800"]
2516
+ },
2517
+ kbd: {
2518
+ bg: ["white", "black"],
2519
+ fg: ["200", "800"],
2520
+ border: ["100", "900"]
2462
2521
  },
2463
2522
  link: {
2464
- fg: ["200/0.6", "900/0.6"]
2523
+ fg: ["200", "800"]
2465
2524
  },
2466
2525
  code: {
2467
- bg: ["50/0.5", "950/0.5"],
2468
- fg: ["200/0.6", "900/0.6"]
2526
+ bg: ["50", "950"],
2527
+ fg: ["200", "800"]
2469
2528
  }
2470
2529
  }
2471
2530
  }
@@ -2515,10 +2574,25 @@ const defaultColorTokens = {
2515
2574
  _blend: ["screen", "multiply"],
2516
2575
  bg: ["500", "400"],
2517
2576
  fg: ["white", "black"]
2577
+ },
2578
+ yellow: {
2579
+ bg: ["600", "400"]
2580
+ },
2581
+ green: {
2582
+ bg: ["600", "400"]
2583
+ },
2584
+ cyan: {
2585
+ bg: ["600", "400"]
2586
+ }
2587
+ },
2588
+ badge: {
2589
+ "*": {
2590
+ // _blend: ['multiply', 'screen'],
2591
+ bg: ["100", "900"],
2592
+ fg: ["600", "400"],
2593
+ dot: ["500", "500"],
2594
+ icon: ["500", "500"]
2518
2595
  }
2519
- // yellow: {bg: ['600', '400']},
2520
- // green: {bg: ['600', '400']},
2521
- // cyan: {bg: ['600', '400']},
2522
2596
  },
2523
2597
  border: ["200", "800"],
2524
2598
  muted: {
@@ -2528,6 +2602,11 @@ const defaultColorTokens = {
2528
2602
  accent: {
2529
2603
  fg: ["purple/600", "purple/400"]
2530
2604
  },
2605
+ kbd: {
2606
+ bg: ["white", "black"],
2607
+ fg: ["600", "400"],
2608
+ border: ["200", "800"]
2609
+ },
2531
2610
  link: {
2532
2611
  fg: ["blue/700", "blue/300"]
2533
2612
  },
@@ -2538,21 +2617,6 @@ const defaultColorTokens = {
2538
2617
  skeleton: {
2539
2618
  from: ["100", "900"],
2540
2619
  to: ["100/0.5", "900/0.5"]
2541
- },
2542
- badge: {
2543
- "*": {
2544
- // _blend: ['multiply', 'screen'],
2545
- bg: ["100", "900"],
2546
- fg: ["600", "200"],
2547
- dot: ["300", "700"],
2548
- icon: ["600", "400"]
2549
- }
2550
- },
2551
- kbd: {
2552
- // _blend: ['multiply', 'screen'],
2553
- bg: ["white", "black"],
2554
- fg: ["600", "400"],
2555
- border: ["200", "800"]
2556
2620
  }
2557
2621
  },
2558
2622
  hovered: {
@@ -3823,7 +3887,7 @@ function renderColorValue(str, options) {
3823
3887
  try {
3824
3888
  hex = mixThemeColor(hex, mixOptions);
3825
3889
  } catch (err) {
3826
- console.log("could not blend", hex, mixOptions);
3890
+ console.warn("could not blend", hex, mixOptions);
3827
3891
  throw err;
3828
3892
  }
3829
3893
  if (hex === "#aN") {
@@ -4075,10 +4139,9 @@ function renderThemeColorBadgeColor(value, options) {
4075
4139
  colorPalette
4076
4140
  };
4077
4141
  return {
4078
- // _blend: blendMode,
4079
4142
  bg,
4080
- fg: renderColorValue(value.fg, colorOptions),
4081
4143
  dot: renderColorValue(value.dot, colorOptions),
4144
+ fg: renderColorValue(value.fg, colorOptions),
4082
4145
  icon: renderColorValue(value.icon, colorOptions)
4083
4146
  };
4084
4147
  }
@@ -4137,7 +4200,7 @@ function renderThemeColorState(value, options) {
4137
4200
  blendMode
4138
4201
  }),
4139
4202
  badge: renderThemeColorBadge(value.badge, {
4140
- baseBg,
4203
+ baseBg: bg,
4141
4204
  colorPalette,
4142
4205
  blendMode
4143
4206
  }),
@@ -4345,7 +4408,6 @@ function _setCachedTheme(rootTheme, scheme, tone, theme) {
4345
4408
  const toneCache = schemeCache.get(tone);
4346
4409
  toneCache.set(rootTheme, theme);
4347
4410
  }
4348
- const defaultTheme = buildTheme();
4349
4411
  exports.COLOR_CONFIG_AVATAR_COLORS = COLOR_CONFIG_AVATAR_COLORS;
4350
4412
  exports.COLOR_CONFIG_BLEND_KEYS = COLOR_CONFIG_BLEND_KEYS;
4351
4413
  exports.COLOR_CONFIG_CARD_KEYS = COLOR_CONFIG_CARD_KEYS;
@@ -4361,11 +4423,11 @@ exports.THEME_COLOR_BUTTON_MODES = THEME_COLOR_BUTTON_MODES;
4361
4423
  exports.THEME_COLOR_CARD_TONES = THEME_COLOR_CARD_TONES;
4362
4424
  exports.THEME_COLOR_INPUT_MODES = THEME_COLOR_INPUT_MODES;
4363
4425
  exports.THEME_COLOR_INPUT_STATES = THEME_COLOR_INPUT_STATES;
4426
+ exports.THEME_COLOR_SCHEMES = THEME_COLOR_SCHEMES;
4364
4427
  exports.THEME_COLOR_STATES = THEME_COLOR_STATES;
4365
4428
  exports.THEME_COLOR_STATE_TONES = THEME_COLOR_STATE_TONES;
4366
4429
  exports.buildTheme = buildTheme;
4367
4430
  exports.createColorTheme = createColorTheme;
4368
- exports.defaultTheme = defaultTheme;
4369
4431
  exports.getContrastRatio = getContrastRatio;
4370
4432
  exports.getScopedTheme = getScopedTheme;
4371
4433
  exports.getTheme_v2 = getTheme_v2;