@torpor/ui 1.3.5 → 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 (129) 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 +21 -3
  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-DEeG5vFY.js → loader/index.js} +10 -3
  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/dist/utils/loader.ts +20 -3
  125. package/package.json +41 -5
  126. package/dist/Charts/GridLines.torp +0 -65
  127. package/dist/Charts/XAxis.torp +0 -69
  128. package/dist/Charts/YAxis.torp +0 -49
  129. package/dist/loader-DEeG5vFY.js.map +0 -1
@@ -0,0 +1,81 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ interface SortableListProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue;
9
+ /** Styles for the root element */
10
+ style?: StyleValue;
11
+ /** The items, in display order */
12
+ items: Bindable<any[]>;
13
+ /** Extracts the text for an item (defaults to the item itself) */
14
+ getItemLabel?: (item: any) => string;
15
+ /** Extracts a stable key for an item (defaults to its position) */
16
+ getItemValue?: (item: any) => any;
17
+ /** If set to true, the user cannot reorder the items */
18
+ disabled?: boolean;
19
+ /** An accessible name for the list */
20
+ ariaLabel?: string;
21
+ /** Raised when the items have been reordered */
22
+ onchange?: (items: any[]) => void;
23
+ /** Raised with the source and destination positions after a reorder */
24
+ onmove?: (from: number, to: number) => void;
25
+ }
26
+
27
+ /**
28
+ * A list whose items can be reordered by dragging, or from the keyboard
29
+ * with Alt+Up / Alt+Down (and Alt+Home / Alt+End for the ends).
30
+ *
31
+ * See [the WAI ARIA guidelines for listbox reordering](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/).
32
+ *
33
+ * The structure of a SortableList is:
34
+ *
35
+ * ```
36
+ * <SortableList &items={$state.items} ariaLabel="Steps">
37
+ * <SortableListItem item={item} index={i}>...</SortableListItem>
38
+ * </SortableList>
39
+ * ```
40
+ *
41
+ * With no children, the items are rendered automatically.
42
+ */
43
+ declare function SortableList(
44
+ $parent: ParentNode,
45
+ $anchor: Node | null,
46
+ $props: SortableListProps | undefined,
47
+ $context?: Record<PropertyKey, any>,
48
+ $slots?: Record<string, SlotRender>,
49
+ ): void;
50
+
51
+
52
+
53
+ interface SortableListItemProps {
54
+ /** The item this row represents */
55
+ item: any;
56
+ /** This item's position in the list */
57
+ index: number;
58
+ /** The number of items in the list */
59
+ total?: number;
60
+ /** An ID for the list item element */
61
+ id?: string;
62
+ /** Classes for the list item element */
63
+ class?: ClassValue;
64
+ /** Styles for the list item element */
65
+ style?: StyleValue;
66
+ }
67
+
68
+ /**
69
+ * One reorderable item in a SortableList. Dragging it moves it; with focus,
70
+ * Alt+Up / Alt+Down move it one position, and Alt+Home / Alt+End move it to
71
+ * an end of the list.
72
+ */
73
+ declare function SortableListItem(
74
+ $parent: ParentNode,
75
+ $anchor: Node | null,
76
+ $props: SortableListItemProps | undefined,
77
+ $context?: Record<PropertyKey, any>,
78
+ $slots?: Record<string, SlotRender>,
79
+ ): void;
80
+
81
+ export { SortableList, SortableListItem };
@@ -0,0 +1,3 @@
1
+ import SortableList from "./SortableList.torp";
2
+ import SortableListItem from "./SortableListItem.torp";
3
+ export { SortableList, SortableListItem };
@@ -25,7 +25,7 @@ export default function TabContent($props: TabContentProps | undefined) {
25
25
  if (!context) {
26
26
  throw new Error("TabContent must be contained within a TabGroup");
27
27
  }
28
- let $state = context.registerItem($props?.index, $props?.value);
28
+ const $state = context.registerItem($props?.index, $props?.value);
29
29
 
30
30
  // Set the content ID so that it can be used with aria-controls in TabTrigger
31
31
  $state.contentId = $props?.id ?? defaultId;
@@ -137,8 +137,8 @@ export default function TabGroup($props: TabGroupProps | undefined) {
137
137
  active: false,
138
138
  headerId: "",
139
139
  contentId: "",
140
- disabled: $props?.disabled ?? disabled ?? false,
141
- parentDisabled: $props?.disabled ?? false,
140
+ disabled: $props?.disabled === true || disabled === true,
141
+ parentDisabled: $props?.disabled === true,
142
142
  setFocused: () => {},
143
143
  });
144
144
  group.registerItem(newItemState);
@@ -37,7 +37,7 @@ export default function TabHeader($props: TabHeaderProps | undefined) {
37
37
  if (!context) {
38
38
  throw new Error("TabHeader must be contained within a TabGroup");
39
39
  }
40
- let $state = context.registerHeader($props?.index, $props?.value, $props?.disabled);
40
+ const $state = context.registerHeader($props?.index, $props?.value, $props?.disabled);
41
41
 
42
42
  const itemContext: TabItemContext = {
43
43
  triggerItem: context.triggerItem,
@@ -69,7 +69,7 @@ export default function TagInput($props: TagInputProps | undefined) {
69
69
 
70
70
  // Wire up the enclosing Form and Field, if any
71
71
  const form = createFormField(
72
- $props?.name,
72
+ () => $props?.name,
73
73
  $context[FormContextName] as FormContext | undefined,
74
74
  $context[FieldContextName] as FieldContext | undefined,
75
75
  );
@@ -77,7 +77,7 @@ export default function TimePicker($props: TimePickerProps | undefined) {
77
77
 
78
78
  // Wire up the enclosing Form and Field, if any
79
79
  const form = createFormField(
80
- $props?.name,
80
+ () => $props?.name,
81
81
  $context[FormContextName] as FormContext | undefined,
82
82
  $context[FieldContextName] as FieldContext | undefined,
83
83
  );
@@ -33,7 +33,9 @@ interface ToolBarProps {
33
33
  * ```
34
34
  */
35
35
  export default function ToolBar($props: ToolBarProps | undefined) {
36
- let orientation = $props?.orientation ?? "horizontal";
36
+ function getOrientation(): "horizontal" | "vertical" {
37
+ return $props?.orientation ?? "horizontal";
38
+ }
37
39
 
38
40
  // The focus group owns the item ledger and roving-tabindex bookkeeping
39
41
  const group = createFocusGroup<ItemState>();
@@ -55,7 +57,9 @@ export default function ToolBar($props: ToolBarProps | undefined) {
55
57
  handleItemKey,
56
58
  registerItem,
57
59
  handlePopout,
58
- orientation,
60
+ get orientation() {
61
+ return getOrientation();
62
+ },
59
63
  };
60
64
  $context[ToolBarContextName] = context;
61
65
 
@@ -85,7 +89,7 @@ export default function ToolBar($props: ToolBarProps | undefined) {
85
89
  break;
86
90
  }
87
91
  default: {
88
- group.handleGroupKey(index, e, { vertical: orientation === "vertical" });
92
+ group.handleGroupKey(index, e, { vertical: getOrientation() === "vertical" });
89
93
  break;
90
94
  }
91
95
  }
@@ -108,7 +112,7 @@ export default function ToolBar($props: ToolBarProps | undefined) {
108
112
  tabindex="0"
109
113
  role="toolbar"
110
114
  aria-label={$props?.ariaLabel}
111
- aria-orientation={orientation === "vertical" ? "vertical" : undefined}
115
+ aria-orientation={getOrientation() === "vertical" ? "vertical" : undefined}
112
116
  onfocus={handleFocus}
113
117
  >
114
118
  <slot />
@@ -39,7 +39,7 @@ export default function ToolBarPopoutTrigger($props: ToolBarPopoutTriggerProps |
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>
@@ -0,0 +1,104 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { type TooltipContext, TooltipContextName, type TooltipState } from "./TooltipTypes";
3
+
4
+ interface TooltipProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue;
9
+ /** Styles for the root element */
10
+ style?: StyleValue;
11
+ /** Milliseconds to wait before showing the tooltip (default 500; 0 shows immediately) */
12
+ openDelay?: number;
13
+ /** Milliseconds to wait after the pointer leaves before hiding (default 100) */
14
+ closeDelay?: number;
15
+ /** Where the tooltip is shown, relative to the trigger (default "top") */
16
+ side?: "top" | "right" | "bottom" | "left";
17
+ /** How the tooltip is aligned, relative to the trigger (default "center") */
18
+ alignment?: "start" | "center" | "end";
19
+ /** If set to true, hovering and focusing the trigger are ignored */
20
+ disabled?: boolean;
21
+ /** Raised when the tooltip has opened */
22
+ onopen?: () => void;
23
+ /** Raised when the tooltip has closed */
24
+ onclose?: () => void;
25
+ }
26
+
27
+ /**
28
+ * A short description of an element, shown on hover or focus.
29
+ *
30
+ * See [the WAI ARIA guidelines for Tooltips](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/).
31
+ *
32
+ * The structure of a Tooltip is:
33
+ *
34
+ * ```
35
+ * <Tooltip>
36
+ * <TooltipTrigger>Copy</TooltipTrigger>
37
+ * <TooltipContent>Copy to the clipboard</TooltipContent>
38
+ * </Tooltip>
39
+ * ```
40
+ *
41
+ * The trigger is described by the content through `aria-describedby`, and
42
+ * Escape dismisses the tooltip. Tooltips should contain only short,
43
+ * non-interactive hints; use PopoverHover for rich hover content.
44
+ */
45
+ export default function Tooltip($props: TooltipProps | undefined) {
46
+ let anchorElement: HTMLElement | undefined;
47
+ let wasVisible = false;
48
+
49
+ let $state: TooltipState = $watch({
50
+ visible: false,
51
+ contentId: undefined,
52
+ triggerId: undefined,
53
+ });
54
+
55
+ function show() {
56
+ $state.visible = true;
57
+ }
58
+
59
+ function hide() {
60
+ $state.visible = false;
61
+ }
62
+
63
+ // Dispatch the open/close events when the tooltip is shown or hidden
64
+ $run(() => {
65
+ const visible = $state.visible;
66
+ if (visible === wasVisible) return;
67
+ wasVisible = visible;
68
+ if (visible) {
69
+ $props?.onopen?.();
70
+ } else {
71
+ $props?.onclose?.();
72
+ }
73
+ });
74
+
75
+ let context: TooltipContext = {
76
+ state: $state,
77
+ get anchorElement() {
78
+ return anchorElement;
79
+ },
80
+ set anchorElement(element: HTMLElement | undefined) {
81
+ anchorElement = element;
82
+ },
83
+ getDisabled: () => $props?.disabled === true,
84
+ getOpenDelay: () => $props?.openDelay,
85
+ getCloseDelay: () => $props?.closeDelay,
86
+ getSide: () => $props?.side ?? "top",
87
+ getAlignment: () => $props?.alignment ?? "center",
88
+ show,
89
+ hide,
90
+ };
91
+ $context[TooltipContextName] = context;
92
+
93
+ @render {
94
+ <div {$props?.id} class={["torp-tooltip", $props?.class]} {$props?.style}>
95
+ <slot />
96
+ </div>
97
+ }
98
+
99
+ @style {
100
+ .torp-tooltip {
101
+ display: inline-block;
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,81 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import getId from "../utils/getId";
3
+ import { createPopoutContent } from "../utils/popoutContent";
4
+ import { type TooltipContext, TooltipContextName } from "./TooltipTypes";
5
+
6
+ interface TooltipContentProps {
7
+ /** An ID for the content element */
8
+ id?: string;
9
+ /** Classes for the content element */
10
+ class?: ClassValue;
11
+ /** Styles for the content element */
12
+ style?: StyleValue;
13
+ /** Where the tooltip is shown, relative to the trigger (default from the Tooltip) */
14
+ side?: "top" | "right" | "bottom" | "left";
15
+ /** How the tooltip is aligned, relative to the trigger (default from the Tooltip) */
16
+ alignment?: "start" | "center" | "end";
17
+ }
18
+
19
+ /**
20
+ * The hint displayed for a Tooltip while its trigger is hovered or focused.
21
+ */
22
+ export default function TooltipContent($props: TooltipContentProps | undefined) {
23
+ let defaultId = getId();
24
+ let div: HTMLDivElement;
25
+
26
+ // Get stuff out of the TooltipContext
27
+ const context = $context[TooltipContextName] as TooltipContext;
28
+ if (!context) {
29
+ throw new Error("TooltipContent must be contained within a Tooltip");
30
+ }
31
+ const $state = context.state;
32
+
33
+ // Set the content ID so that the trigger can reference it with aria-describedby
34
+ $state.contentId = $props?.id ?? defaultId;
35
+
36
+ const popout = createPopoutContent({
37
+ getAnchor: () => context.anchorElement,
38
+ getContent: () => div,
39
+ close: () => context.hide(),
40
+ side: $props?.side ?? context.getSide(),
41
+ alignment: $props?.alignment ?? context.getAlignment(),
42
+ closeOnEscape: true,
43
+ ignoreAnchorClicks: true,
44
+ });
45
+
46
+ /**
47
+ * The content is fixed-positioned with viewport coordinates, so move it
48
+ * to the body where fixed descendants aren't captured.
49
+ */
50
+ function portal(el: HTMLElement) {
51
+ const root = el.ownerDocument.body;
52
+ if (root !== null && el.parentNode !== root) {
53
+ root.appendChild(el);
54
+ }
55
+ }
56
+
57
+ $run(() => {
58
+ if (!$state.visible) {
59
+ popout.hide();
60
+ }
61
+ return () => popout.hide();
62
+ });
63
+
64
+ @render {
65
+ @if ($state.visible) {
66
+ <div
67
+ id={$props?.id ?? defaultId}
68
+ class={["torp-tooltip-content", $props?.class]}
69
+ {$props?.style}
70
+ role="tooltip"
71
+ &ref={div}
72
+ onmount={(el) => {
73
+ portal(el);
74
+ popout.show();
75
+ }}
76
+ >
77
+ <slot />
78
+ </div>
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,79 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { createHoverReveal } from "../utils/hoverReveal";
3
+ import getId from "../utils/getId";
4
+ import { type TooltipContext, TooltipContextName } from "./TooltipTypes";
5
+
6
+ interface TooltipTriggerProps {
7
+ /** An ID for the trigger element */
8
+ id?: string;
9
+ /** Classes for the trigger element */
10
+ class?: ClassValue;
11
+ /** Styles for the trigger element */
12
+ style?: StyleValue;
13
+ /** Raised when the trigger is clicked */
14
+ onclick?: (e: MouseEvent) => void;
15
+ }
16
+
17
+ /**
18
+ * The element that shows a Tooltip on hover or focus. Rendered as a button,
19
+ * so it is reachable by keyboard and works on touch screens.
20
+ */
21
+ export default function TooltipTrigger($props: TooltipTriggerProps | undefined) {
22
+ let defaultId = getId();
23
+
24
+ // Get stuff out of the TooltipContext
25
+ const context = $context[TooltipContextName] as TooltipContext;
26
+ if (!context) {
27
+ throw new Error("TooltipTrigger must be contained within a Tooltip");
28
+ }
29
+ const $state = context.state;
30
+
31
+ // Set the trigger ID so that it can be used with aria-describedby
32
+ $state.triggerId = $props?.id ?? defaultId;
33
+
34
+ const hover = createHoverReveal({
35
+ show: () => context.show(),
36
+ hide: () => context.hide(),
37
+ isVisible: () => $state.visible,
38
+ disabled: context.getDisabled,
39
+ getContent: () => ($state.contentId ? document.getElementById($state.contentId) : undefined),
40
+ hoverDelay: context.getOpenDelay(),
41
+ exitGrace: context.getCloseDelay() ?? 100,
42
+ });
43
+
44
+ $run(() => {
45
+ return () => hover.dispose();
46
+ });
47
+
48
+ function handleKey(e: KeyboardEvent) {
49
+ if (e.key === "Escape" && $state.visible) {
50
+ e.preventDefault();
51
+ context.hide();
52
+ }
53
+ }
54
+
55
+ @render {
56
+ <button
57
+ type="button"
58
+ id={$props?.id ?? defaultId}
59
+ class={["torp-tooltip-trigger", $props?.class]}
60
+ {$props?.style}
61
+ aria-describedby={$state.contentId}
62
+ onmouseenter={() => hover.handleEnter()}
63
+ onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
64
+ onpointerdown={(e: PointerEvent) => hover.handlePointerDown(e)}
65
+ onfocus={() => hover.handleFocus()}
66
+ onblur={(e: FocusEvent) => hover.handleBlur(e)}
67
+ onkeydown={handleKey}
68
+ onclick={(e: MouseEvent) => $props?.onclick?.(e)}
69
+ onmount={(el: HTMLButtonElement) => {
70
+ context.anchorElement = el;
71
+ return () => {
72
+ if (context.anchorElement === el) context.anchorElement = undefined;
73
+ };
74
+ }}
75
+ >
76
+ <slot />
77
+ </button>
78
+ }
79
+ }
@@ -0,0 +1,28 @@
1
+ export const TooltipContextName: unique symbol = Symbol.for("torp.Tooltip");
2
+
3
+ export interface TooltipState {
4
+ /** Whether the tooltip is visible */
5
+ visible: boolean;
6
+ /** The ID of the tooltip content */
7
+ contentId: string | undefined;
8
+ /** The ID of the trigger element */
9
+ triggerId: string | undefined;
10
+ }
11
+
12
+ export interface TooltipContext {
13
+ state: TooltipState;
14
+ /** The element the tooltip is shown next to */
15
+ anchorElement: HTMLElement | undefined;
16
+ /** Whether the trigger ignores hover and focus */
17
+ getDisabled: () => boolean;
18
+ /** Milliseconds to wait before opening */
19
+ getOpenDelay: () => number | undefined;
20
+ /** Milliseconds to wait before closing */
21
+ getCloseDelay: () => number | undefined;
22
+ /** Where the tooltip is shown, relative to the trigger */
23
+ getSide: () => "top" | "right" | "bottom" | "left";
24
+ /** How the tooltip is aligned, relative to the trigger */
25
+ getAlignment: () => "start" | "center" | "end";
26
+ show: () => void;
27
+ hide: () => void;
28
+ }
@@ -0,0 +1,104 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ interface TooltipProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue;
9
+ /** Styles for the root element */
10
+ style?: StyleValue;
11
+ /** Milliseconds to wait before showing the tooltip (default 500; 0 shows immediately) */
12
+ openDelay?: number;
13
+ /** Milliseconds to wait after the pointer leaves before hiding (default 100) */
14
+ closeDelay?: number;
15
+ /** Where the tooltip is shown, relative to the trigger (default "top") */
16
+ side?: "top" | "right" | "bottom" | "left";
17
+ /** How the tooltip is aligned, relative to the trigger (default "center") */
18
+ alignment?: "start" | "center" | "end";
19
+ /** If set to true, hovering and focusing the trigger are ignored */
20
+ disabled?: boolean;
21
+ /** Raised when the tooltip has opened */
22
+ onopen?: () => void;
23
+ /** Raised when the tooltip has closed */
24
+ onclose?: () => void;
25
+ }
26
+
27
+ /**
28
+ * A short description of an element, shown on hover or focus.
29
+ *
30
+ * See [the WAI ARIA guidelines for Tooltips](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/).
31
+ *
32
+ * The structure of a Tooltip is:
33
+ *
34
+ * ```
35
+ * <Tooltip>
36
+ * <TooltipTrigger>Copy</TooltipTrigger>
37
+ * <TooltipContent>Copy to the clipboard</TooltipContent>
38
+ * </Tooltip>
39
+ * ```
40
+ *
41
+ * The trigger is described by the content through `aria-describedby`, and
42
+ * Escape dismisses the tooltip. Tooltips should contain only short,
43
+ * non-interactive hints; use PopoverHover for rich hover content.
44
+ */
45
+ declare function Tooltip(
46
+ $parent: ParentNode,
47
+ $anchor: Node | null,
48
+ $props: TooltipProps | undefined,
49
+ $context?: Record<PropertyKey, any>,
50
+ $slots?: Record<string, SlotRender>,
51
+ ): void;
52
+
53
+
54
+
55
+ interface TooltipContentProps {
56
+ /** An ID for the content element */
57
+ id?: string;
58
+ /** Classes for the content element */
59
+ class?: ClassValue;
60
+ /** Styles for the content element */
61
+ style?: StyleValue;
62
+ /** Where the tooltip is shown, relative to the trigger (default from the Tooltip) */
63
+ side?: "top" | "right" | "bottom" | "left";
64
+ /** How the tooltip is aligned, relative to the trigger (default from the Tooltip) */
65
+ alignment?: "start" | "center" | "end";
66
+ }
67
+
68
+ /**
69
+ * The hint displayed for a Tooltip while its trigger is hovered or focused.
70
+ */
71
+ declare function TooltipContent(
72
+ $parent: ParentNode,
73
+ $anchor: Node | null,
74
+ $props: TooltipContentProps | undefined,
75
+ $context?: Record<PropertyKey, any>,
76
+ $slots?: Record<string, SlotRender>,
77
+ ): void;
78
+
79
+
80
+
81
+ interface TooltipTriggerProps {
82
+ /** An ID for the trigger element */
83
+ id?: string;
84
+ /** Classes for the trigger element */
85
+ class?: ClassValue;
86
+ /** Styles for the trigger element */
87
+ style?: StyleValue;
88
+ /** Raised when the trigger is clicked */
89
+ onclick?: (e: MouseEvent) => void;
90
+ }
91
+
92
+ /**
93
+ * The element that shows a Tooltip on hover or focus. Rendered as a button,
94
+ * so it is reachable by keyboard and works on touch screens.
95
+ */
96
+ declare function TooltipTrigger(
97
+ $parent: ParentNode,
98
+ $anchor: Node | null,
99
+ $props: TooltipTriggerProps | undefined,
100
+ $context?: Record<PropertyKey, any>,
101
+ $slots?: Record<string, SlotRender>,
102
+ ): void;
103
+
104
+ export { Tooltip, TooltipContent, TooltipTrigger };
@@ -0,0 +1,4 @@
1
+ import Tooltip from "./Tooltip.torp";
2
+ import TooltipContent from "./TooltipContent.torp";
3
+ import TooltipTrigger from "./TooltipTrigger.torp";
4
+ export { Tooltip, TooltipContent, TooltipTrigger };
@@ -85,7 +85,7 @@ export default function Tree($props: TreeProps | undefined) {
85
85
 
86
86
  // Wire up the enclosing Form and Field, if any
87
87
  const form = createFormField(
88
- $props?.name,
88
+ () => $props?.name,
89
89
  $context[FormContextName] as FormContext | undefined,
90
90
  $context[FieldContextName] as FieldContext | undefined,
91
91
  );
@@ -69,7 +69,7 @@ export default function TreeItem($props: TreeItemProps | undefined) {
69
69
  value: $props?.value ?? "",
70
70
  expanded: false,
71
71
  selected: false,
72
- disabled: $props?.disabled ?? false,
72
+ disabled: $props?.disabled === true,
73
73
  parentDisabled: false,
74
74
  level,
75
75
  hasChildren: false,