@torpor/ui 0.1.7 → 0.2.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 (276) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/Accordion/Accordion.torp +2 -2
  3. package/dist/Accordion/AccordionContent.torp +2 -2
  4. package/dist/Accordion/AccordionHeader.torp +2 -2
  5. package/dist/Accordion/AccordionItem.torp +2 -2
  6. package/dist/Accordion/AccordionTrigger.torp +2 -2
  7. package/dist/Accordion/index.d.ts +92 -0
  8. package/dist/Breadcrumb/Breadcrumb.torp +33 -0
  9. package/dist/Breadcrumb/BreadcrumbItem.torp +19 -0
  10. package/dist/Breadcrumb/BreadcrumbSeparator.torp +16 -0
  11. package/dist/Breadcrumb/index.d.ts +56 -0
  12. package/dist/Breadcrumb/index.js +14 -0
  13. package/dist/Calendar/Calendar.torp +265 -0
  14. package/dist/Calendar/CalendarDay.torp +67 -0
  15. package/dist/Calendar/CalendarTypes.ts +22 -0
  16. package/dist/Calendar/index.d.ts +38 -0
  17. package/dist/Calendar/index.js +10 -0
  18. package/dist/Calendar/index.js.map +1 -0
  19. package/dist/Dialog/Dialog.torp +3 -3
  20. package/dist/Dialog/DialogBody.torp +2 -2
  21. package/dist/Dialog/DialogButton.torp +2 -2
  22. package/dist/Dialog/DialogFooter.torp +2 -2
  23. package/dist/Dialog/DialogHeader.torp +2 -2
  24. package/dist/Dialog/index.d.ts +92 -0
  25. package/dist/Disclosure/Disclosure.torp +69 -0
  26. package/dist/Disclosure/DisclosureContent.torp +36 -0
  27. package/dist/Disclosure/DisclosureHeader.torp +34 -0
  28. package/dist/Disclosure/DisclosureTrigger.torp +36 -0
  29. package/dist/Disclosure/DisclosureTypes.ts +14 -0
  30. package/dist/Disclosure/index.d.ts +74 -0
  31. package/dist/Disclosure/index.js +18 -0
  32. package/dist/Disclosure/index.js.map +1 -0
  33. package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +10 -19
  34. package/dist/Drawer/index.d.ts +20 -0
  35. package/dist/Drawer/index.js +6 -0
  36. package/dist/Drawer/index.js.map +1 -0
  37. package/dist/Menu/Menu.torp +160 -0
  38. package/dist/Menu/MenuButton.torp +53 -0
  39. package/dist/Menu/MenuCheck.torp +70 -0
  40. package/dist/Menu/MenuGroup.torp +19 -0
  41. package/dist/Menu/MenuIndicator.torp +29 -0
  42. package/dist/Menu/MenuPopout.torp +71 -0
  43. package/dist/Menu/MenuPopoutContent.torp +74 -0
  44. package/dist/Menu/MenuPopoutTrigger.torp +117 -0
  45. package/dist/Menu/MenuRadio.torp +88 -0
  46. package/dist/Menu/MenuRadioGroup.torp +86 -0
  47. package/dist/Menu/MenuSeparator.torp +14 -0
  48. package/dist/Menu/MenuTypes.ts +58 -0
  49. package/dist/Menu/index.d.ts +200 -0
  50. package/dist/Menu/index.js +46 -0
  51. package/dist/Menu/index.js.map +1 -0
  52. package/dist/MenuBar/MenuBar.torp +150 -0
  53. package/dist/MenuBar/MenuBarItem.torp +104 -0
  54. package/dist/MenuBar/MenuBarItemContent.torp +108 -0
  55. package/dist/MenuBar/MenuBarItemTrigger.torp +89 -0
  56. package/dist/MenuBar/MenuBarTypes.ts +36 -0
  57. package/dist/MenuBar/index.d.ts +74 -0
  58. package/dist/MenuBar/index.js +18 -0
  59. package/dist/MenuBar/index.js.map +1 -0
  60. package/dist/NavMenu/NavMenu.torp +2 -2
  61. package/dist/NavMenu/NavMenuButton.torp +2 -2
  62. package/dist/NavMenu/NavMenuElement.torp +2 -2
  63. package/dist/NavMenu/NavMenuGroup.torp +2 -2
  64. package/dist/NavMenu/NavMenuGroupHeader.torp +2 -2
  65. package/dist/NavMenu/NavMenuLink.torp +2 -2
  66. package/dist/NavMenu/NavMenuPopout.torp +2 -2
  67. package/dist/NavMenu/NavMenuPopoutButton.torp +3 -3
  68. package/dist/NavMenu/NavMenuPopoutContent.torp +29 -27
  69. package/dist/NavMenu/NavMenuSeparator.torp +2 -2
  70. package/dist/NavMenu/index.d.ts +182 -0
  71. package/dist/Notification/Notification.torp +48 -0
  72. package/dist/Notification/NotificationClose.torp +28 -0
  73. package/dist/Notification/NotificationContainer.torp +14 -0
  74. package/dist/Notification/NotificationContent.torp +13 -0
  75. package/dist/Notification/NotificationTypes.ts +5 -0
  76. package/dist/Notification/index.d.ts +74 -0
  77. package/dist/Notification/index.js +36 -0
  78. package/dist/Notification/index.js.map +1 -0
  79. package/dist/Notification/showNotification.ts +30 -0
  80. package/dist/Popover/Popover.torp +2 -2
  81. package/dist/Popover/PopoverContent.torp +31 -28
  82. package/dist/Popover/PopoverContentAnchored.torp +39 -38
  83. package/dist/Popover/PopoverContentContextual.torp +39 -36
  84. package/dist/Popover/PopoverOverlay.torp +3 -3
  85. package/dist/Popover/PopoverTrigger.torp +2 -2
  86. package/dist/Popover/PopoverTriggerContextual.torp +2 -2
  87. package/dist/Popover/PopoverTriggerHover.torp +3 -3
  88. package/dist/Popover/index.d.ts +146 -0
  89. package/dist/TabGroup/TabContent.torp +2 -2
  90. package/dist/TabGroup/TabGroup.torp +2 -2
  91. package/dist/TabGroup/TabHeader.torp +2 -2
  92. package/dist/TabGroup/TabList.torp +2 -2
  93. package/dist/TabGroup/TabTrigger.torp +2 -2
  94. package/dist/TabGroup/index.d.ts +92 -0
  95. package/dist/icons/ArrowDown.torp +15 -0
  96. package/dist/icons/ArrowLeft.torp +15 -0
  97. package/dist/icons/ArrowRight.torp +15 -0
  98. package/dist/icons/ArrowUp.torp +15 -0
  99. package/dist/icons/Bars.torp +17 -0
  100. package/dist/icons/Check.torp +15 -0
  101. package/dist/icons/ChevronDown.torp +15 -0
  102. package/dist/icons/ChevronLeft.torp +15 -0
  103. package/dist/icons/ChevronRight.torp +15 -0
  104. package/dist/icons/ChevronUp.torp +15 -0
  105. package/dist/icons/Cross.torp +16 -0
  106. package/dist/icons/Loading.torp +16 -0
  107. package/dist/icons/Minus.torp +15 -0
  108. package/dist/icons/Plus.torp +16 -0
  109. package/dist/icons/index.d.ts +254 -0
  110. package/dist/icons/index.js +58 -0
  111. package/dist/icons/index.js.map +1 -0
  112. package/dist/{motion.d.cts → index.d.ts} +2 -2
  113. package/dist/metafile-esm.json +1 -1
  114. package/dist/motion/fade.ts +7 -0
  115. package/dist/motion/index.d.ts +2 -0
  116. package/dist/{motion.js → motion/index.js} +1 -1
  117. package/dist/motion/index.js.map +1 -0
  118. package/dist/mount/index.d.ts +2 -0
  119. package/dist/utils/dateUtils.ts +244 -0
  120. package/dist/utils/index.d.ts +2 -0
  121. package/dist/utils/setPopoverPosition.ts +4 -0
  122. package/package.json +50 -34
  123. package/scripts/postbuild.ts +42 -5
  124. package/src/Accordion/Accordion.torp +2 -2
  125. package/src/Accordion/AccordionContent.torp +2 -2
  126. package/src/Accordion/AccordionHeader.torp +2 -2
  127. package/src/Accordion/AccordionItem.torp +2 -2
  128. package/src/Accordion/AccordionTrigger.torp +2 -2
  129. package/src/Breadcrumb/Breadcrumb.torp +33 -0
  130. package/src/Breadcrumb/BreadcrumbItem.torp +19 -0
  131. package/src/Breadcrumb/BreadcrumbSeparator.torp +16 -0
  132. package/src/Breadcrumb/index.ts +5 -0
  133. package/src/Calendar/Calendar.torp +265 -0
  134. package/src/Calendar/CalendarDay.torp +67 -0
  135. package/src/Calendar/CalendarTypes.ts +22 -0
  136. package/src/Calendar/index.ts +4 -0
  137. package/src/Dialog/Dialog.torp +3 -3
  138. package/src/Dialog/DialogBody.torp +2 -2
  139. package/src/Dialog/DialogButton.torp +2 -2
  140. package/src/Dialog/DialogFooter.torp +2 -2
  141. package/src/Dialog/DialogHeader.torp +2 -2
  142. package/src/Disclosure/Disclosure.torp +69 -0
  143. package/src/Disclosure/DisclosureContent.torp +36 -0
  144. package/src/Disclosure/DisclosureHeader.torp +34 -0
  145. package/src/Disclosure/DisclosureTrigger.torp +36 -0
  146. package/src/Disclosure/DisclosureTypes.ts +14 -0
  147. package/src/Disclosure/index.ts +6 -0
  148. package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +10 -19
  149. package/src/Drawer/index.ts +3 -0
  150. package/src/Menu/Menu.torp +160 -0
  151. package/src/Menu/MenuButton.torp +53 -0
  152. package/src/Menu/MenuCheck.torp +70 -0
  153. package/src/Menu/MenuGroup.torp +19 -0
  154. package/src/Menu/MenuIndicator.torp +29 -0
  155. package/src/Menu/MenuPopout.torp +71 -0
  156. package/src/Menu/MenuPopoutContent.torp +74 -0
  157. package/src/Menu/MenuPopoutTrigger.torp +117 -0
  158. package/src/Menu/MenuRadio.torp +88 -0
  159. package/src/Menu/MenuRadioGroup.torp +86 -0
  160. package/src/Menu/MenuSeparator.torp +14 -0
  161. package/src/Menu/MenuTypes.ts +58 -0
  162. package/src/Menu/index.ts +25 -0
  163. package/src/MenuBar/MenuBar.torp +150 -0
  164. package/src/MenuBar/MenuBarItem.torp +104 -0
  165. package/src/MenuBar/MenuBarItemContent.torp +108 -0
  166. package/src/MenuBar/MenuBarItemTrigger.torp +89 -0
  167. package/src/MenuBar/MenuBarTypes.ts +36 -0
  168. package/src/MenuBar/index.ts +6 -0
  169. package/src/NavMenu/NavMenu.torp +2 -2
  170. package/src/NavMenu/NavMenuButton.torp +2 -2
  171. package/src/NavMenu/NavMenuElement.torp +2 -2
  172. package/src/NavMenu/NavMenuGroup.torp +2 -2
  173. package/src/NavMenu/NavMenuGroupHeader.torp +2 -2
  174. package/src/NavMenu/NavMenuLink.torp +2 -2
  175. package/src/NavMenu/NavMenuPopout.torp +2 -2
  176. package/src/NavMenu/NavMenuPopoutButton.torp +3 -3
  177. package/src/NavMenu/NavMenuPopoutContent.torp +29 -27
  178. package/src/NavMenu/NavMenuSeparator.torp +2 -2
  179. package/src/Notification/Notification.torp +48 -0
  180. package/src/Notification/NotificationClose.torp +28 -0
  181. package/src/Notification/NotificationContainer.torp +14 -0
  182. package/src/Notification/NotificationContent.torp +13 -0
  183. package/src/Notification/NotificationTypes.ts +5 -0
  184. package/src/Notification/index.ts +13 -0
  185. package/src/Notification/showNotification.ts +30 -0
  186. package/src/Popover/Popover.torp +2 -2
  187. package/src/Popover/PopoverContent.torp +31 -28
  188. package/src/Popover/PopoverContentAnchored.torp +39 -38
  189. package/src/Popover/PopoverContentContextual.torp +39 -36
  190. package/src/Popover/PopoverOverlay.torp +3 -3
  191. package/src/Popover/PopoverTrigger.torp +2 -2
  192. package/src/Popover/PopoverTriggerContextual.torp +2 -2
  193. package/src/Popover/PopoverTriggerHover.torp +3 -3
  194. package/src/Slider/Slider.torp +83 -0
  195. package/src/Slider/index.ts +3 -0
  196. package/src/TabGroup/TabContent.torp +2 -2
  197. package/src/TabGroup/TabGroup.torp +2 -2
  198. package/src/TabGroup/TabHeader.torp +2 -2
  199. package/src/TabGroup/TabList.torp +2 -2
  200. package/src/TabGroup/TabTrigger.torp +2 -2
  201. package/src/icons/ArrowDown.torp +15 -0
  202. package/src/icons/ArrowLeft.torp +15 -0
  203. package/src/icons/ArrowRight.torp +15 -0
  204. package/src/icons/ArrowUp.torp +15 -0
  205. package/src/icons/Bars.torp +17 -0
  206. package/src/icons/Check.torp +15 -0
  207. package/src/icons/ChevronDown.torp +15 -0
  208. package/src/icons/ChevronLeft.torp +15 -0
  209. package/src/icons/ChevronRight.torp +15 -0
  210. package/src/icons/ChevronUp.torp +15 -0
  211. package/src/icons/Cross.torp +16 -0
  212. package/src/icons/Loading.torp +16 -0
  213. package/src/icons/Minus.torp +15 -0
  214. package/src/icons/Plus.torp +16 -0
  215. package/src/icons/index.ts +31 -0
  216. package/src/motion/fade.ts +2 -2
  217. package/src/motion/index.ts +3 -0
  218. package/src/utils/dateUtils.ts +244 -0
  219. package/src/utils/setPopoverPosition.ts +4 -0
  220. package/test/Breadcrumb/accessibility.test.ts +29 -0
  221. package/test/Breadcrumb/basic.test.ts +17 -0
  222. package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
  223. package/test/Calendar/components/CalendarTest.torp +9 -0
  224. package/test/Calendar/default.test.ts +18 -0
  225. package/test/Dialog/components/DialogAccessibility.torp +5 -5
  226. package/test/Disclosure/accessibility.test.ts +30 -0
  227. package/test/Disclosure/components/DisclosureTest.torp +17 -0
  228. package/test/Disclosure/default.test.ts +15 -0
  229. package/test/Disclosure/toggle.test.ts +19 -0
  230. package/test/Menu/accessibility.test.ts +82 -0
  231. package/test/Menu/basic.test.ts +57 -0
  232. package/test/Menu/components/MenuAccessibility.torp +59 -0
  233. package/test/Menu/components/MenuBasic.torp +58 -0
  234. package/test/MenuBar/accessibility.test.ts +86 -0
  235. package/test/MenuBar/basic.test.ts +21 -0
  236. package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
  237. package/test/MenuBar/components/MenuBarBasic.torp +25 -0
  238. package/test/Notification/accessibility.test.ts +21 -0
  239. package/test/Notification/components/CustomNotification.torp +14 -0
  240. package/test/Notification/components/NotificationAccessibility.torp +14 -0
  241. package/test/Notification/components/NotificationFunction.torp +20 -0
  242. package/test/Notification/components/NotificationVariable.torp +22 -0
  243. package/test/Notification/function.test.ts +25 -0
  244. package/test/Notification/variable.test.ts +25 -0
  245. package/test/Popover/components/CustomDialog.torp +25 -0
  246. package/test/Popover/components/PromptFunction.torp +19 -0
  247. package/test/Popover/components/PromptVariable.torp +38 -0
  248. package/test/Popover/function.test.ts +26 -0
  249. package/test/Popover/variable.test.ts +27 -0
  250. package/tsup.config.ts +12 -4
  251. package/dist/Accordion/index.cjs +0 -53
  252. package/dist/Accordion/index.cjs.map +0 -1
  253. package/dist/Dialog/index.cjs +0 -53
  254. package/dist/Dialog/index.cjs.map +0 -1
  255. package/dist/NavMenu/index.cjs +0 -78
  256. package/dist/NavMenu/index.cjs.map +0 -1
  257. package/dist/Offscreen/index.cjs +0 -33
  258. package/dist/Offscreen/index.cjs.map +0 -1
  259. package/dist/Offscreen/index.js +0 -6
  260. package/dist/Popover/index.cjs +0 -222
  261. package/dist/Popover/index.cjs.map +0 -1
  262. package/dist/TabGroup/index.cjs +0 -53
  263. package/dist/TabGroup/index.cjs.map +0 -1
  264. package/dist/metafile-cjs.json +0 -1
  265. package/dist/motion.cjs +0 -34
  266. package/dist/motion.cjs.map +0 -1
  267. package/dist/motion.d.ts +0 -6
  268. package/dist/motion.js.map +0 -1
  269. package/src/Accordion.ts +0 -7
  270. package/src/Dialog.ts +0 -7
  271. package/src/NavMenu.ts +0 -23
  272. package/src/Offscreen/index.ts +0 -3
  273. package/src/Popover.ts +0 -29
  274. package/src/TabGroup.ts +0 -7
  275. package/src/motion.ts +0 -3
  276. /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
@@ -0,0 +1,86 @@
1
+ import {
2
+ type MenuRadioGroupContext,
3
+ MenuRadioGroupContextName,
4
+ type RadioGroupItemState
5
+ } from "./MenuTypes";
6
+
7
+ /**
8
+ * A container for a logical group of menu RadioGroup items.
9
+ *
10
+ * @prop {string} ariaLabel -- An ARIA label for describing the menu to screen readers
11
+ * @prop {string | undefined} value -- The value of the checked MenuRadio
12
+ * @prop {(any) => void} onchange - Called when the checked item has changed
13
+ */
14
+ export default function MenuRadioGroup() {
15
+ // A collection containing the state and some functions for each item
16
+ let itemStates: RadioGroupItemState[] = [];
17
+
18
+ // Set the context to pass down to items
19
+ let context: MenuRadioGroupContext = {
20
+ registerItemInGroup,
21
+ toggleItem
22
+ };
23
+ $context[MenuRadioGroupContextName] = context;
24
+
25
+ $mount(() => {
26
+ // Set the initial checked item
27
+ setValue($props.value);
28
+ });
29
+
30
+ function registerItemInGroup(itemValue: string, setChecked: (value: boolean) => void) {
31
+ // Add the item"s state to the array
32
+ const newItemState: RadioGroupItemState = {
33
+ value: itemValue,
34
+ checked: false,
35
+ setChecked
36
+ };
37
+ itemStates.push(newItemState);
38
+ itemStates = itemStates;
39
+ }
40
+
41
+ function setValue(newValue?: string) {
42
+ // No point doing this if there aren't any items yet (e.g. from the initial setValue() call)
43
+ if (!itemStates.length) {
44
+ return;
45
+ }
46
+
47
+ // Ensure the value passed in was a string (in case e.g. the user has set values to ints)
48
+ newValue = newValue?.toString();
49
+ for (let item of itemStates) {
50
+ item.checked = item.value === newValue;
51
+ item.setChecked(item.checked);
52
+ }
53
+
54
+ // Set the value
55
+ if ($props.value !== newValue) {
56
+ $props.value = newValue;
57
+
58
+ if ($props.onchange) {
59
+ $props.onchange($props.value);
60
+ }
61
+ }
62
+ }
63
+
64
+ function toggleItem(toggleValue: string) {
65
+ let newValue = "";
66
+ for (let item of itemStates) {
67
+ const checked = item.value === toggleValue;
68
+ item.setChecked(checked);
69
+ if (checked) {
70
+ newValue = item.value;
71
+ }
72
+ }
73
+ $props.value = newValue;
74
+ }
75
+
76
+ @render {
77
+ <div
78
+ {$props.id}
79
+ class={`torp-menu-radio-group ${$props.class ?? ""}`.trim()}
80
+ role="group"
81
+ aria-label={$props.ariaLabel}
82
+ >
83
+ <slot />
84
+ </div>
85
+ }
86
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * An element in a menu that separates logical sets of menu items.
3
+ */
4
+ export default function MenuSeparator() {
5
+ @render {
6
+ <div
7
+ {$props.id}
8
+ class={`torp-menu-separator ${$props.class ?? ""}`.trim()}
9
+ role="separator"
10
+ >
11
+ <slot />
12
+ </div>
13
+ }
14
+ }
@@ -0,0 +1,58 @@
1
+ export const MenuContextName = "Menu";
2
+ export const MenuButtonContextName = "MenuButton";
3
+ export const MenuRadioGroupContextName = "MenuRadioGroup";
4
+ export const MenuPopoutContextName = "MenuPopout";
5
+
6
+ export interface MenuContext {
7
+ setVisible: (value: boolean, result?: any) => void;
8
+
9
+ /** Called from a MenuButton to close the Menu and return a result */
10
+ handleTrigger: (type: "confirm" | "cancel" | undefined, value?: any) => void;
11
+
12
+ /** Called from a MenuButton when its button is focused */
13
+ handleItemFocus: (index: number) => void;
14
+
15
+ /** Called from a MenuButton when a key is pressed */
16
+ handleItemKey: (e: KeyboardEvent) => void;
17
+
18
+ state: {
19
+ /** Whether the Menu is visible. Writable so that it can be subscribed to by children */
20
+ visible: boolean;
21
+ };
22
+
23
+ /** The element that caused this Menu to be shown */
24
+ anchorElement?: HTMLElement;
25
+
26
+ /** Called from each MenuButton/Check/Radio to register itself with this Menu */
27
+ registerItem: (setFocused: () => void) => { index: number };
28
+ }
29
+
30
+ export interface MenuButtonContext {
31
+ state: {
32
+ checked: boolean;
33
+ };
34
+ }
35
+
36
+ export interface MenuRadioGroupContext {
37
+ registerItemInGroup: (value: string, setChecked: (value: boolean) => void) => void;
38
+ toggleItem: (value: string) => void;
39
+ }
40
+
41
+ export interface MenuPopoutContext {
42
+ setVisible: (value: boolean) => void;
43
+ state: {
44
+ visible: boolean;
45
+ };
46
+ anchorElement?: HTMLElement;
47
+ focusFirstElement?: () => void;
48
+ }
49
+
50
+ export interface ItemState {
51
+ setFocused: () => void;
52
+ }
53
+
54
+ export interface RadioGroupItemState {
55
+ value: string;
56
+ checked: boolean;
57
+ setChecked: (value: boolean) => void;
58
+ }
@@ -0,0 +1,200 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ /**
5
+ * Mounts or hydrates the component into the supplied parent node.
6
+ * @param $parent -- The parent node.
7
+ * @param $anchor -- The node to mount the component before.
8
+ * @param $props -- The values that have been passed into the component as properties.
9
+ * @param $context -- Values that have been passed into the component from its ancestors.
10
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
11
+ */
12
+ declare function Menu(
13
+ $parent: ParentNode,
14
+ $anchor: Node | null,
15
+ $props?: Record<PropertyKey, any>,
16
+ $context?: Record<PropertyKey, any>,
17
+ $slots?: Record<string, SlotRender>,
18
+ ): void;
19
+
20
+
21
+
22
+ /**
23
+ * Mounts or hydrates the component into the supplied parent node.
24
+ * @param $parent -- The parent node.
25
+ * @param $anchor -- The node to mount the component before.
26
+ * @param $props -- The values that have been passed into the component as properties.
27
+ * @param $context -- Values that have been passed into the component from its ancestors.
28
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
29
+ */
30
+ declare function MenuButton(
31
+ $parent: ParentNode,
32
+ $anchor: Node | null,
33
+ $props?: Record<PropertyKey, any>,
34
+ $context?: Record<PropertyKey, any>,
35
+ $slots?: Record<string, SlotRender>,
36
+ ): void;
37
+
38
+
39
+
40
+ /**
41
+ * Mounts or hydrates the component into the supplied parent node.
42
+ * @param $parent -- The parent node.
43
+ * @param $anchor -- The node to mount the component before.
44
+ * @param $props -- The values that have been passed into the component as properties.
45
+ * @param $context -- Values that have been passed into the component from its ancestors.
46
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
47
+ */
48
+ declare function MenuCheck(
49
+ $parent: ParentNode,
50
+ $anchor: Node | null,
51
+ $props?: Record<PropertyKey, any>,
52
+ $context?: Record<PropertyKey, any>,
53
+ $slots?: Record<string, SlotRender>,
54
+ ): void;
55
+
56
+
57
+
58
+ /**
59
+ * Mounts or hydrates the component into the supplied parent node.
60
+ * @param $parent -- The parent node.
61
+ * @param $anchor -- The node to mount the component before.
62
+ * @param $props -- The values that have been passed into the component as properties.
63
+ * @param $context -- Values that have been passed into the component from its ancestors.
64
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
65
+ */
66
+ declare function MenuGroup(
67
+ $parent: ParentNode,
68
+ $anchor: Node | null,
69
+ $props?: Record<PropertyKey, any>,
70
+ $context?: Record<PropertyKey, any>,
71
+ $slots?: Record<string, SlotRender>,
72
+ ): void;
73
+
74
+
75
+
76
+ /**
77
+ * Mounts or hydrates the component into the supplied parent node.
78
+ * @param $parent -- The parent node.
79
+ * @param $anchor -- The node to mount the component before.
80
+ * @param $props -- The values that have been passed into the component as properties.
81
+ * @param $context -- Values that have been passed into the component from its ancestors.
82
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
83
+ */
84
+ declare function MenuIndicator(
85
+ $parent: ParentNode,
86
+ $anchor: Node | null,
87
+ $props?: Record<PropertyKey, any>,
88
+ $context?: Record<PropertyKey, any>,
89
+ $slots?: Record<string, SlotRender>,
90
+ ): void;
91
+
92
+
93
+
94
+ /**
95
+ * Mounts or hydrates the component into the supplied parent node.
96
+ * @param $parent -- The parent node.
97
+ * @param $anchor -- The node to mount the component before.
98
+ * @param $props -- The values that have been passed into the component as properties.
99
+ * @param $context -- Values that have been passed into the component from its ancestors.
100
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
101
+ */
102
+ declare function MenuPopout(
103
+ $parent: ParentNode,
104
+ $anchor: Node | null,
105
+ $props,
106
+ $context?: Record<PropertyKey, any>,
107
+ $slots?: Record<string, SlotRender>,
108
+ ): void;
109
+
110
+
111
+
112
+ /**
113
+ * Mounts or hydrates the component into the supplied parent node.
114
+ * @param $parent -- The parent node.
115
+ * @param $anchor -- The node to mount the component before.
116
+ * @param $props -- The values that have been passed into the component as properties.
117
+ * @param $context -- Values that have been passed into the component from its ancestors.
118
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
119
+ */
120
+ declare function MenuPopoutContent(
121
+ $parent: ParentNode,
122
+ $anchor: Node | null,
123
+ $props?: Record<PropertyKey, any>,
124
+ $context?: Record<PropertyKey, any>,
125
+ $slots?: Record<string, SlotRender>,
126
+ ): void;
127
+
128
+
129
+
130
+ /**
131
+ * Mounts or hydrates the component into the supplied parent node.
132
+ * @param $parent -- The parent node.
133
+ * @param $anchor -- The node to mount the component before.
134
+ * @param $props -- The values that have been passed into the component as properties.
135
+ * @param $context -- Values that have been passed into the component from its ancestors.
136
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
137
+ */
138
+ declare function MenuPopoutTrigger(
139
+ $parent: ParentNode,
140
+ $anchor: Node | null,
141
+ $props?: Record<PropertyKey, any>,
142
+ $context?: Record<PropertyKey, any>,
143
+ $slots?: Record<string, SlotRender>,
144
+ ): void;
145
+
146
+
147
+
148
+ /**
149
+ * Mounts or hydrates the component into the supplied parent node.
150
+ * @param $parent -- The parent node.
151
+ * @param $anchor -- The node to mount the component before.
152
+ * @param $props -- The values that have been passed into the component as properties.
153
+ * @param $context -- Values that have been passed into the component from its ancestors.
154
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
155
+ */
156
+ declare function MenuRadio(
157
+ $parent: ParentNode,
158
+ $anchor: Node | null,
159
+ $props?: Record<PropertyKey, any>,
160
+ $context?: Record<PropertyKey, any>,
161
+ $slots?: Record<string, SlotRender>,
162
+ ): void;
163
+
164
+
165
+
166
+ /**
167
+ * Mounts or hydrates the component into the supplied parent node.
168
+ * @param $parent -- The parent node.
169
+ * @param $anchor -- The node to mount the component before.
170
+ * @param $props -- The values that have been passed into the component as properties.
171
+ * @param $context -- Values that have been passed into the component from its ancestors.
172
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
173
+ */
174
+ declare function MenuRadioGroup(
175
+ $parent: ParentNode,
176
+ $anchor: Node | null,
177
+ $props?: Record<PropertyKey, any>,
178
+ $context?: Record<PropertyKey, any>,
179
+ $slots?: Record<string, SlotRender>,
180
+ ): void;
181
+
182
+
183
+
184
+ /**
185
+ * Mounts or hydrates the component into the supplied parent node.
186
+ * @param $parent -- The parent node.
187
+ * @param $anchor -- The node to mount the component before.
188
+ * @param $props -- The values that have been passed into the component as properties.
189
+ * @param $context -- Values that have been passed into the component from its ancestors.
190
+ * @param $slots -- Functions for rendering children into slot nodes within the component.
191
+ */
192
+ declare function MenuSeparator(
193
+ $parent: ParentNode,
194
+ $anchor: Node | null,
195
+ $props?: Record<PropertyKey, any>,
196
+ $context?: Record<PropertyKey, any>,
197
+ $slots?: Record<string, SlotRender>,
198
+ ): void;
199
+
200
+ export { Menu, MenuButton, MenuCheck, MenuGroup, MenuIndicator, MenuPopout, MenuPopoutContent, MenuPopoutTrigger, MenuRadio, MenuRadioGroup, MenuSeparator };
@@ -0,0 +1,46 @@
1
+ // src/Menu/Menu.torp
2
+ import Menu_default from "./Menu.torp";
3
+
4
+ // src/Menu/MenuButton.torp
5
+ import MenuButton_default from "./MenuButton.torp";
6
+
7
+ // src/Menu/MenuCheck.torp
8
+ import MenuCheck_default from "./MenuCheck.torp";
9
+
10
+ // src/Menu/MenuGroup.torp
11
+ import MenuGroup_default from "./MenuGroup.torp";
12
+
13
+ // src/Menu/MenuIndicator.torp
14
+ import MenuIndicator_default from "./MenuIndicator.torp";
15
+
16
+ // src/Menu/MenuPopout.torp
17
+ import MenuPopout_default from "./MenuPopout.torp";
18
+
19
+ // src/Menu/MenuPopoutContent.torp
20
+ import MenuPopoutContent_default from "./MenuPopoutContent.torp";
21
+
22
+ // src/Menu/MenuPopoutTrigger.torp
23
+ import MenuPopoutTrigger_default from "./MenuPopoutTrigger.torp";
24
+
25
+ // src/Menu/MenuRadio.torp
26
+ import MenuRadio_default from "./MenuRadio.torp";
27
+
28
+ // src/Menu/MenuRadioGroup.torp
29
+ import MenuRadioGroup_default from "./MenuRadioGroup.torp";
30
+
31
+ // src/Menu/MenuSeparator.torp
32
+ import MenuSeparator_default from "./MenuSeparator.torp";
33
+ export {
34
+ Menu_default as Menu,
35
+ MenuButton_default as MenuButton,
36
+ MenuCheck_default as MenuCheck,
37
+ MenuGroup_default as MenuGroup,
38
+ MenuIndicator_default as MenuIndicator,
39
+ MenuPopout_default as MenuPopout,
40
+ MenuPopoutContent_default as MenuPopoutContent,
41
+ MenuPopoutTrigger_default as MenuPopoutTrigger,
42
+ MenuRadio_default as MenuRadio,
43
+ MenuRadioGroup_default as MenuRadioGroup,
44
+ MenuSeparator_default as MenuSeparator
45
+ };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,150 @@
1
+ import { MenuBarContextName, type MenuBarContext, type ItemState } from "./MenuBarTypes";
2
+
3
+ /**
4
+ * A menu bar, similar to that shown at the top of Windows applications or at the top of the screen on Macs.
5
+ *
6
+ * See [the WAI ARIA guidelines for Menus](https://www.w3.org/WAI/ARIA/apg/patterns/menu/).
7
+ *
8
+ * The structure of a MenuBar is:
9
+ *
10
+ * ```
11
+ * <MenuBar>
12
+ * <MenuBarItem>
13
+ * <MenuBarItemTrigger />
14
+ * <MenuBarItemContent>
15
+ * <Menu />
16
+ * </MenuBarItemContent>
17
+ * </MenuBarItem>
18
+ * </MenuBar>
19
+ * ```
20
+ *
21
+ * @prop {string} ariaLabel -- An ARIA label for describing the menu to screen readers
22
+ * @prop {"horizontal" | "vertical"} orientation -- The orientation of the menu, which affects keyboard navigation
23
+ */
24
+ export default function MenuBar() {
25
+ $props.orientation ??= "horizontal";
26
+
27
+ let $state = $watch({
28
+ active: false,
29
+ });
30
+
31
+ // A collection containing the state and some functions for each item
32
+ let itemStates: ItemState[] = [];
33
+ let focusIndex = -1;
34
+
35
+ // Set the context to pass down to items
36
+ let context: MenuBarContext = {
37
+ handleItemShow,
38
+ handleButtonFocus,
39
+ handleButtonKey,
40
+ registerItem,
41
+ state: $state
42
+ };
43
+ $context[MenuBarContextName] = context;
44
+
45
+ function registerItem(setVisible: (value: boolean) => void, setFocused: () => void) {
46
+ // Add the item"s state to the array and return its index
47
+ const newItemState: ItemState = {
48
+ setVisible,
49
+ setFocused
50
+ };
51
+ itemStates.push(newItemState);
52
+ itemStates = itemStates;
53
+ return { index: itemStates.length - 1 };
54
+ }
55
+
56
+ function handleItemShow(index: number) {
57
+ // Make sure other items are hidden
58
+ itemStates.forEach((item, i) => {
59
+ if (i !== index) {
60
+ item.setVisible(false);
61
+ }
62
+ });
63
+ }
64
+
65
+ function handleButtonFocus(index: number) {
66
+ focusIndex = index;
67
+ }
68
+
69
+ function handleButtonKey(e: KeyboardEvent) {
70
+ switch (e.key) {
71
+ case "Right":
72
+ case "ArrowRight": {
73
+ if (orientation === "horizontal") {
74
+ e.preventDefault();
75
+ focusItem("next");
76
+ }
77
+ break;
78
+ }
79
+ case "Left":
80
+ case "ArrowLeft": {
81
+ if (orientation === "horizontal") {
82
+ e.preventDefault();
83
+ focusItem("previous");
84
+ }
85
+ break;
86
+ }
87
+ case "Down":
88
+ case "ArrowDown": {
89
+ if (orientation === "vertical") {
90
+ e.preventDefault();
91
+ focusItem("next");
92
+ }
93
+ break;
94
+ }
95
+ case "Up":
96
+ case "ArrowUp": {
97
+ if (orientation === "vertical") {
98
+ e.preventDefault();
99
+ focusItem("previous");
100
+ }
101
+ break;
102
+ }
103
+ case "Home": {
104
+ e.preventDefault();
105
+ focusItem("start");
106
+ break;
107
+ }
108
+ case "End": {
109
+ e.preventDefault();
110
+ focusItem("end");
111
+ break;
112
+ }
113
+ }
114
+ }
115
+
116
+ function focusItem(target: "start" | "previous" | "next" | "end") {
117
+ switch (target) {
118
+ case "start": {
119
+ focusIndex = 0;
120
+ break;
121
+ }
122
+ case "previous": {
123
+ focusIndex = Math.max(0, focusIndex - 1);
124
+ break;
125
+ }
126
+ case "next": {
127
+ focusIndex = Math.min(itemStates.length - 1, focusIndex + 1);
128
+ break;
129
+ }
130
+ case "end": {
131
+ focusIndex = itemStates.length - 1;
132
+ break;
133
+ }
134
+ }
135
+ itemStates[focusIndex]?.setFocused();
136
+ }
137
+
138
+ @render {
139
+ <div
140
+ {$props.id}
141
+ class={`torp-menu-bar ${$props.class ?? ""}`.trim()}
142
+ tabindex="-1"
143
+ role="menubar"
144
+ aria-label={$props.ariaLabel}
145
+ aria-orientation={$props.orientation}
146
+ >
147
+ <slot />
148
+ </div>
149
+ }
150
+ }
@@ -0,0 +1,104 @@
1
+ import {
2
+ MenuBarContextName,
3
+ MenuBarItemContextName,
4
+ type MenuBarContext,
5
+ type MenuBarItemContext
6
+ } from "./MenuBarTypes";
7
+ import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
8
+
9
+ /**
10
+ * A popout that is attached to a menubar button and can be used to show a submenu.
11
+ *
12
+ * The structure of a MenuBarItem is:
13
+ *
14
+ * ```
15
+ * <MenuBarItem>
16
+ * <MenuBarItemTrigger /> (optional)
17
+ * <MenuBarItemContent />
18
+ * </MenuBarItem>
19
+ * ```
20
+ *
21
+ * @prop {boolean} visible -- Whether the item is visible
22
+ * @prop {(boolean) => void} ontoggle -- Called when the item is opened or closed
23
+ * @prop {() => void} onopen -- Called when the item has opened
24
+ * @prop {() => void} onclose -- Called when the item has closed
25
+ */
26
+ export default function MenuBarItem() {
27
+ $props.visible ??= false;
28
+
29
+ let $state = $watch({
30
+ visible: $props.visible
31
+ });
32
+
33
+ let result: any;
34
+
35
+ // Get stuff out of the MenuBarContext
36
+ const menubarContext = $context[MenuBarContextName] as MenuBarContext;
37
+ if (!menubarContext) {
38
+ throw new Error("MenuBarItem must be contained within a MenuBar");
39
+ }
40
+ const { handleItemShow } = menubarContext;
41
+
42
+ // Set the context to pass down to items
43
+ let context: MenuBarItemContext = {
44
+ setVisible,
45
+ state: $state,
46
+ index: -1
47
+ };
48
+ $context[MenuBarItemContextName] = context;
49
+
50
+ // Set the context to pass down to items
51
+ let popoverContext: PopoverContext = {
52
+ setVisible,
53
+ handleButton,
54
+ modal: false,
55
+ state: $state,
56
+ //anchorElement: anchor,
57
+ };
58
+ $context[PopoverContextName] = popoverContext;
59
+
60
+ $mount(() => {
61
+ setVisible();
62
+ });
63
+
64
+ function setVisible(value: boolean) {
65
+ if (!value || menubarContext.state.active) {
66
+ $state.visible = value;
67
+ if (value) {
68
+ handleItemShow(context.index);
69
+ }
70
+ }
71
+ }
72
+
73
+ let firstToggle = true;
74
+ $run(() => {
75
+ const ontoggle = $props.ontoggle;
76
+ const onopen = $props.onopen;
77
+ const onclose = $props.onclose;
78
+ const visible = $state.visible;
79
+ if (firstToggle) {
80
+ firstToggle = false;
81
+ } else {
82
+ if (ontoggle) ontoggle(visible);
83
+ if (visible) {
84
+ if (onopen) onopen()
85
+ } else {
86
+ if (onclose) onclose(result);
87
+ }
88
+ }
89
+ });
90
+
91
+ function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
92
+ menubarContext.state.active = false;
93
+ setVisible(false);
94
+ }
95
+
96
+ @render {
97
+ <div
98
+ {$props.id}
99
+ class={`torp-menu-bar-item ${$props.class ?? ""}`.trim()}
100
+ >
101
+ <slot />
102
+ </div>
103
+ }
104
+ }