@torpor/ui 0.3.4 → 0.3.6

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 (226) hide show
  1. package/dist/Form/Form.torp +1 -0
  2. package/dist/metafile-esm.json +1 -1
  3. package/package.json +12 -9
  4. package/CHANGELOG.md +0 -338
  5. package/scripts/postbuild.ts +0 -127
  6. package/src/Accordion/Accordion.torp +0 -230
  7. package/src/Accordion/AccordionContent.torp +0 -46
  8. package/src/Accordion/AccordionHeader.torp +0 -45
  9. package/src/Accordion/AccordionItem.torp +0 -101
  10. package/src/Accordion/AccordionTrigger.torp +0 -70
  11. package/src/Accordion/AccordionTypes.ts +0 -36
  12. package/src/Accordion/index.ts +0 -7
  13. package/src/Breadcrumb/Breadcrumb.torp +0 -45
  14. package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
  15. package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
  16. package/src/Breadcrumb/index.ts +0 -5
  17. package/src/Calendar/Calendar.torp +0 -277
  18. package/src/Calendar/CalendarDay.torp +0 -78
  19. package/src/Calendar/CalendarTypes.ts +0 -22
  20. package/src/Calendar/index.ts +0 -4
  21. package/src/Contextual/Contextual.torp +0 -129
  22. package/src/Contextual/ContextualContent.torp +0 -112
  23. package/src/Contextual/ContextualTrigger.torp +0 -70
  24. package/src/Contextual/ContextualTypes.ts +0 -30
  25. package/src/Contextual/index.ts +0 -5
  26. package/src/Dialog/Dialog.torp +0 -136
  27. package/src/Dialog/DialogBody.torp +0 -44
  28. package/src/Dialog/DialogButton.torp +0 -66
  29. package/src/Dialog/DialogFooter.torp +0 -25
  30. package/src/Dialog/DialogHeader.torp +0 -45
  31. package/src/Dialog/DialogTypes.ts +0 -17
  32. package/src/Dialog/index.ts +0 -7
  33. package/src/Disclosure/Disclosure.torp +0 -82
  34. package/src/Disclosure/DisclosureContent.torp +0 -46
  35. package/src/Disclosure/DisclosureHeader.torp +0 -45
  36. package/src/Disclosure/DisclosureTrigger.torp +0 -47
  37. package/src/Disclosure/DisclosureTypes.ts +0 -13
  38. package/src/Disclosure/index.ts +0 -6
  39. package/src/Drawer/Drawer.torp +0 -127
  40. package/src/Drawer/DrawerContent.torp +0 -83
  41. package/src/Drawer/DrawerOverlay.torp +0 -42
  42. package/src/Drawer/DrawerTrigger.torp +0 -39
  43. package/src/Drawer/DrawerTypes.ts +0 -24
  44. package/src/Drawer/index.ts +0 -6
  45. package/src/Form/CheckBox.torp +0 -94
  46. package/src/Form/Field.torp +0 -95
  47. package/src/Form/File.torp +0 -102
  48. package/src/Form/Form.torp +0 -146
  49. package/src/Form/FormTypes.ts +0 -35
  50. package/src/Form/Hidden.torp +0 -25
  51. package/src/Form/Input.torp +0 -112
  52. package/src/Form/Label.torp +0 -35
  53. package/src/Form/Message.torp +0 -39
  54. package/src/Form/Option.torp +0 -28
  55. package/src/Form/Select.torp +0 -101
  56. package/src/Form/StandardSchemaV1.ts +0 -70
  57. package/src/Form/TextArea.torp +0 -105
  58. package/src/Form/index.ts +0 -13
  59. package/src/Menu/Menu.torp +0 -174
  60. package/src/Menu/MenuButton.torp +0 -74
  61. package/src/Menu/MenuCheck.torp +0 -89
  62. package/src/Menu/MenuGroup.torp +0 -31
  63. package/src/Menu/MenuIndicator.torp +0 -40
  64. package/src/Menu/MenuPopout.torp +0 -83
  65. package/src/Menu/MenuPopoutContent.torp +0 -84
  66. package/src/Menu/MenuPopoutTrigger.torp +0 -128
  67. package/src/Menu/MenuRadio.torp +0 -103
  68. package/src/Menu/MenuRadioGroup.torp +0 -109
  69. package/src/Menu/MenuSeparator.torp +0 -26
  70. package/src/Menu/MenuTypes.ts +0 -60
  71. package/src/Menu/index.ts +0 -25
  72. package/src/MenuBar/MenuBar.torp +0 -162
  73. package/src/MenuBar/MenuBarItem.torp +0 -116
  74. package/src/MenuBar/MenuBarItemContent.torp +0 -119
  75. package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
  76. package/src/MenuBar/MenuBarTypes.ts +0 -36
  77. package/src/MenuBar/index.ts +0 -6
  78. package/src/Modal/Modal.torp +0 -122
  79. package/src/Modal/ModalContent.torp +0 -81
  80. package/src/Modal/ModalOverlay.torp +0 -42
  81. package/src/Modal/ModalTrigger.torp +0 -54
  82. package/src/Modal/ModalTypes.ts +0 -22
  83. package/src/Modal/index.ts +0 -10
  84. package/src/Modal/showModal.ts +0 -19
  85. package/src/Modal/showPrompt.ts +0 -23
  86. package/src/NavMenu/NavMenu.torp +0 -190
  87. package/src/NavMenu/NavMenuButton.torp +0 -55
  88. package/src/NavMenu/NavMenuElement.torp +0 -55
  89. package/src/NavMenu/NavMenuGroup.torp +0 -41
  90. package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
  91. package/src/NavMenu/NavMenuLink.torp +0 -60
  92. package/src/NavMenu/NavMenuPopout.torp +0 -89
  93. package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
  94. package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
  95. package/src/NavMenu/NavMenuSeparator.torp +0 -24
  96. package/src/NavMenu/NavMenuTypes.ts +0 -32
  97. package/src/NavMenu/index.ts +0 -23
  98. package/src/Notification/Notification.torp +0 -71
  99. package/src/Notification/NotificationClose.torp +0 -39
  100. package/src/Notification/NotificationContainer.torp +0 -26
  101. package/src/Notification/NotificationContent.torp +0 -25
  102. package/src/Notification/NotificationTypes.ts +0 -5
  103. package/src/Notification/index.ts +0 -13
  104. package/src/Notification/showNotification.ts +0 -30
  105. package/src/Popover/Popover.torp +0 -129
  106. package/src/Popover/PopoverContent.torp +0 -117
  107. package/src/Popover/PopoverTrigger.torp +0 -62
  108. package/src/Popover/PopoverTypes.ts +0 -30
  109. package/src/Popover/index.ts +0 -6
  110. package/src/Popover/showPopover.ts +0 -24
  111. package/src/Slider/Slider.torp +0 -84
  112. package/src/Slider/index.ts +0 -3
  113. package/src/TabGroup/TabContent.torp +0 -49
  114. package/src/TabGroup/TabGroup.torp +0 -250
  115. package/src/TabGroup/TabGroupTypes.ts +0 -44
  116. package/src/TabGroup/TabHeader.torp +0 -81
  117. package/src/TabGroup/TabList.torp +0 -61
  118. package/src/TabGroup/TabTrigger.torp +0 -76
  119. package/src/TabGroup/index.ts +0 -7
  120. package/src/ambient.d.ts +0 -7
  121. package/src/icons/ArrowDown.torp +0 -18
  122. package/src/icons/ArrowLeft.torp +0 -18
  123. package/src/icons/ArrowRight.torp +0 -18
  124. package/src/icons/ArrowUp.torp +0 -18
  125. package/src/icons/Bars.torp +0 -20
  126. package/src/icons/Check.torp +0 -18
  127. package/src/icons/ChevronDown.torp +0 -18
  128. package/src/icons/ChevronLeft.torp +0 -18
  129. package/src/icons/ChevronRight.torp +0 -18
  130. package/src/icons/ChevronUp.torp +0 -18
  131. package/src/icons/Cross.torp +0 -19
  132. package/src/icons/IconTypes.ts +0 -10
  133. package/src/icons/Loading.torp +0 -19
  134. package/src/icons/Minus.torp +0 -18
  135. package/src/icons/Plus.torp +0 -19
  136. package/src/icons/index.ts +0 -31
  137. package/src/motion/fade.ts +0 -16
  138. package/src/motion/grow.ts +0 -23
  139. package/src/motion/index.ts +0 -6
  140. package/src/motion/measure.ts +0 -28
  141. package/src/motion/slide.ts +0 -45
  142. package/src/mount/clickPopover.ts +0 -51
  143. package/src/mount/contextPopover.ts +0 -51
  144. package/src/mount/disableScroll.ts +0 -28
  145. package/src/mount/hoverPopover.ts +0 -58
  146. package/src/mount/hoverTrigger.ts +0 -59
  147. package/src/mount/trapFocus.ts +0 -58
  148. package/src/utils/dateUtils.ts +0 -244
  149. package/src/utils/documentEvents.ts +0 -17
  150. package/src/utils/getId.ts +0 -6
  151. package/src/utils/getScrollParent.ts +0 -22
  152. package/src/utils/setContextPosition.ts +0 -31
  153. package/src/utils/setPopoverPosition.ts +0 -142
  154. package/test/Accordion/accessibility.test.ts +0 -59
  155. package/test/Accordion/components/AccordionAccessibility.torp +0 -44
  156. package/test/Accordion/components/AccordionKeyboard.torp +0 -32
  157. package/test/Accordion/components/AccordionList.torp +0 -23
  158. package/test/Accordion/components/AccordionMultiple.torp +0 -32
  159. package/test/Accordion/components/AccordionSingle.torp +0 -32
  160. package/test/Accordion/for-items.test.ts +0 -52
  161. package/test/Accordion/keyboard.test.ts +0 -64
  162. package/test/Accordion/multiple-item-toggle.test.ts +0 -32
  163. package/test/Accordion/multiple-item-value.test.ts +0 -17
  164. package/test/Accordion/single-item-toggle.test.ts +0 -31
  165. package/test/Accordion/single-item-value.test.ts +0 -17
  166. package/test/Breadcrumb/accessibility.test.ts +0 -29
  167. package/test/Breadcrumb/basic.test.ts +0 -17
  168. package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
  169. package/test/Calendar/components/CalendarTest.torp +0 -9
  170. package/test/Calendar/default.test.ts +0 -18
  171. package/test/Dialog/accessibility-alert.test.ts +0 -40
  172. package/test/Dialog/accessibility-modal.test.ts +0 -52
  173. package/test/Dialog/components/DialogAccessibility.torp +0 -25
  174. package/test/Dialog/components/DialogFunction.torp +0 -36
  175. package/test/Dialog/components/DialogModal.torp +0 -30
  176. package/test/Dialog/components/DialogVariable.torp +0 -33
  177. package/test/Dialog/function.test.ts +0 -26
  178. package/test/Dialog/variable.test.ts +0 -27
  179. package/test/Disclosure/accessibility.test.ts +0 -31
  180. package/test/Disclosure/components/DisclosureTest.torp +0 -17
  181. package/test/Disclosure/default.test.ts +0 -15
  182. package/test/Disclosure/toggle.test.ts +0 -20
  183. package/test/Form/components/FieldTest.torp +0 -25
  184. package/test/Form/components/FormTest.torp +0 -31
  185. package/test/Form/components/InputTest.torp +0 -9
  186. package/test/Form/field.test.ts +0 -34
  187. package/test/Form/form.test.ts +0 -34
  188. package/test/Form/input.test.ts +0 -19
  189. package/test/Menu/accessibility.test.ts +0 -83
  190. package/test/Menu/basic.test.ts +0 -58
  191. package/test/Menu/components/MenuAccessibility.torp +0 -59
  192. package/test/Menu/components/MenuBasic.torp +0 -58
  193. package/test/MenuBar/accessibility.test.ts +0 -87
  194. package/test/MenuBar/basic.test.ts +0 -22
  195. package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
  196. package/test/MenuBar/components/MenuBarBasic.torp +0 -25
  197. package/test/NavMenu/accessibility.test.ts +0 -97
  198. package/test/NavMenu/basic.test.ts +0 -22
  199. package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
  200. package/test/NavMenu/components/NavMenuBasic.torp +0 -28
  201. package/test/Notification/accessibility.test.ts +0 -21
  202. package/test/Notification/components/CustomNotification.torp +0 -14
  203. package/test/Notification/components/NotificationAccessibility.torp +0 -14
  204. package/test/Notification/components/NotificationFunction.torp +0 -17
  205. package/test/Notification/components/NotificationVariable.torp +0 -22
  206. package/test/Notification/function.test.ts +0 -25
  207. package/test/Notification/variable.test.ts +0 -25
  208. package/test/Popover/components/CustomDialog.torp +0 -25
  209. package/test/Popover/components/PopoverFunction.torp +0 -37
  210. package/test/Popover/components/PopoverTrigger.torp +0 -36
  211. package/test/Popover/components/PopoverVariable.torp +0 -40
  212. package/test/Popover/function.test.ts +0 -21
  213. package/test/Popover/trigger.test.ts +0 -27
  214. package/test/Popover/variable.test.ts +0 -27
  215. package/test/TabGroup/accessibility.test.ts +0 -67
  216. package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
  217. package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
  218. package/test/TabGroup/components/TabGroupList.torp +0 -26
  219. package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
  220. package/test/TabGroup/for-items.test.ts +0 -52
  221. package/test/TabGroup/item-trigger.test.ts +0 -33
  222. package/test/TabGroup/item-value.test.ts +0 -17
  223. package/test/TabGroup/keyboard.test.ts +0 -72
  224. package/tsconfig.json +0 -4
  225. package/tsup.config.ts +0 -37
  226. package/vitest.config.ts +0 -12
@@ -1,89 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- MenuButtonContextName,
4
- MenuContextName,
5
- type MenuButtonContext,
6
- type MenuContext
7
- } from "./MenuTypes";
8
-
9
- interface MenuCheckProps {
10
- /** An ID for the root element */
11
- id?: string;
12
- /** Classes for the root element */
13
- class?: ClassValue,
14
- /** Styles for the root element */
15
- style?: StyleValue,
16
- /** Whether this item is checked */
17
- checked?: boolean,
18
- /** Whether this item is disabled */
19
- disabled?: boolean,
20
- /** Raised when the checkbox is clicked */
21
- onclick?: (e: MouseEvent) => void,
22
- }
23
-
24
- /**
25
- * A button that is placed in a Menu or MenuGroup to allow the user to turn an
26
- * option on or off.
27
- *
28
- */
29
- export default function MenuCheck($props: MenuCheckProps | undefined) {
30
- let $state = $watch({
31
- checked: $props?.checked ?? false
32
- });
33
-
34
- $run(() => {
35
- if ($props !== undefined) {
36
- $props.checked = $state.checked;
37
- }
38
- });
39
-
40
- let button: HTMLButtonElement;
41
-
42
- // Get stuff out of the MenuContext
43
- const menuContext = $context[MenuContextName] as MenuContext;
44
- if (!menuContext) {
45
- throw new Error("MenuCheck must be contained within a Menu");
46
- }
47
- const { registerItem, handleItemKey, handleItemFocus } = menuContext;
48
-
49
- // Register this item with the parent Menu
50
- const { index } = registerItem(setFocused);
51
-
52
- // Set the context to pass down to items
53
- let context: MenuButtonContext = {
54
- state: $state
55
- };
56
- $context[MenuButtonContextName] = context;
57
-
58
- function setFocused() {
59
- button.focus();
60
- }
61
-
62
- function handleClick(e: MouseEvent) {
63
- $state.checked = !$state.checked;
64
- if ($props?.onclick) {
65
- $props.onclick(e);
66
- }
67
- }
68
-
69
- @render {
70
- <button
71
- {$props?.id}
72
- class={["torp-menu-check", $props?.class]}
73
- {$props?.style}
74
- type="button"
75
- {$props?.disabled}
76
- role="menuitemcheckbox"
77
- aria-checked={$props?.checked ? "true" : "false"}
78
- aria-disabled={$props?.disabled ? "true" : undefined}
79
- data-state={$props?.checked ? "checked" : "unchecked"}
80
- data-disabled={$props?.disabled ? "true" : undefined}
81
- onkeydown={handleItemKey}
82
- onclick={handleClick}
83
- onfocus={() => handleItemFocus(index)}
84
- &ref={button}
85
- >
86
- <slot />
87
- </button>
88
- }
89
- }
@@ -1,31 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface MenuGroupProps {
4
- /** An ID for the root element */
5
- id?: string;
6
- /** Classes for the root element */
7
- class?: ClassValue,
8
- /** Styles for the root element */
9
- style?: StyleValue,
10
- /** An ARIA label for describing the group to screen readers */
11
- ariaLabel?: string,
12
- }
13
-
14
- /**
15
- * A container for a logical group of menu items.
16
- */
17
- export default function MenuGroup($props: MenuGroupProps | undefined) {
18
- // TODO: Intercept the context to steal toggleItem??
19
-
20
- @render {
21
- <div
22
- {$props?.id}
23
- class={["torp-menu-group", $props?.class]}
24
- {$props?.style}
25
- role="group"
26
- aria-label={$props?.ariaLabel}
27
- >
28
- <slot />
29
- </div>
30
- }
31
- }
@@ -1,40 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { MenuButtonContextName, type MenuButtonContext } from "./MenuTypes";
3
-
4
- interface MenuIndicatorProps {
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
- /** Whether this item is disabled */
12
- disabled?: boolean,
13
- }
14
-
15
- /**
16
- * An indicator for a MenuCheck or MenuRadio component, which is displayed
17
- * when the value of checked is true.
18
- */
19
- export default function MenuIndicator($props: MenuIndicatorProps | undefined) {
20
- // Get stuff out of the MenuButtonContext
21
- const context = $context[MenuButtonContextName] as MenuButtonContext;
22
- if (!context) {
23
- throw new Error("MenuIndicator must be contained within a MenuCheck or MenuRadio");
24
- }
25
- let $state = context.state;
26
-
27
- @render {
28
- @if ($state.checked) {
29
- <div
30
- {$props?.id}
31
- class={["torp-menu-indicator", $props?.class]}
32
- {$props?.style}
33
- aria-disabled={$props?.disabled ? "true" : undefined}
34
- data-disabled={$props?.disabled ? "true" : undefined}
35
- >
36
- <slot />
37
- </div>
38
- }
39
- }
40
- }
@@ -1,83 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { MenuPopoutContextName, type MenuPopoutContext } from "./MenuTypes";
3
-
4
- interface MenuPopoutProps {
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
- /** Whether the popout is visible */
12
- visible?: boolean,
13
- /** Raised when the popout is opened or closed */
14
- ontoggle?: (open: boolean) => void,
15
- /** Raised when the popout has opened */
16
- onopen?: () => void,
17
- /** Raised when the popout has closed */
18
- onclose?: (result: any) => void,
19
- }
20
-
21
- /**
22
- * A popout that is attached to a menu button and can be used to show a submenu.
23
- *
24
- * The structure of a MenuPopout is:
25
- *
26
- * ```
27
- * <MenuPopout>
28
- * <MenuPopoutTrigger /> (optional)
29
- * <MenuPopoutContent />
30
- * </MenuPopout>
31
- * ```
32
- */
33
- export default function MenuPopout($props: MenuPopoutProps | undefined) {
34
- let $state = $watch({
35
- visible: $props?.visible ?? false
36
- });
37
-
38
- let result: any;
39
-
40
- // Set the context to pass down to items
41
- let context: MenuPopoutContext = {
42
- setVisible,
43
- state: $state
44
- };
45
- $context[MenuPopoutContextName] = context;
46
-
47
- function setVisible(value: boolean) {
48
- $state.visible = value;
49
- }
50
-
51
- let firstToggle = true;
52
- $run(() => {
53
- const ontoggle = $props?.ontoggle;
54
- const onopen = $props?.onopen;
55
- const onclose = $props?.onclose;
56
- const visible = $state.visible;
57
- if (firstToggle) {
58
- firstToggle = false;
59
- } else {
60
- if (ontoggle) ontoggle(visible);
61
- if (visible) {
62
- if (onopen) onopen()
63
- } else {
64
- if (onclose) onclose(result);
65
- }
66
- }
67
- });
68
-
69
- function handleMouseLeave() {
70
- setVisible(false);
71
- }
72
-
73
- @render {
74
- <div
75
- {$props?.id}
76
- class={["torp-menu-popout", $props?.class]}
77
- {$props?.style}
78
- onmouseleave={handleMouseLeave}
79
- >
80
- <slot />
81
- </div>
82
- }
83
- }
@@ -1,84 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import setPopoverPosition from "../utils/setPopoverPosition";
3
- import { MenuPopoutContextName, type MenuPopoutContext } from "./MenuTypes";
4
-
5
- interface MenuPopoutContentProps {
6
- /** An ID for the root element */
7
- id?: string;
8
- /** Classes for the root element */
9
- class?: ClassValue,
10
- /** Styles for the root element */
11
- style?: StyleValue,
12
- /** Where the popout will be shown, relative to the popout button */
13
- side?: "top" | "right" | "bottom" | "left",
14
- /** How the popout will be aligned, relative to the popout button */
15
- alignment?: "start" | "center" | "end",
16
- }
17
-
18
- /**
19
- * The content that is displayed for a MenuPopout when it is open.
20
- */
21
- export default function MenuPopoutContent($props: MenuPopoutContentProps | undefined) {
22
- let div: HTMLDivElement;
23
- let shown = false;
24
-
25
- // Get stuff out of the MenuPopoutContext
26
- const popoutContext = $context[MenuPopoutContextName] as MenuPopoutContext;
27
- if (!popoutContext) {
28
- throw new Error("MenuPopoutContent must be contained within a MenuPopout");
29
- }
30
- let $state = popoutContext.state;
31
-
32
- $run(() => {
33
- if (!$state.visible) {
34
- hide();
35
- }
36
- });
37
-
38
- function show() {
39
- shown = true;
40
-
41
- // Set the position and listen for window resize and scroll to reset the position
42
- setPosition();
43
- addEventListener("resize", setPosition);
44
- addEventListener("scroll", setPosition);
45
- if (popoutContext.focusFirstElement) {
46
- popoutContext.focusFirstElement();
47
- }
48
- }
49
-
50
- function hide() {
51
- if (!shown) return;
52
-
53
- // Stop listening for window resize and focus the anchor element per WAI guidelines
54
- removeEventListener("resize", setPosition);
55
- removeEventListener("scroll", setPosition);
56
- if (popoutContext.anchorElement?.focus) {
57
- popoutContext.anchorElement.focus();
58
- }
59
- }
60
-
61
- function setPosition() {
62
- if (!popoutContext.anchorElement) {
63
- throw new Error("MenuPopoutContent must have an anchor element");
64
- }
65
-
66
- let side = $props?.side ?? "right";
67
- let alignment = $props?.alignment ?? "start";
68
- setPopoverPosition(popoutContext.anchorElement, div, side, alignment);
69
- }
70
-
71
- @render {
72
- @if ($state.visible) {
73
- <div
74
- {$props?.id}
75
- class={["torp-menu-popout-content", $props?.class]}
76
- {$props?.style}
77
- &ref={div}
78
- onmount={show}
79
- >
80
- <slot />
81
- </div>
82
- }
83
- }
84
- }
@@ -1,128 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- MenuContextName,
4
- MenuPopoutContextName,
5
- type MenuContext,
6
- type MenuPopoutContext
7
- } from "./MenuTypes";
8
-
9
- interface MenuPopoutTriggerProps {
10
- /** An ID for the root element */
11
- id?: string;
12
- /** Classes for the root element */
13
- class?: ClassValue,
14
- /** Styles for the root element */
15
- style?: StyleValue,
16
- /** The delay before showing the popout, in milliseconds */
17
- hoverDelay?: number,
18
- /** Whether this button is disabled */
19
- disabled?: boolean,
20
- }
21
-
22
- /**
23
- * A button that is placed in a Menu or MenuGroup and signals a response by a user.
24
- */
25
- export default function MenuPopoutTrigger($props: MenuPopoutTriggerProps | undefined) {
26
- let defaultHoverDelay = 500;
27
-
28
- let button: HTMLButtonElement;
29
- let interval: NodeJS.Timeout | undefined;
30
-
31
- // Get stuff out of the MenuContext
32
- const menuContext = $context[MenuContextName] as MenuContext;
33
- if (!menuContext) {
34
- throw new Error("MenuPopoutTrigger must be contained within a Menu");
35
- }
36
- const { registerItem, handleItemKey, handleItemFocus } = menuContext;
37
-
38
- // Get stuff out of the MenuPopoutContext
39
- const popoutContext = $context[MenuPopoutContextName] as MenuPopoutContext;
40
- if (!popoutContext) {
41
- throw new Error("MenuPopoutTrigger must be contained within a MenuPopout");
42
- }
43
- const { state: $state, setVisible } = popoutContext;
44
-
45
- // Register this item with the parent Menu and store the index
46
- const { index } = registerItem(setFocused);
47
-
48
- // TODO: This is getting called before @render
49
- //$mount(() => {
50
- // // Set the anchor element to the button when it exists
51
- // popoutContext.anchorElement = button;
52
- //});
53
-
54
- function setFocused() {
55
- button.focus();
56
- }
57
-
58
- function handleClick() {
59
- setVisible(true);
60
- }
61
-
62
- function handlePopoutKey(e: KeyboardEvent) {
63
- switch (e.key) {
64
- case "Right":
65
- case "ArrowRight":
66
- // TODO: This should be based on what side the menu shows on
67
- e.preventDefault();
68
- setVisible(true);
69
- break;
70
- default:
71
- handleItemKey(e);
72
- }
73
- }
74
-
75
- function handleMouseEnter() {
76
- if ($props?.disabled) return;
77
-
78
- // Handle the hover after a delay
79
- if (!interval) {
80
- interval = setTimeout(() => setVisible(true), $props?.hoverDelay ?? defaultHoverDelay);
81
- }
82
- }
83
-
84
- function handleMouseLeave() {
85
- if ($props?.disabled) return;
86
-
87
- // Prevent short hovers or touches from firing the event
88
- if (interval) {
89
- clearTimeout(interval);
90
- interval = undefined;
91
- }
92
- }
93
-
94
- function handleMouseMove() {
95
- if ($props?.disabled) return;
96
-
97
- // Reset the interval on mouse move
98
- if (interval) {
99
- clearTimeout(interval);
100
- interval = setTimeout(() => setVisible(true), $props?.hoverDelay ?? defaultHoverDelay);
101
- }
102
- }
103
-
104
- @render {
105
- <button
106
- {$props?.id}
107
- class={["torp-menu-popout-trigger", $props?.class]}
108
- {$props?.style}
109
- type="button"
110
- {$props?.disabled}
111
- role="menuitem"
112
- aria-haspopup="true"
113
- aria-expanded={($state.visible ?? false).toString()}
114
- aria-disabled={$props?.disabled ? "true" : undefined}
115
- data-disabled={$props?.disabled ? "true" : undefined}
116
- onkeydown={handlePopoutKey}
117
- onclick={handleClick}
118
- onfocus={() => handleItemFocus(index)}
119
- onmouseenter={handleMouseEnter}
120
- onmouseleave={handleMouseLeave}
121
- onmousemove={handleMouseMove}
122
- &ref={button}
123
- onmount={(el) => popoutContext.anchorElement = el}
124
- >
125
- <slot />
126
- </button>
127
- }
128
- }
@@ -1,103 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- MenuButtonContextName,
4
- MenuContextName,
5
- MenuRadioGroupContextName,
6
- type MenuButtonContext,
7
- type MenuContext,
8
- type MenuRadioGroupContext
9
- } from "./MenuTypes";
10
-
11
- interface MenuRadioProps {
12
- /** An ID for the root element */
13
- id?: string;
14
- /** Classes for the root element */
15
- class?: ClassValue,
16
- /** Styles for the root element */
17
- style?: StyleValue,
18
- /** The value of the item */
19
- value?: string,
20
- /** Whether this item is checked */
21
- checked?: boolean,
22
- /** Whether this item is disabled */
23
- disabled?: boolean,
24
- }
25
-
26
- /**
27
- * A button that is placed in a Menu or MenuGroup to allow the user to select
28
- * from a number of options.
29
- */
30
- export default function MenuRadio($props: MenuRadioProps | undefined) {
31
- let $state = $watch({
32
- checked: $props?.checked ?? false,
33
- });
34
-
35
- $run(() => {
36
- if ($props !== undefined) {
37
- $props.checked = $state.checked;
38
- }
39
- });
40
-
41
- let button: HTMLButtonElement;
42
-
43
- // Get stuff out of the MenuContext
44
- const menuContext = $context[MenuContextName] as MenuContext;
45
- if (!menuContext) {
46
- throw new Error("MenuRadio must be contained within a Menu");
47
- }
48
- const { registerItem, handleItemKey, handleItemFocus } = menuContext;
49
-
50
- // Get stuff out of the MenuRadioGroupContext
51
- const groupContext = $context[MenuRadioGroupContextName] as MenuRadioGroupContext;
52
- if (!groupContext) {
53
- throw new Error("MenuRadio must be contained within a MenuRadioGroup");
54
- }
55
- const { registerItemInGroup, toggleItem } = groupContext;
56
-
57
- // Register this item with the parent Menu
58
- const { index } = registerItem(setFocused);
59
-
60
- // Register this item with the parent MenuRadioGroup
61
- registerItemInGroup($props?.value ?? "", setChecked);
62
-
63
- // Set the context to pass down to items
64
- let context: MenuButtonContext = {
65
- state: $state
66
- };
67
- $context[MenuButtonContextName] = context;
68
-
69
- function setFocused() {
70
- button.focus();
71
- }
72
-
73
- function setChecked(value: boolean) {
74
- $state.checked = value;
75
- }
76
-
77
- function handleClick() {
78
- if (!$state.checked) {
79
- toggleItem($props?.value ?? "");
80
- }
81
- }
82
-
83
- @render {
84
- <button
85
- {$props?.id}
86
- class={["torp-menu-radio", $props?.class]}
87
- {$props?.style}
88
- type="button"
89
- {$props?.disabled}
90
- role="menuitemradio"
91
- aria-checked={$props?.checked}
92
- aria-disabled={$props?.disabled ? "true" : undefined}
93
- data-state={$props?.checked ? "checked" : "unchecked"}
94
- data-disabled={$props?.disabled ? "true" : undefined}
95
- onkeydown={handleItemKey}
96
- onclick={handleClick}
97
- onfocus={() => handleItemFocus(index)}
98
- &ref={button}
99
- >
100
- <slot />
101
- </button>
102
- }
103
- }
@@ -1,109 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- type MenuRadioGroupContext,
4
- MenuRadioGroupContextName,
5
- type RadioGroupItemState
6
- } from "./MenuTypes";
7
-
8
- interface MenuRadioGroupProps {
9
- /** An ID for the root element */
10
- id?: string;
11
- /** Classes for the root element */
12
- class?: ClassValue,
13
- /** Styles for the root element */
14
- style?: StyleValue,
15
- /** An ARIA label for describing the menu to screen readers */
16
- ariaLabel?: string,
17
- /** The value of the checked MenuRadio */
18
- value?: string | undefined,
19
- /** Raised when the checked item has changed */
20
- onchange?: (value: any) => void,
21
- }
22
-
23
- /**
24
- * A container for a logical group of menu RadioGroup items.
25
- */
26
- export default function MenuRadioGroup($props: MenuRadioGroupProps | undefined) {
27
- // A collection containing the state and some functions for each item
28
- let itemStates: RadioGroupItemState[] = [];
29
-
30
- let $state = $watch({
31
- value: $props?.value
32
- });
33
-
34
- $run(() => {
35
- if ($props !== undefined) {
36
- $props.value = $state.value;
37
- }
38
- });
39
-
40
- // Set the context to pass down to items
41
- let context: MenuRadioGroupContext = {
42
- registerItemInGroup,
43
- toggleItem
44
- };
45
- $context[MenuRadioGroupContextName] = context;
46
-
47
- $mount(() => {
48
- // Set the initial checked item
49
- setValue($props?.value);
50
- });
51
-
52
- function registerItemInGroup(itemValue: string, setChecked: (value: boolean) => void) {
53
- // Add the item's state to the array
54
- const newItemState: RadioGroupItemState = {
55
- value: itemValue,
56
- checked: false,
57
- setChecked
58
- };
59
- itemStates.push(newItemState);
60
- itemStates = itemStates;
61
- }
62
-
63
- function setValue(newValue?: string) {
64
- // No point doing this if there aren't any items yet (e.g. from the initial setValue() call)
65
- if (!itemStates.length) {
66
- return;
67
- }
68
-
69
- // Ensure the value passed in was a string (in case e.g. the user has set values to ints)
70
- newValue = newValue?.toString();
71
- for (let item of itemStates) {
72
- item.checked = item.value === newValue;
73
- item.setChecked(item.checked);
74
- }
75
-
76
- // Set the value
77
- if ($state.value !== newValue) {
78
- $state.value = newValue;
79
-
80
- if ($props?.onchange) {
81
- $props?.onchange($props?.value);
82
- }
83
- }
84
- }
85
-
86
- function toggleItem(toggleValue: string) {
87
- let newValue = "";
88
- for (let item of itemStates) {
89
- const checked = item.value === toggleValue;
90
- item.setChecked(checked);
91
- if (checked) {
92
- newValue = item.value;
93
- }
94
- }
95
- $state.value = newValue;
96
- }
97
-
98
- @render {
99
- <div
100
- {$props?.id}
101
- class={["torp-menu-radio-group", $props?.class]}
102
- {$props?.style}
103
- role="group"
104
- aria-label={$props?.ariaLabel}
105
- >
106
- <slot />
107
- </div>
108
- }
109
- }
@@ -1,26 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface MenuSeparatorProps {
4
- /** An ID for the root element */
5
- id?: string;
6
- /** Classes for the root element */
7
- class?: ClassValue,
8
- /** Styles for the root element */
9
- style?: StyleValue,
10
- }
11
-
12
- /**
13
- * An element in a menu that separates logical sets of menu items.
14
- */
15
- export default function MenuSeparator($props: MenuSeparatorProps | undefined) {
16
- @render {
17
- <div
18
- {$props?.id}
19
- class={["torp-menu-separator", $props?.class]}
20
- {$props?.style}
21
- role="separator"
22
- >
23
- <slot />
24
- </div>
25
- }
26
- }