@diegopluna/narvi 0.0.1 → 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 (112) hide show
  1. package/README.md +27 -8
  2. package/dist/base.css +96 -0
  3. package/dist/color.d.ts +38 -0
  4. package/dist/color.js +88 -0
  5. package/dist/components/activity/ActivityTrigger.svelte +2 -3
  6. package/dist/components/app-shell/AppShellHeader.svelte +2 -3
  7. package/dist/components/app-shell/AppShellSidebar.svelte +6 -6
  8. package/dist/components/approval/Approval.svelte +8 -4
  9. package/dist/components/button/Button.svelte +15 -18
  10. package/dist/components/card/Card.svelte +98 -12
  11. package/dist/components/card/Card.svelte.d.ts +8 -3
  12. package/dist/components/checkbox/Checkbox.svelte +16 -13
  13. package/dist/components/collapsible/CollapsibleContent.svelte +38 -0
  14. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +11 -0
  15. package/dist/components/collapsible/CollapsibleRoot.svelte +44 -0
  16. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +11 -0
  17. package/dist/components/collapsible/CollapsibleTrigger.svelte +83 -0
  18. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +13 -0
  19. package/dist/components/collapsible/context.d.ts +5 -0
  20. package/dist/components/collapsible/context.js +11 -0
  21. package/dist/components/collapsible/index.d.ts +7 -0
  22. package/dist/components/collapsible/index.js +4 -0
  23. package/dist/components/command/styles.js +3 -3
  24. package/dist/components/composer/ComposerAttachment.svelte +4 -6
  25. package/dist/components/composer/ComposerModelPicker.svelte +8 -10
  26. package/dist/components/composer/ComposerRoot.svelte +7 -6
  27. package/dist/components/composer/ComposerSubmit.svelte +4 -5
  28. package/dist/components/composer/ComposerToggle.svelte +11 -11
  29. package/dist/components/conversation/ConversationScrollButton.svelte +6 -8
  30. package/dist/components/dialog/DialogContent.svelte +5 -1
  31. package/dist/components/dialog/styles.d.ts +0 -23
  32. package/dist/components/dialog/styles.js +7 -43
  33. package/dist/components/grid/Grid.svelte +111 -0
  34. package/dist/components/grid/Grid.svelte.d.ts +27 -0
  35. package/dist/components/hover-card/HoverCardContent.svelte +50 -0
  36. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +10 -0
  37. package/dist/components/hover-card/HoverCardRoot.svelte +22 -0
  38. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -0
  39. package/dist/components/hover-card/index.d.ts +7 -0
  40. package/dist/components/hover-card/index.js +7 -0
  41. package/dist/components/link/Link.svelte +2 -4
  42. package/dist/components/message/MessageAction.svelte +2 -3
  43. package/dist/components/message/MessageActions.svelte +2 -3
  44. package/dist/components/message/MessageCopy.svelte +4 -5
  45. package/dist/components/message/MessageRoot.svelte +3 -4
  46. package/dist/components/message/MessageTime.svelte +2 -3
  47. package/dist/components/plan/Plan.svelte +3 -4
  48. package/dist/components/progress/Progress.svelte +4 -6
  49. package/dist/components/rail/RailItem.svelte +9 -9
  50. package/dist/components/reasoning/ReasoningTrigger.svelte +2 -3
  51. package/dist/components/resize-handle/ResizeHandle.svelte +3 -5
  52. package/dist/components/reveal/Reveal.svelte +89 -0
  53. package/dist/components/reveal/Reveal.svelte.d.ts +17 -0
  54. package/dist/components/reveal/revealed.d.ts +38 -0
  55. package/dist/components/reveal/revealed.js +79 -0
  56. package/dist/components/segmented/SegmentedControl.svelte +5 -9
  57. package/dist/components/sheet/SheetContent.svelte +63 -0
  58. package/dist/components/sheet/SheetContent.svelte.d.ts +18 -0
  59. package/dist/components/sheet/index.d.ts +12 -0
  60. package/dist/components/sheet/index.js +12 -0
  61. package/dist/components/sheet/styles.d.ts +51 -0
  62. package/dist/components/sheet/styles.js +65 -0
  63. package/dist/components/shimmer/Shimmer.svelte +8 -6
  64. package/dist/components/sidebar/SidebarGroup.svelte +5 -3
  65. package/dist/components/sidebar/SidebarItem.svelte +10 -8
  66. package/dist/components/slider/Slider.svelte +199 -0
  67. package/dist/components/slider/Slider.svelte.d.ts +55 -0
  68. package/dist/components/stack/Stack.svelte +37 -44
  69. package/dist/components/stack/Stack.svelte.d.ts +12 -6
  70. package/dist/components/suggestions/SuggestionsItem.svelte +7 -9
  71. package/dist/components/switch/Switch.svelte +8 -12
  72. package/dist/components/tabs/Tabs.svelte +3 -6
  73. package/dist/components/text/Text.svelte +47 -5
  74. package/dist/components/text/Text.svelte.d.ts +8 -2
  75. package/dist/components/toast/Toaster.svelte +7 -5
  76. package/dist/components/toggle/Toggle.svelte +40 -0
  77. package/dist/components/toggle/Toggle.svelte.d.ts +15 -0
  78. package/dist/components/toggle-group/ToggleGroupItem.svelte +37 -0
  79. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +12 -0
  80. package/dist/components/toggle-group/ToggleGroupRoot.svelte +95 -0
  81. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +33 -0
  82. package/dist/components/toggle-group/context.d.ts +6 -0
  83. package/dist/components/toggle-group/context.js +11 -0
  84. package/dist/components/toggle-group/index.d.ts +5 -0
  85. package/dist/components/toggle-group/index.js +3 -0
  86. package/dist/components/tool/ToolTrigger.svelte +4 -6
  87. package/dist/components/tooltip/TooltipContent.svelte +6 -3
  88. package/dist/components/work-fold/WorkFold.svelte +12 -25
  89. package/dist/components/work-fold/WorkFold.svelte.d.ts +1 -1
  90. package/dist/index.d.ts +25 -3
  91. package/dist/index.js +24 -2
  92. package/dist/internal/Chevron.svelte +2 -3
  93. package/dist/internal/Collapse.svelte +6 -5
  94. package/dist/internal/Collapse.svelte.d.ts +2 -1
  95. package/dist/internal/control.js +4 -4
  96. package/dist/internal/layer.js +6 -8
  97. package/dist/internal/layout.d.ts +13 -0
  98. package/dist/internal/layout.js +453 -0
  99. package/dist/internal/responsive.d.ts +45 -0
  100. package/dist/internal/responsive.js +42 -0
  101. package/dist/internal/sx.d.ts +39 -4
  102. package/dist/internal/sx.js +17 -0
  103. package/dist/internal/toggle.d.ts +74 -0
  104. package/dist/internal/toggle.js +87 -0
  105. package/dist/media.stylex.d.ts +52 -0
  106. package/dist/media.stylex.js +53 -0
  107. package/dist/preset.js +9 -3
  108. package/dist/tokens.stylex.d.ts +15 -0
  109. package/dist/tokens.stylex.js +24 -2
  110. package/dist/vite.d.ts +27 -3
  111. package/dist/vite.js +25 -3
  112. package/package.json +14 -5
@@ -0,0 +1,65 @@
1
+ import * as stylex from '@stylexjs/stylex';
2
+ import { motion } from '../../tokens.stylex.js';
3
+ import { media } from '../../media.stylex.js';
4
+ const CLOSED = ':is([data-state="closed"])';
5
+ // iOS's drawer curve: it leaves the edge quickly and settles long
6
+ const DRAWER = 'cubic-bezier(0.32, 0.72, 0, 1)';
7
+ /** Laid over Dialog's content: a panel along one edge of the window, which it slides in from. */
8
+ export const sheet = stylex.create({
9
+ sheet: {
10
+ maxHeight: 'none',
11
+ marginInline: 0,
12
+ translate: 'none',
13
+ borderRadius: 0,
14
+ scale: null,
15
+ transitionProperty: { default: 'opacity', [media.motion]: 'opacity, translate' },
16
+ transitionDuration: { default: motion.slow, [CLOSED]: motion.base },
17
+ transitionTimingFunction: DRAWER
18
+ },
19
+ // Widths of a sheet along the start or end
20
+ sm: { width: 'min(20rem, calc(100vw - 2rem))' },
21
+ md: { width: 'min(26rem, calc(100vw - 2rem))' },
22
+ lg: { width: 'min(36rem, calc(100vw - 2rem))' },
23
+ end: {
24
+ top: 0,
25
+ bottom: 0,
26
+ insetInlineStart: 'auto',
27
+ insetInlineEnd: 0,
28
+ translate: {
29
+ default: null,
30
+ [media.motion]: { default: '0 0', '@starting-style': '100% 0', [CLOSED]: '100% 0' }
31
+ }
32
+ },
33
+ start: {
34
+ top: 0,
35
+ bottom: 0,
36
+ insetInlineStart: 0,
37
+ insetInlineEnd: 'auto',
38
+ translate: {
39
+ default: null,
40
+ [media.motion]: { default: '0 0', '@starting-style': '-100% 0', [CLOSED]: '-100% 0' }
41
+ }
42
+ },
43
+ // Along the top or bottom it runs the full width, as tall as its content, and
44
+ // never more than the window less 4rem, so the page it covers still shows
45
+ top: {
46
+ top: 0,
47
+ bottom: 'auto',
48
+ width: '100%',
49
+ maxHeight: 'calc(100dvh - 4rem)',
50
+ translate: {
51
+ default: null,
52
+ [media.motion]: { default: '0 0', '@starting-style': '0 -100%', [CLOSED]: '0 -100%' }
53
+ }
54
+ },
55
+ bottom: {
56
+ top: 'auto',
57
+ bottom: 0,
58
+ width: '100%',
59
+ maxHeight: 'calc(100dvh - 4rem)',
60
+ translate: {
61
+ default: null,
62
+ [media.motion]: { default: '0 0', '@starting-style': '0 100%', [CLOSED]: '0 100%' }
63
+ }
64
+ }
65
+ });
@@ -5,6 +5,7 @@
5
5
  import { loop } from '../../internal/loop.js';
6
6
  import { attrs, type Sx } from '../../internal/sx.js';
7
7
  import { colors } from '../../tokens.stylex.js';
8
+ import { media } from '../../media.stylex.js';
8
9
 
9
10
  export type ShimmerProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
10
11
  /** Turn it off to show the text plainly, for example once the work is done. */
@@ -13,9 +14,6 @@
13
14
  children?: Snippet;
14
15
  };
15
16
 
16
- const REDUCE = '@media (prefers-reduced-motion: reduce)';
17
- const FORCED = '@media (forced-colors: active)';
18
-
19
17
  const styles = stylex.create({
20
18
  // Inline, so it wraps and truncates like the text around it
21
19
  base: {
@@ -23,11 +21,15 @@
23
21
  },
24
22
  // Ithildin: the letters are only half there until moonlight passes over them
25
23
  active: {
26
- color: { default: 'transparent', [REDUCE]: colors.textMuted, [FORCED]: 'CanvasText' },
24
+ color: {
25
+ default: 'transparent',
26
+ [media.reducedMotion]: colors.textMuted,
27
+ [media.forcedColors]: 'CanvasText'
28
+ },
27
29
  backgroundImage: {
28
30
  default: `linear-gradient(90deg, ${colors.textSubtle} 0%, ${colors.textSubtle} 40%, ${colors.ithil} 50%, ${colors.textSubtle} 60%, ${colors.textSubtle} 100%)`,
29
- [REDUCE]: 'none',
30
- [FORCED]: 'none'
31
+ [media.reducedMotion]: 'none',
32
+ [media.forcedColors]: 'none'
31
33
  },
32
34
  backgroundSize: '300% 100%',
33
35
  backgroundClip: 'text',
@@ -6,6 +6,7 @@
6
6
  import Collapse from '../../internal/Collapse.svelte';
7
7
  import { attrs, type Sx } from '../../internal/sx.js';
8
8
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
9
+ import { media } from '../../media.stylex.js';
9
10
 
10
11
  export type SidebarGroupProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
11
12
  /** The group's name: a project, or "Today". */
@@ -21,8 +22,6 @@
21
22
  children?: Snippet;
22
23
  };
23
24
 
24
- const HOVER = '@media (hover: hover) and (pointer: fine)';
25
-
26
25
  const styles = stylex.create({
27
26
  group: { display: 'flex', flexDirection: 'column', paddingTop: '0.75rem' },
28
27
  head: {
@@ -44,7 +43,10 @@
44
43
  borderWidth: 0,
45
44
  borderRadius: radius.xs,
46
45
  backgroundColor: 'transparent',
47
- color: { default: colors.textSubtle, ':hover': { default: null, [HOVER]: colors.textMuted } },
46
+ color: {
47
+ default: colors.textSubtle,
48
+ ':hover': { default: null, [media.hover]: colors.textMuted }
49
+ },
48
50
  fontFamily: font.mono,
49
51
  fontSize: '0.6875rem',
50
52
  letterSpacing: '0.04em',
@@ -10,6 +10,7 @@
10
10
  import { sidebarItemMarker } from '../../internal/markers.stylex.js';
11
11
  import { attrs, type Sx } from '../../internal/sx.js';
12
12
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
13
+ import { media } from '../../media.stylex.js';
13
14
 
14
15
  export type SidebarItemProps = Omit<HTMLAnchorAttributes, 'children'> & {
15
16
  /** A link to go to. Without it the row is a button; listen with `onclick`. */
@@ -33,8 +34,6 @@
33
34
  children?: Snippet;
34
35
  };
35
36
 
36
- const HOVER = '@media (hover: hover) and (pointer: fine)';
37
- const FORCED = '@media (forced-colors: active)';
38
37
  // StyleX reads `when` only where it is written inline, in the keys below
39
38
 
40
39
  const styles = stylex.create({
@@ -56,7 +55,7 @@
56
55
  borderRadius: radius.lg,
57
56
  backgroundColor: {
58
57
  default: 'transparent',
59
- ':hover': { default: null, [HOVER]: colors.hover }
58
+ ':hover': { default: null, [media.hover]: colors.hover }
60
59
  },
61
60
  color: colors.text,
62
61
  fontFamily: 'inherit',
@@ -68,7 +67,7 @@
68
67
  WebkitTapHighlightColor: 'transparent',
69
68
  WebkitAppRegion: 'no-drag',
70
69
  outlineStyle: 'solid',
71
- outlineWidth: { default: 0, ':focus-visible': '2px', [FORCED]: '1px' },
70
+ outlineWidth: { default: 0, ':focus-visible': '2px', [media.forcedColors]: '1px' },
72
71
  outlineColor: { default: 'transparent', ':focus-visible': colors.focusRing },
73
72
  outlineOffset: '-2px',
74
73
  transitionProperty: 'background-color, color',
@@ -90,7 +89,7 @@
90
89
  bottom: '25%',
91
90
  width: '2px',
92
91
  borderRadius: '2px',
93
- backgroundColor: { default: colors.ithil, [FORCED]: 'Highlight' },
92
+ backgroundColor: { default: colors.ithil, [media.forcedColors]: 'Highlight' },
94
93
  boxShadow: `0 0 8px ${colors.glow}`,
95
94
  forcedColorAdjust: 'none'
96
95
  }
@@ -129,7 +128,7 @@
129
128
  trailHides: {
130
129
  opacity: {
131
130
  default: 1,
132
- [HOVER]: { default: 1, [stylex.when.ancestor(':hover', sidebarItemMarker)]: 0 },
131
+ [media.hover]: { default: 1, [stylex.when.ancestor(':hover', sidebarItemMarker)]: 0 },
133
132
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 0
134
133
  }
135
134
  },
@@ -157,12 +156,15 @@
157
156
  boxShadow: `inset 0 0 0 1px ${colors.line}, 0 2px 6px -2px ${colors.shade}`,
158
157
  opacity: {
159
158
  default: 1,
160
- [HOVER]: { default: 0, [stylex.when.ancestor(':hover', sidebarItemMarker)]: 1 },
159
+ [media.hover]: { default: 0, [stylex.when.ancestor(':hover', sidebarItemMarker)]: 1 },
161
160
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 1
162
161
  },
163
162
  pointerEvents: {
164
163
  default: 'auto',
165
- [HOVER]: { default: 'none', [stylex.when.ancestor(':hover', sidebarItemMarker)]: 'auto' },
164
+ [media.hover]: {
165
+ default: 'none',
166
+ [stylex.when.ancestor(':hover', sidebarItemMarker)]: 'auto'
167
+ },
166
168
  [stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 'auto'
167
169
  },
168
170
  transitionProperty: 'opacity',
@@ -0,0 +1,199 @@
1
+ <script lang="ts" module>
2
+ import { Slider } from 'bits-ui';
3
+ import * as stylex from '@stylexjs/stylex';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+ import { attrs, type Sx } from '../../internal/sx.js';
6
+ import { colors, motion, radius } from '../../tokens.stylex.js';
7
+ import { media } from '../../media.stylex.js';
8
+
9
+ export type SliderProps<T extends number | number[] = number> = Omit<
10
+ HTMLAttributes<HTMLSpanElement>,
11
+ 'children' | 'dir'
12
+ > & {
13
+ /**
14
+ * Where the thumb stands. Bindable. A number gives one thumb; an array gives
15
+ * one thumb for each of its values, such as a range's two ends.
16
+ */
17
+ value?: T;
18
+ /** Called as the value changes, while dragging and with each key press. */
19
+ onValueChange?: (value: T) => void;
20
+ /** Called once the person lets go, or with each key press: the moment to save. */
21
+ onValueCommit?: (value: T) => void;
22
+ min?: number;
23
+ max?: number;
24
+ /** How far one step goes, or the values it may stop at. */
25
+ step?: number | number[];
26
+ orientation?: 'horizontal' | 'vertical';
27
+ /** Set `rtl` in a right-to-left layout, so the slider runs from the right. */
28
+ dir?: 'ltr' | 'rtl';
29
+ disabled?: boolean;
30
+ /**
31
+ * Names each thumb, for a slider of more than one: `['Minimum', 'Maximum']`.
32
+ * One thumb takes the slider's own `aria-label` or `aria-labelledby`.
33
+ */
34
+ thumbLabels?: string[];
35
+ /** Reads a value out in words, such as `0:42` for a playhead or `40%`. */
36
+ format?: (value: number) => string;
37
+ sx?: Sx;
38
+ ref?: HTMLSpanElement | null;
39
+ };
40
+
41
+ const DISABLED = ':is([data-disabled])';
42
+ const ACTIVE = ':is([data-active])';
43
+
44
+ const styles = stylex.create({
45
+ root: {
46
+ position: 'relative',
47
+ boxSizing: 'border-box',
48
+ display: 'flex',
49
+ alignItems: 'center',
50
+ flexShrink: 0,
51
+ touchAction: 'none',
52
+ userSelect: 'none',
53
+ WebkitUserSelect: 'none',
54
+ WebkitTapHighlightColor: 'transparent',
55
+ WebkitAppRegion: 'no-drag',
56
+ cursor: { default: 'pointer', [DISABLED]: 'not-allowed' },
57
+ opacity: { default: 1, [DISABLED]: 0.5 }
58
+ },
59
+ horizontal: { width: '100%', minWidth: '6rem', height: '1.5rem' },
60
+ vertical: {
61
+ flexDirection: 'column',
62
+ width: '1.5rem',
63
+ height: '100%',
64
+ minHeight: '6rem'
65
+ },
66
+ // A recess, like Progress's track
67
+ track: {
68
+ position: 'relative',
69
+ flexGrow: 1,
70
+ overflow: 'hidden',
71
+ borderRadius: radius.full,
72
+ backgroundColor: colors.well,
73
+ boxShadow: `inset 0 0 0 1px ${colors.lineStrong}`,
74
+ outlineStyle: 'solid',
75
+ outlineWidth: '1px',
76
+ outlineColor: 'transparent',
77
+ outlineOffset: '-1px'
78
+ },
79
+ trackHorizontal: { height: '0.25rem' },
80
+ trackVertical: { width: '0.25rem' },
81
+ // How far along: lit with ithildin, as progress is
82
+ range: {
83
+ backgroundImage: {
84
+ default: `linear-gradient(90deg, ${colors.ithilStrong}, ${colors.ithil})`,
85
+ [media.forcedColors]: 'linear-gradient(Highlight, Highlight)'
86
+ },
87
+ forcedColorAdjust: 'none'
88
+ },
89
+ rangeHorizontal: { height: '100%' },
90
+ rangeVertical: { width: '100%' },
91
+ // Placed by bits-ui with `left` and `translate`, so a press grows it with `scale`
92
+ thumb: {
93
+ zIndex: 1,
94
+ boxSizing: 'border-box',
95
+ display: 'block',
96
+ width: '1rem',
97
+ height: '1rem',
98
+ borderRadius: radius.full,
99
+ backgroundColor: { default: '#fff', [media.forcedColors]: 'ButtonText' },
100
+ boxShadow: {
101
+ default: `0 0 0 1px ${colors.lineStrong}, 0 1px 3px rgb(0 0 0 / 0.3)`,
102
+ ':hover': {
103
+ default: null,
104
+ [media.hover]: `0 0 0 1px ${colors.edgeHover}, 0 1px 3px rgb(0 0 0 / 0.3)`
105
+ }
106
+ },
107
+ forcedColorAdjust: 'none',
108
+ cursor: { default: 'grab', [ACTIVE]: 'grabbing', [DISABLED]: 'not-allowed' },
109
+ scale: { default: null, [media.motion]: { default: 1, [ACTIVE]: 1.15 } },
110
+ outlineStyle: 'solid',
111
+ outlineWidth: { default: '1px', ':focus-visible': '2px' },
112
+ outlineColor: {
113
+ default: 'transparent',
114
+ ':focus-visible': { default: colors.focusRing, [media.forcedColors]: 'Highlight' }
115
+ },
116
+ outlineOffset: { default: '-1px', ':focus-visible': '2px' },
117
+ transitionProperty: { default: 'box-shadow', [media.motion]: 'scale, box-shadow' },
118
+ transitionDuration: motion.fast,
119
+ transitionTimingFunction: motion.easeOut,
120
+ // A 40px target for a finger, without changing the layout
121
+ '::after': {
122
+ content: '""',
123
+ position: 'absolute',
124
+ inset: '-0.75rem',
125
+ borderRadius: radius.full
126
+ }
127
+ }
128
+ });
129
+ </script>
130
+
131
+ <script lang="ts" generics="T extends number | number[] = number">
132
+ let {
133
+ value = $bindable(),
134
+ onValueChange,
135
+ onValueCommit,
136
+ min = 0,
137
+ max = 100,
138
+ step = 1,
139
+ orientation = 'horizontal',
140
+ dir = 'ltr',
141
+ disabled = false,
142
+ thumbLabels,
143
+ format,
144
+ 'aria-label': ariaLabel,
145
+ 'aria-labelledby': ariaLabelledby,
146
+ sx,
147
+ class: className,
148
+ ref = $bindable(null),
149
+ ...rest
150
+ }: SliderProps<T> = $props();
151
+
152
+ const vertical = $derived(orientation === 'vertical');
153
+
154
+ // bits-ui types a single and a multiple slider apart; which one this is
155
+ // follows from the value it is given
156
+ const root = $derived({
157
+ type: Array.isArray(value) ? 'multiple' : 'single',
158
+ value,
159
+ onValueChange: (next: number | number[]) => {
160
+ value = next as T;
161
+ onValueChange?.(next as T);
162
+ },
163
+ onValueCommit: (next: number | number[]) => onValueCommit?.(next as T),
164
+ min,
165
+ max,
166
+ step,
167
+ orientation,
168
+ dir,
169
+ disabled
170
+ } as Slider.RootProps);
171
+
172
+ const valueAt = (index: number) =>
173
+ Array.isArray(value) ? (value[index] ?? min) : ((value as number | undefined) ?? min);
174
+ </script>
175
+
176
+ <Slider.Root
177
+ bind:ref
178
+ data-slot="slider"
179
+ {...root}
180
+ {...rest as Record<string, unknown>}
181
+ {...attrs([styles.root, vertical ? styles.vertical : styles.horizontal, sx], className)}
182
+ >
183
+ {#snippet children({ thumbItems })}
184
+ <span {...stylex.attrs(styles.track, vertical ? styles.trackVertical : styles.trackHorizontal)}>
185
+ <Slider.Range
186
+ {...stylex.attrs(styles.range, vertical ? styles.rangeVertical : styles.rangeHorizontal)}
187
+ />
188
+ </span>
189
+ {#each thumbItems as thumb (thumb.index)}
190
+ <Slider.Thumb
191
+ index={thumb.index}
192
+ aria-label={thumbLabels?.[thumb.index] ?? ariaLabel}
193
+ aria-labelledby={thumbLabels?.[thumb.index] ? undefined : ariaLabelledby}
194
+ aria-valuetext={format?.(valueAt(thumb.index))}
195
+ {...stylex.attrs(styles.thumb)}
196
+ />
197
+ {/each}
198
+ {/snippet}
199
+ </Slider.Root>
@@ -0,0 +1,55 @@
1
+ import { Slider } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import { type Sx } from '../../internal/sx.js';
4
+ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'dir'> & {
5
+ /**
6
+ * Where the thumb stands. Bindable. A number gives one thumb; an array gives
7
+ * one thumb for each of its values, such as a range's two ends.
8
+ */
9
+ value?: T;
10
+ /** Called as the value changes, while dragging and with each key press. */
11
+ onValueChange?: (value: T) => void;
12
+ /** Called once the person lets go, or with each key press: the moment to save. */
13
+ onValueCommit?: (value: T) => void;
14
+ min?: number;
15
+ max?: number;
16
+ /** How far one step goes, or the values it may stop at. */
17
+ step?: number | number[];
18
+ orientation?: 'horizontal' | 'vertical';
19
+ /** Set `rtl` in a right-to-left layout, so the slider runs from the right. */
20
+ dir?: 'ltr' | 'rtl';
21
+ disabled?: boolean;
22
+ /**
23
+ * Names each thumb, for a slider of more than one: `['Minimum', 'Maximum']`.
24
+ * One thumb takes the slider's own `aria-label` or `aria-labelledby`.
25
+ */
26
+ thumbLabels?: string[];
27
+ /** Reads a value out in words, such as `0:42` for a playhead or `40%`. */
28
+ format?: (value: number) => string;
29
+ sx?: Sx;
30
+ ref?: HTMLSpanElement | null;
31
+ };
32
+ declare function $$render<T extends number | number[] = number>(): {
33
+ props: SliderProps<T>;
34
+ exports: {};
35
+ bindings: "value" | "ref";
36
+ slots: {};
37
+ events: {};
38
+ };
39
+ declare class __sveltets_Render<T extends number | number[] = number> {
40
+ props(): ReturnType<typeof $$render<T>>['props'];
41
+ events(): ReturnType<typeof $$render<T>>['events'];
42
+ slots(): ReturnType<typeof $$render<T>>['slots'];
43
+ bindings(): "value" | "ref";
44
+ exports(): {};
45
+ }
46
+ interface $$IsomorphicComponent {
47
+ new <T extends number | number[] = number>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
48
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
49
+ } & ReturnType<__sveltets_Render<T>['exports']>;
50
+ <T extends number | number[] = number>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
51
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
52
+ }
53
+ declare const Slider: $$IsomorphicComponent;
54
+ type Slider<T extends number | number[] = number> = InstanceType<typeof Slider<T>>;
55
+ export default Slider;
@@ -2,20 +2,35 @@
2
2
  import * as stylex from '@stylexjs/stylex';
3
3
  import type { Snippet } from 'svelte';
4
4
  import type { HTMLAttributes } from 'svelte/elements';
5
+ import {
6
+ alignStyles,
7
+ directionStyles,
8
+ gapStyles,
9
+ justifyStyles,
10
+ wrapStyles,
11
+ type Align,
12
+ type Direction,
13
+ type Gap,
14
+ type Justify
15
+ } from '../../internal/layout.js';
16
+ import { responsive, type Responsive } from '../../internal/responsive.js';
5
17
  import { attrs, type Sx } from '../../internal/sx.js';
6
- import { space } from '../../tokens.stylex.js';
7
18
 
8
19
  /** Steps on the 4px spacing scale: `4` is 16px. */
9
- export type StackGap = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 16;
20
+ export type StackGap = Gap;
21
+ export type StackDirection = Direction;
22
+ export type StackAlign = Align;
23
+ export type StackJustify = Justify;
10
24
 
11
25
  export type StackProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
12
26
  /** Element to render. */
13
27
  as?: 'div' | 'section' | 'article' | 'nav' | 'header' | 'footer' | 'main' | 'ul' | 'ol' | 'li';
14
- direction?: 'column' | 'row';
15
- gap?: StackGap;
16
- align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
17
- justify?: 'start' | 'center' | 'end' | 'between';
18
- wrap?: boolean;
28
+ /** Main axis. Like every layout prop, a value or values by breakpoint. */
29
+ direction?: Responsive<StackDirection>;
30
+ gap?: Responsive<StackGap>;
31
+ align?: Responsive<StackAlign>;
32
+ justify?: Responsive<StackJustify>;
33
+ wrap?: Responsive<boolean>;
19
34
  sx?: Sx;
20
35
  children?: Snippet;
21
36
  };
@@ -28,40 +43,10 @@
28
43
  margin: 0,
29
44
  padding: 0,
30
45
  listStyleType: 'none'
31
- },
32
- column: { flexDirection: 'column' },
33
- row: { flexDirection: 'row' },
34
- wrap: { flexWrap: 'wrap' }
46
+ }
35
47
  });
36
48
 
37
- const gaps = stylex.create({
38
- 0: { gap: 0 },
39
- 1: { gap: space.x1 },
40
- 2: { gap: space.x2 },
41
- 3: { gap: space.x3 },
42
- 4: { gap: space.x4 },
43
- 5: { gap: space.x5 },
44
- 6: { gap: space.x6 },
45
- 8: { gap: space.x8 },
46
- 10: { gap: space.x10 },
47
- 12: { gap: space.x12 },
48
- 16: { gap: space.x16 }
49
- });
50
-
51
- const aligns = stylex.create({
52
- start: { alignItems: 'flex-start' },
53
- center: { alignItems: 'center' },
54
- end: { alignItems: 'flex-end' },
55
- stretch: { alignItems: 'stretch' },
56
- baseline: { alignItems: 'baseline' }
57
- });
58
-
59
- const justifies = stylex.create({
60
- start: { justifyContent: 'flex-start' },
61
- center: { justifyContent: 'center' },
62
- end: { justifyContent: 'flex-end' },
63
- between: { justifyContent: 'space-between' }
64
- });
49
+ const toWrap = (value: boolean) => (value ? 'wrap' : 'nowrap');
65
50
  </script>
66
51
 
67
52
  <script lang="ts">
@@ -77,6 +62,14 @@
77
62
  children,
78
63
  ...rest
79
64
  }: StackProps = $props();
65
+
66
+ // `wrap` is a boolean outside, and a keyword inside. A plain `false` adds no class, as before.
67
+ const wrapValue = $derived.by((): Responsive<'wrap' | 'nowrap'> | undefined => {
68
+ if (typeof wrap === 'boolean') return wrap ? 'wrap' : undefined;
69
+ return Object.fromEntries(
70
+ Object.entries(wrap).map(([at, value]) => [at, toWrap(value as boolean)])
71
+ );
72
+ });
80
73
  </script>
81
74
 
82
75
  <svelte:element
@@ -85,11 +78,11 @@
85
78
  {...attrs(
86
79
  [
87
80
  styles.base,
88
- styles[direction],
89
- gaps[gap],
90
- align && aligns[align],
91
- justify && justifies[justify],
92
- wrap && styles.wrap,
81
+ responsive(direction, 'column', directionStyles),
82
+ responsive(gap, 4, gapStyles),
83
+ responsive(align, undefined, alignStyles),
84
+ responsive(justify, undefined, justifyStyles),
85
+ responsive(wrapValue, undefined, wrapStyles),
93
86
  sx
94
87
  ],
95
88
  className
@@ -1,16 +1,22 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
+ import { type Align, type Direction, type Gap, type Justify } from '../../internal/layout.js';
4
+ import { type Responsive } from '../../internal/responsive.js';
3
5
  import { type Sx } from '../../internal/sx.js';
4
6
  /** Steps on the 4px spacing scale: `4` is 16px. */
5
- export type StackGap = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | 16;
7
+ export type StackGap = Gap;
8
+ export type StackDirection = Direction;
9
+ export type StackAlign = Align;
10
+ export type StackJustify = Justify;
6
11
  export type StackProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
7
12
  /** Element to render. */
8
13
  as?: 'div' | 'section' | 'article' | 'nav' | 'header' | 'footer' | 'main' | 'ul' | 'ol' | 'li';
9
- direction?: 'column' | 'row';
10
- gap?: StackGap;
11
- align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';
12
- justify?: 'start' | 'center' | 'end' | 'between';
13
- wrap?: boolean;
14
+ /** Main axis. Like every layout prop, a value or values by breakpoint. */
15
+ direction?: Responsive<StackDirection>;
16
+ gap?: Responsive<StackGap>;
17
+ align?: Responsive<StackAlign>;
18
+ justify?: Responsive<StackJustify>;
19
+ wrap?: Responsive<boolean>;
14
20
  sx?: Sx;
15
21
  children?: Snippet;
16
22
  };
@@ -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 { getSuggestionsContext } from './context.js';
9
10
 
10
11
  export type SuggestionsItemProps = Omit<HTMLButtonAttributes, 'children' | 'value'> & {
@@ -16,9 +17,6 @@
16
17
  children?: Snippet;
17
18
  };
18
19
 
19
- const HOVER = '@media (hover: hover) and (pointer: fine)';
20
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
21
-
22
20
  // They rise into place one after another, the first time they are shown
23
21
  const arrive = stylex.keyframes({
24
22
  from: { opacity: 0, translate: '0 6px' },
@@ -42,12 +40,12 @@
42
40
  borderRadius: `calc(${radius.xl} * 4 / 3)`,
43
41
  backgroundColor: {
44
42
  default: colors.surface,
45
- ':hover': { default: null, [HOVER]: colors.hover }
43
+ ':hover': { default: null, [media.hover]: colors.hover }
46
44
  },
47
45
  boxShadow: `inset 0 0 0 1px ${colors.line}`,
48
46
  color: {
49
47
  default: colors.textMuted,
50
- ':hover': { default: null, [HOVER]: colors.text }
48
+ ':hover': { default: null, [media.hover]: colors.text }
51
49
  },
52
50
  fontFamily: 'inherit',
53
51
  fontSize: font.sizeSm,
@@ -56,19 +54,19 @@
56
54
  whiteSpace: 'nowrap',
57
55
  cursor: 'pointer',
58
56
  WebkitTapHighlightColor: 'transparent',
59
- animationName: { default: fade, [MOTION]: arrive },
57
+ animationName: { default: fade, [media.motion]: arrive },
60
58
  animationDuration: motion.slow,
61
59
  animationTimingFunction: motion.easeOut,
62
60
  animationFillMode: 'backwards',
63
61
  // Capped, so a long list does not keep the last ones waiting
64
62
  animationDelay: 'calc(min(var(--narvi-suggestion-index, 0), 6) * 40ms)',
65
- scale: { default: null, ':active': { default: null, [MOTION]: 0.97 } },
63
+ scale: { default: null, ':active': { default: null, [media.motion]: 0.97 } },
66
64
  transitionProperty: {
67
65
  default: 'background-color, color',
68
- [MOTION]: 'scale, background-color, color'
66
+ [media.motion]: 'scale, background-color, color'
69
67
  },
70
68
  transitionDuration: motion.base,
71
- transitionTimingFunction: { default: 'ease', [MOTION]: `${motion.easeOut}, ease, ease` }
69
+ transitionTimingFunction: { default: 'ease', [media.motion]: `${motion.easeOut}, ease, ease` }
72
70
  }
73
71
  });
74
72
  </script>