@torpor/ui 0.1.7 → 0.2.1

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 (313) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/Accordion/Accordion.torp +25 -13
  3. package/dist/Accordion/AccordionContent.torp +15 -8
  4. package/dist/Accordion/AccordionHeader.torp +16 -7
  5. package/dist/Accordion/AccordionItem.torp +24 -10
  6. package/dist/Accordion/AccordionTrigger.torp +16 -8
  7. package/dist/Accordion/AccordionTypes.ts +2 -0
  8. package/dist/Accordion/index.d.ts +157 -0
  9. package/dist/Breadcrumb/Breadcrumb.torp +42 -0
  10. package/dist/Breadcrumb/BreadcrumbItem.torp +28 -0
  11. package/dist/Breadcrumb/BreadcrumbSeparator.torp +25 -0
  12. package/dist/Breadcrumb/index.d.ts +84 -0
  13. package/dist/Breadcrumb/index.js +14 -0
  14. package/dist/Calendar/Calendar.torp +273 -0
  15. package/dist/Calendar/CalendarDay.torp +75 -0
  16. package/dist/Calendar/CalendarTypes.ts +22 -0
  17. package/dist/Calendar/index.d.ts +36 -0
  18. package/dist/Calendar/index.js +10 -0
  19. package/dist/Calendar/index.js.map +1 -0
  20. package/dist/Dialog/Dialog.torp +16 -6
  21. package/dist/Dialog/DialogBody.torp +13 -5
  22. package/dist/Dialog/DialogButton.torp +18 -6
  23. package/dist/Dialog/DialogFooter.torp +13 -3
  24. package/dist/Dialog/DialogHeader.torp +13 -4
  25. package/dist/Dialog/index.d.ts +135 -0
  26. package/dist/Disclosure/Disclosure.torp +79 -0
  27. package/dist/Disclosure/DisclosureContent.torp +43 -0
  28. package/dist/Disclosure/DisclosureHeader.torp +43 -0
  29. package/dist/Disclosure/DisclosureTrigger.torp +44 -0
  30. package/dist/Disclosure/DisclosureTypes.ts +14 -0
  31. package/dist/Disclosure/index.d.ts +113 -0
  32. package/dist/Disclosure/index.js +18 -0
  33. package/dist/Disclosure/index.js.map +1 -0
  34. package/{src/Offscreen/Offscreen.torp → dist/Drawer/Drawer.torp} +20 -19
  35. package/dist/Drawer/index.d.ts +21 -0
  36. package/dist/Drawer/index.js +6 -0
  37. package/dist/Drawer/index.js.map +1 -0
  38. package/dist/Form/Field.torp +93 -0
  39. package/dist/Form/Form.torp +131 -0
  40. package/dist/Form/FormTypes.ts +30 -0
  41. package/dist/Form/Input.torp +94 -0
  42. package/dist/Form/Label.torp +31 -0
  43. package/dist/Form/Message.torp +35 -0
  44. package/dist/Form/StandardSchemaV1.ts +70 -0
  45. package/dist/Form/index.d.ts +117 -0
  46. package/dist/Form/index.js +22 -0
  47. package/dist/Form/index.js.map +1 -0
  48. package/dist/Menu/Menu.torp +169 -0
  49. package/dist/Menu/MenuButton.torp +64 -0
  50. package/dist/Menu/MenuCheck.torp +81 -0
  51. package/dist/Menu/MenuGroup.torp +29 -0
  52. package/dist/Menu/MenuIndicator.torp +38 -0
  53. package/dist/Menu/MenuPopout.torp +82 -0
  54. package/dist/Menu/MenuPopoutContent.torp +83 -0
  55. package/dist/Menu/MenuPopoutTrigger.torp +126 -0
  56. package/dist/Menu/MenuRadio.torp +99 -0
  57. package/dist/Menu/MenuRadioGroup.torp +97 -0
  58. package/dist/Menu/MenuSeparator.torp +24 -0
  59. package/dist/Menu/MenuTypes.ts +58 -0
  60. package/dist/Menu/index.d.ts +293 -0
  61. package/dist/Menu/index.js +46 -0
  62. package/dist/Menu/index.js.map +1 -0
  63. package/dist/MenuBar/MenuBar.torp +159 -0
  64. package/dist/MenuBar/MenuBarItem.torp +115 -0
  65. package/dist/MenuBar/MenuBarItemContent.torp +117 -0
  66. package/dist/MenuBar/MenuBarItemTrigger.torp +98 -0
  67. package/dist/MenuBar/MenuBarTypes.ts +36 -0
  68. package/dist/MenuBar/index.d.ts +125 -0
  69. package/dist/MenuBar/index.js +18 -0
  70. package/dist/MenuBar/index.js.map +1 -0
  71. package/dist/NavMenu/NavMenu.torp +15 -6
  72. package/dist/NavMenu/NavMenuButton.torp +14 -7
  73. package/dist/NavMenu/NavMenuElement.torp +16 -8
  74. package/dist/NavMenu/NavMenuGroup.torp +14 -5
  75. package/dist/NavMenu/NavMenuGroupHeader.torp +14 -6
  76. package/dist/NavMenu/NavMenuLink.torp +18 -10
  77. package/dist/NavMenu/NavMenuPopout.torp +13 -5
  78. package/dist/NavMenu/NavMenuPopoutButton.torp +17 -11
  79. package/dist/NavMenu/NavMenuPopoutContent.torp +42 -30
  80. package/dist/NavMenu/NavMenuSeparator.torp +12 -3
  81. package/dist/NavMenu/index.d.ts +259 -0
  82. package/dist/Notification/Notification.torp +58 -0
  83. package/dist/Notification/NotificationClose.torp +37 -0
  84. package/dist/Notification/NotificationContainer.torp +24 -0
  85. package/dist/Notification/NotificationContent.torp +23 -0
  86. package/dist/Notification/NotificationTypes.ts +5 -0
  87. package/dist/Notification/index.d.ts +92 -0
  88. package/dist/Notification/index.js +36 -0
  89. package/dist/Notification/index.js.map +1 -0
  90. package/dist/Notification/showNotification.ts +30 -0
  91. package/dist/Popover/Popover.torp +22 -8
  92. package/dist/Popover/PopoverContent.torp +41 -29
  93. package/dist/Popover/PopoverContentAnchored.torp +52 -44
  94. package/dist/Popover/PopoverContentContextual.torp +49 -37
  95. package/dist/Popover/PopoverOverlay.torp +13 -4
  96. package/dist/Popover/PopoverTrigger.torp +12 -3
  97. package/dist/Popover/PopoverTriggerContextual.torp +12 -3
  98. package/dist/Popover/PopoverTriggerHover.torp +14 -5
  99. package/dist/Popover/index.d.ts +191 -0
  100. package/dist/TabGroup/TabContent.torp +13 -7
  101. package/dist/TabGroup/TabGroup.torp +23 -11
  102. package/dist/TabGroup/TabHeader.torp +16 -7
  103. package/dist/TabGroup/TabList.torp +15 -6
  104. package/dist/TabGroup/TabTrigger.torp +14 -6
  105. package/dist/TabGroup/index.d.ts +150 -0
  106. package/dist/icons/ArrowDown.torp +15 -0
  107. package/dist/icons/ArrowLeft.torp +15 -0
  108. package/dist/icons/ArrowRight.torp +15 -0
  109. package/dist/icons/ArrowUp.torp +15 -0
  110. package/dist/icons/Bars.torp +17 -0
  111. package/dist/icons/Check.torp +15 -0
  112. package/dist/icons/ChevronDown.torp +15 -0
  113. package/dist/icons/ChevronLeft.torp +15 -0
  114. package/dist/icons/ChevronRight.torp +15 -0
  115. package/dist/icons/ChevronUp.torp +15 -0
  116. package/dist/icons/Cross.torp +16 -0
  117. package/dist/icons/Loading.torp +16 -0
  118. package/dist/icons/Minus.torp +15 -0
  119. package/dist/icons/Plus.torp +16 -0
  120. package/dist/icons/index.d.ts +142 -0
  121. package/dist/icons/index.js +58 -0
  122. package/dist/icons/index.js.map +1 -0
  123. package/dist/{motion.d.cts → index.d.ts} +2 -2
  124. package/dist/metafile-esm.json +1 -1
  125. package/dist/motion/fade.ts +7 -0
  126. package/dist/motion/index.d.ts +2 -0
  127. package/dist/{motion.js → motion/index.js} +1 -1
  128. package/dist/motion/index.js.map +1 -0
  129. package/dist/mount/index.d.ts +2 -0
  130. package/dist/utils/dateUtils.ts +244 -0
  131. package/dist/utils/index.d.ts +2 -0
  132. package/dist/utils/setPopoverPosition.ts +4 -0
  133. package/package.json +60 -35
  134. package/scripts/postbuild.ts +42 -5
  135. package/src/Accordion/Accordion.torp +25 -13
  136. package/src/Accordion/AccordionContent.torp +15 -8
  137. package/src/Accordion/AccordionHeader.torp +16 -7
  138. package/src/Accordion/AccordionItem.torp +24 -10
  139. package/src/Accordion/AccordionTrigger.torp +16 -8
  140. package/src/Accordion/AccordionTypes.ts +2 -0
  141. package/src/Breadcrumb/Breadcrumb.torp +42 -0
  142. package/src/Breadcrumb/BreadcrumbItem.torp +28 -0
  143. package/src/Breadcrumb/BreadcrumbSeparator.torp +25 -0
  144. package/src/Breadcrumb/index.ts +5 -0
  145. package/src/Calendar/Calendar.torp +273 -0
  146. package/src/Calendar/CalendarDay.torp +75 -0
  147. package/src/Calendar/CalendarTypes.ts +22 -0
  148. package/src/Calendar/index.ts +4 -0
  149. package/src/Dialog/Dialog.torp +16 -6
  150. package/src/Dialog/DialogBody.torp +13 -5
  151. package/src/Dialog/DialogButton.torp +18 -6
  152. package/src/Dialog/DialogFooter.torp +13 -3
  153. package/src/Dialog/DialogHeader.torp +13 -4
  154. package/src/Disclosure/Disclosure.torp +79 -0
  155. package/src/Disclosure/DisclosureContent.torp +43 -0
  156. package/src/Disclosure/DisclosureHeader.torp +43 -0
  157. package/src/Disclosure/DisclosureTrigger.torp +44 -0
  158. package/src/Disclosure/DisclosureTypes.ts +14 -0
  159. package/src/Disclosure/index.ts +6 -0
  160. package/{dist/Offscreen/Offscreen.torp → src/Drawer/Drawer.torp} +20 -19
  161. package/src/Drawer/index.ts +3 -0
  162. package/src/Form/Field.torp +93 -0
  163. package/src/Form/Form.torp +131 -0
  164. package/src/Form/FormTypes.ts +30 -0
  165. package/src/Form/Input.torp +94 -0
  166. package/src/Form/Label.torp +31 -0
  167. package/src/Form/Message.torp +35 -0
  168. package/src/Form/StandardSchemaV1.ts +70 -0
  169. package/src/Form/index.ts +7 -0
  170. package/src/Menu/Menu.torp +169 -0
  171. package/src/Menu/MenuButton.torp +64 -0
  172. package/src/Menu/MenuCheck.torp +81 -0
  173. package/src/Menu/MenuGroup.torp +29 -0
  174. package/src/Menu/MenuIndicator.torp +38 -0
  175. package/src/Menu/MenuPopout.torp +82 -0
  176. package/src/Menu/MenuPopoutContent.torp +83 -0
  177. package/src/Menu/MenuPopoutTrigger.torp +126 -0
  178. package/src/Menu/MenuRadio.torp +99 -0
  179. package/src/Menu/MenuRadioGroup.torp +97 -0
  180. package/src/Menu/MenuSeparator.torp +24 -0
  181. package/src/Menu/MenuTypes.ts +58 -0
  182. package/src/Menu/index.ts +25 -0
  183. package/src/MenuBar/MenuBar.torp +159 -0
  184. package/src/MenuBar/MenuBarItem.torp +115 -0
  185. package/src/MenuBar/MenuBarItemContent.torp +117 -0
  186. package/src/MenuBar/MenuBarItemTrigger.torp +98 -0
  187. package/src/MenuBar/MenuBarTypes.ts +36 -0
  188. package/src/MenuBar/index.ts +6 -0
  189. package/src/NavMenu/NavMenu.torp +15 -6
  190. package/src/NavMenu/NavMenuButton.torp +14 -7
  191. package/src/NavMenu/NavMenuElement.torp +16 -8
  192. package/src/NavMenu/NavMenuGroup.torp +14 -5
  193. package/src/NavMenu/NavMenuGroupHeader.torp +14 -6
  194. package/src/NavMenu/NavMenuLink.torp +18 -10
  195. package/src/NavMenu/NavMenuPopout.torp +13 -5
  196. package/src/NavMenu/NavMenuPopoutButton.torp +17 -11
  197. package/src/NavMenu/NavMenuPopoutContent.torp +42 -30
  198. package/src/NavMenu/NavMenuSeparator.torp +12 -3
  199. package/src/Notification/Notification.torp +58 -0
  200. package/src/Notification/NotificationClose.torp +37 -0
  201. package/src/Notification/NotificationContainer.torp +24 -0
  202. package/src/Notification/NotificationContent.torp +23 -0
  203. package/src/Notification/NotificationTypes.ts +5 -0
  204. package/src/Notification/index.ts +13 -0
  205. package/src/Notification/showNotification.ts +30 -0
  206. package/src/Popover/Popover.torp +22 -8
  207. package/src/Popover/PopoverContent.torp +41 -29
  208. package/src/Popover/PopoverContentAnchored.torp +52 -44
  209. package/src/Popover/PopoverContentContextual.torp +49 -37
  210. package/src/Popover/PopoverOverlay.torp +13 -4
  211. package/src/Popover/PopoverTrigger.torp +12 -3
  212. package/src/Popover/PopoverTriggerContextual.torp +12 -3
  213. package/src/Popover/PopoverTriggerHover.torp +14 -5
  214. package/src/Slider/Slider.torp +83 -0
  215. package/src/Slider/index.ts +3 -0
  216. package/src/TabGroup/TabContent.torp +13 -7
  217. package/src/TabGroup/TabGroup.torp +23 -11
  218. package/src/TabGroup/TabHeader.torp +16 -7
  219. package/src/TabGroup/TabList.torp +15 -6
  220. package/src/TabGroup/TabTrigger.torp +14 -6
  221. package/src/icons/ArrowDown.torp +15 -0
  222. package/src/icons/ArrowLeft.torp +15 -0
  223. package/src/icons/ArrowRight.torp +15 -0
  224. package/src/icons/ArrowUp.torp +15 -0
  225. package/src/icons/Bars.torp +17 -0
  226. package/src/icons/Check.torp +15 -0
  227. package/src/icons/ChevronDown.torp +15 -0
  228. package/src/icons/ChevronLeft.torp +15 -0
  229. package/src/icons/ChevronRight.torp +15 -0
  230. package/src/icons/ChevronUp.torp +15 -0
  231. package/src/icons/Cross.torp +16 -0
  232. package/src/icons/Loading.torp +16 -0
  233. package/src/icons/Minus.torp +15 -0
  234. package/src/icons/Plus.torp +16 -0
  235. package/src/icons/index.ts +31 -0
  236. package/src/motion/fade.ts +2 -2
  237. package/src/motion/index.ts +3 -0
  238. package/src/utils/dateUtils.ts +244 -0
  239. package/src/utils/setPopoverPosition.ts +4 -0
  240. package/test/Accordion/components/AccordionAccessibility.torp +2 -0
  241. package/test/Accordion/components/AccordionKeyboard.torp +2 -0
  242. package/test/Accordion/components/AccordionList.torp +2 -0
  243. package/test/Accordion/components/AccordionMultiple.torp +2 -0
  244. package/test/Accordion/components/AccordionSingle.torp +2 -0
  245. package/test/Breadcrumb/accessibility.test.ts +29 -0
  246. package/test/Breadcrumb/basic.test.ts +17 -0
  247. package/test/Breadcrumb/components/BreadcrumbTest.torp +15 -0
  248. package/test/Calendar/components/CalendarTest.torp +9 -0
  249. package/test/Calendar/default.test.ts +18 -0
  250. package/test/Dialog/components/DialogAccessibility.torp +5 -5
  251. package/test/Disclosure/accessibility.test.ts +31 -0
  252. package/test/Disclosure/components/DisclosureTest.torp +19 -0
  253. package/test/Disclosure/default.test.ts +15 -0
  254. package/test/Disclosure/toggle.test.ts +20 -0
  255. package/test/Form/components/FieldTest.torp +25 -0
  256. package/test/Form/components/FormTest.torp +31 -0
  257. package/test/Form/components/InputTest.torp +9 -0
  258. package/test/Form/field.test.ts +34 -0
  259. package/test/Form/form.test.ts +34 -0
  260. package/test/Form/input.test.ts +19 -0
  261. package/test/Menu/accessibility.test.ts +83 -0
  262. package/test/Menu/basic.test.ts +58 -0
  263. package/test/Menu/components/MenuAccessibility.torp +59 -0
  264. package/test/Menu/components/MenuBasic.torp +58 -0
  265. package/test/MenuBar/accessibility.test.ts +87 -0
  266. package/test/MenuBar/basic.test.ts +22 -0
  267. package/test/MenuBar/components/MenuBarAccessibility.torp +34 -0
  268. package/test/MenuBar/components/MenuBarBasic.torp +25 -0
  269. package/test/NavMenu/basic.test.ts +1 -1
  270. package/test/NavMenu/components/{NavMenu.torp → NavMenuBasic.torp} +1 -1
  271. package/test/Notification/accessibility.test.ts +21 -0
  272. package/test/Notification/components/CustomNotification.torp +14 -0
  273. package/test/Notification/components/NotificationAccessibility.torp +14 -0
  274. package/test/Notification/components/NotificationFunction.torp +20 -0
  275. package/test/Notification/components/NotificationVariable.torp +22 -0
  276. package/test/Notification/function.test.ts +25 -0
  277. package/test/Notification/variable.test.ts +25 -0
  278. package/test/Popover/components/CustomDialog.torp +25 -0
  279. package/test/Popover/components/PromptFunction.torp +19 -0
  280. package/test/Popover/components/PromptVariable.torp +38 -0
  281. package/test/Popover/function.test.ts +26 -0
  282. package/test/Popover/variable.test.ts +27 -0
  283. package/test/TabGroup/components/TabGroupAccessibility.torp +2 -0
  284. package/test/TabGroup/components/TabGroupKeyboard.torp +2 -0
  285. package/test/TabGroup/components/TabGroupList.torp +2 -0
  286. package/test/TabGroup/components/TabGroupTrigger.torp +2 -0
  287. package/tsup.config.ts +12 -4
  288. package/dist/Accordion/index.cjs +0 -53
  289. package/dist/Accordion/index.cjs.map +0 -1
  290. package/dist/Dialog/index.cjs +0 -53
  291. package/dist/Dialog/index.cjs.map +0 -1
  292. package/dist/NavMenu/index.cjs +0 -78
  293. package/dist/NavMenu/index.cjs.map +0 -1
  294. package/dist/Offscreen/index.cjs +0 -33
  295. package/dist/Offscreen/index.cjs.map +0 -1
  296. package/dist/Offscreen/index.js +0 -6
  297. package/dist/Popover/index.cjs +0 -222
  298. package/dist/Popover/index.cjs.map +0 -1
  299. package/dist/TabGroup/index.cjs +0 -53
  300. package/dist/TabGroup/index.cjs.map +0 -1
  301. package/dist/metafile-cjs.json +0 -1
  302. package/dist/motion.cjs +0 -34
  303. package/dist/motion.cjs.map +0 -1
  304. package/dist/motion.d.ts +0 -6
  305. package/dist/motion.js.map +0 -1
  306. package/src/Accordion.ts +0 -7
  307. package/src/Dialog.ts +0 -7
  308. package/src/NavMenu.ts +0 -23
  309. package/src/Offscreen/index.ts +0 -3
  310. package/src/Popover.ts +0 -29
  311. package/src/TabGroup.ts +0 -7
  312. package/src/motion.ts +0 -3
  313. /package/dist/{Offscreen → Breadcrumb}/index.js.map +0 -0
@@ -1,5 +1,14 @@
1
1
  import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTypes";
2
2
 
3
+ interface NavMenuPopoutProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Class name(s) for the root element */
7
+ class?: string,
8
+ /** Whether the popout is visible */
9
+ visible?: boolean,
10
+ }
11
+
3
12
  /**
4
13
  * A popout that is attached to a menu button and can be used to show a submenu.
5
14
  *
@@ -11,10 +20,9 @@ import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTy
11
20
  * <NavMenuPopoutContent />
12
21
  * </NavMenuPopout>
13
22
  * ```
14
- *
15
- * @prop {boolean} visible -- Whether the popout is visible
16
23
  */
17
- export default function NavMenuPopout($props: any) {
24
+ export default function NavMenuPopout($props: NavMenuPopoutProps) {
25
+ $props ??= $watch({});
18
26
  $props.visible ??= false;
19
27
 
20
28
  let $state = $watch({
@@ -59,11 +67,11 @@ export default function NavMenuPopout($props: any) {
59
67
 
60
68
  @render {
61
69
  <div
62
- id={$props.id}
70
+ {$props.id}
63
71
  class={`torp-nav-menu-popout ${$props.class ?? ""}`.trim()}
64
72
  onmouseleave={handleMouseLeave}
65
73
  >
66
- <:slot />
74
+ <slot />
67
75
  </div>
68
76
  }
69
77
  }
@@ -1,4 +1,3 @@
1
-
2
1
  import {
3
2
  NavMenuContextName,
4
3
  NavMenuPopoutContextName,
@@ -6,18 +5,25 @@ import {
6
5
  type NavMenuPopoutContext,
7
6
  } from "./NavMenuTypes";
8
7
 
8
+ interface NavMenuPopoutButtonProps {
9
+ /** An ID for the root element */
10
+ id?: string;
11
+ /** Class name(s) for the root element */
12
+ class?: string,
13
+ /** The delay before showing the popout, in milliseconds */
14
+ hoverDelay?: number,
15
+ /** Whether this button is disabled */
16
+ disabled?: boolean,
17
+ }
18
+
9
19
  /**
10
20
  * A button that is placed in a NavMenu and signals a response by a user.
11
21
  *
12
- * @prop {number} hoverDelay -- The delay before showing the popout, in milliseconds
13
- * @prop {boolean} disabled -- Whether this button is disabled
14
22
  */
15
- export default function NavMenuPopoutButton($props: any) {
23
+ export default function NavMenuPopoutButton($props: NavMenuPopoutButtonProps) {
24
+ $props ??= $watch({});
16
25
  $props.hoverDelay ??= 500;
17
26
 
18
- /** Set when the item is disabled */
19
- let dataDisabled = $props.disabled || undefined;
20
-
21
27
  let button: HTMLButtonElement;
22
28
  let interval: NodeJS.Timeout | undefined;
23
29
 
@@ -96,7 +102,7 @@ export default function NavMenuPopoutButton($props: any) {
96
102
 
97
103
  @render {
98
104
  <button
99
- id={$props.id}
105
+ {$props.id}
100
106
  class={`torp-nav-menu-popout-button ${$props.class ?? ""}`.trim()}
101
107
  type="button"
102
108
  {$props.disabled}
@@ -104,7 +110,7 @@ export default function NavMenuPopoutButton($props: any) {
104
110
  aria-haspopup="true"
105
111
  aria-expanded={$state.visible.toString()}
106
112
  aria-disabled={$props.disabled ? "true" : undefined}
107
- data-disabled={dataDisabled}
113
+ data-disabled={$state.disabled ? "true" : undefined}
108
114
  onkeydown={handlePopoutKey}
109
115
  onclick={handleClick}
110
116
  onfocus={() => handleItemFocus(index)}
@@ -112,9 +118,9 @@ export default function NavMenuPopoutButton($props: any) {
112
118
  onmouseleave={handleMouseLeave}
113
119
  onmousemove={handleMouseMove}
114
120
  &ref={button}
115
- :onmount={(el) => popoutContext.anchorElement = el }
121
+ onmount={(el) => popoutContext.anchorElement = el }
116
122
  >
117
- <:slot />
123
+ <slot />
118
124
  </button>
119
125
  }
120
126
  }
@@ -3,17 +3,28 @@ import getScrollParent from "../utils/getScrollParent";
3
3
  import setPopoverPosition from "../utils/setPopoverPosition";
4
4
  import { NavMenuPopoutContextName, type NavMenuPopoutContext } from "./NavMenuTypes";
5
5
 
6
+ interface NavMenuPopoutContentProps {
7
+ /** An ID for the root element */
8
+ id?: string;
9
+ /** Class name(s) for the root element */
10
+ class?: string,
11
+ /** Where the popout will be shown, relative to the popout button */
12
+ side?: "top" | "right" | "bottom" | "left",
13
+ /** How the popout will be aligned, relative to the popout button */
14
+ alignment?: "start" | "center" | "end",
15
+ }
16
+
6
17
  /**
7
18
  * The content that is displayed for a NavMenuPopout when it is open.
8
19
  *
9
- * @prop {"top" | "right" | "bottom" | "left"} side -- Where the popout will be shown, relative to the popout button
10
- * @prop {"start" | "center" | "end"} alignment -- How the popout will be aligned, relative to the popout button
11
20
  */
12
- export default function NavMenuPopoutContent($props: any) {
21
+ export default function NavMenuPopoutContent($props: NavMenuPopoutContentProps) {
22
+ $props ??= $watch({});
13
23
  $props.side ??= "bottom";
14
24
  $props.alignment ??= "start";
15
25
 
16
26
  let div: HTMLDivElement;
27
+ let shown = false;
17
28
 
18
29
  // Get stuff out of the NavMenuPopoutContext
19
30
  const context = $context[NavMenuPopoutContextName] as NavMenuPopoutContext;
@@ -22,35 +33,36 @@ export default function NavMenuPopoutContent($props: any) {
22
33
  }
23
34
  let $state = context.state;
24
35
 
25
- let first = true;
26
36
  $run(() => {
27
- let visible = $state.visible;
37
+ if (!$state.visible) {
38
+ hide();
39
+ }
40
+ });
41
+
42
+ function show() {
43
+ shown = true;
28
44
 
29
- if (first) {
30
- first = false;
31
- return;
45
+ // Set the position and listen for window resize and scroll to reset the position
46
+ setPosition();
47
+ const scrollParent = getScrollParent(context.anchorElement)
48
+ scrollParent.addEventListener("resize", setPosition);
49
+ scrollParent.addEventListener("scroll", setPosition);
50
+ if (context.focusFirstElement) {
51
+ context.focusFirstElement();
32
52
  }
53
+ }
54
+
55
+ function hide() {
56
+ if (!shown) return;
33
57
 
34
- if (visible) {
35
- // Wait for the content div to be shown, set its position, and listen for window resize to re-position
36
- //await tick();
37
- setPosition();
38
- if (context.focusFirstElement) {
39
- context.focusFirstElement();
40
- }
41
- const scrollParent = getScrollParent(context.anchorElement)
42
- scrollParent.addEventListener("resize", setPosition);
43
- scrollParent.addEventListener("scroll", setPosition);
44
- } else {
45
- // Stop listening for window resize and focus the anchor element per WAI guidelines
46
- const scrollParent = getScrollParent(context.anchorElement)
47
- scrollParent.removeEventListener("resize", setPosition);
48
- scrollParent.removeEventListener("scroll", setPosition);
49
- if (context.anchorElement?.focus) {
50
- context.anchorElement.focus();
51
- }
58
+ // Stop listening for window resize and focus the anchor element per WAI guidelines
59
+ const scrollParent = getScrollParent(context.anchorElement)
60
+ scrollParent.removeEventListener("resize", setPosition);
61
+ scrollParent.removeEventListener("scroll", setPosition);
62
+ if (context.anchorElement?.focus) {
63
+ context.anchorElement.focus();
52
64
  }
53
- });
65
+ }
54
66
 
55
67
  function setPosition() {
56
68
  if (!context.anchorElement) {
@@ -65,12 +77,12 @@ export default function NavMenuPopoutContent($props: any) {
65
77
  @render {
66
78
  @if ($state.visible) {
67
79
  <div
68
- id={$props.id}
80
+ {$props.id}
69
81
  class={`torp-nav-menu-popout-content ${$props.class ?? ""}`.trim()}
70
82
  &ref={div}
71
- :onmount={(el) => setPopoverPosition(context.anchorElement, el, $props.side, $props.alignment)}
83
+ onmount={show}
72
84
  >
73
- <:slot />
85
+ <slot />
74
86
  </div>
75
87
  }
76
88
  }
@@ -1,14 +1,23 @@
1
1
 
2
+ interface NavMenuSeparatorProps {
3
+ /** An ID for the root element */
4
+ id?: string;
5
+ /** Class name(s) for the root element */
6
+ class?: string,
7
+ }
8
+
2
9
  /**
3
10
  * An element in a menu that separates logical sets of menu items.
4
11
  */
5
- export default function NavMenuSeparator($props: any) {
12
+ export default function NavMenuSeparator($props: NavMenuSeparatorProps) {
13
+ $props ??= $watch({});
14
+
6
15
  @render {
7
16
  <div
8
- id={$props.id}
17
+ {$props.id}
9
18
  class={`torp-nav-menu-separator ${$props.class ?? ""}`.trim()} role="separator"
10
19
  >
11
- <:slot />
20
+ <slot />
12
21
  </div>
13
22
  }
14
23
  }
@@ -0,0 +1,58 @@
1
+ import { NotificationContextName, type NotificationContext } from "./NotificationTypes";
2
+
3
+ interface NotificationProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Class name(s) for the root element */
7
+ class?: string,
8
+ /** Whether the notification is visible */
9
+ visible?: boolean,
10
+ /** The duration, in milliseconds, to keep the notification visible */
11
+ duration?: number,
12
+ /** Raised when the notification has closed, either after the duration has elapsed, or when the user has pressed the close button */
13
+ onclose?: () => void,
14
+ }
15
+
16
+ /**
17
+ * An element that displays a brief, important message in a way that attracts
18
+ * the user's attention without interrupting the user's task.
19
+ *
20
+ * See [the WAI ARIA guidelines for Alerts](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).
21
+ */
22
+ export default function Notification($props: NotificationProps) {
23
+ $props ??= $watch({});
24
+ $props.visible ??= true;
25
+ $props.duration ??= 5000;
26
+
27
+ // Set the context to pass down to items
28
+ let context: NotificationContext = {
29
+ closeNotification
30
+ };
31
+ $context[NotificationContextName] = context;
32
+
33
+ $mount(() => {
34
+ if ($props.duration) {
35
+ setTimeout(closeNotification, $props.duration);
36
+ }
37
+ });
38
+
39
+ function closeNotification() {
40
+ $props.visible = false;
41
+
42
+ if ($props.onclose) {
43
+ $props.onclose();
44
+ }
45
+ }
46
+
47
+ @render {
48
+ @if ($props.visible) {
49
+ <div
50
+ {$props.id}
51
+ class={`torp-notification ${$props.class ?? ""}`.trim()}
52
+ role="alert"
53
+ >
54
+ <slot />
55
+ </div>
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,37 @@
1
+ import { NotificationContextName, type NotificationContext } from "./NotificationTypes";
2
+
3
+ interface NotificationCloseProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Class name(s) for the root element */
7
+ class?: string,
8
+ }
9
+
10
+ /**
11
+ * The button that a user can press to close this Notification.
12
+ */
13
+ export default function NotificationClose($props: NotificationCloseProps) {
14
+ $props ??= $watch({});
15
+
16
+ // Get stuff out of the NotificationContext
17
+ const context = $context[NotificationContextName] as NotificationContext;
18
+ if (!context) {
19
+ throw new Error("NotificationClose must be contained within a Notification");
20
+ }
21
+ const { closeNotification } = context;
22
+
23
+ function handleClick() {
24
+ closeNotification();
25
+ }
26
+
27
+ @render {
28
+ <button
29
+ {$props.id}
30
+ class={`torp-notification-close ${$props.class ?? ""}`.trim()}
31
+ type="button"
32
+ onclick={handleClick}
33
+ >
34
+ <slot />
35
+ </button>
36
+ }
37
+ }
@@ -0,0 +1,24 @@
1
+
2
+ interface NotificationContainerProps {
3
+ /** An ID for the root element */
4
+ id?: string;
5
+ /** Class name(s) for the root element */
6
+ class?: string,
7
+ }
8
+
9
+ /**
10
+ * The container for one or more Notifications, which can be used to position
11
+ * the notifications inside the viewport.
12
+ */
13
+ export default function NotificationContainer($props: NotificationContainerProps) {
14
+ $props ??= $watch({});
15
+
16
+ @render {
17
+ <div
18
+ {$props.id}
19
+ class={`torp-notification-container ${$props.class ?? ""}`.trim()}
20
+ >
21
+ <slot />
22
+ </div>
23
+ }
24
+ }
@@ -0,0 +1,23 @@
1
+
2
+ interface NotificationContentProps {
3
+ /** An ID for the root element */
4
+ id?: string;
5
+ /** Class name(s) for the root element */
6
+ class?: string,
7
+ }
8
+
9
+ /**
10
+ * The content to display within a Notification.
11
+ */
12
+ export default function NotificationContent($props: NotificationContentProps) {
13
+ $props ??= $watch({});
14
+
15
+ @render {
16
+ <div
17
+ {$props.id}
18
+ class={`torp-notification-content ${$props.class ?? ""}`.trim()}
19
+ >
20
+ <slot />
21
+ </div>
22
+ }
23
+ }
@@ -0,0 +1,5 @@
1
+ export const NotificationContextName = 'Notification';
2
+
3
+ export interface NotificationContext {
4
+ closeNotification: () => void;
5
+ }
@@ -0,0 +1,13 @@
1
+ import Notification from "./Notification.torp";
2
+ import NotificationClose from "./NotificationClose.torp";
3
+ import NotificationContainer from "./NotificationContainer.torp";
4
+ import NotificationContent from "./NotificationContent.torp";
5
+ import showNotification from "./showNotification";
6
+
7
+ export {
8
+ Notification,
9
+ NotificationContainer,
10
+ NotificationContent,
11
+ NotificationClose,
12
+ showNotification,
13
+ };
@@ -0,0 +1,30 @@
1
+ import { mount } from "@torpor/view";
2
+
3
+ /**
4
+ * Shows a notification component in code.
5
+ * @param notification The notification component
6
+ * @param props The properties for the notification component
7
+ * @param target The target element to show the notification in
8
+ */
9
+ export default function showNotification(notification: any, props: any, target?: Element): void {
10
+ if (!target) {
11
+ // Put the notification in the first NotificationContainer, or the
12
+ // document body if there are no NotificationContainers
13
+ target = document.getElementsByClassName("torp-notification-container")[0];
14
+ if (!target) {
15
+ throw new Error("No notification container found");
16
+ }
17
+ }
18
+
19
+ // HACK: Should allow mounting in a non-empty container
20
+ // Move existing nodes into a fragment, and add them back after mounting
21
+ var fragment = document.createDocumentFragment();
22
+ while (target.firstChild) {
23
+ fragment.append(target.firstChild);
24
+ }
25
+
26
+ // Create the notification
27
+ mount(target, notification, props);
28
+
29
+ target.prepend(fragment);
30
+ }
@@ -1,5 +1,22 @@
1
1
  import { PopoverContextName, type Point, type PopoverContext, type PopoverState } from "./PopoverTypes";
2
2
 
3
+ interface PopoverProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Class name(s) for the root element */
7
+ class?: string,
8
+ /** Whether the popover is modal. If true, an overlay should be supplied to obscure outside content, and only the popover content will be visible to screen readers */
9
+ modal?: boolean,
10
+ /** Whether the popover is visible */
11
+ visible?: boolean,
12
+ /** The element to anchor this popover to, as an alternative to supplying a PopoverTrigger */
13
+ anchor?: HTMLElement,
14
+ /** The position to display this popover at if it's contextual, as an alternative to supplying a PopoverTriggerContextual */
15
+ position?: Point,
16
+ /** A function to be called when the user selects a response */
17
+ callback?: ((value: any) => void),
18
+ }
19
+
3
20
  /**
4
21
  * A popover that can be used to show rich content or obtain information from a user.
5
22
  *
@@ -14,13 +31,10 @@ import { PopoverContextName, type Point, type PopoverContext, type PopoverState
14
31
  * <PopoverContent/PopoverContentAnchored/PopoverContentContextual />
15
32
  * </Popover>
16
33
  * ```
17
- * @prop {boolean} modal -- Whether the popover is modal. If true, an overlay should be supplied to obscure outside content, and only the popover content will be visible to screen readers
18
- * @prop {boolean} visible -- Whether the popover is visible
19
- * @prop {HTMLElement | undefined} anchor -- The element to anchor this popover to, as an alternative to supplying a PopoverTrigger
20
- * @prop {Point | undefined} position -- The position to display this popover at if it's contextual, as an alternative to supplying a PopoverTriggerContextual
21
- * @prop {((value: any) => void) | undefined} [callback] -- A function to be called when the user selects a response
22
34
  */
23
- export default function Popover($props: any) {
35
+ export default function Popover($props: PopoverProps) {
36
+ $props ??= $watch({});
37
+
24
38
  let $state: PopoverState = $watch({
25
39
  visible: false,
26
40
  position: { x: 0, y: 0 }
@@ -96,10 +110,10 @@ export default function Popover($props: any) {
96
110
 
97
111
  @render {
98
112
  <div
99
- id={$props.id}
113
+ {$props.id}
100
114
  class={`torp-popover ${$props.class ?? ""}`.trim()}
101
115
  >
102
- <:slot />
116
+ <slot />
103
117
  </div>
104
118
  }
105
119
  }
@@ -1,12 +1,23 @@
1
1
  import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
2
2
  import { PopoverContextName, type PopoverContext } from "./PopoverTypes";
3
3
 
4
+ interface PopoverContentProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Class name(s) for the root element */
8
+ class?: string,
9
+ }
10
+
4
11
  /**
5
12
  * The content that is displayed for a Popover when it is open, such as a Dialog
6
13
  * in the middle of the screen or a div that slides in from the side.
7
14
  */
8
- export default function PopoverContent($props: any) {
15
+ export default function PopoverContent($props: PopoverContentProps) {
16
+ $props ??= $watch({});
17
+
9
18
  let div: HTMLDivElement;
19
+ let shown = false;
20
+ let closeOnClick = false;
10
21
 
11
22
  // Get stuff out of the PopoverContext
12
23
  const context = $context[PopoverContextName] as PopoverContext;
@@ -15,37 +26,37 @@ export default function PopoverContent($props: any) {
15
26
  }
16
27
  let $state = context.state;
17
28
 
18
- let closeOnClick = false;
19
-
20
- let first = true;
21
29
  $run(() => {
22
- let visible = $state.visible;
30
+ if (!$state.visible) {
31
+ hide();
32
+ }
33
+ });
23
34
 
24
- if (first) {
25
- first = false;
26
- return;
35
+ function show() {
36
+ shown = true;
37
+
38
+ // HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
39
+ // before we close on click. Otherwise the click immediately bubbles to the document
40
+ closeOnClick = false;
41
+ addDocumentEvent("mousedown", handleDocumentMouseDown);
42
+ addDocumentEvent("click", handleDocumentClick);
43
+
44
+ if (context.focusFirstElement) {
45
+ context.focusFirstElement();
27
46
  }
47
+ }
48
+
49
+ function hide() {
50
+ if (!shown) return;
28
51
 
29
- if (visible) {
30
- // HACK: Because this Popover could be shown with a click, we need to wait for another mousedown
31
- // before we close on click. Otherwise the click immediately bubbles to the document
32
- closeOnClick = false;
33
- addDocumentEvent("mousedown", handleDocumentMouseDown);
34
- addDocumentEvent("click", handleDocumentClick);
35
- // Wait for the content div to be shown, set its position, and listen for window resize to re-position
36
- //await tick();
37
- if (context.focusFirstElement) {
38
- context.focusFirstElement();
39
- }
40
- } else {
41
- removeDocumentEvent("mousedown", handleDocumentMouseDown);
42
- removeDocumentEvent("click", handleDocumentClick);
43
- // Focus the anchor element per WAI guidelines
44
- if (context.anchorElement?.focus) {
45
- context.anchorElement.focus();
46
- }
52
+ removeDocumentEvent("mousedown", handleDocumentMouseDown);
53
+ removeDocumentEvent("click", handleDocumentClick);
54
+
55
+ // Focus the anchor element per WAI guidelines
56
+ if (context.anchorElement?.focus) {
57
+ context.anchorElement.focus();
47
58
  }
48
- });
59
+ }
49
60
 
50
61
  function handleDocumentMouseDown() {
51
62
  closeOnClick = true;
@@ -65,11 +76,12 @@ export default function PopoverContent($props: any) {
65
76
  @render {
66
77
  @if ($state.visible) {
67
78
  <div
68
- id={$props.id}
79
+ {$props.id}
69
80
  class={`torp-popover-content ${$props.class ?? ""}`.trim()}
70
81
  &ref={div}
82
+ onmount={show}
71
83
  >
72
- <:slot />
84
+ <slot />
73
85
  </div>
74
86
  }
75
87
  }