@diegopluna/narvi 0.0.2 → 0.1.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.
Files changed (108) hide show
  1. package/README.md +17 -6
  2. package/dist/base.css +96 -0
  3. package/dist/components/activity/ActivityTrigger.svelte +2 -3
  4. package/dist/components/app-shell/AppShellHeader.svelte +2 -3
  5. package/dist/components/app-shell/AppShellSidebar.svelte +6 -6
  6. package/dist/components/approval/Approval.svelte +8 -4
  7. package/dist/components/button/Button.svelte +15 -18
  8. package/dist/components/card/Card.svelte +10 -13
  9. package/dist/components/checkbox/Checkbox.svelte +16 -13
  10. package/dist/components/collapsible/CollapsibleContent.svelte +38 -0
  11. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +11 -0
  12. package/dist/components/collapsible/CollapsibleRoot.svelte +44 -0
  13. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +11 -0
  14. package/dist/components/collapsible/CollapsibleTrigger.svelte +83 -0
  15. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +13 -0
  16. package/dist/components/collapsible/context.d.ts +5 -0
  17. package/dist/components/collapsible/context.js +11 -0
  18. package/dist/components/collapsible/index.d.ts +7 -0
  19. package/dist/components/collapsible/index.js +4 -0
  20. package/dist/components/command/styles.js +3 -3
  21. package/dist/components/composer/ComposerAttachment.svelte +4 -6
  22. package/dist/components/composer/ComposerModelPicker.svelte +8 -10
  23. package/dist/components/composer/ComposerRoot.svelte +7 -6
  24. package/dist/components/composer/ComposerSubmit.svelte +4 -5
  25. package/dist/components/composer/ComposerToggle.svelte +11 -11
  26. package/dist/components/conversation/ConversationScrollButton.svelte +6 -8
  27. package/dist/components/dialog/DialogContent.svelte +5 -1
  28. package/dist/components/dialog/styles.d.ts +0 -23
  29. package/dist/components/dialog/styles.js +7 -43
  30. package/dist/components/grid/Grid.svelte +111 -0
  31. package/dist/components/grid/Grid.svelte.d.ts +27 -0
  32. package/dist/components/hover-card/HoverCardContent.svelte +50 -0
  33. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +10 -0
  34. package/dist/components/hover-card/HoverCardRoot.svelte +22 -0
  35. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -0
  36. package/dist/components/hover-card/index.d.ts +7 -0
  37. package/dist/components/hover-card/index.js +7 -0
  38. package/dist/components/link/Link.svelte +2 -4
  39. package/dist/components/message/MessageAction.svelte +2 -3
  40. package/dist/components/message/MessageActions.svelte +2 -3
  41. package/dist/components/message/MessageCopy.svelte +4 -5
  42. package/dist/components/message/MessageRoot.svelte +3 -4
  43. package/dist/components/message/MessageTime.svelte +2 -3
  44. package/dist/components/plan/Plan.svelte +3 -4
  45. package/dist/components/progress/Progress.svelte +4 -6
  46. package/dist/components/rail/RailItem.svelte +9 -9
  47. package/dist/components/reasoning/ReasoningTrigger.svelte +2 -3
  48. package/dist/components/resize-handle/ResizeHandle.svelte +3 -5
  49. package/dist/components/reveal/Reveal.svelte +89 -0
  50. package/dist/components/reveal/Reveal.svelte.d.ts +17 -0
  51. package/dist/components/reveal/revealed.d.ts +38 -0
  52. package/dist/components/reveal/revealed.js +79 -0
  53. package/dist/components/segmented/SegmentedControl.svelte +5 -9
  54. package/dist/components/sheet/SheetContent.svelte +63 -0
  55. package/dist/components/sheet/SheetContent.svelte.d.ts +18 -0
  56. package/dist/components/sheet/index.d.ts +12 -0
  57. package/dist/components/sheet/index.js +12 -0
  58. package/dist/components/sheet/styles.d.ts +51 -0
  59. package/dist/components/sheet/styles.js +65 -0
  60. package/dist/components/shimmer/Shimmer.svelte +8 -6
  61. package/dist/components/sidebar/SidebarGroup.svelte +5 -3
  62. package/dist/components/sidebar/SidebarItem.svelte +10 -8
  63. package/dist/components/slider/Slider.svelte +199 -0
  64. package/dist/components/slider/Slider.svelte.d.ts +55 -0
  65. package/dist/components/stack/Stack.svelte +37 -44
  66. package/dist/components/stack/Stack.svelte.d.ts +12 -6
  67. package/dist/components/suggestions/SuggestionsItem.svelte +7 -9
  68. package/dist/components/switch/Switch.svelte +8 -12
  69. package/dist/components/tabs/Tabs.svelte +3 -6
  70. package/dist/components/text/Text.svelte +47 -5
  71. package/dist/components/text/Text.svelte.d.ts +8 -2
  72. package/dist/components/toast/Toaster.svelte +7 -5
  73. package/dist/components/toggle/Toggle.svelte +40 -0
  74. package/dist/components/toggle/Toggle.svelte.d.ts +15 -0
  75. package/dist/components/toggle-group/ToggleGroupItem.svelte +37 -0
  76. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +12 -0
  77. package/dist/components/toggle-group/ToggleGroupRoot.svelte +95 -0
  78. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +33 -0
  79. package/dist/components/toggle-group/context.d.ts +6 -0
  80. package/dist/components/toggle-group/context.js +11 -0
  81. package/dist/components/toggle-group/index.d.ts +5 -0
  82. package/dist/components/toggle-group/index.js +3 -0
  83. package/dist/components/tool/ToolTrigger.svelte +4 -6
  84. package/dist/components/tooltip/TooltipContent.svelte +6 -3
  85. package/dist/components/work-fold/WorkFold.svelte +12 -25
  86. package/dist/components/work-fold/WorkFold.svelte.d.ts +1 -1
  87. package/dist/index.d.ts +23 -3
  88. package/dist/index.js +21 -2
  89. package/dist/internal/Chevron.svelte +2 -3
  90. package/dist/internal/Collapse.svelte +6 -5
  91. package/dist/internal/Collapse.svelte.d.ts +2 -1
  92. package/dist/internal/control.js +4 -4
  93. package/dist/internal/layer.js +6 -8
  94. package/dist/internal/layout.d.ts +13 -0
  95. package/dist/internal/layout.js +453 -0
  96. package/dist/internal/responsive.d.ts +45 -0
  97. package/dist/internal/responsive.js +42 -0
  98. package/dist/internal/sx.d.ts +30 -3
  99. package/dist/internal/sx.js +17 -0
  100. package/dist/internal/toggle.d.ts +74 -0
  101. package/dist/internal/toggle.js +87 -0
  102. package/dist/media.stylex.d.ts +52 -0
  103. package/dist/media.stylex.js +53 -0
  104. package/dist/tokens.stylex.d.ts +15 -0
  105. package/dist/tokens.stylex.js +20 -0
  106. package/dist/vite.d.ts +2 -0
  107. package/dist/vite.js +10 -2
  108. package/package.json +7 -2
package/README.md CHANGED
@@ -41,9 +41,9 @@ export default defineConfig({
41
41
  });
42
42
  ```
43
43
 
44
- Mount `<DevStyles />` in the root layout, import a stylesheet that sets
45
- `:root { color-scheme: light dark; }`, and import components from `@diegopluna/narvi`. The docs site covers
46
- this in full under Installation.
44
+ Mount `<DevStyles />` in the root layout, start your stylesheet with
45
+ `@import '@diegopluna/narvi/base.css';` (the page's colours, `color-scheme` and a small reset), and import
46
+ components from `@diegopluna/narvi`. The docs site covers this in full under Installation.
47
47
 
48
48
  ## Release
49
49
 
@@ -58,6 +58,14 @@ publish succeeds, so a failed run can be run again.
58
58
  `light-dark()` declaration, so the theme follows `color-scheme`. The palette is stone and
59
59
  moonlight: near-black and warm paper for surfaces, a pale metal ("mithril") for the solid button,
60
60
  and one silver-blue ("ithildin") that is kept for state: focus, selection and progress.
61
+ - **Conditions** live in `src/lib/media.stylex.ts`: `media.hover`, `media.motion`, `media.forcedColors`
62
+ and the rest, and the breakpoints `sm` to `xl`, as `defineConsts` constants that any file can import.
63
+ - **The base stylesheet**, `src/lib/base.css`, holds what belongs on the document: `color-scheme`, the
64
+ page's colours and a small reset, in the `narvi.base` layer below every component. Its colours are
65
+ copied from the tokens by `scripts/base-css.js` when the library is built, and a test checks them.
66
+ - **Layout props** on Stack and Grid take a value or values by breakpoint. They compile to static
67
+ classes: one rule reads a custom property per breakpoint (`src/lib/internal/layout.ts`), and each
68
+ value is a class that sets one of them (`src/lib/internal/responsive.ts` explains how).
61
69
  - **Components** live in `src/lib/components/<name>/<Name>.svelte`. Styles are created in the
62
70
  `<script module>` block and applied with the `attrs` helper from `src/lib/internal/sx.ts`, which
63
71
  also merges the consumer's `sx` and `class`. Interface text inherits the page's font; only large
@@ -66,7 +74,8 @@ publish succeeds, so a failed run can be run again.
66
74
  `src/lib/internal/shared.ts` adds a transparent outline that becomes the edge in forced-colours
67
75
  mode. Control boundaries (`colors.edge`) hold 3:1 against their surface.
68
76
  - **The Vite plugin** in `src/lib/vite.ts` is a preset over `@stylexjs/unplugin`. It puts every
69
- style in one cascade layer, `narvi`, so unlayered CSS beats it. `narvi({ tailwind: true })`
77
+ style in one cascade layer, `narvi`, so unlayered CSS beats it, and declares `narvi.base` first
78
+ inside it, so `base.css` stays below the components whichever stylesheet loads first. `narvi({ tailwind: true })`
70
79
  orders that layer between Tailwind's `base` and its `components` and `utilities`.
71
80
 
72
81
  The look started as a study in `Frame` + `Card`: a tray around an inset panel, whose radius is the
@@ -87,5 +96,7 @@ movement behind `prefers-reduced-motion: no-preference`.
87
96
  4. Add the page to `src/docs/nav.ts`.
88
97
 
89
98
  Two StyleX rules to keep in mind: values inside `stylex.create` must be known at build time, so a
90
- constant such as a media query has to be defined in the same file, and tokens must be imported
91
- straight from `tokens.stylex.js`.
99
+ media query comes from `media.stylex.js` (or is written in the same file), and tokens and media
100
+ queries must be imported straight from their `.stylex.js` files. Use `media` throughout rather than
101
+ writing a condition out: StyleX ranks a constant condition above a written one, and orders constant
102
+ breakpoints by width only when they are in px.
package/dist/base.css ADDED
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Narvi's base stylesheet: what a StyleX app needs on the document itself, and a small reset.
3
+ *
4
+ * @import '@diegopluna/narvi/base.css';
5
+ *
6
+ * It sits in `narvi.base`, the lowest layer of Narvi's own, so every component beats it, and
7
+ * any CSS of yours outside a layer beats both. The Narvi Vite plugin declares that layer
8
+ * first, so the order holds whichever stylesheet the browser reads first.
9
+ *
10
+ * A colour followed by a comment naming a token is copied from that token when the library
11
+ * is built (`scripts/base-css.js`), so the page and the components never drift apart.
12
+ */
13
+ @layer narvi.base {
14
+ *,
15
+ *::before,
16
+ *::after {
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ :root {
21
+ /* Narvi's colours take their light or dark half from this. */
22
+ color-scheme: light dark;
23
+ /* The page, on the root rather than the body, so overscroll shows it too */
24
+ background-color: light-dark(#f4f3ef, #06080c); /* colors.bg */
25
+ color: light-dark(#14171c, #e9edf3); /* colors.text */
26
+ /* Narvi's interface text inherits the page's face: set your own on the root */
27
+ font-family:
28
+ system-ui,
29
+ -apple-system,
30
+ 'Segoe UI',
31
+ Roboto,
32
+ sans-serif;
33
+ -webkit-text-size-adjust: 100%;
34
+ text-size-adjust: 100%;
35
+ -webkit-font-smoothing: antialiased;
36
+ -moz-osx-font-smoothing: grayscale;
37
+ text-rendering: optimizeLegibility;
38
+ }
39
+
40
+ body {
41
+ margin: 0;
42
+ }
43
+
44
+ /* Spacing comes from layout (Stack, Grid, gap), not from the browser's margins */
45
+ h1,
46
+ h2,
47
+ h3,
48
+ h4,
49
+ h5,
50
+ h6,
51
+ p,
52
+ blockquote,
53
+ figure,
54
+ dl,
55
+ dd,
56
+ pre {
57
+ margin: 0;
58
+ }
59
+
60
+ /* A list is laid out as you style it: no markers, no 40px indent */
61
+ ul,
62
+ ol,
63
+ menu {
64
+ margin: 0;
65
+ padding: 0;
66
+ list-style: none;
67
+ }
68
+
69
+ /* Media sit on their own line, and shrink with their container */
70
+ img,
71
+ picture,
72
+ svg,
73
+ video,
74
+ canvas,
75
+ audio,
76
+ iframe,
77
+ embed,
78
+ object {
79
+ display: block;
80
+ }
81
+
82
+ img,
83
+ video {
84
+ max-width: 100%;
85
+ height: auto;
86
+ }
87
+
88
+ /* Form controls take the page's face rather than the system's. Only the face: their size
89
+ and line height are left to the browser, or to the component, as without a reset. */
90
+ button,
91
+ input,
92
+ select,
93
+ textarea {
94
+ font-family: inherit;
95
+ }
96
+ }
@@ -7,6 +7,7 @@
7
7
  import { attrs, type Sx } from '../../internal/sx.js';
8
8
  import Tile from '../../internal/Tile.svelte';
9
9
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
10
+ import { media } from '../../media.stylex.js';
10
11
  import RollingText from '../rolling-text/RollingText.svelte';
11
12
  import { getActivityContext } from './context.js';
12
13
 
@@ -24,8 +25,6 @@
24
25
  sx?: Sx;
25
26
  };
26
27
 
27
- const HOVER = '@media (hover: hover) and (pointer: fine)';
28
-
29
28
  const styles = stylex.create({
30
29
  trigger: {
31
30
  display: 'flex',
@@ -39,7 +38,7 @@
39
38
  borderWidth: 0,
40
39
  borderRadius: radius.xs,
41
40
  backgroundColor: 'transparent',
42
- color: { default: colors.textMuted, ':hover': { default: null, [HOVER]: colors.text } },
41
+ color: { default: colors.textMuted, ':hover': { default: null, [media.hover]: colors.text } },
43
42
  fontFamily: 'inherit',
44
43
  fontSize: font.sizeMd,
45
44
  lineHeight: font.leadingSnug,
@@ -5,6 +5,7 @@
5
5
  import { shared } from '../../internal/shared.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
 
9
10
  export type AppShellHeaderProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
10
11
  /**
@@ -16,8 +17,6 @@
16
17
  children?: Snippet;
17
18
  };
18
19
 
19
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
20
-
21
20
  const styles = stylex.create({
22
21
  header: {
23
22
  display: 'flex',
@@ -34,7 +33,7 @@
34
33
  borderBottomStyle: 'solid',
35
34
  borderBottomColor: colors.line,
36
35
  fontSize: font.sizeMd,
37
- transitionProperty: { default: 'none', [MOTION]: 'padding-inline-start' },
36
+ transitionProperty: { default: 'none', [media.motion]: 'padding-inline-start' },
38
37
  transitionDuration: motion.slow,
39
38
  transitionTimingFunction: motion.easeInOut
40
39
  }
@@ -4,6 +4,7 @@
4
4
  import type { HTMLAttributes } from 'svelte/elements';
5
5
  import { attrs, type Sx } from '../../internal/sx.js';
6
6
  import { colors, motion } from '../../tokens.stylex.js';
7
+ import { media } from '../../media.stylex.js';
7
8
  import { useAppShell } from './context.js';
8
9
 
9
10
  export type AppShellSidebarProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
@@ -18,7 +19,6 @@
18
19
  children?: Snippet;
19
20
  };
20
21
 
21
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
22
22
  // The drawer's curve: quick out of the edge, a long gentle settle
23
23
  const DRAWER = 'cubic-bezier(0.32, 0.72, 0, 1)';
24
24
 
@@ -34,7 +34,7 @@
34
34
  },
35
35
  wide: {
36
36
  width: 'calc(var(--narvi-sidebar-width) + var(--narvi-rail-current, 0px))',
37
- transitionProperty: { default: 'none', [MOTION]: 'width' },
37
+ transitionProperty: { default: 'none', [media.motion]: 'width' },
38
38
  transitionDuration: motion.slow,
39
39
  transitionTimingFunction: motion.easeInOut
40
40
  },
@@ -53,15 +53,15 @@
53
53
  // Hidden only once it has slid away; shown at once when it opens, so
54
54
  // focus can move into it on the first frame
55
55
  visibility: 'hidden',
56
- transitionProperty: { default: 'visibility', [MOTION]: 'translate, visibility' },
57
- transitionDuration: { default: '0s', [MOTION]: '320ms, 0s' },
58
- transitionDelay: { default: '0s', [MOTION]: '0s, 320ms' },
56
+ transitionProperty: { default: 'visibility', [media.motion]: 'translate, visibility' },
57
+ transitionDuration: { default: '0s', [media.motion]: '320ms, 0s' },
58
+ transitionDelay: { default: '0s', [media.motion]: '0s, 320ms' },
59
59
  transitionTimingFunction: DRAWER
60
60
  },
61
61
  drawerOpen: {
62
62
  translate: '0 0',
63
63
  visibility: 'visible',
64
- transitionDelay: { default: '0s', [MOTION]: '0s, 0s' }
64
+ transitionDelay: { default: '0s', [media.motion]: '0s, 0s' }
65
65
  },
66
66
  scrim: {
67
67
  position: 'fixed',
@@ -10,6 +10,7 @@
10
10
  import Glyph from '../../internal/Glyph.svelte';
11
11
  import { attrs, type Sx } from '../../internal/sx.js';
12
12
  import { colors, font, motion, radius, space } from '../../tokens.stylex.js';
13
+ import { media } from '../../media.stylex.js';
13
14
  import Button from '../button/Button.svelte';
14
15
 
15
16
  export type ApprovalChoice = {
@@ -48,8 +49,6 @@
48
49
  class?: string;
49
50
  };
50
51
 
51
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
52
-
53
52
  const styles = stylex.create({
54
53
  card: {
55
54
  display: 'flex',
@@ -60,8 +59,11 @@
60
59
  backgroundColor: `color-mix(in oklab, ${colors.warning} 7%, ${colors.bgRaised})`,
61
60
  boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.warning} 40%, transparent)`,
62
61
  opacity: { default: 1, '@starting-style': 0 },
63
- translate: { default: null, [MOTION]: { default: '0 0', '@starting-style': '0 0.375rem' } },
64
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, translate' },
62
+ translate: {
63
+ default: null,
64
+ [media.motion]: { default: '0 0', '@starting-style': '0 0.375rem' }
65
+ },
66
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, translate' },
65
67
  transitionDuration: motion.slow,
66
68
  transitionTimingFunction: motion.easeOut
67
69
  },
@@ -90,6 +92,8 @@
90
92
  files: {
91
93
  margin: 0,
92
94
  paddingInlineStart: '1rem',
95
+ // Stated, not left to the browser: a reset such as base.css removes markers
96
+ listStyleType: 'disc',
93
97
  color: colors.textMuted,
94
98
  fontFamily: font.mono,
95
99
  fontSize: font.sizeXs,
@@ -5,6 +5,7 @@
5
5
  import { shared } from '../../internal/shared.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
  import Spinner from '../spinner/Spinner.svelte';
9
10
 
10
11
  export type ButtonVariant = 'primary' | 'secondary' | 'soft' | 'ghost' | 'danger';
@@ -25,10 +26,6 @@
25
26
  children?: Snippet;
26
27
  };
27
28
 
28
- // StyleX needs these in the same file to evaluate them at build time
29
- const HOVER = '@media (hover: hover) and (pointer: fine)';
30
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
31
-
32
29
  const styles = stylex.create({
33
30
  base: {
34
31
  position: 'relative',
@@ -49,16 +46,16 @@
49
46
  appearance: 'none',
50
47
  WebkitTapHighlightColor: 'transparent',
51
48
  // Press feedback, only for people who have not asked for less motion
52
- scale: { default: null, ':active': { default: null, [MOTION]: 0.96 } },
49
+ scale: { default: null, ':active': { default: null, [media.motion]: 0.96 } },
53
50
  // The press answers at once with a strong ease-out. Hover colours use a plain ease.
54
51
  transitionProperty: {
55
52
  default: 'background-color, color, filter',
56
- [MOTION]: 'scale, background-color, color, filter'
53
+ [media.motion]: 'scale, background-color, color, filter'
57
54
  },
58
55
  transitionDuration: motion.base,
59
56
  transitionTimingFunction: {
60
57
  default: 'ease',
61
- [MOTION]: `${motion.easeOut}, ease, ease, ease`
58
+ [media.motion]: `${motion.easeOut}, ease, ease, ease`
62
59
  }
63
60
  },
64
61
 
@@ -95,7 +92,7 @@
95
92
  color: colors.onMithril,
96
93
  backgroundImage: `linear-gradient(180deg, ${colors.mithrilTop}, ${colors.mithrilBottom})`,
97
94
  boxShadow: `inset 0 1px 0 ${colors.mithrilEdge}, inset 0 -1px 0 rgb(0 0 0 / 0.14), 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 22px -10px ${colors.mithrilDrop}`,
98
- filter: { default: null, ':hover': { default: null, [HOVER]: 'brightness(1.06)' } },
95
+ filter: { default: null, ':hover': { default: null, [media.hover]: 'brightness(1.06)' } },
99
96
  // The deeper hover shadow is a layer of its own that fades in. Fading
100
97
  // opacity is cheap; animating the shadow itself repaints it every frame.
101
98
  '::before': {
@@ -104,7 +101,7 @@
104
101
  inset: 0,
105
102
  borderRadius: 'inherit',
106
103
  boxShadow: `0 12px 22px -10px ${colors.mithrilDrop}`,
107
- opacity: { default: 0, ':hover': { default: null, [HOVER]: 1 } },
104
+ opacity: { default: 0, ':hover': { default: null, [media.hover]: 1 } },
108
105
  pointerEvents: 'none',
109
106
  transitionProperty: 'opacity',
110
107
  transitionDuration: motion.base,
@@ -115,7 +112,7 @@
115
112
  color: colors.text,
116
113
  backgroundColor: {
117
114
  default: colors.surfaceRaised,
118
- ':hover': { default: null, [HOVER]: colors.hover }
115
+ ':hover': { default: null, [media.hover]: colors.hover }
119
116
  },
120
117
  boxShadow: `inset 0 0 0 1px ${colors.lineStrong}, inset 0 1px 0 ${colors.highlight}, 0 1px 2px ${colors.shade}`
121
118
  },
@@ -123,17 +120,17 @@
123
120
  color: colors.ithil,
124
121
  backgroundColor: {
125
122
  default: colors.ithilSoft,
126
- ':hover': { default: null, [HOVER]: colors.focusHalo }
123
+ ':hover': { default: null, [media.hover]: colors.focusHalo }
127
124
  }
128
125
  },
129
126
  ghost: {
130
127
  color: {
131
128
  default: colors.textMuted,
132
- ':hover': { default: null, [HOVER]: colors.text }
129
+ ':hover': { default: null, [media.hover]: colors.text }
133
130
  },
134
131
  backgroundColor: {
135
132
  default: 'transparent',
136
- ':hover': { default: null, [HOVER]: colors.hover }
133
+ ':hover': { default: null, [media.hover]: colors.hover }
137
134
  }
138
135
  },
139
136
  danger: {
@@ -142,7 +139,7 @@
142
139
  default: 'transparent',
143
140
  ':hover': {
144
141
  default: null,
145
- [HOVER]: `color-mix(in oklab, ${colors.danger} 12%, transparent)`
142
+ [media.hover]: `color-mix(in oklab, ${colors.danger} 12%, transparent)`
146
143
  }
147
144
  },
148
145
  boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.danger} 45%, transparent)`
@@ -163,7 +160,7 @@
163
160
  alignItems: 'center',
164
161
  justifyContent: 'center',
165
162
  gap: 'inherit',
166
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, filter' },
163
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, filter' },
167
164
  transitionDuration: motion.base,
168
165
  transitionTimingFunction: motion.easeOut
169
166
  },
@@ -171,7 +168,7 @@
171
168
  // and not two things overlapping
172
169
  contentHidden: {
173
170
  opacity: 0,
174
- filter: { default: null, [MOTION]: 'blur(2px)' }
171
+ filter: { default: null, [media.motion]: 'blur(2px)' }
175
172
  },
176
173
  // The spinner fades in as the label fades out. It leaves at once: when the
177
174
  // work is done, the label should be back without delay.
@@ -181,8 +178,8 @@
181
178
  display: 'grid',
182
179
  placeItems: 'center',
183
180
  opacity: { default: 1, '@starting-style': 0 },
184
- scale: { default: null, [MOTION]: { default: 1, '@starting-style': 0.9 } },
185
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, scale' },
181
+ scale: { default: null, [media.motion]: { default: 1, '@starting-style': 0.9 } },
182
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, scale' },
186
183
  transitionDuration: motion.base,
187
184
  transitionTimingFunction: motion.easeOut
188
185
  }
@@ -5,6 +5,7 @@
5
5
  import { shared } from '../../internal/shared.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors, font, motion, radius, space } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
 
9
10
  export type CardVariant = 'raised' | 'outlined' | 'filled';
10
11
  export type CardPadding = 'none' | 'sm' | 'md' | 'lg';
@@ -25,10 +26,6 @@
25
26
  children?: Snippet;
26
27
  };
27
28
 
28
- // StyleX needs these in the same file to evaluate them at build time
29
- const HOVER = '@media (hover: hover) and (pointer: fine)';
30
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
31
-
32
29
  const styles = stylex.create({
33
30
  base: {
34
31
  boxSizing: 'border-box',
@@ -61,51 +58,51 @@
61
58
  cursor: 'pointer',
62
59
  WebkitTapHighlightColor: 'transparent',
63
60
  // Press feedback, smaller than a button's, as a card is much larger
64
- scale: { default: null, ':active': { default: null, [MOTION]: 0.99 } },
61
+ scale: { default: null, ':active': { default: null, [media.motion]: 0.99 } },
65
62
  transitionProperty: {
66
63
  default: 'background-color, box-shadow',
67
- [MOTION]: 'scale, background-color, box-shadow'
64
+ [media.motion]: 'scale, background-color, box-shadow'
68
65
  },
69
66
  transitionDuration: motion.base,
70
67
  transitionTimingFunction: {
71
68
  default: 'ease',
72
- [MOTION]: `${motion.easeOut}, ease, ease`
69
+ [media.motion]: `${motion.easeOut}, ease, ease`
73
70
  }
74
71
  },
75
72
  // On hover the surface lifts a step and its edge firms up, as a control's does
76
73
  raisedLink: {
77
74
  backgroundColor: {
78
75
  default: colors.bgRaised,
79
- ':hover': { default: null, [HOVER]: colors.surfaceRaised }
76
+ ':hover': { default: null, [media.hover]: colors.surfaceRaised }
80
77
  },
81
78
  boxShadow: {
82
79
  default: `inset 0 0 0 1px ${colors.line}, 0 1px 2px ${colors.shade}, 0 12px 24px -16px ${colors.shade}`,
83
80
  ':hover': {
84
81
  default: null,
85
- [HOVER]: `inset 0 0 0 1px ${colors.lineStrong}, 0 1px 2px ${colors.shade}, 0 14px 28px -16px ${colors.shade}`
82
+ [media.hover]: `inset 0 0 0 1px ${colors.lineStrong}, 0 1px 2px ${colors.shade}, 0 14px 28px -16px ${colors.shade}`
86
83
  }
87
84
  }
88
85
  },
89
86
  outlinedLink: {
90
87
  backgroundColor: {
91
88
  default: colors.bgRaised,
92
- ':hover': { default: null, [HOVER]: colors.surfaceRaised }
89
+ ':hover': { default: null, [media.hover]: colors.surfaceRaised }
93
90
  },
94
91
  boxShadow: {
95
92
  default: `inset 0 0 0 1px ${colors.line}`,
96
- ':hover': { default: null, [HOVER]: `inset 0 0 0 1px ${colors.lineStrong}` }
93
+ ':hover': { default: null, [media.hover]: `inset 0 0 0 1px ${colors.lineStrong}` }
97
94
  }
98
95
  },
99
96
  filledLink: {
100
97
  backgroundColor: {
101
98
  default: colors.well,
102
- ':hover': { default: null, [HOVER]: colors.hover }
99
+ ':hover': { default: null, [media.hover]: colors.hover }
103
100
  },
104
101
  boxShadow: {
105
102
  default: `inset 0 0 0 1px ${colors.line}, inset 0 1px 2px ${colors.shade}`,
106
103
  ':hover': {
107
104
  default: null,
108
- [HOVER]: `inset 0 0 0 1px ${colors.lineStrong}, inset 0 1px 2px ${colors.shade}`
105
+ [media.hover]: `inset 0 0 0 1px ${colors.lineStrong}, inset 0 1px 2px ${colors.shade}`
109
106
  }
110
107
  }
111
108
  }
@@ -4,6 +4,7 @@
4
4
  import type { HTMLInputAttributes } from 'svelte/elements';
5
5
  import { attrs, type Sx } from '../../internal/sx.js';
6
6
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
7
+ import { media } from '../../media.stylex.js';
7
8
 
8
9
  export type CheckboxProps = Omit<HTMLInputAttributes, 'type' | 'children'> & {
9
10
  checked?: boolean;
@@ -19,11 +20,6 @@
19
20
  children?: Snippet;
20
21
  };
21
22
 
22
- // StyleX needs these in the same file to evaluate them at build time
23
- const HOVER = '@media (hover: hover) and (pointer: fine)';
24
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
25
- const FORCED = '@media (forced-colors: active)';
26
-
27
23
  const CHECK = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5 5 9l4.5-6'/%3E%3C/svg%3E")`;
28
24
  const DASH = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2.5 6h7'/%3E%3C/svg%3E")`;
29
25
 
@@ -65,18 +61,18 @@
65
61
  borderRadius: radius.xs,
66
62
  borderColor: {
67
63
  default: colors.edge,
68
- ':hover': { default: null, [HOVER]: colors.edgeHover },
64
+ ':hover': { default: null, [media.hover]: colors.edgeHover },
69
65
  ':checked': 'transparent',
70
66
  ':indeterminate': 'transparent',
71
- [FORCED]: 'ButtonText'
67
+ [media.forcedColors]: 'ButtonText'
72
68
  },
73
- backgroundColor: { default: colors.well, [FORCED]: 'Canvas' },
69
+ backgroundColor: { default: colors.well, [media.forcedColors]: 'Canvas' },
74
70
  backgroundOrigin: 'border-box',
75
71
  backgroundImage: {
76
72
  default: 'none',
77
73
  ':checked': `linear-gradient(180deg, ${colors.ithil}, ${colors.ithilStrong})`,
78
74
  ':indeterminate': `linear-gradient(180deg, ${colors.ithil}, ${colors.ithilStrong})`,
79
- [FORCED]: {
75
+ [media.forcedColors]: {
80
76
  default: 'none',
81
77
  ':checked': 'linear-gradient(Highlight, Highlight)',
82
78
  ':indeterminate': 'linear-gradient(Highlight, Highlight)'
@@ -102,7 +98,7 @@
102
98
  content: '""',
103
99
  width: '0.625rem',
104
100
  height: '0.625rem',
105
- backgroundColor: { default: colors.onIthil, [FORCED]: 'HighlightText' },
101
+ backgroundColor: { default: colors.onIthil, [media.forcedColors]: 'HighlightText' },
106
102
  maskImage: { default: CHECK, ':indeterminate': DASH },
107
103
  maskSize: 'contain',
108
104
  maskRepeat: 'no-repeat',
@@ -111,12 +107,19 @@
111
107
  // The mark settles in from just under full size, with a touch of blur to
112
108
  // soften the swap. It never grows from nothing, and it is quick: boxes
113
109
  // get ticked many times a day.
114
- scale: { default: null, [MOTION]: { default: 0.9, ':checked': 1, ':indeterminate': 1 } },
110
+ scale: {
111
+ default: null,
112
+ [media.motion]: { default: 0.9, ':checked': 1, ':indeterminate': 1 }
113
+ },
115
114
  filter: {
116
115
  default: null,
117
- [MOTION]: { default: 'blur(2px)', ':checked': 'blur(0px)', ':indeterminate': 'blur(0px)' }
116
+ [media.motion]: {
117
+ default: 'blur(2px)',
118
+ ':checked': 'blur(0px)',
119
+ ':indeterminate': 'blur(0px)'
120
+ }
118
121
  },
119
- transitionProperty: { default: 'opacity', [MOTION]: 'opacity, scale, filter' },
122
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, scale, filter' },
120
123
  transitionDuration: motion.fast,
121
124
  transitionTimingFunction: motion.easeOut
122
125
  }
@@ -0,0 +1,38 @@
1
+ <script lang="ts" module>
2
+ import { Collapsible } from 'bits-ui';
3
+ import type { Snippet } from 'svelte';
4
+ import Collapse from '../../internal/Collapse.svelte';
5
+ import type { Sx } from '../../internal/sx.js';
6
+
7
+ export type CollapsibleContentProps = Omit<
8
+ Collapsible.ContentProps,
9
+ 'children' | 'child' | 'forceMount' | 'hiddenUntilFound'
10
+ > & {
11
+ /** Styles for the content, inside the fold: padding and gaps go here. */
12
+ sx?: Sx;
13
+ children?: Snippet;
14
+ };
15
+ </script>
16
+
17
+ <script lang="ts">
18
+ let {
19
+ ref = $bindable(null),
20
+ sx,
21
+ class: className,
22
+ children,
23
+ ...rest
24
+ }: CollapsibleContentProps = $props();
25
+ </script>
26
+
27
+ <!--
28
+ Kept in the page while shut, so its height can ease between nothing and its
29
+ content's; Collapse makes it inert meanwhile, out of the tab order and the
30
+ accessibility tree.
31
+ -->
32
+ <Collapsible.Content bind:ref forceMount {...rest}>
33
+ {#snippet child({ props, open })}
34
+ <Collapse {open} data-slot="collapsible-content" {...props} innerSx={sx} innerClass={className}>
35
+ {@render children?.()}
36
+ </Collapse>
37
+ {/snippet}
38
+ </Collapsible.Content>
@@ -0,0 +1,11 @@
1
+ import { Collapsible } from 'bits-ui';
2
+ import type { Snippet } from 'svelte';
3
+ import type { Sx } from '../../internal/sx.js';
4
+ export type CollapsibleContentProps = Omit<Collapsible.ContentProps, 'children' | 'child' | 'forceMount' | 'hiddenUntilFound'> & {
5
+ /** Styles for the content, inside the fold: padding and gaps go here. */
6
+ sx?: Sx;
7
+ children?: Snippet;
8
+ };
9
+ declare const CollapsibleContent: import("svelte").Component<CollapsibleContentProps, {}, "ref">;
10
+ type CollapsibleContent = ReturnType<typeof CollapsibleContent>;
11
+ export default CollapsibleContent;
@@ -0,0 +1,44 @@
1
+ <script lang="ts" module>
2
+ import { Collapsible } from 'bits-ui';
3
+ import * as stylex from '@stylexjs/stylex';
4
+ import type { Snippet } from 'svelte';
5
+ import { attrs, type Sx } from '../../internal/sx.js';
6
+ import { setCollapsibleContext } from './context.js';
7
+
8
+ export type CollapsibleRootProps = Omit<Collapsible.RootProps, 'children' | 'child'> & {
9
+ sx?: Sx;
10
+ /** A Collapsible.Trigger and a Collapsible.Content, with anything else around them. */
11
+ children?: Snippet;
12
+ };
13
+
14
+ const styles = stylex.create({
15
+ root: { display: 'flex', flexDirection: 'column', minWidth: 0 }
16
+ });
17
+ </script>
18
+
19
+ <script lang="ts">
20
+ let {
21
+ open = $bindable(false),
22
+ ref = $bindable(null),
23
+ sx,
24
+ class: className,
25
+ children,
26
+ ...rest
27
+ }: CollapsibleRootProps = $props();
28
+
29
+ setCollapsibleContext({
30
+ get open() {
31
+ return open;
32
+ }
33
+ });
34
+ </script>
35
+
36
+ <Collapsible.Root
37
+ bind:open
38
+ bind:ref
39
+ data-slot="collapsible"
40
+ {...rest}
41
+ {...attrs([styles.root, sx], className)}
42
+ >
43
+ {@render children?.()}
44
+ </Collapsible.Root>
@@ -0,0 +1,11 @@
1
+ import { Collapsible } from 'bits-ui';
2
+ import type { Snippet } from 'svelte';
3
+ import { type Sx } from '../../internal/sx.js';
4
+ export type CollapsibleRootProps = Omit<Collapsible.RootProps, 'children' | 'child'> & {
5
+ sx?: Sx;
6
+ /** A Collapsible.Trigger and a Collapsible.Content, with anything else around them. */
7
+ children?: Snippet;
8
+ };
9
+ declare const CollapsibleRoot: import("svelte").Component<CollapsibleRootProps, {}, "ref" | "open">;
10
+ type CollapsibleRoot = ReturnType<typeof CollapsibleRoot>;
11
+ export default CollapsibleRoot;