@torpor/ui 0.3.7 → 1.0.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 (346) hide show
  1. package/README.md +83 -7
  2. package/dist/Accordion/Accordion.torp +43 -165
  3. package/dist/Accordion/AccordionContent.torp +6 -6
  4. package/dist/Accordion/AccordionHeader.torp +7 -11
  5. package/dist/Accordion/AccordionItem.torp +24 -24
  6. package/dist/Accordion/AccordionTrigger.torp +17 -8
  7. package/dist/Accordion/AccordionTypes.ts +6 -6
  8. package/dist/Accordion/index.d.ts +23 -25
  9. package/dist/Accordion/index.js +6 -22
  10. package/dist/Breadcrumb/Breadcrumb.torp +12 -10
  11. package/dist/Breadcrumb/BreadcrumbItem.torp +6 -6
  12. package/dist/Breadcrumb/BreadcrumbList.torp +21 -0
  13. package/dist/Breadcrumb/BreadcrumbSeparator.torp +4 -4
  14. package/dist/Breadcrumb/index.d.ts +39 -15
  15. package/dist/Breadcrumb/index.js +5 -14
  16. package/dist/Calendar/Calendar.torp +163 -156
  17. package/dist/Calendar/CalendarDay.torp +91 -45
  18. package/dist/Calendar/CalendarDayHeader.torp +36 -0
  19. package/dist/Calendar/CalendarGrid.torp +104 -0
  20. package/dist/Calendar/CalendarGridHeader.torp +43 -0
  21. package/dist/Calendar/CalendarHeader.torp +48 -0
  22. package/dist/Calendar/CalendarHeaderTrigger.torp +54 -0
  23. package/dist/Calendar/CalendarTypes.ts +25 -4
  24. package/dist/Calendar/buildDays.ts +54 -0
  25. package/dist/Calendar/index.d.ts +191 -5
  26. package/dist/Calendar/index.js +8 -10
  27. package/dist/Carousel/Carousel.torp +180 -0
  28. package/dist/Carousel/CarouselIndicators.torp +65 -0
  29. package/dist/Carousel/CarouselNext.torp +43 -0
  30. package/dist/Carousel/CarouselPrevious.torp +44 -0
  31. package/dist/Carousel/CarouselSlide.torp +57 -0
  32. package/dist/Carousel/CarouselTypes.ts +28 -0
  33. package/dist/Carousel/index.d.ts +147 -0
  34. package/dist/Carousel/index.js +6 -0
  35. package/dist/Charts/BarChart.torp +70 -0
  36. package/dist/Charts/Chart.torp +120 -0
  37. package/dist/Charts/ChartBars.torp +78 -0
  38. package/dist/Charts/ChartColumns.torp +66 -0
  39. package/dist/Charts/ChartGrid.torp +54 -0
  40. package/dist/Charts/ChartLines.torp +60 -0
  41. package/dist/Charts/ChartTypes.ts +25 -0
  42. package/dist/Charts/ChartXAxis.torp +83 -0
  43. package/dist/Charts/ChartYAxis.torp +105 -0
  44. package/dist/Charts/ColumnChart.torp +70 -0
  45. package/dist/{Chart → Charts}/GridLines.torp +7 -4
  46. package/dist/Charts/LineChart.torp +73 -0
  47. package/dist/{Chart → Charts}/PieChart.torp +14 -20
  48. package/dist/{Chart → Charts}/ScatterChart.torp +45 -38
  49. package/dist/{Chart → Charts}/SparkLine.torp +16 -19
  50. package/dist/{Chart → Charts}/XAxis.torp +18 -12
  51. package/dist/{Chart → Charts}/YAxis.torp +15 -9
  52. package/dist/Charts/index.d.ts +469 -0
  53. package/dist/Charts/index.js +17 -0
  54. package/dist/ColorPicker/ColorPalette.torp +154 -0
  55. package/dist/ColorPicker/ColorPicker.torp +157 -0
  56. package/dist/ColorPicker/index.d.ts +85 -0
  57. package/dist/ColorPicker/index.js +3 -0
  58. package/dist/ComboBox/ComboBox.torp +205 -0
  59. package/dist/ComboBox/ComboBoxContent.torp +112 -0
  60. package/dist/ComboBox/ComboBoxInput.torp +145 -0
  61. package/dist/ComboBox/ComboBoxTrigger.torp +49 -0
  62. package/dist/ComboBox/ComboBoxTypes.ts +39 -0
  63. package/dist/ComboBox/index.d.ts +152 -0
  64. package/dist/ComboBox/index.js +6 -0
  65. package/dist/CommandPalette/CommandPalette.torp +220 -0
  66. package/dist/CommandPalette/CommandTypes.ts +14 -0
  67. package/dist/CommandPalette/index.d.ts +45 -0
  68. package/dist/CommandPalette/index.js +2 -0
  69. package/dist/Contextual/Contextual.torp +39 -52
  70. package/dist/Contextual/ContextualContent.torp +29 -73
  71. package/dist/Contextual/ContextualHover.torp +112 -0
  72. package/dist/Contextual/ContextualTrigger.torp +31 -42
  73. package/dist/Contextual/ContextualTypes.ts +5 -18
  74. package/dist/Contextual/index.d.ts +44 -27
  75. package/dist/Contextual/index.js +5 -14
  76. package/dist/DataGrid/DataGrid.torp +496 -0
  77. package/dist/DataGrid/DataGridTypes.ts +25 -0
  78. package/dist/DataGrid/index.d.ts +90 -0
  79. package/dist/DataGrid/index.js +3 -0
  80. package/dist/DataGrid/sortRows.ts +32 -0
  81. package/dist/DatePicker/DatePicker.torp +222 -0
  82. package/dist/DatePicker/DatePickerHeader.torp +20 -0
  83. package/dist/DatePicker/index.d.ts +55 -0
  84. package/dist/DatePicker/index.js +2 -0
  85. package/dist/DateRangePicker/DateRangePicker.torp +311 -0
  86. package/dist/DateRangePicker/DateRangePickerDay.torp +137 -0
  87. package/dist/DateRangePicker/DateRangePickerTypes.ts +21 -0
  88. package/dist/DateRangePicker/index.d.ts +76 -0
  89. package/dist/DateRangePicker/index.js +3 -0
  90. package/dist/Dialog/Dialog.torp +33 -30
  91. package/dist/Dialog/DialogBody.torp +5 -9
  92. package/dist/Dialog/DialogButton.torp +14 -11
  93. package/dist/Dialog/DialogFooter.torp +3 -7
  94. package/dist/Dialog/DialogHeader.torp +6 -10
  95. package/dist/Dialog/DialogTypes.ts +2 -2
  96. package/dist/Dialog/index.d.ts +28 -26
  97. package/dist/Dialog/index.js +6 -22
  98. package/dist/Disclosure/Disclosure.torp +18 -18
  99. package/dist/Disclosure/DisclosureContent.torp +5 -6
  100. package/dist/Disclosure/DisclosureHeader.torp +7 -11
  101. package/dist/Disclosure/DisclosureTrigger.torp +4 -5
  102. package/dist/Disclosure/DisclosureTypes.ts +1 -1
  103. package/dist/Disclosure/index.d.ts +14 -16
  104. package/dist/Disclosure/index.js +5 -18
  105. package/dist/Drawer/Drawer.torp +21 -51
  106. package/dist/Drawer/DrawerContent.torp +67 -13
  107. package/dist/Drawer/DrawerOverlay.torp +4 -4
  108. package/dist/Drawer/DrawerTrigger.torp +16 -4
  109. package/dist/Drawer/DrawerTypes.ts +4 -1
  110. package/dist/Drawer/index.d.ts +16 -20
  111. package/dist/Drawer/index.js +5 -18
  112. package/dist/FocusGroup/FocusGroup.torp +70 -0
  113. package/dist/FocusGroup/FocusGroupButton.torp +59 -0
  114. package/dist/FocusGroup/FocusGroupTypes.ts +14 -0
  115. package/dist/FocusGroup/index.d.ts +44 -0
  116. package/dist/FocusGroup/index.js +3 -0
  117. package/dist/Form/CheckBox.torp +28 -20
  118. package/dist/Form/Field.torp +17 -17
  119. package/dist/Form/File.torp +31 -22
  120. package/dist/Form/FileDrop.torp +187 -0
  121. package/dist/Form/Form.torp +24 -22
  122. package/dist/Form/FormTypes.ts +2 -0
  123. package/dist/Form/FormValues.torp +37 -0
  124. package/dist/Form/Hidden.torp +4 -12
  125. package/dist/Form/Input.torp +38 -32
  126. package/dist/Form/Label.torp +3 -3
  127. package/dist/Form/Message.torp +13 -5
  128. package/dist/Form/MessageSummary.torp +39 -0
  129. package/dist/Form/Option.torp +11 -7
  130. package/dist/Form/Select.torp +32 -28
  131. package/dist/Form/TextArea.torp +35 -31
  132. package/dist/Form/Toggle.torp +109 -0
  133. package/dist/Form/index.d.ts +198 -77
  134. package/dist/Form/index.js +16 -46
  135. package/dist/ListBox/ListBox.torp +374 -0
  136. package/dist/ListBox/ListBoxItem.torp +131 -0
  137. package/dist/ListBox/ListBoxSeparator.torp +29 -0
  138. package/dist/ListBox/ListBoxTypes.ts +41 -0
  139. package/dist/ListBox/LoadedListBoxItems.torp +41 -0
  140. package/dist/ListBox/index.d.ts +136 -0
  141. package/dist/ListBox/index.js +4 -0
  142. package/dist/MaskedInput/MaskedInput.torp +143 -0
  143. package/dist/MaskedInput/index.d.ts +52 -0
  144. package/dist/MaskedInput/index.js +2 -0
  145. package/dist/Menu/Menu.torp +90 -70
  146. package/dist/Menu/MenuButton.torp +17 -10
  147. package/dist/Menu/MenuCheck.torp +22 -18
  148. package/dist/Menu/MenuGroup.torp +4 -4
  149. package/dist/Menu/MenuIndicator.torp +5 -13
  150. package/dist/Menu/MenuPopout.torp +20 -50
  151. package/dist/Menu/MenuPopoutContent.torp +15 -66
  152. package/dist/Menu/MenuPopoutTrigger.torp +19 -100
  153. package/dist/Menu/MenuRadio.torp +25 -26
  154. package/dist/Menu/MenuRadioGroup.torp +25 -68
  155. package/dist/Menu/MenuSeparator.torp +3 -2
  156. package/dist/Menu/MenuTypes.ts +12 -21
  157. package/dist/Menu/index.d.ts +45 -51
  158. package/dist/Menu/index.js +12 -46
  159. package/dist/MenuBar/MenuBar.torp +31 -83
  160. package/dist/MenuBar/MenuBarItem.torp +34 -55
  161. package/dist/MenuBar/MenuBarItemContent.torp +15 -101
  162. package/dist/MenuBar/MenuBarItemTrigger.torp +20 -55
  163. package/dist/MenuBar/MenuBarTypes.ts +13 -12
  164. package/dist/MenuBar/index.d.ts +17 -19
  165. package/dist/MenuBar/index.js +5 -18
  166. package/dist/Modal/Modal.torp +28 -48
  167. package/dist/Modal/ModalContent.torp +21 -44
  168. package/dist/Modal/ModalOverlay.torp +4 -4
  169. package/dist/Modal/ModalTrigger.torp +16 -32
  170. package/dist/Modal/ModalTypes.ts +6 -17
  171. package/dist/Modal/index.d.ts +17 -29
  172. package/dist/Modal/index.js +29 -28
  173. package/dist/Modal/index.js.map +1 -1
  174. package/dist/Modal/showPrompt.ts +2 -2
  175. package/dist/NavMenu/NavMenu.torp +22 -104
  176. package/dist/NavMenu/NavMenuButton.torp +10 -8
  177. package/dist/NavMenu/NavMenuElement.torp +6 -7
  178. package/dist/NavMenu/NavMenuGroup.torp +5 -5
  179. package/dist/NavMenu/NavMenuGroupHeader.torp +5 -8
  180. package/dist/NavMenu/NavMenuLink.torp +7 -10
  181. package/dist/NavMenu/NavMenuPopout.torp +16 -61
  182. package/dist/NavMenu/NavMenuPopoutContent.torp +14 -73
  183. package/dist/NavMenu/NavMenuPopoutTrigger.torp +47 -0
  184. package/dist/NavMenu/NavMenuSeparator.torp +3 -6
  185. package/dist/NavMenu/NavMenuTypes.ts +6 -15
  186. package/dist/NavMenu/index.d.ts +55 -55
  187. package/dist/NavMenu/index.js +11 -42
  188. package/dist/Notification/Notification.torp +12 -24
  189. package/dist/Notification/NotificationClose.torp +6 -3
  190. package/dist/Notification/NotificationContainer.torp +3 -7
  191. package/dist/Notification/NotificationContent.torp +3 -7
  192. package/dist/Notification/NotificationTypes.ts +1 -1
  193. package/dist/Notification/index.d.ts +15 -12
  194. package/dist/Notification/index.js +22 -32
  195. package/dist/Notification/index.js.map +1 -1
  196. package/dist/NumberInput/NumberInput.torp +255 -0
  197. package/dist/NumberInput/index.d.ts +44 -0
  198. package/dist/NumberInput/index.js +2 -0
  199. package/dist/Pagination/Pagination.torp +152 -0
  200. package/dist/Pagination/PaginationItem.torp +137 -0
  201. package/dist/Pagination/PaginationTypes.ts +22 -0
  202. package/dist/Pagination/buildPages.ts +61 -0
  203. package/dist/Pagination/index.d.ts +63 -0
  204. package/dist/Pagination/index.js +3 -0
  205. package/dist/Popover/Popover.torp +39 -52
  206. package/dist/Popover/PopoverContent.torp +27 -76
  207. package/dist/Popover/PopoverHover.torp +90 -0
  208. package/dist/Popover/PopoverTrigger.torp +17 -40
  209. package/dist/Popover/PopoverTypes.ts +5 -18
  210. package/dist/Popover/index.d.ts +40 -25
  211. package/dist/Popover/index.js +18 -18
  212. package/dist/Popover/index.js.map +1 -1
  213. package/dist/Progress/Progress.torp +88 -0
  214. package/dist/Progress/index.d.ts +37 -0
  215. package/dist/Progress/index.js +2 -0
  216. package/dist/Rating/Rating.torp +225 -0
  217. package/dist/Rating/index.d.ts +44 -0
  218. package/dist/Rating/index.js +2 -0
  219. package/dist/SegmentedControl/SegmentedControl.torp +233 -0
  220. package/dist/SegmentedControl/SegmentedControlTypes.ts +26 -0
  221. package/dist/SegmentedControl/SegmentedItem.torp +78 -0
  222. package/dist/SegmentedControl/index.d.ts +74 -0
  223. package/dist/SegmentedControl/index.js +3 -0
  224. package/dist/SelectBox/SelectBox.torp +190 -0
  225. package/dist/SelectBox/SelectBoxContent.torp +107 -0
  226. package/dist/SelectBox/SelectBoxTrigger.torp +141 -0
  227. package/dist/SelectBox/SelectBoxTypes.ts +33 -0
  228. package/dist/SelectBox/index.d.ts +112 -0
  229. package/dist/SelectBox/index.js +5 -0
  230. package/dist/Slider/Slider.torp +248 -0
  231. package/dist/Slider/index.d.ts +45 -0
  232. package/dist/Slider/index.js +2 -0
  233. package/dist/Splitter/Splitter.torp +156 -0
  234. package/dist/Splitter/SplitterHandle.torp +161 -0
  235. package/dist/Splitter/SplitterPane.torp +63 -0
  236. package/dist/Splitter/SplitterTypes.ts +31 -0
  237. package/dist/Splitter/index.d.ts +103 -0
  238. package/dist/Splitter/index.js +4 -0
  239. package/dist/Stepper/Stepper.torp +146 -0
  240. package/dist/Stepper/StepperMarker.torp +24 -0
  241. package/dist/Stepper/StepperNext.torp +44 -0
  242. package/dist/Stepper/StepperPrevious.torp +44 -0
  243. package/dist/Stepper/StepperStep.torp +90 -0
  244. package/dist/Stepper/StepperTypes.ts +30 -0
  245. package/dist/Stepper/index.d.ts +149 -0
  246. package/dist/Stepper/index.js +6 -0
  247. package/dist/TabGroup/TabContent.torp +6 -6
  248. package/dist/TabGroup/TabGroup.torp +97 -113
  249. package/dist/TabGroup/TabGroupTypes.ts +3 -3
  250. package/dist/TabGroup/TabHeader.torp +23 -19
  251. package/dist/TabGroup/TabList.torp +8 -21
  252. package/dist/TabGroup/TabTrigger.torp +6 -7
  253. package/dist/TabGroup/index.d.ts +26 -26
  254. package/dist/TabGroup/index.js +6 -22
  255. package/dist/TagInput/TagInput.torp +378 -0
  256. package/dist/TagInput/index.d.ts +48 -0
  257. package/dist/TagInput/index.js +2 -0
  258. package/dist/TimePicker/TimePicker.torp +462 -0
  259. package/dist/TimePicker/index.d.ts +53 -0
  260. package/dist/TimePicker/index.js +2 -0
  261. package/dist/ToolBar/ToolBar.torp +117 -0
  262. package/dist/ToolBar/ToolBarButton.torp +56 -0
  263. package/dist/ToolBar/ToolBarElement.torp +51 -0
  264. package/dist/ToolBar/ToolBarPopout.torp +45 -0
  265. package/dist/ToolBar/ToolBarPopoutContent.torp +34 -0
  266. package/dist/ToolBar/ToolBarPopoutTrigger.torp +47 -0
  267. package/dist/ToolBar/ToolBarSeparator.torp +21 -0
  268. package/dist/ToolBar/ToolBarTypes.ts +28 -0
  269. package/dist/ToolBar/index.d.ts +210 -0
  270. package/dist/ToolBar/index.js +8 -0
  271. package/dist/Tree/Tree.torp +395 -0
  272. package/dist/Tree/TreeItem.torp +176 -0
  273. package/dist/Tree/TreeItemChildren.torp +60 -0
  274. package/dist/Tree/TreeItemContent.torp +46 -0
  275. package/dist/Tree/TreeItemLabel.torp +94 -0
  276. package/dist/Tree/TreeItemTrigger.torp +78 -0
  277. package/dist/Tree/TreeLoadedChildren.torp +122 -0
  278. package/dist/Tree/TreeTypes.ts +63 -0
  279. package/dist/Tree/index.d.ts +262 -0
  280. package/dist/Tree/index.js +7 -0
  281. package/dist/icons/ChevronDoubleLeft.torp +19 -0
  282. package/dist/icons/ChevronDoubleRight.torp +19 -0
  283. package/dist/icons/index.d.ts +61 -1
  284. package/dist/icons/index.js +17 -58
  285. package/dist/loader-DEeG5vFY.js +44 -0
  286. package/dist/loader-DEeG5vFY.js.map +1 -0
  287. package/dist/motion/index.d.ts +12 -8
  288. package/dist/motion/index.d.ts.map +1 -0
  289. package/dist/motion/index.js +72 -88
  290. package/dist/motion/index.js.map +1 -1
  291. package/dist/mount/draggable.ts +63 -0
  292. package/dist/mount/dropTarget.ts +108 -0
  293. package/dist/mount/hoverTrigger.ts +1 -1
  294. package/dist/utils/$handle.ts +23 -0
  295. package/dist/utils/LoadedItems.torp +47 -0
  296. package/dist/utils/PopoutClickTrigger.torp +99 -0
  297. package/dist/utils/PopoutTypes.ts +82 -0
  298. package/dist/utils/SubmenuPopout.torp +89 -0
  299. package/dist/utils/SubmenuPopoutContent.torp +87 -0
  300. package/dist/utils/SubmenuPopoutTrigger.torp +160 -0
  301. package/dist/utils/chartColors.ts +13 -13
  302. package/dist/utils/chartLayout.ts +143 -0
  303. package/dist/utils/chartUtils.ts +1 -1
  304. package/dist/utils/colorUtils.ts +103 -0
  305. package/dist/utils/createItemGroup.ts +152 -0
  306. package/dist/utils/dateUtils.ts +8 -7
  307. package/dist/utils/documentEvents.ts +4 -4
  308. package/dist/utils/dragState.ts +86 -0
  309. package/dist/utils/focusGroup.ts +204 -0
  310. package/dist/utils/focusItem.ts +44 -0
  311. package/dist/utils/formField.ts +70 -0
  312. package/dist/utils/hoverOpen.ts +50 -0
  313. package/dist/utils/hoverReveal.ts +194 -0
  314. package/dist/utils/loader.ts +113 -0
  315. package/dist/utils/maskUtils.ts +98 -0
  316. package/dist/utils/popoutContent.ts +137 -0
  317. package/dist/utils/reorderList.ts +52 -0
  318. package/package.json +116 -25
  319. package/dist/Accordion/index.js.map +0 -1
  320. package/dist/Breadcrumb/index.js.map +0 -1
  321. package/dist/Calendar/index.js.map +0 -1
  322. package/dist/Chart/BarChart.torp +0 -159
  323. package/dist/Chart/LineChart.torp +0 -196
  324. package/dist/Chart/index.d.ts +0 -220
  325. package/dist/Chart/index.js +0 -34
  326. package/dist/Chart/index.js.map +0 -1
  327. package/dist/Contextual/index.js.map +0 -1
  328. package/dist/Dialog/index.js.map +0 -1
  329. package/dist/Disclosure/index.js.map +0 -1
  330. package/dist/Drawer/index.js.map +0 -1
  331. package/dist/Form/index.js.map +0 -1
  332. package/dist/Menu/index.js.map +0 -1
  333. package/dist/MenuBar/index.js.map +0 -1
  334. package/dist/NavMenu/NavMenuPopoutButton.torp +0 -129
  335. package/dist/NavMenu/index.js.map +0 -1
  336. package/dist/TabGroup/index.js.map +0 -1
  337. package/dist/icons/index.js.map +0 -1
  338. package/dist/index.d.ts +0 -19
  339. package/dist/metafile-esm.json +0 -1
  340. package/dist/motion/fade.ts +0 -16
  341. package/dist/motion/grow.ts +0 -23
  342. package/dist/motion/measure.ts +0 -28
  343. package/dist/motion/slide.ts +0 -45
  344. package/dist/mount/index.d.ts +0 -2
  345. package/dist/utils/index.d.ts +0 -2
  346. /package/dist/{Chart → Charts}/DataSeries.ts +0 -0
@@ -1,24 +1,22 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
3
- import { ModalContextName, type ModalContext } from "./ModalTypes";
2
+ import getId from "../utils/getId";
3
+ import { createPopoutContent } from "../utils/popoutContent";
4
+ import { type ModalContext, ModalContextName } from "./ModalTypes";
4
5
 
5
6
  interface ModalContentProps {
6
7
  /** An ID for the root element */
7
8
  id?: string;
8
9
  /** Classes for the root element */
9
- class?: ClassValue,
10
+ class?: ClassValue;
10
11
  /** Styles for the root element */
11
- style?: StyleValue,
12
+ style?: StyleValue;
12
13
  }
13
14
 
14
15
  /**
15
- * The content that is displayed for a Modal when it is open, displayed
16
- * alongside an element.
16
+ * The content that is displayed for a Modal when it is open.
17
17
  */
18
18
  export default function ModalContent($props: ModalContentProps | undefined) {
19
- let div: HTMLDivElement;
20
- let shown = false;
21
- let closeOnClick = false;
19
+ let defaultId = getId();
22
20
 
23
21
  // Get stuff out of the ModalContext
24
22
  const context = $context[ModalContextName] as ModalContext;
@@ -27,52 +25,31 @@ export default function ModalContent($props: ModalContentProps | undefined) {
27
25
  }
28
26
  let $state = context.state;
29
27
 
30
- $run(() => {
31
- if (!$state.visible) {
32
- hide();
33
- }
34
- });
35
-
36
- function show() {
37
- shown = true;
38
-
39
- // HACK: Because this Modal could be shown with a click, we need to wait for another mousedown
40
- // before we close on click. Otherwise the click immediately bubbles to the document
41
- closeOnClick = false;
42
- addDocumentEvent("mousedown", handleDocumentMouseDown);
43
- addDocumentEvent("click", handleDocumentClick);
44
- }
45
-
46
- function hide() {
47
- if (!shown) return;
28
+ // Set the content ID so that the trigger can use it with aria-controls
29
+ $state.contentId = $props?.id ?? defaultId;
48
30
 
49
- removeDocumentEvent("mousedown", handleDocumentMouseDown);
50
- removeDocumentEvent("click", handleDocumentClick);
51
- }
31
+ const popout = createPopoutContent({
32
+ getAnchor: () => undefined,
33
+ getContent: () => div,
34
+ close: (e) => context.handleClickOutside?.(e),
35
+ });
52
36
 
53
- function handleDocumentMouseDown() {
54
- closeOnClick = true;
55
- }
37
+ let div: HTMLDivElement;
56
38
 
57
- function handleDocumentClick(e: MouseEvent) {
58
- if (
59
- closeOnClick &&
60
- div &&
61
- !div.contains(e.target as HTMLElement)
62
- ) {
63
- e.preventDefault();
64
- context.handleClickOutside!(e);
39
+ $run(() => {
40
+ if (!$state.visible) {
41
+ popout.hide();
65
42
  }
66
- }
43
+ });
67
44
 
68
45
  @render {
69
46
  @if ($state.visible) {
70
47
  <div
71
- {$props?.id}
48
+ id={$props?.id ?? defaultId}
72
49
  class={["torp-modal-content", $props?.class]}
73
50
  {$props?.style}
74
51
  &ref={div}
75
- onmount={show}
52
+ onmount={(_el) => popout.show()}
76
53
  >
77
54
  <slot />
78
55
  </div>
@@ -1,14 +1,14 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
2
  import { disableScroll } from "../mount/disableScroll";
3
- import { ModalContextName, type ModalContext } from "./ModalTypes";
3
+ import { type ModalContext, ModalContextName } from "./ModalTypes";
4
4
 
5
5
  interface ModalOverlayProps {
6
6
  /** An ID for the root element */
7
7
  id?: string;
8
8
  /** Classes for the root element */
9
- class?: ClassValue,
9
+ class?: ClassValue;
10
10
  /** Styles for the root element */
11
- style?: StyleValue,
11
+ style?: StyleValue;
12
12
  }
13
13
 
14
14
  /**
@@ -33,7 +33,7 @@ export default function ModalOverlay($props: ModalOverlayProps | undefined) {
33
33
  class={["torp-modal-overlay", $props?.class]}
34
34
  {$props?.style}
35
35
  tabindex="-1"
36
- onmount={(el) => disableScroll(el)}
36
+ onmount={(_el) => disableScroll()}
37
37
  >
38
38
  <slot />
39
39
  </div>
@@ -1,54 +1,38 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { ModalContextName, type ModalContext } from "./ModalTypes";
3
- import hoverTrigger from "../mount/hoverTrigger";
2
+ import PopoutClickTrigger from "../utils/PopoutClickTrigger.torp";
3
+ import { type ModalContext, ModalContextName } from "./ModalTypes";
4
4
 
5
5
  interface ModalTriggerProps {
6
6
  /** An ID for the root element */
7
7
  id?: string;
8
8
  /** Classes for the root element */
9
- class?: ClassValue,
9
+ class?: ClassValue;
10
10
  /** Styles for the root element */
11
- style?: StyleValue,
12
- /** Whether the modal is activated by click/press or by hover **/
13
- activation?: "press" | "hover"
11
+ style?: StyleValue;
14
12
  }
15
13
 
16
14
  /**
17
- * The button that causes a Modal to appear or disappear.
15
+ * The button that opens a Modal when pressed.
16
+ *
17
+ * Modals require a deliberate act to open, so there is no hover activation.
18
18
  */
19
- export default function ModalTrigger($props: ModalTriggerProps | undefined) {
20
- let activation = $props?.activation ?? "press";
21
-
19
+ export default function ModalTrigger($props?: ModalTriggerProps) {
22
20
  // Get stuff out of the ModalContext
23
21
  const context = $context[ModalContextName] as ModalContext;
24
22
  if (!context) {
25
23
  throw new Error("ModalTrigger must be contained within a Modal");
26
24
  }
27
- let $state = context.state;
28
-
29
- function handleClick() {
30
- if (activation !== "press") return;
31
-
32
- $state.visible = !$state.visible;
33
- }
34
-
35
- function handleHover() {
36
- if (activation !== "hover") return;
37
-
38
- $state.visible = !$state.visible
39
- }
40
25
 
41
26
  @render {
42
- <button
43
- type="button"
44
- {$props?.id}
45
- class={["torp-modal-trigger", $props?.class]}
46
- {$props?.style}
47
- onclick={handleClick}
48
- onmount={(el) => hoverTrigger(el, { onHover: handleHover, onExit: handleHover })}
49
- &ref={context.anchorElement}
27
+ <PopoutClickTrigger
28
+ id={$props?.id}
29
+ class={$props?.class ?? "torp-modal-trigger"}
30
+ style={$props?.style}
31
+ context={context}
32
+ tag="button"
33
+ event="click"
50
34
  >
51
35
  <slot />
52
- </button>
36
+ </PopoutClickTrigger>
53
37
  }
54
38
  }
@@ -1,22 +1,11 @@
1
- export const ModalContextName = "Modal";
1
+ import { type PopoutContext, type PopoutState } from "../utils/PopoutTypes";
2
+
3
+ export const ModalContextName: unique symbol = Symbol.for("torp.Modal");
2
4
 
3
5
  /** The shared context for modal components (Contextual, Prompt and Modal) */
4
- export interface ModalContext {
5
- handleButton: (type: "confirm" | "cancel" | undefined, value?: any) => void;
6
- // HACK: We need to be able to let children (i.e. Dialogs) override the click outside functionality
7
- // There may be a more elegant way to accomplish this too
8
- handleClickOutside?: (e: MouseEvent) => void;
6
+ export interface ModalContext extends PopoutContext {
9
7
  state: ModalState;
10
- // HACK: focusFirstElement is necessary because if we focus the first element e.g. in a Dialog's
11
- // onMount, it will scroll the page to the focused element and mess up our careful positioning
12
- // We need to be able to manually set the order to
13
- // 1. set visible (so we have an element with content)
14
- // 2. set position (so the element is in the right place)
15
- // 3. set focus (for accessibility)
16
- // There may be a more elegant way to accomplish this!
17
- focusFirstElement?: () => void;
18
8
  }
19
9
 
20
- export interface ModalState {
21
- visible: boolean;
22
- }
10
+ /** A modal's state is exactly the shared popout state */
11
+ export type ModalState = PopoutState;
@@ -5,19 +5,15 @@ interface ModalProps {
5
5
  /** An ID for the root element */
6
6
  id?: string;
7
7
  /** Classes for the root element */
8
- class?: ClassValue,
8
+ class?: ClassValue;
9
9
  /** Styles for the root element */
10
- style?: StyleValue,
10
+ style?: StyleValue;
11
11
  /** Whether the modal is visible */
12
- visible?: boolean,
13
- /** A function to be called when the user selects a response */
14
- callback?: ((value: any) => void),
15
- /** Raised when the modal is opened or closed */
16
- ontoggle?: (open: boolean) => void,
12
+ visible: Bindable<boolean | undefined>;
17
13
  /** Raised when the modal has opened */
18
- onopen?: () => void,
14
+ onopen?: () => void;
19
15
  /** Raised when the modal has closed */
20
- onclose?: (result: any) => void,
16
+ onclose?: (result: any) => void;
21
17
  }
22
18
 
23
19
  /**
@@ -49,14 +45,13 @@ interface ModalContentProps {
49
45
  /** An ID for the root element */
50
46
  id?: string;
51
47
  /** Classes for the root element */
52
- class?: ClassValue,
48
+ class?: ClassValue;
53
49
  /** Styles for the root element */
54
- style?: StyleValue,
50
+ style?: StyleValue;
55
51
  }
56
52
 
57
53
  /**
58
- * The content that is displayed for a Modal when it is open, displayed
59
- * alongside an element.
54
+ * The content that is displayed for a Modal when it is open.
60
55
  */
61
56
  declare function ModalContent(
62
57
  $parent: ParentNode,
@@ -72,9 +67,9 @@ interface ModalOverlayProps {
72
67
  /** An ID for the root element */
73
68
  id?: string;
74
69
  /** Classes for the root element */
75
- class?: ClassValue,
70
+ class?: ClassValue;
76
71
  /** Styles for the root element */
77
- style?: StyleValue,
72
+ style?: StyleValue;
78
73
  }
79
74
 
80
75
  /**
@@ -91,26 +86,19 @@ declare function ModalOverlay(
91
86
 
92
87
 
93
88
 
94
- interface ModalTriggerProps {
95
- /** An ID for the root element */
96
- id?: string;
97
- /** Classes for the root element */
98
- class?: ClassValue,
99
- /** Styles for the root element */
100
- style?: StyleValue,
101
- /** Whether the modal is activated by click/press or by hover **/
102
- activation?: "press" | "hover"
103
- }
104
-
105
89
  /**
106
- * The button that causes a Modal to appear or disappear.
90
+ * The button that opens a Modal when pressed.
91
+ *
92
+ * Modals require a deliberate act to open, so there is no hover activation.
107
93
  */
108
94
  declare function ModalTrigger(
109
95
  $parent: ParentNode,
110
96
  $anchor: Node | null,
111
- $props: ModalTriggerProps | undefined,
97
+ $props?: ModalTriggerProps,
112
98
  $context?: Record<PropertyKey, any>,
113
99
  $slots?: Record<string, SlotRender>,
114
100
  ): void;
115
101
 
116
- export { Modal, ModalContent, ModalOverlay, ModalTrigger };
102
+ export { Modal, ModalContent, ModalOverlay, ModalTrigger };
103
+ export { default as showModal } from "./showModal";
104
+ export { default as showPrompt } from "./showPrompt";
@@ -1,33 +1,34 @@
1
- // src/Modal/Modal.torp
2
- import Modal_default from "./Modal.torp";
3
-
4
- // src/Modal/ModalContent.torp
5
- import ModalContent_default from "./ModalContent.torp";
6
-
7
- // src/Modal/ModalOverlay.torp
8
- import ModalOverlay_default from "./ModalOverlay.torp";
9
-
10
- // src/Modal/ModalTrigger.torp
11
- import ModalTrigger_default from "./ModalTrigger.torp";
12
-
13
- // src/Modal/showModal.ts
1
+ import Modal from "./Modal.torp";
2
+ import ModalContent from "./ModalContent.torp";
3
+ import ModalOverlay from "./ModalOverlay.torp";
4
+ import ModalTrigger from "./ModalTrigger.torp";
5
+ //#region src/Modal/showModal.ts
6
+ /**
7
+ * Shows a modal component in code.
8
+ * @param modal The modal component
9
+ * @param props The properties for the modal component
10
+ * @param target The target element to show the modal in
11
+ * @returns The value selected by the user
12
+ */
14
13
  function showModal(modal, props, target) {
15
- modal(target || document.body, null, props);
14
+ modal(target || document.body, null, props);
16
15
  }
17
-
18
- // src/Modal/showPrompt.ts
16
+ //#endregion
17
+ //#region src/Modal/showPrompt.ts
18
+ /**
19
+ * Shows a modal component in code, and asynchronously returns the value selected by the user.
20
+ * @param modal The modal component
21
+ * @param props The properties for the modal component
22
+ * @param target The target element to show the modal in
23
+ * @returns The value selected by the user
24
+ */
19
25
  function showPrompt(modal, props, target) {
20
- return new Promise((resolve) => {
21
- const allProps = Object.assign({}, props, { callback: resolve });
22
- modal(target || document.body, null, allProps);
23
- });
26
+ return new Promise((resolve) => {
27
+ const allProps = Object.assign({}, props, { onclose: resolve });
28
+ modal(target || document.body, null, allProps);
29
+ });
24
30
  }
25
- export {
26
- Modal_default as Modal,
27
- ModalContent_default as ModalContent,
28
- ModalOverlay_default as ModalOverlay,
29
- ModalTrigger_default as ModalTrigger,
30
- showModal,
31
- showPrompt
32
- };
31
+ //#endregion
32
+ export { Modal, ModalContent, ModalOverlay, ModalTrigger, showModal, showPrompt };
33
+
33
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Modal/showModal.ts","../../src/Modal/showPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline modal\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showModal(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Create the modal\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tmodal(target || document.body, null, props);\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code, and asynchronously returns the value selected by the user.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showPrompt(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<any> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the callback\n\t\tconst allProps = Object.assign({}, props, { callback: resolve });\n\n\t\t// Create the modal\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tmodal(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAUe,SAAR,UACN,OACA,OACA,QACO;AAGP,QAAM,UAAU,SAAS,MAAM,MAAM,KAAK;AAC3C;;;ACTe,SAAR,WACN,OACA,OACA,QACe;AACf,SAAO,IAAI,QAAQ,CAAC,YAAY;AAE/B,UAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,UAAU,QAAQ,CAAC;AAI/D,UAAM,UAAU,SAAS,MAAM,MAAM,QAAQ;AAAA,EAC9C,CAAC;AACF;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/Modal/showModal.ts","../../src/Modal/showPrompt.ts"],"sourcesContent":["// TODO: Allow passing in a variable -- so that you can show an inline modal\nimport type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showModal(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): void {\n\t// Create the modal\n\t// TODO: This needs to clean up after itself, like the mount methods do\n\tmodal(target || document.body, null, props);\n}\n","import type { Component } from \"@torpor/view\";\n\n/**\n * Shows a modal component in code, and asynchronously returns the value selected by the user.\n * @param modal The modal component\n * @param props The properties for the modal component\n * @param target The target element to show the modal in\n * @returns The value selected by the user\n */\nexport default function showPrompt(\n\tmodal: Component,\n\tprops?: Record<PropertyKey, any>,\n\ttarget?: Element,\n): Promise<any> {\n\treturn new Promise((resolve) => {\n\t\t// Add the promise as the onclose handler\n\t\tconst allProps = Object.assign({}, props, { onclose: resolve });\n\n\t\t// Create the modal\n\t\t// TODO: This needs to clean up after itself, like the use methods do\n\t\tmodal(target || document.body, null, allProps);\n\t});\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAwB,UACvB,OACA,OACA,QACO;CAGP,MAAM,UAAU,SAAS,MAAM,MAAM,KAAK;AAC3C;;;;;;;;;;ACTA,SAAwB,WACvB,OACA,OACA,QACe;CACf,OAAO,IAAI,SAAS,YAAY;EAE/B,MAAM,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO,EAAE,SAAS,QAAQ,CAAC;EAI9D,MAAM,UAAU,SAAS,MAAM,MAAM,QAAQ;CAC9C,CAAC;AACF"}
@@ -13,8 +13,8 @@ export default function showPrompt(
13
13
  target?: Element,
14
14
  ): Promise<any> {
15
15
  return new Promise((resolve) => {
16
- // Add the promise as the callback
17
- const allProps = Object.assign({}, props, { callback: resolve });
16
+ // Add the promise as the onclose handler
17
+ const allProps = Object.assign({}, props, { onclose: resolve });
18
18
 
19
19
  // Create the modal
20
20
  // TODO: This needs to clean up after itself, like the use methods do
@@ -1,23 +1,19 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import {
3
- NavMenuContextName,
4
- type NavMenuContext,
5
- type ItemState,
6
- NavMenuPopoutContextName,
7
- type NavMenuPopoutContext
8
- } from "./NavMenuTypes";
2
+ import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
3
+ import { createFocusGroup } from "../utils/focusGroup";
4
+ import { type ItemState, type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
9
5
 
10
6
  interface NavMenuProps {
11
7
  /** An ID for the root element */
12
8
  id?: string;
13
9
  /** Classes for the root element */
14
- class?: ClassValue,
10
+ class?: ClassValue;
15
11
  /** Styles for the root element */
16
- style?: StyleValue,
12
+ style?: StyleValue;
17
13
  /** An ARIA label for describing the menu to screen readers */
18
- ariaLabel?: string | undefined,
14
+ ariaLabel?: string | undefined;
19
15
  /** The orientation of the menu, which affects keyboard navigation */
20
- orientation?: "horizontal" | "vertical",
16
+ orientation?: "horizontal" | "vertical";
21
17
  }
22
18
 
23
19
  /**
@@ -39,139 +35,61 @@ interface NavMenuProps {
39
35
  export default function NavMenu($props: NavMenuProps | undefined) {
40
36
  let orientation = $props?.orientation ?? "horizontal";
41
37
 
42
- // A collection containing the state and some functions for each item
43
- let itemStates: ItemState[] = [];
44
- let focusIndex = -1;
38
+ // The focus group owns the item ledger and roving-tabindex bookkeeping
39
+ const group = createFocusGroup<ItemState>();
45
40
 
46
41
  // Check whether this is a menu in a popout
47
- const popoutContext = $context[NavMenuPopoutContextName] as NavMenuPopoutContext;
42
+ const popoutContext = $context[PopoutContextName] as PopoutContext;
48
43
  const inPopout = !!popoutContext;
49
44
  let popoutState = popoutContext?.state;
50
45
 
51
46
  // Set the focusFirstElement method in the PopoverContext(s) so that it can be called after everything has been shown
52
47
  if (popoutContext) {
53
- popoutContext.focusFirstElement = focusFirstElement;
48
+ popoutContext.focusFirstElement = group.focusFirstItem;
49
+ popoutContext.focusLastElement = group.focusLastItem;
54
50
  }
55
51
 
56
52
  // Set the context to pass down to items
57
53
  let context: NavMenuContext = {
58
54
  handleItemFocus,
59
55
  handleItemKey,
60
- registerItem
56
+ registerItem,
61
57
  };
62
58
  $context[NavMenuContextName] = context;
63
59
 
64
60
  // If the NavMenu is not in a popout, focus its first item. Otherwise the popout will call focusFirstElement, below
65
61
  function handleFocus() {
66
- if (!popoutContext && itemStates.length) {
67
- itemStates[0].setFocused();
62
+ if (!popoutContext && group.itemStates.length) {
63
+ group.focusFirstItem();
68
64
  }
69
65
  }
70
66
 
71
- function focusFirstElement() {
72
- if (itemStates.length) {
73
- itemStates[0].setFocused();
74
- }
75
- }
76
-
77
- function registerItem(setFocused: () => void) {
78
- // Add the item's state to the array and return its index
79
- const newItemState: ItemState = {
80
- setFocused
81
- };
82
- itemStates.push(newItemState);
83
- itemStates = itemStates;
84
- return { index: itemStates.length - 1 };
67
+ function registerItem(item: ItemState) {
68
+ return group.registerItem(item);
85
69
  }
86
70
 
87
71
  function handleItemFocus(index: number) {
88
- focusIndex = index;
72
+ group.handleItemFocus(index);
89
73
  }
90
74
 
91
75
  function handleItemKey(e: KeyboardEvent) {
92
76
  switch (e.key) {
93
- case "Esc":
94
77
  case "Escape": {
95
78
  if (inPopout) {
96
79
  e.preventDefault();
97
- //setPopoutVisible(false);
98
80
  popoutState.visible = false;
99
81
  }
100
82
  break;
101
83
  }
102
- case "Right":
103
- case "ArrowRight": {
104
- if (orientation === "horizontal") {
105
- e.preventDefault();
106
- focusItem("next");
107
- }
108
- break;
109
- }
110
- case "Left":
111
- case "ArrowLeft": {
112
- if (orientation === "horizontal") {
113
- e.preventDefault();
114
- focusItem("previous");
115
- }
116
- break;
117
- }
118
- case "Down":
119
- case "ArrowDown": {
120
- if (orientation === "vertical") {
121
- e.preventDefault();
122
- focusItem("next");
123
- }
124
- break;
125
- }
126
- case "Up":
127
- case "ArrowUp": {
128
- if (orientation === "vertical") {
129
- e.preventDefault();
130
- focusItem("previous");
131
- } else {
132
- // TODO: This should be based on what side the menu shows on
133
- // And on the orientation
134
- if (inPopout) {
135
- e.preventDefault();
136
- popoutState.visible = false;
137
- }
138
- }
139
- break;
140
- }
141
- case "Home": {
142
- e.preventDefault();
143
- focusItem("start");
144
- break;
145
- }
146
- case "End": {
147
- e.preventDefault();
148
- focusItem("end");
84
+ default: {
85
+ group.handleGroupKey(group.getFocusIndex(), e, {
86
+ vertical: orientation === "vertical",
87
+ });
149
88
  break;
150
89
  }
151
90
  }
152
91
  }
153
92
 
154
- function focusItem(target: "start" | "previous" | "next" | "end") {
155
- switch (target) {
156
- case "start": {
157
- focusIndex = 0;
158
- break;
159
- }
160
- case "previous": {
161
- focusIndex = Math.max(0, focusIndex - 1);
162
- break;
163
- }
164
- case "next": {
165
- focusIndex = Math.min(itemStates.length - 1, focusIndex + 1);
166
- break;
167
- }
168
- case "end": {
169
- focusIndex = itemStates.length - 1;
170
- break;
171
- }
172
- }
173
- itemStates[focusIndex]?.setFocused();
174
- }
175
93
 
176
94
  @render {
177
95
  <nav
@@ -1,15 +1,19 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
2
+ import { type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
3
3
 
4
4
  interface NavMenuButtonProps {
5
5
  /** An ID for the root element */
6
6
  id?: string;
7
7
  /** Classes for the root element */
8
- class?: ClassValue,
8
+ class?: ClassValue;
9
9
  /** Styles for the root element */
10
- style?: StyleValue,
10
+ style?: StyleValue;
11
11
  /** Whether this button is disabled */
12
- disabled?: boolean,
12
+ disabled?: boolean;
13
+ /** Raised when the button is clicked */
14
+ onclick?: (e: MouseEvent) => void;
15
+ /** Raised when a key is pressed down */
16
+ onkeydown?: (e: KeyboardEvent) => void;
13
17
  }
14
18
 
15
19
  /**
@@ -27,7 +31,7 @@ export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
27
31
  const { registerItem, handleItemKey, handleItemFocus } = menuContext;
28
32
 
29
33
  // Register this item with the parent NavMenu and store the index
30
- const { index } = registerItem(setFocused);
34
+ const { index } = registerItem({ setFocused, disabled: $props?.disabled });
31
35
 
32
36
  function setFocused() {
33
37
  button.focus();
@@ -42,10 +46,8 @@ export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
42
46
  {$props?.disabled}
43
47
  role="menuitem"
44
48
  aria-disabled={$props?.disabled ? "true" : undefined}
45
- data-disabled={$props?.disabled ? "true" : undefined}
46
- onkeydown
47
49
  onkeydown={handleItemKey}
48
- onclick
50
+ {$props?.onclick}
49
51
  onfocus={() => handleItemFocus(index)}
50
52
  &ref={button}
51
53
  >
@@ -1,17 +1,17 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { NavMenuContextName, type NavMenuContext } from "./NavMenuTypes";
2
+ import { type NavMenuContext, NavMenuContextName } from "./NavMenuTypes";
3
3
 
4
4
  interface NavMenuElementProps {
5
5
  /** An ID for the root element */
6
6
  id?: string;
7
7
  /** Classes for the root element */
8
- class?: ClassValue,
8
+ class?: ClassValue;
9
9
  /** Styles for the root element */
10
- style?: StyleValue,
10
+ style?: StyleValue;
11
11
  /** Whether this button is disabled */
12
- disabled?: boolean,
12
+ disabled?: boolean;
13
13
  /** An element that can be focused via keyboard navigation */
14
- element?: HTMLElement,
14
+ element?: HTMLElement;
15
15
  }
16
16
 
17
17
  /**
@@ -27,7 +27,7 @@ export default function NavMenuElement($props: NavMenuElementProps | undefined)
27
27
  const { registerItem, handleItemKey, handleItemFocus } = menuContext;
28
28
 
29
29
  // Register this item with the parent NavMenu and store the index
30
- const { index } = registerItem(setFocused);
30
+ const { index } = registerItem({ setFocused, disabled: $props?.disabled });
31
31
 
32
32
  function setFocused() {
33
33
  if ($props?.element) {
@@ -43,7 +43,6 @@ export default function NavMenuElement($props: NavMenuElementProps | undefined)
43
43
  type="div"
44
44
  role="menuitem"
45
45
  aria-disabled={$props?.disabled ? "true" : undefined}
46
- data-disabled={$props?.disabled ? "true" : undefined}
47
46
  onkeydown
48
47
  onkeydown={handleItemKey}
49
48
  onclick