@glimstone/svelte 4.9.2 → 5.0.1

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 (94) hide show
  1. package/dist/AngleSlider.svelte +33 -9
  2. package/dist/AngleSlider.svelte.d.ts +1 -1
  3. package/dist/Avatar.svelte +1 -1
  4. package/dist/Badge.svelte +3 -7
  5. package/dist/Badge.svelte.d.ts +2 -5
  6. package/dist/Card.svelte +5 -1
  7. package/dist/Card.svelte.d.ts +3 -0
  8. package/dist/Chart.svelte +84 -0
  9. package/dist/Chart.svelte.d.ts +19 -0
  10. package/dist/ChartLegend.svelte +19 -0
  11. package/dist/ChartLegend.svelte.d.ts +7 -0
  12. package/dist/Checkbox.svelte +16 -3
  13. package/dist/ColorPicker.svelte +49 -4
  14. package/dist/ColorPicker.svelte.d.ts +2 -0
  15. package/dist/Combobox.svelte +12 -4
  16. package/dist/ConfirmDialog.svelte +8 -2
  17. package/dist/ContextMenu.svelte +4 -2
  18. package/dist/ContextMenu.svelte.d.ts +2 -0
  19. package/dist/DatePicker.svelte +21 -11
  20. package/dist/FieldErrorLine.svelte +24 -0
  21. package/dist/FieldErrorLine.svelte.d.ts +7 -0
  22. package/dist/FieldRow.svelte +16 -4
  23. package/dist/FileUpload.svelte +14 -4
  24. package/dist/FileUpload.svelte.d.ts +2 -0
  25. package/dist/FortressPermissions.svelte +3 -1
  26. package/dist/HoverCard.svelte +34 -5
  27. package/dist/HoverCard.svelte.d.ts +12 -2
  28. package/dist/IconTipButton.svelte +6 -2
  29. package/dist/IconTipButton.svelte.d.ts +3 -0
  30. package/dist/InfoBubble.svelte +1 -1
  31. package/dist/ListRow.svelte +71 -6
  32. package/dist/ListRow.svelte.d.ts +17 -2
  33. package/dist/ListSelect.svelte +7 -2
  34. package/dist/ListTable.svelte +33 -15
  35. package/dist/ListTable.svelte.d.ts +5 -0
  36. package/dist/MenuSelect.svelte +11 -3
  37. package/dist/Meter.svelte +21 -3
  38. package/dist/Meter.svelte.d.ts +4 -0
  39. package/dist/MultiSelect.svelte +2 -1
  40. package/dist/NotifyCard.svelte +1 -1
  41. package/dist/NumberField.svelte +2 -2
  42. package/dist/PasswordField.svelte +7 -6
  43. package/dist/PinInput.svelte +4 -2
  44. package/dist/Rating.svelte +10 -1
  45. package/dist/RevealEye.svelte +17 -0
  46. package/dist/RevealEye.svelte.d.ts +6 -0
  47. package/dist/SearchHit.svelte +10 -0
  48. package/dist/SearchHit.svelte.d.ts +7 -0
  49. package/dist/Selector.svelte +28 -4
  50. package/dist/Selector.svelte.d.ts +4 -3
  51. package/dist/SettingsNav.svelte +152 -0
  52. package/dist/SettingsNav.svelte.d.ts +46 -0
  53. package/dist/SignInTile.svelte +19 -14
  54. package/dist/SkeletonRow.svelte +8 -2
  55. package/dist/SkeletonRow.svelte.d.ts +4 -0
  56. package/dist/Slider.svelte +1 -0
  57. package/dist/Sparkline.svelte +24 -0
  58. package/dist/Sparkline.svelte.d.ts +11 -0
  59. package/dist/StatusSummary.svelte +55 -0
  60. package/dist/StatusSummary.svelte.d.ts +18 -0
  61. package/dist/SubCard.svelte +16 -16
  62. package/dist/SubCard.svelte.d.ts +3 -3
  63. package/dist/TextArea.svelte +13 -3
  64. package/dist/TextField.svelte +2 -2
  65. package/dist/TimeDial.svelte +74 -0
  66. package/dist/TimeDial.svelte.d.ts +13 -0
  67. package/dist/TimePicker.svelte +57 -0
  68. package/dist/TimePicker.svelte.d.ts +19 -0
  69. package/dist/TimeRangePicker.svelte +52 -0
  70. package/dist/TimeRangePicker.svelte.d.ts +16 -0
  71. package/dist/TimeShell.svelte +145 -0
  72. package/dist/TimeShell.svelte.d.ts +16 -0
  73. package/dist/Timer.svelte +6 -1
  74. package/dist/TipBubble.svelte +1 -1
  75. package/dist/ToastCard.svelte +7 -3
  76. package/dist/ToastCard.svelte.d.ts +2 -0
  77. package/dist/ToastViewport.svelte +6 -3
  78. package/dist/Toggle.svelte +3 -1
  79. package/dist/Tour.svelte +8 -2
  80. package/dist/Window.svelte +5 -3
  81. package/dist/Window.svelte.d.ts +3 -1
  82. package/dist/bubble.svelte.d.ts +12 -1
  83. package/dist/bubble.svelte.js +13 -5
  84. package/dist/engines.svelte.d.ts +7 -1
  85. package/dist/engines.svelte.js +13 -1
  86. package/dist/glyphs.d.ts +3 -0
  87. package/dist/glyphs.js +3 -0
  88. package/dist/index.d.ts +13 -7
  89. package/dist/index.js +9 -4
  90. package/package.json +2 -2
  91. package/dist/AboutCard.svelte +0 -116
  92. package/dist/AboutCard.svelte.d.ts +0 -40
  93. package/dist/DropdownListbox.svelte +0 -178
  94. package/dist/DropdownListbox.svelte.d.ts +0 -23
package/dist/Meter.svelte CHANGED
@@ -16,23 +16,29 @@
16
16
  quiet?: boolean;
17
17
  /** The level in words, such as "120 GB free of 4 TB": read out, and shown in the bubble. */
18
18
  valueText?: string;
19
+ /** The figure beside the track, such as "1.4 / 2 TB". The percentage when left out. */
20
+ figure?: string;
21
+ /** Shows the figure beside the track. On by default for `medium`, off for `small` and `quiet`. */
22
+ showValue?: boolean;
19
23
  class?: string;
20
24
  }
21
25
  </script>
22
26
 
23
27
  <script lang="ts">
24
- import { meterView } from "@glimstone/core";
28
+ import { meterFigure, meterShowsValue, meterView } from "@glimstone/core";
25
29
  import { useTipBubble } from "./bubble.svelte.js";
26
30
  import TipBubble from "./TipBubble.svelte";
27
31
 
28
32
  // A level that stands, such as how full a disk is. meterView() in the core
29
33
  // decides when it turns red and how it runs without a value.
30
- let { value, label, size = "medium", threshold = 0.9, quiet, valueText, class: className }: MeterProps = $props();
34
+ let { value, label, size = "medium", threshold = 0.9, quiet, valueText, figure, showValue, class: className }: MeterProps = $props();
31
35
  const view = $derived(meterView(value, { size, threshold, quiet }));
32
36
  const tip = useTipBubble(() => valueText);
33
37
  const busy = $derived(view.percent === null);
38
+ const shown = $derived(meterShowsValue(size, quiet, showValue));
34
39
  </script>
35
40
 
41
+ {#snippet meter()}
36
42
  <!-- svelte-ignore a11y_no_static_element_interactions -->
37
43
  <span
38
44
  data-glim="Meter"
@@ -52,4 +58,16 @@
52
58
  >
53
59
  <span class="glim-meter-fill" style={view.width ? `width: ${view.width}` : undefined}></span>
54
60
  </span>
55
- <TipBubble state={tip} />
61
+ {/snippet}
62
+
63
+ <!-- The figure repeats what the meter already says, so a screen reader hears it once. -->
64
+ {#if shown}
65
+ <span class="glim-meter-row glim-meter-row--{size}">
66
+ {@render meter()}
67
+ <span class="glim-meter-value glim-num" aria-hidden="true">{meterFigure(view.percent, figure)}</span>
68
+ <TipBubble state={tip} />
69
+ </span>
70
+ {:else}
71
+ {@render meter()}
72
+ <TipBubble state={tip} />
73
+ {/if}
@@ -13,6 +13,10 @@ export interface MeterProps {
13
13
  quiet?: boolean;
14
14
  /** The level in words, such as "120 GB free of 4 TB": read out, and shown in the bubble. */
15
15
  valueText?: string;
16
+ /** The figure beside the track, such as "1.4 / 2 TB". The percentage when left out. */
17
+ figure?: string;
18
+ /** Shows the figure beside the track. On by default for `medium`, off for `small` and `quiet`. */
19
+ showValue?: boolean;
16
20
  class?: string;
17
21
  }
18
22
  declare const Meter: import("svelte").Component<MeterProps, {}, "">;
@@ -34,6 +34,7 @@
34
34
  import { useFieldName } from "./fieldName.js";
35
35
  import { IconCheck, IconClose, IconExpand } from "./glyphs.js";
36
36
  import { lift } from "./lift.js";
37
+ import SearchHit from "./SearchHit.svelte";
37
38
 
38
39
  // A field that picks several choices from a list and keeps them as tags,
39
40
  // each with its own remove mark. It is Zag's combobox in multiple mode, so
@@ -146,7 +147,7 @@
146
147
  {/if}
147
148
  {#each shown as item (item.value)}
148
149
  <li {...api.getItemProps({ item })} class="glim-select-item">
149
- <span {...api.getItemTextProps({ item })}>{item.label}</span>
150
+ <span {...api.getItemTextProps({ item })} data-search={searches && query ? "" : undefined}><SearchHit label={item.label} query={searches ? query : ""} /></span>
150
151
  <span {...api.getItemIndicatorProps({ item })} class="glim-select-check">{@render IconCheck()}</span>
151
152
  </li>
152
153
  {/each}
@@ -133,7 +133,7 @@
133
133
  {/each}
134
134
  </div>
135
135
  {:else if s.loaded}
136
- <EmptyState nested title={fill(text.empty, { app })} />
136
+ <EmptyState nested glyph={glyphFor(keys.notifications)} title={fill(text.empty, { app })} />
137
137
  {/if}
138
138
  <div class="glim-notify-foot">
139
139
  <Button label={text.add} labelKey={keys.add} disabled={!s.loaded} data-notify="add" onClick={flow.pick} />
@@ -22,7 +22,7 @@
22
22
 
23
23
  <script lang="ts">
24
24
  import { attachNumberSteppers, fieldErrorView, syncNumberSteppers } from "@glimstone/core";
25
- import FieldError from "./FieldError.svelte";
25
+ import FieldErrorLine from "./FieldErrorLine.svelte";
26
26
  import { useFieldName } from "./fieldName.js";
27
27
 
28
28
  // A number input with its two steppers inside the field; the steppers, the
@@ -67,4 +67,4 @@
67
67
  class={`glim-num-input glim-num-field glim-num ${className}`.trim()}
68
68
  />
69
69
  </span>
70
- {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
70
+ <FieldErrorLine id={err.errorId} {error} />
@@ -25,10 +25,10 @@
25
25
 
26
26
  <script lang="ts">
27
27
  import { fieldErrorView, fieldNoteView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
28
- import FieldError from "./FieldError.svelte";
28
+ import FieldErrorLine from "./FieldErrorLine.svelte";
29
29
  import { useFieldName } from "./fieldName.js";
30
- import { IconEye, IconEyeOff } from "./glyphs.js";
31
30
  import IconTipButton from "./IconTipButton.svelte";
31
+ import RevealEye from "./RevealEye.svelte";
32
32
 
33
33
  // A field for a secret with the reveal eye inside it ("The reveal eye" in the
34
34
  // design language). The props are a native <input>'s, so a call site swaps
@@ -85,10 +85,10 @@
85
85
  class="glim-input"
86
86
  />
87
87
  <IconTipButton {...eyeAttrs} tip={shown ? words.hide : words.show} class="glim-secret-eye" disabled={!!disabled} onclick={() => (shown = !shown)}>
88
- {#if shown}{@render IconEyeOff()}{:else}{@render IconEye()}{/if}
88
+ <RevealEye struck={shown} />
89
89
  </IconTipButton>
90
90
  </span>
91
- {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
91
+ <FieldErrorLine id={err.errorId} {error} />
92
92
  {#if quiet.noteId}<span id={quiet.noteId} class="glim-field-note">{note}</span>{/if}
93
93
  {#if confirm && view.shown}
94
94
  <span class="glim-secret-confirm">
@@ -100,6 +100,7 @@
100
100
  autocomplete="new-password"
101
101
  spellcheck={false}
102
102
  bind:value={repeat}
103
+ placeholder={words.again}
103
104
  aria-invalid={mismatch.invalid}
104
105
  aria-describedby={mismatch.describedBy}
105
106
  {disabled}
@@ -107,11 +108,11 @@
107
108
  class="glim-input"
108
109
  />
109
110
  <IconTipButton tip={repeatShown ? words.hide : words.show} class="glim-secret-eye" disabled={!!disabled} onclick={() => (repeatShown = !repeatShown)}>
110
- {#if repeatShown}{@render IconEyeOff()}{:else}{@render IconEye()}{/if}
111
+ <RevealEye struck={repeatShown} />
111
112
  </IconTipButton>
112
113
  </span>
113
114
  <span aria-live="polite" class="glim-secret-confirm-live">
114
- {#if mismatch.errorId}<FieldError id={mismatch.errorId}>{words.mismatch}</FieldError>{/if}
115
+ <FieldErrorLine id={mismatch.errorId} error={view.mismatch ? words.mismatch : undefined} />
115
116
  </span>
116
117
  </span>
117
118
  </span>
@@ -26,12 +26,13 @@
26
26
  <script lang="ts">
27
27
  import * as pinInput from "@zag-js/pin-input";
28
28
  import { normalizeProps, useMachine } from "@zag-js/svelte";
29
- import { PIN_INPUT_TEXT, pinCells } from "@glimstone/core";
29
+ import { PIN_INPUT_TEXT, pinCells, pinGroupStarts } from "@glimstone/core";
30
30
  import { useFieldName } from "./fieldName.js";
31
31
 
32
32
  // A short code typed one character to a box, such as the six digits of a
33
33
  // second factor. A code is data, so the boxes run left to right in every
34
- // language. Inside a FieldRow the row names it.
34
+ // language, and a code of six or nine stands in groups of three. Inside a
35
+ // FieldRow the row names it.
35
36
  let {
36
37
  label,
37
38
  value = $bindable(),
@@ -74,6 +75,7 @@
74
75
  <label {...api.getLabelProps()} class={label === undefined ? "glim-sr-only" : "glim-field-label"}>{name()}</label>
75
76
  <div {...api.getControlProps()} class="glim-pin-control">
76
77
  {#each api.items as index (index)}
78
+ {#if pinGroupStarts(index, length)}<span class="glim-pin-sep" aria-hidden="true"></span>{/if}
77
79
  <input {...api.getInputProps({ index })} class="glim-input glim-pin-cell glim-num" />
78
80
  {/each}
79
81
  </div>
@@ -33,6 +33,9 @@
33
33
 
34
34
  const name = useFieldName(() => label);
35
35
  const words = $derived({ ...RATING_TEXT, ...text });
36
+ // Counts the picks: the stylesheet names one spring per parity, so a second
37
+ // pick of the same star springs again.
38
+ let picks = $state(0);
36
39
  const id = $props.id();
37
40
  const service = useMachine(ratingGroup.machine, () => ({
38
41
  id,
@@ -43,6 +46,7 @@
43
46
  readOnly,
44
47
  disabled,
45
48
  onValueChange: (d: { value: number }) => {
49
+ picks += 1;
46
50
  value = d.value;
47
51
  onChange?.(d.value);
48
52
  },
@@ -55,7 +59,12 @@
55
59
  <label {...api.getLabelProps()} class={label === undefined ? "glim-sr-only" : "glim-field-label"}>{name()}</label>
56
60
  <div {...api.getControlProps()} class="glim-rating-control">
57
61
  {#each api.items as index (index)}
58
- <span {...api.getItemProps({ index })} class="glim-rating-star">
62
+ <span
63
+ {...api.getItemProps({ index })}
64
+ data-pop={picks > 0 && index === Math.ceil(api.value) ? (picks % 2 ? "odd" : "even") : undefined}
65
+ style:--i={index - 1}
66
+ class="glim-rating-star"
67
+ >
59
68
  {@render IconStar()}
60
69
  <span class="glim-rating-fill" aria-hidden="true">{@render IconStar()}</span>
61
70
  </span>
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { MARKS } from "@glimstone/core";
3
+
4
+ // The eye, with a stroke that draws itself through it once the secret shows.
5
+ // The stroke cuts a gap into the eye behind it, so it reads on the filled glyph.
6
+ let { struck }: { struck: boolean } = $props();
7
+ const cut = $props.id();
8
+ </script>
9
+
10
+ <svg width="16" height="16" viewBox="0 0 14 14" fill="currentColor" aria-hidden="true" data-struck={struck ? "" : undefined} class="glim-mark">
11
+ <mask id={cut} maskUnits="userSpaceOnUse" x="0" y="0" width="14" height="14">
12
+ <rect width="14" height="14" fill="white" />
13
+ <path d="M1.6 1.6 12.4 12.4" stroke="black" stroke-width="3.4" pathLength="1" stroke-dasharray="1" stroke-dashoffset={struck ? 0 : 1} stroke-linecap="round" fill="none" class="glim-secret-slash" />
14
+ </mask>
15
+ <g mask="url(#{cut})">{@html MARKS.eye.body}</g>
16
+ <path d="M1.6 1.6 12.4 12.4" stroke="currentColor" stroke-width="1.5" pathLength="1" stroke-dasharray="1" stroke-dashoffset={struck ? 0 : 1} stroke-linecap="round" fill="none" class="glim-secret-slash" />
17
+ </svg>
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ struck: boolean;
3
+ };
4
+ declare const RevealEye: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type RevealEye = ReturnType<typeof RevealEye>;
6
+ export default RevealEye;
@@ -0,0 +1,10 @@
1
+ <script lang="ts">
2
+ import { searchParts } from "@glimstone/core";
3
+
4
+ // A row's label in a list that filters as somebody types, with the part
5
+ // that matches the search set apart.
6
+ let { label, query }: { label: string; query: string } = $props();
7
+ const parts = $derived(searchParts(label, query));
8
+ </script>
9
+
10
+ {#if parts}{parts.before}<span class="glim-combobox-hit">{parts.hit}</span>{parts.after}{:else}{label}{/if}
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ label: string;
3
+ query: string;
4
+ };
5
+ declare const SearchHit: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type SearchHit = ReturnType<typeof SearchHit>;
7
+ export default SearchHit;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" module>
2
- import type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
2
+ import type { LabelMode, SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
3
3
  import type { SelectorItem } from "./selectorItem.js";
4
4
 
5
5
  export type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
@@ -20,6 +20,10 @@
20
20
  onPress?: (id: V) => void;
21
21
  /** `vertical` is the column of tiles beside a settings area's pages. */
22
22
  orientation?: SelectorOrientation;
23
+ /** The label mode of this strip alone, in place of the app's setting, for a
24
+ * strip that has to speak in glyphs, words or both whatever the rest does. */
25
+ labels?: LabelMode;
26
+
23
27
  size?: SelectorSize;
24
28
  variant?: SelectorVariant;
25
29
  /** "manual" moves the focus with the arrows and chooses on Space, Enter or a
@@ -37,8 +41,6 @@
37
41
  * alone where every segment has one, a strip of one turns into a dropdown
38
42
  * otherwise, and a `many` strip cuts its labels short. */
39
43
  fit?: boolean;
40
- /** Has no effect: every strip keeps to one row. */
41
- pairsOnPhone?: boolean;
42
44
  /** The button height for every segment, for a strip beside a Button. */
43
45
  buttonHeight?: boolean;
44
46
  /** Take a colour under rainbow. Turn it off where the colour means nothing,
@@ -67,8 +69,11 @@
67
69
  selectorFlex,
68
70
  selectorView,
69
71
  subscribeMedia,
72
+ slideTabPanel,
73
+ tabSlideDir,
70
74
  toggleSelection,
71
75
  watchSelectorFit,
76
+ watchSelectorThumb,
72
77
  WIDE_QUERY,
73
78
  type SelectorLayout,
74
79
  } from "@glimstone/core";
@@ -94,6 +99,7 @@
94
99
  onChange,
95
100
  onPress,
96
101
  orientation = "horizontal",
102
+ labels,
97
103
  size = "md",
98
104
  variant = "well",
99
105
  activation = "auto",
@@ -118,7 +124,7 @@
118
124
  $effect(() => subscribeMedia(WIDE_QUERY, () => (wide = mediaMatches(WIDE_QUERY))));
119
125
  const strip = $derived(
120
126
  selectorView({
121
- mode: mode.current,
127
+ mode: labels ?? mode.current,
122
128
  select: many ? "many" : "one",
123
129
  activation,
124
130
  orientation,
@@ -171,6 +177,23 @@
171
177
 
172
178
  const flex = $derived(selectorFlex({ layout, inline, fit }));
173
179
 
180
+ // One value glides: a thumb under the segments carries the fill from the
181
+ // old choice to the new one. Toggles in a `many` strip each keep their own.
182
+ const gliding = $derived(!vertical && !many);
183
+ $effect(() => {
184
+ if (gliding) return watchSelectorThumb(track);
185
+ });
186
+
187
+ // A tab strip moves its panel in from the side of the tab it came from.
188
+ const chosenIndex = $derived(many ? -1 : items.findIndex((it) => it.id === value));
189
+ let lastIndex = -1;
190
+ $effect(() => {
191
+ const to = chosenIndex;
192
+ const dir = tabSlideDir(lastIndex, to);
193
+ lastIndex = to;
194
+ if (dir && panelId && strip.kind === "tab") slideTabPanel(document.getElementById(panelId), dir);
195
+ });
196
+
174
197
  // countSelector writes the strip's colour onto the track's style itself, so
175
198
  // the layout's properties go on one by one rather than as style text.
176
199
  $effect(() => {
@@ -220,6 +243,7 @@
220
243
  onkeydown={onKeyDown}
221
244
  class={`${strip.className}${listed ? " glim-sel--listed" : ""} ${className}`.trim()}
222
245
  >
246
+ {#if gliding}<span class="glim-sel-thumb" aria-hidden="true"></span>{/if}
223
247
  {#each items as item, i (item.id)}
224
248
  <SelectorSegment
225
249
  {item}
@@ -1,4 +1,4 @@
1
- import type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
1
+ import type { LabelMode, SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
2
2
  import type { SelectorItem } from "./selectorItem.js";
3
3
  export type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
4
4
  export type { SelectorItem } from "./selectorItem.js";
@@ -17,6 +17,9 @@ export interface SelectorProps<M extends SelectMode = "one", V extends string |
17
17
  onPress?: (id: V) => void;
18
18
  /** `vertical` is the column of tiles beside a settings area's pages. */
19
19
  orientation?: SelectorOrientation;
20
+ /** The label mode of this strip alone, in place of the app's setting, for a
21
+ * strip that has to speak in glyphs, words or both whatever the rest does. */
22
+ labels?: LabelMode;
20
23
  size?: SelectorSize;
21
24
  variant?: SelectorVariant;
22
25
  /** "manual" moves the focus with the arrows and chooses on Space, Enter or a
@@ -34,8 +37,6 @@ export interface SelectorProps<M extends SelectMode = "one", V extends string |
34
37
  * alone where every segment has one, a strip of one turns into a dropdown
35
38
  * otherwise, and a `many` strip cuts its labels short. */
36
39
  fit?: boolean;
37
- /** Has no effect: every strip keeps to one row. */
38
- pairsOnPhone?: boolean;
39
40
  /** The button height for every segment, for a strip beside a Button. */
40
41
  buttonHeight?: boolean;
41
42
  /** Take a colour under rainbow. Turn it off where the colour means nothing,
@@ -0,0 +1,152 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from "svelte";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
+ import type { SettingsNavText } from "@glimstone/core";
5
+
6
+ export interface SettingsNavItem {
7
+ /** Stable id, handed back by onChange. */
8
+ id: string;
9
+ label: string;
10
+ /** The page's glyph, muted until the row is chosen or under the pointer. */
11
+ glyph?: Snippet;
12
+ /** The page's own address, so a modified click opens it beside the current one.
13
+ * Without one the row is a button. */
14
+ href?: string;
15
+ }
16
+
17
+ export interface SettingsNavGroup {
18
+ /** A short name in sentence case, such as "Sync". */
19
+ title: string;
20
+ items: SettingsNavItem[];
21
+ }
22
+
23
+ export interface SettingsNavProps extends Omit<HTMLAttributes<HTMLDivElement>, "onchange" | "children" | "class" | "style"> {
24
+ groups: SettingsNavGroup[];
25
+ /** The page that is showing. Without one a phone shows the list itself. */
26
+ value: string | null;
27
+ /** Called with the page a row opens, and with null from the back link. Left
28
+ * out, a row with an href is a plain link for the app's router. */
29
+ onChange?: (id: string | null) => void;
30
+ /** The area's name, such as "Settings": the list's accessible name and the
31
+ * back link's words. */
32
+ label: string;
33
+ /** Where the back link leads, the list's own address. Without one it is a button. */
34
+ backHref?: string;
35
+ /** The person's order of the pages as ids, which the tiles follow with cards.
36
+ * Without one they stand in the order of the groups. */
37
+ order?: readonly string[] | null;
38
+ /** Hears the whole new order once a tile is dragged or moved with Alt and an
39
+ * arrow key. Without it, and always without cards, nothing moves. */
40
+ onReorder?: (order: string[]) => void;
41
+ /** The words the component brings along, in the app's language. */
42
+ text?: Partial<SettingsNavText>;
43
+ /** The page that is showing. */
44
+ children?: Snippet;
45
+ class?: string;
46
+ style?: string;
47
+ }
48
+ </script>
49
+
50
+ <script lang="ts">
51
+ import { moveItem, opensInApp, reorderList, SETTINGS_NAV_TEXT, settingsNavTilesView, settingsNavView } from "@glimstone/core";
52
+ import { useLayout } from "./engines.svelte.js";
53
+ import { IconBack, IconForward } from "./glyphs.js";
54
+ import { css } from "./style.js";
55
+
56
+ // The pages of a settings area in a column of its own, and the page beside
57
+ // it: with cards a column of tiles in the person's order, without them a
58
+ // light list in titled groups. Below 36rem of its own width it becomes a
59
+ // phone's two steps, the pages and then a page with a back link to them.
60
+ // The other props of a <div> go to the root.
61
+ let { groups, value, onChange, label, backHref, order, onReorder, text, children, class: className = "", style, ...rest }: SettingsNavProps = $props();
62
+
63
+ const id = $props.id();
64
+ const layout = useLayout();
65
+ const cards = $derived(layout.current !== "flat");
66
+ const reorder = $derived(cards && !!onReorder);
67
+ const view = $derived(settingsNavView(groups, value));
68
+ const tiles = $derived(settingsNavTilesView(groups, value, order));
69
+ let nav: HTMLElement | undefined = $state();
70
+
71
+ $effect(() => {
72
+ const list = nav;
73
+ if (!reorder || !list) return;
74
+ return reorderList(list, {
75
+ items: () => [...list.children] as HTMLElement[],
76
+ onMove: (from, to) => onReorder?.(moveItem(tiles.tiles.map((t) => t.item.id), from, to)),
77
+ moved: (from, to, count) => ({ ...SETTINGS_NAV_TEXT, ...text }).moved(tiles.tiles[from]?.item.label ?? "", to + 1, count),
78
+ });
79
+ });
80
+
81
+ function open(e: MouseEvent, next: string | null, link: boolean) {
82
+ if (!onChange || (link && !opensInApp(e))) return;
83
+ e.preventDefault();
84
+ if (next !== value) onChange(next);
85
+ }
86
+ </script>
87
+
88
+ <div data-glim="SettingsNav" {...rest} data-root={view.root ? "" : undefined} class={`glim-settings ${className}`.trim()} {style}>
89
+ <nav
90
+ bind:this={nav}
91
+ class="glim-settings-nav"
92
+ class:glim-settings-tiles={cards}
93
+ class:glim-settings-tiles--reorder={reorder}
94
+ aria-label={label}
95
+ >
96
+ {#if cards}
97
+ {#each tiles.tiles as tile (tile.item.id)}
98
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
99
+ <svelte:element
100
+ this={tile.item.href ? "a" : "button"}
101
+ href={tile.item.href}
102
+ type={tile.item.href ? undefined : "button"}
103
+ class={tile.className}
104
+ style={css(tile.style)}
105
+ aria-current={tile.active ? "page" : undefined}
106
+ aria-keyshortcuts={reorder ? "Alt+ArrowUp Alt+ArrowDown" : undefined}
107
+ onclick={(e: MouseEvent) => open(e, tile.item.id, !!tile.item.href)}
108
+ >
109
+ {@render tile.item.glyph?.()}
110
+ <span class="glim-sel-tile-label">{tile.item.label}</span>
111
+ <span class="glim-settings-chevron" aria-hidden="true">{@render IconForward()}</span>
112
+ </svelte:element>
113
+ {/each}
114
+ {:else}
115
+ {#each view.groups as g, i (g.title)}
116
+ <div class="glim-settings-group" role="group" aria-labelledby={`${id}-${i}`}>
117
+ <div id={`${id}-${i}`} class="glim-settings-group-title">{g.title}</div>
118
+ {#each g.rows as row (row.item.id)}
119
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
120
+ <svelte:element
121
+ this={row.item.href ? "a" : "button"}
122
+ href={row.item.href}
123
+ type={row.item.href ? undefined : "button"}
124
+ class={row.className}
125
+ style={css(row.style)}
126
+ aria-current={row.active ? "page" : undefined}
127
+ onclick={(e: MouseEvent) => open(e, row.item.id, !!row.item.href)}
128
+ >
129
+ {@render row.item.glyph?.()}
130
+ <span class="glim-nav-label">{row.item.label}</span>
131
+ <span class="glim-settings-chevron" aria-hidden="true">{@render IconForward()}</span>
132
+ </svelte:element>
133
+ {/each}
134
+ </div>
135
+ {/each}
136
+ {/if}
137
+ </nav>
138
+ <div class="glim-settings-page">
139
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
140
+ <svelte:element
141
+ this={backHref ? "a" : "button"}
142
+ href={backHref}
143
+ type={backHref ? undefined : "button"}
144
+ class="glim-settings-back"
145
+ onclick={(e: MouseEvent) => open(e, null, !!backHref)}
146
+ >
147
+ {@render IconBack()}
148
+ <span>{label}</span>
149
+ </svelte:element>
150
+ {@render children?.()}
151
+ </div>
152
+ </div>
@@ -0,0 +1,46 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ import type { SettingsNavText } from "@glimstone/core";
4
+ export interface SettingsNavItem {
5
+ /** Stable id, handed back by onChange. */
6
+ id: string;
7
+ label: string;
8
+ /** The page's glyph, muted until the row is chosen or under the pointer. */
9
+ glyph?: Snippet;
10
+ /** The page's own address, so a modified click opens it beside the current one.
11
+ * Without one the row is a button. */
12
+ href?: string;
13
+ }
14
+ export interface SettingsNavGroup {
15
+ /** A short name in sentence case, such as "Sync". */
16
+ title: string;
17
+ items: SettingsNavItem[];
18
+ }
19
+ export interface SettingsNavProps extends Omit<HTMLAttributes<HTMLDivElement>, "onchange" | "children" | "class" | "style"> {
20
+ groups: SettingsNavGroup[];
21
+ /** The page that is showing. Without one a phone shows the list itself. */
22
+ value: string | null;
23
+ /** Called with the page a row opens, and with null from the back link. Left
24
+ * out, a row with an href is a plain link for the app's router. */
25
+ onChange?: (id: string | null) => void;
26
+ /** The area's name, such as "Settings": the list's accessible name and the
27
+ * back link's words. */
28
+ label: string;
29
+ /** Where the back link leads, the list's own address. Without one it is a button. */
30
+ backHref?: string;
31
+ /** The person's order of the pages as ids, which the tiles follow with cards.
32
+ * Without one they stand in the order of the groups. */
33
+ order?: readonly string[] | null;
34
+ /** Hears the whole new order once a tile is dragged or moved with Alt and an
35
+ * arrow key. Without it, and always without cards, nothing moves. */
36
+ onReorder?: (order: string[]) => void;
37
+ /** The words the component brings along, in the app's language. */
38
+ text?: Partial<SettingsNavText>;
39
+ /** The page that is showing. */
40
+ children?: Snippet;
41
+ class?: string;
42
+ style?: string;
43
+ }
44
+ declare const SettingsNav: import("svelte").Component<SettingsNavProps, {}, "">;
45
+ type SettingsNav = ReturnType<typeof SettingsNav>;
46
+ export default SettingsNav;