@torpor/ui 1.3.6 → 1.4.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 (128) hide show
  1. package/dist/Accordion/AccordionItem.torp +1 -1
  2. package/dist/Alert/Alert.torp +41 -0
  3. package/dist/Alert/index.d.ts +37 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Charts/ChartScatter.torp +167 -0
  6. package/dist/Charts/ScatterChart.torp +49 -178
  7. package/dist/Charts/index.d.ts +38 -78
  8. package/dist/Charts/index.js +2 -4
  9. package/dist/ColorPicker/ColorPalette.torp +107 -29
  10. package/dist/ColorPicker/ColorPicker.torp +121 -10
  11. package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
  12. package/dist/ColorPicker/ColorPickerArea.torp +175 -0
  13. package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
  14. package/dist/ColorPicker/ColorPickerHue.torp +59 -0
  15. package/dist/ColorPicker/ColorPickerInput.torp +7 -18
  16. package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
  17. package/dist/ColorPicker/index.d.ts +139 -14
  18. package/dist/ColorPicker/index.js +5 -1
  19. package/dist/ComboBox/ComboBox.torp +40 -5
  20. package/dist/ComboBox/index.d.ts +5 -2
  21. package/dist/ComboBox/index.js +1 -2
  22. package/dist/Contextual/Contextual.torp +25 -77
  23. package/dist/Contextual/ContextualContent.torp +10 -51
  24. package/dist/Contextual/ContextualHover.torp +13 -85
  25. package/dist/Contextual/ContextualTrigger.torp +9 -16
  26. package/dist/Contextual/ContextualTypes.ts +6 -12
  27. package/dist/Contextual/index.d.ts +10 -13
  28. package/dist/DataGrid/DataGrid.torp +2 -2
  29. package/dist/DataGrid/index.d.ts +1 -1
  30. package/dist/DatePicker/DatePicker.torp +6 -4
  31. package/dist/DateRangePicker/DateRangePicker.torp +14 -13
  32. package/dist/DateTimePicker/DateTimePicker.torp +264 -0
  33. package/dist/DateTimePicker/index.d.ts +46 -0
  34. package/dist/DateTimePicker/index.js +1 -0
  35. package/dist/Dialog/Dialog.torp +0 -1
  36. package/dist/Dialog/index.d.ts +0 -1
  37. package/dist/Drawer/Drawer.torp +5 -23
  38. package/dist/Drawer/DrawerContent.torp +1 -0
  39. package/dist/Drawer/DrawerOverlay.torp +9 -16
  40. package/dist/Drawer/DrawerTrigger.torp +9 -24
  41. package/dist/Drawer/DrawerTypes.ts +3 -1
  42. package/dist/Form/CheckBox.torp +10 -18
  43. package/dist/Form/File.torp +10 -18
  44. package/dist/Form/FileDrop.torp +16 -22
  45. package/dist/Form/Input.torp +14 -20
  46. package/dist/Form/Radio.torp +71 -0
  47. package/dist/Form/RadioGroup.torp +221 -0
  48. package/dist/Form/RadioGroupTypes.ts +40 -0
  49. package/dist/Form/Select.torp +10 -18
  50. package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
  51. package/dist/Form/TextArea.torp +10 -18
  52. package/dist/Form/ToggleButton.torp +94 -0
  53. package/dist/Form/ToggleGroup.torp +150 -0
  54. package/dist/Form/ToggleGroupTypes.ts +23 -0
  55. package/dist/Form/index.d.ts +173 -15
  56. package/dist/Form/index.js +6 -2
  57. package/dist/ListBox/ListBox.torp +27 -5
  58. package/dist/ListBox/ListBoxItem.torp +1 -1
  59. package/dist/ListBox/index.d.ts +6 -2
  60. package/dist/MaskedInput/MaskedInput.torp +1 -1
  61. package/dist/Menu/MenuPopoutTrigger.torp +1 -1
  62. package/dist/MenuBar/MenuBar.torp +5 -3
  63. package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
  64. package/dist/Meter/Meter.torp +126 -0
  65. package/dist/Meter/MeterIndicator.torp +41 -0
  66. package/dist/Meter/MeterTypes.ts +8 -0
  67. package/dist/Meter/index.d.ts +79 -0
  68. package/dist/Meter/index.js +3 -0
  69. package/dist/Modal/Modal.torp +4 -22
  70. package/dist/Modal/ModalOverlay.torp +9 -16
  71. package/dist/NavMenu/NavMenu.torp +5 -3
  72. package/dist/NumberInput/NumberInput.torp +1 -1
  73. package/dist/PinInput/PinInput.torp +220 -0
  74. package/dist/PinInput/index.d.ts +48 -0
  75. package/dist/PinInput/index.js +1 -0
  76. package/dist/Popover/Popover.torp +18 -24
  77. package/dist/Popover/PopoverContent.torp +8 -0
  78. package/dist/Popover/PopoverHover.torp +30 -3
  79. package/dist/Popover/PopoverTypes.ts +2 -0
  80. package/dist/Popover/index.d.ts +8 -1
  81. package/dist/Rating/Rating.torp +1 -1
  82. package/dist/SegmentedControl/SegmentedControl.torp +3 -3
  83. package/dist/SegmentedControl/SegmentedItem.torp +1 -1
  84. package/dist/SelectBox/SelectBox.torp +40 -5
  85. package/dist/SelectBox/index.d.ts +5 -2
  86. package/dist/SelectBox/index.js +1 -2
  87. package/dist/Slider/Slider.torp +1 -1
  88. package/dist/SortableList/SortableList.torp +132 -0
  89. package/dist/SortableList/SortableListItem.torp +117 -0
  90. package/dist/SortableList/SortableListTypes.ts +16 -0
  91. package/dist/SortableList/index.d.ts +81 -0
  92. package/dist/SortableList/index.js +3 -0
  93. package/dist/TabGroup/TabContent.torp +1 -1
  94. package/dist/TabGroup/TabGroup.torp +2 -2
  95. package/dist/TabGroup/TabHeader.torp +1 -1
  96. package/dist/TagInput/TagInput.torp +1 -1
  97. package/dist/TimePicker/TimePicker.torp +1 -1
  98. package/dist/ToolBar/ToolBar.torp +8 -4
  99. package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
  100. package/dist/Tooltip/Tooltip.torp +104 -0
  101. package/dist/Tooltip/TooltipContent.torp +81 -0
  102. package/dist/Tooltip/TooltipTrigger.torp +79 -0
  103. package/dist/Tooltip/TooltipTypes.ts +28 -0
  104. package/dist/Tooltip/index.d.ts +104 -0
  105. package/dist/Tooltip/index.js +4 -0
  106. package/dist/Tree/Tree.torp +1 -1
  107. package/dist/Tree/TreeItem.torp +1 -1
  108. package/dist/VirtualList/VirtualList.torp +149 -0
  109. package/dist/VirtualList/index.d.ts +46 -0
  110. package/dist/VirtualList/index.js +1 -0
  111. package/dist/dnd/index.d.ts +2 -0
  112. package/dist/dnd/index.js +212 -0
  113. package/dist/dnd/index.js.map +1 -0
  114. package/dist/loader/index.d.ts +2 -0
  115. package/dist/{loader-CBGbVpkN.js → loader/index.js} +2 -2
  116. package/dist/loader/index.js.map +1 -0
  117. package/dist/utils/PopoutClickTrigger.torp +1 -0
  118. package/dist/utils/PopoutOverlay.torp +39 -0
  119. package/dist/utils/PopoutTypes.ts +4 -0
  120. package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
  121. package/dist/utils/colorUtils.ts +260 -75
  122. package/dist/utils/formField.ts +4 -3
  123. package/dist/utils/handlePopoutButton.ts +43 -0
  124. package/package.json +41 -5
  125. package/dist/Charts/GridLines.torp +0 -65
  126. package/dist/Charts/XAxis.torp +0 -69
  127. package/dist/Charts/YAxis.torp +0 -49
  128. package/dist/loader-CBGbVpkN.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
2
+ import createFormField from "../utils/formField";
2
3
  import getId from "../utils/getId";
3
4
  import {
4
5
  type FieldContext,
@@ -42,11 +43,10 @@ interface TextAreaProps {
42
43
  export default function TextArea($props: TextAreaProps | undefined) {
43
44
  let defaultId = getId();
44
45
 
45
- let blurred = false;
46
-
47
46
  // Get stuff out of the FormContext and FieldContext
48
- const formContext = $context[FormContextName] as FormContext;
49
- const fieldContext = $context[FieldContextName] as FieldContext;
47
+ const formContext = $context[FormContextName] as FormContext | undefined;
48
+ const fieldContext = $context[FieldContextName] as FieldContext | undefined;
49
+ const form = createFormField(() => $props?.name, formContext, fieldContext);
50
50
 
51
51
  // Use the FieldContext's state, or create a new one
52
52
  let $state =
@@ -65,22 +65,14 @@ export default function TextArea($props: TextAreaProps | undefined) {
65
65
  $bind($state, $props, "value");
66
66
 
67
67
  function handleInput(e: Event) {
68
- if (formContext) {
69
- formContext.validate();
70
- }
71
- if (fieldContext && blurred) {
72
- fieldContext.validate();
73
- }
68
+ form.handleInput();
74
69
  if ($props?.oninput) {
75
70
  $props.oninput(e);
76
71
  }
77
72
  }
78
73
 
79
74
  function handleBlur() {
80
- if (fieldContext) {
81
- fieldContext.validate();
82
- }
83
- blurred = true;
75
+ form.handleBlur();
84
76
  }
85
77
 
86
78
  @render {
@@ -88,7 +80,7 @@ export default function TextArea($props: TextAreaProps | undefined) {
88
80
  id={$props?.id ?? defaultId}
89
81
  class={["torp-text-area", $props?.class]}
90
82
  {$props?.style}
91
- name={$props?.name ?? fieldContext?.name}
83
+ name={form.name}
92
84
  &value={$state.value}
93
85
  {$props?.rows}
94
86
  {$props?.placeholder}
@@ -96,9 +88,9 @@ export default function TextArea($props: TextAreaProps | undefined) {
96
88
  {$props?.required}
97
89
  {$props?.maxlength}
98
90
  aria-label={$props?.ariaLabel}
99
- data-valid={$state.valid ? "valid" : "invalid"}
100
- aria-describedby={$state.messageId}
101
- aria-invalid={fieldContext && !$state.valid ? "true" : undefined}
91
+ data-valid={form.valid ? "valid" : "invalid"}
92
+ aria-describedby={form.messageId}
93
+ aria-invalid={form.inField && !form.valid ? "true" : undefined}
102
94
  {$props?.onchange}
103
95
  oninput={handleInput}
104
96
  onblur={handleBlur}
@@ -0,0 +1,94 @@
1
+ import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
2
+ import getId from "../utils/getId";
3
+ import { ToggleGroupContextName, type ToggleGroupContext } from "./ToggleGroupTypes";
4
+
5
+ interface ToggleButtonProps {
6
+ /** An ID for the button */
7
+ id?: string;
8
+ /** Classes for the button */
9
+ class?: ClassValue;
10
+ /** Styles for the button */
11
+ style?: StyleValue;
12
+ /** Whether the button is pressed; for a standalone button, bind this */
13
+ pressed?: Bindable<boolean>;
14
+ /** The value this button contributes to a ToggleGroup */
15
+ value?: any;
16
+ /** If set to true, the user cannot interact with this button */
17
+ disabled?: boolean;
18
+ /** Raised when the pressed state changes */
19
+ onchange?: (pressed: boolean) => void;
20
+ /** Raised when the button is clicked */
21
+ onclick?: (e: MouseEvent) => void;
22
+ }
23
+
24
+ /**
25
+ * A button that stays pressed until pressed again, exposing its state with
26
+ * `aria-pressed`.
27
+ *
28
+ * See [the WAI ARIA guidelines for Toggle Buttons](https://www.w3.org/WAI/ARIA/apg/patterns/button/).
29
+ *
30
+ * Standalone, bind `pressed`; inside a ToggleGroup, set `value` and the
31
+ * group owns the pressed state.
32
+ */
33
+ export default function ToggleButton($props: ToggleButtonProps | undefined) {
34
+ const defaultId = getId();
35
+
36
+ // A group is optional: standalone buttons manage their own `pressed`
37
+ const group = $context[ToggleGroupContextName] as ToggleGroupContext | undefined;
38
+ const item = group?.registerItem($props?.value, $props?.disabled);
39
+
40
+ let $state = $watch({
41
+ pressed: $props?.pressed ?? false,
42
+ });
43
+
44
+ if (!group) {
45
+ $bind($state, $props, "pressed");
46
+ }
47
+
48
+ $run(() => {
49
+ return () => {
50
+ if (group && item?.index !== undefined) {
51
+ group.removeItem(item.index);
52
+ }
53
+ };
54
+ });
55
+
56
+ function getDisabled(): boolean {
57
+ return $props?.disabled === true || group?.getDisabled() === true || item?.disabled === true;
58
+ }
59
+
60
+ function isPressed(): boolean {
61
+ if (group) {
62
+ return group.isPressed(item ? item.value : $props?.value);
63
+ }
64
+ return $state.pressed;
65
+ }
66
+
67
+ function handleClick(e: MouseEvent) {
68
+ $props?.onclick?.(e);
69
+ if (getDisabled()) return;
70
+ if (group) {
71
+ const next = !group.isPressed(item ? item.value : $props?.value);
72
+ group.toggle(item ? item.value : $props?.value);
73
+ $props?.onchange?.(next);
74
+ return;
75
+ }
76
+ $state.pressed = !$state.pressed;
77
+ $props?.onchange?.($state.pressed);
78
+ }
79
+
80
+ @render {
81
+ <button
82
+ type="button"
83
+ id={$props?.id ?? defaultId}
84
+ class={["torp-toggle-button", $props?.class]}
85
+ {$props?.style}
86
+ aria-pressed={isPressed() ? "true" : "false"}
87
+ aria-disabled={getDisabled() ? "true" : undefined}
88
+ disabled={getDisabled()}
89
+ onclick={handleClick}
90
+ >
91
+ <slot />
92
+ </button>
93
+ }
94
+ }
@@ -0,0 +1,150 @@
1
+ import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
2
+ import {
3
+ type FieldContext,
4
+ FieldContextName,
5
+ type FormContext,
6
+ FormContextName,
7
+ } from "./FormTypes";
8
+ import FormValues from "./FormValues.torp";
9
+ import createFormField from "../utils/formField";
10
+ import {
11
+ type ToggleGroupContext,
12
+ ToggleGroupContextName,
13
+ type ToggleItemState,
14
+ } from "./ToggleGroupTypes";
15
+
16
+ interface ToggleGroupProps {
17
+ /** An ID for the root element */
18
+ id?: string;
19
+ /** Classes for the root element */
20
+ class?: ClassValue;
21
+ /** Styles for the root element */
22
+ style?: StyleValue;
23
+ /** The name of the group's form data field */
24
+ name?: string;
25
+ /**
26
+ * Whether one or several buttons can be pressed at once (default
27
+ * "multiple", like a formatting toolbar)
28
+ */
29
+ type?: "single" | "multiple";
30
+ /** The pressed value, or an array of values when type is "multiple" */
31
+ value?: Bindable<any | any[]>;
32
+ /** If set to true, the user cannot interact with this group */
33
+ disabled?: boolean;
34
+ /** An accessible name for the group */
35
+ ariaLabel?: string;
36
+ /** Raised when the pressed value has changed */
37
+ onchange?: (value: any | any[]) => void;
38
+ }
39
+
40
+ /**
41
+ * A group of ToggleButtons, any of which can be pressed independently (or
42
+ * exactly one, when `type` is "single").
43
+ *
44
+ * The structure of a ToggleGroup is:
45
+ *
46
+ * ```
47
+ * <ToggleGroup name="format" &value={$state.format}>
48
+ * <ToggleButton value="bold">Bold</ToggleButton>
49
+ * <ToggleButton value="italic">Italic</ToggleButton>
50
+ * </ToggleGroup>
51
+ * ```
52
+ */
53
+ export default function ToggleGroup($props: ToggleGroupProps | undefined) {
54
+ const items: ToggleItemState[] = [];
55
+ let nextItemIndex = 0;
56
+
57
+ // Wire up the enclosing Form and Field, if any
58
+ const form = createFormField(
59
+ () => $props?.name,
60
+ $context[FormContextName] as FormContext | undefined,
61
+ $context[FieldContextName] as FieldContext | undefined,
62
+ );
63
+
64
+ function getType(): "single" | "multiple" {
65
+ return $props?.type ?? "multiple";
66
+ }
67
+
68
+ let $state = $watch({
69
+ value: ($props?.value ?? (getType() === "single" ? undefined : [])) as any | any[],
70
+ });
71
+
72
+ $bind($state, $props, "value");
73
+
74
+ function getDisabled(): boolean {
75
+ return $props?.disabled === true;
76
+ }
77
+
78
+ function registerItem(value: any, disabled: boolean | undefined): ToggleItemState {
79
+ const item: ToggleItemState = $watch({
80
+ index: nextItemIndex++,
81
+ value,
82
+ disabled: disabled === true,
83
+ });
84
+ items.push(item);
85
+ return item;
86
+ }
87
+
88
+ function removeItem(index: number) {
89
+ const i = items.findIndex((item) => item.index === index);
90
+ if (i === -1) return;
91
+ items.splice(i, 1);
92
+ for (let j = i; j < items.length; j++) {
93
+ items[j].index = j;
94
+ }
95
+ }
96
+
97
+ function isPressed(value: any): boolean {
98
+ return Array.isArray($state.value)
99
+ ? $state.value.includes(value)
100
+ : $state.value !== undefined && $state.value === value;
101
+ }
102
+
103
+ function toggle(value: any) {
104
+ if (getDisabled()) return;
105
+ if (getType() === "single") {
106
+ $state.value = isPressed(value) ? undefined : value;
107
+ } else {
108
+ const values = Array.isArray($state.value) ? $state.value : [];
109
+ $state.value = isPressed(value)
110
+ ? values.filter((v) => v !== value)
111
+ : values.concat(value);
112
+ }
113
+ form.handleInput();
114
+ $props?.onchange?.($state.value);
115
+ }
116
+
117
+ let context: ToggleGroupContext = {
118
+ registerItem,
119
+ removeItem,
120
+ isPressed,
121
+ toggle,
122
+ getDisabled,
123
+ };
124
+ $context[ToggleGroupContextName] = context;
125
+
126
+ // Only blur when focus leaves the whole group
127
+ function handleFocusOut(e: FocusEvent) {
128
+ if (!(e.currentTarget as HTMLElement).contains(e.relatedTarget as Node | null)) {
129
+ form.handleBlur();
130
+ }
131
+ }
132
+
133
+ @render {
134
+ <div
135
+ {$props?.id}
136
+ class={["torp-toggle-group", $props?.class]}
137
+ {$props?.style}
138
+ role="group"
139
+ aria-label={$props?.ariaLabel}
140
+ aria-disabled={getDisabled() ? "true" : undefined}
141
+ data-valid={form.valid ? "valid" : "invalid"}
142
+ aria-describedby={form.messageId}
143
+ onfocusout={handleFocusOut}
144
+ >
145
+ <slot />
146
+ </div>
147
+
148
+ <FormValues name={form.name} value={$state.value} />
149
+ }
150
+ }
@@ -0,0 +1,23 @@
1
+ export const ToggleGroupContextName: unique symbol = Symbol("ToggleGroup");
2
+
3
+ export interface ToggleItemState {
4
+ /** Assigned by the group in registration order */
5
+ index?: number;
6
+ /** The value submitted while this button is pressed */
7
+ value: any;
8
+ /** Disabled buttons ignore interaction */
9
+ disabled?: boolean;
10
+ }
11
+
12
+ export interface ToggleGroupContext {
13
+ /** Adds a button to the group; returns its state */
14
+ registerItem: (value: any, disabled: boolean | undefined) => ToggleItemState;
15
+ /** Removes a button by index */
16
+ removeItem: (index: number) => void;
17
+ /** Whether a value is currently pressed */
18
+ isPressed: (value: any) => boolean;
19
+ /** Toggles a value, reporting the change */
20
+ toggle: (value: any) => void;
21
+ /** Whether the whole group is disabled */
22
+ getDisabled: () => boolean;
23
+ }
@@ -354,6 +354,75 @@ declare function Option(
354
354
 
355
355
 
356
356
 
357
+ interface RadioProps {
358
+ /** An ID for the radio element */
359
+ id?: string;
360
+ /** Classes for the radio element */
361
+ class?: ClassValue;
362
+ /** Styles for the radio element */
363
+ style?: StyleValue;
364
+ /** The value submitted when this radio is selected */
365
+ value?: any;
366
+ /** If set to true, the user cannot interact with this radio */
367
+ disabled?: boolean;
368
+ }
369
+
370
+ /**
371
+ * One option in a RadioGroup. Its content is the radio's label.
372
+ */
373
+ declare function Radio(
374
+ $parent: ParentNode,
375
+ $anchor: Node | null,
376
+ $props: RadioProps | undefined,
377
+ $context?: Record<PropertyKey, any>,
378
+ $slots?: Record<string, SlotRender>,
379
+ ): void;
380
+
381
+
382
+
383
+ interface RadioGroupProps {
384
+ /** An ID for the root element */
385
+ id?: string;
386
+ /** Classes for the root element */
387
+ class?: ClassValue;
388
+ /** Styles for the root element */
389
+ style?: StyleValue;
390
+ /** The name of the group's form data field */
391
+ name?: string;
392
+ /** The value of the selected radio */
393
+ value: Bindable<any>;
394
+ /** If set to true, the user cannot interact with this group */
395
+ disabled?: boolean;
396
+ /** An accessible name for the group */
397
+ ariaLabel?: string;
398
+ /** Raised when the selected value has changed */
399
+ onchange?: (value: any) => void;
400
+ }
401
+
402
+ /**
403
+ * A group of radios, of which exactly one can be selected.
404
+ *
405
+ * See [the WAI ARIA guidelines for Radio Groups](https://www.w3.org/WAI/ARIA/apg/patterns/radiogroup/).
406
+ *
407
+ * The structure of a RadioGroup is:
408
+ *
409
+ * ```
410
+ * <RadioGroup name="size" &value={$state.size}>
411
+ * <Radio value="small">Small</Radio>
412
+ * <Radio value="large">Large</Radio>
413
+ * </RadioGroup>
414
+ * ```
415
+ */
416
+ declare function RadioGroup(
417
+ $parent: ParentNode,
418
+ $anchor: Node | null,
419
+ $props: RadioGroupProps | undefined,
420
+ $context?: Record<PropertyKey, any>,
421
+ $slots?: Record<string, SlotRender>,
422
+ ): void;
423
+
424
+
425
+
357
426
  interface SelectProps {
358
427
  /** An ID for the root element */
359
428
  id?: string;
@@ -390,6 +459,46 @@ declare function Select(
390
459
 
391
460
 
392
461
 
462
+ interface SwitchProps {
463
+ /** An ID for the root element */
464
+ id?: string;
465
+ /** Classes for the root element */
466
+ class?: ClassValue;
467
+ /** Styles for the root element */
468
+ style?: StyleValue;
469
+ /** The name of the toggle's form data field */
470
+ name?: string;
471
+ /** Whether the toggle is switched on */
472
+ checked?: boolean;
473
+ /** If set to true, the user cannot interact with this toggle */
474
+ disabled?: boolean;
475
+ /** An ARIA label for describing the toggle to screen readers when there is no associated label element */
476
+ ariaLabel?: string;
477
+ /** Raised on change */
478
+ onchange?: (e: Event) => void;
479
+ /** Raised on input */
480
+ oninput?: (e: Event) => void;
481
+ }
482
+
483
+ /**
484
+ * A switch input in a form, which can be turned on or off.
485
+ *
486
+ * Named after the switch role: unlike a ToggleButton, a switch has an
487
+ * on/off state, not a pressed/not-pressed action. `Toggle` is kept as a
488
+ * deprecated alias for the original name.
489
+ *
490
+ * See [the WAI ARIA guidelines for Switches](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
491
+ */
492
+ declare function Switch(
493
+ $parent: ParentNode,
494
+ $anchor: Node | null,
495
+ $props: SwitchProps | undefined,
496
+ $context?: Record<PropertyKey, any>,
497
+ $slots?: Record<string, SlotRender>,
498
+ ): void;
499
+
500
+
501
+
393
502
  interface TextAreaProps {
394
503
  /** An ID for the root element */
395
504
  id?: string;
@@ -432,38 +541,87 @@ declare function TextArea(
432
541
 
433
542
 
434
543
 
435
- interface ToggleProps {
544
+ interface ToggleButtonProps {
545
+ /** An ID for the button */
546
+ id?: string;
547
+ /** Classes for the button */
548
+ class?: ClassValue;
549
+ /** Styles for the button */
550
+ style?: StyleValue;
551
+ /** Whether the button is pressed; for a standalone button, bind this */
552
+ pressed?: Bindable<boolean>;
553
+ /** The value this button contributes to a ToggleGroup */
554
+ value?: any;
555
+ /** If set to true, the user cannot interact with this button */
556
+ disabled?: boolean;
557
+ /** Raised when the pressed state changes */
558
+ onchange?: (pressed: boolean) => void;
559
+ /** Raised when the button is clicked */
560
+ onclick?: (e: MouseEvent) => void;
561
+ }
562
+
563
+ /**
564
+ * A button that stays pressed until pressed again, exposing its state with
565
+ * `aria-pressed`.
566
+ *
567
+ * See [the WAI ARIA guidelines for Toggle Buttons](https://www.w3.org/WAI/ARIA/apg/patterns/button/).
568
+ *
569
+ * Standalone, bind `pressed`; inside a ToggleGroup, set `value` and the
570
+ * group owns the pressed state.
571
+ */
572
+ declare function ToggleButton(
573
+ $parent: ParentNode,
574
+ $anchor: Node | null,
575
+ $props: ToggleButtonProps | undefined,
576
+ $context?: Record<PropertyKey, any>,
577
+ $slots?: Record<string, SlotRender>,
578
+ ): void;
579
+
580
+
581
+
582
+ interface ToggleGroupProps {
436
583
  /** An ID for the root element */
437
584
  id?: string;
438
585
  /** Classes for the root element */
439
586
  class?: ClassValue;
440
587
  /** Styles for the root element */
441
588
  style?: StyleValue;
442
- /** The name of the toggle's form data field */
589
+ /** The name of the group's form data field */
443
590
  name?: string;
444
- /** Whether the toggle is switched on */
445
- checked?: boolean;
446
- /** If set to true, the user cannot interact with this toggle */
591
+ /**
592
+ * Whether one or several buttons can be pressed at once (default
593
+ * "multiple", like a formatting toolbar)
594
+ */
595
+ type?: "single" | "multiple";
596
+ /** The pressed value, or an array of values when type is "multiple" */
597
+ value?: Bindable<any | any[]>;
598
+ /** If set to true, the user cannot interact with this group */
447
599
  disabled?: boolean;
448
- /** An ARIA label for describing the toggle to screen readers when there is no associated label element */
600
+ /** An accessible name for the group */
449
601
  ariaLabel?: string;
450
- /** Raised on change */
451
- onchange?: (e: Event) => void;
452
- /** Raised on input */
453
- oninput?: (e: Event) => void;
602
+ /** Raised when the pressed value has changed */
603
+ onchange?: (value: any | any[]) => void;
454
604
  }
455
605
 
456
606
  /**
457
- * A switch input in a form, which can be turned on or off.
607
+ * A group of ToggleButtons, any of which can be pressed independently (or
608
+ * exactly one, when `type` is "single").
458
609
  *
459
- * See [the WAI ARIA guidelines for Switches](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).
610
+ * The structure of a ToggleGroup is:
611
+ *
612
+ * ```
613
+ * <ToggleGroup name="format" &value={$state.format}>
614
+ * <ToggleButton value="bold">Bold</ToggleButton>
615
+ * <ToggleButton value="italic">Italic</ToggleButton>
616
+ * </ToggleGroup>
617
+ * ```
460
618
  */
461
- declare function Toggle(
619
+ declare function ToggleGroup(
462
620
  $parent: ParentNode,
463
621
  $anchor: Node | null,
464
- $props: ToggleProps | undefined,
622
+ $props: ToggleGroupProps | undefined,
465
623
  $context?: Record<PropertyKey, any>,
466
624
  $slots?: Record<string, SlotRender>,
467
625
  ): void;
468
626
 
469
- export { CheckBox, Field, File, FileDrop, Form, FormValues, Hidden, Input, Label, Message, MessageSummary, Option, Select, TextArea, Toggle };
627
+ export { CheckBox, Field, File, FileDrop, Form, FormValues, Hidden, Input, Label, Message, MessageSummary, Option, Radio, RadioGroup, Select, Switch, TextArea, ToggleButton, ToggleGroup };
@@ -10,7 +10,11 @@ import Label from "./Label.torp";
10
10
  import Message from "./Message.torp";
11
11
  import MessageSummary from "./MessageSummary.torp";
12
12
  import Option from "./Option.torp";
13
+ import Radio from "./Radio.torp";
14
+ import RadioGroup from "./RadioGroup.torp";
13
15
  import Select from "./Select.torp";
16
+ import Switch from "./Switch.torp";
14
17
  import TextArea from "./TextArea.torp";
15
- import Toggle from "./Toggle.torp";
16
- export { CheckBox, Field, File, FileDrop, Form, FormValues, Hidden, Input, Label, Message, MessageSummary, Option, Select, TextArea, Toggle };
18
+ import ToggleButton from "./ToggleButton.torp";
19
+ import ToggleGroup from "./ToggleGroup.torp";
20
+ export { CheckBox, Field, File, FileDrop, Form, FormValues, Hidden, Input, Label, Message, MessageSummary, Option, Radio, RadioGroup, Select, Switch, TextArea, ToggleButton, ToggleGroup };
@@ -26,8 +26,12 @@ interface ListBoxProps {
26
26
  style?: StyleValue;
27
27
  /** Whether a single ListBoxItem or multiple ListBoxItems can be selected at the same time */
28
28
  type?: "single" | "multiple";
29
- /** The value of the selected ListBoxItem, or an array of values if the type is "multiple" */
30
- value: Bindable<any | any[]>;
29
+ /**
30
+ * The value of the selected ListBoxItem, or an array of values if the
31
+ * type is "multiple". Defaults to the enclosing SelectBox/ComboBox value
32
+ * when omitted.
33
+ */
34
+ value?: Bindable<any | any[]>;
31
35
  /** If set to true, the user cannot interact with any items in the ListBox */
32
36
  disabled?: boolean;
33
37
  /** An ARIA label for describing the ListBox to screen readers */
@@ -76,7 +80,7 @@ export default function ListBox($props: ListBoxProps | undefined) {
76
80
 
77
81
  // Wire up the enclosing Form and Field, if any
78
82
  const form = createFormField(
79
- $props?.name,
83
+ () => $props?.name,
80
84
  $context[FormContextName] as FormContext | undefined,
81
85
  $context[FieldContextName] as FieldContext | undefined,
82
86
  );
@@ -86,16 +90,35 @@ export default function ListBox($props: ListBoxProps | undefined) {
86
90
  return $props?.type ?? "single";
87
91
  }
88
92
 
93
+ // Maybe get stuff out of a popout context (SelectBox, ComboBox)
94
+ const popoutContext = $context[PopoutContextName] as PopoutContext | undefined;
95
+
89
96
  // This may come from a PopoutContext, or we may need to handle it ourselves
90
97
  let searchText: string | undefined;
91
98
 
92
99
  let $state = $watch({
93
- value: $props?.value ?? (getType() === "single" ? undefined : []),
100
+ value:
101
+ $props?.value ??
102
+ popoutContext?.state.value ??
103
+ (getType() === "single" ? undefined : []),
94
104
  searchText: undefined as string | undefined,
95
105
  });
96
106
 
97
107
  $bind($state, $props, "value", "searchText");
98
108
 
109
+ // With no value prop, follow the containing SelectBox/ComboBox value.
110
+ // The initial undefined is skipped so it doesn't erase the multiple default.
111
+ let firstFromPopout = true;
112
+ $run(() => {
113
+ const value = popoutContext?.state.value;
114
+ const skip = firstFromPopout && value === undefined;
115
+ firstFromPopout = false;
116
+ if (!popoutContext || $props?.value !== undefined || skip) return;
117
+ if (value !== $state.value) {
118
+ $state.value = value;
119
+ }
120
+ });
121
+
99
122
  if ($props?.load !== undefined && typeof $props.load !== "function") {
100
123
  throw new Error("ListBox: `load` must be a function");
101
124
  }
@@ -113,7 +136,6 @@ export default function ListBox($props: ListBoxProps | undefined) {
113
136
 
114
137
  // Maybe get stuff out of a popout context
115
138
  let handleButton: HandleButtonPress | undefined = undefined;
116
- const popoutContext = $context[PopoutContextName] as PopoutContext;
117
139
  if (popoutContext) {
118
140
  handleButton = popoutContext.handleButton;
119
141
 
@@ -35,7 +35,7 @@ export default function ListBoxItem($props: ListBoxItemProps | undefined) {
35
35
  value: $props?.value,
36
36
  selected: false,
37
37
  active: false,
38
- disabled: $props?.disabled ?? false,
38
+ disabled: $props?.disabled === true,
39
39
  parentDisabled: false,
40
40
  setFocused,
41
41
  });
@@ -10,8 +10,12 @@ interface ListBoxProps {
10
10
  style?: StyleValue;
11
11
  /** Whether a single ListBoxItem or multiple ListBoxItems can be selected at the same time */
12
12
  type?: "single" | "multiple";
13
- /** The value of the selected ListBoxItem, or an array of values if the type is "multiple" */
14
- value: Bindable<any | any[]>;
13
+ /**
14
+ * The value of the selected ListBoxItem, or an array of values if the
15
+ * type is "multiple". Defaults to the enclosing SelectBox/ComboBox value
16
+ * when omitted.
17
+ */
18
+ value?: Bindable<any | any[]>;
15
19
  /** If set to true, the user cannot interact with any items in the ListBox */
16
20
  disabled?: boolean;
17
21
  /** An ARIA label for describing the ListBox to screen readers */
@@ -56,7 +56,7 @@ export default function MaskedInput($props: MaskedInputProps | undefined) {
56
56
 
57
57
  // Wire up the enclosing Form and Field, if any
58
58
  const form = createFormField(
59
- $props?.name,
59
+ () => $props?.name,
60
60
  $context[FormContextName] as FormContext | undefined,
61
61
  $context[FieldContextName] as FieldContext | undefined,
62
62
  );
@@ -39,7 +39,7 @@ export default function MenuPopoutTrigger($props: MenuPopoutTriggerProps | undef
39
39
  registerItem={registerItem}
40
40
  handleItemKey={handleItemKey}
41
41
  handleItemFocus={handleItemFocus}
42
- onActivate={handlePopout}
42
+ onactivate={handlePopout}
43
43
  >
44
44
  <slot />
45
45
  </SubmenuPopoutTrigger>