@behavioral-agentic-design-system/core 0.42.0 → 0.47.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/package.json +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +9 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +8 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +19 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +46 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +39 -0
- package/src/stories/DateField.stories.tsx +28 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +26 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +10 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +15 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +30 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +7 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- package/src/tokens.json +86 -58
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
const inlineEditViewVariants = cva(
|
|
8
|
+
"inline-flex w-full min-w-0 cursor-text items-center rounded-md outline-none transition-colors select-none",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
ghost:
|
|
13
|
+
"px-0 hover:bg-muted/60 data-[empty=true]:text-muted-foreground",
|
|
14
|
+
outline:
|
|
15
|
+
"border border-transparent px-3 hover:border-input data-[empty=true]:text-muted-foreground",
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
sm: "h-8 text-sm",
|
|
19
|
+
default: "h-9 text-sm md:text-sm",
|
|
20
|
+
lg: "h-10 text-base",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: { variant: "ghost", size: "default" },
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const inlineEditInputVariants = cva(
|
|
28
|
+
"w-full min-w-0 rounded-md border bg-transparent outline-none transition-[color,box-shadow] placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50",
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
variant: {
|
|
32
|
+
ghost:
|
|
33
|
+
"rounded-none border-0 border-b border-input focus-visible:border-ring focus-visible:ring-0",
|
|
34
|
+
outline:
|
|
35
|
+
"border-input shadow-xs focus-visible:border-ring dark:bg-input/30",
|
|
36
|
+
},
|
|
37
|
+
size: {
|
|
38
|
+
sm: "h-8 px-2.5 text-sm",
|
|
39
|
+
default: "h-9 px-3 text-sm md:text-sm",
|
|
40
|
+
lg: "h-10 px-4 text-base",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultVariants: { variant: "ghost", size: "default" },
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
export interface InlineEditProps
|
|
48
|
+
extends Omit<React.ComponentProps<"input">, "size" | "onChange">,
|
|
49
|
+
VariantProps<typeof inlineEditViewVariants> {
|
|
50
|
+
/** Controlled value. Use with onConfirm / onCancel. */
|
|
51
|
+
value?: string
|
|
52
|
+
/** Uncontrolled initial value. */
|
|
53
|
+
defaultValue?: string
|
|
54
|
+
/** Called with the new value when the user confirms (Enter or blur). */
|
|
55
|
+
onConfirm?: (value: string) => void
|
|
56
|
+
/** Called when the user cancels with Escape; value reverts to before-edit state. */
|
|
57
|
+
onCancel?: (value: string) => void
|
|
58
|
+
/** Placeholder shown in view mode when value is empty. */
|
|
59
|
+
placeholder?: string
|
|
60
|
+
/** When true the input renders directly without the view-mode toggle. */
|
|
61
|
+
alwaysEditing?: boolean
|
|
62
|
+
/** Wrapper className */
|
|
63
|
+
className?: string
|
|
64
|
+
/** Input element className override */
|
|
65
|
+
inputClassName?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function InlineEdit({
|
|
69
|
+
value: controlledValue,
|
|
70
|
+
defaultValue = "",
|
|
71
|
+
onConfirm,
|
|
72
|
+
onCancel,
|
|
73
|
+
placeholder = "Click to edit",
|
|
74
|
+
alwaysEditing = false,
|
|
75
|
+
disabled,
|
|
76
|
+
variant,
|
|
77
|
+
size,
|
|
78
|
+
className,
|
|
79
|
+
inputClassName,
|
|
80
|
+
...inputProps
|
|
81
|
+
}: InlineEditProps) {
|
|
82
|
+
const [editing, setEditing] = React.useState(alwaysEditing)
|
|
83
|
+
const [draft, setDraft] = React.useState(controlledValue ?? defaultValue)
|
|
84
|
+
const [committed, setCommitted] = React.useState(controlledValue ?? defaultValue)
|
|
85
|
+
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
86
|
+
|
|
87
|
+
// Sync when controlled value changes from outside
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (controlledValue !== undefined) {
|
|
90
|
+
setDraft(controlledValue)
|
|
91
|
+
setCommitted(controlledValue)
|
|
92
|
+
}
|
|
93
|
+
}, [controlledValue])
|
|
94
|
+
|
|
95
|
+
const startEdit = () => {
|
|
96
|
+
if (disabled || alwaysEditing) return
|
|
97
|
+
setEditing(true)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const confirm = () => {
|
|
101
|
+
if (!editing) return
|
|
102
|
+
setCommitted(draft)
|
|
103
|
+
setEditing(false)
|
|
104
|
+
onConfirm?.(draft)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const cancel = () => {
|
|
108
|
+
if (!editing) return
|
|
109
|
+
setDraft(committed)
|
|
110
|
+
setEditing(false)
|
|
111
|
+
onCancel?.(committed)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
if (editing) {
|
|
116
|
+
inputRef.current?.focus()
|
|
117
|
+
inputRef.current?.select()
|
|
118
|
+
}
|
|
119
|
+
}, [editing])
|
|
120
|
+
|
|
121
|
+
const displayValue = controlledValue ?? committed
|
|
122
|
+
|
|
123
|
+
if (!editing && !alwaysEditing) {
|
|
124
|
+
return (
|
|
125
|
+
<span
|
|
126
|
+
role="button"
|
|
127
|
+
tabIndex={disabled ? -1 : 0}
|
|
128
|
+
data-slot="inline-edit-view"
|
|
129
|
+
data-empty={!displayValue ? "true" : undefined}
|
|
130
|
+
aria-label={displayValue || placeholder}
|
|
131
|
+
onClick={startEdit}
|
|
132
|
+
onKeyDown={(e) => {
|
|
133
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
134
|
+
e.preventDefault()
|
|
135
|
+
startEdit()
|
|
136
|
+
}
|
|
137
|
+
}}
|
|
138
|
+
className={cn(
|
|
139
|
+
inlineEditViewVariants({ variant, size }),
|
|
140
|
+
disabled && "cursor-not-allowed opacity-50",
|
|
141
|
+
className
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
{displayValue || (
|
|
145
|
+
<span className="text-muted-foreground">{placeholder}</span>
|
|
146
|
+
)}
|
|
147
|
+
</span>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<input
|
|
153
|
+
ref={inputRef}
|
|
154
|
+
data-slot="inline-edit-input"
|
|
155
|
+
value={draft}
|
|
156
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
157
|
+
onBlur={confirm}
|
|
158
|
+
onKeyDown={(e) => {
|
|
159
|
+
if (e.key === "Enter") {
|
|
160
|
+
e.preventDefault()
|
|
161
|
+
confirm()
|
|
162
|
+
} else if (e.key === "Escape") {
|
|
163
|
+
e.preventDefault()
|
|
164
|
+
cancel()
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
disabled={disabled}
|
|
168
|
+
placeholder={placeholder}
|
|
169
|
+
{...inputProps}
|
|
170
|
+
className={cn(inlineEditInputVariants({ variant, size }), inputClassName)}
|
|
171
|
+
/>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { InlineEdit, inlineEditViewVariants, inlineEditInputVariants }
|
|
@@ -16,7 +16,10 @@ import { Button } from "./button";
|
|
|
16
16
|
const inputGroupVariants = cva(
|
|
17
17
|
[
|
|
18
18
|
"flex items-center overflow-hidden",
|
|
19
|
-
|
|
19
|
+
// dark:bg-input/30 lives on the group, not the <input>: on the input it
|
|
20
|
+
// tinted only the text box and left the addons and button untinted, which
|
|
21
|
+
// read as a lighter block floating inside the field in dark mode.
|
|
22
|
+
"rounded-md border border-input bg-transparent shadow-xs dark:bg-input/30",
|
|
20
23
|
"transition-[color,box-shadow]",
|
|
21
24
|
"focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
|
|
22
25
|
// Scope disabled styling to the hosted INPUT — has-[:disabled] matched any
|
|
@@ -102,7 +105,7 @@ function InputGroupInput({
|
|
|
102
105
|
className={cn(
|
|
103
106
|
"min-w-0 flex-1 bg-transparent outline-none",
|
|
104
107
|
"placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground",
|
|
105
|
-
"disabled:cursor-not-allowed
|
|
108
|
+
"disabled:cursor-not-allowed",
|
|
106
109
|
inputPaddingBySize[size],
|
|
107
110
|
// Collapse the doubled inner edge next to an addon: the addon already
|
|
108
111
|
// carries the group's horizontal rhythm (its outer padding), so the
|
|
@@ -62,7 +62,7 @@ function MonthPicker({
|
|
|
62
62
|
className,
|
|
63
63
|
id,
|
|
64
64
|
}: MonthPickerProps) {
|
|
65
|
-
const isControlled = value !== undefined
|
|
65
|
+
const isControlled = value !== undefined || onChange !== undefined
|
|
66
66
|
const [internalValue, setInternalValue] = React.useState<Date | undefined>(
|
|
67
67
|
defaultValue
|
|
68
68
|
)
|
|
@@ -49,6 +49,7 @@ function MultiSelect({
|
|
|
49
49
|
options,
|
|
50
50
|
value = [],
|
|
51
51
|
onValueChange,
|
|
52
|
+
// copy-ok: this default is quoted in the component registry and generated docs; change them together.
|
|
52
53
|
placeholder = "Select options...",
|
|
53
54
|
searchPlaceholder = "Search...",
|
|
54
55
|
emptyText = "No results found.",
|
|
@@ -52,6 +52,17 @@ export interface NumberInputProps
|
|
|
52
52
|
|
|
53
53
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
54
54
|
|
|
55
|
+
/** Digits after the decimal point, so 0.1 + 0.2 can be rounded back to 0.3. */
|
|
56
|
+
function decimalsOf(n: number): number {
|
|
57
|
+
if (!Number.isFinite(n)) return 0;
|
|
58
|
+
const [, frac = ""] = String(n).split(".");
|
|
59
|
+
return frac.length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function roundTo(n: number, decimals: number): number {
|
|
63
|
+
return Number(n.toFixed(Math.min(decimals, 12)));
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
// ─── NumberInput ──────────────────────────────────────────────────────────────
|
|
56
67
|
|
|
57
68
|
function NumberInput({
|
|
@@ -66,6 +77,8 @@ function NumberInput({
|
|
|
66
77
|
className,
|
|
67
78
|
"aria-label": ariaLabel = "Number input",
|
|
68
79
|
"aria-labelledby": ariaLabelledBy,
|
|
80
|
+
onBlur: onBlurProp,
|
|
81
|
+
onKeyDown: onKeyDownProp,
|
|
69
82
|
...rest
|
|
70
83
|
}: NumberInputProps) {
|
|
71
84
|
const isControlled = valueProp !== undefined;
|
|
@@ -100,12 +113,21 @@ function NumberInput({
|
|
|
100
113
|
[min, max, isControlled, onChange]
|
|
101
114
|
);
|
|
102
115
|
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
// Step from what is in the box, not the last committed value: with 3 committed, typing 7 and pressing
|
|
117
|
+
// ArrowUp must give 8. Round to the finer of the two precisions so step={0.1} never shows 0.30000000000000004.
|
|
118
|
+
const stepBy = (delta: number) => {
|
|
119
|
+
const typed = parseFloat(inputStr);
|
|
120
|
+
const base = Number.isFinite(typed) ? typed : value;
|
|
121
|
+
commit(roundTo(base + delta, Math.max(decimalsOf(step), decimalsOf(base))));
|
|
122
|
+
};
|
|
123
|
+
const increment = () => stepBy(step);
|
|
124
|
+
const decrement = () => stepBy(-step);
|
|
105
125
|
|
|
106
126
|
// ── keyboard handling ──────────────────────────────────────────────────────
|
|
107
127
|
|
|
108
128
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
129
|
+
onKeyDownProp?.(e);
|
|
130
|
+
if (e.defaultPrevented) return;
|
|
109
131
|
if (e.key === "ArrowUp") {
|
|
110
132
|
e.preventDefault();
|
|
111
133
|
increment();
|
|
@@ -114,10 +136,10 @@ function NumberInput({
|
|
|
114
136
|
decrement();
|
|
115
137
|
} else if (e.key === "PageUp") {
|
|
116
138
|
e.preventDefault();
|
|
117
|
-
|
|
139
|
+
stepBy(step * 10);
|
|
118
140
|
} else if (e.key === "PageDown") {
|
|
119
141
|
e.preventDefault();
|
|
120
|
-
|
|
142
|
+
stepBy(-step * 10);
|
|
121
143
|
} else if (e.key === "Home" && Number.isFinite(min)) {
|
|
122
144
|
e.preventDefault();
|
|
123
145
|
commit(min);
|
|
@@ -135,7 +157,8 @@ function NumberInput({
|
|
|
135
157
|
|
|
136
158
|
// ── blur: commit typed value or reset ─────────────────────────────────────
|
|
137
159
|
|
|
138
|
-
const handleBlur = () => {
|
|
160
|
+
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
161
|
+
onBlurProp?.(e);
|
|
139
162
|
const parsed = parseFloat(inputStr);
|
|
140
163
|
if (Number.isFinite(parsed)) {
|
|
141
164
|
commit(parsed);
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
import { cn } from "../../lib/utils";
|
|
6
|
+
|
|
7
|
+
/* -------------------------------------------------------------------------- */
|
|
8
|
+
/* Variants */
|
|
9
|
+
/* -------------------------------------------------------------------------- */
|
|
10
|
+
|
|
11
|
+
const otpSlotVariants = cva(
|
|
12
|
+
[
|
|
13
|
+
"relative flex h-11 w-10 items-center justify-center",
|
|
14
|
+
"rounded-md border border-input bg-background",
|
|
15
|
+
"text-sm font-medium text-foreground caret-transparent",
|
|
16
|
+
"outline-none ring-offset-background",
|
|
17
|
+
"transition-[color,box-shadow]",
|
|
18
|
+
"focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50",
|
|
19
|
+
"aria-[invalid=true]:border-destructive aria-[invalid=true]:ring-destructive/20",
|
|
20
|
+
],
|
|
21
|
+
{
|
|
22
|
+
variants: {
|
|
23
|
+
size: {
|
|
24
|
+
sm: "h-9 w-9 text-sm",
|
|
25
|
+
default: "h-11 w-10 text-sm",
|
|
26
|
+
lg: "h-12 w-11 text-base",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: { size: "default" },
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/* -------------------------------------------------------------------------- */
|
|
34
|
+
/* OTPInput */
|
|
35
|
+
/* -------------------------------------------------------------------------- */
|
|
36
|
+
|
|
37
|
+
export interface OTPInputProps
|
|
38
|
+
extends Omit<React.ComponentProps<"div">, "onChange"> {
|
|
39
|
+
/** Number of OTP slots. Defaults to 6. */
|
|
40
|
+
length?: number;
|
|
41
|
+
/** Controlled value — a string of up to `length` characters. */
|
|
42
|
+
value?: string;
|
|
43
|
+
/** Called whenever the composed value changes. */
|
|
44
|
+
onChange?: (value: string) => void;
|
|
45
|
+
/** Called when every slot is filled and the value is complete. */
|
|
46
|
+
onComplete?: (value: string) => void;
|
|
47
|
+
/** Accept only numeric input. Defaults to true. */
|
|
48
|
+
numeric?: boolean;
|
|
49
|
+
/** Disable all slots. */
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
/** Mark all slots as invalid (aria-invalid). */
|
|
52
|
+
invalid?: boolean;
|
|
53
|
+
/** Render a separator element after this slot index (0-based). */
|
|
54
|
+
separatorAfter?: number;
|
|
55
|
+
/** aria-label for the group. */
|
|
56
|
+
"aria-label"?: string;
|
|
57
|
+
size?: VariantProps<typeof otpSlotVariants>["size"];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function OTPInput({
|
|
61
|
+
length = 6,
|
|
62
|
+
value: valueProp,
|
|
63
|
+
onChange,
|
|
64
|
+
onComplete,
|
|
65
|
+
numeric = true,
|
|
66
|
+
disabled = false,
|
|
67
|
+
invalid = false,
|
|
68
|
+
separatorAfter,
|
|
69
|
+
className,
|
|
70
|
+
size,
|
|
71
|
+
"aria-label": ariaLabel = "One-time password",
|
|
72
|
+
...props
|
|
73
|
+
}: OTPInputProps) {
|
|
74
|
+
const [internalValue, setInternalValue] = React.useState("");
|
|
75
|
+
const isControlled = valueProp !== undefined;
|
|
76
|
+
const value = isControlled ? valueProp : internalValue;
|
|
77
|
+
|
|
78
|
+
const refs = React.useRef<Array<HTMLInputElement | null>>([]);
|
|
79
|
+
|
|
80
|
+
const setRefs = React.useCallback(
|
|
81
|
+
(index: number) => (el: HTMLInputElement | null) => {
|
|
82
|
+
refs.current[index] = el;
|
|
83
|
+
},
|
|
84
|
+
[]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
function updateValue(next: string) {
|
|
88
|
+
if (!isControlled) setInternalValue(next);
|
|
89
|
+
onChange?.(next);
|
|
90
|
+
if (next.length === length) onComplete?.(next);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleKeyDown(index: number, e: React.KeyboardEvent<HTMLInputElement>) {
|
|
94
|
+
if (e.key === "ArrowLeft") {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
refs.current[index - 1]?.focus();
|
|
97
|
+
} else if (e.key === "ArrowRight") {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
refs.current[index + 1]?.focus();
|
|
100
|
+
} else if (e.key === "Backspace") {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
if (value[index]) {
|
|
103
|
+
// Clear current slot
|
|
104
|
+
const next = value.slice(0, index) + value.slice(index + 1);
|
|
105
|
+
updateValue(next.padEnd(index, "").slice(0, length));
|
|
106
|
+
} else {
|
|
107
|
+
// Already empty — retreat and clear previous
|
|
108
|
+
const prev = index - 1;
|
|
109
|
+
if (prev >= 0) {
|
|
110
|
+
refs.current[prev]?.focus();
|
|
111
|
+
const next = value.slice(0, prev) + value.slice(prev + 1);
|
|
112
|
+
updateValue(next.padEnd(prev, "").slice(0, length));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else if (e.key === "Delete") {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
const next = value.slice(0, index) + value.slice(index + 1);
|
|
118
|
+
updateValue(next.padEnd(index, "").slice(0, length));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function handleInput(index: number, e: React.FormEvent<HTMLInputElement>) {
|
|
123
|
+
const raw = (e.target as HTMLInputElement).value;
|
|
124
|
+
const char = raw.slice(-1);
|
|
125
|
+
if (!char) return;
|
|
126
|
+
if (numeric && !/^\d$/.test(char)) return;
|
|
127
|
+
|
|
128
|
+
const chars = value.split("").concat(Array(length).fill("")).slice(0, length);
|
|
129
|
+
chars[index] = char;
|
|
130
|
+
const next = chars.join("").trimEnd();
|
|
131
|
+
updateValue(next);
|
|
132
|
+
refs.current[Math.min(index + 1, length - 1)]?.focus();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handlePaste(e: React.ClipboardEvent<HTMLInputElement>) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
const pasted = e.clipboardData.getData("text/plain");
|
|
138
|
+
const filtered = numeric ? pasted.replace(/\D/g, "") : pasted;
|
|
139
|
+
const next = filtered.slice(0, length);
|
|
140
|
+
updateValue(next);
|
|
141
|
+
refs.current[Math.min(next.length, length - 1)]?.focus();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function handleFocus(index: number) {
|
|
145
|
+
// Move focus to the first unfilled slot when clicking a filled slot
|
|
146
|
+
// (only when clicking past the filled region)
|
|
147
|
+
const firstEmpty = value.length;
|
|
148
|
+
if (index > firstEmpty) {
|
|
149
|
+
refs.current[firstEmpty]?.focus();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div
|
|
155
|
+
role="group"
|
|
156
|
+
aria-label={ariaLabel}
|
|
157
|
+
className={cn("flex items-center gap-2", className)}
|
|
158
|
+
{...props}
|
|
159
|
+
>
|
|
160
|
+
{Array.from({ length }, (_, i) => (
|
|
161
|
+
<React.Fragment key={i}>
|
|
162
|
+
<div
|
|
163
|
+
className={cn(otpSlotVariants({ size }))}
|
|
164
|
+
aria-invalid={invalid || undefined}
|
|
165
|
+
>
|
|
166
|
+
<input
|
|
167
|
+
ref={setRefs(i)}
|
|
168
|
+
type="text"
|
|
169
|
+
inputMode={numeric ? "numeric" : "text"}
|
|
170
|
+
pattern={numeric ? "[0-9]*" : undefined}
|
|
171
|
+
maxLength={2}
|
|
172
|
+
value={value[i] ?? ""}
|
|
173
|
+
autoComplete={i === 0 ? "one-time-code" : "off"}
|
|
174
|
+
disabled={disabled}
|
|
175
|
+
aria-label={`Digit ${i + 1} of ${length}`}
|
|
176
|
+
className={cn(
|
|
177
|
+
"absolute inset-0 h-full w-full cursor-text select-none",
|
|
178
|
+
"bg-transparent text-center text-[inherit] font-[inherit]",
|
|
179
|
+
"outline-none border-0 ring-0",
|
|
180
|
+
"caret-transparent",
|
|
181
|
+
disabled && "cursor-not-allowed opacity-50"
|
|
182
|
+
)}
|
|
183
|
+
style={{
|
|
184
|
+
transitionDuration: "var(--duration-fast)",
|
|
185
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
186
|
+
}}
|
|
187
|
+
onKeyDown={(e) => handleKeyDown(i, e)}
|
|
188
|
+
onInput={(e) => handleInput(i, e)}
|
|
189
|
+
onPaste={handlePaste}
|
|
190
|
+
onFocus={() => handleFocus(i)}
|
|
191
|
+
onChange={() => {}} // suppress React uncontrolled warning
|
|
192
|
+
/>
|
|
193
|
+
</div>
|
|
194
|
+
{separatorAfter === i && (
|
|
195
|
+
<span
|
|
196
|
+
aria-hidden
|
|
197
|
+
className="text-muted-foreground select-none text-sm font-medium"
|
|
198
|
+
>
|
|
199
|
+
–
|
|
200
|
+
</span>
|
|
201
|
+
)}
|
|
202
|
+
</React.Fragment>
|
|
203
|
+
))}
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { OTPInput, otpSlotVariants };
|