@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.
- package/LICENSE +21 -0
- package/README.md +83 -2
- package/package.json +96 -5
- package/src/appearance/index.ts +2 -0
- package/src/appearance/platform.tsx +123 -0
- package/src/appearance/theme.tsx +535 -0
- package/src/components/ambient/ambient.docs.tsx +68 -0
- package/src/components/ambient/ambient.tsx +43 -0
- package/src/components/ambient/examples/ambient-images.tsx +30 -0
- package/src/components/ambient/examples/ambient-now-playing.tsx +55 -0
- package/src/components/ambient/examples/ambient-showcase.tsx +33 -0
- package/src/components/ambient/examples/ambient-usage.tsx +19 -0
- package/src/components/ambient/index.ts +1 -0
- package/src/components/button/button-styles.ts +60 -0
- package/src/components/button/button.docs.tsx +116 -0
- package/src/components/button/button.tsx +91 -0
- package/src/components/button/examples/button-disabled.tsx +19 -0
- package/src/components/button/examples/button-icon.tsx +39 -0
- package/src/components/button/examples/button-link.tsx +12 -0
- package/src/components/button/examples/button-pending.tsx +27 -0
- package/src/components/button/examples/button-showcase.tsx +115 -0
- package/src/components/button/examples/button-sizes.tsx +12 -0
- package/src/components/button/examples/button-usage.tsx +12 -0
- package/src/components/button/examples/button-variants.tsx +15 -0
- package/src/components/button/examples/button-with-icon.tsx +32 -0
- package/src/components/button/examples/icon-button-player.tsx +38 -0
- package/src/components/button/examples/icon-button-showcase.tsx +83 -0
- package/src/components/button/examples/icon-button-usage.tsx +11 -0
- package/src/components/button/examples/icon-button-variants.tsx +39 -0
- package/src/components/button/icon-button.docs.tsx +68 -0
- package/src/components/button/icon-button.tsx +73 -0
- package/src/components/button/pending-spinner.tsx +14 -0
- package/src/components/button/use-pending-indicator.ts +27 -0
- package/src/components/chip/chip.docs.tsx +37 -0
- package/src/components/chip/chip.tsx +35 -0
- package/src/components/chip/examples/chip-in-rows.tsx +19 -0
- package/src/components/chip/examples/chip-showcase.tsx +51 -0
- package/src/components/chip/examples/chip-tones.tsx +13 -0
- package/src/components/chip/examples/chip-usage.tsx +5 -0
- package/src/components/compact-date-picker/calendar-month.ts +131 -0
- package/src/components/compact-date-picker/compact-date-picker.docs.tsx +81 -0
- package/src/components/compact-date-picker/compact-date-picker.tsx +438 -0
- package/src/components/compact-date-picker/examples/compact-date-picker-showcase.tsx +35 -0
- package/src/components/compact-date-picker/examples/compact-date-picker-usage.tsx +22 -0
- package/src/components/compact-time-picker/compact-time-picker.docs.tsx +80 -0
- package/src/components/compact-time-picker/compact-time-picker.tsx +432 -0
- package/src/components/compact-time-picker/examples/compact-time-picker-showcase.tsx +31 -0
- package/src/components/compact-time-picker/examples/compact-time-picker-usage.tsx +21 -0
- package/src/components/compact-time-picker/time-value.ts +67 -0
- package/src/components/content-view/content-view.docs.tsx +61 -0
- package/src/components/content-view/content-view.tsx +197 -0
- package/src/components/content-view/examples/content-view-header-action.tsx +33 -0
- package/src/components/content-view/examples/content-view-showcase.tsx +65 -0
- package/src/components/content-view/examples/content-view-stats.tsx +35 -0
- package/src/components/content-view/examples/content-view-usage.tsx +14 -0
- package/src/components/content-view/index.ts +1 -0
- package/src/components/context-menu/conceal-menu-source.ts +33 -0
- package/src/components/context-menu/context-menu-host.tsx +445 -0
- package/src/components/context-menu/context-menu-store.ts +165 -0
- package/src/components/context-menu/context-menu.docs.tsx +92 -0
- package/src/components/context-menu/examples/context-menu-checked.tsx +37 -0
- package/src/components/context-menu/examples/context-menu-list.tsx +85 -0
- package/src/components/context-menu/examples/context-menu-showcase.tsx +56 -0
- package/src/components/context-menu/examples/context-menu-toolbar.tsx +63 -0
- package/src/components/context-menu/examples/context-menu-usage.tsx +24 -0
- package/src/components/context-menu/menu-position.ts +55 -0
- package/src/components/context-menu/menu-reveal.ts +75 -0
- package/src/components/context-menu/use-context-menu.ts +90 -0
- package/src/components/conversation/conversation.docs.tsx +88 -0
- package/src/components/conversation/conversation.tsx +279 -0
- package/src/components/conversation/examples/conversation-composer.tsx +36 -0
- package/src/components/conversation/examples/conversation-days.tsx +48 -0
- package/src/components/conversation/examples/conversation-showcase.tsx +71 -0
- package/src/components/conversation/examples/conversation-usage.tsx +28 -0
- package/src/components/conversation/index.ts +1 -0
- package/src/components/date-picker/date-picker.docs.tsx +88 -0
- package/src/components/date-picker/date-picker.tsx +103 -0
- package/src/components/date-picker/date-value.ts +37 -0
- package/src/components/date-picker/examples/date-picker-locales.tsx +41 -0
- package/src/components/date-picker/examples/date-picker-past-only.tsx +29 -0
- package/src/components/date-picker/examples/date-picker-showcase.tsx +49 -0
- package/src/components/date-picker/examples/date-picker-usage.tsx +22 -0
- package/src/components/dialog/dialog-host.tsx +156 -0
- package/src/components/dialog/dialog-store.ts +56 -0
- package/src/components/dialog/dialog.docs.tsx +114 -0
- package/src/components/dialog/dialog.tsx +200 -0
- package/src/components/dialog/examples/dialog-confirm.tsx +24 -0
- package/src/components/dialog/examples/dialog-form.tsx +46 -0
- package/src/components/dialog/examples/dialog-inline.tsx +48 -0
- package/src/components/dialog/examples/dialog-showcase.tsx +53 -0
- package/src/components/dialog/examples/dialog-usage.tsx +31 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/labeled-content/examples/labeled-content-descriptions.tsx +37 -0
- package/src/components/labeled-content/examples/labeled-content-showcase.tsx +54 -0
- package/src/components/labeled-content/examples/labeled-content-usage.tsx +22 -0
- package/src/components/labeled-content/examples/labeled-content-values.tsx +26 -0
- package/src/components/labeled-content/examples/labeled-content-wide.tsx +46 -0
- package/src/components/labeled-content/labeled-content.docs.tsx +69 -0
- package/src/components/labeled-content/labeled-content.tsx +66 -0
- package/src/components/locale-switcher/examples/locale-switcher-native-names.tsx +30 -0
- package/src/components/locale-switcher/examples/locale-switcher-showcase.tsx +46 -0
- package/src/components/locale-switcher/examples/locale-switcher-translated-page.tsx +35 -0
- package/src/components/locale-switcher/examples/locale-switcher-usage.tsx +20 -0
- package/src/components/locale-switcher/index.ts +1 -0
- package/src/components/locale-switcher/locale-switcher.docs.tsx +91 -0
- package/src/components/locale-switcher/locale-switcher.tsx +252 -0
- package/src/components/picker/examples/picker-details.tsx +44 -0
- package/src/components/picker/examples/picker-searchable.tsx +48 -0
- package/src/components/picker/examples/picker-showcase.tsx +66 -0
- package/src/components/picker/examples/picker-usage.tsx +20 -0
- package/src/components/picker/picker.docs.tsx +68 -0
- package/src/components/picker/picker.tsx +493 -0
- package/src/components/popover/examples/popover-help.tsx +57 -0
- package/src/components/popover/examples/popover-menu.tsx +51 -0
- package/src/components/popover/examples/popover-showcase.tsx +61 -0
- package/src/components/popover/examples/popover-usage.tsx +31 -0
- package/src/components/popover/popover.docs.tsx +84 -0
- package/src/components/popover/popover.tsx +138 -0
- package/src/components/profile-image/examples/profile-image-fallbacks.tsx +29 -0
- package/src/components/profile-image/examples/profile-image-group.tsx +34 -0
- package/src/components/profile-image/examples/profile-image-showcase.tsx +30 -0
- package/src/components/profile-image/examples/profile-image-usage.tsx +14 -0
- package/src/components/profile-image/profile-image.docs.tsx +81 -0
- package/src/components/profile-image/profile-image.tsx +80 -0
- package/src/components/search-field/examples/search-field-filter.tsx +53 -0
- package/src/components/search-field/examples/search-field-showcase.tsx +56 -0
- package/src/components/search-field/examples/search-field-toolbar.tsx +27 -0
- package/src/components/search-field/examples/search-field-usage.tsx +18 -0
- package/src/components/search-field/search-field.docs.tsx +58 -0
- package/src/components/search-field/search-field.tsx +29 -0
- package/src/components/search-list/examples/search-list-dropdown.tsx +53 -0
- package/src/components/search-list/examples/search-list-groups.tsx +64 -0
- package/src/components/search-list/examples/search-list-showcase.tsx +67 -0
- package/src/components/search-list/examples/search-list-usage.tsx +27 -0
- package/src/components/search-list/search-list.docs.tsx +87 -0
- package/src/components/search-list/search-list.tsx +265 -0
- package/src/components/section/examples/section-actions.tsx +35 -0
- package/src/components/section/examples/section-groups.tsx +41 -0
- package/src/components/section/examples/section-showcase.tsx +63 -0
- package/src/components/section/examples/section-usage.tsx +19 -0
- package/src/components/section/section.docs.tsx +51 -0
- package/src/components/section/section.tsx +41 -0
- package/src/components/secure-field/examples/secure-field-new-password.tsx +56 -0
- package/src/components/secure-field/examples/secure-field-reveal.tsx +20 -0
- package/src/components/secure-field/examples/secure-field-showcase.tsx +62 -0
- package/src/components/secure-field/examples/secure-field-usage.tsx +19 -0
- package/src/components/secure-field/secure-field.docs.tsx +72 -0
- package/src/components/secure-field/secure-field.tsx +10 -0
- package/src/components/segmented-control/examples/segmented-control-overflow.tsx +28 -0
- package/src/components/segmented-control/examples/segmented-control-showcase.tsx +59 -0
- package/src/components/segmented-control/examples/segmented-control-usage.tsx +20 -0
- package/src/components/segmented-control/examples/segmented-control-views.tsx +32 -0
- package/src/components/segmented-control/segmented-control.docs.tsx +61 -0
- package/src/components/segmented-control/segmented-control.tsx +122 -0
- package/src/components/sheet/examples/sheet-choices.tsx +58 -0
- package/src/components/sheet/examples/sheet-share.tsx +51 -0
- package/src/components/sheet/examples/sheet-showcase.tsx +74 -0
- package/src/components/sheet/examples/sheet-usage.tsx +32 -0
- package/src/components/sheet/modal-environment.ts +113 -0
- package/src/components/sheet/sheet-portal.tsx +89 -0
- package/src/components/sheet/sheet.docs.tsx +75 -0
- package/src/components/sheet/sheet.tsx +112 -0
- package/src/components/sheet/use-sheet-focus.ts +130 -0
- package/src/components/sidebar/examples/sidebar-groups.tsx +133 -0
- package/src/components/sidebar/examples/sidebar-showcase.tsx +123 -0
- package/src/components/sidebar/examples/sidebar-unread.tsx +66 -0
- package/src/components/sidebar/examples/sidebar-usage.tsx +52 -0
- package/src/components/sidebar/sidebar.docs.tsx +135 -0
- package/src/components/sidebar/sidebar.tsx +69 -0
- package/src/components/stat-tile/examples/stat-tile-filters.tsx +32 -0
- package/src/components/stat-tile/examples/stat-tile-grid.tsx +21 -0
- package/src/components/stat-tile/examples/stat-tile-showcase.tsx +52 -0
- package/src/components/stat-tile/examples/stat-tile-usage.tsx +13 -0
- package/src/components/stat-tile/index.ts +1 -0
- package/src/components/stat-tile/stat-tile.docs.tsx +60 -0
- package/src/components/stat-tile/stat-tile.tsx +68 -0
- package/src/components/status-indicator/examples/status-indicator-live.tsx +34 -0
- package/src/components/status-indicator/examples/status-indicator-showcase.tsx +39 -0
- package/src/components/status-indicator/examples/status-indicator-states.tsx +17 -0
- package/src/components/status-indicator/examples/status-indicator-usage.tsx +9 -0
- package/src/components/status-indicator/status-indicator.docs.tsx +43 -0
- package/src/components/status-indicator/status-indicator.tsx +35 -0
- package/src/components/swatch-picker/examples/swatch-picker-accents.tsx +42 -0
- package/src/components/swatch-picker/examples/swatch-picker-labels.tsx +45 -0
- package/src/components/swatch-picker/examples/swatch-picker-showcase.tsx +70 -0
- package/src/components/swatch-picker/examples/swatch-picker-usage.tsx +39 -0
- package/src/components/swatch-picker/swatch-picker.docs.tsx +60 -0
- package/src/components/swatch-picker/swatch-picker.tsx +96 -0
- package/src/components/tab-bar/examples/tab-bar-five-tabs.tsx +66 -0
- package/src/components/tab-bar/examples/tab-bar-minimize.tsx +71 -0
- package/src/components/tab-bar/examples/tab-bar-showcase.tsx +82 -0
- package/src/components/tab-bar/examples/tab-bar-usage.tsx +54 -0
- package/src/components/tab-bar/tab-bar.docs.tsx +136 -0
- package/src/components/tab-bar/tab-bar.tsx +148 -0
- package/src/components/tab-view/examples/tab-view-keyboard.tsx +39 -0
- package/src/components/tab-view/examples/tab-view-settings.tsx +56 -0
- package/src/components/tab-view/examples/tab-view-showcase.tsx +53 -0
- package/src/components/tab-view/examples/tab-view-usage.tsx +23 -0
- package/src/components/tab-view/tab-view.docs.tsx +77 -0
- package/src/components/tab-view/tab-view.tsx +117 -0
- package/src/components/table/examples/table-empty.tsx +53 -0
- package/src/components/table/examples/table-invoices.tsx +102 -0
- package/src/components/table/examples/table-selection.tsx +150 -0
- package/src/components/table/examples/table-showcase.tsx +115 -0
- package/src/components/table/examples/table-usage.tsx +67 -0
- package/src/components/table/examples/table-wide.tsx +75 -0
- package/src/components/table/table.docs.tsx +131 -0
- package/src/components/table/table.tsx +149 -0
- package/src/components/text-editor/examples/text-editor-comment.tsx +48 -0
- package/src/components/text-editor/examples/text-editor-count.tsx +38 -0
- package/src/components/text-editor/examples/text-editor-showcase.tsx +58 -0
- package/src/components/text-editor/examples/text-editor-usage.tsx +25 -0
- package/src/components/text-editor/text-editor.docs.tsx +61 -0
- package/src/components/text-editor/text-editor.tsx +19 -0
- package/src/components/text-field/examples/text-field-icons.tsx +72 -0
- package/src/components/text-field/examples/text-field-showcase.tsx +50 -0
- package/src/components/text-field/examples/text-field-usage.tsx +18 -0
- package/src/components/text-field/examples/text-field-validation.tsx +27 -0
- package/src/components/text-field/text-field.docs.tsx +118 -0
- package/src/components/text-field/text-field.tsx +135 -0
- package/src/components/toast/examples/toast-action.tsx +32 -0
- package/src/components/toast/examples/toast-promise.tsx +45 -0
- package/src/components/toast/examples/toast-showcase.tsx +49 -0
- package/src/components/toast/examples/toast-usage.tsx +13 -0
- package/src/components/toast/toast-store.ts +166 -0
- package/src/components/toast/toast.docs.tsx +79 -0
- package/src/components/toast/toaster.tsx +374 -0
- package/src/components/toggle/examples/toggle-checkboxes.tsx +43 -0
- package/src/components/toggle/examples/toggle-settings.tsx +31 -0
- package/src/components/toggle/examples/toggle-showcase.tsx +59 -0
- package/src/components/toggle/examples/toggle-usage.tsx +13 -0
- package/src/components/toggle/toggle.docs.tsx +69 -0
- package/src/components/toggle/toggle.tsx +85 -0
- package/src/components/tooltip/examples/tooltip-icon-buttons.tsx +27 -0
- package/src/components/tooltip/examples/tooltip-shortcuts.tsx +38 -0
- package/src/components/tooltip/examples/tooltip-showcase.tsx +44 -0
- package/src/components/tooltip/examples/tooltip-usage.tsx +13 -0
- package/src/components/tooltip/tooltip-host.tsx +156 -0
- package/src/components/tooltip/tooltip.docs.tsx +56 -0
- package/src/components/view-controller/examples/view-controller-action.tsx +27 -0
- package/src/components/view-controller/examples/view-controller-settings.tsx +31 -0
- package/src/components/view-controller/examples/view-controller-showcase.tsx +45 -0
- package/src/components/view-controller/examples/view-controller-usage.tsx +19 -0
- package/src/components/view-controller/index.ts +1 -0
- package/src/components/view-controller/view-controller.docs.tsx +71 -0
- package/src/components/view-controller/view-controller.tsx +81 -0
- package/src/docs/index.ts +3 -0
- package/src/docs/registry.ts +113 -0
- package/src/docs/snippet.ts +17 -0
- package/src/docs/types.ts +180 -0
- package/src/hooks/scroll/minimize-decision.ts +13 -0
- package/src/hooks/use-anchored-placement.ts +43 -0
- package/src/hooks/use-dismiss.ts +58 -0
- package/src/hooks/use-media-query.ts +106 -0
- package/src/hooks/use-minimize-on-scroll.ts +92 -0
- package/src/hooks/use-visual-viewport.ts +76 -0
- package/src/hooks/viewport/types.ts +19 -0
- package/src/hooks/viewport/viewport-metrics.ts +25 -0
- package/src/icons/icons.tsx +298 -0
- package/src/index.ts +78 -0
- package/src/lib/anchored-placement.ts +92 -0
- package/src/lib/class-names.ts +21 -0
- package/src/lib/date.ts +96 -0
- package/src/lib/floating-layers.ts +28 -0
- package/src/lib/haptics.ts +25 -0
- package/src/lib/language.ts +21 -0
- package/src/lib/screen-edges.ts +45 -0
- package/src/lib/shapes.ts +70 -0
- package/src/motion/transitions.ts +30 -0
- package/src/styles/base.css +1 -0
- package/src/styles/styles.css +3 -0
- package/src/styles/theme.css +1 -0
- package/src/styles/typeset.css +1 -0
- package/src/styles/utilities.css +1 -0
- package/src/tokens.ts +1 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Returns a date-only value without timezone conversion or date rollover. */
|
|
2
|
+
export function dateValue(
|
|
3
|
+
year: string,
|
|
4
|
+
month: string,
|
|
5
|
+
day: string,
|
|
6
|
+
max?: string
|
|
7
|
+
) {
|
|
8
|
+
if (
|
|
9
|
+
!/^\d{4}$/.test(year) ||
|
|
10
|
+
!/^\d{1,2}$/.test(month) ||
|
|
11
|
+
!/^\d{1,2}$/.test(day)
|
|
12
|
+
)
|
|
13
|
+
return ""
|
|
14
|
+
const y = Number(year)
|
|
15
|
+
const m = Number(month)
|
|
16
|
+
const d = Number(day)
|
|
17
|
+
const leap =
|
|
18
|
+
y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)
|
|
19
|
+
const days = [
|
|
20
|
+
31,
|
|
21
|
+
leap ? 29 : 28,
|
|
22
|
+
31,
|
|
23
|
+
30,
|
|
24
|
+
31,
|
|
25
|
+
30,
|
|
26
|
+
31,
|
|
27
|
+
31,
|
|
28
|
+
30,
|
|
29
|
+
31,
|
|
30
|
+
30,
|
|
31
|
+
31,
|
|
32
|
+
]
|
|
33
|
+
if (y < 1 || m < 1 || m > 12 || d < 1 || d > days[m - 1]!)
|
|
34
|
+
return ""
|
|
35
|
+
const value = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`
|
|
36
|
+
return max && value > max ? "" : value
|
|
37
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DatePicker } from "@passui/react/date-picker"
|
|
2
|
+
import { useState } from "react"
|
|
3
|
+
|
|
4
|
+
const labels = {
|
|
5
|
+
day: "Day",
|
|
6
|
+
month: "Month",
|
|
7
|
+
year: "Year",
|
|
8
|
+
invalid: "Enter a real date.",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function DatePickerLocales() {
|
|
12
|
+
const [us, setUs] = useState("1994-07-21")
|
|
13
|
+
const [uk, setUk] = useState("1994-07-21")
|
|
14
|
+
const [cn, setCn] = useState("1994-07-21")
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div className="flex w-full max-w-xs flex-col gap-8">
|
|
18
|
+
<DatePicker
|
|
19
|
+
label="United States"
|
|
20
|
+
labels={labels}
|
|
21
|
+
locale="en-US"
|
|
22
|
+
value={us}
|
|
23
|
+
onChange={setUs}
|
|
24
|
+
/>
|
|
25
|
+
<DatePicker
|
|
26
|
+
label="United Kingdom"
|
|
27
|
+
labels={labels}
|
|
28
|
+
locale="en-GB"
|
|
29
|
+
value={uk}
|
|
30
|
+
onChange={setUk}
|
|
31
|
+
/>
|
|
32
|
+
<DatePicker
|
|
33
|
+
label="China"
|
|
34
|
+
labels={labels}
|
|
35
|
+
locale="zh-CN"
|
|
36
|
+
value={cn}
|
|
37
|
+
onChange={setCn}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DatePicker } from "@passui/react/date-picker"
|
|
2
|
+
import { useState } from "react"
|
|
3
|
+
|
|
4
|
+
export function DatePickerPastOnly() {
|
|
5
|
+
const [birthday, setBirthday] = useState("2090-01-01")
|
|
6
|
+
const today = new Date().toISOString().slice(0, 10)
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div className="flex w-full max-w-xs flex-col gap-3">
|
|
10
|
+
<DatePicker
|
|
11
|
+
label="Birthday"
|
|
12
|
+
labels={{
|
|
13
|
+
day: "Day",
|
|
14
|
+
month: "Month",
|
|
15
|
+
year: "Year",
|
|
16
|
+
invalid:
|
|
17
|
+
"Your birthday can't be in the future.",
|
|
18
|
+
}}
|
|
19
|
+
locale="en-US"
|
|
20
|
+
max={today}
|
|
21
|
+
value={birthday}
|
|
22
|
+
onChange={setBirthday}
|
|
23
|
+
/>
|
|
24
|
+
<p className="text-footnote text-label-secondary">
|
|
25
|
+
Saved value: {birthday || "none yet"}
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { toast } from "@passui/react"
|
|
2
|
+
import { Button } from "@passui/react/button"
|
|
3
|
+
import { DatePicker } from "@passui/react/date-picker"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
|
|
6
|
+
export function DatePickerShowcase() {
|
|
7
|
+
const [birthday, setBirthday] = useState("")
|
|
8
|
+
const today = new Date().toISOString().slice(0, 10)
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<form
|
|
12
|
+
className="flex w-full max-w-sm flex-col gap-5 rounded-4xl bg-elevated p-6 shadow-sm ring-1 ring-separator/60"
|
|
13
|
+
onSubmit={(event) => {
|
|
14
|
+
event.preventDefault()
|
|
15
|
+
toast.success("Birthday saved")
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
<div className="flex flex-col gap-1">
|
|
19
|
+
<h2 className="text-headline font-semibold text-label">
|
|
20
|
+
When's your birthday?
|
|
21
|
+
</h2>
|
|
22
|
+
<p className="text-footnote text-label-secondary">
|
|
23
|
+
We use it to keep your account suited to
|
|
24
|
+
your age. It isn't shown to anyone.
|
|
25
|
+
</p>
|
|
26
|
+
</div>
|
|
27
|
+
<DatePicker
|
|
28
|
+
label="Birthday"
|
|
29
|
+
labels={{
|
|
30
|
+
day: "Day",
|
|
31
|
+
month: "Month",
|
|
32
|
+
year: "Year",
|
|
33
|
+
invalid: "Enter a real date in the past.",
|
|
34
|
+
}}
|
|
35
|
+
locale="en-US"
|
|
36
|
+
max={today}
|
|
37
|
+
value={birthday}
|
|
38
|
+
onChange={setBirthday}
|
|
39
|
+
/>
|
|
40
|
+
<Button
|
|
41
|
+
type="submit"
|
|
42
|
+
variant="accent"
|
|
43
|
+
disabled={!birthday}
|
|
44
|
+
>
|
|
45
|
+
Continue
|
|
46
|
+
</Button>
|
|
47
|
+
</form>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DatePicker } from "@passui/react/date-picker"
|
|
2
|
+
import { useState } from "react"
|
|
3
|
+
|
|
4
|
+
export function DatePickerUsage() {
|
|
5
|
+
const [birthday, setBirthday] = useState("")
|
|
6
|
+
return (
|
|
7
|
+
<div className="w-full max-w-xs">
|
|
8
|
+
<DatePicker
|
|
9
|
+
label="Birthday"
|
|
10
|
+
labels={{
|
|
11
|
+
day: "Day",
|
|
12
|
+
month: "Month",
|
|
13
|
+
year: "Year",
|
|
14
|
+
invalid: "Enter a real date.",
|
|
15
|
+
}}
|
|
16
|
+
locale="en-US"
|
|
17
|
+
value={birthday}
|
|
18
|
+
onChange={setBirthday}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { AnimatePresence, motion } from "motion/react"
|
|
2
|
+
import {
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useSyncExternalStore,
|
|
6
|
+
} from "react"
|
|
7
|
+
import { cn } from "../../lib/class-names"
|
|
8
|
+
import { spring } from "../../motion/transitions"
|
|
9
|
+
import {
|
|
10
|
+
getDialog,
|
|
11
|
+
type PendingDialog,
|
|
12
|
+
settleDialog,
|
|
13
|
+
subscribeDialogs,
|
|
14
|
+
} from "./dialog-store"
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Renders confirmation dialogs: a glass card that springs up over blurred
|
|
18
|
+
* content. Escape or a click outside cancels; Enter confirms unless the
|
|
19
|
+
* action is destructive, where the safe choice has focus.
|
|
20
|
+
*/
|
|
21
|
+
export function DialogHost() {
|
|
22
|
+
const dialog = useSyncExternalStore(
|
|
23
|
+
subscribeDialogs,
|
|
24
|
+
getDialog,
|
|
25
|
+
() => null
|
|
26
|
+
)
|
|
27
|
+
return (
|
|
28
|
+
<AnimatePresence>
|
|
29
|
+
{dialog && (
|
|
30
|
+
<ConfirmCard
|
|
31
|
+
key={dialog.id}
|
|
32
|
+
dialog={dialog}
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
</AnimatePresence>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function ConfirmCard({ dialog }: { dialog: PendingDialog }) {
|
|
40
|
+
const confirmRef = useRef<HTMLButtonElement>(null)
|
|
41
|
+
const cancelRef = useRef<HTMLButtonElement>(null)
|
|
42
|
+
const titleId = `dialog-title-${dialog.id}`
|
|
43
|
+
const messageId = `dialog-message-${dialog.id}`
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const previous = window.document
|
|
47
|
+
.activeElement as HTMLElement | null
|
|
48
|
+
;(dialog.destructive
|
|
49
|
+
? cancelRef
|
|
50
|
+
: confirmRef
|
|
51
|
+
).current?.focus()
|
|
52
|
+
const onKey = (event: KeyboardEvent) => {
|
|
53
|
+
if (event.key === "Escape") {
|
|
54
|
+
event.preventDefault()
|
|
55
|
+
settleDialog(false)
|
|
56
|
+
}
|
|
57
|
+
// Keep focus inside the dialog.
|
|
58
|
+
if (event.key === "Tab") {
|
|
59
|
+
const order = [
|
|
60
|
+
cancelRef.current,
|
|
61
|
+
confirmRef.current,
|
|
62
|
+
].filter(Boolean) as HTMLElement[]
|
|
63
|
+
const at = order.indexOf(
|
|
64
|
+
window.document
|
|
65
|
+
.activeElement as HTMLElement
|
|
66
|
+
)
|
|
67
|
+
event.preventDefault()
|
|
68
|
+
order[
|
|
69
|
+
(at +
|
|
70
|
+
(event.shiftKey ? -1 : 1) +
|
|
71
|
+
order.length) %
|
|
72
|
+
order.length
|
|
73
|
+
]?.focus()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
window.addEventListener("keydown", onKey)
|
|
77
|
+
return () => {
|
|
78
|
+
window.removeEventListener("keydown", onKey)
|
|
79
|
+
previous?.focus?.()
|
|
80
|
+
}
|
|
81
|
+
}, [dialog.destructive])
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className="fixed inset-0 z-[70] flex items-center justify-center p-5">
|
|
85
|
+
<motion.button
|
|
86
|
+
type="button"
|
|
87
|
+
tabIndex={-1}
|
|
88
|
+
aria-label="Cancel"
|
|
89
|
+
className="absolute inset-0 bg-black/25 backdrop-blur-md"
|
|
90
|
+
initial={{ opacity: 0 }}
|
|
91
|
+
animate={{ opacity: 1 }}
|
|
92
|
+
exit={{ opacity: 0 }}
|
|
93
|
+
transition={{ duration: 0.2 }}
|
|
94
|
+
onClick={() => settleDialog(false)}
|
|
95
|
+
/>
|
|
96
|
+
<motion.div
|
|
97
|
+
role="alertdialog"
|
|
98
|
+
aria-modal="true"
|
|
99
|
+
aria-labelledby={titleId}
|
|
100
|
+
aria-describedby={
|
|
101
|
+
dialog.message ? messageId : undefined
|
|
102
|
+
}
|
|
103
|
+
className="glass-menu relative flex w-full max-w-[340px] flex-col gap-4 rounded-5xl p-5 text-center"
|
|
104
|
+
initial={{ opacity: 0, scale: 0.86, y: 12 }}
|
|
105
|
+
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
106
|
+
exit={{
|
|
107
|
+
opacity: 0,
|
|
108
|
+
scale: 0.94,
|
|
109
|
+
y: 6,
|
|
110
|
+
transition: { duration: 0.15 },
|
|
111
|
+
}}
|
|
112
|
+
transition={spring.bouncy}
|
|
113
|
+
>
|
|
114
|
+
<div className="flex flex-col gap-1.5 px-1 pt-1">
|
|
115
|
+
<h2
|
|
116
|
+
id={titleId}
|
|
117
|
+
className="text-body font-semibold text-label"
|
|
118
|
+
>
|
|
119
|
+
{dialog.title}
|
|
120
|
+
</h2>
|
|
121
|
+
{dialog.message && (
|
|
122
|
+
<p
|
|
123
|
+
id={messageId}
|
|
124
|
+
className="text-subheadline leading-snug text-label-secondary"
|
|
125
|
+
>
|
|
126
|
+
{dialog.message}
|
|
127
|
+
</p>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
<div className="flex gap-2.5">
|
|
131
|
+
<button
|
|
132
|
+
ref={cancelRef}
|
|
133
|
+
type="button"
|
|
134
|
+
onClick={() => settleDialog(false)}
|
|
135
|
+
className="h-11 grow rounded-2xl bg-fill text-subheadline font-semibold text-label transition-[background-color,transform] hover:bg-separator/70 active:scale-[0.97] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70"
|
|
136
|
+
>
|
|
137
|
+
{dialog.cancelLabel ?? "Cancel"}
|
|
138
|
+
</button>
|
|
139
|
+
<button
|
|
140
|
+
ref={confirmRef}
|
|
141
|
+
type="button"
|
|
142
|
+
onClick={() => settleDialog(true)}
|
|
143
|
+
className={cn(
|
|
144
|
+
"h-11 grow rounded-2xl text-subheadline font-semibold transition-[filter,transform] hover:brightness-105 active:scale-[0.97] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70",
|
|
145
|
+
dialog.destructive
|
|
146
|
+
? "bg-danger text-white"
|
|
147
|
+
: "bg-inverse text-on-inverse"
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
{dialog.confirmLabel ?? "OK"}
|
|
151
|
+
</button>
|
|
152
|
+
</div>
|
|
153
|
+
</motion.div>
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App-wide confirmation dialogs, replacing the browser's `confirm`.
|
|
3
|
+
* `await confirmDialog({...})` resolves true when confirmed. Render one
|
|
4
|
+
* `<DialogHost />`.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfirmOptions {
|
|
7
|
+
title: string
|
|
8
|
+
message?: string
|
|
9
|
+
confirmLabel?: string
|
|
10
|
+
cancelLabel?: string
|
|
11
|
+
/** Destructive actions are shown in red and are not the default button. */
|
|
12
|
+
destructive?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface PendingDialog extends ConfirmOptions {
|
|
16
|
+
id: number
|
|
17
|
+
resolve: (confirmed: boolean) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let current: PendingDialog | null = null
|
|
21
|
+
let nextId = 1
|
|
22
|
+
const queue: PendingDialog[] = []
|
|
23
|
+
const listeners = new Set<() => void>()
|
|
24
|
+
|
|
25
|
+
const emit = () => {
|
|
26
|
+
for (const listener of listeners) listener()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function confirmDialog(
|
|
30
|
+
options: ConfirmOptions
|
|
31
|
+
): Promise<boolean> {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
const dialog = { ...options, id: nextId++, resolve }
|
|
34
|
+
if (current) queue.push(dialog)
|
|
35
|
+
else current = dialog
|
|
36
|
+
emit()
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function settleDialog(confirmed: boolean) {
|
|
41
|
+
if (!current) return
|
|
42
|
+
current.resolve(confirmed)
|
|
43
|
+
current = queue.shift() ?? null
|
|
44
|
+
emit()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function subscribeDialogs(listener: () => void) {
|
|
48
|
+
listeners.add(listener)
|
|
49
|
+
return () => {
|
|
50
|
+
listeners.delete(listener)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function getDialog(): PendingDialog | null {
|
|
55
|
+
return current
|
|
56
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
import { Button } from "../button/button"
|
|
3
|
+
import { jsxAttribute } from "../../docs/snippet"
|
|
4
|
+
import { defineDocs } from "../../docs/types"
|
|
5
|
+
import { Dialog, type DialogPresentation } from "./dialog"
|
|
6
|
+
import { DialogConfirm } from "./examples/dialog-confirm"
|
|
7
|
+
import { DialogForm } from "./examples/dialog-form"
|
|
8
|
+
import { DialogInline } from "./examples/dialog-inline"
|
|
9
|
+
import { DialogShowcase } from "./examples/dialog-showcase"
|
|
10
|
+
import { DialogUsage } from "./examples/dialog-usage"
|
|
11
|
+
|
|
12
|
+
// `destructive` is the tone of Dialog.Actions in the footer; the snippet
|
|
13
|
+
// writes that footer itself.
|
|
14
|
+
type DemoProps = {
|
|
15
|
+
title: string
|
|
16
|
+
description: string
|
|
17
|
+
presentation?: DialogPresentation
|
|
18
|
+
destructive: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function DialogDemo({
|
|
22
|
+
title,
|
|
23
|
+
description,
|
|
24
|
+
presentation,
|
|
25
|
+
destructive,
|
|
26
|
+
}: DemoProps) {
|
|
27
|
+
const [open, setOpen] = useState(false)
|
|
28
|
+
return (
|
|
29
|
+
<div className="flex w-full max-w-sm flex-col items-center gap-4">
|
|
30
|
+
<Button
|
|
31
|
+
variant="secondary"
|
|
32
|
+
onClick={() => setOpen(true)}
|
|
33
|
+
>
|
|
34
|
+
Open dialog
|
|
35
|
+
</Button>
|
|
36
|
+
<Dialog
|
|
37
|
+
open={open}
|
|
38
|
+
onOpenChange={setOpen}
|
|
39
|
+
title={title}
|
|
40
|
+
description={description || undefined}
|
|
41
|
+
presentation={presentation}
|
|
42
|
+
footer={
|
|
43
|
+
<Dialog.Actions
|
|
44
|
+
submitLabel={
|
|
45
|
+
destructive ? "Delete" : "Save"
|
|
46
|
+
}
|
|
47
|
+
cancelLabel="Cancel"
|
|
48
|
+
tone={
|
|
49
|
+
destructive
|
|
50
|
+
? "destructive"
|
|
51
|
+
: "default"
|
|
52
|
+
}
|
|
53
|
+
onConfirm={() => setOpen(false)}
|
|
54
|
+
/>
|
|
55
|
+
}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const dialogDocs = defineDocs<DemoProps>()({
|
|
62
|
+
slug: "dialog",
|
|
63
|
+
name: "Dialog",
|
|
64
|
+
importPath: "@passui/react/dialog",
|
|
65
|
+
controls: {
|
|
66
|
+
title: {
|
|
67
|
+
kind: "text",
|
|
68
|
+
default: "Rename project",
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
description: {
|
|
72
|
+
kind: "text",
|
|
73
|
+
default: "The new name shows everywhere at once.",
|
|
74
|
+
},
|
|
75
|
+
presentation: {
|
|
76
|
+
kind: "select",
|
|
77
|
+
options: {
|
|
78
|
+
drawer: true,
|
|
79
|
+
center: true,
|
|
80
|
+
inline: true,
|
|
81
|
+
},
|
|
82
|
+
default: "drawer",
|
|
83
|
+
},
|
|
84
|
+
destructive: { kind: "boolean", default: false },
|
|
85
|
+
},
|
|
86
|
+
render: (values) => <DialogDemo {...values} />,
|
|
87
|
+
childrenSnippet: ({ destructive }) => ({
|
|
88
|
+
imports: ['import { useState } from "react"'],
|
|
89
|
+
setup: ["const [open, setOpen] = useState(false)"],
|
|
90
|
+
omit: ["destructive"],
|
|
91
|
+
expressionProps: {
|
|
92
|
+
open: "open",
|
|
93
|
+
onOpenChange: "setOpen",
|
|
94
|
+
footer: `<Dialog.Actions ${jsxAttribute("submitLabel", destructive ? "Delete" : "Save")} cancelLabel="Cancel"${destructive ? ' tone="destructive"' : ""} onConfirm={() => setOpen(false)} />`,
|
|
95
|
+
},
|
|
96
|
+
children: "",
|
|
97
|
+
}),
|
|
98
|
+
usage: DialogUsage,
|
|
99
|
+
showcase: DialogShowcase,
|
|
100
|
+
examples: [
|
|
101
|
+
{ id: "form", component: DialogForm },
|
|
102
|
+
{
|
|
103
|
+
id: "confirm",
|
|
104
|
+
component: DialogConfirm,
|
|
105
|
+
playground: { destructive: true },
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: "inline",
|
|
109
|
+
component: DialogInline,
|
|
110
|
+
playground: { presentation: "inline" },
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
previewHeight: 460,
|
|
114
|
+
})
|