@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
package/src/Chart.tsx
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import {
|
|
3
|
+
chart,
|
|
4
|
+
SSR_RADIUS,
|
|
5
|
+
SSR_WIDTH,
|
|
6
|
+
tableHTML,
|
|
7
|
+
toHTML,
|
|
8
|
+
type Ctx,
|
|
9
|
+
type Form,
|
|
10
|
+
} from '@kerf-js/veneer-core/charts'
|
|
11
|
+
import { derived, untrack } from '@kerf-js/core'
|
|
12
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
13
|
+
import './styles'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/data/tokens.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/data/base.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/data/chart.css'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/data/legend.css'
|
|
18
|
+
import '@kerf-js/veneer-core/styles/data/tooltip.css'
|
|
19
|
+
|
|
20
|
+
/** What every chart shares around its plot: the caption, the toolbar and the loading, empty and error states. */
|
|
21
|
+
export type ChartFrame = {
|
|
22
|
+
title: string
|
|
23
|
+
/** The title's heading level: one below the heading the chart sits under. Default 3, a chart in a page section. */
|
|
24
|
+
level?: 2 | 3 | 4 | 5 | 6
|
|
25
|
+
description?: unknown
|
|
26
|
+
/** Beside the view toggle: a layout switch, a range picker. */
|
|
27
|
+
toolbar?: unknown
|
|
28
|
+
/** Replaces the plot, in the same frame (06 §12). With no data the frame shows `empty` on its own. */
|
|
29
|
+
state?: 'loading' | 'empty' | 'error' | undefined
|
|
30
|
+
loading?: string | undefined
|
|
31
|
+
/** The title and detail shown in place of the plot when there is no data. */
|
|
32
|
+
empty?: { title: string; detail?: unknown } | undefined
|
|
33
|
+
error?: { title: string; detail?: unknown } | undefined
|
|
34
|
+
/** The next step under an empty or error state: a Retry button. */
|
|
35
|
+
action?: unknown
|
|
36
|
+
}
|
|
37
|
+
type Props<C> = ChartFrame & C & { form: Form<C> }
|
|
38
|
+
|
|
39
|
+
// props that are the frame's, not a form's: a JSX prop builds its element each time it's read, so these are read once
|
|
40
|
+
const FRAME = new Set([
|
|
41
|
+
'form',
|
|
42
|
+
'level',
|
|
43
|
+
'description',
|
|
44
|
+
'toolbar',
|
|
45
|
+
'action',
|
|
46
|
+
'empty',
|
|
47
|
+
'error',
|
|
48
|
+
'loading',
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
const Drawn = ({ stroke }: { stroke: string }) => (
|
|
52
|
+
<svg width="72" height="40" viewBox="0 0 72 40" aria-hidden="true">
|
|
53
|
+
<path d="M8 0V40M22 0V40M36 0V40M50 0V40M64 0V40" stroke="var(--veneer-color-border-strong)" />
|
|
54
|
+
<path
|
|
55
|
+
d={stroke === 'var(--veneer-color-critical-solid)' ? 'M0 20H30' : 'M0 14H72M0 26H72'}
|
|
56
|
+
stroke={stroke}
|
|
57
|
+
stroke-width="2"
|
|
58
|
+
/>
|
|
59
|
+
</svg>
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
function Standby({
|
|
63
|
+
state,
|
|
64
|
+
title,
|
|
65
|
+
text,
|
|
66
|
+
action,
|
|
67
|
+
}: {
|
|
68
|
+
state: 'loading' | 'empty' | 'error'
|
|
69
|
+
title: string
|
|
70
|
+
text?: { title: string; detail?: unknown } | undefined
|
|
71
|
+
action?: unknown
|
|
72
|
+
}) {
|
|
73
|
+
if (untrack(() => state) === 'loading')
|
|
74
|
+
return (
|
|
75
|
+
<div data-part="state" role="status" aria-busy="true">
|
|
76
|
+
<div
|
|
77
|
+
aria-hidden="true"
|
|
78
|
+
style="display:flex;align-items:end;gap:10px;block-size:118px;inline-size:100%;padding-inline:6px"
|
|
79
|
+
>
|
|
80
|
+
{[40, 70, 55, 90, 64, 80, 96].map((h) => (
|
|
81
|
+
<span key={h} data-part="skeleton" style={`--h:${h}px`}></span>
|
|
82
|
+
))}
|
|
83
|
+
</div>
|
|
84
|
+
{text?.title ?? `Loading ${title}…`}
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
87
|
+
const failed = untrack(() => state) === 'error'
|
|
88
|
+
return (
|
|
89
|
+
<div data-part="state" role={failed ? 'alert' : 'status'}>
|
|
90
|
+
<Drawn
|
|
91
|
+
stroke={failed ? 'var(--veneer-color-critical-solid)' : 'var(--veneer-color-accent-solid)'}
|
|
92
|
+
/>
|
|
93
|
+
<b style="color:var(--veneer-color-text)">
|
|
94
|
+
{text?.title ?? (failed ? `Couldn’t load ${title}` : `No ${title}`)}
|
|
95
|
+
</b>
|
|
96
|
+
{text?.detail}
|
|
97
|
+
{action}
|
|
98
|
+
</div>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function Ready<C>(p: {
|
|
103
|
+
form: Form<C>
|
|
104
|
+
cfg: () => C
|
|
105
|
+
id: string
|
|
106
|
+
root: () => HTMLElement | undefined
|
|
107
|
+
}) {
|
|
108
|
+
const id = () => p.id
|
|
109
|
+
// the first layout, once: from here on `chart` owns these nodes, so nothing below re-renders them
|
|
110
|
+
const first = derived(() =>
|
|
111
|
+
untrack(() =>
|
|
112
|
+
p.form.plot(p.cfg(), SSR_WIDTH, { id: p.id, hidden: new Set(), r: SSR_RADIUS } satisfies Ctx),
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
const legend = derived(() => p.form.legend?.(p.cfg()) ?? [])
|
|
116
|
+
const table = derived(() => tableHTML(p.form.table(p.cfg())))
|
|
117
|
+
const summary = derived(() => {
|
|
118
|
+
const c = p.cfg() as C & { summary?: string | ((c: C) => string) | undefined }
|
|
119
|
+
return typeof c.summary === 'function' ? c.summary(c) : (c.summary ?? p.form.summary(c))
|
|
120
|
+
})
|
|
121
|
+
use(
|
|
122
|
+
chart<C>,
|
|
123
|
+
() => p.root(),
|
|
124
|
+
() => ({ form: p.form, cfg: p.cfg(), id: p.id }),
|
|
125
|
+
)
|
|
126
|
+
return (
|
|
127
|
+
<>
|
|
128
|
+
{chartLegend(() => p.form, legend)}
|
|
129
|
+
<div data-part="plot">
|
|
130
|
+
<div data-scope="tooltip" data-part="chart-tip" aria-hidden="true"></div>
|
|
131
|
+
<svg
|
|
132
|
+
data-part="svg"
|
|
133
|
+
viewBox={`0 0 ${first.value.w ?? SSR_WIDTH} ${first.value.h}`}
|
|
134
|
+
width={first.value.w ?? SSR_WIDTH}
|
|
135
|
+
height={first.value.h}
|
|
136
|
+
style={first.value.style}
|
|
137
|
+
role="group"
|
|
138
|
+
aria-roledescription={p.form.kind}
|
|
139
|
+
aria-labelledby={`${id()}-t`}
|
|
140
|
+
aria-describedby={`${id()}-s`}
|
|
141
|
+
// oxlint-disable-next-line kerf/no-html-sink -- toHTML escapes every text and attribute of the scene
|
|
142
|
+
innerHTML={toHTML(first.value.body)}
|
|
143
|
+
></svg>
|
|
144
|
+
</div>
|
|
145
|
+
<div
|
|
146
|
+
data-part="table"
|
|
147
|
+
tabindex="0"
|
|
148
|
+
role="region"
|
|
149
|
+
aria-labelledby={`${id()}-t`}
|
|
150
|
+
// oxlint-disable-next-line kerf/no-html-sink -- tableHTML escapes every cell
|
|
151
|
+
innerHTML={table.value}
|
|
152
|
+
></div>
|
|
153
|
+
<p data-part="summary" id={`${id()}-s`}>
|
|
154
|
+
{summary.value}
|
|
155
|
+
</p>
|
|
156
|
+
</>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function chartLegend<C>(
|
|
161
|
+
form: () => Form<C>,
|
|
162
|
+
legend: { value: NonNullable<ReturnType<NonNullable<Form<C>['legend']>>> },
|
|
163
|
+
) {
|
|
164
|
+
return (
|
|
165
|
+
<>
|
|
166
|
+
{form().ramp !== undefined ? (
|
|
167
|
+
<ul data-scope="legend" aria-label="Scale">
|
|
168
|
+
<li style="display:flex;align-items:center;gap:6px;font-size:var(--veneer-text-caption-size);color:var(--veneer-color-text-subtle);padding-inline:6px">
|
|
169
|
+
Fewer{' '}
|
|
170
|
+
{[0, 1, 2, 3, 4, 5].slice(form().ramp).map((b) => (
|
|
171
|
+
<i
|
|
172
|
+
key={b}
|
|
173
|
+
style={`display:inline-block;inline-size:11px;block-size:11px;border-radius:2px;background:var(--veneer-color-data-seq-${b})`}
|
|
174
|
+
></i>
|
|
175
|
+
))}{' '}
|
|
176
|
+
More
|
|
177
|
+
</li>
|
|
178
|
+
</ul>
|
|
179
|
+
) : (
|
|
180
|
+
legend.value.length > 0 && (
|
|
181
|
+
<ul data-scope="legend" aria-label="Series">
|
|
182
|
+
{legend.value.map((s, i) => (
|
|
183
|
+
<li key={s.name}>
|
|
184
|
+
<button type="button" aria-pressed="true" data-si={i} style={`--_dc:${s.color}`}>
|
|
185
|
+
<i data-shape={form().swatch ?? 'box'}></i>
|
|
186
|
+
{s.name}
|
|
187
|
+
{s.value !== undefined && (
|
|
188
|
+
<>
|
|
189
|
+
{' '}
|
|
190
|
+
<b>{s.value}</b>
|
|
191
|
+
</>
|
|
192
|
+
)}
|
|
193
|
+
</button>
|
|
194
|
+
</li>
|
|
195
|
+
))}
|
|
196
|
+
</ul>
|
|
197
|
+
)
|
|
198
|
+
)}
|
|
199
|
+
</>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The frame every chart shares (06 §12): figure > head · legend · plot (svg, tooltip) · table · summary. The plot is
|
|
205
|
+
* laid out once here, so the server sends a whole chart, and from then on veneer-core's `chart` owns it: width and data
|
|
206
|
+
* changes rewrite attributes on the same nodes, and the legend and the view toggle are delegated from the figure.
|
|
207
|
+
*/
|
|
208
|
+
export function Chart<C extends { data: unknown; title: string }>(props: Props<C>) {
|
|
209
|
+
const id = uid('chart')
|
|
210
|
+
let figure: HTMLElement | undefined
|
|
211
|
+
const cfg = () => {
|
|
212
|
+
const c: Record<string, unknown> = {}
|
|
213
|
+
for (const k of Object.keys(props))
|
|
214
|
+
if (!FRAME.has(k)) c[k] = (props as Record<string, unknown>)[k]
|
|
215
|
+
return c as C
|
|
216
|
+
}
|
|
217
|
+
const hasData = () => {
|
|
218
|
+
const d = props.data
|
|
219
|
+
return d !== undefined && d !== null && (!Array.isArray(d) || d.length > 0)
|
|
220
|
+
}
|
|
221
|
+
const status = () => props.state ?? (hasData() ? undefined : 'empty')
|
|
222
|
+
return (
|
|
223
|
+
<figure ref={(n) => (figure = n)} data-scope="chart" data-view="chart" data-enter="wait">
|
|
224
|
+
<div data-part="head">
|
|
225
|
+
<div>
|
|
226
|
+
<h3
|
|
227
|
+
id={`${id}-t`}
|
|
228
|
+
aria-level={props.level === 3 ? undefined : props.level}
|
|
229
|
+
style="margin:0;font-family:var(--veneer-text-heading-font);font-size:calc(var(--veneer-text-heading-size) - 3px);font-weight:var(--veneer-text-heading-weight);letter-spacing:var(--veneer-text-heading-tracking)"
|
|
230
|
+
>
|
|
231
|
+
{props.title}
|
|
232
|
+
</h3>
|
|
233
|
+
{props.description !== undefined && (
|
|
234
|
+
<p style="margin:2px 0 0;font-size:var(--veneer-text-caption-size);color:var(--veneer-color-text-subtle)">
|
|
235
|
+
{props.description}
|
|
236
|
+
</p>
|
|
237
|
+
)}
|
|
238
|
+
</div>
|
|
239
|
+
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:8px">
|
|
240
|
+
{props.toolbar}
|
|
241
|
+
{status() === undefined && (
|
|
242
|
+
<div data-part="view-toggle" role="group" aria-label="View">
|
|
243
|
+
<button type="button" aria-pressed="true" data-view="chart" aria-label="Chart view">
|
|
244
|
+
<svg aria-hidden="true" focusable="false" viewBox="0 0 16 16">
|
|
245
|
+
<path d="M2 13.5h12M3.5 10.5l3-3.5 2.5 2 3.5-4.5" />
|
|
246
|
+
</svg>
|
|
247
|
+
</button>
|
|
248
|
+
<button type="button" aria-pressed="false" data-view="table" aria-label="Table view">
|
|
249
|
+
<svg aria-hidden="true" focusable="false" viewBox="0 0 16 16">
|
|
250
|
+
<rect x="2" y="2.5" width="12" height="11" rx="1.5" />
|
|
251
|
+
<path d="M2 6.5h12M2 10h12M6.5 6.5v7" />
|
|
252
|
+
</svg>
|
|
253
|
+
</button>
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
{status() === undefined ? (
|
|
259
|
+
<Ready form={props.form} cfg={cfg} id={id} root={() => figure} />
|
|
260
|
+
) : (
|
|
261
|
+
<Standby
|
|
262
|
+
state={status()!}
|
|
263
|
+
title={props.title}
|
|
264
|
+
text={
|
|
265
|
+
status() === 'loading'
|
|
266
|
+
? props.loading === undefined
|
|
267
|
+
? undefined
|
|
268
|
+
: { title: props.loading }
|
|
269
|
+
: status() === 'error'
|
|
270
|
+
? props.error
|
|
271
|
+
: props.empty
|
|
272
|
+
}
|
|
273
|
+
action={props.action}
|
|
274
|
+
/>
|
|
275
|
+
)}
|
|
276
|
+
</figure>
|
|
277
|
+
)
|
|
278
|
+
}
|
package/src/Charts.tsx
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// The chart forms (06 §12), one line each: a form is a pure layout in veneer-core, and `Chart` is the frame around it.
|
|
2
|
+
// Nothing here runs at import, so an app pays only for the forms it renders.
|
|
3
|
+
import {
|
|
4
|
+
spark as sparkAction,
|
|
5
|
+
sparkScene,
|
|
6
|
+
SSR_WIDTH,
|
|
7
|
+
toHTML,
|
|
8
|
+
bar,
|
|
9
|
+
box,
|
|
10
|
+
brush,
|
|
11
|
+
bubble,
|
|
12
|
+
candlestick,
|
|
13
|
+
combo,
|
|
14
|
+
donut,
|
|
15
|
+
funnel,
|
|
16
|
+
gauge,
|
|
17
|
+
heat,
|
|
18
|
+
histogram,
|
|
19
|
+
line,
|
|
20
|
+
radar,
|
|
21
|
+
radial,
|
|
22
|
+
sankey,
|
|
23
|
+
scatter,
|
|
24
|
+
stream,
|
|
25
|
+
sunburst,
|
|
26
|
+
tile,
|
|
27
|
+
treemap,
|
|
28
|
+
waterfall,
|
|
29
|
+
type BarConfig,
|
|
30
|
+
type BoxConfig,
|
|
31
|
+
type BrushConfig,
|
|
32
|
+
type CandleConfig,
|
|
33
|
+
type ComboConfig,
|
|
34
|
+
type DonutConfig,
|
|
35
|
+
type FunnelConfig,
|
|
36
|
+
type GaugeConfig,
|
|
37
|
+
type HeatConfig,
|
|
38
|
+
type HistConfig,
|
|
39
|
+
type LineConfig,
|
|
40
|
+
type RadarConfig,
|
|
41
|
+
type RadialConfig,
|
|
42
|
+
type SankeyConfig,
|
|
43
|
+
type ScatterConfig,
|
|
44
|
+
type StreamConfig,
|
|
45
|
+
type SunConfig,
|
|
46
|
+
type TileConfig,
|
|
47
|
+
type TreemapConfig,
|
|
48
|
+
type WaterConfig,
|
|
49
|
+
} from '@kerf-js/veneer-core/charts'
|
|
50
|
+
import { state, untrack } from '@kerf-js/core'
|
|
51
|
+
import { Button } from './Button'
|
|
52
|
+
import { Chart, type ChartFrame } from './Chart'
|
|
53
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
54
|
+
import './styles'
|
|
55
|
+
import '@kerf-js/veneer-core/styles/data/tokens.css'
|
|
56
|
+
import '@kerf-js/veneer-core/styles/data/base.css'
|
|
57
|
+
|
|
58
|
+
/** Lines over a shared x axis. */
|
|
59
|
+
export const LineChart = (p: ChartFrame & LineConfig) => <Chart form={line} {...p} />
|
|
60
|
+
/** Bars, grouped or stacked. */
|
|
61
|
+
export const BarChart = (p: ChartFrame & BarConfig) => <Chart form={bar} {...p} />
|
|
62
|
+
/** Bars and lines on one plot. */
|
|
63
|
+
export const ComboChart = (p: ChartFrame & ComboConfig) => <Chart form={combo} {...p} />
|
|
64
|
+
/** A ring of parts of a whole. */
|
|
65
|
+
export const DonutChart = (p: ChartFrame & DonutConfig) => <Chart form={donut} {...p} />
|
|
66
|
+
/** Concentric arcs, one per value. */
|
|
67
|
+
export const RadialChart = (p: ChartFrame & RadialConfig) => <Chart form={radial} {...p} />
|
|
68
|
+
/** Stages narrowing from first to last. */
|
|
69
|
+
export const FunnelChart = (p: ChartFrame & FunnelConfig) => <Chart form={funnel} {...p} />
|
|
70
|
+
/** Dots at x and y. */
|
|
71
|
+
export const ScatterChart = (p: ChartFrame & ScatterConfig) => <Chart form={scatter} {...p} />
|
|
72
|
+
/** Dots at x and y, sized by a third value. */
|
|
73
|
+
export const BubbleChart = (p: ChartFrame & ScatterConfig) => <Chart form={bubble} {...p} />
|
|
74
|
+
/** Values binned into equal ranges. */
|
|
75
|
+
export const Histogram = (p: ChartFrame & HistConfig) => <Chart form={histogram} {...p} />
|
|
76
|
+
/** A grid of cells coloured by value. */
|
|
77
|
+
export const HeatGrid = (p: ChartFrame & HeatConfig) => <Chart form={heat} {...p} />
|
|
78
|
+
/** Series on axes spread around a circle. */
|
|
79
|
+
export const RadarChart = (p: ChartFrame & RadarConfig) => <Chart form={radar} {...p} />
|
|
80
|
+
/** Nested rectangles sized by value. */
|
|
81
|
+
export const Treemap = (p: ChartFrame & TreemapConfig) => <Chart form={treemap} {...p} />
|
|
82
|
+
/** Nested rings sized by value. */
|
|
83
|
+
export const Sunburst = (p: ChartFrame & SunConfig) => <Chart form={sunburst} {...p} />
|
|
84
|
+
/** Flows between stages, band width showing the amount. */
|
|
85
|
+
export const SankeyChart = (p: ChartFrame & SankeyConfig) => <Chart form={sankey} {...p} />
|
|
86
|
+
/** Open, high, low and close per period. */
|
|
87
|
+
export const CandlestickChart = (p: ChartFrame & CandleConfig) => (
|
|
88
|
+
<Chart form={candlestick} {...p} />
|
|
89
|
+
)
|
|
90
|
+
/** Quartiles and whiskers per group. */
|
|
91
|
+
export const BoxPlot = (p: ChartFrame & BoxConfig) => <Chart form={box} {...p} />
|
|
92
|
+
/** A running total, each step a rise or a fall. */
|
|
93
|
+
export const WaterfallChart = (p: ChartFrame & WaterConfig) => <Chart form={waterfall} {...p} />
|
|
94
|
+
/** A long series with a window dragged over it. */
|
|
95
|
+
export const BrushChart = (p: ChartFrame & BrushConfig) => <Chart form={brush} {...p} />
|
|
96
|
+
/** Regions drawn as equal tiles. */
|
|
97
|
+
export const TileMap = (p: ChartFrame & TileConfig) => <Chart form={tile} {...p} />
|
|
98
|
+
/** One value on an arc between its bounds. */
|
|
99
|
+
export const GaugeChart = (p: ChartFrame & GaugeConfig) => <Chart form={gauge} {...p} />
|
|
100
|
+
|
|
101
|
+
/** A rolling window (06 §12): one `d` write per tick on a fixed domain. Pausing holds the window and shows it as a table. */
|
|
102
|
+
export function StreamChart(p: ChartFrame & Omit<StreamConfig, 'paused'>) {
|
|
103
|
+
const paused = state(false)
|
|
104
|
+
const held = state(untrack(() => p.data))
|
|
105
|
+
const flip = () => {
|
|
106
|
+
held.value = p.data
|
|
107
|
+
paused.value = !paused.value
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
<Chart
|
|
111
|
+
form={stream}
|
|
112
|
+
{...p}
|
|
113
|
+
data={paused.value ? held.value : p.data}
|
|
114
|
+
paused={paused.value}
|
|
115
|
+
toolbar={
|
|
116
|
+
<Button emphasis="outline" onClick={flip}>
|
|
117
|
+
{paused.value ? 'Resume' : 'Pause'}
|
|
118
|
+
</Button>
|
|
119
|
+
}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** No axes, end dot, `aria-hidden`: a sparkline is context inside a labelled parent. */
|
|
125
|
+
/** `format` says a hovered point the way the headline beside it does (`v => \`${v}%\``), so the unit carries over. */
|
|
126
|
+
export function Sparkline({
|
|
127
|
+
values,
|
|
128
|
+
color,
|
|
129
|
+
format,
|
|
130
|
+
}: {
|
|
131
|
+
values: number[]
|
|
132
|
+
color?: string | undefined
|
|
133
|
+
format?: ((value: number) => string) | undefined
|
|
134
|
+
}) {
|
|
135
|
+
let svg: SVGSVGElement | undefined
|
|
136
|
+
use(
|
|
137
|
+
sparkAction,
|
|
138
|
+
() => svg,
|
|
139
|
+
() => (format ? { values, format } : values),
|
|
140
|
+
)
|
|
141
|
+
return (
|
|
142
|
+
<svg
|
|
143
|
+
ref={(n) => (svg = n)}
|
|
144
|
+
data-part="spark"
|
|
145
|
+
viewBox={`0 0 ${SSR_WIDTH} 36`}
|
|
146
|
+
aria-hidden="true"
|
|
147
|
+
preserveAspectRatio="none"
|
|
148
|
+
style={`display:block;inline-size:100%;block-size:36px;overflow:visible${color ? `;--_dc:${color}` : ''}`}
|
|
149
|
+
// oxlint-disable-next-line kerf/no-html-sink -- toHTML escapes every text and attribute of the scene
|
|
150
|
+
innerHTML={toHTML(
|
|
151
|
+
sparkScene(
|
|
152
|
+
untrack(() => values),
|
|
153
|
+
SSR_WIDTH,
|
|
154
|
+
),
|
|
155
|
+
)}
|
|
156
|
+
></svg>
|
|
157
|
+
)
|
|
158
|
+
}
|
package/src/Chip.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CheckIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { derived } from '@kerf-js/core'
|
|
3
|
+
import type { Interaction } from '@kerf-js/core/interaction'
|
|
4
|
+
import { Icon, type IconRef } from './Icon'
|
|
5
|
+
import { useUi } from './use-ui'
|
|
6
|
+
import './fields'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/inputs/choice.css'
|
|
8
|
+
// the inputs form sits on the components chip (inputs.html loads both): pressed fill, forced colours
|
|
9
|
+
import '@kerf-js/veneer-core/styles/components/chip.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/components/toggle-button.css'
|
|
11
|
+
|
|
12
|
+
const sweepParts = () => (
|
|
13
|
+
<>
|
|
14
|
+
<span data-part="sweep-base" aria-hidden="true"></span>
|
|
15
|
+
<span data-part="sweep" aria-hidden="true"></span>
|
|
16
|
+
</>
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
/** A filter chip (03 §4 Chips): a toggle button; pressed pins the sweep on accent-soft and draws the check. */
|
|
20
|
+
export function Chip({
|
|
21
|
+
pressed,
|
|
22
|
+
count,
|
|
23
|
+
icon,
|
|
24
|
+
ui,
|
|
25
|
+
ref,
|
|
26
|
+
children,
|
|
27
|
+
...rest
|
|
28
|
+
}: {
|
|
29
|
+
ref?: ((el: HTMLButtonElement) => unknown) | undefined
|
|
30
|
+
pressed?: boolean
|
|
31
|
+
count?: unknown
|
|
32
|
+
icon?: IconRef | undefined
|
|
33
|
+
ui?: Interaction
|
|
34
|
+
children?: unknown
|
|
35
|
+
[attr: string]: unknown
|
|
36
|
+
}) {
|
|
37
|
+
let host: HTMLButtonElement | undefined
|
|
38
|
+
useUi(
|
|
39
|
+
() => ui,
|
|
40
|
+
() => host,
|
|
41
|
+
)
|
|
42
|
+
const glyph = derived(() => icon)
|
|
43
|
+
return (
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
data-scope="chip"
|
|
47
|
+
data-sweep=""
|
|
48
|
+
aria-pressed={pressed ? 'true' : 'false'}
|
|
49
|
+
{...rest}
|
|
50
|
+
ref={(n) => {
|
|
51
|
+
host = n
|
|
52
|
+
ref?.(n)
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{sweepParts()}
|
|
56
|
+
{pressed ? <CheckIcon data-part="check" /> : glyph.value && <Icon name={glyph.value} />}
|
|
57
|
+
{children}
|
|
58
|
+
{count !== undefined && <span data-part="count">{count}</span>}
|
|
59
|
+
</button>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Interaction } from '@kerf-js/core/interaction'
|
|
2
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
3
|
+
import { useUi } from './use-ui'
|
|
4
|
+
import './fields'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/inputs/choice-checkbox.css'
|
|
6
|
+
|
|
7
|
+
/** A native checkbox (03 §4): the box never fills, the check wipes in, and CSS draws both, so a list of them stays small; `indeterminate` is the real property. */
|
|
8
|
+
export function Checkbox({
|
|
9
|
+
children,
|
|
10
|
+
hint,
|
|
11
|
+
error,
|
|
12
|
+
indeterminate,
|
|
13
|
+
ui,
|
|
14
|
+
...rest
|
|
15
|
+
}: {
|
|
16
|
+
checked?: boolean
|
|
17
|
+
indeterminate?: boolean
|
|
18
|
+
hint?: unknown
|
|
19
|
+
error?: unknown
|
|
20
|
+
ui?: Interaction
|
|
21
|
+
children?: unknown
|
|
22
|
+
[attr: string]: unknown
|
|
23
|
+
}) {
|
|
24
|
+
let input: HTMLInputElement | undefined
|
|
25
|
+
let host: HTMLLabelElement | undefined
|
|
26
|
+
useUi(
|
|
27
|
+
() => ui,
|
|
28
|
+
() => host,
|
|
29
|
+
)
|
|
30
|
+
use(
|
|
31
|
+
(el: HTMLInputElement, on: boolean | undefined) => {
|
|
32
|
+
el.indeterminate = !!on
|
|
33
|
+
return { update: (v) => void (el.indeterminate = !!v), destroy() {} }
|
|
34
|
+
},
|
|
35
|
+
() => input,
|
|
36
|
+
() => indeterminate,
|
|
37
|
+
)
|
|
38
|
+
return (
|
|
39
|
+
<label ref={(n) => (host = n)} data-scope="checkbox" data-invalid={error ? '' : undefined}>
|
|
40
|
+
<input
|
|
41
|
+
ref={(n) => (input = n)}
|
|
42
|
+
type="checkbox"
|
|
43
|
+
aria-invalid={error ? 'true' : undefined}
|
|
44
|
+
{...rest}
|
|
45
|
+
/>
|
|
46
|
+
<span data-part="control" data-sweep="">
|
|
47
|
+
<span data-part="mark" aria-hidden="true"></span>
|
|
48
|
+
</span>
|
|
49
|
+
<span data-part="label">{children}</span>
|
|
50
|
+
{(error ?? hint) !== undefined && <span data-part="hint">{error ?? hint}</span>}
|
|
51
|
+
</label>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import { untrack } from '@kerf-js/core'
|
|
3
|
+
import type { Interaction } from '@kerf-js/core/interaction'
|
|
4
|
+
import { useUi } from './use-ui'
|
|
5
|
+
import { sweepParts } from './Choice-parts'
|
|
6
|
+
import './fields'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/inputs/choice-radio.css'
|
|
8
|
+
|
|
9
|
+
/** One radio (03 §4): the native input, the sweep ring, a dot that springs in. Use RadioGroup for a set. */
|
|
10
|
+
export function Radio({
|
|
11
|
+
children,
|
|
12
|
+
hint,
|
|
13
|
+
ui,
|
|
14
|
+
...rest
|
|
15
|
+
}: {
|
|
16
|
+
hint?: unknown
|
|
17
|
+
ui?: Interaction
|
|
18
|
+
children?: unknown
|
|
19
|
+
[attr: string]: unknown
|
|
20
|
+
}) {
|
|
21
|
+
let host: HTMLLabelElement | undefined
|
|
22
|
+
useUi(
|
|
23
|
+
() => ui,
|
|
24
|
+
() => host,
|
|
25
|
+
)
|
|
26
|
+
return (
|
|
27
|
+
<label ref={(n) => (host = n)} data-scope="radio">
|
|
28
|
+
<input type="radio" {...rest} />
|
|
29
|
+
<span data-part="control" data-sweep="">
|
|
30
|
+
{sweepParts()}
|
|
31
|
+
</span>
|
|
32
|
+
<span data-part="label">{children}</span>
|
|
33
|
+
{hint !== undefined && <span data-part="hint">{hint}</span>}
|
|
34
|
+
</label>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One RadioGroup choice. */
|
|
39
|
+
export type RadioOption<V extends string> = {
|
|
40
|
+
value: V
|
|
41
|
+
label: unknown
|
|
42
|
+
hint?: unknown
|
|
43
|
+
disabled?: boolean | undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A radio group: native radios, so arrow keys, form values and the group name are the platform's. */
|
|
47
|
+
export function RadioGroup<V extends string>({
|
|
48
|
+
label,
|
|
49
|
+
value,
|
|
50
|
+
onChange,
|
|
51
|
+
options,
|
|
52
|
+
name,
|
|
53
|
+
}: {
|
|
54
|
+
label: string
|
|
55
|
+
value: V
|
|
56
|
+
onChange: (v: V) => void
|
|
57
|
+
options: RadioOption<V>[]
|
|
58
|
+
name?: string | undefined
|
|
59
|
+
}) {
|
|
60
|
+
const group = untrack(() => name) ?? uid('radio')
|
|
61
|
+
return (
|
|
62
|
+
<div role="radiogroup" aria-label={label} style="display:grid;gap:var(--veneer-space-tight)">
|
|
63
|
+
{options.map((o) => (
|
|
64
|
+
<Radio
|
|
65
|
+
key={o.value}
|
|
66
|
+
name={group}
|
|
67
|
+
value={o.value}
|
|
68
|
+
hint={o.hint}
|
|
69
|
+
checked={o.value === value}
|
|
70
|
+
disabled={o.disabled}
|
|
71
|
+
onChange={() => onChange(o.value)}
|
|
72
|
+
>
|
|
73
|
+
{o.label}
|
|
74
|
+
</Radio>
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
)
|
|
78
|
+
}
|