@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
@@ -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>
@@ -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 SwitchProps = Omit<HTMLInputAttributes, 'type' | 'role' | 'children'> & {
9
10
  checked?: boolean;
@@ -17,11 +18,6 @@
17
18
  children?: Snippet;
18
19
  };
19
20
 
20
- // StyleX needs these in the same file to evaluate them at build time
21
- const HOVER = '@media (hover: hover) and (pointer: fine)';
22
- const MOTION = '@media (prefers-reduced-motion: no-preference)';
23
- const FORCED = '@media (forced-colors: active)';
24
-
25
21
  const styles = stylex.create({
26
22
  root: {
27
23
  display: 'inline-flex',
@@ -56,13 +52,13 @@
56
52
  borderRadius: radius.full,
57
53
  backgroundColor: {
58
54
  default: colors.edge,
59
- ':hover': { default: null, [HOVER]: colors.edgeHover },
60
- [FORCED]: { default: 'Canvas', ':checked': 'Highlight' }
55
+ ':hover': { default: null, [media.hover]: colors.edgeHover },
56
+ [media.forcedColors]: { default: 'Canvas', ':checked': 'Highlight' }
61
57
  },
62
58
  backgroundImage: {
63
59
  default: 'none',
64
60
  ':checked': `linear-gradient(180deg, ${colors.ithil}, ${colors.ithilStrong})`,
65
- [FORCED]: 'none'
61
+ [media.forcedColors]: 'none'
66
62
  },
67
63
  boxShadow: {
68
64
  default: `inset 0 1px 2px ${colors.shade}`,
@@ -77,7 +73,7 @@
77
73
  outlineColor: {
78
74
  default: 'transparent',
79
75
  ':focus-visible': colors.focusRing,
80
- [FORCED]: { default: 'ButtonText', ':focus-visible': 'Highlight' }
76
+ [media.forcedColors]: { default: 'ButtonText', ':focus-visible': 'Highlight' }
81
77
  },
82
78
  outlineOffset: { default: '-1px', ':focus-visible': '2px' },
83
79
  transitionProperty: 'background-color',
@@ -97,7 +93,7 @@
97
93
  ':checked': { default: '14px 0', ':dir(rtl)': '-14px 0' }
98
94
  },
99
95
  // While pressed, the thumb stretches towards where it is about to go
100
- scale: { default: null, ':active': { default: null, [MOTION]: '1.2 1' } },
96
+ scale: { default: null, ':active': { default: null, [media.motion]: '1.2 1' } },
101
97
  transformOrigin: {
102
98
  default: 'left center',
103
99
  ':dir(rtl)': 'right center',
@@ -107,12 +103,12 @@
107
103
  backgroundColor: {
108
104
  default: '#fff',
109
105
  ':checked': colors.onIthil,
110
- [FORCED]: { default: 'ButtonText', ':checked': 'HighlightText' }
106
+ [media.forcedColors]: { default: 'ButtonText', ':checked': 'HighlightText' }
111
107
  },
112
108
  boxShadow: '0 1px 2px rgb(0 0 0 / 0.4)',
113
109
  transitionProperty: {
114
110
  default: 'background-color',
115
- [MOTION]: 'translate, scale, transform-origin, background-color'
111
+ [media.motion]: 'translate, scale, transform-origin, background-color'
116
112
  },
117
113
  transitionDuration: '200ms',
118
114
  transitionTimingFunction: motion.easeOut
@@ -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, font, motion, radius } from '../../tokens.stylex.js';
7
+ import { media } from '../../media.stylex.js';
7
8
 
8
9
  export type TabItem = { value: string; label: string; count?: number; disabled?: boolean };
9
10
 
@@ -18,10 +19,6 @@
18
19
  children?: Snippet<[string]>;
19
20
  };
20
21
 
21
- // StyleX needs these in the same file to evaluate them at build time
22
- const HOVER = '@media (hover: hover) and (pointer: fine)';
23
- const FORCED = '@media (forced-colors: active)';
24
-
25
22
  const styles = stylex.create({
26
23
  root: {
27
24
  minWidth: 0,
@@ -46,7 +43,7 @@
46
43
  backgroundColor: 'transparent',
47
44
  color: {
48
45
  default: colors.textMuted,
49
- ':hover': { default: null, [HOVER]: colors.text }
46
+ ':hover': { default: null, [media.hover]: colors.text }
50
47
  },
51
48
  fontFamily: 'inherit',
52
49
  fontSize: font.sizeMd,
@@ -74,7 +71,7 @@
74
71
  bottom: '-1px',
75
72
  height: '2px',
76
73
  borderRadius: '2px',
77
- backgroundColor: { default: colors.ithil, [FORCED]: 'Highlight' },
74
+ backgroundColor: { default: colors.ithil, [media.forcedColors]: 'Highlight' },
78
75
  boxShadow: `0 0 8px ${colors.glow}`,
79
76
  forcedColorAdjust: 'none'
80
77
  }
@@ -5,16 +5,22 @@
5
5
  import { attrs, type Sx } from '../../internal/sx.js';
6
6
  import { colors, font } from '../../tokens.stylex.js';
7
7
 
8
- export type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
8
+ /** `lead` is a lede: the line under a page's title, or the opening of a section. */
9
+ export type TextSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'lead';
9
10
  export type TextTone = 'default' | 'muted' | 'subtle' | 'accent' | 'danger' | 'success';
10
11
  export type TextWeight = 'regular' | 'medium' | 'semibold';
12
+ /** `body` is the page's own face; `display` is the serif that large headings are set in. */
13
+ export type TextFace = 'body' | 'display';
11
14
 
12
15
  export type TextProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
13
16
  /** Element to render. */
14
- as?: 'p' | 'span' | 'div' | 'label' | 'strong' | 'em' | 'small';
17
+ as?: 'p' | 'span' | 'div' | 'label' | 'strong' | 'em' | 'small' | 'figcaption' | 'blockquote';
15
18
  size?: TextSize;
16
19
  tone?: TextTone;
20
+ /** Defaults to `regular` in the body face, and to the heading weight in the display face. */
17
21
  weight?: TextWeight;
22
+ face?: TextFace;
23
+ italic?: boolean;
18
24
  /** Cuts the text off with an ellipsis on one line. */
19
25
  truncate?: boolean;
20
26
  sx?: Sx;
@@ -29,6 +35,13 @@
29
35
  lineHeight: font.leadingNormal,
30
36
  textWrap: 'pretty'
31
37
  },
38
+ display: {
39
+ fontFamily: font.display,
40
+ fontWeight: font.weightDisplay,
41
+ // The serif's capitals are tall and its lowercase small: it sets tighter than the body
42
+ lineHeight: font.leadingSnug
43
+ },
44
+ italic: { fontStyle: 'italic' },
32
45
  truncate: {
33
46
  display: 'block',
34
47
  minWidth: 0,
@@ -43,7 +56,23 @@
43
56
  sm: { fontSize: font.sizeSm },
44
57
  md: { fontSize: font.sizeMd },
45
58
  lg: { fontSize: font.sizeLg },
46
- xl: { fontSize: font.sizeXl }
59
+ xl: { fontSize: font.sizeXl },
60
+ lead: { fontSize: 'clamp(1.125rem, 1rem + 0.5vw, 1.25rem)', textWrap: 'balance' }
61
+ });
62
+
63
+ // The display serif has a small lowercase, so at the same size it reads a step smaller than
64
+ // the body face. Each size is set larger in it, to read as the same size beside body text.
65
+ const displaySizes = stylex.create({
66
+ xs: { fontSize: '0.875rem' },
67
+ sm: { fontSize: '1rem' },
68
+ md: { fontSize: '1.125rem' },
69
+ lg: { fontSize: '1.25rem' },
70
+ xl: { fontSize: '1.375rem' },
71
+ lead: {
72
+ fontSize: 'clamp(1.5rem, 1.2rem + 1.2vw, 1.875rem)',
73
+ lineHeight: font.leadingTight,
74
+ textWrap: 'balance'
75
+ }
47
76
  });
48
77
 
49
78
  const tones = stylex.create({
@@ -67,20 +96,33 @@
67
96
  as = 'p',
68
97
  size = 'md',
69
98
  tone = 'default',
70
- weight = 'regular',
99
+ weight,
100
+ face = 'body',
101
+ italic = false,
71
102
  truncate = false,
72
103
  sx,
73
104
  class: className,
74
105
  children,
75
106
  ...rest
76
107
  }: TextProps = $props();
108
+
109
+ const display = $derived(face === 'display');
77
110
  </script>
78
111
 
79
112
  <svelte:element
80
113
  this={as}
81
114
  {...rest}
82
115
  {...attrs(
83
- [styles.base, sizes[size], tones[tone], weights[weight], truncate && styles.truncate, sx],
116
+ [
117
+ styles.base,
118
+ display && styles.display,
119
+ display ? displaySizes[size] : sizes[size],
120
+ tones[tone],
121
+ weight ? weights[weight] : !display && weights.regular,
122
+ italic && styles.italic,
123
+ truncate && styles.truncate,
124
+ sx
125
+ ],
84
126
  className
85
127
  )}
86
128
  >