@kerf-js/veneer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +1338 -2
- package/package.json +56 -3
- package/plugin.d.mts +187 -0
- package/plugin.mjs +399 -0
- package/src/Accordion.tsx +98 -0
- package/src/Alert.tsx +55 -0
- package/src/Badge.tsx +39 -0
- package/src/Button.tsx +175 -0
- package/src/Calendar-month.tsx +140 -0
- package/src/Calendar.tsx +335 -0
- package/src/Canvas.tsx +221 -0
- package/src/Card.tsx +85 -0
- package/src/Chart.tsx +278 -0
- package/src/Charts.tsx +158 -0
- package/src/Chip.tsx +61 -0
- package/src/Choice-checkbox.tsx +53 -0
- package/src/Choice-parts.tsx +7 -0
- package/src/Choice-radio.tsx +78 -0
- package/src/Choice-segmented.tsx +76 -0
- package/src/Choice-switch.tsx +51 -0
- package/src/Choice.tsx +4 -0
- package/src/CloseX.tsx +14 -0
- package/src/CodeBlock.tsx +81 -0
- package/src/CodeInput.tsx +256 -0
- package/src/Combobox.tsx +281 -0
- package/src/CommandPalette-controller.ts +314 -0
- package/src/CommandPalette-rows.tsx +137 -0
- package/src/CommandPalette.tsx +196 -0
- package/src/DataGrid-actions.ts +119 -0
- package/src/DataGrid-body.tsx +58 -0
- package/src/DataGrid-controller.ts +145 -0
- package/src/DataGrid-header.tsx +108 -0
- package/src/DataGrid-model.ts +248 -0
- package/src/DataGrid-pivot.tsx +108 -0
- package/src/DataGrid-rows.tsx +296 -0
- package/src/DataGrid-toolbar.tsx +127 -0
- package/src/DataGrid-tree.ts +149 -0
- package/src/DataGrid-viewport.tsx +37 -0
- package/src/DataGrid.tsx +145 -0
- package/src/DateField-presets.tsx +27 -0
- package/src/DateField-range.tsx +370 -0
- package/src/DateField.tsx +295 -0
- package/src/Dither.tsx +313 -0
- package/src/Drawer.tsx +123 -0
- package/src/DurationField.tsx +227 -0
- package/src/Feed.tsx +78 -0
- package/src/Field/view.tsx +147 -0
- package/src/Field.tsx +238 -0
- package/src/HamburgerMenu.tsx +119 -0
- package/src/Icon.tsx +15 -0
- package/src/Kbd.tsx +6 -0
- package/src/KeyValueEditor/actions.ts +75 -0
- package/src/KeyValueEditor/rows.tsx +104 -0
- package/src/KeyValueEditor.tsx +112 -0
- package/src/Layout.tsx +221 -0
- package/src/Markdown.tsx +127 -0
- package/src/MentionsInput/actions.ts +161 -0
- package/src/MentionsInput/end.tsx +82 -0
- package/src/MentionsInput.tsx +103 -0
- package/src/Menu.tsx +221 -0
- package/src/Modal.tsx +109 -0
- package/src/MonthPicker/month.tsx +117 -0
- package/src/MonthPicker/period.tsx +197 -0
- package/src/MonthPicker/shared.tsx +272 -0
- package/src/MonthPicker/week.tsx +103 -0
- package/src/MonthPicker.tsx +11 -0
- package/src/MultiSelect.tsx +139 -0
- package/src/Nav.tsx +36 -0
- package/src/NumberField.tsx +156 -0
- package/src/Pagination.tsx +335 -0
- package/src/PaymentCard.tsx +111 -0
- package/src/Picker.tsx +228 -0
- package/src/PlaceField.tsx +285 -0
- package/src/Popover.tsx +88 -0
- package/src/Presence.tsx +37 -0
- package/src/Progress.tsx +71 -0
- package/src/RecurrenceField.tsx +372 -0
- package/src/RichSelect/codes.tsx +94 -0
- package/src/RichSelect/list.tsx +380 -0
- package/src/RichSelect/phone-view.tsx +114 -0
- package/src/RichSelect/phone.tsx +305 -0
- package/src/RichSelect/search-keys.ts +28 -0
- package/src/RichSelect/timezone.tsx +53 -0
- package/src/RichSelect.tsx +13 -0
- package/src/RichTextEditor/controller.tsx +305 -0
- package/src/RichTextEditor/editor.tsx +61 -0
- package/src/RichTextEditor/tools.tsx +132 -0
- package/src/RichTextEditor/view.tsx +210 -0
- package/src/RichTextEditor.tsx +9 -0
- package/src/ScrollGrid/measure.ts +39 -0
- package/src/ScrollGrid/parts.tsx +112 -0
- package/src/ScrollGrid.tsx +375 -0
- package/src/ScrollRail.tsx +114 -0
- package/src/ScrollView.tsx +57 -0
- package/src/Segments/controller.tsx +148 -0
- package/src/Segments/events.ts +99 -0
- package/src/Segments/view.tsx +77 -0
- package/src/Segments.tsx +2 -0
- package/src/Select.tsx +343 -0
- package/src/Shape.tsx +41 -0
- package/src/Shell/branches.tsx +108 -0
- package/src/Shell/button.tsx +33 -0
- package/src/Shell/shared.tsx +220 -0
- package/src/Shell/shell.tsx +25 -0
- package/src/Shell/state.ts +138 -0
- package/src/Shell/view.tsx +280 -0
- package/src/Shell.tsx +17 -0
- package/src/SideNav/sections.tsx +50 -0
- package/src/SideNav/state.ts +140 -0
- package/src/SideNav.tsx +130 -0
- package/src/SideNavTitle.tsx +25 -0
- package/src/SignaturePad/state.ts +172 -0
- package/src/SignaturePad/view.tsx +69 -0
- package/src/SignaturePad.tsx +76 -0
- package/src/Skeleton.tsx +46 -0
- package/src/Slider.tsx +81 -0
- package/src/Spinner.tsx +21 -0
- package/src/Stage-director.ts +361 -0
- package/src/Stage-look.ts +75 -0
- package/src/Stage-poster.tsx +62 -0
- package/src/Stage-types.ts +206 -0
- package/src/Stage.tsx +147 -0
- package/src/TabBar.tsx +114 -0
- package/src/Table-actions.tsx +51 -0
- package/src/Table-base.ts +70 -0
- package/src/Table-body.tsx +84 -0
- package/src/Table-columns.tsx +58 -0
- package/src/Table-details.tsx +66 -0
- package/src/Table-editor.tsx +66 -0
- package/src/Table-head.tsx +52 -0
- package/src/Table-model.ts +82 -0
- package/src/Table-notice.ts +39 -0
- package/src/Table-paging.ts +50 -0
- package/src/Table-rows.tsx +308 -0
- package/src/Table-selection.ts +63 -0
- package/src/Table-sortbar.tsx +41 -0
- package/src/Table-source.ts +66 -0
- package/src/Table-toolbar.tsx +71 -0
- package/src/Table-types.ts +115 -0
- package/src/Table-view.tsx +87 -0
- package/src/Table.tsx +31 -0
- package/src/Tabs.tsx +129 -0
- package/src/Tag.tsx +40 -0
- package/src/Ticker.tsx +42 -0
- package/src/TimeField-date-model.ts +77 -0
- package/src/TimeField-date-view.tsx +152 -0
- package/src/TimeField-model.ts +80 -0
- package/src/TimeField-options.tsx +224 -0
- package/src/TimeField-slots.tsx +32 -0
- package/src/TimeField-types.ts +33 -0
- package/src/TimeField-view.tsx +124 -0
- package/src/TimeField.tsx +126 -0
- package/src/Toast.tsx +143 -0
- package/src/Toggle.tsx +75 -0
- package/src/Tooltip.tsx +69 -0
- package/src/Type.tsx +136 -0
- package/src/VirtualList-controls.ts +105 -0
- package/src/VirtualList-data.ts +43 -0
- package/src/VirtualList-measure.ts +169 -0
- package/src/VirtualList-metrics.ts +41 -0
- package/src/VirtualList-mount.ts +145 -0
- package/src/VirtualList-rows.tsx +91 -0
- package/src/VirtualList-types.ts +76 -0
- package/src/VirtualList-view.tsx +123 -0
- package/src/VirtualList.tsx +81 -0
- package/src/admin/ApiKeys-actions.ts +124 -0
- package/src/admin/ApiKeys-form.tsx +64 -0
- package/src/admin/ApiKeys-view.tsx +101 -0
- package/src/admin/ApiKeys.tsx +224 -0
- package/src/admin/Audit.tsx +246 -0
- package/src/admin/Billing.tsx +307 -0
- package/src/admin/Cart.tsx +177 -0
- package/src/admin/Checkout-address.tsx +125 -0
- package/src/admin/Checkout-cart.tsx +78 -0
- package/src/admin/Checkout-coupon.ts +34 -0
- package/src/admin/Checkout-done.tsx +31 -0
- package/src/admin/Checkout-model.ts +33 -0
- package/src/admin/Checkout-navigation.ts +76 -0
- package/src/admin/Checkout-payment-view.tsx +49 -0
- package/src/admin/Checkout-payment.ts +80 -0
- package/src/admin/Checkout-review.tsx +60 -0
- package/src/admin/Checkout-shipping.tsx +47 -0
- package/src/admin/Checkout-state.ts +122 -0
- package/src/admin/Checkout-steps.ts +10 -0
- package/src/admin/Checkout-summary.tsx +97 -0
- package/src/admin/Checkout-types.ts +60 -0
- package/src/admin/Checkout-view.tsx +51 -0
- package/src/admin/Checkout.tsx +72 -0
- package/src/admin/CsvImport-actions.ts +131 -0
- package/src/admin/CsvImport.tsx +379 -0
- package/src/admin/Danger.tsx +240 -0
- package/src/admin/Integrations/Card.tsx +82 -0
- package/src/admin/Integrations/Webhooks.tsx +341 -0
- package/src/admin/Integrations.tsx +169 -0
- package/src/admin/InviteDialog.tsx +153 -0
- package/src/admin/Members/columns.tsx +181 -0
- package/src/admin/Members.tsx +316 -0
- package/src/admin/Order.tsx +115 -0
- package/src/admin/PlainTable.tsx +34 -0
- package/src/admin/Plans.tsx +375 -0
- package/src/admin/SaveBar/actions.ts +86 -0
- package/src/admin/SaveBar.tsx +153 -0
- package/src/admin/Secret.tsx +74 -0
- package/src/admin/Settings.tsx +145 -0
- package/src/admin/StepBar.tsx +66 -0
- package/src/admin/TagsInput/actions.ts +60 -0
- package/src/admin/TagsInput.tsx +95 -0
- package/src/admin/atoms.tsx +73 -0
- package/src/admin/index.ts +67 -0
- package/src/agent/Actions/reasons.tsx +38 -0
- package/src/agent/Actions.tsx +166 -0
- package/src/agent/AgentPlan.tsx +86 -0
- package/src/agent/ArtifactPanel.tsx +299 -0
- package/src/agent/Assistant.tsx +168 -0
- package/src/agent/Checkpoint.tsx +19 -0
- package/src/agent/Cite.tsx +70 -0
- package/src/agent/ContextMeter.tsx +70 -0
- package/src/agent/Conversation.tsx +70 -0
- package/src/agent/Message.tsx +92 -0
- package/src/agent/ModelPicker.tsx +167 -0
- package/src/agent/Prompt-model.ts +118 -0
- package/src/agent/Prompt-view.tsx +246 -0
- package/src/agent/Prompt.tsx +128 -0
- package/src/agent/Prose.tsx +118 -0
- package/src/agent/Question.tsx +137 -0
- package/src/agent/Reasoning.tsx +31 -0
- package/src/agent/Shimmer.tsx +11 -0
- package/src/agent/Sources.tsx +23 -0
- package/src/agent/SpeechInput.tsx +243 -0
- package/src/agent/Suggestions.tsx +36 -0
- package/src/agent/ToolCall.tsx +219 -0
- package/src/agent/TraceViewer.tsx +96 -0
- package/src/agent/bits.tsx +88 -0
- package/src/agent/index.ts +38 -0
- package/src/bind.ts +57 -0
- package/src/collab/AutoTrack.tsx +91 -0
- package/src/collab/Comments.tsx +204 -0
- package/src/collab/Composer/state.ts +125 -0
- package/src/collab/Composer/view.tsx +155 -0
- package/src/collab/Composer.tsx +141 -0
- package/src/collab/ConversationList.tsx +120 -0
- package/src/collab/Cursors.tsx +71 -0
- package/src/collab/DataIntegrity.tsx +103 -0
- package/src/collab/Kanban-card.ts +74 -0
- package/src/collab/Kanban.tsx +368 -0
- package/src/collab/Lock.tsx +36 -0
- package/src/collab/PresenceStack.tsx +176 -0
- package/src/collab/ShareDialog.tsx +273 -0
- package/src/collab/Status.tsx +101 -0
- package/src/collab/SyncedForm.tsx +42 -0
- package/src/collab/Thread/Message.tsx +265 -0
- package/src/collab/Thread/rows.tsx +56 -0
- package/src/collab/Thread.tsx +323 -0
- package/src/collab/VersionHistory.tsx +173 -0
- package/src/collab/ViewportRail.tsx +73 -0
- package/src/collab/index.ts +37 -0
- package/src/collab/peer.tsx +42 -0
- package/src/fields.ts +5 -0
- package/src/flow/AuthScreen.tsx +81 -0
- package/src/flow/AuthSteps.tsx +296 -0
- package/src/flow/Checklist.tsx +211 -0
- package/src/flow/ConnBanner.tsx +304 -0
- package/src/flow/Flow.tsx +97 -0
- package/src/flow/MfaSetup.tsx +244 -0
- package/src/flow/Otp.tsx +243 -0
- package/src/flow/ReauthDialog.tsx +79 -0
- package/src/flow/ShortcutsOverlay.tsx +121 -0
- package/src/flow/SignGate.tsx +184 -0
- package/src/flow/SignIn.tsx +136 -0
- package/src/flow/SignUp.tsx +149 -0
- package/src/flow/Sso.tsx +96 -0
- package/src/flow/SystemPage/accounts.tsx +74 -0
- package/src/flow/SystemPage/art.tsx +113 -0
- package/src/flow/SystemPage.tsx +395 -0
- package/src/flow/Tour.tsx +207 -0
- package/src/flow/index.ts +29 -0
- package/src/flow/kit.tsx +334 -0
- package/src/index.ts +237 -0
- package/src/layout.css +4 -0
- package/src/links.css +4 -0
- package/src/live/ActivityFeed.tsx +88 -0
- package/src/live/Bell.tsx +108 -0
- package/src/live/Connection.tsx +113 -0
- package/src/live/Inbox.tsx +113 -0
- package/src/live/InboxFeed.tsx +67 -0
- package/src/live/InboxGestures.ts +41 -0
- package/src/live/InboxHandlers.ts +102 -0
- package/src/live/InboxHeader.tsx +81 -0
- package/src/live/InboxModel.ts +81 -0
- package/src/live/InboxRow.tsx +125 -0
- package/src/live/MeetingRoom.tsx +22 -0
- package/src/live/MeetingRoomControlBar.tsx +197 -0
- package/src/live/MeetingRoomHandlers.ts +53 -0
- package/src/live/MeetingRoomLayout.tsx +27 -0
- package/src/live/MeetingRoomModel.ts +49 -0
- package/src/live/MeetingRoomMount.ts +49 -0
- package/src/live/MeetingRoomParts.tsx +178 -0
- package/src/live/MeetingRoomPerson.tsx +21 -0
- package/src/live/MeetingRoomState.ts +88 -0
- package/src/live/MeetingRoomTile.tsx +84 -0
- package/src/live/MeetingRoomTypes.ts +68 -0
- package/src/live/MeetingRoomView.tsx +36 -0
- package/src/live/NotificationPreferences.tsx +99 -0
- package/src/live/NotificationPreferencesActions.ts +55 -0
- package/src/live/NotificationPreferencesCell.tsx +26 -0
- package/src/live/NotificationPreferencesCells.tsx +59 -0
- package/src/live/NotificationPreferencesGrid.tsx +129 -0
- package/src/live/NotificationPreferencesModel.tsx +91 -0
- package/src/live/NotificationPreferencesSave.ts +85 -0
- package/src/live/NotificationPreferencesWatch.ts +31 -0
- package/src/live/Prejoin.tsx +238 -0
- package/src/live/PrejoinMeter.tsx +26 -0
- package/src/live/PrejoinPreview.tsx +53 -0
- package/src/live/PushSoftAsk.tsx +63 -0
- package/src/live/TransportPicker.tsx +341 -0
- package/src/live/TransportPickerDetails.tsx +130 -0
- package/src/live/index.ts +31 -0
- package/src/live/notify.tsx +22 -0
- package/src/live/shared.tsx +110 -0
- package/src/parts.tsx +199 -0
- package/src/plugin/catalog.mjs +129 -0
- package/src/plugin/dtcg.mjs +79 -0
- package/src/plugin/icons.mjs +7 -0
- package/src/plugin/seed.mjs +40 -0
- package/src/plugin/theme-context.mjs +44 -0
- package/src/plugin/theme-css.mjs +143 -0
- package/src/plugin/theme-motion.mjs +43 -0
- package/src/plugin/theme-parts.d.mts +41 -0
- package/src/plugin/theme-parts.mjs +224 -0
- package/src/plugin/theme-text.mjs +93 -0
- package/src/plugin/theme-values.mjs +15 -0
- package/src/plugin/theme.d.mts +82 -0
- package/src/plugin/theme.mjs +316 -0
- package/src/schedule/Agenda.tsx +124 -0
- package/src/schedule/AgendaActions.ts +31 -0
- package/src/schedule/AgendaDay.tsx +124 -0
- package/src/schedule/AgendaGestures.ts +27 -0
- package/src/schedule/AgendaKeys.ts +52 -0
- package/src/schedule/AgendaModel.ts +82 -0
- package/src/schedule/AgendaNavigation.ts +38 -0
- package/src/schedule/AgendaPage.tsx +39 -0
- package/src/schedule/AgendaStrip.tsx +55 -0
- package/src/schedule/AvailabilityEditor-actions.ts +146 -0
- package/src/schedule/AvailabilityEditor-day.tsx +119 -0
- package/src/schedule/AvailabilityEditor-view.tsx +205 -0
- package/src/schedule/AvailabilityEditor.tsx +113 -0
- package/src/schedule/BookingCalendar.tsx +121 -0
- package/src/schedule/BookingCalendarActions.ts +85 -0
- package/src/schedule/BookingCalendarModel.ts +86 -0
- package/src/schedule/BookingCalendarParts.tsx +87 -0
- package/src/schedule/Calendar/AgendaView.tsx +45 -0
- package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
- package/src/schedule/Calendar/CalendarMain.tsx +47 -0
- package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
- package/src/schedule/Calendar/Column.tsx +129 -0
- package/src/schedule/Calendar/EventBlock.tsx +71 -0
- package/src/schedule/Calendar/MiniMonth.tsx +169 -0
- package/src/schedule/Calendar/MonthGrid.tsx +296 -0
- package/src/schedule/Calendar/TimeGrid.tsx +252 -0
- package/src/schedule/Calendar/Timeline.tsx +287 -0
- package/src/schedule/Calendar/ZoneChip.tsx +73 -0
- package/src/schedule/Calendar/calendar-shell.ts +160 -0
- package/src/schedule/Calendar/calendar-state.ts +30 -0
- package/src/schedule/Calendar/now-spans.tsx +33 -0
- package/src/schedule/Calendar/shared.ts +3 -0
- package/src/schedule/Calendar/state-actions.ts +189 -0
- package/src/schedule/Calendar/state-base.ts +143 -0
- package/src/schedule/Calendar/state-keys.ts +128 -0
- package/src/schedule/Calendar/time-fit.ts +84 -0
- package/src/schedule/Calendar.tsx +182 -0
- package/src/schedule/EventEditor.tsx +267 -0
- package/src/schedule/EventPopover.tsx +190 -0
- package/src/schedule/MeetingPlanner-model.ts +222 -0
- package/src/schedule/MeetingPlanner-view.tsx +310 -0
- package/src/schedule/MeetingPlanner.tsx +122 -0
- package/src/schedule/MoveSheet.tsx +168 -0
- package/src/schedule/YearView-model.ts +164 -0
- package/src/schedule/YearView-parts.tsx +147 -0
- package/src/schedule/YearView.tsx +100 -0
- package/src/schedule/bits.tsx +65 -0
- package/src/schedule/index.ts +25 -0
- package/src/skeleton-css.ts +4 -0
- package/src/styles.ts +13 -0
- package/src/type.css +15 -0
- package/src/ui.ts +41 -0
- package/src/use-ui.ts +10 -0
- package/tailwind.css +38 -0
- package/tokens/color.mjs +87 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Slot and wheel views for time fields.
|
|
2
|
+
import {
|
|
3
|
+
dayPeriods,
|
|
4
|
+
fieldName,
|
|
5
|
+
fmtTime,
|
|
6
|
+
hour12,
|
|
7
|
+
listKey,
|
|
8
|
+
pad,
|
|
9
|
+
uid,
|
|
10
|
+
type ChangeReason,
|
|
11
|
+
type IsoTime,
|
|
12
|
+
} from '@kerf-js/veneer-core'
|
|
13
|
+
import { flush, onMount, state, untrack, type State } from '@kerf-js/core'
|
|
14
|
+
|
|
15
|
+
/** The slot list (04 TimeField): a listbox with an active option, not a row of tab stops. */
|
|
16
|
+
export function Slots({
|
|
17
|
+
slots,
|
|
18
|
+
selected,
|
|
19
|
+
locale,
|
|
20
|
+
hourCycle,
|
|
21
|
+
label,
|
|
22
|
+
onPick,
|
|
23
|
+
meta,
|
|
24
|
+
}: {
|
|
25
|
+
slots: string[]
|
|
26
|
+
selected: string | null
|
|
27
|
+
locale: string
|
|
28
|
+
hourCycle?: string | undefined
|
|
29
|
+
label: string
|
|
30
|
+
onPick: (t: string, r: ChangeReason) => void
|
|
31
|
+
meta?: boolean | undefined
|
|
32
|
+
}) {
|
|
33
|
+
const id = uid('slots')
|
|
34
|
+
const near = () =>
|
|
35
|
+
Math.max(
|
|
36
|
+
0,
|
|
37
|
+
slots.findIndex((x) => x >= (untrack(() => selected) ?? '09:00')),
|
|
38
|
+
)
|
|
39
|
+
const active = state(untrack(near))
|
|
40
|
+
let list: HTMLUListElement | undefined
|
|
41
|
+
const show = (block: ScrollLogicalPosition) =>
|
|
42
|
+
list?.querySelector<HTMLElement>('[data-active]')?.scrollIntoView?.({ block })
|
|
43
|
+
const onKey = (e: KeyboardEvent) => {
|
|
44
|
+
const m = listKey(e.key, active.value, slots.length)
|
|
45
|
+
if (!m.handled) return
|
|
46
|
+
e.preventDefault()
|
|
47
|
+
if (m.pick) return onPick(slots[active.value]!, 'keyboard')
|
|
48
|
+
active.value = m.to
|
|
49
|
+
flush()
|
|
50
|
+
show('nearest')
|
|
51
|
+
}
|
|
52
|
+
onMount(() => show('center'))
|
|
53
|
+
return (
|
|
54
|
+
<ul
|
|
55
|
+
ref={(n) => (list = n)}
|
|
56
|
+
data-part="listbox"
|
|
57
|
+
role="listbox"
|
|
58
|
+
tabindex="0"
|
|
59
|
+
data-initial=""
|
|
60
|
+
aria-label={label}
|
|
61
|
+
aria-activedescendant={`${id}-${active.value}`}
|
|
62
|
+
onKeyDown={onKey}
|
|
63
|
+
>
|
|
64
|
+
{slots.map((x, n) => (
|
|
65
|
+
<Slot
|
|
66
|
+
key={x}
|
|
67
|
+
id={`${id}-${n}`}
|
|
68
|
+
time={x}
|
|
69
|
+
text={fmtTime(x, locale, hourCycle)}
|
|
70
|
+
selected={x === selected}
|
|
71
|
+
active={n === active.value}
|
|
72
|
+
meta={meta}
|
|
73
|
+
onPick={onPick}
|
|
74
|
+
/>
|
|
75
|
+
))}
|
|
76
|
+
</ul>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
const Slot = ({
|
|
80
|
+
id,
|
|
81
|
+
time,
|
|
82
|
+
text,
|
|
83
|
+
selected,
|
|
84
|
+
active,
|
|
85
|
+
meta,
|
|
86
|
+
onPick,
|
|
87
|
+
}: {
|
|
88
|
+
id: string
|
|
89
|
+
time: string
|
|
90
|
+
text: string
|
|
91
|
+
selected: boolean
|
|
92
|
+
active: boolean
|
|
93
|
+
meta?: boolean | undefined
|
|
94
|
+
onPick: (t: string, r: ChangeReason) => void
|
|
95
|
+
}) => (
|
|
96
|
+
<li
|
|
97
|
+
role="option"
|
|
98
|
+
id={id}
|
|
99
|
+
aria-selected={selected ? 'true' : 'false'}
|
|
100
|
+
data-active={active ? '' : undefined}
|
|
101
|
+
onClick={() => onPick(time, 'pointer')}
|
|
102
|
+
>
|
|
103
|
+
{text}
|
|
104
|
+
{meta && <span data-part="opt-meta">{time}</span>}
|
|
105
|
+
</li>
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
/** The wheel sheet of a phone (04 §1.2): scroll-snap columns; arrows and presses work too. */
|
|
109
|
+
export function Wheels({
|
|
110
|
+
value,
|
|
111
|
+
locale,
|
|
112
|
+
hourCycle,
|
|
113
|
+
onChange,
|
|
114
|
+
}: {
|
|
115
|
+
value: string | null
|
|
116
|
+
locale: string
|
|
117
|
+
hourCycle?: 'h12' | 'h23' | 'auto' | undefined
|
|
118
|
+
onChange: (t: IsoTime) => void
|
|
119
|
+
}) {
|
|
120
|
+
const h12 = untrack(() => hour12(locale, hourCycle))
|
|
121
|
+
const start = untrack(() => value) ?? '09:30'
|
|
122
|
+
const h0 = +start.slice(0, 2),
|
|
123
|
+
m0 = (Math.round(+start.slice(3, 5) / 5) * 5) % 60
|
|
124
|
+
const periods = untrack(() => dayPeriods(locale))
|
|
125
|
+
const cols = [
|
|
126
|
+
{
|
|
127
|
+
key: 'hour',
|
|
128
|
+
name: untrack(() => fieldName('hour', locale)),
|
|
129
|
+
vals: h12 ? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : Array.from({ length: 24 }, (_, i) => i),
|
|
130
|
+
cur: state(h12 ? h0 % 12 || 12 : h0),
|
|
131
|
+
show: (v: number) => (h12 ? String(v) : pad(v)),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: 'minute',
|
|
135
|
+
name: untrack(() => fieldName('minute', locale)),
|
|
136
|
+
vals: Array.from({ length: 12 }, (_, i) => i * 5),
|
|
137
|
+
cur: state(m0),
|
|
138
|
+
show: (v: number) => pad(v),
|
|
139
|
+
},
|
|
140
|
+
...(h12
|
|
141
|
+
? [
|
|
142
|
+
{
|
|
143
|
+
key: 'dayPeriod',
|
|
144
|
+
name: untrack(() => fieldName('dayPeriod', locale)),
|
|
145
|
+
vals: [0, 1],
|
|
146
|
+
cur: state(h0 >= 12 ? 1 : 0),
|
|
147
|
+
show: (v: number) => periods[v],
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
: []),
|
|
151
|
+
]
|
|
152
|
+
const commit = () => {
|
|
153
|
+
let h = cols[0]!.cur.value
|
|
154
|
+
if (h12) h = (h % 12) + (cols[2]!.cur.value ? 12 : 0)
|
|
155
|
+
onChange(`${pad(h)}:${pad(cols[1]!.cur.value)}` as IsoTime)
|
|
156
|
+
}
|
|
157
|
+
return <div data-scope="wheels">{cols.map((c) => wheelColumn(c, commit))}</div>
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function wheelColumn(
|
|
161
|
+
c: {
|
|
162
|
+
key: string
|
|
163
|
+
name: string
|
|
164
|
+
vals: number[]
|
|
165
|
+
cur: State<number>
|
|
166
|
+
show: (v: number) => string | undefined
|
|
167
|
+
},
|
|
168
|
+
commit: () => void,
|
|
169
|
+
) {
|
|
170
|
+
let list: HTMLUListElement | undefined
|
|
171
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
172
|
+
const row = () =>
|
|
173
|
+
(list!.firstElementChild as HTMLElement | null)?.getBoundingClientRect().height || 40
|
|
174
|
+
const select = (i: number, smooth: boolean) => {
|
|
175
|
+
i = Math.max(0, Math.min(c.vals.length - 1, i))
|
|
176
|
+
c.cur.value = c.vals[i]!
|
|
177
|
+
list?.scrollTo?.({ top: i * row(), behavior: smooth ? 'smooth' : 'instant' })
|
|
178
|
+
commit()
|
|
179
|
+
}
|
|
180
|
+
onMount(() =>
|
|
181
|
+
list?.scrollTo?.({
|
|
182
|
+
top: c.vals.indexOf(c.cur.value) * row(),
|
|
183
|
+
behavior: 'instant' as ScrollBehavior,
|
|
184
|
+
}),
|
|
185
|
+
)
|
|
186
|
+
const onScroll = () => {
|
|
187
|
+
clearTimeout(timer)
|
|
188
|
+
timer = setTimeout(() => {
|
|
189
|
+
const i = Math.round(list!.scrollTop / row())
|
|
190
|
+
if (c.vals[i] !== undefined && c.vals[i] !== c.cur.value) {
|
|
191
|
+
c.cur.value = c.vals[i]
|
|
192
|
+
commit()
|
|
193
|
+
}
|
|
194
|
+
}, 90)
|
|
195
|
+
}
|
|
196
|
+
const onKey = (e: KeyboardEvent) => {
|
|
197
|
+
const d = ({ ArrowDown: 1, ArrowUp: -1 } as Record<string, number>)[e.key]
|
|
198
|
+
if (!d) return
|
|
199
|
+
e.preventDefault()
|
|
200
|
+
select(c.vals.indexOf(c.cur.value) + d, true)
|
|
201
|
+
}
|
|
202
|
+
return (
|
|
203
|
+
<ul
|
|
204
|
+
key={c.key}
|
|
205
|
+
ref={(n) => (list = n)}
|
|
206
|
+
role="listbox"
|
|
207
|
+
tabindex="0"
|
|
208
|
+
aria-label={c.name}
|
|
209
|
+
onScroll={onScroll}
|
|
210
|
+
onKeyDown={onKey}
|
|
211
|
+
>
|
|
212
|
+
{c.vals.map((v) => (
|
|
213
|
+
<li
|
|
214
|
+
key={v}
|
|
215
|
+
role="option"
|
|
216
|
+
aria-selected={c.cur.value === v ? 'true' : 'false'}
|
|
217
|
+
onClick={() => select(c.vals.indexOf(v), true)}
|
|
218
|
+
>
|
|
219
|
+
{c.show(v)}
|
|
220
|
+
</li>
|
|
221
|
+
))}
|
|
222
|
+
</ul>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { fromMinutes, minutes } from '@kerf-js/veneer-core'
|
|
2
|
+
import { Slots } from './TimeField-options'
|
|
3
|
+
import type { dateTimeModel } from './TimeField-date-model'
|
|
4
|
+
|
|
5
|
+
type Model = ReturnType<typeof dateTimeModel>
|
|
6
|
+
|
|
7
|
+
/** Generate selectable time slots at a fixed interval. */
|
|
8
|
+
export const stepSlots = (step: number, min?: string, max?: string) => {
|
|
9
|
+
const from = min ? minutes(min) : 0,
|
|
10
|
+
to = max ? minutes(max) : 1439
|
|
11
|
+
const out: string[] = []
|
|
12
|
+
for (let m = from; m <= to; m += step) out.push(fromMinutes(m))
|
|
13
|
+
return out
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Render the current date-time choices. */
|
|
17
|
+
export function DateTimeSlots({ step, m }: { step: number; m: Model }) {
|
|
18
|
+
const { env, time, emit, pop } = m
|
|
19
|
+
return (
|
|
20
|
+
<Slots
|
|
21
|
+
slots={stepSlots(step)}
|
|
22
|
+
selected={time.value}
|
|
23
|
+
locale={env.locale.value}
|
|
24
|
+
label="Time"
|
|
25
|
+
onPick={(x, reason) => {
|
|
26
|
+
time.value = x
|
|
27
|
+
emit(reason)
|
|
28
|
+
pop.set(false)
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Public time and date-time field options.
|
|
2
|
+
import type { IsoDate, IsoDateTime, IsoTime, TimeZoneId } from '@kerf-js/veneer-core'
|
|
3
|
+
import type { Bindable, Openable, RichFieldProps } from './Picker'
|
|
4
|
+
|
|
5
|
+
/** Props for TimeField. */
|
|
6
|
+
export type TimeFieldProps = RichFieldProps &
|
|
7
|
+
Bindable<IsoTime | null> &
|
|
8
|
+
Openable & {
|
|
9
|
+
/** `h12` shows AM and PM, `h23` a 24-hour clock, `auto` the locale's. */
|
|
10
|
+
hourCycle?: 'h12' | 'h23' | 'auto' | undefined
|
|
11
|
+
step?: number | undefined
|
|
12
|
+
/** Adds a seconds segment. */
|
|
13
|
+
seconds?: boolean | undefined
|
|
14
|
+
min?: IsoTime | undefined
|
|
15
|
+
max?: IsoTime | undefined
|
|
16
|
+
slots?: IsoTime[] | undefined
|
|
17
|
+
/** Only for the DST hint. */
|
|
18
|
+
date?: IsoDate | undefined
|
|
19
|
+
timeZone?: TimeZoneId | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Props for DateTimeField. */
|
|
23
|
+
export type DateTimeFieldProps = RichFieldProps &
|
|
24
|
+
Bindable<IsoDateTime | null> &
|
|
25
|
+
Openable & {
|
|
26
|
+
min?: IsoDate | undefined
|
|
27
|
+
max?: IsoDate | undefined
|
|
28
|
+
/** Return true for a day that can't be picked: it shows struck through. */
|
|
29
|
+
isDateUnavailable?: ((d: IsoDate) => boolean) | undefined
|
|
30
|
+
/** The day each calendar row starts on, 0 for Sunday to 6. The locale's otherwise. */
|
|
31
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined
|
|
32
|
+
step?: number | undefined
|
|
33
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Render the time picker under its caller's owner.
|
|
2
|
+
import { ClockIcon } from '@kerf-js/veneer-icons'
|
|
3
|
+
import { fmtTime, type IsoTime } from '@kerf-js/veneer-core'
|
|
4
|
+
import { Composite, Hidden, Panel, Trigger } from './Picker'
|
|
5
|
+
import { Segments } from './Segments'
|
|
6
|
+
import { Slots, Wheels } from './TimeField-options'
|
|
7
|
+
import type { timeModel } from './TimeField-model'
|
|
8
|
+
|
|
9
|
+
type Model = ReturnType<typeof timeModel>
|
|
10
|
+
|
|
11
|
+
/** Render the time field using its per-instance model. */
|
|
12
|
+
export function timeView(m: Model) {
|
|
13
|
+
const live = liveProps(m.input)
|
|
14
|
+
const { input, env, value, pop, started, dst, sheet, text, options, refs } = m
|
|
15
|
+
return (
|
|
16
|
+
<Composite
|
|
17
|
+
{...input.rest()}
|
|
18
|
+
label={live.label}
|
|
19
|
+
hint={dst.value ?? live.hint}
|
|
20
|
+
error={live.error}
|
|
21
|
+
disabled={live.disabled}
|
|
22
|
+
readonly={live.readonly}
|
|
23
|
+
bound={value}
|
|
24
|
+
onReset={() => (started.value = false)}
|
|
25
|
+
filled={value.value !== null || started.value}
|
|
26
|
+
hold={pop.value}
|
|
27
|
+
control={() => timeControls(m)}
|
|
28
|
+
end={
|
|
29
|
+
<Panel
|
|
30
|
+
label={text.value.chooseTime}
|
|
31
|
+
open={pop}
|
|
32
|
+
trigger={() => refs.trigger!}
|
|
33
|
+
presentation={live.presentation}
|
|
34
|
+
align="end"
|
|
35
|
+
>
|
|
36
|
+
{() =>
|
|
37
|
+
sheet.value ? (
|
|
38
|
+
<Wheels
|
|
39
|
+
value={value.value}
|
|
40
|
+
locale={env.locale.value}
|
|
41
|
+
hourCycle={live.hourCycle}
|
|
42
|
+
onChange={(x) => value.set(x, 'pointer')}
|
|
43
|
+
/>
|
|
44
|
+
) : (
|
|
45
|
+
<Slots
|
|
46
|
+
slots={options.value}
|
|
47
|
+
selected={value.value}
|
|
48
|
+
locale={env.locale.value}
|
|
49
|
+
hourCycle={live.hourCycle}
|
|
50
|
+
label={text.value.chooseTime}
|
|
51
|
+
meta
|
|
52
|
+
onPick={(x, r) => {
|
|
53
|
+
value.set(x as IsoTime, r)
|
|
54
|
+
pop.set(false)
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
</Panel>
|
|
60
|
+
}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function timeControls(m: Model) {
|
|
66
|
+
const live = liveProps(m.input)
|
|
67
|
+
const { input, env, value, pop, text, onEdit, open, refs } = m
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<Segments
|
|
71
|
+
required={input.rest().required}
|
|
72
|
+
kind="time"
|
|
73
|
+
options={{ hourCycle: live.hourCycle, seconds: input.seconds() }}
|
|
74
|
+
locale={env.locale.value}
|
|
75
|
+
value={value.value}
|
|
76
|
+
today={env.today.value}
|
|
77
|
+
disabled={live.disabled}
|
|
78
|
+
readonly={live.readonly}
|
|
79
|
+
onEdit={onEdit}
|
|
80
|
+
/>
|
|
81
|
+
<Trigger
|
|
82
|
+
ref={(n: HTMLButtonElement) => (refs.trigger = n)}
|
|
83
|
+
icon={ClockIcon}
|
|
84
|
+
label={
|
|
85
|
+
text.value.chooseTime +
|
|
86
|
+
(value.value ? `, ${fmtTime(value.value, env.locale.value, live.hourCycle)}` : '')
|
|
87
|
+
}
|
|
88
|
+
open={pop.value}
|
|
89
|
+
disabled={live.disabled}
|
|
90
|
+
onToggle={() => (pop.value ? pop.set(false) : open())}
|
|
91
|
+
/>
|
|
92
|
+
<Hidden name={live.name} value={() => value.value ?? ''} />
|
|
93
|
+
</>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function liveProps(input: Model['input']) {
|
|
98
|
+
return {
|
|
99
|
+
get label() {
|
|
100
|
+
return input.label()
|
|
101
|
+
},
|
|
102
|
+
get hint() {
|
|
103
|
+
return input.hint()
|
|
104
|
+
},
|
|
105
|
+
get error() {
|
|
106
|
+
return input.error()
|
|
107
|
+
},
|
|
108
|
+
get disabled() {
|
|
109
|
+
return input.disabled()
|
|
110
|
+
},
|
|
111
|
+
get readonly() {
|
|
112
|
+
return input.readonly()
|
|
113
|
+
},
|
|
114
|
+
get name() {
|
|
115
|
+
return input.name()
|
|
116
|
+
},
|
|
117
|
+
get presentation() {
|
|
118
|
+
return input.presentation()
|
|
119
|
+
},
|
|
120
|
+
get hourCycle() {
|
|
121
|
+
return input.hourCycle()
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { TimeFieldProps, DateTimeFieldProps } from './TimeField-types'
|
|
2
|
+
import { timeModel } from './TimeField-model'
|
|
3
|
+
import { timeView } from './TimeField-view'
|
|
4
|
+
import { dateTimeModel } from './TimeField-date-model'
|
|
5
|
+
import { dateTimeView } from './TimeField-date-view'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/rich/listbox.css'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/rich/datetime.css'
|
|
8
|
+
|
|
9
|
+
export { stepSlots } from './TimeField-slots'
|
|
10
|
+
|
|
11
|
+
export type { TimeFieldProps, DateTimeFieldProps } from './TimeField-types'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* TimeField (04 §2): segments in the locale's order and cycle; the trigger opens a slot list (wheels in a phone
|
|
15
|
+
* sheet). With `date` and `timeZone`, a wall time that doesn't exist or happens twice gets a hint, and a missing one
|
|
16
|
+
* resolves with `disambiguation: "compatible"`.
|
|
17
|
+
*/
|
|
18
|
+
export function TimeField({
|
|
19
|
+
value,
|
|
20
|
+
defaultValue,
|
|
21
|
+
onValueChange,
|
|
22
|
+
open,
|
|
23
|
+
defaultOpen,
|
|
24
|
+
onOpenChange,
|
|
25
|
+
hourCycle,
|
|
26
|
+
step = 15,
|
|
27
|
+
seconds,
|
|
28
|
+
min,
|
|
29
|
+
max,
|
|
30
|
+
slots,
|
|
31
|
+
date,
|
|
32
|
+
timeZone,
|
|
33
|
+
locale,
|
|
34
|
+
today,
|
|
35
|
+
name,
|
|
36
|
+
presentation,
|
|
37
|
+
label,
|
|
38
|
+
hint,
|
|
39
|
+
error,
|
|
40
|
+
disabled,
|
|
41
|
+
readonly,
|
|
42
|
+
...rest
|
|
43
|
+
}: TimeFieldProps) {
|
|
44
|
+
return timeView(
|
|
45
|
+
timeModel({
|
|
46
|
+
value: () => value,
|
|
47
|
+
defaultValue: () => defaultValue,
|
|
48
|
+
onValueChange: () => onValueChange,
|
|
49
|
+
open: () => open,
|
|
50
|
+
defaultOpen: () => defaultOpen,
|
|
51
|
+
onOpenChange: () => onOpenChange,
|
|
52
|
+
hourCycle: () => hourCycle,
|
|
53
|
+
step: () => step,
|
|
54
|
+
seconds: () => seconds,
|
|
55
|
+
min: () => min,
|
|
56
|
+
max: () => max,
|
|
57
|
+
slots: () => slots,
|
|
58
|
+
date: () => date,
|
|
59
|
+
timeZone: () => timeZone,
|
|
60
|
+
locale: () => locale,
|
|
61
|
+
today: () => today,
|
|
62
|
+
name: () => name,
|
|
63
|
+
presentation: () => presentation,
|
|
64
|
+
label: () => label,
|
|
65
|
+
hint: () => hint,
|
|
66
|
+
error: () => error,
|
|
67
|
+
disabled: () => disabled,
|
|
68
|
+
readonly: () => readonly,
|
|
69
|
+
rest: () => rest,
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* DateTimeField (04 §2): a date group and a time group in one control and one popover, calendar beside the slot list.
|
|
76
|
+
* The value is a wall time with no zone; the hint spells it out in full.
|
|
77
|
+
*/
|
|
78
|
+
export function DateTimeField({
|
|
79
|
+
value,
|
|
80
|
+
defaultValue,
|
|
81
|
+
onValueChange,
|
|
82
|
+
open,
|
|
83
|
+
defaultOpen,
|
|
84
|
+
onOpenChange,
|
|
85
|
+
min,
|
|
86
|
+
max,
|
|
87
|
+
isDateUnavailable,
|
|
88
|
+
firstDayOfWeek,
|
|
89
|
+
step = 30,
|
|
90
|
+
locale,
|
|
91
|
+
today,
|
|
92
|
+
name,
|
|
93
|
+
presentation,
|
|
94
|
+
label,
|
|
95
|
+
hint,
|
|
96
|
+
error,
|
|
97
|
+
disabled,
|
|
98
|
+
readonly,
|
|
99
|
+
...rest
|
|
100
|
+
}: DateTimeFieldProps) {
|
|
101
|
+
return dateTimeView(
|
|
102
|
+
dateTimeModel({
|
|
103
|
+
value: () => value,
|
|
104
|
+
defaultValue: () => defaultValue,
|
|
105
|
+
onValueChange: () => onValueChange,
|
|
106
|
+
open: () => open,
|
|
107
|
+
defaultOpen: () => defaultOpen,
|
|
108
|
+
onOpenChange: () => onOpenChange,
|
|
109
|
+
min: () => min,
|
|
110
|
+
max: () => max,
|
|
111
|
+
isDateUnavailable: () => isDateUnavailable,
|
|
112
|
+
firstDayOfWeek: () => firstDayOfWeek,
|
|
113
|
+
step: () => step,
|
|
114
|
+
locale: () => locale,
|
|
115
|
+
today: () => today,
|
|
116
|
+
name: () => name,
|
|
117
|
+
presentation: () => presentation,
|
|
118
|
+
label: () => label,
|
|
119
|
+
hint: () => hint,
|
|
120
|
+
error: () => error,
|
|
121
|
+
disabled: () => disabled,
|
|
122
|
+
readonly: () => readonly,
|
|
123
|
+
rest: () => rest,
|
|
124
|
+
}),
|
|
125
|
+
)
|
|
126
|
+
}
|
package/src/Toast.tsx
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { XIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import {
|
|
3
|
+
toaster,
|
|
4
|
+
toastStore,
|
|
5
|
+
type Toast,
|
|
6
|
+
type ToastInput,
|
|
7
|
+
type ToastPromise,
|
|
8
|
+
} from '@kerf-js/veneer-core'
|
|
9
|
+
import { onCleanup, state, untrack, watch } from '@kerf-js/core'
|
|
10
|
+
import { Icon, toneIcon } from './Icon'
|
|
11
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
12
|
+
import './styles'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/components/button.css' // the action and dismiss buttons' markup
|
|
14
|
+
import '@kerf-js/veneer-core/styles/components/spinner.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/components/toast.css'
|
|
16
|
+
|
|
17
|
+
let store: ReturnType<typeof toastStore> | undefined
|
|
18
|
+
const toasts = () => (store ??= toastStore())
|
|
19
|
+
|
|
20
|
+
// The Toasters mounted, oldest first. They share one list, so only the newest shows it: a page that mounts more
|
|
21
|
+
// than one (a layout's and a demo's) still shows each toast once. One whose corner changes is the one in use, and
|
|
22
|
+
// comes to the front.
|
|
23
|
+
const mounted = state<object[]>([])
|
|
24
|
+
const toFront = (list: object[], me: object) => [...list.filter((k) => k !== me), me]
|
|
25
|
+
|
|
26
|
+
/** Joins the mounted list as it renders, comes to the front when `position` changes, and says if it is in front.
|
|
27
|
+
* On the server nothing mounts for long, so every Toaster renders the list as it stands. */
|
|
28
|
+
function inFront(position: () => unknown) {
|
|
29
|
+
const me = {}
|
|
30
|
+
const front = () => {
|
|
31
|
+
const m = untrack(() => mounted.value)
|
|
32
|
+
if (m.at(-1) !== me) mounted.value = toFront(m, me)
|
|
33
|
+
}
|
|
34
|
+
if (typeof document !== 'undefined') front()
|
|
35
|
+
watch(position, front)
|
|
36
|
+
onCleanup(() => (mounted.value = mounted.value.filter((k) => k !== me)))
|
|
37
|
+
return () => !mounted.value.length || mounted.value.at(-1) === me
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Show a toast from anywhere (05 §5): `toast.show({ title, description, tone, action })`. Needs one <Toaster />.
|
|
42
|
+
* Life is 5s + 60ms a word, 10s with an action; a critical toast with an action stays until dismissed.
|
|
43
|
+
*/
|
|
44
|
+
export const toast = {
|
|
45
|
+
show: (t: ToastInput) => toasts().show(t),
|
|
46
|
+
dismiss: (id: string) => toasts().dismiss(id),
|
|
47
|
+
/** One toast through a promise's life: `pending`, then `done` or `error`, in place. Returns the promise. */
|
|
48
|
+
promise: <T,>(p: Promise<T>, messages: ToastPromise<T>) => toasts().promise(p, messages),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ToasterProps = {
|
|
52
|
+
/** Which corner or edge. Bottom right by default. */ position?:
|
|
53
|
+
| 'top-left'
|
|
54
|
+
| 'top-center'
|
|
55
|
+
| 'top-right'
|
|
56
|
+
| 'bottom-left'
|
|
57
|
+
| 'bottom-center'
|
|
58
|
+
| 'bottom-right'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The toast region and the two pre-mounted live regions (05 §5; components.html:1115-1117). Mount once, near the
|
|
63
|
+
* root. While a modal is open they move into it, or it would make them inert. Newest first; three stack, collapsed, and fan out on hover or focus (which pauses every timer); swipe or
|
|
64
|
+
* Dismiss removes one; F8 focuses the newest.
|
|
65
|
+
*/
|
|
66
|
+
export function Toaster(props: ToasterProps = {}) {
|
|
67
|
+
const list = state<Toast[]>(toasts().get())
|
|
68
|
+
onCleanup(toasts().subscribe((v) => (list.value = v)))
|
|
69
|
+
const mine = inFront(() => props.position)
|
|
70
|
+
let region: HTMLElement | undefined
|
|
71
|
+
use(
|
|
72
|
+
toaster,
|
|
73
|
+
() => region,
|
|
74
|
+
() => toasts(),
|
|
75
|
+
)
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<section
|
|
79
|
+
ref={(n) => (region = n)}
|
|
80
|
+
data-scope="toast"
|
|
81
|
+
data-part="region"
|
|
82
|
+
data-position={props.position === 'bottom-right' ? undefined : props.position}
|
|
83
|
+
aria-label="Notifications (F8)"
|
|
84
|
+
tabindex="-1"
|
|
85
|
+
>
|
|
86
|
+
{(mine() ? list.value : []).map((t) => (
|
|
87
|
+
<div
|
|
88
|
+
key={t.id}
|
|
89
|
+
data-scope="toast"
|
|
90
|
+
data-part="root"
|
|
91
|
+
data-id={t.id}
|
|
92
|
+
data-tone={t.tone ?? 'neutral'}
|
|
93
|
+
data-state={t.state}
|
|
94
|
+
role="group"
|
|
95
|
+
aria-label={t.title}
|
|
96
|
+
>
|
|
97
|
+
{t.loading ? (
|
|
98
|
+
<span data-scope="spinner" data-part="icon" aria-hidden="true"></span>
|
|
99
|
+
) : (
|
|
100
|
+
<Icon name={toneIcon[t.tone ?? 'neutral']} data-part="icon" />
|
|
101
|
+
)}
|
|
102
|
+
<div data-part="title">{t.title}</div>
|
|
103
|
+
{t.description && <div data-part="description">{t.description}</div>}
|
|
104
|
+
<div data-part="actions">
|
|
105
|
+
{/* ghost <Button>s as their markup: they need no JS */}
|
|
106
|
+
{t.action && (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
data-scope="button"
|
|
110
|
+
data-emphasis="ghost"
|
|
111
|
+
data-size="sm"
|
|
112
|
+
data-act=""
|
|
113
|
+
onClick={() => {
|
|
114
|
+
t.action!.onClick()
|
|
115
|
+
toast.dismiss(t.id)
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{t.action.label}
|
|
119
|
+
</button>
|
|
120
|
+
)}
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
data-scope="button"
|
|
124
|
+
data-emphasis="ghost"
|
|
125
|
+
data-tone="neutral"
|
|
126
|
+
data-size="sm"
|
|
127
|
+
data-icon-only=""
|
|
128
|
+
aria-label="Dismiss"
|
|
129
|
+
data-x=""
|
|
130
|
+
onClick={() => toast.dismiss(t.id)}
|
|
131
|
+
>
|
|
132
|
+
<XIcon />
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
{t.life > 0 && <span data-part="progress" aria-hidden="true"></span>}
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
</section>
|
|
139
|
+
<div data-scope="announcer" role="status" aria-live="polite" aria-atomic="true"></div>
|
|
140
|
+
<div data-scope="announcer" role="alert" aria-live="assertive" aria-atomic="true"></div>
|
|
141
|
+
</>
|
|
142
|
+
)
|
|
143
|
+
}
|