@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,375 @@
|
|
|
1
|
+
import {
|
|
2
|
+
meterParts,
|
|
3
|
+
money,
|
|
4
|
+
planPrice,
|
|
5
|
+
prorate,
|
|
6
|
+
uid,
|
|
7
|
+
type BillingInterval,
|
|
8
|
+
type Proration,
|
|
9
|
+
} from '@kerf-js/veneer-core'
|
|
10
|
+
import { derived, state, type State, untrack } from '@kerf-js/core'
|
|
11
|
+
import { Alert } from '../Alert'
|
|
12
|
+
import { Badge } from '../Badge'
|
|
13
|
+
import { Button } from '../Button'
|
|
14
|
+
import { Modal } from '../Modal'
|
|
15
|
+
import { Segmented } from '../Choice'
|
|
16
|
+
import { toast } from '../Toast'
|
|
17
|
+
import { Sweep, latch } from './atoms'
|
|
18
|
+
import '../styles'
|
|
19
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
20
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
21
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
22
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
23
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
24
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
25
|
+
import '@kerf-js/veneer-core/styles/flows/plans.css'
|
|
26
|
+
import '@kerf-js/veneer-core/styles/flows/plan-card.css'
|
|
27
|
+
import '@kerf-js/veneer-core/styles/flows/lines.css'
|
|
28
|
+
import '@kerf-js/veneer-core/styles/flows/usage.css'
|
|
29
|
+
import '@kerf-js/veneer-core/styles/flows/meter.css'
|
|
30
|
+
import '@kerf-js/veneer-core/styles/flows/confirm.css'
|
|
31
|
+
|
|
32
|
+
/** A plan on offer. */
|
|
33
|
+
export type BillingPlan = {
|
|
34
|
+
id: string
|
|
35
|
+
name: string
|
|
36
|
+
/** Per seat, per month. */ price: number
|
|
37
|
+
description?: string | undefined
|
|
38
|
+
features: string[]
|
|
39
|
+
limits?: Record<string, number>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Props for PlanPicker. */
|
|
43
|
+
export interface PlanPickerProps {
|
|
44
|
+
/** The plans to compare, one card each. */
|
|
45
|
+
plans: BillingPlan[]
|
|
46
|
+
current: string
|
|
47
|
+
/** The checked card; a usage meter can preselect the next tier through it. */
|
|
48
|
+
selected?: State<string>
|
|
49
|
+
interval?: State<BillingInterval>
|
|
50
|
+
seats: number
|
|
51
|
+
daysLeft: number
|
|
52
|
+
periodDays?: number
|
|
53
|
+
/** The ISO 4217 code prices are shown in, such as `EUR`. */
|
|
54
|
+
currency?: string
|
|
55
|
+
locale?: string
|
|
56
|
+
/** The server's proration. Default: `prorate` from the numbers above. */
|
|
57
|
+
preview?: (plan: BillingPlan, interval: BillingInterval) => Promise<Proration> | Proration
|
|
58
|
+
/** What stops working on a downgrade, listed in the dialog. */
|
|
59
|
+
losses?: (plan: BillingPlan) => string[]
|
|
60
|
+
/** Resolve with a message (card declined, seat limit) to keep the dialog with an Alert. */
|
|
61
|
+
onChange: (plan: BillingPlan, interval: BillingInterval) => Promise<string | void> | string | void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function planConfirm({
|
|
65
|
+
props,
|
|
66
|
+
next,
|
|
67
|
+
cycle,
|
|
68
|
+
open,
|
|
69
|
+
busy,
|
|
70
|
+
problem,
|
|
71
|
+
up,
|
|
72
|
+
}: {
|
|
73
|
+
props: PlanPickerProps
|
|
74
|
+
next: { readonly value: BillingPlan }
|
|
75
|
+
cycle: State<BillingInterval>
|
|
76
|
+
open: State<boolean>
|
|
77
|
+
busy: State<boolean>
|
|
78
|
+
problem: State<string>
|
|
79
|
+
up: { readonly value: boolean }
|
|
80
|
+
}) {
|
|
81
|
+
const confirm = async () => {
|
|
82
|
+
if (busy.value) return
|
|
83
|
+
busy.value = true
|
|
84
|
+
try {
|
|
85
|
+
const msg = await props.onChange(next.value, cycle.value)
|
|
86
|
+
if (msg) problem.value = msg
|
|
87
|
+
else {
|
|
88
|
+
open.value = false
|
|
89
|
+
toast.show({
|
|
90
|
+
title: `You’re on ${next.value.name}`,
|
|
91
|
+
description: up.value
|
|
92
|
+
? 'New limits are live. A receipt is on its way.'
|
|
93
|
+
: 'The change applies at the end of this period.',
|
|
94
|
+
tone: 'positive',
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
} catch {
|
|
98
|
+
toast.show({
|
|
99
|
+
title: 'The plan didn’t change',
|
|
100
|
+
description: 'Try again in a moment.',
|
|
101
|
+
tone: 'critical',
|
|
102
|
+
action: { label: 'Retry', onClick: confirm },
|
|
103
|
+
})
|
|
104
|
+
} finally {
|
|
105
|
+
busy.value = false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return confirm
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function planModel(props: PlanPickerProps) {
|
|
112
|
+
const group = uid('plan')
|
|
113
|
+
const picked = untrack(() => props.selected) ?? state(untrack(() => props.current))
|
|
114
|
+
const cycle = untrack(() => props.interval) ?? state<BillingInterval>('month')
|
|
115
|
+
const open = state(false)
|
|
116
|
+
const armed = latch(open)
|
|
117
|
+
const quote = state<Proration | undefined>(undefined)
|
|
118
|
+
const busy = state(false)
|
|
119
|
+
const problem = state('')
|
|
120
|
+
const find = (id: string) => props.plans.find((p) => p.id === id)!
|
|
121
|
+
const cost = (n: number) => money(n, props.currency, props.locale)
|
|
122
|
+
const now = derived(() => find(props.current))
|
|
123
|
+
const next = derived(() => find(picked.value))
|
|
124
|
+
const up = derived(() => next.value.price > now.value.price)
|
|
125
|
+
const same = derived(() => picked.value === props.current)
|
|
126
|
+
const per = (p: BillingPlan) =>
|
|
127
|
+
!p.price
|
|
128
|
+
? 'free forever'
|
|
129
|
+
: cycle.value === 'year'
|
|
130
|
+
? 'per seat / month, billed yearly'
|
|
131
|
+
: 'per seat / month'
|
|
132
|
+
const pitch = derived(() => {
|
|
133
|
+
if (same.value) return `You’re on ${now.value.name}. Pick a plan to compare.`
|
|
134
|
+
return up.value
|
|
135
|
+
? `${next.value.name} adds more. You pay the difference for the rest of this period.`
|
|
136
|
+
: `${next.value.name} starts at the end of this period.`
|
|
137
|
+
})
|
|
138
|
+
const review = async () => {
|
|
139
|
+
const p = next.value
|
|
140
|
+
const c = cycle.value
|
|
141
|
+
problem.value = ''
|
|
142
|
+
quote.value = props.preview
|
|
143
|
+
? await props.preview(p, c)
|
|
144
|
+
: prorate({
|
|
145
|
+
from: { name: now.value.name, price: planPrice(now.value.price, c) },
|
|
146
|
+
to: { name: p.name, price: planPrice(p.price, c) },
|
|
147
|
+
seats: props.seats,
|
|
148
|
+
daysLeft: props.daysLeft,
|
|
149
|
+
periodDays: props.periodDays === undefined ? 30 : props.periodDays,
|
|
150
|
+
})
|
|
151
|
+
open.value = true
|
|
152
|
+
}
|
|
153
|
+
const confirm = planConfirm({ props, next, cycle, open, busy, problem, up })
|
|
154
|
+
const lost = derived(() => (up.value || same.value ? [] : (props.losses?.(next.value) ?? [])))
|
|
155
|
+
return {
|
|
156
|
+
planGroup: group,
|
|
157
|
+
picked,
|
|
158
|
+
cycle,
|
|
159
|
+
open,
|
|
160
|
+
armed,
|
|
161
|
+
planQuote: quote,
|
|
162
|
+
busy,
|
|
163
|
+
problem,
|
|
164
|
+
cost,
|
|
165
|
+
up,
|
|
166
|
+
same,
|
|
167
|
+
per,
|
|
168
|
+
pitch,
|
|
169
|
+
review,
|
|
170
|
+
confirm,
|
|
171
|
+
lost,
|
|
172
|
+
next,
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function planDialog(model: ReturnType<typeof planModel>) {
|
|
177
|
+
const { open, up, next, busy, confirm, problem, planQuote: quote, cost, lost } = model
|
|
178
|
+
return (
|
|
179
|
+
<Modal
|
|
180
|
+
open={open}
|
|
181
|
+
size="sm"
|
|
182
|
+
title={`${up.value ? 'Upgrade' : 'Switch'} to ${next.value.name}`}
|
|
183
|
+
description={
|
|
184
|
+
up.value
|
|
185
|
+
? 'Your new limits apply as soon as you confirm.'
|
|
186
|
+
: 'This applies at the end of this period.'
|
|
187
|
+
}
|
|
188
|
+
footer={
|
|
189
|
+
<>
|
|
190
|
+
<Button emphasis="frame" data-close="">
|
|
191
|
+
Cancel
|
|
192
|
+
</Button>
|
|
193
|
+
<Button autofocus loading={busy.value} onClick={confirm}>
|
|
194
|
+
{up.value ? 'Confirm upgrade' : 'Confirm switch'}
|
|
195
|
+
</Button>
|
|
196
|
+
</>
|
|
197
|
+
}
|
|
198
|
+
>
|
|
199
|
+
<div data-scope="stack">
|
|
200
|
+
{problem.value && (
|
|
201
|
+
<Alert tone="critical" live title="The plan didn’t change">
|
|
202
|
+
{problem.value}
|
|
203
|
+
</Alert>
|
|
204
|
+
)}
|
|
205
|
+
<dl data-scope="lines">
|
|
206
|
+
{(quote.value?.lines ?? []).map((l) => (
|
|
207
|
+
<div key={l.label}>
|
|
208
|
+
<dt>{l.label}</dt>
|
|
209
|
+
<dd>{l.amount < 0 ? `−${cost(-l.amount)}` : cost(l.amount)}</dd>
|
|
210
|
+
</div>
|
|
211
|
+
))}
|
|
212
|
+
<div data-part="total">
|
|
213
|
+
<dt>{quote.value?.due === 'today' ? 'Due today' : 'Due next period'}</dt>
|
|
214
|
+
<dd>{cost(quote.value?.total ?? 0)}</dd>
|
|
215
|
+
</div>
|
|
216
|
+
</dl>
|
|
217
|
+
{lost.value.length > 0 && (
|
|
218
|
+
<div data-scope="confirm">
|
|
219
|
+
<span class="muted">These stop working:</span>
|
|
220
|
+
<ul>
|
|
221
|
+
{lost.value.map((t) => (
|
|
222
|
+
<li key={t}>{t}</li>
|
|
223
|
+
))}
|
|
224
|
+
</ul>
|
|
225
|
+
</div>
|
|
226
|
+
)}
|
|
227
|
+
<span class="muted">Charged to the default card.</span>
|
|
228
|
+
</div>
|
|
229
|
+
</Modal>
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function planView(props: PlanPickerProps, model: ReturnType<typeof planModel>) {
|
|
234
|
+
const { planGroup: group, picked, cycle, armed, cost, up, same, per, pitch, review, next } = model
|
|
235
|
+
return (
|
|
236
|
+
<div data-scope="stack">
|
|
237
|
+
<div data-scope="row">
|
|
238
|
+
<Segmented
|
|
239
|
+
label="Billing period"
|
|
240
|
+
value={cycle.value}
|
|
241
|
+
onChange={(v) => (cycle.value = v)}
|
|
242
|
+
size="sm"
|
|
243
|
+
options={[
|
|
244
|
+
{ value: 'month', label: 'Monthly' },
|
|
245
|
+
{ value: 'year', label: 'Annual · save 20%' },
|
|
246
|
+
]}
|
|
247
|
+
/>
|
|
248
|
+
</div>
|
|
249
|
+
<div data-scope="plans">
|
|
250
|
+
<div data-part="grid" role="radiogroup" aria-label="Plan">
|
|
251
|
+
{props.plans.map((p) => (
|
|
252
|
+
<label key={p.id} data-scope="plan-card" data-sweep="">
|
|
253
|
+
<Sweep />
|
|
254
|
+
<input
|
|
255
|
+
type="radio"
|
|
256
|
+
name={group}
|
|
257
|
+
value={p.id}
|
|
258
|
+
checked={p.id === picked.value}
|
|
259
|
+
onChange={() => (picked.value = p.id)}
|
|
260
|
+
/>
|
|
261
|
+
<span data-part="name">
|
|
262
|
+
<span class="row">
|
|
263
|
+
<span data-part="radio" aria-hidden="true"></span>
|
|
264
|
+
{p.name}
|
|
265
|
+
</span>
|
|
266
|
+
{p.id === props.current && <Badge tone="neutral">Current</Badge>}
|
|
267
|
+
</span>
|
|
268
|
+
<span data-part="price">
|
|
269
|
+
<b>{cost(planPrice(p.price, cycle.value))}</b>
|
|
270
|
+
<span>{per(p)}</span>
|
|
271
|
+
</span>
|
|
272
|
+
{p.description && <span class="muted">{p.description}</span>}
|
|
273
|
+
<ul>
|
|
274
|
+
{p.features.map((f) => (
|
|
275
|
+
<li key={f}>{f}</li>
|
|
276
|
+
))}
|
|
277
|
+
</ul>
|
|
278
|
+
</label>
|
|
279
|
+
))}
|
|
280
|
+
</div>
|
|
281
|
+
<div data-scope="row" data-justify="between">
|
|
282
|
+
<span class="muted" role="status">
|
|
283
|
+
{pitch.value}
|
|
284
|
+
</span>
|
|
285
|
+
{same.value && (
|
|
286
|
+
<Button emphasis="soft" tone="neutral" disabled>
|
|
287
|
+
Current plan
|
|
288
|
+
</Button>
|
|
289
|
+
)}
|
|
290
|
+
{!same.value && up.value && (
|
|
291
|
+
<Button onClick={review}>Upgrade to {next.value.name}</Button>
|
|
292
|
+
)}
|
|
293
|
+
{!same.value && !up.value && (
|
|
294
|
+
<Button emphasis="frame" onClick={review}>
|
|
295
|
+
Switch to {next.value.name}
|
|
296
|
+
</Button>
|
|
297
|
+
)}
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
{armed.value && planDialog(model)}
|
|
301
|
+
</div>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The plan picker (09 §4.3): radio cards in a radiogroup, the checked card's sweep pinned, Monthly/Annual above. Arrow
|
|
307
|
+
* keys only compare; the primary opens the proration dialog: line items, the new total, when it applies, Confirm.
|
|
308
|
+
*/
|
|
309
|
+
export function PlanPicker(props: PlanPickerProps) {
|
|
310
|
+
const live = untrack(() => props)
|
|
311
|
+
return planView(live, planModel(live))
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Props for UsageMeter. */
|
|
315
|
+
export interface UsageMeterProps {
|
|
316
|
+
label: string
|
|
317
|
+
value: number
|
|
318
|
+
limit: number
|
|
319
|
+
format?: ((n: number) => string) | undefined
|
|
320
|
+
/** Past the limit: "+ $12.40 overage". */
|
|
321
|
+
overage?: string
|
|
322
|
+
note?: string
|
|
323
|
+
/** A link to the plan picker preselected on the next tier. */
|
|
324
|
+
action?: unknown
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** A usage meter (09 §4.3): the warning tick at 80%, caution from 80%, critical at 100%, stripes past the limit. */
|
|
328
|
+
export function UsageMeter({
|
|
329
|
+
label,
|
|
330
|
+
value,
|
|
331
|
+
limit,
|
|
332
|
+
format = String,
|
|
333
|
+
overage,
|
|
334
|
+
note,
|
|
335
|
+
action,
|
|
336
|
+
}: UsageMeterProps) {
|
|
337
|
+
const m = derived(() => meterParts(value, limit))
|
|
338
|
+
const said = derived(() =>
|
|
339
|
+
m.value.over
|
|
340
|
+
? (overage ?? `${m.value.percent}% used.`)
|
|
341
|
+
: `${m.value.percent}% used.${m.value.tone && note ? ` ${note}` : ''}`,
|
|
342
|
+
)
|
|
343
|
+
return (
|
|
344
|
+
<div data-scope="meter" data-tone={m.value.tone}>
|
|
345
|
+
<div data-part="head">
|
|
346
|
+
<b>{label}</b>
|
|
347
|
+
<span>
|
|
348
|
+
{format(value)} / {format(limit)}
|
|
349
|
+
</span>
|
|
350
|
+
</div>
|
|
351
|
+
<span
|
|
352
|
+
data-part="rail"
|
|
353
|
+
data-on=""
|
|
354
|
+
role="meter"
|
|
355
|
+
aria-label={label}
|
|
356
|
+
aria-valuemin="0"
|
|
357
|
+
aria-valuemax={limit}
|
|
358
|
+
aria-valuenow={Math.min(value, limit)}
|
|
359
|
+
aria-valuetext={`${format(value)} of ${format(limit)}`}
|
|
360
|
+
style={`--v:${m.value.fill}%;--over:${m.value.over}%;--warn:${m.value.warn}%`}
|
|
361
|
+
>
|
|
362
|
+
<span data-part="rail-fill"></span>
|
|
363
|
+
{m.value.over > 0 && <span data-part="over"></span>}
|
|
364
|
+
<span data-part="tick" aria-hidden="true"></span>
|
|
365
|
+
</span>
|
|
366
|
+
<p data-part="note">{said.value}</p>
|
|
367
|
+
{action}
|
|
368
|
+
</div>
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The group of usage meters. */
|
|
373
|
+
export const UsageMeters = ({ children }: { children: unknown }) => (
|
|
374
|
+
<div data-scope="usage">{children}</div>
|
|
375
|
+
)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { State } from '@kerf-js/core'
|
|
2
|
+
import { toast } from '../../Toast'
|
|
3
|
+
import { afterFlush } from '../atoms'
|
|
4
|
+
import type { FieldErrors, SaveBarProps } from '../SaveBar'
|
|
5
|
+
|
|
6
|
+
const SAVED_MS = 1500
|
|
7
|
+
type Data<T> = {
|
|
8
|
+
box: State<T>
|
|
9
|
+
base: State<T>
|
|
10
|
+
phase: State<'idle' | 'pending' | 'saved'>
|
|
11
|
+
fixes: State<number>
|
|
12
|
+
leaving: State<boolean>
|
|
13
|
+
dirty: { readonly value: boolean }
|
|
14
|
+
refs: {
|
|
15
|
+
target: string
|
|
16
|
+
el?: HTMLDivElement | undefined
|
|
17
|
+
timer?: ReturnType<typeof setTimeout> | undefined
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function saveActions<T extends Record<string, unknown>>({
|
|
21
|
+
d,
|
|
22
|
+
errors,
|
|
23
|
+
validate,
|
|
24
|
+
onSave,
|
|
25
|
+
onDiscard,
|
|
26
|
+
hasLeave,
|
|
27
|
+
onLeave,
|
|
28
|
+
}: {
|
|
29
|
+
d: Data<T>
|
|
30
|
+
errors: () => SaveBarProps<T>['errors']
|
|
31
|
+
validate: (now: T) => FieldErrors | undefined
|
|
32
|
+
onSave: SaveBarProps<T>['onSave']
|
|
33
|
+
onDiscard: () => void
|
|
34
|
+
hasLeave: () => SaveBarProps<T>['onLeave']
|
|
35
|
+
onLeave: () => void
|
|
36
|
+
}) {
|
|
37
|
+
const { box, base, phase, fixes, leaving, dirty, refs } = d
|
|
38
|
+
const fail = (found: FieldErrors) => {
|
|
39
|
+
if (errors()) errors()!.value = found
|
|
40
|
+
fixes.value = Object.keys(found).length
|
|
41
|
+
afterFlush(() =>
|
|
42
|
+
refs.el?.closest('form')?.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus(),
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
const save = async () => {
|
|
46
|
+
if (phase.value === 'pending' || !dirty.value) return
|
|
47
|
+
const now = box.value
|
|
48
|
+
const found = validate(now)
|
|
49
|
+
if (found && Object.keys(found).length) return fail(found)
|
|
50
|
+
phase.value = 'pending'
|
|
51
|
+
try {
|
|
52
|
+
const back = await onSave(now)
|
|
53
|
+
if (back && Object.keys(back).length) {
|
|
54
|
+
phase.value = 'idle'
|
|
55
|
+
return fail(back)
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
phase.value = 'idle'
|
|
59
|
+
toast.show({
|
|
60
|
+
title: 'That didn’t save',
|
|
61
|
+
description: 'Your changes are still here.',
|
|
62
|
+
tone: 'critical',
|
|
63
|
+
action: { label: 'Retry', onClick: save },
|
|
64
|
+
})
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (errors()) errors()!.value = {}
|
|
68
|
+
fixes.value = 0
|
|
69
|
+
base.value = now
|
|
70
|
+
phase.value = 'saved'
|
|
71
|
+
refs.timer = setTimeout(() => (phase.value = 'idle'), SAVED_MS)
|
|
72
|
+
}
|
|
73
|
+
const discard = () => {
|
|
74
|
+
box.value = base.value
|
|
75
|
+
if (errors()) errors()!.value = {}
|
|
76
|
+
fixes.value = 0
|
|
77
|
+
onDiscard()
|
|
78
|
+
}
|
|
79
|
+
const leave = () => {
|
|
80
|
+
leaving.value = false
|
|
81
|
+
discard()
|
|
82
|
+
if (hasLeave()) onLeave()
|
|
83
|
+
else refs.el?.ownerDocument.defaultView?.location.assign(refs.target)
|
|
84
|
+
}
|
|
85
|
+
return { save, discard, leave }
|
|
86
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { dirtyKeys, leaveGuard, plural } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, onCleanup, state, type State, untrack } from '@kerf-js/core'
|
|
3
|
+
import { Button } from '../Button'
|
|
4
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
5
|
+
import { ConfirmDialog } from './Danger'
|
|
6
|
+
import { saveActions } from './SaveBar/actions'
|
|
7
|
+
import '../styles'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/flows/save-bar.css'
|
|
15
|
+
|
|
16
|
+
/** Messages by field name. */
|
|
17
|
+
export type FieldErrors = Record<string, string>
|
|
18
|
+
/** Props for SaveBar. */
|
|
19
|
+
export interface SaveBarProps<T extends Record<string, unknown>> {
|
|
20
|
+
/** The live form values. The bar snapshots them at mount and after each save. */
|
|
21
|
+
values: State<T>
|
|
22
|
+
/** Field errors, written here for the fields to read. */
|
|
23
|
+
errors?: State<FieldErrors> | undefined
|
|
24
|
+
/** Client checks; anything returned stops the save. */
|
|
25
|
+
validate?: ((values: T) => FieldErrors) | undefined
|
|
26
|
+
/** Resolve with field errors to keep the bar; throw on a transport failure. */
|
|
27
|
+
onSave: (values: T) => Promise<FieldErrors | void> | FieldErrors | void
|
|
28
|
+
/** Called after Discard has put the snapshot back. */
|
|
29
|
+
onDiscard?: () => void
|
|
30
|
+
/** Where a confirmed leave goes. Default: the browser navigates. */
|
|
31
|
+
onLeave?: (href: string) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The save bar (09 §4.1): a dock that rises when the values differ from their snapshot. Save keeps it up with a
|
|
36
|
+
* pending button, then says Saved for 1.5 s; field errors keep it and focus the first invalid field. Leaving while
|
|
37
|
+
* dirty asks. Enter in the enclosing form saves.
|
|
38
|
+
*/
|
|
39
|
+
export function SaveBar<T extends Record<string, unknown>>({
|
|
40
|
+
values,
|
|
41
|
+
errors,
|
|
42
|
+
validate,
|
|
43
|
+
onSave,
|
|
44
|
+
onDiscard,
|
|
45
|
+
onLeave,
|
|
46
|
+
}: SaveBarProps<T>) {
|
|
47
|
+
const box = untrack(() => values)
|
|
48
|
+
const base = state<T>(untrack(() => box.value))
|
|
49
|
+
const phase = state<'idle' | 'pending' | 'saved'>('idle')
|
|
50
|
+
const fixes = state(0)
|
|
51
|
+
const leaving = state(false)
|
|
52
|
+
const refs: {
|
|
53
|
+
target: string
|
|
54
|
+
el?: HTMLDivElement | undefined
|
|
55
|
+
timer?: ReturnType<typeof setTimeout> | undefined
|
|
56
|
+
} = { target: '' }
|
|
57
|
+
onCleanup(() => clearTimeout(refs.timer))
|
|
58
|
+
|
|
59
|
+
const changed = derived(() => dirtyKeys(base.value, box.value))
|
|
60
|
+
const dirty = derived(() => changed.value.length > 0)
|
|
61
|
+
const message = derived(() =>
|
|
62
|
+
phase.value === 'saved'
|
|
63
|
+
? 'Saved'
|
|
64
|
+
: fixes.value
|
|
65
|
+
? `Fix ${plural(fixes.value, 'field')} to save`
|
|
66
|
+
: 'You have unsaved changes',
|
|
67
|
+
)
|
|
68
|
+
const { save, discard, leave } = saveActions({
|
|
69
|
+
d: { box, base, phase, fixes, leaving, dirty, refs },
|
|
70
|
+
errors: () => errors,
|
|
71
|
+
validate: (now) => validate?.(now),
|
|
72
|
+
onSave: (now) => onSave(now),
|
|
73
|
+
onDiscard: () => onDiscard?.(),
|
|
74
|
+
hasLeave: () => onLeave,
|
|
75
|
+
onLeave: () => onLeave!(refs.target),
|
|
76
|
+
})
|
|
77
|
+
bindSaveBar({ refs, dirty, leaving, save })
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<div
|
|
81
|
+
ref={(n) => (refs.el = n)}
|
|
82
|
+
data-scope="save-bar"
|
|
83
|
+
data-open={dirty.value || phase.value !== 'idle' ? '' : undefined}
|
|
84
|
+
role="region"
|
|
85
|
+
aria-label="Unsaved changes"
|
|
86
|
+
>
|
|
87
|
+
<p data-part="msg" role="status">
|
|
88
|
+
{message.value}
|
|
89
|
+
</p>
|
|
90
|
+
<div data-part="actions">
|
|
91
|
+
<Button
|
|
92
|
+
emphasis="ghost"
|
|
93
|
+
tone="neutral"
|
|
94
|
+
size="sm"
|
|
95
|
+
style="--_ink:var(--veneer-color-on-inverse)"
|
|
96
|
+
disabled={phase.value === 'pending'}
|
|
97
|
+
onClick={discard}
|
|
98
|
+
>
|
|
99
|
+
Discard
|
|
100
|
+
</Button>
|
|
101
|
+
<Button size="sm" loading={phase.value === 'pending'} onClick={save}>
|
|
102
|
+
Save changes
|
|
103
|
+
</Button>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
<ConfirmDialog
|
|
107
|
+
open={leaving}
|
|
108
|
+
title="Leave without saving?"
|
|
109
|
+
description="Your changes on this page will be lost."
|
|
110
|
+
action="Discard and leave"
|
|
111
|
+
cancel="Stay"
|
|
112
|
+
tone="critical"
|
|
113
|
+
onConfirm={leave}
|
|
114
|
+
/>
|
|
115
|
+
</>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function bindSaveBar({
|
|
120
|
+
refs,
|
|
121
|
+
dirty,
|
|
122
|
+
leaving,
|
|
123
|
+
save,
|
|
124
|
+
}: {
|
|
125
|
+
refs: { target: string; el?: HTMLDivElement | undefined }
|
|
126
|
+
dirty: { readonly value: boolean }
|
|
127
|
+
leaving: State<boolean>
|
|
128
|
+
save: () => Promise<void>
|
|
129
|
+
}) {
|
|
130
|
+
use(
|
|
131
|
+
leaveGuard,
|
|
132
|
+
() => refs.el,
|
|
133
|
+
() => ({
|
|
134
|
+
dirty: dirty.value,
|
|
135
|
+
onAttempt: (href: string) => {
|
|
136
|
+
refs.target = href
|
|
137
|
+
leaving.value = true
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
)
|
|
141
|
+
use(
|
|
142
|
+
(node: HTMLDivElement) => {
|
|
143
|
+
const form = node.closest('form')
|
|
144
|
+
const submit = (e: Event) => {
|
|
145
|
+
e.preventDefault()
|
|
146
|
+
void save()
|
|
147
|
+
}
|
|
148
|
+
form?.addEventListener('submit', submit)
|
|
149
|
+
return { update() {}, destroy: () => form?.removeEventListener('submit', submit) }
|
|
150
|
+
},
|
|
151
|
+
() => refs.el,
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { state, type State, watch } from '@kerf-js/core'
|
|
2
|
+
import { Button } from '../Button'
|
|
3
|
+
import { Checkbox } from '../Choice'
|
|
4
|
+
import { Input } from '../Field'
|
|
5
|
+
import { toast } from '../Toast'
|
|
6
|
+
import '../styles'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A secret shown once (09 §4.2, §4.6): a read-only field with Copy, and a checkbox the Done button waits on. Shared by
|
|
16
|
+
* API keys and webhook signing secrets. `done` goes true when it's been acknowledged.
|
|
17
|
+
*/
|
|
18
|
+
export function SecretReveal({
|
|
19
|
+
label,
|
|
20
|
+
secret,
|
|
21
|
+
done,
|
|
22
|
+
ack,
|
|
23
|
+
}: {
|
|
24
|
+
label: string
|
|
25
|
+
secret: string
|
|
26
|
+
done: State<boolean>
|
|
27
|
+
ack: string
|
|
28
|
+
}) {
|
|
29
|
+
const copy = () => {
|
|
30
|
+
navigator.clipboard?.writeText(secret).catch(() => {})
|
|
31
|
+
toast.show({
|
|
32
|
+
title: 'Copied',
|
|
33
|
+
description: 'It’s on your clipboard. Paste it once, then clear it.',
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
return (
|
|
37
|
+
<div data-scope="stack" style="padding-block-start:var(--veneer-space-related)">
|
|
38
|
+
<Input
|
|
39
|
+
label={label}
|
|
40
|
+
readonly
|
|
41
|
+
value={secret}
|
|
42
|
+
autofocus
|
|
43
|
+
spellcheck="false"
|
|
44
|
+
onFocus={(e: Event) => (e.currentTarget as HTMLInputElement).select()}
|
|
45
|
+
/>
|
|
46
|
+
<div>
|
|
47
|
+
<Button emphasis="frame" onClick={copy}>
|
|
48
|
+
Copy
|
|
49
|
+
</Button>
|
|
50
|
+
</div>
|
|
51
|
+
<Checkbox
|
|
52
|
+
checked={done.value}
|
|
53
|
+
onChange={(e: Event) => (done.value = (e.currentTarget as HTMLInputElement).checked)}
|
|
54
|
+
>
|
|
55
|
+
{ack}
|
|
56
|
+
</Checkbox>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const useReveal = (open: State<boolean>) => {
|
|
62
|
+
const secret = state('')
|
|
63
|
+
const seen = state(false)
|
|
64
|
+
watch(
|
|
65
|
+
() => open.value,
|
|
66
|
+
(on) => {
|
|
67
|
+
if (!on) {
|
|
68
|
+
secret.value = ''
|
|
69
|
+
seen.value = false
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
return { secret, seen }
|
|
74
|
+
}
|