From f8ed7d74f4877b677e08aa4758950eb0660ba4e0 Mon Sep 17 00:00:00 2001 From: Omri Katz <9701896+omridevk@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:41:48 +0200 Subject: [PATCH 01/24] feat(ui-kit-system): settings form controls and TanStack Form field components Co-Authored-By: Claude Opus 5.5 --- packages/ui-kit-system/package.json | 5 +- packages/ui-kit-system/src/checkbox-group.tsx | 33 ++ packages/ui-kit-system/src/checkbox.tsx | 40 ++ packages/ui-kit-system/src/color-picker.tsx | 107 ++++ .../ui-kit-system/src/combobox-select.tsx | 95 ++++ packages/ui-kit-system/src/confirm-dialog.tsx | 64 +++ packages/ui-kit-system/src/field-shell.tsx | 172 ++++++ .../ui-kit-system/src/hotkey-recorder.tsx | 198 +++++++ packages/ui-kit-system/src/index.tsx | 12 + packages/ui-kit-system/src/input-frame.ts | 2 + packages/ui-kit-system/src/number-input.tsx | 106 ++++ packages/ui-kit-system/src/password-input.tsx | 87 +++ packages/ui-kit-system/src/radio-cards.tsx | 81 +++ packages/ui-kit-system/src/select.tsx | 2 +- .../ui-kit-system/src/settings-fields.tsx | 522 ++++++++++++++++++ .../src/settings-form-contexts.ts | 3 + packages/ui-kit-system/src/settings-form.tsx | 10 + packages/ui-kit-system/src/tags-input.tsx | 75 +++ packages/ui-kit-system/src/text-field.tsx | 50 +- pnpm-lock.yaml | 28 +- 20 files changed, 1672 insertions(+), 20 deletions(-) create mode 100644 packages/ui-kit-system/src/checkbox-group.tsx create mode 100644 packages/ui-kit-system/src/checkbox.tsx create mode 100644 packages/ui-kit-system/src/color-picker.tsx create mode 100644 packages/ui-kit-system/src/combobox-select.tsx create mode 100644 packages/ui-kit-system/src/confirm-dialog.tsx create mode 100644 packages/ui-kit-system/src/field-shell.tsx create mode 100644 packages/ui-kit-system/src/hotkey-recorder.tsx create mode 100644 packages/ui-kit-system/src/input-frame.ts create mode 100644 packages/ui-kit-system/src/number-input.tsx create mode 100644 packages/ui-kit-system/src/password-input.tsx create mode 100644 packages/ui-kit-system/src/radio-cards.tsx create mode 100644 packages/ui-kit-system/src/settings-fields.tsx create mode 100644 packages/ui-kit-system/src/settings-form-contexts.ts create mode 100644 packages/ui-kit-system/src/settings-form.tsx create mode 100644 packages/ui-kit-system/src/tags-input.tsx diff --git a/packages/ui-kit-system/package.json b/packages/ui-kit-system/package.json index 6b82c62f70..4073970720 100644 --- a/packages/ui-kit-system/package.json +++ b/packages/ui-kit-system/package.json @@ -53,6 +53,8 @@ "@solid-primitives/event-listener": "catalog:", "@solid-primitives/resize-observer": "catalog:", "@solid-primitives/timer": "catalog:", + "@tanstack/solid-form": "^1.33.5", + "@tanstack/solid-hotkeys": "^0.17.0", "@tanstack/solid-virtual": "catalog:", "@zag-js/json-tree-utils": "^1.47.0", "class-variance-authority": "catalog:", @@ -75,7 +77,8 @@ "unocss": "catalog:", "vite": "catalog:", "vite-plugin-solid": "catalog:", - "vitest": "catalog:" + "vitest": "catalog:", + "zod": "catalog:" }, "peerDependencies": { "solid-js": "^1.9.13" diff --git a/packages/ui-kit-system/src/checkbox-group.tsx b/packages/ui-kit-system/src/checkbox-group.tsx new file mode 100644 index 0000000000..5d6399c5ba --- /dev/null +++ b/packages/ui-kit-system/src/checkbox-group.tsx @@ -0,0 +1,33 @@ +import {For, splitProps, type JSX} from 'solid-js' +import {Checkbox as Ark} from '@ark-ui/solid/checkbox' +import {Checkbox} from './checkbox.js' + +const ROOT = 'grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-x-4 gap-y-0.5 min-w-0' + +type CheckboxGroupProps = { + options: {value: string; label: string; disabled?: boolean}[] + value: string[] + onValueChange?: (value: string[]) => void + disabled?: boolean + readOnly?: boolean + invalid?: boolean + class?: string +} + +export function CheckboxGroup(props: CheckboxGroupProps): JSX.Element { + const [local] = splitProps(props, ['options', 'value', 'onValueChange', 'disabled', 'readOnly', 'invalid', 'class']) + return ( + local.value} + onValueChange={(value) => local.onValueChange?.(value)} + disabled={local.disabled} + readOnly={local.readOnly} + invalid={local.invalid} + > + + {(option) => } + + + ) +} diff --git a/packages/ui-kit-system/src/checkbox.tsx b/packages/ui-kit-system/src/checkbox.tsx new file mode 100644 index 0000000000..d15563b9a4 --- /dev/null +++ b/packages/ui-kit-system/src/checkbox.tsx @@ -0,0 +1,40 @@ +import {splitProps, type JSX} from 'solid-js' +import {Checkbox as Ark} from '@ark-ui/solid/checkbox' +import Check from 'lucide-solid/icons/check' + +const ROOT = + 'inline-flex items-center gap-2 min-h-8 cursor-pointer select-none font-chat data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed data-[readonly]:cursor-default' +const CONTROL = + 'grid place-items-center shrink-0 size-4 rounded-[0.25rem] [border:1px_solid_var(--chat-line-2)] text-chat-on-accent trans-cbb data-[state=checked]:bg-chat-accent data-[state=checked]:border-chat-accent data-[invalid]:border-chat-danger data-[focus-visible]:[outline:0.125rem_solid_var(--chat-accent)] data-[focus-visible]:[outline-offset:0.125rem]' +const INDICATOR = 'size-3 data-[state=checked]:anim-presence-in' +const LABEL = 'text-[0.8125rem] text-chat-text' + +type CheckboxProps = { + label: string + value?: string + checked?: boolean + onCheckedChange?: (checked: boolean) => void + disabled?: boolean + readOnly?: boolean + invalid?: boolean + class?: string +} + +export function Checkbox(props: CheckboxProps): JSX.Element { + const [local, rest] = splitProps(props, ['label', 'onCheckedChange', 'class']) + return ( + local.onCheckedChange?.(details.checked === true)} + > + + + + + {local.label} + + + ) +} diff --git a/packages/ui-kit-system/src/color-picker.tsx b/packages/ui-kit-system/src/color-picker.tsx new file mode 100644 index 0000000000..fe61b67de7 --- /dev/null +++ b/packages/ui-kit-system/src/color-picker.tsx @@ -0,0 +1,107 @@ +import {For, Show, splitProps, type JSX} from 'solid-js' +import {ColorPicker as Ark, parseColor, useColorPicker} from '@ark-ui/solid/color-picker' +import Check from 'lucide-solid/icons/check' +import {INPUT_FRAME} from './input-frame.js' + +const ROOT = 'flex flex-wrap items-center gap-x-3 gap-y-2 min-w-0' +const CONTROL = 'flex items-center gap-2' +const TRIGGER = + 'grid size-9 shrink-0 p-0 overflow-hidden rounded-chat-surface-md bg-transparent [border:1px_solid_var(--chat-line-2)] cursor-pointer focus-ring data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed data-[readonly]:cursor-default' +const VALUE_SWATCH = 'size-full' +const HEX_FRAME = `${INPUT_FRAME} w-28` +const HEX_INPUT = + 'flex-1 w-full min-w-0 bg-transparent [border:none] px-2.5 text-inherit font-chat-mono text-[0.75rem] uppercase focus-visible:outline-none read-only:cursor-default' +const PRESETS = 'flex flex-wrap items-center gap-1.5' +const PRESET = + 'grid place-items-center size-6 p-0 rounded-chat-pill bg-transparent [border:2px_solid_transparent] cursor-pointer trans-border focus-ring data-[state=checked]:border-chat-text-hi data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed' +const PRESET_SWATCH = 'grid place-items-center size-4.5 rounded-chat-pill' +const PRESET_CHECK = 'size-3 text-chat-on-accent [filter:drop-shadow(0_0_1px_var(--chat-panel))]' +const CONTENT = + 'hidden data-[state=open]:flex data-[state=open]:anim-combo flex-col gap-3 w-60 p-3 z-[2147483647] rounded-chat-surface-md bg-chat-panel [border:1px_solid_var(--chat-line)] shadow-chat-lg focus-visible:outline-none' +const AREA = 'relative h-36 overflow-hidden rounded-chat-surface-sm touch-none' +const THUMB = + 'size-3.5 rounded-chat-pill [border:2px_solid_var(--chat-panel)] [box-shadow:0_0_0_1px_var(--chat-text-hi)] -translate-x-1/2 -translate-y-1/2 focus-ring' +const SLIDER = 'relative h-3 rounded-chat-pill' +const SLIDER_TRACK = 'h-3 rounded-chat-pill' +const SLIDER_THUMB = `${THUMB} top-1/2` + +const HEX = /^#[0-9a-f]{6}$/i + +type ColorPickerProps = { + value: string + onValueChange?: (value: string) => void + onValueCommit?: (value: string) => void + presets?: string[] + disabled?: boolean + readOnly?: boolean + class?: string +} + +const toHex = (details: {value: {toString: (format: 'hex') => string}}): string => details.value.toString('hex') + +export function ColorPicker(props: ColorPickerProps): JSX.Element { + const [local] = splitProps(props, [ + 'value', + 'onValueChange', + 'onValueCommit', + 'presets', + 'disabled', + 'readOnly', + 'class', + ]) + const picker = useColorPicker(() => ({ + value: HEX.test(local.value) ? parseColor(local.value) : undefined, + format: 'hsba', + disabled: local.disabled, + readOnly: local.readOnly, + positioning: {strategy: 'fixed', placement: 'bottom-start', gutter: 6}, + onValueChange: (details) => { + local.onValueChange?.(toHex(details)) + if (!picker().open) local.onValueCommit?.(toHex(details)) + }, + onValueChangeEnd: (details) => local.onValueCommit?.(toHex(details)), + onOpenChange: (details) => { + if (!details.open) local.onValueCommit?.(picker().value.toString('hex')) + }, + })) + return ( + + + + + +
+ +
+
+ + + + {(preset) => ( + + + + + + + )} + + + + + + + + + + + + + + + + +
+ ) +} diff --git a/packages/ui-kit-system/src/combobox-select.tsx b/packages/ui-kit-system/src/combobox-select.tsx new file mode 100644 index 0000000000..8f59a071fb --- /dev/null +++ b/packages/ui-kit-system/src/combobox-select.tsx @@ -0,0 +1,95 @@ +import {For, Show, splitProps, untrack, type JSX} from 'solid-js' +import {Combobox, useListCollection} from '@ark-ui/solid/combobox' +import {useFilter} from '@ark-ui/solid/locale' +import Check from 'lucide-solid/icons/check' +import ChevronsUpDown from 'lucide-solid/icons/chevrons-up-down' +import {INPUT_FRAME} from './input-frame.js' + +const ROOT = 'min-w-0' +const CONTROL = `${INPUT_FRAME} w-full min-w-48` +const INPUT = + 'flex-1 w-full min-w-0 bg-transparent [border:none] px-2.5 text-inherit [font:inherit] focus-visible:outline-none placeholder:text-chat-text-3 read-only:cursor-default' +const TRIGGER = + 'flex items-center justify-center shrink-0 w-8 bg-transparent [border:none] p-0 text-chat-text-3 cursor-pointer hover:text-chat-text-hi disabled:cursor-not-allowed' +const CONTENT = + 'hidden data-[state=open]:flex data-[state=open]:anim-combo flex-col gap-0.5 z-[2147483647] min-w-[var(--reference-width)] max-h-60 overflow-y-auto rounded-chat-surface-md bg-chat-panel text-chat-text [border:1px_solid_var(--chat-line)] shadow-chat-lg p-1 font-chat focus-visible:outline-none' +const ITEM = + 'flex items-center justify-between gap-2 min-h-8 py-1.5 px-2.5 rounded-chat-surface-sm text-[0.8125rem] text-chat-text cursor-pointer select-none data-[highlighted]:bg-chat-fill-strong data-[highlighted]:text-chat-text-hi data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed' +const META = 'font-chat-mono text-[0.6875rem] text-chat-text-3' +const EMPTY = 'py-2 px-2.5 text-[0.75rem] text-chat-text-3' + +type ComboboxOption = {value: string; label: string; meta?: string} + +type ComboboxSelectProps = { + options: ComboboxOption[] + value: string | undefined + onValueChange?: (value: string) => void + placeholder?: string + emptyText?: string + disabled?: boolean + readOnly?: boolean + class?: string +} + +export function ComboboxSelect(props: ComboboxSelectProps): JSX.Element { + const [local] = splitProps(props, [ + 'options', + 'value', + 'onValueChange', + 'placeholder', + 'emptyText', + 'disabled', + 'readOnly', + 'class', + ]) + const filters = useFilter({sensitivity: 'base'}) + const list = useListCollection({ + initialItems: untrack(() => local.options), + filter: (itemText, filterText) => filters().contains(itemText, filterText), + }) + return ( + { + const [next] = details.value + if (next !== undefined) local.onValueChange?.(next) + }} + onInputValueChange={(details) => list.filter(details.inputValue)} + onOpenChange={(details) => { + if (details.open) list.filter('') + }} + openOnClick + inputBehavior="autohighlight" + disabled={local.disabled} + readOnly={local.readOnly} + positioning={{strategy: 'fixed', placement: 'bottom-start', gutter: 4}} + > + + + + + + + + {local.emptyText ?? 'No matches'} + + {(item) => ( + + {item.label} + + {(meta) => {meta()}} + + + + + )} + + + + + ) +} diff --git a/packages/ui-kit-system/src/confirm-dialog.tsx b/packages/ui-kit-system/src/confirm-dialog.tsx new file mode 100644 index 0000000000..0e562a7398 --- /dev/null +++ b/packages/ui-kit-system/src/confirm-dialog.tsx @@ -0,0 +1,64 @@ +import {splitProps, type JSX} from 'solid-js' +import {Dialog as ArkDialog} from '@ark-ui/solid/dialog' +import {Button} from './button.js' +import {Dialog} from './dialog.js' + +const DESCRIPTION = 'm-0 text-[0.8125rem] leading-[1.45] text-chat-text-2' +const ACTIONS = 'flex items-center justify-end gap-1.5' + +type ConfirmDialogProps = { + open: boolean + onOpenChange: (open: boolean) => void + title: string + description: JSX.Element + confirmLabel: string + cancelLabel?: string + onConfirm: () => void +} + +export function ConfirmDialog(props: ConfirmDialogProps): JSX.Element { + const [local] = splitProps(props, [ + 'open', + 'onOpenChange', + 'title', + 'description', + 'confirmLabel', + 'cancelLabel', + 'onConfirm', + ]) + let cancel: HTMLButtonElement | undefined + return ( + cancel ?? null} + footer={ +
+ + +
+ } + > + {local.description} +
+ ) +} diff --git a/packages/ui-kit-system/src/field-shell.tsx b/packages/ui-kit-system/src/field-shell.tsx new file mode 100644 index 0000000000..fb62f88097 --- /dev/null +++ b/packages/ui-kit-system/src/field-shell.tsx @@ -0,0 +1,172 @@ +import {Show, splitProps, type JSX} from 'solid-js' +import {Field} from '@ark-ui/solid/field' +import {Fieldset} from '@ark-ui/solid/fieldset' +import CircleAlert from 'lucide-solid/icons/circle-alert' +import Lock from 'lucide-solid/icons/lock' +import RotateCcw from 'lucide-solid/icons/rotate-ccw' +import {Button} from './button.js' + +const ROOT = 'flex min-w-0 m-0 p-0 [border:none] font-chat' +const LAYOUT = { + row: 'flex-row items-center justify-between gap-4', + stack: 'flex-col gap-2', +} +const HEAD = 'flex flex-col gap-0.5 flex-1 min-w-0' +const LABEL = + 'inline-flex items-center gap-2 p-0 text-[0.8125rem] leading-snug font-medium text-chat-text-hi data-[disabled]:text-chat-text-2' +const CHANGED = 'size-1.5 shrink-0 rounded-chat-pill bg-chat-accent' +const HELP = 'flex flex-col gap-1 text-[0.75rem] leading-snug text-chat-text-2' +const LOCK = 'inline-flex items-center gap-1.5 font-chat-mono text-[0.6875rem] text-chat-text-3' +const ERROR = 'flex items-start gap-1.5 text-[0.75rem] leading-snug text-chat-danger' +const ICON = 'size-3.5 shrink-0 mt-px' +const RESET = 'self-start gap-1 min-h-6 text-chat-text-3 hover:text-chat-text-hi' +const CONTROL = { + row: 'flex shrink-0 justify-end', + stack: 'flex flex-col min-w-0', +} +const FOCUS_TARGET = + 'input:checked:not([type=hidden]), [role=radio][aria-checked=true], input:not([type=hidden]):not(:disabled), textarea, button:not(:disabled), [role=slider], [tabindex="0"]' + +type FieldShellProps = { + label: string + description?: JSX.Element + error?: string + layout?: 'row' | 'stack' + group?: boolean + changed?: boolean + onReset?: () => void + locked?: string + disabled?: boolean + required?: boolean + class?: string + children: JSX.Element +} + +export function FieldShell(props: FieldShellProps): JSX.Element { + const [local] = splitProps(props, [ + 'label', + 'description', + 'error', + 'layout', + 'group', + 'changed', + 'onReset', + 'locked', + 'disabled', + 'required', + 'class', + 'children', + ]) + let control: HTMLDivElement | undefined + const layout = () => local.layout ?? 'stack' + const rootClass = () => `${ROOT} ${LAYOUT[layout()]} ${local.class ?? ''}` + const showReset = () => Boolean(local.changed && local.onReset && !local.locked && !local.disabled) + const reset = () => { + local.onReset?.() + const target = control?.querySelector(FOCUS_TARGET) + target?.focus() + } + const helper = (): JSX.Element => ( + <> + {(description) => {description()}} + + {(reason) => ( + + + )} + + + ) + const hasHelper = () => Boolean(local.description || local.locked) + const errorBody = (): JSX.Element => ( + <> +