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

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 (57) hide show
  1. package/dist/index.cjs.mjs +10 -36
  2. package/dist/index.d.ts +179 -238
  3. package/dist/index.esm.js +13 -4
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +21 -217
  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/hooks/useMediaIndex/useMediaIndex.test.tsx +6 -3
  16. package/src/core/primitives/kbd/kbd.tsx +2 -0
  17. package/src/core/styles/margin/marginsStyle.test.ts +2 -2
  18. package/src/core/styles/padding/paddingStyle.test.ts +2 -2
  19. package/src/core/theme/__workshop__/build/Root.tsx +20 -3
  20. package/src/core/theme/__workshop__/build/story.tsx +16 -10
  21. package/src/core/theme/__workshop__/canvas.tsx +7 -7
  22. package/src/core/theme/__workshop__/debug/story.tsx +159 -0
  23. package/src/core/theme/__workshop__/index.ts +5 -0
  24. package/src/core/theme/theme.test.tsx +2 -2
  25. package/src/core/types/button.ts +1 -2
  26. package/src/theme/build/_deprecated/color/factory.ts +3 -3
  27. package/src/theme/build/buildColorTheme.ts +16 -16
  28. package/src/theme/build/colorToken/colorToken.ts +19 -0
  29. package/src/theme/build/colorToken/compileColorToken.ts +17 -0
  30. package/src/theme/build/colorToken/index.ts +2 -0
  31. package/src/theme/build/colorToken/types.ts +6 -0
  32. package/src/theme/build/renderColorTheme.ts +14 -15
  33. package/src/theme/build/renderColorValue.ts +1 -1
  34. package/src/theme/config/system.ts +9 -9
  35. package/src/theme/config/tokens/color/types.ts +12 -1
  36. package/src/theme/config/tokens/parseTokenKey.ts +1 -0
  37. package/src/theme/config/tokens/parseTokenValue.ts +1 -0
  38. package/src/theme/defaults/colorTokens.ts +127 -66
  39. package/src/theme/index.ts +0 -7
  40. package/src/theme/system/color/_constants.ts +5 -2
  41. package/src/theme/system/color/_system.ts +2 -1
  42. package/src/theme/system/color/avatar.ts +2 -12
  43. package/src/theme/system/color/button.ts +4 -20
  44. package/src/theme/system/color/input.ts +3 -11
  45. package/src/theme/system/color/selectable.ts +3 -14
  46. package/src/theme/system/shadow.ts +0 -6
  47. package/src/theme/system/styles.ts +0 -6
  48. package/src/theme/system/theme.ts +2 -0
  49. package/src/theme/system/v0/avatar.ts +1 -1
  50. package/src/theme/system/v0/color/button.ts +4 -4
  51. package/src/theme/system/v0/color/card.ts +2 -2
  52. package/src/theme/system/v0/color/input.ts +3 -3
  53. package/src/theme/system/v0/color/muted.ts +2 -2
  54. package/src/theme/system/v0/color/solid.ts +2 -2
  55. package/src/theme/versioning/themeColor_v0_v2.ts +2 -2
  56. package/src/theme/versioning/v2_v0.ts +2 -2
  57. package/src/theme/build/colorToken.ts +0 -39
package/dist/theme.esm.js CHANGED
@@ -1916,13 +1916,10 @@ function inputStateThemeColor_v2_v0(t) {
1916
1916
  placeholder: t.placeholder
1917
1917
  };
1918
1918
  }
1919
+ const THEME_COLOR_SCHEMES = ["light", "dark"];
1919
1920
  const THEME_COLOR_BLEND_MODES = ["multiply", "screen"];
1920
- const THEME_COLOR_CARD_TONES = ["transparent", "default", "primary",
1921
- // todo: rename to `accent` in the next breaking major version
1922
- "positive", "caution", "critical"];
1923
- const THEME_COLOR_STATE_TONES = ["default", "primary",
1924
- // todo: rename to `accent` in the next breaking major version
1925
- "positive", "caution", "critical"];
1921
+ const THEME_COLOR_CARD_TONES = ["transparent", "default", "primary", "positive", "caution", "critical"];
1922
+ const THEME_COLOR_STATE_TONES = ["default", "primary", "positive", "caution", "critical"];
1926
1923
  const THEME_COLOR_STATES = ["enabled", "hovered", "pressed", "selected", "disabled"];
1927
1924
  const THEME_COLOR_BUTTON_MODES = ["default", "ghost", "bleed"];
1928
1925
  const THEME_COLOR_INPUT_MODES = ["default", "invalid"];
@@ -2100,6 +2097,18 @@ function isColorValue(str) {
2100
2097
  function isColorOpacityValue(str) {
2101
2098
  return str === "0" || /^0\.[0-9]+$/.test(str) || str === "1";
2102
2099
  }
2100
+ function compileColorTokenValue(node) {
2101
+ let key = "";
2102
+ if (node.key === "black" || node.key === "white") {
2103
+ key = node.key;
2104
+ } else {
2105
+ key = "".concat(node.hue, "/").concat(node.tint);
2106
+ }
2107
+ if (node.opacity !== void 0) {
2108
+ key += "/".concat(node.opacity);
2109
+ }
2110
+ return key;
2111
+ }
2103
2112
  const DEFAULT_COLOR_TOKEN_VALUE = ["500", "500"];
2104
2113
  function resolveColorTokenValue(context) {
2105
2114
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COLOR_TOKEN_VALUE;
@@ -2116,22 +2125,13 @@ function resolveColorTokenValue(context) {
2116
2125
  hue: node.hue || hue
2117
2126
  });
2118
2127
  }
2119
- function compileColorTokenValue(node) {
2120
- let key = "";
2121
- if (node.key === "black" || node.key === "white") {
2122
- key = node.key;
2123
- } else {
2124
- key = "".concat(node.hue, "/").concat(node.tint);
2125
- }
2126
- if (node.opacity !== void 0) {
2127
- key += "/".concat(node.opacity);
2128
- }
2129
- return key;
2130
- }
2131
2128
  const defaultColorTokens = {
2132
2129
  base: {
2133
2130
  "*": {
2134
2131
  _blend: ["multiply", "screen"],
2132
+ accent: {
2133
+ fg: ["purple/600", "purple/400"]
2134
+ },
2135
2135
  avatar: {
2136
2136
  "*": {
2137
2137
  _blend: ["screen", "multiply"],
@@ -2152,7 +2152,9 @@ const defaultColorTokens = {
2152
2152
  badge: {
2153
2153
  "*": {
2154
2154
  bg: ["100", "900"],
2155
- fg: ["600", "400"]
2155
+ fg: ["600", "400"],
2156
+ icon: ["500", "500"],
2157
+ dot: ["500", "500"]
2156
2158
  },
2157
2159
  positive: {
2158
2160
  bg: ["200/0.6", "900"],
@@ -2167,7 +2169,7 @@ const defaultColorTokens = {
2167
2169
  border: ["200", "800"],
2168
2170
  code: {
2169
2171
  bg: ["50", "950"],
2170
- fg: ["600", "400"]
2172
+ fg: ["700", "300"]
2171
2173
  },
2172
2174
  fg: ["800", "200"],
2173
2175
  focusRing: ["blue/500", "blue/500"],
@@ -2177,7 +2179,7 @@ const defaultColorTokens = {
2177
2179
  border: ["200", "800"]
2178
2180
  },
2179
2181
  link: {
2180
- fg: ["blue/600", "blue/400"]
2182
+ fg: ["blue/700", "blue/300"]
2181
2183
  },
2182
2184
  muted: {
2183
2185
  bg: ["50", "950"],
@@ -2234,8 +2236,10 @@ const defaultColorTokens = {
2234
2236
  },
2235
2237
  badge: {
2236
2238
  "*": {
2237
- dot: ["300", "700"],
2238
- icon: ["600", "400"]
2239
+ bg: ["900", "100"],
2240
+ fg: ["400", "600"],
2241
+ dot: ["500", "500"],
2242
+ icon: ["500", "500"]
2239
2243
  }
2240
2244
  },
2241
2245
  bg: ["500", "400"],
@@ -2247,8 +2251,8 @@ const defaultColorTokens = {
2247
2251
  fg: ["white", "black"],
2248
2252
  icon: ["200", "800"],
2249
2253
  kbd: {
2250
- bg: ["900", "50"],
2251
- fg: ["white", "black"],
2254
+ bg: ["black", "white"],
2255
+ fg: ["200", "800"],
2252
2256
  border: ["800", "200"]
2253
2257
  },
2254
2258
  link: {
@@ -2275,8 +2279,21 @@ const defaultColorTokens = {
2275
2279
  },
2276
2280
  disabled: {
2277
2281
  _hue: "gray",
2282
+ badge: {
2283
+ "*": {
2284
+ bg: ["gray/700", "gray/300"],
2285
+ fg: ["white", "black"],
2286
+ dot: ["white", "black"],
2287
+ icon: ["white", "black"]
2288
+ }
2289
+ },
2278
2290
  bg: ["200", "800"],
2279
- icon: ["white", "black"]
2291
+ icon: ["white", "black"],
2292
+ kbd: {
2293
+ bg: ["black", "white"],
2294
+ fg: ["white", "black"],
2295
+ border: ["700", "300"]
2296
+ }
2280
2297
  }
2281
2298
  },
2282
2299
  default: {
@@ -2326,12 +2343,29 @@ const defaultColorTokens = {
2326
2343
  "*": {
2327
2344
  "*": {
2328
2345
  _blend: ["multiply", "screen"],
2346
+ accent: {
2347
+ fg: ["purple/700/0.6", "purple/400/0.8"]
2348
+ },
2349
+ badge: {
2350
+ "*": {
2351
+ bg: ["100", "900"],
2352
+ fg: ["600", "400"],
2353
+ dot: ["500", "500"],
2354
+ icon: ["500", "500"]
2355
+ }
2356
+ },
2329
2357
  bg: ["50", "950"],
2358
+ border: ["100", "900"],
2359
+ code: {
2360
+ bg: ["500/0.1", "400/0.1"],
2361
+ fg: ["700/0.6", "400/0.6"]
2362
+ },
2330
2363
  fg: ["700", "400"],
2331
2364
  icon: ["600", "500"],
2332
- border: ["100", "900"],
2333
- accent: {
2334
- fg: ["purple/700/0.6", "purple/400/0.8"]
2365
+ kbd: {
2366
+ bg: ["white", "black"],
2367
+ fg: ["600", "400"],
2368
+ border: ["200", "800"]
2335
2369
  },
2336
2370
  link: {
2337
2371
  fg: ["blue/700/0.6", "blue/400/0.8"]
@@ -2340,19 +2374,9 @@ const defaultColorTokens = {
2340
2374
  bg: ["100", "950"],
2341
2375
  fg: ["700/0.6", "400/0.6"]
2342
2376
  },
2343
- code: {
2344
- bg: ["500/0.1", "400/0.1"],
2345
- fg: ["700/0.6", "400/0.6"]
2346
- },
2347
2377
  skeleton: {
2348
2378
  from: ["100", "900"],
2349
2379
  to: ["100/0.5", "900/0.5"]
2350
- },
2351
- badge: {
2352
- "*": {
2353
- dot: ["300", "700"],
2354
- icon: ["600", "400"]
2355
- }
2356
2380
  }
2357
2381
  },
2358
2382
  hovered: {
@@ -2369,21 +2393,35 @@ const defaultColorTokens = {
2369
2393
  },
2370
2394
  disabled: {
2371
2395
  _hue: "gray",
2372
- fg: ["200", "800"],
2373
- icon: ["200", "800"],
2396
+ accent: {
2397
+ fg: ["200", "800"]
2398
+ },
2399
+ badge: {
2400
+ "*": {
2401
+ _hue: "gray",
2402
+ bg: ["50", "950"],
2403
+ fg: ["gray/200", "gray/800"],
2404
+ dot: ["gray/200", "gray/800"],
2405
+ icon: ["gray/200", "gray/800"]
2406
+ }
2407
+ },
2374
2408
  border: ["100", "900"],
2375
- muted: {
2376
- fg: ["200/0.6", "900/0.6"]
2409
+ code: {
2410
+ bg: ["50", "950"],
2411
+ fg: ["200", "800"]
2377
2412
  },
2378
- accent: {
2379
- fg: ["200/0.6", "900/0.6"]
2413
+ fg: ["200", "800"],
2414
+ icon: ["200", "800"],
2415
+ kbd: {
2416
+ bg: ["white", "black"],
2417
+ fg: ["200", "800"],
2418
+ border: ["100", "900"]
2380
2419
  },
2381
2420
  link: {
2382
- fg: ["200/0.6", "900/0.6"]
2421
+ fg: ["200", "800"]
2383
2422
  },
2384
- code: {
2385
- bg: ["50/0.5", "950/0.5"],
2386
- fg: ["200/0.6", "900/0.6"]
2423
+ muted: {
2424
+ fg: ["200", "800"]
2387
2425
  }
2388
2426
  }
2389
2427
  },
@@ -2402,33 +2440,40 @@ const defaultColorTokens = {
2402
2440
  "*": {
2403
2441
  "*": {
2404
2442
  _blend: ["multiply", "screen"],
2443
+ accent: {
2444
+ fg: ["purple/700/0.7", "purple/300/0.7"]
2445
+ },
2446
+ badge: {
2447
+ "*": {
2448
+ bg: ["100", "900"],
2449
+ fg: ["600", "400"],
2450
+ dot: ["500", "500"],
2451
+ icon: ["500", "500"]
2452
+ }
2453
+ },
2405
2454
  bg: ["white", "black"],
2406
- fg: ["700", "300"],
2407
- icon: ["700/0.7", "300/0.7"],
2408
2455
  border: ["white/0", "black/0"],
2409
- muted: {
2456
+ code: {
2410
2457
  bg: ["100", "950"],
2411
- fg: ["700/0.7", "300/0.7"]
2458
+ fg: ["600", "300"]
2412
2459
  },
2413
- accent: {
2414
- fg: ["purple/700/0.7", "purple/300/0.7"]
2460
+ fg: ["700", "300"],
2461
+ icon: ["700/0.7", "300/0.7"],
2462
+ kbd: {
2463
+ bg: ["white", "black"],
2464
+ fg: ["600", "400"],
2465
+ border: ["200", "800"]
2415
2466
  },
2416
2467
  link: {
2417
2468
  fg: ["blue/700/0.7", "blue/300/0.7"]
2418
2469
  },
2419
- code: {
2470
+ muted: {
2420
2471
  bg: ["100", "950"],
2421
- fg: ["600", "300"]
2472
+ fg: ["700/0.7", "300/0.7"]
2422
2473
  },
2423
2474
  skeleton: {
2424
2475
  from: ["100", "900"],
2425
2476
  to: ["100/0.5", "900/0.5"]
2426
- },
2427
- badge: {
2428
- "*": {
2429
- dot: ["300", "700"],
2430
- icon: ["600", "400"]
2431
- }
2432
2477
  }
2433
2478
  },
2434
2479
  hovered: {
@@ -2448,19 +2493,33 @@ const defaultColorTokens = {
2448
2493
  },
2449
2494
  disabled: {
2450
2495
  _hue: "gray",
2496
+ badge: {
2497
+ "*": {
2498
+ _hue: "gray",
2499
+ bg: ["50", "950"],
2500
+ fg: ["gray/200", "gray/800"],
2501
+ dot: ["gray/200", "gray/800"],
2502
+ icon: ["gray/200", "gray/800"]
2503
+ }
2504
+ },
2451
2505
  fg: ["200", "800"],
2452
2506
  muted: {
2453
- fg: ["200/0.6", "900/0.6"]
2507
+ fg: ["200", "800"]
2454
2508
  },
2455
2509
  accent: {
2456
- fg: ["200/0.6", "900/0.6"]
2510
+ fg: ["200", "800"]
2511
+ },
2512
+ kbd: {
2513
+ bg: ["white", "black"],
2514
+ fg: ["200", "800"],
2515
+ border: ["100", "900"]
2457
2516
  },
2458
2517
  link: {
2459
- fg: ["200/0.6", "900/0.6"]
2518
+ fg: ["200", "800"]
2460
2519
  },
2461
2520
  code: {
2462
- bg: ["50/0.5", "950/0.5"],
2463
- fg: ["200/0.6", "900/0.6"]
2521
+ bg: ["50", "950"],
2522
+ fg: ["200", "800"]
2464
2523
  }
2465
2524
  }
2466
2525
  }
@@ -2510,10 +2569,25 @@ const defaultColorTokens = {
2510
2569
  _blend: ["screen", "multiply"],
2511
2570
  bg: ["500", "400"],
2512
2571
  fg: ["white", "black"]
2572
+ },
2573
+ yellow: {
2574
+ bg: ["600", "400"]
2575
+ },
2576
+ green: {
2577
+ bg: ["600", "400"]
2578
+ },
2579
+ cyan: {
2580
+ bg: ["600", "400"]
2581
+ }
2582
+ },
2583
+ badge: {
2584
+ "*": {
2585
+ // _blend: ['multiply', 'screen'],
2586
+ bg: ["100", "900"],
2587
+ fg: ["600", "400"],
2588
+ dot: ["500", "500"],
2589
+ icon: ["500", "500"]
2513
2590
  }
2514
- // yellow: {bg: ['600', '400']},
2515
- // green: {bg: ['600', '400']},
2516
- // cyan: {bg: ['600', '400']},
2517
2591
  },
2518
2592
  border: ["200", "800"],
2519
2593
  muted: {
@@ -2523,6 +2597,11 @@ const defaultColorTokens = {
2523
2597
  accent: {
2524
2598
  fg: ["purple/600", "purple/400"]
2525
2599
  },
2600
+ kbd: {
2601
+ bg: ["white", "black"],
2602
+ fg: ["600", "400"],
2603
+ border: ["200", "800"]
2604
+ },
2526
2605
  link: {
2527
2606
  fg: ["blue/700", "blue/300"]
2528
2607
  },
@@ -2533,21 +2612,6 @@ const defaultColorTokens = {
2533
2612
  skeleton: {
2534
2613
  from: ["100", "900"],
2535
2614
  to: ["100/0.5", "900/0.5"]
2536
- },
2537
- badge: {
2538
- "*": {
2539
- // _blend: ['multiply', 'screen'],
2540
- bg: ["100", "900"],
2541
- fg: ["600", "200"],
2542
- dot: ["300", "700"],
2543
- icon: ["600", "400"]
2544
- }
2545
- },
2546
- kbd: {
2547
- // _blend: ['multiply', 'screen'],
2548
- bg: ["white", "black"],
2549
- fg: ["600", "400"],
2550
- border: ["200", "800"]
2551
2615
  }
2552
2616
  },
2553
2617
  hovered: {
@@ -3818,7 +3882,7 @@ function renderColorValue(str, options) {
3818
3882
  try {
3819
3883
  hex = mixThemeColor(hex, mixOptions);
3820
3884
  } catch (err) {
3821
- console.log("could not blend", hex, mixOptions);
3885
+ console.warn("could not blend", hex, mixOptions);
3822
3886
  throw err;
3823
3887
  }
3824
3888
  if (hex === "#aN") {
@@ -4070,10 +4134,9 @@ function renderThemeColorBadgeColor(value, options) {
4070
4134
  colorPalette
4071
4135
  };
4072
4136
  return {
4073
- // _blend: blendMode,
4074
4137
  bg,
4075
- fg: renderColorValue(value.fg, colorOptions),
4076
4138
  dot: renderColorValue(value.dot, colorOptions),
4139
+ fg: renderColorValue(value.fg, colorOptions),
4077
4140
  icon: renderColorValue(value.icon, colorOptions)
4078
4141
  };
4079
4142
  }
@@ -4132,7 +4195,7 @@ function renderThemeColorState(value, options) {
4132
4195
  blendMode
4133
4196
  }),
4134
4197
  badge: renderThemeColorBadge(value.badge, {
4135
- baseBg,
4198
+ baseBg: bg,
4136
4199
  colorPalette,
4137
4200
  blendMode
4138
4201
  }),
@@ -4340,6 +4403,5 @@ function _setCachedTheme(rootTheme, scheme, tone, theme) {
4340
4403
  const toneCache = schemeCache.get(tone);
4341
4404
  toneCache.set(rootTheme, theme);
4342
4405
  }
4343
- const defaultTheme = buildTheme();
4344
- export { COLOR_CONFIG_AVATAR_COLORS, COLOR_CONFIG_BLEND_KEYS, COLOR_CONFIG_CARD_KEYS, COLOR_CONFIG_CARD_TONES, COLOR_CONFIG_INPUT_MODES, COLOR_CONFIG_INPUT_STATES, COLOR_CONFIG_STATES, COLOR_CONFIG_STATE_KEYS, COLOR_CONFIG_STATE_TONES, THEME_COLOR_AVATAR_COLORS, THEME_COLOR_BLEND_MODES, THEME_COLOR_BUTTON_MODES, THEME_COLOR_CARD_TONES, THEME_COLOR_INPUT_MODES, THEME_COLOR_INPUT_STATES, THEME_COLOR_STATES, THEME_COLOR_STATE_TONES, buildTheme, createColorTheme, defaultTheme, getContrastRatio, getScopedTheme, getTheme_v2, hexToRgb, hslToRgb, isColorBlendModeValue, isColorButtonMode, isColorConfigBaseKey, isColorConfigBaseTone, isColorConfigBlendKey, isColorConfigStateKey, isColorConfigStateTone, isColorHueKey, isColorOpacityValue, isColorTintKey, isColorTokenValue, isColorValue, is_v0, is_v2, mix, multiply, parseColor, parseTokenKey, parseTokenValue, rgbToHex, rgbToHsl, rgba, rgbaToRGBA, screen, v0_v2, v2_v0 };
4406
+ export { COLOR_CONFIG_AVATAR_COLORS, COLOR_CONFIG_BLEND_KEYS, COLOR_CONFIG_CARD_KEYS, COLOR_CONFIG_CARD_TONES, COLOR_CONFIG_INPUT_MODES, COLOR_CONFIG_INPUT_STATES, COLOR_CONFIG_STATES, COLOR_CONFIG_STATE_KEYS, COLOR_CONFIG_STATE_TONES, THEME_COLOR_AVATAR_COLORS, THEME_COLOR_BLEND_MODES, THEME_COLOR_BUTTON_MODES, THEME_COLOR_CARD_TONES, THEME_COLOR_INPUT_MODES, THEME_COLOR_INPUT_STATES, THEME_COLOR_SCHEMES, THEME_COLOR_STATES, THEME_COLOR_STATE_TONES, buildTheme, createColorTheme, getContrastRatio, getScopedTheme, getTheme_v2, hexToRgb, hslToRgb, isColorBlendModeValue, isColorButtonMode, isColorConfigBaseKey, isColorConfigBaseTone, isColorConfigBlendKey, isColorConfigStateKey, isColorConfigStateTone, isColorHueKey, isColorOpacityValue, isColorTintKey, isColorTokenValue, isColorValue, is_v0, is_v2, mix, multiply, parseColor, parseTokenKey, parseTokenValue, rgbToHex, rgbToHsl, rgba, rgbaToRGBA, screen, v0_v2, v2_v0 };
4345
4407
  //# sourceMappingURL=theme.esm.js.map