@torpor/ui 0.2.1 → 0.3.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 (290) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/Accordion/Accordion.torp +29 -22
  3. package/dist/Accordion/AccordionContent.torp +7 -8
  4. package/dist/Accordion/AccordionHeader.torp +4 -6
  5. package/dist/Accordion/AccordionItem.torp +15 -12
  6. package/dist/Accordion/AccordionTrigger.torp +6 -7
  7. package/dist/Accordion/AccordionTypes.ts +4 -3
  8. package/dist/Accordion/index.d.ts +5 -5
  9. package/dist/Breadcrumb/Breadcrumb.torp +9 -10
  10. package/dist/Breadcrumb/BreadcrumbItem.torp +5 -7
  11. package/dist/Breadcrumb/BreadcrumbSeparator.torp +3 -5
  12. package/dist/Breadcrumb/index.d.ts +8 -7
  13. package/dist/Calendar/Calendar.torp +12 -13
  14. package/dist/Calendar/CalendarDay.torp +3 -3
  15. package/dist/Contextual/Contextual.torp +125 -0
  16. package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
  17. package/dist/Contextual/ContextualTrigger.torp +66 -0
  18. package/dist/Contextual/ContextualTypes.ts +30 -0
  19. package/dist/Contextual/index.d.ts +90 -0
  20. package/dist/Contextual/index.js +14 -0
  21. package/dist/Contextual/index.js.map +1 -0
  22. package/dist/Dialog/Dialog.torp +38 -72
  23. package/dist/Dialog/DialogBody.torp +6 -8
  24. package/dist/Dialog/DialogButton.torp +14 -12
  25. package/dist/Dialog/DialogFooter.torp +3 -5
  26. package/dist/Dialog/DialogHeader.torp +6 -8
  27. package/dist/Dialog/DialogTypes.ts +3 -2
  28. package/dist/Dialog/index.d.ts +16 -11
  29. package/dist/Disclosure/Disclosure.torp +22 -23
  30. package/dist/Disclosure/DisclosureContent.torp +7 -8
  31. package/dist/Disclosure/DisclosureHeader.torp +5 -7
  32. package/dist/Disclosure/DisclosureTrigger.torp +7 -8
  33. package/dist/Disclosure/DisclosureTypes.ts +0 -1
  34. package/dist/Disclosure/index.d.ts +12 -12
  35. package/dist/Drawer/Drawer.torp +101 -70
  36. package/dist/Drawer/DrawerContent.torp +80 -0
  37. package/dist/Drawer/DrawerOverlay.torp +38 -0
  38. package/dist/Drawer/DrawerTrigger.torp +35 -0
  39. package/dist/Drawer/DrawerTypes.ts +24 -0
  40. package/dist/Drawer/index.d.ts +90 -3
  41. package/dist/Drawer/index.js +13 -1
  42. package/dist/Form/Field.torp +2 -4
  43. package/dist/Form/Form.torp +7 -9
  44. package/dist/Form/Input.torp +20 -17
  45. package/dist/Form/Label.torp +1 -1
  46. package/dist/Form/Message.torp +1 -1
  47. package/dist/Form/index.d.ts +18 -4
  48. package/dist/Menu/Menu.torp +16 -15
  49. package/dist/Menu/MenuButton.torp +19 -13
  50. package/dist/Menu/MenuCheck.torp +18 -14
  51. package/dist/Menu/MenuGroup.torp +4 -6
  52. package/dist/Menu/MenuIndicator.torp +5 -7
  53. package/dist/Menu/MenuPopout.torp +12 -15
  54. package/dist/Menu/MenuPopoutContent.torp +6 -8
  55. package/dist/Menu/MenuPopoutTrigger.torp +12 -14
  56. package/dist/Menu/MenuRadio.torp +14 -14
  57. package/dist/Menu/MenuRadioGroup.torp +22 -14
  58. package/dist/Menu/MenuSeparator.torp +3 -5
  59. package/dist/Menu/MenuTypes.ts +7 -5
  60. package/dist/Menu/index.d.ts +28 -22
  61. package/dist/MenuBar/MenuBar.torp +13 -14
  62. package/dist/MenuBar/MenuBarItem.torp +13 -16
  63. package/dist/MenuBar/MenuBarItemContent.torp +7 -9
  64. package/dist/MenuBar/MenuBarItemTrigger.torp +6 -9
  65. package/dist/MenuBar/index.d.ts +16 -16
  66. package/dist/Modal/Modal.torp +118 -0
  67. package/dist/Modal/ModalContent.torp +77 -0
  68. package/dist/Modal/ModalOverlay.torp +38 -0
  69. package/dist/Modal/ModalTrigger.torp +50 -0
  70. package/dist/Modal/ModalTypes.ts +22 -0
  71. package/dist/Modal/index.d.ts +108 -0
  72. package/dist/Modal/index.js +33 -0
  73. package/dist/Modal/index.js.map +1 -0
  74. package/dist/Modal/showModal.ts +19 -0
  75. package/dist/Modal/showPrompt.ts +23 -0
  76. package/dist/NavMenu/NavMenu.torp +7 -8
  77. package/dist/NavMenu/NavMenuButton.torp +6 -8
  78. package/dist/NavMenu/NavMenuElement.torp +8 -8
  79. package/dist/NavMenu/NavMenuGroup.torp +4 -6
  80. package/dist/NavMenu/NavMenuGroupHeader.torp +5 -6
  81. package/dist/NavMenu/NavMenuLink.torp +8 -11
  82. package/dist/NavMenu/NavMenuPopout.torp +25 -17
  83. package/dist/NavMenu/NavMenuPopoutButton.torp +12 -13
  84. package/dist/NavMenu/NavMenuPopoutContent.torp +12 -12
  85. package/dist/NavMenu/NavMenuSeparator.torp +3 -5
  86. package/dist/NavMenu/index.d.ts +17 -11
  87. package/dist/Notification/Notification.torp +22 -13
  88. package/dist/Notification/NotificationClose.torp +3 -5
  89. package/dist/Notification/NotificationContainer.torp +3 -5
  90. package/dist/Notification/NotificationContent.torp +3 -5
  91. package/dist/Notification/index.d.ts +4 -4
  92. package/dist/Popover/Popover.torp +31 -25
  93. package/dist/Popover/PopoverContent.torp +35 -10
  94. package/dist/Popover/PopoverTrigger.torp +24 -4
  95. package/dist/Popover/PopoverTypes.ts +1 -1
  96. package/dist/Popover/index.d.ts +16 -124
  97. package/dist/Popover/index.js +1 -163
  98. package/dist/Popover/index.js.map +1 -1
  99. package/dist/TabGroup/TabContent.torp +12 -9
  100. package/dist/TabGroup/TabGroup.torp +41 -35
  101. package/dist/TabGroup/TabGroupTypes.ts +10 -5
  102. package/dist/TabGroup/TabHeader.torp +15 -8
  103. package/dist/TabGroup/TabList.torp +4 -6
  104. package/dist/TabGroup/TabTrigger.torp +8 -9
  105. package/dist/TabGroup/index.d.ts +14 -6
  106. package/dist/icons/ArrowDown.torp +3 -1
  107. package/dist/icons/ArrowLeft.torp +3 -1
  108. package/dist/icons/ArrowRight.torp +3 -1
  109. package/dist/icons/ArrowUp.torp +3 -1
  110. package/dist/icons/Bars.torp +3 -1
  111. package/dist/icons/Check.torp +3 -1
  112. package/dist/icons/ChevronDown.torp +3 -1
  113. package/dist/icons/ChevronLeft.torp +3 -1
  114. package/dist/icons/ChevronRight.torp +3 -1
  115. package/dist/icons/ChevronUp.torp +3 -1
  116. package/dist/icons/Cross.torp +3 -1
  117. package/dist/icons/IconTypes.ts +6 -0
  118. package/dist/icons/Loading.torp +3 -1
  119. package/dist/icons/Minus.torp +3 -1
  120. package/dist/icons/Plus.torp +3 -1
  121. package/dist/icons/index.d.ts +271 -14
  122. package/dist/index.d.ts +17 -4
  123. package/dist/metafile-esm.json +1 -1
  124. package/dist/motion/fade.ts +15 -6
  125. package/dist/motion/grow.ts +23 -0
  126. package/dist/motion/index.d.ts +19 -2
  127. package/dist/motion/index.js +93 -3
  128. package/dist/motion/index.js.map +1 -1
  129. package/dist/motion/measure.ts +28 -0
  130. package/dist/motion/slide.ts +45 -0
  131. package/dist/mount/clickPopover.ts +51 -0
  132. package/dist/mount/contextPopover.ts +51 -0
  133. package/dist/mount/hoverPopover.ts +58 -0
  134. package/package.json +21 -14
  135. package/scripts/postbuild.ts +11 -1
  136. package/src/Accordion/Accordion.torp +29 -22
  137. package/src/Accordion/AccordionContent.torp +7 -8
  138. package/src/Accordion/AccordionHeader.torp +4 -6
  139. package/src/Accordion/AccordionItem.torp +15 -12
  140. package/src/Accordion/AccordionTrigger.torp +6 -7
  141. package/src/Accordion/AccordionTypes.ts +4 -3
  142. package/src/Breadcrumb/Breadcrumb.torp +9 -10
  143. package/src/Breadcrumb/BreadcrumbItem.torp +5 -7
  144. package/src/Breadcrumb/BreadcrumbSeparator.torp +3 -5
  145. package/src/Calendar/Calendar.torp +12 -13
  146. package/src/Calendar/CalendarDay.torp +3 -3
  147. package/src/Contextual/Contextual.torp +125 -0
  148. package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
  149. package/src/Contextual/ContextualTrigger.torp +66 -0
  150. package/src/Contextual/ContextualTypes.ts +30 -0
  151. package/src/Contextual/index.ts +5 -0
  152. package/src/Dialog/Dialog.torp +38 -72
  153. package/src/Dialog/DialogBody.torp +6 -8
  154. package/src/Dialog/DialogButton.torp +14 -12
  155. package/src/Dialog/DialogFooter.torp +3 -5
  156. package/src/Dialog/DialogHeader.torp +6 -8
  157. package/src/Dialog/DialogTypes.ts +3 -2
  158. package/src/Disclosure/Disclosure.torp +22 -23
  159. package/src/Disclosure/DisclosureContent.torp +7 -8
  160. package/src/Disclosure/DisclosureHeader.torp +5 -7
  161. package/src/Disclosure/DisclosureTrigger.torp +7 -8
  162. package/src/Disclosure/DisclosureTypes.ts +0 -1
  163. package/src/Drawer/Drawer.torp +101 -70
  164. package/src/Drawer/DrawerContent.torp +80 -0
  165. package/src/Drawer/DrawerOverlay.torp +38 -0
  166. package/src/Drawer/DrawerTrigger.torp +35 -0
  167. package/src/Drawer/DrawerTypes.ts +24 -0
  168. package/src/Drawer/index.ts +4 -1
  169. package/src/Form/Field.torp +2 -4
  170. package/src/Form/Form.torp +7 -9
  171. package/src/Form/Input.torp +20 -17
  172. package/src/Form/Label.torp +1 -1
  173. package/src/Form/Message.torp +1 -1
  174. package/src/Menu/Menu.torp +16 -15
  175. package/src/Menu/MenuButton.torp +19 -13
  176. package/src/Menu/MenuCheck.torp +18 -14
  177. package/src/Menu/MenuGroup.torp +4 -6
  178. package/src/Menu/MenuIndicator.torp +5 -7
  179. package/src/Menu/MenuPopout.torp +12 -15
  180. package/src/Menu/MenuPopoutContent.torp +6 -8
  181. package/src/Menu/MenuPopoutTrigger.torp +12 -14
  182. package/src/Menu/MenuRadio.torp +14 -14
  183. package/src/Menu/MenuRadioGroup.torp +22 -14
  184. package/src/Menu/MenuSeparator.torp +3 -5
  185. package/src/Menu/MenuTypes.ts +7 -5
  186. package/src/MenuBar/MenuBar.torp +13 -14
  187. package/src/MenuBar/MenuBarItem.torp +13 -16
  188. package/src/MenuBar/MenuBarItemContent.torp +7 -9
  189. package/src/MenuBar/MenuBarItemTrigger.torp +6 -9
  190. package/src/Modal/Modal.torp +118 -0
  191. package/src/Modal/ModalContent.torp +77 -0
  192. package/src/Modal/ModalOverlay.torp +38 -0
  193. package/src/Modal/ModalTrigger.torp +50 -0
  194. package/src/Modal/ModalTypes.ts +22 -0
  195. package/src/Modal/index.ts +10 -0
  196. package/src/Modal/showModal.ts +19 -0
  197. package/src/Modal/showPrompt.ts +23 -0
  198. package/src/NavMenu/NavMenu.torp +7 -8
  199. package/src/NavMenu/NavMenuButton.torp +6 -8
  200. package/src/NavMenu/NavMenuElement.torp +8 -8
  201. package/src/NavMenu/NavMenuGroup.torp +4 -6
  202. package/src/NavMenu/NavMenuGroupHeader.torp +5 -6
  203. package/src/NavMenu/NavMenuLink.torp +8 -11
  204. package/src/NavMenu/NavMenuPopout.torp +25 -17
  205. package/src/NavMenu/NavMenuPopoutButton.torp +12 -13
  206. package/src/NavMenu/NavMenuPopoutContent.torp +12 -12
  207. package/src/NavMenu/NavMenuSeparator.torp +3 -5
  208. package/src/Notification/Notification.torp +22 -13
  209. package/src/Notification/NotificationClose.torp +3 -5
  210. package/src/Notification/NotificationContainer.torp +3 -5
  211. package/src/Notification/NotificationContent.torp +3 -5
  212. package/src/Popover/Popover.torp +31 -25
  213. package/src/Popover/PopoverContent.torp +35 -10
  214. package/src/Popover/PopoverTrigger.torp +24 -4
  215. package/src/Popover/PopoverTypes.ts +1 -1
  216. package/src/Popover/index.ts +1 -24
  217. package/src/Slider/Slider.torp +3 -3
  218. package/src/TabGroup/TabContent.torp +12 -9
  219. package/src/TabGroup/TabGroup.torp +41 -35
  220. package/src/TabGroup/TabGroupTypes.ts +10 -5
  221. package/src/TabGroup/TabHeader.torp +15 -8
  222. package/src/TabGroup/TabList.torp +4 -6
  223. package/src/TabGroup/TabTrigger.torp +8 -9
  224. package/src/icons/ArrowDown.torp +3 -1
  225. package/src/icons/ArrowLeft.torp +3 -1
  226. package/src/icons/ArrowRight.torp +3 -1
  227. package/src/icons/ArrowUp.torp +3 -1
  228. package/src/icons/Bars.torp +3 -1
  229. package/src/icons/Check.torp +3 -1
  230. package/src/icons/ChevronDown.torp +3 -1
  231. package/src/icons/ChevronLeft.torp +3 -1
  232. package/src/icons/ChevronRight.torp +3 -1
  233. package/src/icons/ChevronUp.torp +3 -1
  234. package/src/icons/Cross.torp +3 -1
  235. package/src/icons/IconTypes.ts +6 -0
  236. package/src/icons/Loading.torp +3 -1
  237. package/src/icons/Minus.torp +3 -1
  238. package/src/icons/Plus.torp +3 -1
  239. package/src/motion/fade.ts +15 -6
  240. package/src/motion/grow.ts +23 -0
  241. package/src/motion/index.ts +4 -1
  242. package/src/motion/measure.ts +28 -0
  243. package/src/motion/slide.ts +45 -0
  244. package/src/mount/clickPopover.ts +51 -0
  245. package/src/mount/contextPopover.ts +51 -0
  246. package/src/mount/hoverPopover.ts +58 -0
  247. package/test/Accordion/components/AccordionAccessibility.torp +1 -3
  248. package/test/Accordion/components/AccordionKeyboard.torp +1 -3
  249. package/test/Accordion/components/AccordionList.torp +1 -3
  250. package/test/Accordion/components/AccordionMultiple.torp +2 -4
  251. package/test/Accordion/components/AccordionSingle.torp +2 -4
  252. package/test/Dialog/accessibility-modal.test.ts +2 -2
  253. package/test/Dialog/components/DialogAccessibility.torp +8 -14
  254. package/test/Dialog/components/DialogFunction.torp +20 -4
  255. package/test/Dialog/components/DialogModal.torp +30 -0
  256. package/test/Dialog/components/DialogVariable.torp +7 -7
  257. package/test/Disclosure/components/DisclosureTest.torp +1 -3
  258. package/test/Menu/components/MenuAccessibility.torp +5 -5
  259. package/test/Menu/components/MenuBasic.torp +5 -5
  260. package/test/Notification/components/NotificationFunction.torp +0 -3
  261. package/test/Notification/components/NotificationVariable.torp +1 -1
  262. package/test/Popover/components/PopoverFunction.torp +37 -0
  263. package/test/Popover/components/PopoverTrigger.torp +36 -0
  264. package/test/Popover/components/{PromptVariable.torp → PopoverVariable.torp} +5 -3
  265. package/test/Popover/function.test.ts +2 -7
  266. package/test/Popover/trigger.test.ts +27 -0
  267. package/test/Popover/variable.test.ts +2 -2
  268. package/test/TabGroup/components/TabGroupAccessibility.torp +1 -3
  269. package/test/TabGroup/components/TabGroupKeyboard.torp +1 -3
  270. package/test/TabGroup/components/TabGroupList.torp +1 -3
  271. package/test/TabGroup/components/TabGroupTrigger.torp +1 -3
  272. package/tsup.config.ts +2 -0
  273. package/dist/Popover/PopoverContentAnchored.torp +0 -113
  274. package/dist/Popover/PopoverOverlay.torp +0 -39
  275. package/dist/Popover/PopoverTriggerContextual.torp +0 -46
  276. package/dist/Popover/PopoverTriggerHover.torp +0 -47
  277. package/dist/Popover/mountClickPopover.ts +0 -50
  278. package/dist/Popover/mountContextPopover.ts +0 -50
  279. package/dist/Popover/mountHoverPopover.ts +0 -57
  280. package/dist/Popover/showPopoverPrompt.ts +0 -23
  281. package/src/Popover/PopoverContentAnchored.torp +0 -113
  282. package/src/Popover/PopoverOverlay.torp +0 -39
  283. package/src/Popover/PopoverTriggerContextual.torp +0 -46
  284. package/src/Popover/PopoverTriggerHover.torp +0 -47
  285. package/src/Popover/mountClickPopover.ts +0 -50
  286. package/src/Popover/mountContextPopover.ts +0 -50
  287. package/src/Popover/mountHoverPopover.ts +0 -57
  288. package/src/Popover/showPopoverPrompt.ts +0 -23
  289. package/test/Dialog/components/CustomDialog.torp +0 -20
  290. package/test/Popover/components/PromptFunction.torp +0 -19
@@ -33,9 +33,8 @@ interface NavMenuProps {
33
33
  * </NavMenu>
34
34
  * ```
35
35
  */
36
- export default function NavMenu($props: NavMenuProps) {
37
- $props ??= $watch({});
38
- $props.orientation ||= "horizontal";
36
+ export default function NavMenu($props: NavMenuProps | undefined) {
37
+ let orientation = $props?.orientation ?? "horizontal";
39
38
 
40
39
  // A collection containing the state and some functions for each item
41
40
  let itemStates: ItemState[] = [];
@@ -60,7 +59,7 @@ export default function NavMenu($props: NavMenuProps) {
60
59
  $context[NavMenuContextName] = context;
61
60
 
62
61
  // If the NavMenu is not in a popout, focus its first item. Otherwise the popout will call focusFirstElement, below
63
- function handleFocus(e: FocusEvent & { currentTarget: EventTarget & HTMLElement }) {
62
+ function handleFocus() {
64
63
  if (!popoutContext && itemStates.length) {
65
64
  itemStates[0].setFocused();
66
65
  }
@@ -173,12 +172,12 @@ export default function NavMenu($props: NavMenuProps) {
173
172
 
174
173
  @render {
175
174
  <nav
176
- {$props.id}
177
- class={`torp-nav-menu ${$props.class ?? ""}`.trim()}
175
+ {$props?.id}
176
+ class={`torp-nav-menu ${$props?.class ?? ""}`.trim()}
178
177
  tabindex="0"
179
178
  role="menubar"
180
- aria-label={$props.ariaLabel}
181
- aria-orientation={$props.orientation}
179
+ aria-label={$props?.ariaLabel}
180
+ aria-orientation={orientation}
182
181
  onfocus={handleFocus}
183
182
  >
184
183
  <slot />
@@ -13,9 +13,7 @@ interface NavMenuButtonProps {
13
13
  * A button that is placed in a NavMenu to carry out a non-navigation action such as logging out.
14
14
  *
15
15
  */
16
- export default function NavMenuButton($props: NavMenuButtonProps) {
17
- $props ??= $watch({});
18
-
16
+ export default function NavMenuButton($props: NavMenuButtonProps | undefined) {
19
17
  let button: HTMLButtonElement;
20
18
 
21
19
  // Get stuff out of the NavMenuContext
@@ -34,13 +32,13 @@ export default function NavMenuButton($props: NavMenuButtonProps) {
34
32
 
35
33
  @render {
36
34
  <button
37
- {$props.id}
38
- class={`torp-nav-menu-button ${$props.class ?? ""}`.trim()}
35
+ {$props?.id}
36
+ class={`torp-nav-menu-button ${$props?.class ?? ""}`.trim()}
39
37
  type="button"
40
- {$props.disabled}
38
+ {$props?.disabled}
41
39
  role="menuitem"
42
- aria-disabled={$props.disabled ? "true" : undefined}
43
- data-disabled={$props.disabled ? "true" : undefined}
40
+ aria-disabled={$props?.disabled ? "true" : undefined}
41
+ data-disabled={$props?.disabled ? "true" : undefined}
44
42
  onkeydown
45
43
  onkeydown={handleItemKey}
46
44
  onclick
@@ -15,9 +15,7 @@ interface NavMenuElementProps {
15
15
  * An element of any type that can be placed in a NavMenu.
16
16
  *
17
17
  */
18
- export default function NavMenuElement($props: NavMenuElementProps) {
19
- $props ??= $watch({});
20
-
18
+ export default function NavMenuElement($props: NavMenuElementProps | undefined) {
21
19
  // Get stuff out of the NavMenuContext
22
20
  const menuContext = $context[NavMenuContextName] as NavMenuContext;
23
21
  if (!menuContext) {
@@ -29,17 +27,19 @@ export default function NavMenuElement($props: NavMenuElementProps) {
29
27
  const { index } = registerItem(setFocused);
30
28
 
31
29
  function setFocused() {
32
- element.focus();
30
+ if ($props?.element) {
31
+ $props.element.focus();
32
+ }
33
33
  }
34
34
 
35
35
  @render {
36
36
  <div
37
- {$props.id}
38
- class={`torp-nav-menu-div ${$props.class ?? ""}`.trim()}
37
+ {$props?.id}
38
+ class={`torp-nav-menu-div ${$props?.class ?? ""}`.trim()}
39
39
  type="div"
40
40
  role="menuitem"
41
- aria-disabled={$props.disabled ? "true" : undefined}
42
- data-disabled={$props.disabled ? "true" : undefined}
41
+ aria-disabled={$props?.disabled ? "true" : undefined}
42
+ data-disabled={$props?.disabled ? "true" : undefined}
43
43
  onkeydown
44
44
  onkeydown={handleItemKey}
45
45
  onclick
@@ -12,9 +12,7 @@ interface NavMenuGroupProps {
12
12
  /**
13
13
  * A container for a logical group of navigation menu items.
14
14
  */
15
- export default function NavMenuGroup($props: NavMenuGroupProps) {
16
- $props ??= $watch({});
17
-
15
+ export default function NavMenuGroup($props: NavMenuGroupProps | undefined) {
18
16
  let $state = $watch({
19
17
  headerId: ""
20
18
  });
@@ -27,10 +25,10 @@ export default function NavMenuGroup($props: NavMenuGroupProps) {
27
25
 
28
26
  @render {
29
27
  <div
30
- {$props.id}
31
- class={`torp-nav-menu-group ${$props.class ?? ""}`.trim()}
28
+ {$props?.id}
29
+ class={`torp-nav-menu-group ${$props?.class ?? ""}`.trim()}
32
30
  role="group"
33
- aria-label={$props.ariaLabel}
31
+ aria-label={$props?.ariaLabel}
34
32
  aria-labelledby={$state.headerId}
35
33
  >
36
34
  <slot />
@@ -13,9 +13,8 @@ interface NavMenuGroupHeaderProps {
13
13
  /**
14
14
  * The header for a NavMenuGroup.
15
15
  */
16
- export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps) {
17
- $props ??= $watch({});
18
- $props.id ??= getId();
16
+ export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps | undefined) {
17
+ let defaultId = getId();
19
18
 
20
19
  const context = $context[NavMenuGroupContextName] as NavMenuGroupContext;
21
20
  if (!context) {
@@ -24,13 +23,13 @@ export default function NavMenuGroupHeader($props: NavMenuGroupHeaderProps) {
24
23
  let $state = context.state;
25
24
 
26
25
  // Set the header ID now that we know what it is
27
- $state.headerId = $props.id;
26
+ $state.headerId = $props?.id ?? defaultId;
28
27
 
29
28
  @render {
30
29
  @// TODO: self={$props.as}
31
30
  <h4
32
- {$props.id}
33
- class={`torp-nav-menu-group-header ${$props.class ?? ""}`.trim()}
31
+ id={$props?.id ?? defaultId}
32
+ class={`torp-nav-menu-group-header ${$props?.class ?? ""}`.trim()}
34
33
  >
35
34
  <slot />
36
35
  </h4>
@@ -18,10 +18,7 @@ interface NavMenuLinkProps {
18
18
  * A link that is placed in a NavMenu and signals a response by a user.
19
19
  *
20
20
  */
21
- export default function NavMenuLink($props: NavMenuLinkProps) {
22
- $props ??= $watch({ href: "#" });
23
- $props.newWindow ??= false;
24
-
21
+ export default function NavMenuLink($props: NavMenuLinkProps | undefined) {
25
22
  let link: HTMLAnchorElement;
26
23
 
27
24
  // Get stuff out of the NavMenuContext
@@ -40,14 +37,14 @@ export default function NavMenuLink($props: NavMenuLinkProps) {
40
37
 
41
38
  @render {
42
39
  <a
43
- {$props.id}
44
- class={`torp-nav-menu-link ${$props.class ?? ""}`.trim()}
45
- href={$props.href}
46
- {$props.disabled}
47
- target={$props.newWindow ? "_blank" : undefined}
40
+ {$props?.id}
41
+ class={`torp-nav-menu-link ${$props?.class ?? ""}`.trim()}
42
+ {$props?.href}
43
+ {$props?.disabled}
44
+ target={$props?.newWindow ? "_blank" : undefined}
48
45
  role="menuitem"
49
- aria-disabled={$props.disabled ? "true" : undefined}
50
- data-disabled={$props.disabled ? "true" : undefined}
46
+ aria-disabled={$props?.disabled ? "true" : undefined}
47
+ data-disabled={$props?.disabled ? "true" : undefined}
51
48
  onkeydown
52
49
  onkeydown={handleItemKey}
53
50
  onclick
@@ -7,6 +7,12 @@ interface NavMenuPopoutProps {
7
7
  class?: string,
8
8
  /** Whether the popout is visible */
9
9
  visible?: boolean,
10
+ /** Raised when the popout is opened or closed */
11
+ ontoggle?: (open: boolean) => void,
12
+ /** Raised when the popout has opened */
13
+ onopen?: () => void,
14
+ /** Raised when the popout has closed */
15
+ onclose?: (result: any) => void,
10
16
  }
11
17
 
12
18
  /**
@@ -16,17 +22,24 @@ interface NavMenuPopoutProps {
16
22
  *
17
23
  * ```
18
24
  * <NavMenuPopout>
19
- * <NavMenuPopoutButton />
25
+ * <NavMenuPopoutButton />
20
26
  * <NavMenuPopoutContent />
21
27
  * </NavMenuPopout>
22
28
  * ```
23
29
  */
24
- export default function NavMenuPopout($props: NavMenuPopoutProps) {
25
- $props ??= $watch({});
26
- $props.visible ??= false;
27
-
30
+ export default function NavMenuPopout($props: NavMenuPopoutProps | undefined) {
28
31
  let $state = $watch({
29
- visible: $props.visible
32
+ visible: false
33
+ });
34
+
35
+ // Sync props and state
36
+ $run(() => {
37
+ $state.visible = $props?.visible ?? false;
38
+ });
39
+ $run(() => {
40
+ if ($props !== undefined) {
41
+ $props.visible = $state.visible;
42
+ }
30
43
  });
31
44
 
32
45
  let result: any;
@@ -37,18 +50,13 @@ export default function NavMenuPopout($props: NavMenuPopoutProps) {
37
50
  };
38
51
  $context[NavMenuPopoutContextName] = context;
39
52
 
40
- // Copy props into state whenever they change
41
- $run(() => {
42
- $state.visible = $props.visible ?? false;
43
- });
44
-
45
53
  // Dispatch the toggle event when the popout is opened or closed
46
54
  let firstToggle = true;
47
55
  $run(() => {
48
- const ontoggle = $props.ontoggle;
49
- const onopen = $props.onopen;
50
- const onclose = $props.onclose;
51
- const visible = $props.visible;
56
+ const ontoggle = $props?.ontoggle;
57
+ const onopen = $props?.onopen;
58
+ const onclose = $props?.onclose;
59
+ const visible = $state.visible;
52
60
  if (firstToggle) {
53
61
  firstToggle = false;
54
62
  } else {
@@ -67,8 +75,8 @@ export default function NavMenuPopout($props: NavMenuPopoutProps) {
67
75
 
68
76
  @render {
69
77
  <div
70
- {$props.id}
71
- class={`torp-nav-menu-popout ${$props.class ?? ""}`.trim()}
78
+ {$props?.id}
79
+ class={`torp-nav-menu-popout ${$props?.class ?? ""}`.trim()}
72
80
  onmouseleave={handleMouseLeave}
73
81
  >
74
82
  <slot />
@@ -20,9 +20,8 @@ interface NavMenuPopoutButtonProps {
20
20
  * A button that is placed in a NavMenu and signals a response by a user.
21
21
  *
22
22
  */
23
- export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps) {
24
- $props ??= $watch({});
25
- $props.hoverDelay ??= 500;
23
+ export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps | undefined) {
24
+ let defaultHoverDelay = 500;
26
25
 
27
26
  let button: HTMLButtonElement;
28
27
  let interval: NodeJS.Timeout | undefined;
@@ -72,16 +71,16 @@ export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps) {
72
71
  }
73
72
 
74
73
  function handleMouseEnter() {
75
- if ($props.disabled) return;
74
+ if ($props?.disabled) return;
76
75
 
77
76
  // Handle the hover after a delay
78
77
  if (!interval) {
79
- interval = setTimeout(() => $state.visible = true, $props.hoverDelay);
78
+ interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
80
79
  }
81
80
  }
82
81
 
83
82
  function handleMouseLeave() {
84
- if ($props.disabled) return;
83
+ if ($props?.disabled) return;
85
84
 
86
85
  // Prevent short hovers or touches from firing the event
87
86
  if (interval) {
@@ -91,26 +90,26 @@ export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps) {
91
90
  }
92
91
 
93
92
  function handleMouseMove() {
94
- if ($props.disabled) return;
93
+ if ($props?.disabled) return;
95
94
 
96
95
  // Reset the interval on mouse move
97
96
  if (interval) {
98
97
  clearTimeout(interval);
99
- interval = setTimeout(() => $state.visible = true, $props.hoverDelay);
98
+ interval = setTimeout(() => $state.visible = true, $props?.hoverDelay ?? defaultHoverDelay);
100
99
  }
101
100
  }
102
101
 
103
102
  @render {
104
103
  <button
105
- {$props.id}
106
- class={`torp-nav-menu-popout-button ${$props.class ?? ""}`.trim()}
104
+ {$props?.id}
105
+ class={`torp-nav-menu-popout-button ${$props?.class ?? ""}`.trim()}
107
106
  type="button"
108
- {$props.disabled}
107
+ {$props?.disabled}
109
108
  role="menuitem"
110
109
  aria-haspopup="true"
111
110
  aria-expanded={$state.visible.toString()}
112
- aria-disabled={$props.disabled ? "true" : undefined}
113
- data-disabled={$state.disabled ? "true" : undefined}
111
+ aria-disabled={$props?.disabled ? "true" : undefined}
112
+ data-disabled={$props?.disabled ? "true" : undefined}
114
113
  onkeydown={handlePopoutKey}
115
114
  onclick={handleClick}
116
115
  onfocus={() => handleItemFocus(index)}
@@ -18,11 +18,7 @@ interface NavMenuPopoutContentProps {
18
18
  * The content that is displayed for a NavMenuPopout when it is open.
19
19
  *
20
20
  */
21
- export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps) {
22
- $props ??= $watch({});
23
- $props.side ??= "bottom";
24
- $props.alignment ??= "start";
25
-
21
+ export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps | undefined) {
26
22
  let div: HTMLDivElement;
27
23
  let shown = false;
28
24
 
@@ -44,7 +40,8 @@ export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps)
44
40
 
45
41
  // Set the position and listen for window resize and scroll to reset the position
46
42
  setPosition();
47
- const scrollParent = getScrollParent(context.anchorElement)
43
+ const anchorElement = context.anchorElement!
44
+ const scrollParent = getScrollParent(anchorElement)
48
45
  scrollParent.addEventListener("resize", setPosition);
49
46
  scrollParent.addEventListener("scroll", setPosition);
50
47
  if (context.focusFirstElement) {
@@ -56,11 +53,12 @@ export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps)
56
53
  if (!shown) return;
57
54
 
58
55
  // Stop listening for window resize and focus the anchor element per WAI guidelines
59
- const scrollParent = getScrollParent(context.anchorElement)
56
+ const anchorElement = context.anchorElement!
57
+ const scrollParent = getScrollParent(anchorElement)
60
58
  scrollParent.removeEventListener("resize", setPosition);
61
59
  scrollParent.removeEventListener("scroll", setPosition);
62
- if (context.anchorElement?.focus) {
63
- context.anchorElement.focus();
60
+ if (anchorElement.focus) {
61
+ anchorElement.focus();
64
62
  }
65
63
  }
66
64
 
@@ -70,15 +68,17 @@ export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps)
70
68
  }
71
69
 
72
70
  if (div) {
73
- setPopoverPosition(context.anchorElement, div, $props.side, $props.alignment);
71
+ let side = $props?.side ?? "bottom";
72
+ let alignment = $props?.alignment ?? "start";
73
+ setPopoverPosition(context.anchorElement, div, side, alignment);
74
74
  }
75
75
  }
76
76
 
77
77
  @render {
78
78
  @if ($state.visible) {
79
79
  <div
80
- {$props.id}
81
- class={`torp-nav-menu-popout-content ${$props.class ?? ""}`.trim()}
80
+ {$props?.id}
81
+ class={`torp-nav-menu-popout-content ${$props?.class ?? ""}`.trim()}
82
82
  &ref={div}
83
83
  onmount={show}
84
84
  >
@@ -9,13 +9,11 @@ interface NavMenuSeparatorProps {
9
9
  /**
10
10
  * An element in a menu that separates logical sets of menu items.
11
11
  */
12
- export default function NavMenuSeparator($props: NavMenuSeparatorProps) {
13
- $props ??= $watch({});
14
-
12
+ export default function NavMenuSeparator($props: NavMenuSeparatorProps | undefined) {
15
13
  @render {
16
14
  <div
17
- {$props.id}
18
- class={`torp-nav-menu-separator ${$props.class ?? ""}`.trim()} role="separator"
15
+ {$props?.id}
16
+ class={`torp-nav-menu-separator ${$props?.class ?? ""}`.trim()} role="separator"
19
17
  >
20
18
  <slot />
21
19
  </div>
@@ -31,7 +31,7 @@ interface NavMenuProps {
31
31
  declare function NavMenu(
32
32
  $parent: ParentNode,
33
33
  $anchor: Node | null,
34
- $props: NavMenuProps,
34
+ $props: NavMenuProps | undefined,
35
35
  $context?: Record<PropertyKey, any>,
36
36
  $slots?: Record<string, SlotRender>,
37
37
  ): void;
@@ -54,7 +54,7 @@ interface NavMenuButtonProps {
54
54
  declare function NavMenuButton(
55
55
  $parent: ParentNode,
56
56
  $anchor: Node | null,
57
- $props: NavMenuButtonProps,
57
+ $props: NavMenuButtonProps | undefined,
58
58
  $context?: Record<PropertyKey, any>,
59
59
  $slots?: Record<string, SlotRender>,
60
60
  ): void;
@@ -79,7 +79,7 @@ interface NavMenuElementProps {
79
79
  declare function NavMenuElement(
80
80
  $parent: ParentNode,
81
81
  $anchor: Node | null,
82
- $props: NavMenuElementProps,
82
+ $props: NavMenuElementProps | undefined,
83
83
  $context?: Record<PropertyKey, any>,
84
84
  $slots?: Record<string, SlotRender>,
85
85
  ): void;
@@ -101,7 +101,7 @@ interface NavMenuGroupProps {
101
101
  declare function NavMenuGroup(
102
102
  $parent: ParentNode,
103
103
  $anchor: Node | null,
104
- $props: NavMenuGroupProps,
104
+ $props: NavMenuGroupProps | undefined,
105
105
  $context?: Record<PropertyKey, any>,
106
106
  $slots?: Record<string, SlotRender>,
107
107
  ): void;
@@ -123,7 +123,7 @@ interface NavMenuGroupHeaderProps {
123
123
  declare function NavMenuGroupHeader(
124
124
  $parent: ParentNode,
125
125
  $anchor: Node | null,
126
- $props: NavMenuGroupHeaderProps,
126
+ $props: NavMenuGroupHeaderProps | undefined,
127
127
  $context?: Record<PropertyKey, any>,
128
128
  $slots?: Record<string, SlotRender>,
129
129
  ): void;
@@ -150,7 +150,7 @@ interface NavMenuLinkProps {
150
150
  declare function NavMenuLink(
151
151
  $parent: ParentNode,
152
152
  $anchor: Node | null,
153
- $props: NavMenuLinkProps,
153
+ $props: NavMenuLinkProps | undefined,
154
154
  $context?: Record<PropertyKey, any>,
155
155
  $slots?: Record<string, SlotRender>,
156
156
  ): void;
@@ -164,6 +164,12 @@ interface NavMenuPopoutProps {
164
164
  class?: string,
165
165
  /** Whether the popout is visible */
166
166
  visible?: boolean,
167
+ /** Raised when the popout is opened or closed */
168
+ ontoggle?: (open: boolean) => void,
169
+ /** Raised when the popout has opened */
170
+ onopen?: () => void,
171
+ /** Raised when the popout has closed */
172
+ onclose?: (result: any) => void,
167
173
  }
168
174
 
169
175
  /**
@@ -173,7 +179,7 @@ interface NavMenuPopoutProps {
173
179
  *
174
180
  * ```
175
181
  * <NavMenuPopout>
176
- * <NavMenuPopoutButton />
182
+ * <NavMenuPopoutButton />
177
183
  * <NavMenuPopoutContent />
178
184
  * </NavMenuPopout>
179
185
  * ```
@@ -181,7 +187,7 @@ interface NavMenuPopoutProps {
181
187
  declare function NavMenuPopout(
182
188
  $parent: ParentNode,
183
189
  $anchor: Node | null,
184
- $props: NavMenuPopoutProps,
190
+ $props: NavMenuPopoutProps | undefined,
185
191
  $context?: Record<PropertyKey, any>,
186
192
  $slots?: Record<string, SlotRender>,
187
193
  ): void;
@@ -206,7 +212,7 @@ interface NavMenuPopoutButtonProps {
206
212
  declare function NavMenuPopoutButton(
207
213
  $parent: ParentNode,
208
214
  $anchor: Node | null,
209
- $props: NavMenuPopoutButtonProps,
215
+ $props: NavMenuPopoutButtonProps | undefined,
210
216
  $context?: Record<PropertyKey, any>,
211
217
  $slots?: Record<string, SlotRender>,
212
218
  ): void;
@@ -231,7 +237,7 @@ interface NavMenuPopoutContentProps {
231
237
  declare function NavMenuPopoutContent(
232
238
  $parent: ParentNode,
233
239
  $anchor: Node | null,
234
- $props: NavMenuPopoutContentProps,
240
+ $props: NavMenuPopoutContentProps | undefined,
235
241
  $context?: Record<PropertyKey, any>,
236
242
  $slots?: Record<string, SlotRender>,
237
243
  ): void;
@@ -251,7 +257,7 @@ interface NavMenuSeparatorProps {
251
257
  declare function NavMenuSeparator(
252
258
  $parent: ParentNode,
253
259
  $anchor: Node | null,
254
- $props: NavMenuSeparatorProps,
260
+ $props: NavMenuSeparatorProps | undefined,
255
261
  $context?: Record<PropertyKey, any>,
256
262
  $slots?: Record<string, SlotRender>,
257
263
  ): void;
@@ -19,10 +19,21 @@ interface NotificationProps {
19
19
  *
20
20
  * See [the WAI ARIA guidelines for Alerts](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).
21
21
  */
22
- export default function Notification($props: NotificationProps) {
23
- $props ??= $watch({});
24
- $props.visible ??= true;
25
- $props.duration ??= 5000;
22
+ export default function Notification($props: NotificationProps | undefined) {
23
+ let defaultDuration = 5000;
24
+
25
+ let $state = $watch({
26
+ visible: false
27
+ });
28
+
29
+ $run(() => {
30
+ $state.visible = $props?.visible ?? true;
31
+ });
32
+ $run(() => {
33
+ if ($props !== undefined) {
34
+ $props.visible = $state.visible;
35
+ }
36
+ });
26
37
 
27
38
  // Set the context to pass down to items
28
39
  let context: NotificationContext = {
@@ -31,24 +42,22 @@ export default function Notification($props: NotificationProps) {
31
42
  $context[NotificationContextName] = context;
32
43
 
33
44
  $mount(() => {
34
- if ($props.duration) {
35
- setTimeout(closeNotification, $props.duration);
36
- }
45
+ setTimeout(closeNotification, $props?.duration ?? defaultDuration);
37
46
  });
38
47
 
39
48
  function closeNotification() {
40
- $props.visible = false;
49
+ $state.visible = false;
41
50
 
42
- if ($props.onclose) {
43
- $props.onclose();
51
+ if ($props?.onclose) {
52
+ $props?.onclose();
44
53
  }
45
54
  }
46
55
 
47
56
  @render {
48
- @if ($props.visible) {
57
+ @if ($state.visible) {
49
58
  <div
50
- {$props.id}
51
- class={`torp-notification ${$props.class ?? ""}`.trim()}
59
+ {$props?.id}
60
+ class={`torp-notification ${$props?.class ?? ""}`.trim()}
52
61
  role="alert"
53
62
  >
54
63
  <slot />
@@ -10,9 +10,7 @@ interface NotificationCloseProps {
10
10
  /**
11
11
  * The button that a user can press to close this Notification.
12
12
  */
13
- export default function NotificationClose($props: NotificationCloseProps) {
14
- $props ??= $watch({});
15
-
13
+ export default function NotificationClose($props: NotificationCloseProps | undefined) {
16
14
  // Get stuff out of the NotificationContext
17
15
  const context = $context[NotificationContextName] as NotificationContext;
18
16
  if (!context) {
@@ -26,8 +24,8 @@ export default function NotificationClose($props: NotificationCloseProps) {
26
24
 
27
25
  @render {
28
26
  <button
29
- {$props.id}
30
- class={`torp-notification-close ${$props.class ?? ""}`.trim()}
27
+ {$props?.id}
28
+ class={`torp-notification-close ${$props?.class ?? ""}`.trim()}
31
29
  type="button"
32
30
  onclick={handleClick}
33
31
  >
@@ -10,13 +10,11 @@ interface NotificationContainerProps {
10
10
  * The container for one or more Notifications, which can be used to position
11
11
  * the notifications inside the viewport.
12
12
  */
13
- export default function NotificationContainer($props: NotificationContainerProps) {
14
- $props ??= $watch({});
15
-
13
+ export default function NotificationContainer($props: NotificationContainerProps | undefined) {
16
14
  @render {
17
15
  <div
18
- {$props.id}
19
- class={`torp-notification-container ${$props.class ?? ""}`.trim()}
16
+ {$props?.id}
17
+ class={`torp-notification-container ${$props?.class ?? ""}`.trim()}
20
18
  >
21
19
  <slot />
22
20
  </div>
@@ -9,13 +9,11 @@ interface NotificationContentProps {
9
9
  /**
10
10
  * The content to display within a Notification.
11
11
  */
12
- export default function NotificationContent($props: NotificationContentProps) {
13
- $props ??= $watch({});
14
-
12
+ export default function NotificationContent($props: NotificationContentProps | undefined) {
15
13
  @render {
16
14
  <div
17
- {$props.id}
18
- class={`torp-notification-content ${$props.class ?? ""}`.trim()}
15
+ {$props?.id}
16
+ class={`torp-notification-content ${$props?.class ?? ""}`.trim()}
19
17
  >
20
18
  <slot />
21
19
  </div>
@@ -23,7 +23,7 @@ interface NotificationProps {
23
23
  declare function Notification(
24
24
  $parent: ParentNode,
25
25
  $anchor: Node | null,
26
- $props: NotificationProps,
26
+ $props: NotificationProps | undefined,
27
27
  $context?: Record<PropertyKey, any>,
28
28
  $slots?: Record<string, SlotRender>,
29
29
  ): void;
@@ -43,7 +43,7 @@ interface NotificationCloseProps {
43
43
  declare function NotificationClose(
44
44
  $parent: ParentNode,
45
45
  $anchor: Node | null,
46
- $props: NotificationCloseProps,
46
+ $props: NotificationCloseProps | undefined,
47
47
  $context?: Record<PropertyKey, any>,
48
48
  $slots?: Record<string, SlotRender>,
49
49
  ): void;
@@ -64,7 +64,7 @@ interface NotificationContainerProps {
64
64
  declare function NotificationContainer(
65
65
  $parent: ParentNode,
66
66
  $anchor: Node | null,
67
- $props: NotificationContainerProps,
67
+ $props: NotificationContainerProps | undefined,
68
68
  $context?: Record<PropertyKey, any>,
69
69
  $slots?: Record<string, SlotRender>,
70
70
  ): void;
@@ -84,7 +84,7 @@ interface NotificationContentProps {
84
84
  declare function NotificationContent(
85
85
  $parent: ParentNode,
86
86
  $anchor: Node | null,
87
- $props: NotificationContentProps,
87
+ $props: NotificationContentProps | undefined,
88
88
  $context?: Record<PropertyKey, any>,
89
89
  $slots?: Record<string, SlotRender>,
90
90
  ): void;