@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,34 @@
|
|
|
1
|
+
// Applying and undoing checkout coupons.
|
|
2
|
+
import { toast } from '../Toast'
|
|
3
|
+
import type { CheckoutInput, checkoutState } from './Checkout-state'
|
|
4
|
+
|
|
5
|
+
/** Create coupon callbacks for one checkout. */
|
|
6
|
+
export function checkoutCoupon(input: CheckoutInput, s: ReturnType<typeof checkoutState>) {
|
|
7
|
+
const { code, codeError, checking, applied } = s
|
|
8
|
+
const apply = async (e: Event) => {
|
|
9
|
+
e.preventDefault()
|
|
10
|
+
const v = code.value.trim().toUpperCase()
|
|
11
|
+
if (!v) return void (codeError.value = 'Enter a code first.')
|
|
12
|
+
checking.value = true
|
|
13
|
+
const c = await input.applyCoupon(v)
|
|
14
|
+
checking.value = false
|
|
15
|
+
if (!c) return void (codeError.value = 'That code isn’t valid or has expired.')
|
|
16
|
+
applied.value = c
|
|
17
|
+
code.value = ''
|
|
18
|
+
codeError.value = ''
|
|
19
|
+
toast.show({
|
|
20
|
+
title: `${c.code} applied`,
|
|
21
|
+
description: `${c.percentOff}% off your items.`,
|
|
22
|
+
tone: 'positive',
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
const unapply = () => {
|
|
26
|
+
const c = applied.value!
|
|
27
|
+
applied.value = undefined
|
|
28
|
+
toast.show({
|
|
29
|
+
title: `${c.code} removed`,
|
|
30
|
+
action: { label: 'Undo', onClick: () => (applied.value = c) },
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
return { apply, unapply }
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OrderConfirmation } from './Order'
|
|
2
|
+
import type { CheckoutModel } from './Checkout-view'
|
|
3
|
+
|
|
4
|
+
export function checkoutDone(model: CheckoutModel) {
|
|
5
|
+
const { id, step, email, placed, option } = model.s
|
|
6
|
+
const { input } = model
|
|
7
|
+
const live = {
|
|
8
|
+
get onContinueShopping() {
|
|
9
|
+
return input.onContinueShopping()
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
return (
|
|
13
|
+
<section
|
|
14
|
+
data-part="step"
|
|
15
|
+
data-step="done"
|
|
16
|
+
data-state={step.value === 'done' ? 'active' : undefined}
|
|
17
|
+
aria-labelledby={`${id}-done`}
|
|
18
|
+
>
|
|
19
|
+
{placed.value && (
|
|
20
|
+
<OrderConfirmation
|
|
21
|
+
titleId={`${id}-done`}
|
|
22
|
+
orderId={placed.value.id}
|
|
23
|
+
email={email.value}
|
|
24
|
+
stage={placed.value.stage}
|
|
25
|
+
note={`${option.value?.name ?? ''} delivery. ${option.value?.eta ?? ''}.`}
|
|
26
|
+
onContinue={live.onContinueShopping}
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
</section>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Compose the state and callbacks for one checkout.
|
|
2
|
+
import { derived } from '@kerf-js/core'
|
|
3
|
+
import { cartCount } from '@kerf-js/veneer-core'
|
|
4
|
+
import { checkoutState, type CheckoutInput } from './Checkout-state'
|
|
5
|
+
import { checkoutNavigation } from './Checkout-navigation'
|
|
6
|
+
import { checkoutCoupon } from './Checkout-coupon'
|
|
7
|
+
import { checkoutPayment } from './Checkout-payment'
|
|
8
|
+
import { STEPS } from './Checkout-steps'
|
|
9
|
+
|
|
10
|
+
/** Create the checkout model under the caller's owner. */
|
|
11
|
+
export function checkoutModel(input: CheckoutInput) {
|
|
12
|
+
const s = checkoutState(input)
|
|
13
|
+
const { step, name, address, option, lines } = s
|
|
14
|
+
const at = derived(() => STEPS.findIndex((item) => item.id === step.value))
|
|
15
|
+
const nav = checkoutNavigation(input, s)
|
|
16
|
+
const coupon = checkoutCoupon(input, s)
|
|
17
|
+
const pay = checkoutPayment(input, s, nav)
|
|
18
|
+
const edits = derived(() => [
|
|
19
|
+
{
|
|
20
|
+
step: 'address',
|
|
21
|
+
label: 'Ship to',
|
|
22
|
+
text: `${name.value}, ${[address.value?.lines[0], address.value?.locality, address.value?.postalCode].filter(Boolean).join(', ')}`,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
step: 'shipping',
|
|
26
|
+
label: 'Delivery',
|
|
27
|
+
text: `${option.value?.name ?? ''} · ${option.value?.eta ?? ''}`,
|
|
28
|
+
},
|
|
29
|
+
{ step: 'payment', label: 'Payment', text: 'Card from your provider' },
|
|
30
|
+
])
|
|
31
|
+
const count = derived(() => cartCount(lines.value))
|
|
32
|
+
return { input, s, at, nav, coupon, pay, edits, count }
|
|
33
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Checkout step changes and address validation.
|
|
2
|
+
import { announce, addressProblems } from '@kerf-js/veneer-core'
|
|
3
|
+
import { afterFlush } from './atoms'
|
|
4
|
+
import { STEPS } from './Checkout-steps'
|
|
5
|
+
import type { CheckoutStep } from './Checkout-types'
|
|
6
|
+
import type { CheckoutInput, checkoutState } from './Checkout-state'
|
|
7
|
+
|
|
8
|
+
type State = ReturnType<typeof checkoutState>
|
|
9
|
+
|
|
10
|
+
/** Create the step navigation callbacks for one checkout. */
|
|
11
|
+
export function checkoutNavigation(input: CheckoutInput, s: State) {
|
|
12
|
+
const {
|
|
13
|
+
step,
|
|
14
|
+
dir,
|
|
15
|
+
refs,
|
|
16
|
+
name,
|
|
17
|
+
email,
|
|
18
|
+
address,
|
|
19
|
+
billing,
|
|
20
|
+
sameBilling,
|
|
21
|
+
nameError,
|
|
22
|
+
emailError,
|
|
23
|
+
addressErrors,
|
|
24
|
+
billingErrors,
|
|
25
|
+
addressAlert,
|
|
26
|
+
} = s
|
|
27
|
+
const stepTitle = (to: CheckoutStep) =>
|
|
28
|
+
to === 'done' ? 'Order confirmed' : STEPS.find((x) => x.id === to)!.title
|
|
29
|
+
const section = (to: CheckoutStep) => refs.root?.querySelector<HTMLElement>(`[data-step="${to}"]`)
|
|
30
|
+
const go = (to: CheckoutStep, focus?: 'field', back?: boolean) => {
|
|
31
|
+
dir.value = back ? 'back' : undefined
|
|
32
|
+
step.value = to
|
|
33
|
+
input.onStepChange(to)
|
|
34
|
+
if (refs.root)
|
|
35
|
+
announce(
|
|
36
|
+
refs.root.ownerDocument,
|
|
37
|
+
to === 'done'
|
|
38
|
+
? stepTitle(to)
|
|
39
|
+
: `Step ${STEPS.findIndex((x) => x.id === to) + 1} of ${STEPS.length}, ${stepTitle(to)}`,
|
|
40
|
+
)
|
|
41
|
+
afterFlush(() => {
|
|
42
|
+
const node = section(to)
|
|
43
|
+
const field =
|
|
44
|
+
focus &&
|
|
45
|
+
node?.querySelector<HTMLElement>(
|
|
46
|
+
'input:not([type="hidden"]):checked, input:not([type="hidden"]), button[data-part="trigger"]',
|
|
47
|
+
)
|
|
48
|
+
;(field || node?.querySelector<HTMLElement>('[data-part="step-title"]'))?.focus()
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
const prev = (to: CheckoutStep) => go(to, undefined, true)
|
|
52
|
+
const submitAddress = (e: Event) => {
|
|
53
|
+
e.preventDefault()
|
|
54
|
+
nameError.value = name.value.trim() ? '' : 'Enter the name for delivery.'
|
|
55
|
+
emailError.value = !email.value
|
|
56
|
+
? 'We send the receipt here.'
|
|
57
|
+
: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value)
|
|
58
|
+
? ''
|
|
59
|
+
: 'That doesn’t look like an email.'
|
|
60
|
+
addressErrors.value = addressProblems(address.value, input.defaultCountry()!)
|
|
61
|
+
billingErrors.value = sameBilling.value
|
|
62
|
+
? {}
|
|
63
|
+
: addressProblems(billing.value, input.defaultCountry()!)
|
|
64
|
+
const n =
|
|
65
|
+
[nameError.value, emailError.value].filter(Boolean).length +
|
|
66
|
+
Object.keys(addressErrors.value).length +
|
|
67
|
+
Object.keys(billingErrors.value).length
|
|
68
|
+
addressAlert.value = n ? `${n === 1 ? '1 field needs' : `${n} fields need`} attention` : ''
|
|
69
|
+
if (!n) return go('shipping')
|
|
70
|
+
if (refs.root) announce(refs.root.ownerDocument, addressAlert.value)
|
|
71
|
+
afterFlush(() =>
|
|
72
|
+
section('address')?.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus(),
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
return { go, prev, submitAddress }
|
|
76
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Alert } from '../Alert'
|
|
2
|
+
import { Button } from '../Button'
|
|
3
|
+
import type { CheckoutModel, CheckoutNav } from './Checkout-view'
|
|
4
|
+
|
|
5
|
+
export function checkoutPayment(model: CheckoutModel, Nav: CheckoutNav) {
|
|
6
|
+
const { id, step, declined, paySlot } = model.s
|
|
7
|
+
const { input } = model
|
|
8
|
+
const { go } = model.nav
|
|
9
|
+
return (
|
|
10
|
+
<section
|
|
11
|
+
data-part="step"
|
|
12
|
+
data-step="payment"
|
|
13
|
+
data-state={step.value === 'payment' ? 'active' : undefined}
|
|
14
|
+
aria-labelledby={`${id}-payment`}
|
|
15
|
+
>
|
|
16
|
+
<div data-part="step-body">
|
|
17
|
+
<h2 data-part="step-title" id={`${id}-payment`} tabindex="-1">
|
|
18
|
+
Payment
|
|
19
|
+
</h2>
|
|
20
|
+
{declined.value && (
|
|
21
|
+
<Alert tone="critical" live title="Your card was declined">
|
|
22
|
+
{declined.value} Try another card.
|
|
23
|
+
</Alert>
|
|
24
|
+
)}
|
|
25
|
+
{input.wallet() && (
|
|
26
|
+
<Button emphasis="frame" full onClick={input.wallet()!.onClick}>
|
|
27
|
+
{input.wallet()!.label}
|
|
28
|
+
</Button>
|
|
29
|
+
)}
|
|
30
|
+
{input.wallet() && (
|
|
31
|
+
<div data-scope="auth" data-embedded="">
|
|
32
|
+
<div data-part="divider">or with a card</div>
|
|
33
|
+
</div>
|
|
34
|
+
)}
|
|
35
|
+
{paySlot.value}
|
|
36
|
+
<Nav back="shipping">
|
|
37
|
+
<Button
|
|
38
|
+
onClick={() => {
|
|
39
|
+
declined.value = ''
|
|
40
|
+
go('review')
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
Review order
|
|
44
|
+
</Button>
|
|
45
|
+
</Nav>
|
|
46
|
+
</div>
|
|
47
|
+
</section>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Submit an order with a per-checkout idempotency key.
|
|
2
|
+
import { announce, errorStep, newOrderKey } from '@kerf-js/veneer-core'
|
|
3
|
+
import { toast } from '../Toast'
|
|
4
|
+
import type { CheckoutInput, checkoutState } from './Checkout-state'
|
|
5
|
+
import type { checkoutNavigation } from './Checkout-navigation'
|
|
6
|
+
|
|
7
|
+
/** Create the payment callback for one checkout. */
|
|
8
|
+
export function checkoutPayment(
|
|
9
|
+
input: CheckoutInput,
|
|
10
|
+
s: ReturnType<typeof checkoutState>,
|
|
11
|
+
nav: ReturnType<typeof checkoutNavigation>,
|
|
12
|
+
) {
|
|
13
|
+
const {
|
|
14
|
+
placing,
|
|
15
|
+
address,
|
|
16
|
+
lines,
|
|
17
|
+
name,
|
|
18
|
+
email,
|
|
19
|
+
phone,
|
|
20
|
+
sameBilling,
|
|
21
|
+
billing,
|
|
22
|
+
ship,
|
|
23
|
+
applied,
|
|
24
|
+
total,
|
|
25
|
+
placed,
|
|
26
|
+
declined,
|
|
27
|
+
outOfStock,
|
|
28
|
+
newTotal,
|
|
29
|
+
cost,
|
|
30
|
+
refs,
|
|
31
|
+
} = s
|
|
32
|
+
const { go } = nav
|
|
33
|
+
let key: string | undefined
|
|
34
|
+
const pay = async () => {
|
|
35
|
+
if (placing.value) return // a double tap: the first press owns the key
|
|
36
|
+
placing.value = true
|
|
37
|
+
const useKey = input.idempotencyKey() ?? (key ??= newOrderKey())
|
|
38
|
+
const a = address.value!
|
|
39
|
+
try {
|
|
40
|
+
const r = await input.onPlaceOrder(() => ({
|
|
41
|
+
lines: lines.value,
|
|
42
|
+
name: name.value,
|
|
43
|
+
email: email.value,
|
|
44
|
+
phone: phone.value,
|
|
45
|
+
address: a,
|
|
46
|
+
billing: sameBilling.value ? a : billing.value!,
|
|
47
|
+
shipping: ship.value,
|
|
48
|
+
coupon: applied.value?.code,
|
|
49
|
+
total: total.value,
|
|
50
|
+
idempotencyKey: useKey,
|
|
51
|
+
}))
|
|
52
|
+
if ('order' in r) {
|
|
53
|
+
placed.value = r.order
|
|
54
|
+
key = undefined
|
|
55
|
+
return go('done')
|
|
56
|
+
}
|
|
57
|
+
key = undefined // a definite answer: the next attempt is a new one
|
|
58
|
+
const err = r.error
|
|
59
|
+
declined.value = err.code === 'CARD_DECLINED' ? err.reason : ''
|
|
60
|
+
outOfStock.value = err.code === 'OUT_OF_STOCK' ? err.sku : ''
|
|
61
|
+
newTotal.value = err.code === 'PRICE_CHANGED' ? err.total : undefined
|
|
62
|
+
if (err.code === 'PRICE_CHANGED') {
|
|
63
|
+
if (refs.root)
|
|
64
|
+
announce(refs.root.ownerDocument, `The total changed to ${cost(err.total)}`, true)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
go(errorStep(err), undefined, true)
|
|
68
|
+
} catch {
|
|
69
|
+
toast.show({
|
|
70
|
+
title: 'We couldn’t reach the store',
|
|
71
|
+
description: 'You weren’t charged twice. Try again.',
|
|
72
|
+
tone: 'critical',
|
|
73
|
+
action: { label: 'Retry', onClick: pay },
|
|
74
|
+
})
|
|
75
|
+
} finally {
|
|
76
|
+
placing.value = false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return pay
|
|
80
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { LockIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { Alert } from '../Alert'
|
|
3
|
+
import { Button } from '../Button'
|
|
4
|
+
import type { CheckoutStep } from './Checkout-types'
|
|
5
|
+
import type { CheckoutModel, CheckoutNav } from './Checkout-view'
|
|
6
|
+
|
|
7
|
+
export function checkoutReview(model: CheckoutModel, Nav: CheckoutNav) {
|
|
8
|
+
const { id, step, placing, newTotal, total, cost } = model.s
|
|
9
|
+
const { edits } = model
|
|
10
|
+
const { pay } = model
|
|
11
|
+
const { go } = model.nav
|
|
12
|
+
return (
|
|
13
|
+
<section
|
|
14
|
+
data-part="step"
|
|
15
|
+
data-step="review"
|
|
16
|
+
data-state={step.value === 'review' ? 'active' : undefined}
|
|
17
|
+
aria-labelledby={`${id}-review`}
|
|
18
|
+
>
|
|
19
|
+
<div data-part="step-body">
|
|
20
|
+
<h2 data-part="step-title" id={`${id}-review`} tabindex="-1">
|
|
21
|
+
Review and pay
|
|
22
|
+
</h2>
|
|
23
|
+
{newTotal.value !== undefined && (
|
|
24
|
+
<Alert tone="caution" title={`The total is now ${cost(newTotal.value)}`}>
|
|
25
|
+
The price changed while you were checking out. Look it over, then pay again.
|
|
26
|
+
</Alert>
|
|
27
|
+
)}
|
|
28
|
+
<dl data-scope="lines">
|
|
29
|
+
{edits.value.map((r) => (
|
|
30
|
+
<div key={r.step}>
|
|
31
|
+
<dt>
|
|
32
|
+
{r.label}
|
|
33
|
+
<br />
|
|
34
|
+
<span>{r.text}</span>
|
|
35
|
+
</dt>
|
|
36
|
+
<dd>
|
|
37
|
+
<Button
|
|
38
|
+
emphasis="link"
|
|
39
|
+
aria-label={`Edit ${r.label.toLowerCase()}`}
|
|
40
|
+
onClick={() => go(r.step as CheckoutStep, 'field', true)}
|
|
41
|
+
>
|
|
42
|
+
Edit
|
|
43
|
+
</Button>
|
|
44
|
+
</dd>
|
|
45
|
+
</div>
|
|
46
|
+
))}
|
|
47
|
+
</dl>
|
|
48
|
+
<span class="muted">
|
|
49
|
+
By paying you agree to the terms of sale. You can cancel within 1 hour.
|
|
50
|
+
</span>
|
|
51
|
+
<Nav back="payment">
|
|
52
|
+
<Button size="lg" loading={placing.value} onClick={pay}>
|
|
53
|
+
<LockIcon />
|
|
54
|
+
{`Pay ${cost(total.value)}`}
|
|
55
|
+
</Button>
|
|
56
|
+
</Nav>
|
|
57
|
+
</div>
|
|
58
|
+
</section>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Button } from '../Button'
|
|
2
|
+
import { Sweep } from './atoms'
|
|
3
|
+
import type { CheckoutModel, CheckoutNav } from './Checkout-view'
|
|
4
|
+
|
|
5
|
+
export function checkoutShipping(model: CheckoutModel, Nav: CheckoutNav) {
|
|
6
|
+
const { id, step, ship, cost } = model.s
|
|
7
|
+
const { input } = model
|
|
8
|
+
const { go } = model.nav
|
|
9
|
+
return (
|
|
10
|
+
<section
|
|
11
|
+
data-part="step"
|
|
12
|
+
data-step="shipping"
|
|
13
|
+
data-state={step.value === 'shipping' ? 'active' : undefined}
|
|
14
|
+
aria-labelledby={`${id}-shipping`}
|
|
15
|
+
>
|
|
16
|
+
<div data-part="step-body">
|
|
17
|
+
<h2 data-part="step-title" id={`${id}-shipping`} tabindex="-1">
|
|
18
|
+
How fast?
|
|
19
|
+
</h2>
|
|
20
|
+
<fieldset data-scope="choice">
|
|
21
|
+
<legend data-part="sr-only">Shipping speed</legend>
|
|
22
|
+
{input.shipping().map((o) => (
|
|
23
|
+
<label key={o.id} data-scope="plan-card" data-sweep="">
|
|
24
|
+
<Sweep />
|
|
25
|
+
<input
|
|
26
|
+
type="radio"
|
|
27
|
+
name={`${id}-ship`}
|
|
28
|
+
value={o.id}
|
|
29
|
+
checked={o.id === ship.value}
|
|
30
|
+
onChange={() => (ship.value = o.id)}
|
|
31
|
+
/>
|
|
32
|
+
<span data-part="radio" aria-hidden="true"></span>
|
|
33
|
+
<span>
|
|
34
|
+
<b>{o.name}</b>
|
|
35
|
+
<small>{o.eta}</small>
|
|
36
|
+
</span>
|
|
37
|
+
<b>{o.price ? cost(o.price) : 'Free'}</b>
|
|
38
|
+
</label>
|
|
39
|
+
))}
|
|
40
|
+
</fieldset>
|
|
41
|
+
<Nav back="address">
|
|
42
|
+
<Button onClick={() => go('payment')}>Continue to payment</Button>
|
|
43
|
+
</Nav>
|
|
44
|
+
</div>
|
|
45
|
+
</section>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Per-instance checkout state and derived pricing.
|
|
2
|
+
import { derived, state, untrack } from '@kerf-js/core'
|
|
3
|
+
import {
|
|
4
|
+
cartTotals,
|
|
5
|
+
money,
|
|
6
|
+
openWhenWide,
|
|
7
|
+
uid,
|
|
8
|
+
type Address,
|
|
9
|
+
type AddressPart,
|
|
10
|
+
} from '@kerf-js/veneer-core'
|
|
11
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
12
|
+
import type { OrderStage } from './Order'
|
|
13
|
+
import type { CheckoutProps, CheckoutStep, Coupon } from './Checkout-types'
|
|
14
|
+
import { WIDE } from './Checkout-steps'
|
|
15
|
+
|
|
16
|
+
/** Live access to checkout props. */
|
|
17
|
+
export type CheckoutInput = {
|
|
18
|
+
[K in Exclude<keyof CheckoutProps, 'onStepChange' | 'onPlaceOrder'>]-?: () => CheckoutProps[K]
|
|
19
|
+
} & {
|
|
20
|
+
applyCoupon: (code: string) => ReturnType<NonNullable<CheckoutProps['coupon']>> | undefined
|
|
21
|
+
onStepChange: (step: CheckoutStep) => void
|
|
22
|
+
onPlaceOrder: (
|
|
23
|
+
order: () => Parameters<CheckoutProps['onPlaceOrder']>[0],
|
|
24
|
+
) => ReturnType<CheckoutProps['onPlaceOrder']>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Create checkout state under the caller's owner. */
|
|
28
|
+
export function checkoutState(input: CheckoutInput) {
|
|
29
|
+
const id = uid('co')
|
|
30
|
+
const step = state<CheckoutStep>('cart')
|
|
31
|
+
const dir = state<'back' | undefined>(undefined)
|
|
32
|
+
const ship = state(untrack(() => input.shipping()[0]?.id ?? ''))
|
|
33
|
+
const code = state('')
|
|
34
|
+
const codeError = state('')
|
|
35
|
+
const applied = state<Coupon | undefined>(undefined)
|
|
36
|
+
const checking = state(false)
|
|
37
|
+
const placing = state(false)
|
|
38
|
+
const declined = state('')
|
|
39
|
+
const outOfStock = state('')
|
|
40
|
+
const newTotal = state<number | undefined>(undefined)
|
|
41
|
+
const placed = state<{ id: string; stage?: OrderStage | undefined } | undefined>(undefined)
|
|
42
|
+
const paySlot = derived(input.payment)
|
|
43
|
+
const refs: { root: HTMLElement | undefined; summary: HTMLDetailsElement | undefined } = {
|
|
44
|
+
root: undefined,
|
|
45
|
+
summary: undefined,
|
|
46
|
+
}
|
|
47
|
+
use(
|
|
48
|
+
openWhenWide,
|
|
49
|
+
() => refs.summary,
|
|
50
|
+
() => WIDE,
|
|
51
|
+
)
|
|
52
|
+
const pricing = checkoutPricing(input, { ship, applied, newTotal })
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
step,
|
|
56
|
+
dir,
|
|
57
|
+
ship,
|
|
58
|
+
code,
|
|
59
|
+
codeError,
|
|
60
|
+
applied,
|
|
61
|
+
checking,
|
|
62
|
+
placing,
|
|
63
|
+
declined,
|
|
64
|
+
outOfStock,
|
|
65
|
+
newTotal,
|
|
66
|
+
placed,
|
|
67
|
+
paySlot,
|
|
68
|
+
refs,
|
|
69
|
+
...contactState(),
|
|
70
|
+
...pricing,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function contactState() {
|
|
75
|
+
const name = state('')
|
|
76
|
+
const email = state('')
|
|
77
|
+
const phone = state('')
|
|
78
|
+
const address = state<Address | null>(null)
|
|
79
|
+
const billing = state<Address | null>(null)
|
|
80
|
+
const sameBilling = state(true)
|
|
81
|
+
const nameError = state('')
|
|
82
|
+
const emailError = state('')
|
|
83
|
+
const addressErrors = state<Partial<Record<AddressPart, string>>>({})
|
|
84
|
+
const billingErrors = state<Partial<Record<AddressPart, string>>>({})
|
|
85
|
+
const addressAlert = state('')
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
email,
|
|
89
|
+
phone,
|
|
90
|
+
address,
|
|
91
|
+
billing,
|
|
92
|
+
sameBilling,
|
|
93
|
+
nameError,
|
|
94
|
+
emailError,
|
|
95
|
+
addressErrors,
|
|
96
|
+
billingErrors,
|
|
97
|
+
addressAlert,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function checkoutPricing(
|
|
102
|
+
input: CheckoutInput,
|
|
103
|
+
fields: {
|
|
104
|
+
ship: ReturnType<typeof state<string>>
|
|
105
|
+
applied: ReturnType<typeof state<Coupon | undefined>>
|
|
106
|
+
newTotal: ReturnType<typeof state<number | undefined>>
|
|
107
|
+
},
|
|
108
|
+
) {
|
|
109
|
+
const { ship, applied, newTotal } = fields
|
|
110
|
+
const lines = derived(() => input.cart().value)
|
|
111
|
+
const option = derived(() => input.shipping().find((o) => o.id === ship.value))
|
|
112
|
+
const totals = derived(() =>
|
|
113
|
+
cartTotals(lines.value, {
|
|
114
|
+
shipping: option.value?.price ?? 0,
|
|
115
|
+
percentOff: applied.value?.percentOff,
|
|
116
|
+
taxRate: input.taxRate()!,
|
|
117
|
+
}),
|
|
118
|
+
)
|
|
119
|
+
const total = derived(() => newTotal.value ?? totals.value.total)
|
|
120
|
+
const cost = (n: number) => money(n, input.currency(), input.locale())
|
|
121
|
+
return { lines, option, totals, total, cost }
|
|
122
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CheckoutStep } from './Checkout-types'
|
|
2
|
+
|
|
3
|
+
export const STEPS: { id: CheckoutStep; title: string }[] = [
|
|
4
|
+
{ id: 'cart', title: 'Cart' },
|
|
5
|
+
{ id: 'address', title: 'Address' },
|
|
6
|
+
{ id: 'shipping', title: 'Shipping' },
|
|
7
|
+
{ id: 'payment', title: 'Payment' },
|
|
8
|
+
{ id: 'review', title: 'Review' },
|
|
9
|
+
]
|
|
10
|
+
export const WIDE = 860
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { BagIcon, DownIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { Button } from '../Button'
|
|
3
|
+
import { Input } from '../Field'
|
|
4
|
+
import { Tag } from '../Tag'
|
|
5
|
+
import type { CheckoutModel } from './Checkout-view'
|
|
6
|
+
|
|
7
|
+
export function checkoutSummary(model: CheckoutModel) {
|
|
8
|
+
const { code, codeError, applied, checking, lines, total, cost, refs } = model.s
|
|
9
|
+
const { input } = model
|
|
10
|
+
const { apply, unapply } = model.coupon
|
|
11
|
+
return (
|
|
12
|
+
<details ref={(n) => (refs.summary = n)} data-part="summary">
|
|
13
|
+
<summary>
|
|
14
|
+
<span class="row">
|
|
15
|
+
<BagIcon />
|
|
16
|
+
Order summary
|
|
17
|
+
</span>
|
|
18
|
+
<span class="row">
|
|
19
|
+
<b>{cost(total.value)}</b>
|
|
20
|
+
<DownIcon />
|
|
21
|
+
</span>
|
|
22
|
+
</summary>
|
|
23
|
+
{lines.value.map((l) => (
|
|
24
|
+
<div key={l.id} data-scope="line-item">
|
|
25
|
+
<span data-part="thumb">{l.art && <img src={l.art} alt="" />}</span>
|
|
26
|
+
<span>
|
|
27
|
+
<b>{l.name}</b>
|
|
28
|
+
<small>Qty {l.quantity}</small>
|
|
29
|
+
</span>
|
|
30
|
+
<span data-part="price">{cost(l.price * l.quantity)}</span>
|
|
31
|
+
</div>
|
|
32
|
+
))}
|
|
33
|
+
{input.coupon() && (
|
|
34
|
+
<form
|
|
35
|
+
data-scope="row"
|
|
36
|
+
data-wrap="none"
|
|
37
|
+
data-align="start"
|
|
38
|
+
novalidate
|
|
39
|
+
onSubmit={(e: Event) => void apply(e)}
|
|
40
|
+
>
|
|
41
|
+
<div data-grow="">
|
|
42
|
+
<Input
|
|
43
|
+
label="Discount code"
|
|
44
|
+
value={code.value}
|
|
45
|
+
error={codeError.value}
|
|
46
|
+
onInput={(e) => {
|
|
47
|
+
code.value = e.currentTarget.value
|
|
48
|
+
codeError.value = ''
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
<Button emphasis="frame" type="submit" loading={checking.value}>
|
|
53
|
+
Apply
|
|
54
|
+
</Button>
|
|
55
|
+
</form>
|
|
56
|
+
)}
|
|
57
|
+
{applied.value && (
|
|
58
|
+
<div class="chips">
|
|
59
|
+
<Tag label={applied.value.code} onRemove={unapply}>
|
|
60
|
+
{applied.value.code}
|
|
61
|
+
</Tag>
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
{checkoutTotals(model)}
|
|
65
|
+
</details>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function checkoutTotals(model: CheckoutModel) {
|
|
70
|
+
const { applied, newTotal, option, totals, total, cost } = model.s
|
|
71
|
+
return (
|
|
72
|
+
<dl data-scope="lines">
|
|
73
|
+
<div>
|
|
74
|
+
<dt>Subtotal</dt>
|
|
75
|
+
<dd>{cost(totals.value.subtotal)}</dd>
|
|
76
|
+
</div>
|
|
77
|
+
{applied.value && (
|
|
78
|
+
<div>
|
|
79
|
+
<dt>Discount · {applied.value.code}</dt>
|
|
80
|
+
<dd>−{cost(totals.value.discount)}</dd>
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
<div>
|
|
84
|
+
<dt>Shipping · {option.value?.name}</dt>
|
|
85
|
+
<dd>{totals.value.shipping ? cost(totals.value.shipping) : 'Free'}</dd>
|
|
86
|
+
</div>
|
|
87
|
+
<div>
|
|
88
|
+
<dt>Estimated tax</dt>
|
|
89
|
+
<dd>{cost(totals.value.tax)}</dd>
|
|
90
|
+
</div>
|
|
91
|
+
<div data-part="total">
|
|
92
|
+
<dt>Total</dt>
|
|
93
|
+
<dd data-changed={newTotal.value !== undefined ? '' : undefined}>{cost(total.value)}</dd>
|
|
94
|
+
</div>
|
|
95
|
+
</dl>
|
|
96
|
+
)
|
|
97
|
+
}
|