@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,41 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
3
-
4
- interface NavMenuGroupProps {
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
- /** An ARIA label for describing the group to screen readers */
12
- ariaLabel?: string,
13
- }
14
-
15
- /**
16
- * A container for a logical group of navigation menu items.
17
- */
18
- export default function NavMenuGroup($props: NavMenuGroupProps | undefined) {
19
- let $state = $watch({
20
- headerId: ""
21
- });
22
-
23
- // Set the context to pass down to items
24
- let context: NavMenuGroupContext = {
25
- state: $state,
26
- };
27
- $context[NavMenuGroupContextName] = context;
28
-
29
- @render {
30
- <div
31
- {$props?.id}
32
- class={["torp-nav-menu-group", $props?.class]}
33
- {$props?.style}
34
- role="group"
35
- aria-label={$props?.ariaLabel}
36
- aria-labelledby={$state.headerId}
37
- >
38
- <slot />
39
- </div>
40
- }
41
- }
@@ -1,41 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import getId from "../utils/getId";
3
- import { NavMenuGroupContextName, type NavMenuGroupContext } from "./NavMenuTypes";
4
-
5
- interface NavMenuGroupHeaderProps {
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
- /** The type of HTML header to use */
13
- as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6",
14
- }
15
-
16
- /**
17
- * The header for a NavMenuGroup.
18
- */
19
- export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps | undefined) {
20
- let defaultId = getId();
21
-
22
- const context = $context[NavMenuGroupContextName] as NavMenuGroupContext;
23
- if (!context) {
24
- throw new Error("NavMenuGroupHeader must be contained within a NavMenuGroup");
25
- }
26
- let $state = context.state;
27
-
28
- // Set the header ID now that we know what it is
29
- $state.headerId = $props?.id ?? defaultId;
30
-
31
- @render {
32
- @// TODO: self={$props.as}
33
- <h4
34
- id={$props?.id ?? defaultId}
35
- class={["torp-nav-menu-group-header", $props?.class]}
36
- {$props?.style}
37
- >
38
- <slot />
39
- </h4>
40
- }
41
- }
@@ -1,60 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
3
-
4
- interface NavMenuLinkProps {
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 URL for the menu link */
12
- href: string,
13
- /** Whether the menu link should open in a new tab/window */
14
- newWindow?: boolean,
15
- /** Whether this link is disabled */
16
- disabled?: boolean,
17
- }
18
-
19
- /**
20
- * A link that is placed in a NavMenu and signals a response by a user.
21
- *
22
- */
23
- export default function NavMenuLink($props: NavMenuLinkProps | undefined) {
24
- let link: HTMLAnchorElement;
25
-
26
- // Get stuff out of the NavMenuContext
27
- const menuContext = $context[NavMenuContextName] as NavMenuContext;
28
- if (!menuContext) {
29
- throw new Error("NavMenuLink must be contained within a NavMenu");
30
- }
31
- const { registerItem, handleItemKey, handleItemFocus } = menuContext;
32
-
33
- // Register this item with the parent NavMenu and store the index
34
- const { index } = registerItem(setFocused);
35
-
36
- function setFocused() {
37
- link.focus();
38
- }
39
-
40
- @render {
41
- <a
42
- {$props?.id}
43
- class={["torp-nav-menu-link", $props?.class]}
44
- {$props?.style}
45
- {$props?.href}
46
- {$props?.disabled}
47
- target={$props?.newWindow ? "_blank" : undefined}
48
- role="menuitem"
49
- aria-disabled={$props?.disabled ? "true" : undefined}
50
- data-disabled={$props?.disabled ? "true" : undefined}
51
- onkeydown
52
- onkeydown={handleItemKey}
53
- onclick
54
- onfocus={() => handleItemFocus(index)}
55
- &ref={link}
56
- >
57
- <slot />
58
- </a>
59
- }
60
- }
@@ -1,89 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTypes";
3
-
4
- interface NavMenuPopoutProps {
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 NavMenuPopout is:
25
- *
26
- * ```
27
- * <NavMenuPopout>
28
- * <NavMenuPopoutButton />
29
- * <NavMenuPopoutContent />
30
- * </NavMenuPopout>
31
- * ```
32
- */
33
- export default function NavMenuPopout($props: NavMenuPopoutProps | undefined) {
34
- let $state = $watch({
35
- visible: false
36
- });
37
-
38
- // Sync props and state
39
- $run(() => {
40
- $state.visible = $props?.visible ?? false;
41
- });
42
- $run(() => {
43
- if ($props !== undefined) {
44
- $props.visible = $state.visible;
45
- }
46
- });
47
-
48
- let result: any;
49
-
50
- // Set the context to pass down to items
51
- let context: NavMenuPopoutContext = {
52
- state: $state,
53
- };
54
- $context[NavMenuPopoutContextName] = context;
55
-
56
- // Dispatch the toggle event when the popout is opened or closed
57
- let firstToggle = true;
58
- $run(() => {
59
- const ontoggle = $props?.ontoggle;
60
- const onopen = $props?.onopen;
61
- const onclose = $props?.onclose;
62
- const visible = $state.visible;
63
- if (firstToggle) {
64
- firstToggle = false;
65
- } else {
66
- if (ontoggle) ontoggle(visible);
67
- if (visible) {
68
- if (onopen) onopen()
69
- } else {
70
- if (onclose) onclose(result);
71
- }
72
- }
73
- });
74
-
75
- function handleMouseLeave() {
76
- $state.visible = false;
77
- }
78
-
79
- @render {
80
- <div
81
- {$props?.id}
82
- class={["torp-nav-menu-popout", $props?.class]}
83
- {$props?.style}
84
- onmouseleave={handleMouseLeave}
85
- >
86
- <slot />
87
- </div>
88
- }
89
- }
@@ -1,129 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- NavMenuContextName,
4
- NavMenuPopoutContextName,
5
- type NavMenuContext,
6
- type NavMenuPopoutContext,
7
- } from "./NavMenuTypes";
8
-
9
- interface NavMenuPopoutButtonProps {
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 NavMenu and signals a response by a user.
24
- *
25
- */
26
- export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps | undefined) {
27
- let defaultHoverDelay = 500;
28
-
29
- let button: HTMLButtonElement;
30
- let interval: NodeJS.Timeout | undefined;
31
-
32
- // Get stuff out of the NavMenuContext
33
- const menuContext = $context[NavMenuContextName] as NavMenuContext;
34
- if (!menuContext) {
35
- throw new Error("NavMenuPopoutButton must be contained within a NavMenu");
36
- }
37
- const { registerItem, handleItemKey, handleItemFocus } = menuContext;
38
-
39
- // Get stuff out of the NavMenuPopoutContext
40
- const popoutContext = $context[NavMenuPopoutContextName] as NavMenuPopoutContext;
41
- if (!popoutContext) {
42
- throw new Error("NavMenuPopoutButton must be contained within a NavMenuPopout");
43
- }
44
- let $state = popoutContext.state;
45
-
46
- // Register this item with the parent NavMenu and store the index
47
- const { index } = registerItem(setFocused);
48
-
49
- // TODO: $mount should be run AFTER the button has been set
50
- //$mount(() => {
51
- // // Set the anchor element to the button when it exists
52
- // popoutContext.anchorElement = button;
53
- //});
54
-
55
- function setFocused() {
56
- button.focus();
57
- }
58
-
59
- function handleClick() {
60
- $state.visible = true;
61
- }
62
-
63
- function handlePopoutKey(e: KeyboardEvent) {
64
- switch (e.key) {
65
- case "Right":
66
- case "ArrowRight":
67
- // TODO: This should be based on what side the menu shows on
68
- e.preventDefault();
69
- $state.visible = true;
70
- break;
71
- default:
72
- handleItemKey(e);
73
- }
74
- }
75
-
76
- function handleMouseEnter() {
77
- if ($props?.disabled) return;
78
-
79
- // Handle the hover after a delay
80
- if (!interval) {
81
- interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
82
- }
83
- }
84
-
85
- function handleMouseLeave() {
86
- if ($props?.disabled) return;
87
-
88
- // Prevent short hovers or touches from firing the event
89
- if (interval) {
90
- clearTimeout(interval);
91
- interval = undefined;
92
- }
93
- }
94
-
95
- function handleMouseMove() {
96
- if ($props?.disabled) return;
97
-
98
- // Reset the interval on mouse move
99
- if (interval) {
100
- clearTimeout(interval);
101
- interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
102
- }
103
- }
104
-
105
- @render {
106
- <button
107
- {$props?.id}
108
- class={["torp-nav-menu-popout-button", $props?.class]}
109
- {$props?.style}
110
- type="button"
111
- {$props?.disabled}
112
- role="menuitem"
113
- aria-haspopup="true"
114
- aria-expanded={$state.visible.toString()}
115
- aria-disabled={$props?.disabled ? "true" : undefined}
116
- data-disabled={$props?.disabled ? "true" : undefined}
117
- onkeydown={handlePopoutKey}
118
- onclick={handleClick}
119
- onfocus={() => handleItemFocus(index)}
120
- onmouseenter={handleMouseEnter}
121
- onmouseleave={handleMouseLeave}
122
- onmousemove={handleMouseMove}
123
- &ref={button}
124
- onmount={(el) => popoutContext.anchorElement = el }
125
- >
126
- <slot />
127
- </button>
128
- }
129
- }
@@ -1,92 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import getScrollParent from "../utils/getScrollParent";
3
- import setPopoverPosition from "../utils/setPopoverPosition";
4
- import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTypes";
5
-
6
- interface NavMenuPopoutContentProps {
7
- /** An ID for the root element */
8
- id?: string;
9
- /** Classes for the root element */
10
- class?: ClassValue,
11
- /** Styles for the root element */
12
- style?: StyleValue,
13
- /** Where the popout will be shown, relative to the popout button */
14
- side?: "top" | "right" | "bottom" | "left",
15
- /** How the popout will be aligned, relative to the popout button */
16
- alignment?: "start" | "center" | "end",
17
- }
18
-
19
- /**
20
- * The content that is displayed for a NavMenuPopout when it is open.
21
- *
22
- */
23
- export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps | undefined) {
24
- let div: HTMLDivElement;
25
- let shown = false;
26
-
27
- // Get stuff out of the NavMenuPopoutContext
28
- const context = $context[NavMenuPopoutContextName] as NavMenuPopoutContext;
29
- if (!context) {
30
- throw new Error("NavMenuPopoutContent must be contained within a NavMenuPopout");
31
- }
32
- let $state = context.state;
33
-
34
- $run(() => {
35
- if (!$state.visible) {
36
- hide();
37
- }
38
- });
39
-
40
- function show() {
41
- shown = true;
42
-
43
- // Set the position and listen for window resize and scroll to reset the position
44
- setPosition();
45
- const anchorElement = context.anchorElement!
46
- const scrollParent = getScrollParent(anchorElement)
47
- scrollParent.addEventListener("resize", setPosition);
48
- scrollParent.addEventListener("scroll", setPosition);
49
- if (context.focusFirstElement) {
50
- context.focusFirstElement();
51
- }
52
- }
53
-
54
- function hide() {
55
- if (!shown) return;
56
-
57
- // Stop listening for window resize and focus the anchor element per WAI guidelines
58
- const anchorElement = context.anchorElement!
59
- const scrollParent = getScrollParent(anchorElement)
60
- scrollParent.removeEventListener("resize", setPosition);
61
- scrollParent.removeEventListener("scroll", setPosition);
62
- if (anchorElement.focus) {
63
- anchorElement.focus();
64
- }
65
- }
66
-
67
- function setPosition() {
68
- if (!context.anchorElement) {
69
- throw new Error("NavMenuPopoutContent must have an anchor element");
70
- }
71
-
72
- if (div) {
73
- let side = $props?.side ?? "bottom";
74
- let alignment = $props?.alignment ?? "start";
75
- setPopoverPosition(context.anchorElement, div, side, alignment);
76
- }
77
- }
78
-
79
- @render {
80
- @if ($state.visible) {
81
- <div
82
- {$props?.id}
83
- class={["torp-nav-menu-popout-content", $props?.class]}
84
- {$props?.style}
85
- &ref={div}
86
- onmount={show}
87
- >
88
- <slot />
89
- </div>
90
- }
91
- }
92
- }
@@ -1,24 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface NavMenuSeparatorProps {
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 NavMenuSeparator($props: NavMenuSeparatorProps | undefined) {
16
- @render {
17
- <div
18
- {$props?.id}
19
- class={`torp-nav-menu-separator ${$props?.class ?? ""}`.trim()} role="separator"
20
- >
21
- <slot />
22
- </div>
23
- }
24
- }
@@ -1,32 +0,0 @@
1
- export const NavMenuContextName = "NavMenu";
2
- export const NavMenuPopoutContextName = "NavMenuPopout";
3
- export const NavMenuGroupContextName = "NavMenuGroup";
4
-
5
- export interface NavMenuContext {
6
- /** Called from a NavMenuLink or NavMenuButton when its button is focused */
7
- handleItemFocus: (index: number) => void;
8
-
9
- /** Called from a NavMenuLink or NavMenuButton when a key is pressed */
10
- handleItemKey: (e: KeyboardEvent) => void;
11
-
12
- /** Called from each NavMenuLink or NavMenuButton to register itself with this NavMenu */
13
- registerItem: (setFocused: () => void) => { index: number };
14
- }
15
-
16
- export interface NavMenuPopoutContext {
17
- state: {
18
- visible: boolean;
19
- };
20
- anchorElement?: HTMLElement;
21
- focusFirstElement?: () => void;
22
- }
23
-
24
- export interface NavMenuGroupContext {
25
- state: {
26
- headerId: string;
27
- };
28
- }
29
-
30
- export interface ItemState {
31
- setFocused: () => void;
32
- }
@@ -1,23 +0,0 @@
1
- import NavMenu from "./NavMenu.torp";
2
- import NavMenuButton from "./NavMenuButton.torp";
3
- import NavMenuElement from "./NavMenuElement.torp";
4
- import NavMenuGroup from "./NavMenuGroup.torp";
5
- import NavMenuGroupHeader from "./NavMenuGroupHeader.torp";
6
- import NavMenuLink from "./NavMenuLink.torp";
7
- import NavMenuPopout from "./NavMenuPopout.torp";
8
- import NavMenuPopoutButton from "./NavMenuPopoutButton.torp";
9
- import NavMenuPopoutContent from "./NavMenuPopoutContent.torp";
10
- import NavMenuSeparator from "./NavMenuSeparator.torp";
11
-
12
- export {
13
- NavMenu,
14
- NavMenuLink,
15
- NavMenuButton,
16
- NavMenuElement,
17
- NavMenuPopout,
18
- NavMenuPopoutButton,
19
- NavMenuPopoutContent,
20
- NavMenuGroup,
21
- NavMenuGroupHeader,
22
- NavMenuSeparator,
23
- };
@@ -1,71 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NotificationContextName, type NotificationContext } from "./NotificationTypes";
3
-
4
- interface NotificationProps {
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 notification is visible */
12
- visible?: boolean,
13
- /** The duration, in milliseconds, to keep the notification visible */
14
- duration?: number,
15
- /** Raised when the notification has closed, either after the duration has elapsed, or when the user has pressed the close button */
16
- onclose?: () => void,
17
- }
18
-
19
- /**
20
- * An element that displays a brief, important message in a way that attracts
21
- * the user's attention without interrupting the user's task.
22
- *
23
- * See [the WAI ARIA guidelines for Alerts](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).
24
- */
25
- export default function Notification($props: NotificationProps | undefined) {
26
- let defaultDuration = 5000;
27
-
28
- let $state = $watch({
29
- visible: false
30
- });
31
-
32
- $run(() => {
33
- $state.visible = $props?.visible ?? true;
34
- });
35
- $run(() => {
36
- if ($props !== undefined) {
37
- $props.visible = $state.visible;
38
- }
39
- });
40
-
41
- // Set the context to pass down to items
42
- let context: NotificationContext = {
43
- closeNotification
44
- };
45
- $context[NotificationContextName] = context;
46
-
47
- $mount(() => {
48
- setTimeout(closeNotification, $props?.duration ?? defaultDuration);
49
- });
50
-
51
- function closeNotification() {
52
- $state.visible = false;
53
-
54
- if ($props?.onclose) {
55
- $props?.onclose();
56
- }
57
- }
58
-
59
- @render {
60
- @if ($state.visible) {
61
- <div
62
- {$props?.id}
63
- class={["torp-notification", $props?.class]}
64
- {$props?.style}
65
- role="alert"
66
- >
67
- <slot />
68
- </div>
69
- }
70
- }
71
- }
@@ -1,39 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NotificationContextName, type NotificationContext } from "./NotificationTypes";
3
-
4
- interface NotificationCloseProps {
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
- }
12
-
13
- /**
14
- * The button that a user can press to close this Notification.
15
- */
16
- export default function NotificationClose($props: NotificationCloseProps | undefined) {
17
- // Get stuff out of the NotificationContext
18
- const context = $context[NotificationContextName] as NotificationContext;
19
- if (!context) {
20
- throw new Error("NotificationClose must be contained within a Notification");
21
- }
22
- const { closeNotification } = context;
23
-
24
- function handleClick() {
25
- closeNotification();
26
- }
27
-
28
- @render {
29
- <button
30
- {$props?.id}
31
- class={["torp-notification-close", $props?.class]}
32
- {$props?.style}
33
- type="button"
34
- onclick={handleClick}
35
- >
36
- <slot />
37
- </button>
38
- }
39
- }
@@ -1,26 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface NotificationContainerProps {
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
- * The container for one or more Notifications, which can be used to position
14
- * the notifications inside the viewport.
15
- */
16
- export default function NotificationContainer($props: NotificationContainerProps | undefined) {
17
- @render {
18
- <div
19
- {$props?.id}
20
- class={["torp-notification-container", $props?.class]}
21
- {$props?.style}
22
- >
23
- <slot />
24
- </div>
25
- }
26
- }
@@ -1,25 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
-
3
- interface NotificationContentProps {
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
- * The content to display within a Notification.
14
- */
15
- export default function NotificationContent($props: NotificationContentProps | undefined) {
16
- @render {
17
- <div
18
- {$props?.id}
19
- class={["torp-notification-content", $props?.class]}
20
- {$props?.style}
21
- >
22
- <slot />
23
- </div>
24
- }
25
- }