@passui/react 0.0.0-stage → 0.1.14

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 (275) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -2
  3. package/package.json +96 -5
  4. package/src/appearance/index.ts +2 -0
  5. package/src/appearance/platform.tsx +123 -0
  6. package/src/appearance/theme.tsx +535 -0
  7. package/src/components/ambient/ambient.docs.tsx +68 -0
  8. package/src/components/ambient/ambient.tsx +43 -0
  9. package/src/components/ambient/examples/ambient-images.tsx +30 -0
  10. package/src/components/ambient/examples/ambient-now-playing.tsx +55 -0
  11. package/src/components/ambient/examples/ambient-showcase.tsx +33 -0
  12. package/src/components/ambient/examples/ambient-usage.tsx +19 -0
  13. package/src/components/ambient/index.ts +1 -0
  14. package/src/components/button/button-styles.ts +60 -0
  15. package/src/components/button/button.docs.tsx +116 -0
  16. package/src/components/button/button.tsx +91 -0
  17. package/src/components/button/examples/button-disabled.tsx +19 -0
  18. package/src/components/button/examples/button-icon.tsx +39 -0
  19. package/src/components/button/examples/button-link.tsx +12 -0
  20. package/src/components/button/examples/button-pending.tsx +27 -0
  21. package/src/components/button/examples/button-showcase.tsx +115 -0
  22. package/src/components/button/examples/button-sizes.tsx +12 -0
  23. package/src/components/button/examples/button-usage.tsx +12 -0
  24. package/src/components/button/examples/button-variants.tsx +15 -0
  25. package/src/components/button/examples/button-with-icon.tsx +32 -0
  26. package/src/components/button/examples/icon-button-player.tsx +38 -0
  27. package/src/components/button/examples/icon-button-showcase.tsx +83 -0
  28. package/src/components/button/examples/icon-button-usage.tsx +11 -0
  29. package/src/components/button/examples/icon-button-variants.tsx +39 -0
  30. package/src/components/button/icon-button.docs.tsx +68 -0
  31. package/src/components/button/icon-button.tsx +73 -0
  32. package/src/components/button/pending-spinner.tsx +14 -0
  33. package/src/components/button/use-pending-indicator.ts +27 -0
  34. package/src/components/chip/chip.docs.tsx +37 -0
  35. package/src/components/chip/chip.tsx +35 -0
  36. package/src/components/chip/examples/chip-in-rows.tsx +19 -0
  37. package/src/components/chip/examples/chip-showcase.tsx +51 -0
  38. package/src/components/chip/examples/chip-tones.tsx +13 -0
  39. package/src/components/chip/examples/chip-usage.tsx +5 -0
  40. package/src/components/compact-date-picker/calendar-month.ts +131 -0
  41. package/src/components/compact-date-picker/compact-date-picker.docs.tsx +81 -0
  42. package/src/components/compact-date-picker/compact-date-picker.tsx +438 -0
  43. package/src/components/compact-date-picker/examples/compact-date-picker-showcase.tsx +35 -0
  44. package/src/components/compact-date-picker/examples/compact-date-picker-usage.tsx +22 -0
  45. package/src/components/compact-time-picker/compact-time-picker.docs.tsx +80 -0
  46. package/src/components/compact-time-picker/compact-time-picker.tsx +432 -0
  47. package/src/components/compact-time-picker/examples/compact-time-picker-showcase.tsx +31 -0
  48. package/src/components/compact-time-picker/examples/compact-time-picker-usage.tsx +21 -0
  49. package/src/components/compact-time-picker/time-value.ts +67 -0
  50. package/src/components/content-view/content-view.docs.tsx +61 -0
  51. package/src/components/content-view/content-view.tsx +197 -0
  52. package/src/components/content-view/examples/content-view-header-action.tsx +33 -0
  53. package/src/components/content-view/examples/content-view-showcase.tsx +65 -0
  54. package/src/components/content-view/examples/content-view-stats.tsx +35 -0
  55. package/src/components/content-view/examples/content-view-usage.tsx +14 -0
  56. package/src/components/content-view/index.ts +1 -0
  57. package/src/components/context-menu/conceal-menu-source.ts +33 -0
  58. package/src/components/context-menu/context-menu-host.tsx +445 -0
  59. package/src/components/context-menu/context-menu-store.ts +165 -0
  60. package/src/components/context-menu/context-menu.docs.tsx +92 -0
  61. package/src/components/context-menu/examples/context-menu-checked.tsx +37 -0
  62. package/src/components/context-menu/examples/context-menu-list.tsx +85 -0
  63. package/src/components/context-menu/examples/context-menu-showcase.tsx +56 -0
  64. package/src/components/context-menu/examples/context-menu-toolbar.tsx +63 -0
  65. package/src/components/context-menu/examples/context-menu-usage.tsx +24 -0
  66. package/src/components/context-menu/menu-position.ts +55 -0
  67. package/src/components/context-menu/menu-reveal.ts +75 -0
  68. package/src/components/context-menu/use-context-menu.ts +90 -0
  69. package/src/components/conversation/conversation.docs.tsx +88 -0
  70. package/src/components/conversation/conversation.tsx +279 -0
  71. package/src/components/conversation/examples/conversation-composer.tsx +36 -0
  72. package/src/components/conversation/examples/conversation-days.tsx +48 -0
  73. package/src/components/conversation/examples/conversation-showcase.tsx +71 -0
  74. package/src/components/conversation/examples/conversation-usage.tsx +28 -0
  75. package/src/components/conversation/index.ts +1 -0
  76. package/src/components/date-picker/date-picker.docs.tsx +88 -0
  77. package/src/components/date-picker/date-picker.tsx +103 -0
  78. package/src/components/date-picker/date-value.ts +37 -0
  79. package/src/components/date-picker/examples/date-picker-locales.tsx +41 -0
  80. package/src/components/date-picker/examples/date-picker-past-only.tsx +29 -0
  81. package/src/components/date-picker/examples/date-picker-showcase.tsx +49 -0
  82. package/src/components/date-picker/examples/date-picker-usage.tsx +22 -0
  83. package/src/components/dialog/dialog-host.tsx +156 -0
  84. package/src/components/dialog/dialog-store.ts +56 -0
  85. package/src/components/dialog/dialog.docs.tsx +114 -0
  86. package/src/components/dialog/dialog.tsx +200 -0
  87. package/src/components/dialog/examples/dialog-confirm.tsx +24 -0
  88. package/src/components/dialog/examples/dialog-form.tsx +46 -0
  89. package/src/components/dialog/examples/dialog-inline.tsx +48 -0
  90. package/src/components/dialog/examples/dialog-showcase.tsx +53 -0
  91. package/src/components/dialog/examples/dialog-usage.tsx +31 -0
  92. package/src/components/dialog/index.ts +1 -0
  93. package/src/components/labeled-content/examples/labeled-content-descriptions.tsx +37 -0
  94. package/src/components/labeled-content/examples/labeled-content-showcase.tsx +54 -0
  95. package/src/components/labeled-content/examples/labeled-content-usage.tsx +22 -0
  96. package/src/components/labeled-content/examples/labeled-content-values.tsx +26 -0
  97. package/src/components/labeled-content/examples/labeled-content-wide.tsx +46 -0
  98. package/src/components/labeled-content/labeled-content.docs.tsx +69 -0
  99. package/src/components/labeled-content/labeled-content.tsx +66 -0
  100. package/src/components/locale-switcher/examples/locale-switcher-native-names.tsx +30 -0
  101. package/src/components/locale-switcher/examples/locale-switcher-showcase.tsx +46 -0
  102. package/src/components/locale-switcher/examples/locale-switcher-translated-page.tsx +35 -0
  103. package/src/components/locale-switcher/examples/locale-switcher-usage.tsx +20 -0
  104. package/src/components/locale-switcher/index.ts +1 -0
  105. package/src/components/locale-switcher/locale-switcher.docs.tsx +91 -0
  106. package/src/components/locale-switcher/locale-switcher.tsx +252 -0
  107. package/src/components/picker/examples/picker-details.tsx +44 -0
  108. package/src/components/picker/examples/picker-searchable.tsx +48 -0
  109. package/src/components/picker/examples/picker-showcase.tsx +66 -0
  110. package/src/components/picker/examples/picker-usage.tsx +20 -0
  111. package/src/components/picker/picker.docs.tsx +68 -0
  112. package/src/components/picker/picker.tsx +493 -0
  113. package/src/components/popover/examples/popover-help.tsx +57 -0
  114. package/src/components/popover/examples/popover-menu.tsx +51 -0
  115. package/src/components/popover/examples/popover-showcase.tsx +61 -0
  116. package/src/components/popover/examples/popover-usage.tsx +31 -0
  117. package/src/components/popover/popover.docs.tsx +84 -0
  118. package/src/components/popover/popover.tsx +138 -0
  119. package/src/components/profile-image/examples/profile-image-fallbacks.tsx +29 -0
  120. package/src/components/profile-image/examples/profile-image-group.tsx +34 -0
  121. package/src/components/profile-image/examples/profile-image-showcase.tsx +30 -0
  122. package/src/components/profile-image/examples/profile-image-usage.tsx +14 -0
  123. package/src/components/profile-image/profile-image.docs.tsx +81 -0
  124. package/src/components/profile-image/profile-image.tsx +80 -0
  125. package/src/components/search-field/examples/search-field-filter.tsx +53 -0
  126. package/src/components/search-field/examples/search-field-showcase.tsx +56 -0
  127. package/src/components/search-field/examples/search-field-toolbar.tsx +27 -0
  128. package/src/components/search-field/examples/search-field-usage.tsx +18 -0
  129. package/src/components/search-field/search-field.docs.tsx +58 -0
  130. package/src/components/search-field/search-field.tsx +29 -0
  131. package/src/components/search-list/examples/search-list-dropdown.tsx +53 -0
  132. package/src/components/search-list/examples/search-list-groups.tsx +64 -0
  133. package/src/components/search-list/examples/search-list-showcase.tsx +67 -0
  134. package/src/components/search-list/examples/search-list-usage.tsx +27 -0
  135. package/src/components/search-list/search-list.docs.tsx +87 -0
  136. package/src/components/search-list/search-list.tsx +265 -0
  137. package/src/components/section/examples/section-actions.tsx +35 -0
  138. package/src/components/section/examples/section-groups.tsx +41 -0
  139. package/src/components/section/examples/section-showcase.tsx +63 -0
  140. package/src/components/section/examples/section-usage.tsx +19 -0
  141. package/src/components/section/section.docs.tsx +51 -0
  142. package/src/components/section/section.tsx +41 -0
  143. package/src/components/secure-field/examples/secure-field-new-password.tsx +56 -0
  144. package/src/components/secure-field/examples/secure-field-reveal.tsx +20 -0
  145. package/src/components/secure-field/examples/secure-field-showcase.tsx +62 -0
  146. package/src/components/secure-field/examples/secure-field-usage.tsx +19 -0
  147. package/src/components/secure-field/secure-field.docs.tsx +72 -0
  148. package/src/components/secure-field/secure-field.tsx +10 -0
  149. package/src/components/segmented-control/examples/segmented-control-overflow.tsx +28 -0
  150. package/src/components/segmented-control/examples/segmented-control-showcase.tsx +59 -0
  151. package/src/components/segmented-control/examples/segmented-control-usage.tsx +20 -0
  152. package/src/components/segmented-control/examples/segmented-control-views.tsx +32 -0
  153. package/src/components/segmented-control/segmented-control.docs.tsx +61 -0
  154. package/src/components/segmented-control/segmented-control.tsx +122 -0
  155. package/src/components/sheet/examples/sheet-choices.tsx +58 -0
  156. package/src/components/sheet/examples/sheet-share.tsx +51 -0
  157. package/src/components/sheet/examples/sheet-showcase.tsx +74 -0
  158. package/src/components/sheet/examples/sheet-usage.tsx +32 -0
  159. package/src/components/sheet/modal-environment.ts +113 -0
  160. package/src/components/sheet/sheet-portal.tsx +89 -0
  161. package/src/components/sheet/sheet.docs.tsx +75 -0
  162. package/src/components/sheet/sheet.tsx +112 -0
  163. package/src/components/sheet/use-sheet-focus.ts +130 -0
  164. package/src/components/sidebar/examples/sidebar-groups.tsx +133 -0
  165. package/src/components/sidebar/examples/sidebar-showcase.tsx +123 -0
  166. package/src/components/sidebar/examples/sidebar-unread.tsx +66 -0
  167. package/src/components/sidebar/examples/sidebar-usage.tsx +52 -0
  168. package/src/components/sidebar/sidebar.docs.tsx +135 -0
  169. package/src/components/sidebar/sidebar.tsx +69 -0
  170. package/src/components/stat-tile/examples/stat-tile-filters.tsx +32 -0
  171. package/src/components/stat-tile/examples/stat-tile-grid.tsx +21 -0
  172. package/src/components/stat-tile/examples/stat-tile-showcase.tsx +52 -0
  173. package/src/components/stat-tile/examples/stat-tile-usage.tsx +13 -0
  174. package/src/components/stat-tile/index.ts +1 -0
  175. package/src/components/stat-tile/stat-tile.docs.tsx +60 -0
  176. package/src/components/stat-tile/stat-tile.tsx +68 -0
  177. package/src/components/status-indicator/examples/status-indicator-live.tsx +34 -0
  178. package/src/components/status-indicator/examples/status-indicator-showcase.tsx +39 -0
  179. package/src/components/status-indicator/examples/status-indicator-states.tsx +17 -0
  180. package/src/components/status-indicator/examples/status-indicator-usage.tsx +9 -0
  181. package/src/components/status-indicator/status-indicator.docs.tsx +43 -0
  182. package/src/components/status-indicator/status-indicator.tsx +35 -0
  183. package/src/components/swatch-picker/examples/swatch-picker-accents.tsx +42 -0
  184. package/src/components/swatch-picker/examples/swatch-picker-labels.tsx +45 -0
  185. package/src/components/swatch-picker/examples/swatch-picker-showcase.tsx +70 -0
  186. package/src/components/swatch-picker/examples/swatch-picker-usage.tsx +39 -0
  187. package/src/components/swatch-picker/swatch-picker.docs.tsx +60 -0
  188. package/src/components/swatch-picker/swatch-picker.tsx +96 -0
  189. package/src/components/tab-bar/examples/tab-bar-five-tabs.tsx +66 -0
  190. package/src/components/tab-bar/examples/tab-bar-minimize.tsx +71 -0
  191. package/src/components/tab-bar/examples/tab-bar-showcase.tsx +82 -0
  192. package/src/components/tab-bar/examples/tab-bar-usage.tsx +54 -0
  193. package/src/components/tab-bar/tab-bar.docs.tsx +136 -0
  194. package/src/components/tab-bar/tab-bar.tsx +148 -0
  195. package/src/components/tab-view/examples/tab-view-keyboard.tsx +39 -0
  196. package/src/components/tab-view/examples/tab-view-settings.tsx +56 -0
  197. package/src/components/tab-view/examples/tab-view-showcase.tsx +53 -0
  198. package/src/components/tab-view/examples/tab-view-usage.tsx +23 -0
  199. package/src/components/tab-view/tab-view.docs.tsx +77 -0
  200. package/src/components/tab-view/tab-view.tsx +117 -0
  201. package/src/components/table/examples/table-empty.tsx +53 -0
  202. package/src/components/table/examples/table-invoices.tsx +102 -0
  203. package/src/components/table/examples/table-selection.tsx +150 -0
  204. package/src/components/table/examples/table-showcase.tsx +115 -0
  205. package/src/components/table/examples/table-usage.tsx +67 -0
  206. package/src/components/table/examples/table-wide.tsx +75 -0
  207. package/src/components/table/table.docs.tsx +131 -0
  208. package/src/components/table/table.tsx +149 -0
  209. package/src/components/text-editor/examples/text-editor-comment.tsx +48 -0
  210. package/src/components/text-editor/examples/text-editor-count.tsx +38 -0
  211. package/src/components/text-editor/examples/text-editor-showcase.tsx +58 -0
  212. package/src/components/text-editor/examples/text-editor-usage.tsx +25 -0
  213. package/src/components/text-editor/text-editor.docs.tsx +61 -0
  214. package/src/components/text-editor/text-editor.tsx +19 -0
  215. package/src/components/text-field/examples/text-field-icons.tsx +72 -0
  216. package/src/components/text-field/examples/text-field-showcase.tsx +50 -0
  217. package/src/components/text-field/examples/text-field-usage.tsx +18 -0
  218. package/src/components/text-field/examples/text-field-validation.tsx +27 -0
  219. package/src/components/text-field/text-field.docs.tsx +118 -0
  220. package/src/components/text-field/text-field.tsx +135 -0
  221. package/src/components/toast/examples/toast-action.tsx +32 -0
  222. package/src/components/toast/examples/toast-promise.tsx +45 -0
  223. package/src/components/toast/examples/toast-showcase.tsx +49 -0
  224. package/src/components/toast/examples/toast-usage.tsx +13 -0
  225. package/src/components/toast/toast-store.ts +166 -0
  226. package/src/components/toast/toast.docs.tsx +79 -0
  227. package/src/components/toast/toaster.tsx +374 -0
  228. package/src/components/toggle/examples/toggle-checkboxes.tsx +43 -0
  229. package/src/components/toggle/examples/toggle-settings.tsx +31 -0
  230. package/src/components/toggle/examples/toggle-showcase.tsx +59 -0
  231. package/src/components/toggle/examples/toggle-usage.tsx +13 -0
  232. package/src/components/toggle/toggle.docs.tsx +69 -0
  233. package/src/components/toggle/toggle.tsx +85 -0
  234. package/src/components/tooltip/examples/tooltip-icon-buttons.tsx +27 -0
  235. package/src/components/tooltip/examples/tooltip-shortcuts.tsx +38 -0
  236. package/src/components/tooltip/examples/tooltip-showcase.tsx +44 -0
  237. package/src/components/tooltip/examples/tooltip-usage.tsx +13 -0
  238. package/src/components/tooltip/tooltip-host.tsx +156 -0
  239. package/src/components/tooltip/tooltip.docs.tsx +56 -0
  240. package/src/components/view-controller/examples/view-controller-action.tsx +27 -0
  241. package/src/components/view-controller/examples/view-controller-settings.tsx +31 -0
  242. package/src/components/view-controller/examples/view-controller-showcase.tsx +45 -0
  243. package/src/components/view-controller/examples/view-controller-usage.tsx +19 -0
  244. package/src/components/view-controller/index.ts +1 -0
  245. package/src/components/view-controller/view-controller.docs.tsx +71 -0
  246. package/src/components/view-controller/view-controller.tsx +81 -0
  247. package/src/docs/index.ts +3 -0
  248. package/src/docs/registry.ts +113 -0
  249. package/src/docs/snippet.ts +17 -0
  250. package/src/docs/types.ts +180 -0
  251. package/src/hooks/scroll/minimize-decision.ts +13 -0
  252. package/src/hooks/use-anchored-placement.ts +43 -0
  253. package/src/hooks/use-dismiss.ts +58 -0
  254. package/src/hooks/use-media-query.ts +106 -0
  255. package/src/hooks/use-minimize-on-scroll.ts +92 -0
  256. package/src/hooks/use-visual-viewport.ts +76 -0
  257. package/src/hooks/viewport/types.ts +19 -0
  258. package/src/hooks/viewport/viewport-metrics.ts +25 -0
  259. package/src/icons/icons.tsx +298 -0
  260. package/src/index.ts +78 -0
  261. package/src/lib/anchored-placement.ts +92 -0
  262. package/src/lib/class-names.ts +21 -0
  263. package/src/lib/date.ts +96 -0
  264. package/src/lib/floating-layers.ts +28 -0
  265. package/src/lib/haptics.ts +25 -0
  266. package/src/lib/language.ts +21 -0
  267. package/src/lib/screen-edges.ts +45 -0
  268. package/src/lib/shapes.ts +70 -0
  269. package/src/motion/transitions.ts +30 -0
  270. package/src/styles/base.css +1 -0
  271. package/src/styles/styles.css +3 -0
  272. package/src/styles/theme.css +1 -0
  273. package/src/styles/typeset.css +1 -0
  274. package/src/styles/utilities.css +1 -0
  275. package/src/tokens.ts +1 -0
@@ -0,0 +1,432 @@
1
+ import {
2
+ AnimatePresence,
3
+ motion,
4
+ useReducedMotion,
5
+ } from "motion/react"
6
+ import {
7
+ type KeyboardEvent,
8
+ useEffect,
9
+ useId,
10
+ useLayoutEffect,
11
+ useRef,
12
+ useState,
13
+ } from "react"
14
+ import { createPortal } from "react-dom"
15
+ import { FLOATING_LAYER } from "../../hooks/use-dismiss"
16
+ import { ClockIcon } from "../../icons/icons"
17
+ import { useAnchoredPlacement } from "../../hooks/use-anchored-placement"
18
+ import { cn } from "../../lib/class-names"
19
+ import { registerFloatingLayer } from "../../lib/floating-layers"
20
+ import { haptic } from "../../lib/haptics"
21
+ import { spring } from "../../motion/transitions"
22
+ import {
23
+ formatTime,
24
+ fromTwelveHours,
25
+ minuteChoices,
26
+ parseTime,
27
+ type TimeOfDay,
28
+ toTwelveHours,
29
+ usesTwelveHours,
30
+ } from "./time-value"
31
+
32
+ export interface CompactTimePickerProps {
33
+ /** `HH:MM` on a 24 hour clock, or "" when no time is chosen. */
34
+ value: string
35
+ onChange: (value: string) => void
36
+ /** Names the button and the panel for assistive technology. */
37
+ label: string
38
+ locale: string
39
+ /** Minutes offered, in steps; an exact time already chosen is kept. */
40
+ minuteStep?: number
41
+ /** Shown when no time is chosen. */
42
+ placeholder?: string
43
+ labels: { hour: string; minute: string; period: string }
44
+ className?: string
45
+ }
46
+
47
+ /**
48
+ * A time as a compact button that opens columns of hours and minutes,
49
+ * like SwiftUI's compact DatePicker for times, on the clock the locale
50
+ * reads (12 hours with AM and PM, or 24).
51
+ */
52
+ export function CompactTimePicker({
53
+ value,
54
+ onChange,
55
+ label,
56
+ locale,
57
+ minuteStep = 5,
58
+ placeholder,
59
+ labels,
60
+ className,
61
+ }: CompactTimePickerProps) {
62
+ const [open, setOpen] = useState(false)
63
+ const trigger = useRef<HTMLButtonElement>(null)
64
+ const panelId = useId()
65
+ const chosen = parseTime(value)
66
+ const shown = chosen
67
+ ? new Intl.DateTimeFormat(locale, {
68
+ hour: "numeric",
69
+ minute: "2-digit",
70
+ timeZone: "UTC",
71
+ }).format(
72
+ new Date(
73
+ Date.UTC(
74
+ 2000,
75
+ 0,
76
+ 1,
77
+ chosen.hour,
78
+ chosen.minute
79
+ )
80
+ )
81
+ )
82
+ : (placeholder ?? "")
83
+
84
+ return (
85
+ <>
86
+ <button
87
+ ref={trigger}
88
+ type="button"
89
+ aria-label={
90
+ chosen ? `${label}, ${shown}` : label
91
+ }
92
+ aria-haspopup="dialog"
93
+ aria-expanded={open}
94
+ aria-controls={open ? panelId : undefined}
95
+ onClick={() => setOpen((current) => !current)}
96
+ className={cn(
97
+ "flex w-full min-w-0 items-center gap-2 rounded-lg control-field px-3 py-2 text-start text-subheadline text-label",
98
+ className
99
+ )}
100
+ >
101
+ <span
102
+ className={cn(
103
+ "min-w-0 grow truncate tabular-nums",
104
+ !chosen && "text-label-tertiary"
105
+ )}
106
+ >
107
+ {shown}
108
+ </span>
109
+ <ClockIcon
110
+ size={16}
111
+ className="shrink-0 text-label-tertiary"
112
+ />
113
+ </button>
114
+ {typeof document !== "undefined" &&
115
+ createPortal(
116
+ <AnimatePresence>
117
+ {open && trigger.current && (
118
+ <TimeColumns
119
+ id={panelId}
120
+ anchor={trigger.current}
121
+ label={label}
122
+ locale={locale}
123
+ time={
124
+ chosen ?? {
125
+ hour: 9,
126
+ minute: 0,
127
+ }
128
+ }
129
+ minuteStep={minuteStep}
130
+ labels={labels}
131
+ onChange={(next) => {
132
+ haptic("selection")
133
+ onChange(formatTime(next))
134
+ }}
135
+ onClose={() => {
136
+ setOpen(false)
137
+ trigger.current?.focus()
138
+ }}
139
+ />
140
+ )}
141
+ </AnimatePresence>,
142
+ document.body
143
+ )}
144
+ </>
145
+ )
146
+ }
147
+
148
+ interface ColumnItem {
149
+ key: number
150
+ text: string
151
+ }
152
+
153
+ function TimeColumns({
154
+ id,
155
+ anchor,
156
+ label,
157
+ locale,
158
+ time,
159
+ minuteStep,
160
+ labels,
161
+ onChange,
162
+ onClose,
163
+ }: {
164
+ id: string
165
+ anchor: HTMLElement
166
+ label: string
167
+ locale: string
168
+ time: TimeOfDay
169
+ minuteStep: number
170
+ labels: CompactTimePickerProps["labels"]
171
+ onChange: (time: TimeOfDay) => void
172
+ onClose: () => void
173
+ }) {
174
+ const root = useRef<HTMLDivElement>(null)
175
+ const reducedMotion = useReducedMotion()
176
+ const twelve = usesTwelveHours(locale)
177
+ const placement = useAnchoredPlacement(
178
+ anchor,
179
+ twelve ? 240 : 180,
180
+ 280
181
+ )
182
+ const number = new Intl.NumberFormat(locale, {
183
+ minimumIntegerDigits: 2,
184
+ })
185
+ const plain = new Intl.NumberFormat(locale)
186
+ const clock = toTwelveHours(time.hour)
187
+
188
+ const hours: ColumnItem[] = twelve
189
+ ? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(
190
+ (hour) => ({
191
+ key: hour,
192
+ text: plain.format(hour),
193
+ })
194
+ )
195
+ : Array.from({ length: 24 }, (_, hour) => ({
196
+ key: hour,
197
+ text: number.format(hour),
198
+ }))
199
+ const minutes = minuteChoices(
200
+ minuteStep,
201
+ time.minute
202
+ ).map((minute) => ({
203
+ key: minute,
204
+ text: number.format(minute),
205
+ }))
206
+ // The locale's own words for morning and afternoon.
207
+ const periodName = (pm: boolean) =>
208
+ new Intl.DateTimeFormat(locale, {
209
+ hour: "numeric",
210
+ hour12: true,
211
+ timeZone: "UTC",
212
+ })
213
+ .formatToParts(
214
+ new Date(Date.UTC(2000, 0, 1, pm ? 13 : 1))
215
+ )
216
+ .find((part) => part.type === "dayPeriod")
217
+ ?.value ?? (pm ? "PM" : "AM")
218
+ const periods = [
219
+ { key: 0, text: periodName(false) },
220
+ { key: 1, text: periodName(true) },
221
+ ]
222
+
223
+ useLayoutEffect(() => {
224
+ if (!root.current) return
225
+ return registerFloatingLayer(root.current, anchor)
226
+ }, [anchor])
227
+
228
+ useEffect(() => {
229
+ const onPointer = (event: PointerEvent) => {
230
+ const target = event.target as Node
231
+ if (
232
+ !root.current?.contains(target) &&
233
+ !anchor.contains(target)
234
+ )
235
+ onClose()
236
+ }
237
+ document.addEventListener("pointerdown", onPointer)
238
+ return () =>
239
+ document.removeEventListener(
240
+ "pointerdown",
241
+ onPointer
242
+ )
243
+ }, [anchor, onClose])
244
+
245
+ return (
246
+ <motion.div
247
+ ref={root}
248
+ id={id}
249
+ role="dialog"
250
+ aria-label={label}
251
+ initial={
252
+ reducedMotion
253
+ ? { opacity: 0 }
254
+ : {
255
+ opacity: 0,
256
+ scale: 0.96,
257
+ y: placement.above ? 6 : -6,
258
+ }
259
+ }
260
+ animate={{ opacity: 1, scale: 1, y: 0 }}
261
+ exit={
262
+ reducedMotion
263
+ ? { opacity: 0 }
264
+ : {
265
+ opacity: 0,
266
+ scale: 0.98,
267
+ transition: { duration: 0.1 },
268
+ }
269
+ }
270
+ transition={
271
+ reducedMotion
272
+ ? { duration: 0 }
273
+ : spring.smooth
274
+ }
275
+ style={{
276
+ left: placement.left,
277
+ width: placement.width,
278
+ top: placement.top,
279
+ bottom: placement.bottom,
280
+ maxHeight: placement.maxHeight,
281
+ overflowY: placement.maxHeight
282
+ ? "auto"
283
+ : undefined,
284
+ transformOrigin: placement.above
285
+ ? "50% 100%"
286
+ : "50% 0%",
287
+ }}
288
+ className="glass-menu fixed z-[80] flex gap-1 rounded-3xl p-2"
289
+ {...{ [FLOATING_LAYER]: "" }}
290
+ onKeyDown={(event) => {
291
+ if (event.key !== "Escape") return
292
+ event.preventDefault()
293
+ event.stopPropagation()
294
+ onClose()
295
+ }}
296
+ >
297
+ <Column
298
+ label={labels.hour}
299
+ items={hours}
300
+ selected={twelve ? clock.hour : time.hour}
301
+ autoFocus
302
+ onSelect={(hour) =>
303
+ onChange({
304
+ ...time,
305
+ hour: twelve
306
+ ? fromTwelveHours(hour, clock.pm)
307
+ : hour,
308
+ })
309
+ }
310
+ />
311
+ <Column
312
+ label={labels.minute}
313
+ items={minutes}
314
+ selected={time.minute}
315
+ onSelect={(minute) =>
316
+ onChange({ ...time, minute })
317
+ }
318
+ />
319
+ {twelve && (
320
+ <Column
321
+ label={labels.period}
322
+ items={periods}
323
+ selected={clock.pm ? 1 : 0}
324
+ onSelect={(period) =>
325
+ onChange({
326
+ ...time,
327
+ hour: fromTwelveHours(
328
+ clock.hour,
329
+ period === 1
330
+ ),
331
+ })
332
+ }
333
+ />
334
+ )}
335
+ </motion.div>
336
+ )
337
+ }
338
+
339
+ /** One scrolling column of choices; Up and Down move through it. */
340
+ function Column({
341
+ label,
342
+ items,
343
+ selected,
344
+ autoFocus = false,
345
+ onSelect,
346
+ }: {
347
+ label: string
348
+ items: ColumnItem[]
349
+ selected: number
350
+ autoFocus?: boolean
351
+ onSelect: (key: number) => void
352
+ }) {
353
+ const list = useRef<HTMLDivElement>(null)
354
+
355
+ // The chosen item starts in the middle of the column, then follows changes.
356
+ useEffect(() => {
357
+ const element =
358
+ list.current?.querySelector<HTMLElement>(
359
+ `[data-key="${selected}"]`
360
+ )
361
+ element?.scrollIntoView({ block: "center" })
362
+ if (
363
+ autoFocus &&
364
+ list.current?.contains(document.activeElement) ===
365
+ false
366
+ )
367
+ element?.focus()
368
+ }, [selected, autoFocus])
369
+
370
+ const onKeyDown = (
371
+ event: KeyboardEvent<HTMLDivElement>
372
+ ) => {
373
+ const step =
374
+ event.key === "ArrowDown"
375
+ ? 1
376
+ : event.key === "ArrowUp"
377
+ ? -1
378
+ : 0
379
+ if (!step) return
380
+ event.preventDefault()
381
+ const index = items.findIndex(
382
+ (item) => item.key === selected
383
+ )
384
+ const next =
385
+ items[
386
+ (index + step + items.length) % items.length
387
+ ]
388
+ if (!next) return
389
+ onSelect(next.key)
390
+ requestAnimationFrame(() =>
391
+ list.current
392
+ ?.querySelector<HTMLElement>(
393
+ `[data-key="${next.key}"]`
394
+ )
395
+ ?.focus()
396
+ )
397
+ }
398
+
399
+ return (
400
+ <div
401
+ ref={list}
402
+ role="listbox"
403
+ aria-label={label}
404
+ onKeyDown={onKeyDown}
405
+ className="flex max-h-56 flex-1 snap-y snap-mandatory flex-col overflow-y-auto overscroll-contain py-[5.25rem] [scrollbar-width:none]"
406
+ >
407
+ {items.map((item) => {
408
+ const isSelected = item.key === selected
409
+ return (
410
+ <button
411
+ key={item.key}
412
+ type="button"
413
+ role="option"
414
+ data-key={item.key}
415
+ aria-selected={isSelected}
416
+ tabIndex={isSelected ? 0 : -1}
417
+ onClick={() => onSelect(item.key)}
418
+ className={cn(
419
+ "flex h-11 shrink-0 snap-center items-center justify-center rounded-xl text-title3 tabular-nums transition-colors",
420
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70",
421
+ isSelected
422
+ ? "bg-fill font-semibold text-label"
423
+ : "text-label-secondary hover:bg-fill/60"
424
+ )}
425
+ >
426
+ {item.text}
427
+ </button>
428
+ )
429
+ })}
430
+ </div>
431
+ )
432
+ }
@@ -0,0 +1,31 @@
1
+ import { CompactTimePicker } from "@passui/react/compact-time-picker"
2
+ import { useState } from "react"
3
+
4
+ const labels = {
5
+ hour: "Hour",
6
+ minute: "Minute",
7
+ period: "AM or PM",
8
+ }
9
+
10
+ export function CompactTimePickerShowcase() {
11
+ const [starts, setStarts] = useState("09:00")
12
+ const [ends, setEnds] = useState("10:30")
13
+ return (
14
+ <div className="grid w-full max-w-sm grid-cols-2 gap-3">
15
+ <CompactTimePicker
16
+ label="Starts"
17
+ labels={labels}
18
+ locale="en-US"
19
+ value={starts}
20
+ onChange={setStarts}
21
+ />
22
+ <CompactTimePicker
23
+ label="Ends"
24
+ labels={labels}
25
+ locale="en-GB"
26
+ value={ends}
27
+ onChange={setEnds}
28
+ />
29
+ </div>
30
+ )
31
+ }
@@ -0,0 +1,21 @@
1
+ import { CompactTimePicker } from "@passui/react/compact-time-picker"
2
+ import { useState } from "react"
3
+
4
+ export function CompactTimePickerUsage() {
5
+ const [time, setTime] = useState("18:30")
6
+ return (
7
+ <div className="w-full max-w-xs">
8
+ <CompactTimePicker
9
+ label="Time"
10
+ labels={{
11
+ hour: "Hour",
12
+ minute: "Minute",
13
+ period: "AM or PM",
14
+ }}
15
+ locale="en-US"
16
+ value={time}
17
+ onChange={setTime}
18
+ />
19
+ </div>
20
+ )
21
+ }
@@ -0,0 +1,67 @@
1
+ /** A time of day on a 24 hour clock. */
2
+ export interface TimeOfDay {
3
+ hour: number
4
+ minute: number
5
+ }
6
+
7
+ /** Reads `HH:MM` (24 hour); null for anything else. */
8
+ export function parseTime(value: string): TimeOfDay | null {
9
+ const match = /^(\d{2}):(\d{2})$/.exec(value)
10
+ if (!match) return null
11
+ const hour = Number(match[1])
12
+ const minute = Number(match[2])
13
+ return hour < 24 && minute < 60 ? { hour, minute } : null
14
+ }
15
+
16
+ export function formatTime({
17
+ hour,
18
+ minute,
19
+ }: TimeOfDay): string {
20
+ return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`
21
+ }
22
+
23
+ /** Whether people where `locale` is used read time on a 12 hour clock. */
24
+ export function usesTwelveHours(locale: string): boolean {
25
+ try {
26
+ const cycle = new Intl.DateTimeFormat(locale, {
27
+ hour: "numeric",
28
+ }).resolvedOptions().hourCycle
29
+ return cycle === "h11" || cycle === "h12"
30
+ } catch {
31
+ return false
32
+ }
33
+ }
34
+
35
+ /** The hour as shown on a 12 hour clock (12, 1 to 11) and whether it's after noon. */
36
+ export function toTwelveHours(hour: number): {
37
+ hour: number
38
+ pm: boolean
39
+ } {
40
+ return {
41
+ hour: hour % 12 === 0 ? 12 : hour % 12,
42
+ pm: hour >= 12,
43
+ }
44
+ }
45
+
46
+ export function fromTwelveHours(
47
+ hour: number,
48
+ pm: boolean
49
+ ): number {
50
+ return (hour % 12) + (pm ? 12 : 0)
51
+ }
52
+
53
+ /** Minutes offered in steps of `step`, keeping `current` when it falls between them. */
54
+ export function minuteChoices(
55
+ step: number,
56
+ current?: number
57
+ ): number[] {
58
+ const choices = Array.from(
59
+ { length: Math.ceil(60 / step) },
60
+ (_, index) => index * step
61
+ )
62
+ if (current !== undefined && !choices.includes(current)) {
63
+ choices.push(current)
64
+ choices.sort((a, b) => a - b)
65
+ }
66
+ return choices
67
+ }
@@ -0,0 +1,61 @@
1
+ import { ContentViewHeaderAction } from "./examples/content-view-header-action"
2
+ import { jsxAttribute } from "../../docs/snippet"
3
+ import { defineDocs } from "../../docs/types"
4
+ import {
5
+ ContentView,
6
+ type ContentViewVariant,
7
+ } from "./content-view"
8
+ import { ContentViewShowcase } from "./examples/content-view-showcase"
9
+ import { ContentViewStats } from "./examples/content-view-stats"
10
+ import { ContentViewUsage } from "./examples/content-view-usage"
11
+
12
+ // heading and description belong to ContentView.Header, inside the card;
13
+ // the snippet writes that header itself.
14
+ type DemoProps = {
15
+ variant?: ContentViewVariant
16
+ heading: string
17
+ description: string
18
+ }
19
+
20
+ export const contentViewDocs = defineDocs<DemoProps>()({
21
+ slug: "content-view",
22
+ name: "ContentView",
23
+ importPath: "@passui/react/content-view",
24
+ controls: {
25
+ variant: {
26
+ kind: "select",
27
+ options: { elevated: true },
28
+ default: "elevated",
29
+ },
30
+ heading: { kind: "text", default: "Recovery" },
31
+ description: {
32
+ kind: "text",
33
+ default: "Ways back in if you lose your phone.",
34
+ },
35
+ },
36
+ render: ({ variant, heading, description }) => (
37
+ <ContentView variant={variant} className="w-72 p-5">
38
+ <ContentView.Header
39
+ heading={heading}
40
+ p={description || undefined}
41
+ className="flex flex-col gap-1"
42
+ pClassName="text-footnote text-label-secondary"
43
+ />
44
+ </ContentView>
45
+ ),
46
+ childrenSnippet: ({ heading, description }) => ({
47
+ imports: [],
48
+ omit: ["heading", "description"],
49
+ extraProps: { className: "p-5" },
50
+ children: `\n <ContentView.Header ${jsxAttribute("heading", heading)}${description ? ` ${jsxAttribute("p", description)}` : ""} />\n`,
51
+ }),
52
+ usage: ContentViewUsage,
53
+ showcase: ContentViewShowcase,
54
+ examples: [
55
+ { id: "stats", component: ContentViewStats },
56
+ {
57
+ id: "header-action",
58
+ component: ContentViewHeaderAction,
59
+ },
60
+ ],
61
+ })