@mortenbrudvik/waveui 0.8.0 → 0.9.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/README.md +231 -85
- package/dist/components/data-display/InfoButton.cjs +2 -0
- package/dist/components/data-display/InfoButton.cjs.map +1 -0
- package/dist/components/data-display/InfoButton.mjs +173 -0
- package/dist/components/data-display/InfoButton.mjs.map +1 -0
- package/dist/components/data-display/InfoLabel.cjs +1 -1
- package/dist/components/data-display/InfoLabel.cjs.map +1 -1
- package/dist/components/data-display/InfoLabel.mjs +39 -96
- package/dist/components/data-display/InfoLabel.mjs.map +1 -1
- package/dist/components/input/Checkbox.cjs +1 -1
- package/dist/components/input/Checkbox.cjs.map +1 -1
- package/dist/components/input/Checkbox.mjs +91 -75
- package/dist/components/input/Checkbox.mjs.map +1 -1
- package/dist/components/input/ColorPicker.parts.cjs +1 -1
- package/dist/components/input/ColorPicker.parts.cjs.map +1 -1
- package/dist/components/input/ColorPicker.parts.mjs +1 -1
- package/dist/components/input/ColorPicker.parts.mjs.map +1 -1
- package/dist/components/input/Combobox.cjs +1 -1
- package/dist/components/input/Combobox.cjs.map +1 -1
- package/dist/components/input/Combobox.expand.cjs +1 -1
- package/dist/components/input/Combobox.expand.cjs.map +1 -1
- package/dist/components/input/Combobox.expand.mjs +20 -20
- package/dist/components/input/Combobox.expand.mjs.map +1 -1
- package/dist/components/input/Combobox.mjs +143 -138
- package/dist/components/input/Combobox.mjs.map +1 -1
- package/dist/components/input/DatePicker.cjs +1 -1
- package/dist/components/input/DatePicker.cjs.map +1 -1
- package/dist/components/input/DatePicker.mjs +213 -209
- package/dist/components/input/DatePicker.mjs.map +1 -1
- package/dist/components/input/Dropdown.cjs +1 -1
- package/dist/components/input/Dropdown.cjs.map +1 -1
- package/dist/components/input/Dropdown.mjs +80 -74
- package/dist/components/input/Dropdown.mjs.map +1 -1
- package/dist/components/input/Field.cjs +1 -1
- package/dist/components/input/Field.cjs.map +1 -1
- package/dist/components/input/Field.mjs +99 -66
- package/dist/components/input/Field.mjs.map +1 -1
- package/dist/components/input/Input.cjs +1 -1
- package/dist/components/input/Input.cjs.map +1 -1
- package/dist/components/input/Input.mjs +79 -55
- package/dist/components/input/Input.mjs.map +1 -1
- package/dist/components/input/Label.cjs +1 -1
- package/dist/components/input/Label.cjs.map +1 -1
- package/dist/components/input/Label.mjs +19 -13
- package/dist/components/input/Label.mjs.map +1 -1
- package/dist/components/input/Rating.cjs +1 -1
- package/dist/components/input/Rating.cjs.map +1 -1
- package/dist/components/input/Rating.item.cjs +2 -0
- package/dist/components/input/Rating.item.cjs.map +1 -0
- package/dist/components/input/Rating.item.mjs +255 -0
- package/dist/components/input/Rating.item.mjs.map +1 -0
- package/dist/components/input/Rating.mjs +150 -151
- package/dist/components/input/Rating.mjs.map +1 -1
- package/dist/components/input/SearchBox.cjs +1 -1
- package/dist/components/input/SearchBox.cjs.map +1 -1
- package/dist/components/input/SearchBox.mjs +146 -115
- package/dist/components/input/SearchBox.mjs.map +1 -1
- package/dist/components/input/Select.cjs +1 -1
- package/dist/components/input/Select.cjs.map +1 -1
- package/dist/components/input/Select.mjs +34 -25
- package/dist/components/input/Select.mjs.map +1 -1
- package/dist/components/input/Slider.cjs +1 -1
- package/dist/components/input/Slider.cjs.map +1 -1
- package/dist/components/input/Slider.mjs +77 -54
- package/dist/components/input/Slider.mjs.map +1 -1
- package/dist/components/input/SpinButton.cjs +1 -1
- package/dist/components/input/SpinButton.cjs.map +1 -1
- package/dist/components/input/SpinButton.mjs +198 -96
- package/dist/components/input/SpinButton.mjs.map +1 -1
- package/dist/components/input/Switch.cjs +1 -1
- package/dist/components/input/Switch.cjs.map +1 -1
- package/dist/components/input/Switch.mjs +71 -55
- package/dist/components/input/Switch.mjs.map +1 -1
- package/dist/components/input/TagPicker.cjs +1 -1
- package/dist/components/input/TagPicker.cjs.map +1 -1
- package/dist/components/input/TagPicker.mjs +142 -116
- package/dist/components/input/TagPicker.mjs.map +1 -1
- package/dist/components/input/Textarea.cjs +1 -1
- package/dist/components/input/Textarea.cjs.map +1 -1
- package/dist/components/input/Textarea.mjs +28 -21
- package/dist/components/input/Textarea.mjs.map +1 -1
- package/dist/components/input/TimePicker.cjs +1 -1
- package/dist/components/input/TimePicker.cjs.map +1 -1
- package/dist/components/input/TimePicker.mjs +189 -184
- package/dist/components/input/TimePicker.mjs.map +1 -1
- package/dist/components/input/fieldLabel.cjs +2 -0
- package/dist/components/input/fieldLabel.cjs.map +1 -0
- package/dist/components/input/fieldLabel.mjs +17 -0
- package/dist/components/input/fieldLabel.mjs.map +1 -0
- package/dist/components/input/inputLook.cjs +2 -0
- package/dist/components/input/inputLook.cjs.map +1 -0
- package/dist/components/input/inputLook.mjs +28 -0
- package/dist/components/input/inputLook.mjs.map +1 -0
- package/dist/components/input/pickerStyles.cjs +1 -1
- package/dist/components/input/pickerStyles.cjs.map +1 -1
- package/dist/components/input/pickerStyles.mjs +42 -4
- package/dist/components/input/pickerStyles.mjs.map +1 -1
- package/dist/components/navigation/Menu.popover.cjs +1 -1
- package/dist/components/navigation/Menu.popover.cjs.map +1 -1
- package/dist/components/navigation/Menu.popover.mjs +10 -10
- package/dist/components/navigation/Menu.root.cjs +1 -1
- package/dist/components/navigation/Menu.root.cjs.map +1 -1
- package/dist/components/navigation/Menu.root.mjs +10 -10
- package/dist/components/overlays/Popover.cjs +1 -1
- package/dist/components/overlays/Popover.cjs.map +1 -1
- package/dist/components/overlays/Popover.mjs +203 -208
- package/dist/components/overlays/Popover.mjs.map +1 -1
- package/dist/components/overlays/Popover.shared.cjs +1 -1
- package/dist/components/overlays/Popover.shared.cjs.map +1 -1
- package/dist/components/overlays/Popover.shared.mjs +82 -77
- package/dist/components/overlays/Popover.shared.mjs.map +1 -1
- package/dist/components/provider/WaveProvider.cjs +1 -1
- package/dist/components/provider/WaveProvider.cjs.map +1 -1
- package/dist/components/provider/WaveProvider.mjs +25 -19
- package/dist/components/provider/WaveProvider.mjs.map +1 -1
- package/dist/hooks/useFieldControl.cjs.map +1 -1
- package/dist/hooks/useFieldControl.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +805 -99
- package/dist/index.d.ts +805 -99
- package/dist/index.mjs +101 -99
- package/dist/lib/classNames.cjs +1 -1
- package/dist/lib/classNames.cjs.map +1 -1
- package/dist/lib/classNames.mjs +74 -66
- package/dist/lib/classNames.mjs.map +1 -1
- package/dist/lib/styles.cjs +1 -1
- package/dist/lib/styles.cjs.map +1 -1
- package/dist/lib/styles.mjs +21 -4
- package/dist/lib/styles.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/styles/tokens.css +13 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/slot.cjs"),ee=require("../../lib/composeEventHandlers.cjs"),i=require("../../lib/classNames.cjs"),te=require("../../hooks/useControllable.cjs"),a=require("../../hooks/useId.cjs"),ne=require("../../hooks/useMergedRefs.cjs"),o=require("../../lib/aria.cjs"),s=require("../../hooks/useFieldControl.cjs"),c=require("../../lib/styles.cjs"),l=require("../../lib/icons.cjs"),
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/slot.cjs"),ee=require("../../lib/composeEventHandlers.cjs"),i=require("../../lib/classNames.cjs"),te=require("../../hooks/useControllable.cjs"),a=require("../../hooks/useId.cjs"),ne=require("../../hooks/useMergedRefs.cjs"),o=require("../../lib/aria.cjs"),s=require("../../hooks/useFieldControl.cjs"),c=require("../../lib/styles.cjs"),l=require("../../lib/icons.cjs"),re=require("../../hooks/useFormReset.cjs"),ie=require("../internal/HiddenInput.cjs");let u=require("react");u=e.__toESM(u,1);let d=require("react/jsx-runtime");var ae=`forced-colors:border-[Highlight] forced-colors:bg-[Highlight]`,oe=`forced-colors:border-[GrayText] forced-colors:bg-[Canvas]`,f=`forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none`,p={medium:{box:`h-[18px] w-[18px]`,glyph:12,offset:`mt-px`},large:{box:`h-[22px] w-[22px]`,glyph:16,offset:`-mt-px`}},m={square:`rounded-xs`,circular:`rounded-full`},h=({checked:e,defaultChecked:h=!1,indeterminate:g=!1,onCheckedChange:se,onChange:_,disabled:v=!1,disabledFocusable:y=!1,label:b,labelPosition:x=`after`,size:S=`medium`,shape:C=`square`,name:ce,value:le,required:w,form:T,id:ue,"aria-label":de,"aria-labelledby":fe,"aria-describedby":pe,"aria-invalid":me,"aria-required":E,"aria-errormessage":D,"aria-details":O,"aria-disabled":k,autoFocus:A,tabIndex:j,onClick:M,onFocus:N,onBlur:P,onKeyDown:F,onKeyUp:I,controlRef:L,className:R,children:z,ref:he,...ge})=>{_!==void 0&&n.warnDeprecated(`Checkbox`,`onChange`,`onCheckedChange`);let B=r.slotRendersContent(z);u.useEffect(()=>{B&&n.warnOnce(`Checkbox:children`,"Checkbox: children are not rendered. Pass the label in `label`.")},[B]);let[V,H]=te.useControllable(e,h,e=>{se?.(e),_?.(e)}),_e=a.useId(`checkbox`),U=a.useId(`checkbox-label`),W=s.useFieldContext(),G=s.useFieldControl({id:ue,"aria-label":de,"aria-labelledby":fe,"aria-describedby":pe,"aria-invalid":me,"aria-required":E??w}),ve=w??W?.required??!1,K=r.slotRendersContent(b),ye=K&&G[`aria-label`]===void 0?o.joinIds(G[`aria-labelledby`],W&&G.id===W.controlId?W.labelId:void 0,U):G[`aria-labelledby`],q=u.useRef(null),be=ne.useMergedRefs(q,L);re.useFormReset(q,()=>H(h),T);let xe=V||g,J=Object.hasOwn(p,S)?S:`medium`,Y=Object.hasOwn(m,C)?C:`square`,X=p[J],Se=m[Y],Z=v||y,Q=Z?f:c.forcedColors.selectedLeaf,$=K?(0,d.jsx)(`span`,{id:U,className:t.cn(i.checkboxClassNames.label,`text-body-1 text-foreground`),children:r.materialiseSlotContent(b)}):null;return(0,d.jsxs)(`label`,{ref:he,"data-label-position":x,"data-size":J,"data-shape":Y,className:t.cn(i.checkboxClassNames.root,`relative inline-flex items-start gap-2 select-none`,Z?`cursor-not-allowed opacity-50 has-focus-visible:opacity-100`:`cursor-pointer`,R),...ge,children:[x===`before`&&$,(0,d.jsx)(`button`,{id:_e,type:`button`,...G,"aria-labelledby":ye,"aria-errormessage":D,"aria-details":O,"aria-disabled":k,autoFocus:A,tabIndex:j,onFocus:N,onBlur:P,onKeyDown:F,onKeyUp:I,ref:be,role:`checkbox`,"aria-checked":g?`mixed`:V,disabled:v&&!y,...o.focusableDisabledProps(y,{reachable:!0}),onClick:y?e=>{e.preventDefault(),e.stopPropagation()}:ee.composeEventHandlers(M,()=>H(e=>!e)),className:t.cn(i.checkboxClassNames.indicator,t.cn(`flex shrink-0 items-center justify-center border p-0 transition-colors motion-reduce:transition-none`,X.box,Se),K&&X.offset,c.focusRing,xe?t.cn(`border-primary bg-primary text-primary-foreground`,Z?oe:ae):t.cn(`border-stroke-accessible bg-transparent`,Z?c.forcedColors.disabled:c.forcedColors.control)),children:g?(0,d.jsx)(l.SubtractIcon,{size:X.glyph,className:Q}):V?(0,d.jsx)(l.CheckIcon,{size:X.glyph,className:Q}):null}),x!==`before`&&$,(0,d.jsx)(ie.HiddenInput,{type:`checkbox`,name:ce,form:T,disabled:Z,value:le,checked:V,required:ve,onInvalid:()=>q.current?.focus()})]})};h.displayName=`Checkbox`,exports.Checkbox=h;
|
|
2
2
|
//# sourceMappingURL=Checkbox.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.cjs","names":["slotRendersContent","useControllable","useId","useFieldContext","useFieldControl","joinIds","React","useMergedRefs","forcedColors","cn","checkboxClassNames","materialiseSlotContent","focusableDisabledProps","composeEventHandlers","focusRing","SubtractIcon","CheckIcon","HiddenInput","require_runtime","require_cn","require_dev","require_slot","require_composeEventHandlers","require_classNames","require_useControllable","require_useId","require_useMergedRefs","require_aria","require_useFieldControl","require_styles","require_icons","require_useFormReset","require_HiddenInput","react","react_jsx_runtime","checkedBox","disabledCheckedBox","disabledGlyph","Checkbox","checkedProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","ariaErrorMessage","ariaDetails","ariaDisabled","rest","onChange","hasChildren","children","checked","setChecked","defaultChecked","onCheckedChange","next","generatedId","labelTextId","field","fieldProps","required","isRequired","hasLabel","label","labelledBy","buttonRef","mergedControlRef","controlRef","form","on","indeterminate","unavailable","disabled","disabledFocusable","glyphClassName","labelText","labelPosition","className","event","onClick","prev"],"sources":["../../../src/components/input/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { focusableDisabledProps, joinIds } from '../../lib/aria';\nimport { checkboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnDeprecated, warnOnce } from '../../lib/dev';\nimport { CheckIcon, SubtractIcon } from '../../lib/icons';\nimport { materialiseSlotContent, slotRendersContent } from '../../lib/slot';\nimport { focusRing, forcedColors } from '../../lib/styles';\nimport type { LabelPosition } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useId } from '../../hooks/useId';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\n\n/*\n * Forced colors: the focusable box keeps system-color utilities, so the browser still forces its\n * focus outline and border; only the glyph (the leaf indicator) opts out of forced colors. A\n * disabled box draws a GrayText glyph and border on Canvas, without the Highlight fill.\n */\nconst checkedBox = 'forced-colors:border-[Highlight] forced-colors:bg-[Highlight]';\nconst disabledCheckedBox = 'forced-colors:border-[GrayText] forced-colors:bg-[Canvas]';\nconst disabledGlyph = 'forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none';\n\n/** Handlers that run on the `role=\"checkbox\"` button instead of the root label (C-ROUTING). */\ntype CheckboxControlHandlers = 'onClick' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp';\n\n/** Where a Checkbox renders its label: after the box (default) or before it. */\nexport type CheckboxLabelPosition = Extract<LabelPosition, 'before' | 'after'>;\n\n/** Properties for the Checkbox component. */\nexport interface CheckboxProps extends Omit<\n React.HTMLAttributes<HTMLLabelElement>,\n 'onChange' | 'defaultChecked' | CheckboxControlHandlers\n> {\n /** Controlled checked state. */\n checked?: boolean;\n /** Initial checked state for uncontrolled usage (also the value a form reset restores).\n * @default false\n */\n defaultChecked?: boolean;\n /**\n * Shows the mixed state: the dash glyph and `aria-checked=\"mixed\"`, whatever `checked` is. A\n * click still toggles `checked` and calls `onCheckedChange`, but the checkbox keeps showing and\n * announcing \"mixed\" until you clear `indeterminate`. For a tri-state \"select all\", derive\n * `checked` and `indeterminate` from the items and set every item in `onCheckedChange`.\n * @default false\n */\n indeterminate?: boolean;\n /** Called with the new checked state when it changes (not for no-op updates). */\n onCheckedChange?: (checked: boolean) => void;\n /**\n * Called with the new checked state when it changes.\n * @deprecated Use `onCheckedChange`.\n */\n onChange?: (checked: boolean) => void;\n /** Whether the checkbox is disabled and non-interactive. */\n disabled?: boolean;\n /**\n * Marks the checkbox unavailable but keeps it focusable and in the tab order: for a disabled\n * checkbox that needs a Tooltip, or one in a toolbar. Renders `aria-disabled=\"true\"`,\n * `data-disabled` and `data-disabled-focusable` on the checkbox instead of the native `disabled`\n * attribute. The checkbox cannot be toggled and is not submitted with its form; your `onClick`\n * is not called, and a click on the checkbox (or Space and Enter) does not reach ancestor click\n * handlers, as for a natively disabled control. Wins over `disabled` when both are set. In a\n * roving container (a `Toolbar`) it stays in the arrow-key order.\n * @default false\n */\n disabledFocusable?: boolean;\n /**\n * Label next to the control (any phrasing content, links included, but no other form\n * controls). It names the control through `aria-labelledby`, after a consumer or Field\n * `aria-labelledby`; a consumer `aria-label` names it instead. Clicking its text toggles the\n * control; clicking a link inside it follows the link. `children` are not rendered: pass the\n * label here.\n */\n label?: React.ReactNode;\n /**\n * Where the label renders: after the control (default) or before it. The DOM order follows the\n * visual order.\n * @default 'after'\n */\n labelPosition?: CheckboxLabelPosition;\n /**\n * Form field name. With a name, the checkbox takes part in native form submission: it submits\n * `name=value` while checked.\n */\n name?: string;\n /** Value submitted while checked.\n * @default 'on'\n */\n value?: string;\n /** The form must not be submitted while the checkbox is unchecked (native validation). */\n required?: boolean;\n /** Id of the form the checkbox belongs to, when it is rendered outside that form. */\n form?: string;\n /** Click handler of the checkbox control (the `role=\"checkbox\"` button). */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** Focus handler of the checkbox control. */\n onFocus?: React.FocusEventHandler<HTMLButtonElement>;\n /** Blur handler of the checkbox control. */\n onBlur?: React.FocusEventHandler<HTMLButtonElement>;\n /** Keydown handler of the checkbox control. */\n onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Keyup handler of the checkbox control. */\n onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Ref to the focusable `role=\"checkbox\"` button. */\n controlRef?: React.Ref<HTMLButtonElement>;\n /** Ref to the root `<label>` element. */\n ref?: React.Ref<HTMLLabelElement>;\n}\n\n/**\n * A checkbox for a boolean (or mixed) choice, drawn as a `role=\"checkbox\"` button inside a\n * `<label>`.\n *\n * - The root `<label>` receives `ref`, `className`, `style` and `data-*`; the control receives\n * `id`, `aria-label`/`-labelledby`/`-describedby`/`-invalid`/`-required`/`-errormessage`/\n * `-details`/`-disabled`, `tabIndex`, `autoFocus` and the click, focus and key handlers\n * (`controlRef` exposes it). A consumer `onClick` runs once per activation, before the toggle;\n * `preventDefault()` in it cancels the toggle.\n * - Inside a `Field` it is named by the Field label (followed by its own `label` text) and described\n * by the Field message and hint.\n * - With `name` (or `required`) it takes part in native forms like `<input type=\"checkbox\">`, and\n * a form reset restores `defaultChecked`.\n * - `label` takes rich content (a link to the terms) and renders after the box, or before it with\n * `labelPosition=\"before\"` (the root carries `data-label-position`). The box lines up with the\n * first line of a label that wraps or has a second line. `children` are not rendered (a\n * development warning says so).\n */\nexport const Checkbox = ({\n checked: checkedProp,\n defaultChecked = false,\n indeterminate = false,\n onCheckedChange,\n onChange,\n disabled = false,\n disabledFocusable = false,\n label,\n labelPosition = 'after',\n name,\n value,\n required,\n form,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n 'aria-errormessage': ariaErrorMessage,\n 'aria-details': ariaDetails,\n 'aria-disabled': ariaDisabled,\n autoFocus,\n tabIndex,\n onClick,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n controlRef,\n className,\n children,\n ref,\n ...rest\n}: CheckboxProps) => {\n if (onChange !== undefined) warnDeprecated('Checkbox', 'onChange', 'onCheckedChange');\n const hasChildren = slotRendersContent(children);\n React.useEffect(() => {\n if (hasChildren) {\n warnOnce(\n 'Checkbox:children',\n 'Checkbox: children are not rendered. Pass the label in `label`.',\n );\n }\n }, [hasChildren]);\n const [checked, setChecked] = useControllable(checkedProp, defaultChecked, (next: boolean) => {\n onCheckedChange?.(next);\n onChange?.(next);\n });\n\n const generatedId = useId('checkbox');\n const labelTextId = useId('checkbox-label');\n const field = useFieldContext();\n const fieldProps = useFieldControl({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n // An explicit `required={false}` wins over a required Field, so aria-required always matches\n // the native validation below (`isRequired`).\n 'aria-required': ariaRequired ?? required,\n });\n const isRequired = required ?? field?.required ?? false;\n // `0` is a label; `null`, `false`, `''` and empty collections are not (C-SLOTS).\n const hasLabel = slotRendersContent(label);\n // The label text names the control through aria-labelledby, disabled or not: axe exempts the\n // dimmed text of a disabled control only when the control references it this way (its <label>\n // exemption covers native inputs only). A consumer aria-label still names the control alone.\n // The ids already there (the consumer's, the Field label from useFieldControl) come first, then\n // the Field label whose <label htmlFor> targets this control (aria-labelledby would hide it), so\n // the name keeps every label.\n const labelledBy =\n hasLabel && fieldProps['aria-label'] === undefined\n ? joinIds(\n fieldProps['aria-labelledby'],\n field && fieldProps.id === field.controlId ? field.labelId : undefined,\n labelTextId,\n )\n : fieldProps['aria-labelledby'];\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const mergedControlRef = useMergedRefs(buttonRef, controlRef);\n useFormReset(buttonRef, () => setChecked(defaultChecked), form);\n\n const on = checked || indeterminate;\n // Focusable-disabled wins over `disabled`: the box stays focusable but looks and acts disabled.\n const unavailable = disabled || disabledFocusable;\n // The glyph is the forced-colors leaf; the box stays on system colors (see `checkedBox`).\n const glyphClassName = unavailable ? disabledGlyph : forcedColors.selectedLeaf;\n const labelText = hasLabel ? (\n <span id={labelTextId} className={cn(checkboxClassNames.label, 'text-body-1 text-foreground')}>\n {materialiseSlotContent(label)}\n </span>\n ) : null;\n\n return (\n <label\n ref={ref}\n data-label-position={labelPosition}\n className={cn(\n checkboxClassNames.root,\n // items-start: the box lines up with the first line of a label that wraps or has a second\n // line, not with its middle.\n 'relative inline-flex items-start gap-2 select-none',\n // The dimmed look lifts while a focus ring shows inside the root (the control's, under\n // disabledFocusable, or a link's in the label): opacity would dim the ring below 3:1.\n unavailable\n ? 'cursor-not-allowed opacity-50 has-focus-visible:opacity-100'\n : 'cursor-pointer',\n className,\n )}\n {...rest}\n >\n {labelPosition === 'before' && labelText}\n <button\n id={generatedId}\n type=\"button\"\n {...fieldProps}\n aria-labelledby={labelledBy}\n aria-errormessage={ariaErrorMessage}\n aria-details={ariaDetails}\n aria-disabled={ariaDisabled}\n autoFocus={autoFocus}\n tabIndex={tabIndex}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n ref={mergedControlRef}\n role=\"checkbox\"\n aria-checked={indeterminate ? 'mixed' : checked}\n disabled={disabled && !disabledFocusable}\n {...focusableDisabledProps(disabledFocusable, { reachable: true })}\n onClick={\n disabledFocusable\n ? // Clicks, Space and Enter (which click a button) neither toggle nor reach `onClick`,\n // and, as a natively disabled control dispatches no click, no ancestor sees them.\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n }\n : composeEventHandlers(onClick, () => setChecked((prev) => !prev))\n }\n className={cn(\n checkboxClassNames.indicator,\n // p-0 and the unchecked bg-transparent are set here, not left to the native reset, which\n // any app button style overrides (C-NATIVE).\n 'flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-xs border p-0 transition-colors motion-reduce:transition-none',\n // Centred on the 20px first line of the label text.\n hasLabel && 'mt-px',\n focusRing,\n on\n ? cn(\n 'border-primary bg-primary text-primary-foreground',\n unavailable ? disabledCheckedBox : checkedBox,\n )\n : cn(\n 'border-stroke-accessible bg-transparent',\n unavailable ? forcedColors.disabled : forcedColors.control,\n ),\n )}\n >\n {indeterminate ? (\n <SubtractIcon size={12} className={glyphClassName} />\n ) : checked ? (\n <CheckIcon size={12} className={glyphClassName} />\n ) : null}\n </button>\n {labelPosition !== 'before' && labelText}\n <HiddenInput\n type=\"checkbox\"\n name={name}\n form={form}\n disabled={unavailable}\n value={value}\n checked={checked}\n required={isRequired}\n onInvalid={() => buttonRef.current?.focus()}\n />\n </label>\n );\n};\n\nCheckbox.displayName = 'Checkbox';\n"],"mappings":"qqBAsBA,IAAMmC,GAAa,gEACbC,GAAqB,4DACrBC,GAAgB,uEA4GTC,GAAY,CACvB,QAASC,EACT,iBAAiB,GACjB,gBAAgB,GAChB,kBACA,WACA,WAAW,GACX,oBAAoB,GACpB,QACA,gBAAgB,QAChB,QACA,SACA,WACA,OACA,MACA,aAAcC,EACd,kBAAmBC,EACnB,mBAAoBC,EACpB,eAAgBC,EAChB,gBAAiBC,EACjB,oBAAqBC,EACrB,eAAgBC,EAChB,gBAAiBC,EACjB,YACA,WACA,UACA,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SAAUV,EACV,cAAiBI,EAAU,SAAS,MAAM,CAC3C,CAAA,CACI,GAEX,EAEA,EAAS,YAAc"}
|
|
1
|
+
{"version":3,"file":"Checkbox.cjs","names":["slotRendersContent","useControllable","useId","useFieldContext","useFieldControl","joinIds","React","useMergedRefs","forcedColors","cn","checkboxClassNames","materialiseSlotContent","focusableDisabledProps","composeEventHandlers","focusRing","SubtractIcon","CheckIcon","HiddenInput","require_runtime","require_cn","require_dev","require_slot","require_composeEventHandlers","require_classNames","require_useControllable","require_useId","require_useMergedRefs","require_aria","require_useFieldControl","require_styles","require_icons","require_useFormReset","require_HiddenInput","react","react_jsx_runtime","checkedBox","disabledCheckedBox","disabledGlyph","CHECKBOX_SIZE","CHECKBOX_SHAPE","Checkbox","checkedProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","ariaErrorMessage","ariaDetails","ariaDisabled","rest","onChange","hasChildren","children","checked","setChecked","defaultChecked","onCheckedChange","next","generatedId","labelTextId","field","fieldProps","required","isRequired","hasLabel","label","labelledBy","buttonRef","mergedControlRef","controlRef","form","on","indeterminate","resolvedSize","size","resolvedShape","shape","sizeMetrics","shapeClass","unavailable","disabled","disabledFocusable","glyphClassName","labelText","labelPosition","className","event","onClick","prev"],"sources":["../../../src/components/input/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { focusableDisabledProps, joinIds } from '../../lib/aria';\nimport { checkboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnDeprecated, warnOnce } from '../../lib/dev';\nimport { CheckIcon, SubtractIcon } from '../../lib/icons';\nimport { materialiseSlotContent, slotRendersContent } from '../../lib/slot';\nimport { focusRing, forcedColors } from '../../lib/styles';\nimport type { LabelPosition, Shape, Size } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useId } from '../../hooks/useId';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\n\n/*\n * Forced colors: the focusable box keeps system-color utilities, so the browser still forces its\n * focus outline and border; only the glyph (the leaf indicator) opts out of forced colors. A\n * disabled box draws a GrayText glyph and border on Canvas, without the Highlight fill.\n */\nconst checkedBox = 'forced-colors:border-[Highlight] forced-colors:bg-[Highlight]';\nconst disabledCheckedBox = 'forced-colors:border-[GrayText] forced-colors:bg-[Canvas]';\nconst disabledGlyph = 'forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none';\n\n/** Handlers that run on the `role=\"checkbox\"` button instead of the root label (C-ROUTING). */\ntype CheckboxControlHandlers = 'onClick' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp';\n\n/** Where a Checkbox renders its label: after the box (default) or before it. */\nexport type CheckboxLabelPosition = Extract<LabelPosition, 'before' | 'after'>;\n\n/** Size of the box: an 18px box (the 0.7 look) or a 22px box with a bigger glyph. */\nexport type CheckboxSize = Extract<Size, 'medium' | 'large'>;\n\n/** Shape of the box: square corners (the 0.7 look) or a circular, round box. */\nexport type CheckboxShape = Extract<Shape, 'square' | 'circular'>;\n\n/** Per-size box, glyph and label-offset classes. */\nconst CHECKBOX_SIZE: Readonly<\n Record<CheckboxSize, { box: string; glyph: number; offset: string }>\n> = {\n medium: { box: 'h-[18px] w-[18px]', glyph: 12, offset: 'mt-px' },\n large: { box: 'h-[22px] w-[22px]', glyph: 16, offset: '-mt-px' },\n};\n\n/** Per-shape corner classes. */\nconst CHECKBOX_SHAPE: Readonly<Record<CheckboxShape, string>> = {\n square: 'rounded-xs',\n circular: 'rounded-full',\n};\n\n/** Properties for the Checkbox component. */\nexport interface CheckboxProps extends Omit<\n React.HTMLAttributes<HTMLLabelElement>,\n 'onChange' | 'defaultChecked' | CheckboxControlHandlers\n> {\n /** Controlled checked state. */\n checked?: boolean;\n /** Initial checked state for uncontrolled usage (also the value a form reset restores).\n * @default false\n */\n defaultChecked?: boolean;\n /**\n * Shows the mixed state: the dash glyph and `aria-checked=\"mixed\"`, whatever `checked` is. A\n * click still toggles `checked` and calls `onCheckedChange`, but the checkbox keeps showing and\n * announcing \"mixed\" until you clear `indeterminate`. For a tri-state \"select all\", derive\n * `checked` and `indeterminate` from the items and set every item in `onCheckedChange`.\n * @default false\n */\n indeterminate?: boolean;\n /** Called with the new checked state when it changes (not for no-op updates). */\n onCheckedChange?: (checked: boolean) => void;\n /**\n * Called with the new checked state when it changes.\n * @deprecated Use `onCheckedChange`.\n */\n onChange?: (checked: boolean) => void;\n /** Whether the checkbox is disabled and non-interactive. */\n disabled?: boolean;\n /**\n * Marks the checkbox unavailable but keeps it focusable and in the tab order: for a disabled\n * checkbox that needs a Tooltip, or one in a toolbar. Renders `aria-disabled=\"true\"`,\n * `data-disabled` and `data-disabled-focusable` on the checkbox instead of the native `disabled`\n * attribute. The checkbox cannot be toggled and is not submitted with its form; your `onClick`\n * is not called, and a click on the checkbox (or Space and Enter) does not reach ancestor click\n * handlers, as for a natively disabled control. Wins over `disabled` when both are set. In a\n * roving container (a `Toolbar`) it stays in the arrow-key order.\n * @default false\n */\n disabledFocusable?: boolean;\n /**\n * Label next to the control (any phrasing content, links included, but no other form\n * controls). It names the control through `aria-labelledby`, after a consumer or Field\n * `aria-labelledby`; a consumer `aria-label` names it instead. Clicking its text toggles the\n * control; clicking a link inside it follows the link. `children` are not rendered: pass the\n * label here.\n */\n label?: React.ReactNode;\n /**\n * Where the label renders: after the control (default) or before it. The DOM order follows the\n * visual order.\n * @default 'after'\n */\n labelPosition?: CheckboxLabelPosition;\n /**\n * Size of the box: an 18px box (the 0.7 look) or a 22px box with a bigger glyph. Unlike the\n * text controls and pickers, Checkbox does not read a surrounding Field's size or a\n * WaveProvider's input defaults: this prop is the only source of its size.\n * @default 'medium'\n */\n size?: CheckboxSize;\n /**\n * Shape of the box: square corners (the 0.7 look) or a circular, round box.\n * @default 'square'\n */\n shape?: CheckboxShape;\n /**\n * Form field name. With a name, the checkbox takes part in native form submission: it submits\n * `name=value` while checked.\n */\n name?: string;\n /** Value submitted while checked.\n * @default 'on'\n */\n value?: string;\n /** The form must not be submitted while the checkbox is unchecked (native validation). */\n required?: boolean;\n /** Id of the form the checkbox belongs to, when it is rendered outside that form. */\n form?: string;\n /** Click handler of the checkbox control (the `role=\"checkbox\"` button). */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** Focus handler of the checkbox control. */\n onFocus?: React.FocusEventHandler<HTMLButtonElement>;\n /** Blur handler of the checkbox control. */\n onBlur?: React.FocusEventHandler<HTMLButtonElement>;\n /** Keydown handler of the checkbox control. */\n onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Keyup handler of the checkbox control. */\n onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Ref to the focusable `role=\"checkbox\"` button. */\n controlRef?: React.Ref<HTMLButtonElement>;\n /** Ref to the root `<label>` element. */\n ref?: React.Ref<HTMLLabelElement>;\n}\n\n/**\n * A checkbox for a boolean (or mixed) choice, drawn as a `role=\"checkbox\"` button inside a\n * `<label>`.\n *\n * - The root `<label>` receives `ref`, `className`, `style` and `data-*`; the control receives\n * `id`, `aria-label`/`-labelledby`/`-describedby`/`-invalid`/`-required`/`-errormessage`/\n * `-details`/`-disabled`, `tabIndex`, `autoFocus` and the click, focus and key handlers\n * (`controlRef` exposes it). A consumer `onClick` runs once per activation, before the toggle;\n * `preventDefault()` in it cancels the toggle.\n * - Inside a `Field` it is named by the Field label (followed by its own `label` text) and described\n * by the Field message and hint.\n * - With `name` (or `required`) it takes part in native forms like `<input type=\"checkbox\">`, and\n * a form reset restores `defaultChecked`.\n * - `label` takes rich content (a link to the terms) and renders after the box, or before it with\n * `labelPosition=\"before\"` (the root carries `data-label-position`). The box lines up with the\n * first line of a label that wraps or has a second line. `children` are not rendered (a\n * development warning says so).\n * - `size` (`medium`, `large`) and `shape` (`square`, `circular`) set the box's dimensions and\n * corners; the root carries `data-size` and `data-shape`. Checkbox does not read a surrounding\n * `Field`'s size or a `WaveProvider`'s input defaults.\n */\nexport const Checkbox = ({\n checked: checkedProp,\n defaultChecked = false,\n indeterminate = false,\n onCheckedChange,\n onChange,\n disabled = false,\n disabledFocusable = false,\n label,\n labelPosition = 'after',\n size = 'medium',\n shape = 'square',\n name,\n value,\n required,\n form,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n 'aria-errormessage': ariaErrorMessage,\n 'aria-details': ariaDetails,\n 'aria-disabled': ariaDisabled,\n autoFocus,\n tabIndex,\n onClick,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n controlRef,\n className,\n children,\n ref,\n ...rest\n}: CheckboxProps) => {\n if (onChange !== undefined) warnDeprecated('Checkbox', 'onChange', 'onCheckedChange');\n const hasChildren = slotRendersContent(children);\n React.useEffect(() => {\n if (hasChildren) {\n warnOnce(\n 'Checkbox:children',\n 'Checkbox: children are not rendered. Pass the label in `label`.',\n );\n }\n }, [hasChildren]);\n const [checked, setChecked] = useControllable(checkedProp, defaultChecked, (next: boolean) => {\n onCheckedChange?.(next);\n onChange?.(next);\n });\n\n const generatedId = useId('checkbox');\n const labelTextId = useId('checkbox-label');\n const field = useFieldContext();\n const fieldProps = useFieldControl({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n // An explicit `required={false}` wins over a required Field, so aria-required always matches\n // the native validation below (`isRequired`).\n 'aria-required': ariaRequired ?? required,\n });\n const isRequired = required ?? field?.required ?? false;\n // `0` is a label; `null`, `false`, `''` and empty collections are not (C-SLOTS).\n const hasLabel = slotRendersContent(label);\n // The label text names the control through aria-labelledby, disabled or not: axe exempts the\n // dimmed text of a disabled control only when the control references it this way (its <label>\n // exemption covers native inputs only). A consumer aria-label still names the control alone.\n // The ids already there (the consumer's, the Field label from useFieldControl) come first, then\n // the Field label whose <label htmlFor> targets this control (aria-labelledby would hide it), so\n // the name keeps every label.\n const labelledBy =\n hasLabel && fieldProps['aria-label'] === undefined\n ? joinIds(\n fieldProps['aria-labelledby'],\n field && fieldProps.id === field.controlId ? field.labelId : undefined,\n labelTextId,\n )\n : fieldProps['aria-labelledby'];\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const mergedControlRef = useMergedRefs(buttonRef, controlRef);\n useFormReset(buttonRef, () => setChecked(defaultChecked), form);\n\n const on = checked || indeterminate;\n // A size or shape outside the unions (from untyped code) renders, and is reported in the data\n // attributes, as the default: TypeScript rejects one, but the value still reaches this render.\n const resolvedSize: CheckboxSize = Object.hasOwn(CHECKBOX_SIZE, size) ? size : 'medium';\n const resolvedShape: CheckboxShape = Object.hasOwn(CHECKBOX_SHAPE, shape) ? shape : 'square';\n const sizeMetrics = CHECKBOX_SIZE[resolvedSize];\n const shapeClass = CHECKBOX_SHAPE[resolvedShape];\n // Focusable-disabled wins over `disabled`: the box stays focusable but looks and acts disabled.\n const unavailable = disabled || disabledFocusable;\n // The glyph is the forced-colors leaf; the box stays on system colors (see `checkedBox`).\n const glyphClassName = unavailable ? disabledGlyph : forcedColors.selectedLeaf;\n const labelText = hasLabel ? (\n <span id={labelTextId} className={cn(checkboxClassNames.label, 'text-body-1 text-foreground')}>\n {materialiseSlotContent(label)}\n </span>\n ) : null;\n\n return (\n <label\n ref={ref}\n data-label-position={labelPosition}\n data-size={resolvedSize}\n data-shape={resolvedShape}\n className={cn(\n checkboxClassNames.root,\n // items-start: the box lines up with the first line of a label that wraps or has a second\n // line, not with its middle.\n 'relative inline-flex items-start gap-2 select-none',\n // The dimmed look lifts while a focus ring shows inside the root (the control's, under\n // disabledFocusable, or a link's in the label): opacity would dim the ring below 3:1.\n unavailable\n ? 'cursor-not-allowed opacity-50 has-focus-visible:opacity-100'\n : 'cursor-pointer',\n className,\n )}\n {...rest}\n >\n {labelPosition === 'before' && labelText}\n <button\n id={generatedId}\n type=\"button\"\n {...fieldProps}\n aria-labelledby={labelledBy}\n aria-errormessage={ariaErrorMessage}\n aria-details={ariaDetails}\n aria-disabled={ariaDisabled}\n autoFocus={autoFocus}\n tabIndex={tabIndex}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n ref={mergedControlRef}\n role=\"checkbox\"\n aria-checked={indeterminate ? 'mixed' : checked}\n disabled={disabled && !disabledFocusable}\n {...focusableDisabledProps(disabledFocusable, { reachable: true })}\n onClick={\n disabledFocusable\n ? // Clicks, Space and Enter (which click a button) neither toggle nor reach `onClick`,\n // and, as a natively disabled control dispatches no click, no ancestor sees them.\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n }\n : composeEventHandlers(onClick, () => setChecked((prev) => !prev))\n }\n className={cn(\n checkboxClassNames.indicator,\n // p-0 and the unchecked bg-transparent are set here, not left to the native reset, which\n // any app button style overrides (C-NATIVE).\n cn(\n 'flex shrink-0 items-center justify-center border p-0 transition-colors motion-reduce:transition-none',\n sizeMetrics.box,\n shapeClass,\n ),\n // Centred on the label's 20px first line: nudged down at medium, up at large.\n hasLabel && sizeMetrics.offset,\n focusRing,\n on\n ? cn(\n 'border-primary bg-primary text-primary-foreground',\n unavailable ? disabledCheckedBox : checkedBox,\n )\n : cn(\n 'border-stroke-accessible bg-transparent',\n unavailable ? forcedColors.disabled : forcedColors.control,\n ),\n )}\n >\n {indeterminate ? (\n <SubtractIcon size={sizeMetrics.glyph} className={glyphClassName} />\n ) : checked ? (\n <CheckIcon size={sizeMetrics.glyph} className={glyphClassName} />\n ) : null}\n </button>\n {labelPosition !== 'before' && labelText}\n <HiddenInput\n type=\"checkbox\"\n name={name}\n form={form}\n disabled={unavailable}\n value={value}\n checked={checked}\n required={isRequired}\n onInvalid={() => buttonRef.current?.focus()}\n />\n </label>\n );\n};\n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U2B,GAAY,CAACC,EACvB,GAAItE,EAAAA,uBAAuBsE,EAAmB,CAAE,UAAW,EAAK,CAAC,EACjE,QACEA,EAGK,GAA+C,CAC9CK,EAAM,eAAe,EACrBA,EAAM,gBAAgB,CACxB,EACA1E,GAAAA,qBAAqB2E,MAAejC,EAAY,GAAS,CAACkC,CAAI,CAAC,EAErE,UAAWhF,EAAAA,GACTC,EAAAA,mBAAmB,UAGnBD,EAAAA,GACE,uGACAqE,EAAY,IACZC,EACF,EAEAd,GAAYa,EAAY,OACxBhE,EAAAA,UACA0D,GACI/D,EAAAA,GACE,oDACAuE,EAAc5C,GAAqBD,EACrC,EACA1B,EAAAA,GACE,0CACAuE,EAAcxE,EAAAA,aAAa,SAAWA,EAAAA,aAAa,OACrD,CACN,EAEC,SAAAiE,GACC,EAAAvC,EAAA,IAAA,CAACnB,EAAAA,aAAD,CAAc,KAAM+D,EAAY,MAAO,UAAWK,CAAiB,CAAA,EACjE7B,GACF,EAAApB,EAAA,IAAA,CAAClB,EAAAA,UAAD,CAAW,KAAM8D,EAAY,MAAO,UAAWK,CAAiB,CAAA,EAC9D,IACE,CAAA,EACPE,IAAkB,UAAYD,GAC/B,EAAAlD,EAAA,IAAA,CAACjB,GAAAA,YAAD,CACE,KAAK,WACC,QACA,OACN,SAAU+D,EACH,SACE,UACT,SAAUhB,GACV,cAAiBI,EAAU,SAAS,MAAM,CAC3C,CAAA,CACI,GAEX,EAEA,EAAS,YAAc"}
|
|
@@ -1,97 +1,113 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn as e } from "../../lib/cn.mjs";
|
|
3
3
|
import { warnDeprecated as t, warnOnce as ee } from "../../lib/dev.mjs";
|
|
4
|
-
import { materialiseSlotContent as
|
|
5
|
-
import { composeEventHandlers as
|
|
6
|
-
import { checkboxClassNames as
|
|
7
|
-
import { useControllable as
|
|
8
|
-
import { useId as
|
|
9
|
-
import { useMergedRefs as
|
|
10
|
-
import { focusableDisabledProps as
|
|
11
|
-
import { useFieldContext as
|
|
12
|
-
import { focusRing as
|
|
13
|
-
import { CheckIcon as
|
|
14
|
-
import { useFormReset as
|
|
15
|
-
import { HiddenInput as
|
|
16
|
-
import * as
|
|
17
|
-
import { jsx as
|
|
4
|
+
import { materialiseSlotContent as n, slotRendersContent as r } from "../../lib/slot.mjs";
|
|
5
|
+
import { composeEventHandlers as i } from "../../lib/composeEventHandlers.mjs";
|
|
6
|
+
import { checkboxClassNames as a } from "../../lib/classNames.mjs";
|
|
7
|
+
import { useControllable as te } from "../../hooks/useControllable.mjs";
|
|
8
|
+
import { useId as o } from "../../hooks/useId.mjs";
|
|
9
|
+
import { useMergedRefs as ne } from "../../hooks/useMergedRefs.mjs";
|
|
10
|
+
import { focusableDisabledProps as re, joinIds as ie } from "../../lib/aria.mjs";
|
|
11
|
+
import { useFieldContext as ae, useFieldControl as oe } from "../../hooks/useFieldControl.mjs";
|
|
12
|
+
import { focusRing as se, forcedColors as s } from "../../lib/styles.mjs";
|
|
13
|
+
import { CheckIcon as ce, SubtractIcon as le } from "../../lib/icons.mjs";
|
|
14
|
+
import { useFormReset as c } from "../../hooks/useFormReset.mjs";
|
|
15
|
+
import { HiddenInput as l } from "../internal/HiddenInput.mjs";
|
|
16
|
+
import * as u from "react";
|
|
17
|
+
import { jsx as d, jsxs as ue } from "react/jsx-runtime";
|
|
18
18
|
//#region src/components/input/Checkbox.tsx
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
var de = "forced-colors:border-[Highlight] forced-colors:bg-[Highlight]", fe = "forced-colors:border-[GrayText] forced-colors:bg-[Canvas]", pe = "forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none", f = {
|
|
20
|
+
medium: {
|
|
21
|
+
box: "h-[18px] w-[18px]",
|
|
22
|
+
glyph: 12,
|
|
23
|
+
offset: "mt-px"
|
|
24
|
+
},
|
|
25
|
+
large: {
|
|
26
|
+
box: "h-[22px] w-[22px]",
|
|
27
|
+
glyph: 16,
|
|
28
|
+
offset: "-mt-px"
|
|
29
|
+
}
|
|
30
|
+
}, p = {
|
|
31
|
+
square: "rounded-xs",
|
|
32
|
+
circular: "rounded-full"
|
|
33
|
+
}, m = ({ checked: m, defaultChecked: h = !1, indeterminate: g = !1, onCheckedChange: me, onChange: _, disabled: v = !1, disabledFocusable: y = !1, label: b, labelPosition: x = "after", size: S = "medium", shape: C = "square", name: w, value: T, required: E, form: D, id: O, "aria-label": k, "aria-labelledby": A, "aria-describedby": j, "aria-invalid": M, "aria-required": N, "aria-errormessage": P, "aria-details": F, "aria-disabled": I, autoFocus: L, tabIndex: R, onClick: z, onFocus: he, onBlur: ge, onKeyDown: _e, onKeyUp: ve, controlRef: ye, className: be, children: xe, ref: Se, ...Ce }) => {
|
|
34
|
+
_ !== void 0 && t("Checkbox", "onChange", "onCheckedChange");
|
|
35
|
+
let B = r(xe);
|
|
36
|
+
u.useEffect(() => {
|
|
37
|
+
B && ee("Checkbox:children", "Checkbox: children are not rendered. Pass the label in `label`.");
|
|
38
|
+
}, [B]);
|
|
39
|
+
let [V, H] = te(m, h, (e) => {
|
|
40
|
+
me?.(e), _?.(e);
|
|
41
|
+
}), we = o("checkbox"), U = o("checkbox-label"), W = ae(), G = oe({
|
|
42
|
+
id: O,
|
|
43
|
+
"aria-label": k,
|
|
44
|
+
"aria-labelledby": A,
|
|
45
|
+
"aria-describedby": j,
|
|
46
|
+
"aria-invalid": M,
|
|
47
|
+
"aria-required": N ?? E
|
|
48
|
+
}), Te = E ?? W?.required ?? !1, K = r(b), Ee = K && G["aria-label"] === void 0 ? ie(G["aria-labelledby"], W && G.id === W.controlId ? W.labelId : void 0, U) : G["aria-labelledby"], q = u.useRef(null), De = ne(q, ye);
|
|
49
|
+
c(q, () => H(h), D);
|
|
50
|
+
let Oe = V || g, J = Object.hasOwn(f, S) ? S : "medium", Y = Object.hasOwn(p, C) ? C : "square", X = f[J], ke = p[Y], Z = v || y, Q = Z ? pe : s.selectedLeaf, $ = K ? /* @__PURE__ */ d("span", {
|
|
51
|
+
id: U,
|
|
52
|
+
className: e(a.label, "text-body-1 text-foreground"),
|
|
53
|
+
children: n(b)
|
|
40
54
|
}) : null;
|
|
41
|
-
return /* @__PURE__ */
|
|
42
|
-
ref:
|
|
43
|
-
"data-label-position":
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
return /* @__PURE__ */ ue("label", {
|
|
56
|
+
ref: Se,
|
|
57
|
+
"data-label-position": x,
|
|
58
|
+
"data-size": J,
|
|
59
|
+
"data-shape": Y,
|
|
60
|
+
className: e(a.root, "relative inline-flex items-start gap-2 select-none", Z ? "cursor-not-allowed opacity-50 has-focus-visible:opacity-100" : "cursor-pointer", be),
|
|
61
|
+
...Ce,
|
|
46
62
|
children: [
|
|
47
|
-
|
|
48
|
-
/* @__PURE__ */
|
|
49
|
-
id:
|
|
63
|
+
x === "before" && $,
|
|
64
|
+
/* @__PURE__ */ d("button", {
|
|
65
|
+
id: we,
|
|
50
66
|
type: "button",
|
|
51
|
-
...
|
|
52
|
-
"aria-labelledby":
|
|
53
|
-
"aria-errormessage":
|
|
54
|
-
"aria-details":
|
|
55
|
-
"aria-disabled":
|
|
56
|
-
autoFocus:
|
|
57
|
-
tabIndex:
|
|
58
|
-
onFocus:
|
|
59
|
-
onBlur:
|
|
60
|
-
onKeyDown:
|
|
61
|
-
onKeyUp:
|
|
62
|
-
ref:
|
|
67
|
+
...G,
|
|
68
|
+
"aria-labelledby": Ee,
|
|
69
|
+
"aria-errormessage": P,
|
|
70
|
+
"aria-details": F,
|
|
71
|
+
"aria-disabled": I,
|
|
72
|
+
autoFocus: L,
|
|
73
|
+
tabIndex: R,
|
|
74
|
+
onFocus: he,
|
|
75
|
+
onBlur: ge,
|
|
76
|
+
onKeyDown: _e,
|
|
77
|
+
onKeyUp: ve,
|
|
78
|
+
ref: De,
|
|
63
79
|
role: "checkbox",
|
|
64
|
-
"aria-checked":
|
|
65
|
-
disabled:
|
|
66
|
-
...
|
|
67
|
-
onClick:
|
|
80
|
+
"aria-checked": g ? "mixed" : V,
|
|
81
|
+
disabled: v && !y,
|
|
82
|
+
...re(y, { reachable: !0 }),
|
|
83
|
+
onClick: y ? (e) => {
|
|
68
84
|
e.preventDefault(), e.stopPropagation();
|
|
69
|
-
} :
|
|
70
|
-
className: e(
|
|
71
|
-
children:
|
|
72
|
-
size:
|
|
85
|
+
} : i(z, () => H((e) => !e)),
|
|
86
|
+
className: e(a.indicator, e("flex shrink-0 items-center justify-center border p-0 transition-colors motion-reduce:transition-none", X.box, ke), K && X.offset, se, Oe ? e("border-primary bg-primary text-primary-foreground", Z ? fe : de) : e("border-stroke-accessible bg-transparent", Z ? s.disabled : s.control)),
|
|
87
|
+
children: g ? /* @__PURE__ */ d(le, {
|
|
88
|
+
size: X.glyph,
|
|
73
89
|
className: Q
|
|
74
|
-
}) :
|
|
75
|
-
size:
|
|
90
|
+
}) : V ? /* @__PURE__ */ d(ce, {
|
|
91
|
+
size: X.glyph,
|
|
76
92
|
className: Q
|
|
77
93
|
}) : null
|
|
78
94
|
}),
|
|
79
|
-
|
|
80
|
-
/* @__PURE__ */
|
|
95
|
+
x !== "before" && $,
|
|
96
|
+
/* @__PURE__ */ d(l, {
|
|
81
97
|
type: "checkbox",
|
|
82
|
-
name:
|
|
83
|
-
form:
|
|
98
|
+
name: w,
|
|
99
|
+
form: D,
|
|
84
100
|
disabled: Z,
|
|
85
|
-
value:
|
|
86
|
-
checked:
|
|
87
|
-
required:
|
|
88
|
-
onInvalid: () =>
|
|
101
|
+
value: T,
|
|
102
|
+
checked: V,
|
|
103
|
+
required: Te,
|
|
104
|
+
onInvalid: () => q.current?.focus()
|
|
89
105
|
})
|
|
90
106
|
]
|
|
91
107
|
});
|
|
92
108
|
};
|
|
93
|
-
|
|
109
|
+
m.displayName = "Checkbox";
|
|
94
110
|
//#endregion
|
|
95
|
-
export {
|
|
111
|
+
export { m as Checkbox };
|
|
96
112
|
|
|
97
113
|
//# sourceMappingURL=Checkbox.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.mjs","names":["useId","useId$1","React","checkedBox","disabledCheckedBox","disabledGlyph","Checkbox","checkedProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","ariaErrorMessage","ariaDetails","ariaDisabled","rest","onChange","warnDeprecated","hasChildren","slotRendersContent","children","warnOnce","checked","setChecked","useControllable","defaultChecked","onCheckedChange","next","generatedId","labelTextId","field","useFieldContext","fieldProps","useFieldControl","required","isRequired","hasLabel","label","labelledBy","joinIds","buttonRef","mergedControlRef","useMergedRefs","controlRef","form","on","indeterminate","unavailable","disabled","disabledFocusable","glyphClassName","forcedColors","labelText","cn","checkboxClassNames","materialiseSlotContent","labelPosition","className","focusableDisabledProps","event","composeEventHandlers","onClick","prev","focusRing","SubtractIcon","CheckIcon","HiddenInput"],"sources":["../../../src/components/input/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { focusableDisabledProps, joinIds } from '../../lib/aria';\nimport { checkboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnDeprecated, warnOnce } from '../../lib/dev';\nimport { CheckIcon, SubtractIcon } from '../../lib/icons';\nimport { materialiseSlotContent, slotRendersContent } from '../../lib/slot';\nimport { focusRing, forcedColors } from '../../lib/styles';\nimport type { LabelPosition } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useId } from '../../hooks/useId';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\n\n/*\n * Forced colors: the focusable box keeps system-color utilities, so the browser still forces its\n * focus outline and border; only the glyph (the leaf indicator) opts out of forced colors. A\n * disabled box draws a GrayText glyph and border on Canvas, without the Highlight fill.\n */\nconst checkedBox = 'forced-colors:border-[Highlight] forced-colors:bg-[Highlight]';\nconst disabledCheckedBox = 'forced-colors:border-[GrayText] forced-colors:bg-[Canvas]';\nconst disabledGlyph = 'forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none';\n\n/** Handlers that run on the `role=\"checkbox\"` button instead of the root label (C-ROUTING). */\ntype CheckboxControlHandlers = 'onClick' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp';\n\n/** Where a Checkbox renders its label: after the box (default) or before it. */\nexport type CheckboxLabelPosition = Extract<LabelPosition, 'before' | 'after'>;\n\n/** Properties for the Checkbox component. */\nexport interface CheckboxProps extends Omit<\n React.HTMLAttributes<HTMLLabelElement>,\n 'onChange' | 'defaultChecked' | CheckboxControlHandlers\n> {\n /** Controlled checked state. */\n checked?: boolean;\n /** Initial checked state for uncontrolled usage (also the value a form reset restores).\n * @default false\n */\n defaultChecked?: boolean;\n /**\n * Shows the mixed state: the dash glyph and `aria-checked=\"mixed\"`, whatever `checked` is. A\n * click still toggles `checked` and calls `onCheckedChange`, but the checkbox keeps showing and\n * announcing \"mixed\" until you clear `indeterminate`. For a tri-state \"select all\", derive\n * `checked` and `indeterminate` from the items and set every item in `onCheckedChange`.\n * @default false\n */\n indeterminate?: boolean;\n /** Called with the new checked state when it changes (not for no-op updates). */\n onCheckedChange?: (checked: boolean) => void;\n /**\n * Called with the new checked state when it changes.\n * @deprecated Use `onCheckedChange`.\n */\n onChange?: (checked: boolean) => void;\n /** Whether the checkbox is disabled and non-interactive. */\n disabled?: boolean;\n /**\n * Marks the checkbox unavailable but keeps it focusable and in the tab order: for a disabled\n * checkbox that needs a Tooltip, or one in a toolbar. Renders `aria-disabled=\"true\"`,\n * `data-disabled` and `data-disabled-focusable` on the checkbox instead of the native `disabled`\n * attribute. The checkbox cannot be toggled and is not submitted with its form; your `onClick`\n * is not called, and a click on the checkbox (or Space and Enter) does not reach ancestor click\n * handlers, as for a natively disabled control. Wins over `disabled` when both are set. In a\n * roving container (a `Toolbar`) it stays in the arrow-key order.\n * @default false\n */\n disabledFocusable?: boolean;\n /**\n * Label next to the control (any phrasing content, links included, but no other form\n * controls). It names the control through `aria-labelledby`, after a consumer or Field\n * `aria-labelledby`; a consumer `aria-label` names it instead. Clicking its text toggles the\n * control; clicking a link inside it follows the link. `children` are not rendered: pass the\n * label here.\n */\n label?: React.ReactNode;\n /**\n * Where the label renders: after the control (default) or before it. The DOM order follows the\n * visual order.\n * @default 'after'\n */\n labelPosition?: CheckboxLabelPosition;\n /**\n * Form field name. With a name, the checkbox takes part in native form submission: it submits\n * `name=value` while checked.\n */\n name?: string;\n /** Value submitted while checked.\n * @default 'on'\n */\n value?: string;\n /** The form must not be submitted while the checkbox is unchecked (native validation). */\n required?: boolean;\n /** Id of the form the checkbox belongs to, when it is rendered outside that form. */\n form?: string;\n /** Click handler of the checkbox control (the `role=\"checkbox\"` button). */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** Focus handler of the checkbox control. */\n onFocus?: React.FocusEventHandler<HTMLButtonElement>;\n /** Blur handler of the checkbox control. */\n onBlur?: React.FocusEventHandler<HTMLButtonElement>;\n /** Keydown handler of the checkbox control. */\n onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Keyup handler of the checkbox control. */\n onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Ref to the focusable `role=\"checkbox\"` button. */\n controlRef?: React.Ref<HTMLButtonElement>;\n /** Ref to the root `<label>` element. */\n ref?: React.Ref<HTMLLabelElement>;\n}\n\n/**\n * A checkbox for a boolean (or mixed) choice, drawn as a `role=\"checkbox\"` button inside a\n * `<label>`.\n *\n * - The root `<label>` receives `ref`, `className`, `style` and `data-*`; the control receives\n * `id`, `aria-label`/`-labelledby`/`-describedby`/`-invalid`/`-required`/`-errormessage`/\n * `-details`/`-disabled`, `tabIndex`, `autoFocus` and the click, focus and key handlers\n * (`controlRef` exposes it). A consumer `onClick` runs once per activation, before the toggle;\n * `preventDefault()` in it cancels the toggle.\n * - Inside a `Field` it is named by the Field label (followed by its own `label` text) and described\n * by the Field message and hint.\n * - With `name` (or `required`) it takes part in native forms like `<input type=\"checkbox\">`, and\n * a form reset restores `defaultChecked`.\n * - `label` takes rich content (a link to the terms) and renders after the box, or before it with\n * `labelPosition=\"before\"` (the root carries `data-label-position`). The box lines up with the\n * first line of a label that wraps or has a second line. `children` are not rendered (a\n * development warning says so).\n */\nexport const Checkbox = ({\n checked: checkedProp,\n defaultChecked = false,\n indeterminate = false,\n onCheckedChange,\n onChange,\n disabled = false,\n disabledFocusable = false,\n label,\n labelPosition = 'after',\n name,\n value,\n required,\n form,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n 'aria-errormessage': ariaErrorMessage,\n 'aria-details': ariaDetails,\n 'aria-disabled': ariaDisabled,\n autoFocus,\n tabIndex,\n onClick,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n controlRef,\n className,\n children,\n ref,\n ...rest\n}: CheckboxProps) => {\n if (onChange !== undefined) warnDeprecated('Checkbox', 'onChange', 'onCheckedChange');\n const hasChildren = slotRendersContent(children);\n React.useEffect(() => {\n if (hasChildren) {\n warnOnce(\n 'Checkbox:children',\n 'Checkbox: children are not rendered. Pass the label in `label`.',\n );\n }\n }, [hasChildren]);\n const [checked, setChecked] = useControllable(checkedProp, defaultChecked, (next: boolean) => {\n onCheckedChange?.(next);\n onChange?.(next);\n });\n\n const generatedId = useId('checkbox');\n const labelTextId = useId('checkbox-label');\n const field = useFieldContext();\n const fieldProps = useFieldControl({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n // An explicit `required={false}` wins over a required Field, so aria-required always matches\n // the native validation below (`isRequired`).\n 'aria-required': ariaRequired ?? required,\n });\n const isRequired = required ?? field?.required ?? false;\n // `0` is a label; `null`, `false`, `''` and empty collections are not (C-SLOTS).\n const hasLabel = slotRendersContent(label);\n // The label text names the control through aria-labelledby, disabled or not: axe exempts the\n // dimmed text of a disabled control only when the control references it this way (its <label>\n // exemption covers native inputs only). A consumer aria-label still names the control alone.\n // The ids already there (the consumer's, the Field label from useFieldControl) come first, then\n // the Field label whose <label htmlFor> targets this control (aria-labelledby would hide it), so\n // the name keeps every label.\n const labelledBy =\n hasLabel && fieldProps['aria-label'] === undefined\n ? joinIds(\n fieldProps['aria-labelledby'],\n field && fieldProps.id === field.controlId ? field.labelId : undefined,\n labelTextId,\n )\n : fieldProps['aria-labelledby'];\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const mergedControlRef = useMergedRefs(buttonRef, controlRef);\n useFormReset(buttonRef, () => setChecked(defaultChecked), form);\n\n const on = checked || indeterminate;\n // Focusable-disabled wins over `disabled`: the box stays focusable but looks and acts disabled.\n const unavailable = disabled || disabledFocusable;\n // The glyph is the forced-colors leaf; the box stays on system colors (see `checkedBox`).\n const glyphClassName = unavailable ? disabledGlyph : forcedColors.selectedLeaf;\n const labelText = hasLabel ? (\n <span id={labelTextId} className={cn(checkboxClassNames.label, 'text-body-1 text-foreground')}>\n {materialiseSlotContent(label)}\n </span>\n ) : null;\n\n return (\n <label\n ref={ref}\n data-label-position={labelPosition}\n className={cn(\n checkboxClassNames.root,\n // items-start: the box lines up with the first line of a label that wraps or has a second\n // line, not with its middle.\n 'relative inline-flex items-start gap-2 select-none',\n // The dimmed look lifts while a focus ring shows inside the root (the control's, under\n // disabledFocusable, or a link's in the label): opacity would dim the ring below 3:1.\n unavailable\n ? 'cursor-not-allowed opacity-50 has-focus-visible:opacity-100'\n : 'cursor-pointer',\n className,\n )}\n {...rest}\n >\n {labelPosition === 'before' && labelText}\n <button\n id={generatedId}\n type=\"button\"\n {...fieldProps}\n aria-labelledby={labelledBy}\n aria-errormessage={ariaErrorMessage}\n aria-details={ariaDetails}\n aria-disabled={ariaDisabled}\n autoFocus={autoFocus}\n tabIndex={tabIndex}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n ref={mergedControlRef}\n role=\"checkbox\"\n aria-checked={indeterminate ? 'mixed' : checked}\n disabled={disabled && !disabledFocusable}\n {...focusableDisabledProps(disabledFocusable, { reachable: true })}\n onClick={\n disabledFocusable\n ? // Clicks, Space and Enter (which click a button) neither toggle nor reach `onClick`,\n // and, as a natively disabled control dispatches no click, no ancestor sees them.\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n }\n : composeEventHandlers(onClick, () => setChecked((prev) => !prev))\n }\n className={cn(\n checkboxClassNames.indicator,\n // p-0 and the unchecked bg-transparent are set here, not left to the native reset, which\n // any app button style overrides (C-NATIVE).\n 'flex h-[18px] w-[18px] shrink-0 items-center justify-center rounded-xs border p-0 transition-colors motion-reduce:transition-none',\n // Centred on the 20px first line of the label text.\n hasLabel && 'mt-px',\n focusRing,\n on\n ? cn(\n 'border-primary bg-primary text-primary-foreground',\n unavailable ? disabledCheckedBox : checkedBox,\n )\n : cn(\n 'border-stroke-accessible bg-transparent',\n unavailable ? forcedColors.disabled : forcedColors.control,\n ),\n )}\n >\n {indeterminate ? (\n <SubtractIcon size={12} className={glyphClassName} />\n ) : checked ? (\n <CheckIcon size={12} className={glyphClassName} />\n ) : null}\n </button>\n {labelPosition !== 'before' && labelText}\n <HiddenInput\n type=\"checkbox\"\n name={name}\n form={form}\n disabled={unavailable}\n value={value}\n checked={checked}\n required={isRequired}\n onInvalid={() => buttonRef.current?.focus()}\n />\n </label>\n );\n};\n\nCheckbox.displayName = 'Chec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UAAUnB;IACH;IACE;IACT,UAAUZ;IACV,iBAAiBK,EAAU,SAAS,MAAM;GAC3C,CAAA;EACI;;AAEX;AAEA,EAAS,cAAc"}
|
|
1
|
+
{"version":3,"file":"Checkbox.mjs","names":["useId","useId$1","React","checkedBox","disabledCheckedBox","disabledGlyph","CHECKBOX_SIZE","CHECKBOX_SHAPE","Checkbox","checkedProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","ariaErrorMessage","ariaDetails","ariaDisabled","rest","onChange","warnDeprecated","hasChildren","slotRendersContent","children","warnOnce","checked","setChecked","useControllable","defaultChecked","onCheckedChange","next","generatedId","labelTextId","field","useFieldContext","fieldProps","useFieldControl","required","isRequired","hasLabel","label","labelledBy","joinIds","buttonRef","mergedControlRef","useMergedRefs","controlRef","form","on","indeterminate","resolvedSize","size","resolvedShape","shape","sizeMetrics","shapeClass","unavailable","disabled","disabledFocusable","glyphClassName","forcedColors","labelText","cn","checkboxClassNames","materialiseSlotContent","labelPosition","className","focusableDisabledProps","event","composeEventHandlers","onClick","prev","focusRing","SubtractIcon","CheckIcon","HiddenInput"],"sources":["../../../src/components/input/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { focusableDisabledProps, joinIds } from '../../lib/aria';\nimport { checkboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnDeprecated, warnOnce } from '../../lib/dev';\nimport { CheckIcon, SubtractIcon } from '../../lib/icons';\nimport { materialiseSlotContent, slotRendersContent } from '../../lib/slot';\nimport { focusRing, forcedColors } from '../../lib/styles';\nimport type { LabelPosition, Shape, Size } from '../../lib/types';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useId } from '../../hooks/useId';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\n\n/*\n * Forced colors: the focusable box keeps system-color utilities, so the browser still forces its\n * focus outline and border; only the glyph (the leaf indicator) opts out of forced colors. A\n * disabled box draws a GrayText glyph and border on Canvas, without the Highlight fill.\n */\nconst checkedBox = 'forced-colors:border-[Highlight] forced-colors:bg-[Highlight]';\nconst disabledCheckedBox = 'forced-colors:border-[GrayText] forced-colors:bg-[Canvas]';\nconst disabledGlyph = 'forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none';\n\n/** Handlers that run on the `role=\"checkbox\"` button instead of the root label (C-ROUTING). */\ntype CheckboxControlHandlers = 'onClick' | 'onFocus' | 'onBlur' | 'onKeyDown' | 'onKeyUp';\n\n/** Where a Checkbox renders its label: after the box (default) or before it. */\nexport type CheckboxLabelPosition = Extract<LabelPosition, 'before' | 'after'>;\n\n/** Size of the box: an 18px box (the 0.7 look) or a 22px box with a bigger glyph. */\nexport type CheckboxSize = Extract<Size, 'medium' | 'large'>;\n\n/** Shape of the box: square corners (the 0.7 look) or a circular, round box. */\nexport type CheckboxShape = Extract<Shape, 'square' | 'circular'>;\n\n/** Per-size box, glyph and label-offset classes. */\nconst CHECKBOX_SIZE: Readonly<\n Record<CheckboxSize, { box: string; glyph: number; offset: string }>\n> = {\n medium: { box: 'h-[18px] w-[18px]', glyph: 12, offset: 'mt-px' },\n large: { box: 'h-[22px] w-[22px]', glyph: 16, offset: '-mt-px' },\n};\n\n/** Per-shape corner classes. */\nconst CHECKBOX_SHAPE: Readonly<Record<CheckboxShape, string>> = {\n square: 'rounded-xs',\n circular: 'rounded-full',\n};\n\n/** Properties for the Checkbox component. */\nexport interface CheckboxProps extends Omit<\n React.HTMLAttributes<HTMLLabelElement>,\n 'onChange' | 'defaultChecked' | CheckboxControlHandlers\n> {\n /** Controlled checked state. */\n checked?: boolean;\n /** Initial checked state for uncontrolled usage (also the value a form reset restores).\n * @default false\n */\n defaultChecked?: boolean;\n /**\n * Shows the mixed state: the dash glyph and `aria-checked=\"mixed\"`, whatever `checked` is. A\n * click still toggles `checked` and calls `onCheckedChange`, but the checkbox keeps showing and\n * announcing \"mixed\" until you clear `indeterminate`. For a tri-state \"select all\", derive\n * `checked` and `indeterminate` from the items and set every item in `onCheckedChange`.\n * @default false\n */\n indeterminate?: boolean;\n /** Called with the new checked state when it changes (not for no-op updates). */\n onCheckedChange?: (checked: boolean) => void;\n /**\n * Called with the new checked state when it changes.\n * @deprecated Use `onCheckedChange`.\n */\n onChange?: (checked: boolean) => void;\n /** Whether the checkbox is disabled and non-interactive. */\n disabled?: boolean;\n /**\n * Marks the checkbox unavailable but keeps it focusable and in the tab order: for a disabled\n * checkbox that needs a Tooltip, or one in a toolbar. Renders `aria-disabled=\"true\"`,\n * `data-disabled` and `data-disabled-focusable` on the checkbox instead of the native `disabled`\n * attribute. The checkbox cannot be toggled and is not submitted with its form; your `onClick`\n * is not called, and a click on the checkbox (or Space and Enter) does not reach ancestor click\n * handlers, as for a natively disabled control. Wins over `disabled` when both are set. In a\n * roving container (a `Toolbar`) it stays in the arrow-key order.\n * @default false\n */\n disabledFocusable?: boolean;\n /**\n * Label next to the control (any phrasing content, links included, but no other form\n * controls). It names the control through `aria-labelledby`, after a consumer or Field\n * `aria-labelledby`; a consumer `aria-label` names it instead. Clicking its text toggles the\n * control; clicking a link inside it follows the link. `children` are not rendered: pass the\n * label here.\n */\n label?: React.ReactNode;\n /**\n * Where the label renders: after the control (default) or before it. The DOM order follows the\n * visual order.\n * @default 'after'\n */\n labelPosition?: CheckboxLabelPosition;\n /**\n * Size of the box: an 18px box (the 0.7 look) or a 22px box with a bigger glyph. Unlike the\n * text controls and pickers, Checkbox does not read a surrounding Field's size or a\n * WaveProvider's input defaults: this prop is the only source of its size.\n * @default 'medium'\n */\n size?: CheckboxSize;\n /**\n * Shape of the box: square corners (the 0.7 look) or a circular, round box.\n * @default 'square'\n */\n shape?: CheckboxShape;\n /**\n * Form field name. With a name, the checkbox takes part in native form submission: it submits\n * `name=value` while checked.\n */\n name?: string;\n /** Value submitted while checked.\n * @default 'on'\n */\n value?: string;\n /** The form must not be submitted while the checkbox is unchecked (native validation). */\n required?: boolean;\n /** Id of the form the checkbox belongs to, when it is rendered outside that form. */\n form?: string;\n /** Click handler of the checkbox control (the `role=\"checkbox\"` button). */\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n /** Focus handler of the checkbox control. */\n onFocus?: React.FocusEventHandler<HTMLButtonElement>;\n /** Blur handler of the checkbox control. */\n onBlur?: React.FocusEventHandler<HTMLButtonElement>;\n /** Keydown handler of the checkbox control. */\n onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Keyup handler of the checkbox control. */\n onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Ref to the focusable `role=\"checkbox\"` button. */\n controlRef?: React.Ref<HTMLButtonElement>;\n /** Ref to the root `<label>` element. */\n ref?: React.Ref<HTMLLabelElement>;\n}\n\n/**\n * A checkbox for a boolean (or mixed) choice, drawn as a `role=\"checkbox\"` button inside a\n * `<label>`.\n *\n * - The root `<label>` receives `ref`, `className`, `style` and `data-*`; the control receives\n * `id`, `aria-label`/`-labelledby`/`-describedby`/`-invalid`/`-required`/`-errormessage`/\n * `-details`/`-disabled`, `tabIndex`, `autoFocus` and the click, focus and key handlers\n * (`controlRef` exposes it). A consumer `onClick` runs once per activation, before the toggle;\n * `preventDefault()` in it cancels the toggle.\n * - Inside a `Field` it is named by the Field label (followed by its own `label` text) and described\n * by the Field message and hint.\n * - With `name` (or `required`) it takes part in native forms like `<input type=\"checkbox\">`, and\n * a form reset restores `defaultChecked`.\n * - `label` takes rich content (a link to the terms) and renders after the box, or before it with\n * `labelPosition=\"before\"` (the root carries `data-label-position`). The box lines up with the\n * first line of a label that wraps or has a second line. `children` are not rendered (a\n * development warning says so).\n * - `size` (`medium`, `large`) and `shape` (`square`, `circular`) set the box's dimensions and\n * corners; the root carries `data-size` and `data-shape`. Checkbox does not read a surrounding\n * `Field`'s size or a `WaveProvider`'s input defaults.\n */\nexport const Checkbox = ({\n checked: checkedProp,\n defaultChecked = false,\n indeterminate = false,\n onCheckedChange,\n onChange,\n disabled = false,\n disabledFocusable = false,\n label,\n labelPosition = 'after',\n size = 'medium',\n shape = 'square',\n name,\n value,\n required,\n form,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n 'aria-errormessage': ariaErrorMessage,\n 'aria-details': ariaDetails,\n 'aria-disabled': ariaDisabled,\n autoFocus,\n tabIndex,\n onClick,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n controlRef,\n className,\n children,\n ref,\n ...rest\n}: CheckboxProps) => {\n if (onChange !== undefined) warnDeprecated('Checkbox', 'onChange', 'onCheckedChange');\n const hasChildren = slotRendersContent(children);\n React.useEffect(() => {\n if (hasChildren) {\n warnOnce(\n 'Checkbox:children',\n 'Checkbox: children are not rendered. Pass the label in `label`.',\n );\n }\n }, [hasChildren]);\n const [checked, setChecked] = useControllable(checkedProp, defaultChecked, (next: boolean) => {\n onCheckedChange?.(next);\n onChange?.(next);\n });\n\n const generatedId = useId('checkbox');\n const labelTextId = useId('checkbox-label');\n const field = useFieldContext();\n const fieldProps = useFieldControl({\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n // An explicit `required={false}` wins over a required Field, so aria-required always matches\n // the native validation below (`isRequired`).\n 'aria-required': ariaRequired ?? required,\n });\n const isRequired = required ?? field?.required ?? false;\n // `0` is a label; `null`, `false`, `''` and empty collections are not (C-SLOTS).\n const hasLabel = slotRendersContent(label);\n // The label text names the control through aria-labelledby, disabled or not: axe exempts the\n // dimmed text of a disabled control only when the control references it this way (its <label>\n // exemption covers native inputs only). A consumer aria-label still names the control alone.\n // The ids already there (the consumer's, the Field label from useFieldControl) come first, then\n // the Field label whose <label htmlFor> targets this control (aria-labelledby would hide it), so\n // the name keeps every label.\n const labelledBy =\n hasLabel && fieldProps['aria-label'] === undefined\n ? joinIds(\n fieldProps['aria-labelledby'],\n field && fieldProps.id === field.controlId ? field.labelId : undefined,\n labelTextId,\n )\n : fieldProps['aria-labelledby'];\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const mergedControlRef = useMergedRefs(buttonRef, controlRef);\n useFormReset(buttonRef, () => setChecked(defaultChecked), form);\n\n const on = checked || indeterminate;\n // A size or shape outside the unions (from untyped code) renders, and is reported in the data\n // attributes, as the default: TypeScript rejects one, but the value still reaches this render.\n const resolvedSize: CheckboxSize = Object.hasOwn(CHECKBOX_SIZE, size) ? size : 'medium';\n const resolvedShape: CheckboxShape = Object.hasOwn(CHECKBOX_SHAPE, shape) ? shape : 'square';\n const sizeMetrics = CHECKBOX_SIZE[resolvedSize];\n const shapeClass = CHECKBOX_SHAPE[resolvedShape];\n // Focusable-disabled wins over `disabled`: the box stays focusable but looks and acts disabled.\n const unavailable = disabled || disabledFocusable;\n // The glyph is the forced-colors leaf; the box stays on system colors (see `checkedBox`).\n const glyphClassName = unavailable ? disabledGlyph : forcedColors.selectedLeaf;\n const labelText = hasLabel ? (\n <span id={labelTextId} className={cn(checkboxClassNames.label, 'text-body-1 text-foreground')}>\n {materialiseSlotContent(label)}\n </span>\n ) : null;\n\n return (\n <label\n ref={ref}\n data-label-position={labelPosition}\n data-size={resolvedSize}\n data-shape={resolvedShape}\n className={cn(\n checkboxClassNames.root,\n // items-start: the box lines up with the first line of a label that wraps or has a second\n // line, not with its middle.\n 'relative inline-flex items-start gap-2 select-none',\n // The dimmed look lifts while a focus ring shows inside the root (the control's, under\n // disabledFocusable, or a link's in the label): opacity would dim the ring below 3:1.\n unavailable\n ? 'cursor-not-allowed opacity-50 has-focus-visible:opacity-100'\n : 'cursor-pointer',\n className,\n )}\n {...rest}\n >\n {labelPosition === 'before' && labelText}\n <button\n id={generatedId}\n type=\"button\"\n {...fieldProps}\n aria-labelledby={labelledBy}\n aria-errormessage={ariaErrorMessage}\n aria-details={ariaDetails}\n aria-disabled={ariaDisabled}\n autoFocus={autoFocus}\n tabIndex={tabIndex}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n ref={mergedControlRef}\n role=\"checkbox\"\n aria-checked={indeterminate ? 'mixed' : checked}\n disabled={disabled && !disabledFocusable}\n {...focusableDisabledProps(disabledFocusable, { reachable: true })}\n onClick={\n disabledFocusable\n ? // Clicks, Space and Enter (which click a button) neither toggle nor reach `onClick`,\n // and, as a natively disabled control dispatches no click, no ancestor sees them.\n (event: React.MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n event.stopPropagation();\n }\n : composeEventHandlers(onClick, () => setChecked((prev) => !prev))\n }\n className={cn(\n checkboxClassNames.indicator,\n // p-0 and the unchecked bg-transparent are set here, not left to the native reset, which\n // any app button style overrides (C-NATIVE).\n cn(\n 'flex shrink-0 items-center justify-center border p-0 transition-colors motion-reduce:transition-none',\n sizeMetrics.box,\n shapeClass,\n ),\n // Centred on the label's 20px first line: nudged down at medium, up at large.\n hasLabel && sizeMetrics.offset,\n focusRing,\n on\n ? cn(\n 'border-primary bg-primary text-primary-foreground',\n unavailable ? disabledCheckedBox : checkedBox,\n )\n : cn(\n 'border-stroke-accessible bg-transparent',\n unavailable ? forcedColors.disabled : forcedColors.control,\n ),\n )}\n >\n {indeterminate ? (\n <SubtractIcon size={sizeMetrics.glyph} className={glyphClassName} />\n ) : checked ? (\n <CheckIcon size={sizeMetrics.glyph} className={glyphClassName} />\n ) : null}\n </button>\n {labelPosition !== 'before' && labelText}\n <HiddenInput\n type=\"checkbox\"\n name={name}\n form={form}\n disabled={unavailable}\n value={value}\n checked={checked}\n required={isRequired}\n onInvalid={() => buttonRef.current?.focus()}\n />\n </label>\n );\n};\n\nCheckbox.displayName = 'Checkbox';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,IAAMG,KAAa,iEACbC,KA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ACF,GAEAhB,KAAYe,EAAY,QACxBkB,IACAxB,KACIc,EACE,qDACAN,IAAcpD,KAAqBD,EACrC,IACA2D,EACE,2CACAN,IAAcI,EAAa,WAAWA,EAAa,OACrD,CACN;IAEC,UAAAX,IACC,kBAACwB,IAAD;KAAc,MAAMnB,EAAY;KAAO,WAAWK;IAAiB,CAAA,IACjElC,IACF,kBAACiD,IAAD;KAAW,MAAMpB,EAAY;KAAO,WAAWK;IAAiB,CAAA,IAC9D;GACE,CAAA;GACPM,MAAkB,YAAYJ;GAC/B,kBAACc,GAAD;IACE,MAAK;IACC;IACA;IACN,UAAUnB;IACH;IACE;IACT,UAAUlB;IACV,iBAAiBK,EAAU,SAAS,MAAM;GAC3C,CAAA;EACI;;AAEX;AAEA,EAAS,cAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/composeEventHandlers.cjs"),i=require("../../lib/classNames.cjs"),a=require("../../hooks/useControllable.cjs"),o=require("../../hooks/useId.cjs"),s=require("../../hooks/useMergedRefs.cjs"),c=require("../../lib/aria.cjs"),l=require("../../lib/styles.cjs"),u=require("./Input.cjs"),d=require("./colorUtils.cjs"),f=require("./SwatchPicker.cjs");let p=require("react");p=e.__toESM(p,1);let m=require("react/jsx-runtime");var h=`#0f6cbd`,g={h:208,s:.92,v:.74},_={hex:`Hex`,hexInput:`Hex color value`,hexError:`Enter a hex color such as ${h}.`,presets:`Preset colors`,opacity:`Opacity`,area:`Saturation and brightness`,saturation:`Saturation`,brightness:`Brightness`,roleDescription:`2D slider`,hue:`Hue`,transparency:`Transparency`},v=p.createContext(null);v.displayName=`ColorPickerContext`;function y(){return p.useContext(v)}var b=()=>{};function x({value:e,defaultValue:t,onValueChange:n,disabled:r}){let i=y(),o=i!==null&&e===void 0&&t===void 0?i:null,s=t??g,[c,l]=a.useControllable(e,s,o?void 0:n);return o?{picker:o,color:o.hsv,setColor:e=>{o.setHsv(e),n?.(e)},reset:b,disabled:r||o.disabled}:{picker:null,color:c,setColor:l,reset:()=>{d.sameColor(c,s)||l(s)},disabled:r}}var S={hsv:g,setHsv:b,color:h,parsed:null,setColor:b,pickPreset:b,presetItems:[],shape:`rounded`,labels:_,disabled:!0,draftResetKey:0,field:null,groupInvalid:void 0,errorMessageId:void 0,registerHexInput:b};function C(e){return p.useContext(v)||(n.reportMissingContext(e,`<ColorPicker>`),S)}function w(e){let t=e.trim();return t===``||t===`#`}function T(e){let t=e.trim().replace(/^#/,``).length;return t===4||t===8}var E=({id:e,"aria-label":n,"aria-labelledby":a,"aria-describedby":f,"aria-invalid":h,"aria-errormessage":g,"aria-details":_,"aria-required":v,autoFocus:y,tabIndex:b,onFocus:x,onBlur:S,onKeyDown:E,onKeyUp:D,inputMode:O,enterKeyHint:k,autoCapitalize:ee,autoCorrect:te,spellCheck:ne,controlRef:re,className:A,ref:j,...M})=>{let N=C(`ColorPicker.HexField`),{color:P,parsed:ie,field:F,groupInvalid:I,errorMessageId:L,labels:R}=N,z=ie?.alpha??255,[B,V]=p.useState(null),[H,U]=p.useState(P);P!==H&&(U(P),B?.flagged&&V(null));let[W,G]=p.useState(N.draftResetKey);N.draftResetKey!==W&&(G(N.draftResetKey),V(null));let K=B?.text??P,q=B!==null&&!w(B.text)&&(B.flagged||!d.isHexDraft(B.text)),J=I!==void 0&&I!==!1&&I!==`false`,Y=o.useId(`wave-color-picker-error`),X=h??(q?!0:J?I:void 0),ae=u.isInvalidLook(!1,X),oe=p.useRef(null),se=s.useMergedRefs(oe,re,N.registerHexInput),Z=(e,t)=>N.setColor(d.formatHexColor(e,t)),Q=e=>{let t=e.target.value.trim();t!==``&&!t.startsWith(`#`)&&(t=`#${t}`),V({text:t,flagged:!1});let n=d.parseHexInput(t);n&&Z(n.rgb,T(t)?n.alpha:z)},$=()=>{if(B===null||B.flagged)return;let e=d.parseHexColor(B.text);if(e||w(B.text)){e&&!d.parseHexInput(B.text)&&Z(e.rgb,T(B.text)?e.alpha:z),V(null);return}V({text:B.text,flagged:!0})},ce=r.composeEventHandlers(S,$),le=r.composeEventHandlers(E,e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&$()});return(0,m.jsxs)(`label`,{ref:j,className:t.cn(i.colorPickerHexFieldClassNames.root,`flex min-w-0 flex-col gap-1`,A),...M,children:[(0,m.jsx)(`span`,{className:t.cn(i.colorPickerHexFieldClassNames.label,`text-caption-1 text-muted-foreground`),children:R.hex}),(0,m.jsx)(`input`,{ref:se,id:e,type:`text`,value:K,onChange:Q,onKeyDown:le,onKeyUp:D,onFocus:x,onBlur:ce,"aria-label":n??(a===void 0?R.hexInput:void 0),"aria-labelledby":a,"aria-invalid":X,"aria-errormessage":g??L,"aria-describedby":c.joinIds(q&&Y,F?.validationMessageId??(J?F?.errorId:void 0),L,f),"aria-details":_,"aria-required":v,autoFocus:y,tabIndex:b,inputMode:O,enterKeyHint:k,autoCapitalize:ee,autoCorrect:te,spellCheck:ne??!1,maxLength:9,autoComplete:`off`,className:t.cn(i.colorPickerHexFieldClassNames.input,`w-24 rounded border border-input border-b-stroke-accessible bg-background px-2 py-1 text-body-1 text-foreground`,l.inputFocus,ae&&`border-destructive
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/composeEventHandlers.cjs"),i=require("../../lib/classNames.cjs"),a=require("../../hooks/useControllable.cjs"),o=require("../../hooks/useId.cjs"),s=require("../../hooks/useMergedRefs.cjs"),c=require("../../lib/aria.cjs"),l=require("../../lib/styles.cjs"),u=require("./Input.cjs"),d=require("./colorUtils.cjs"),f=require("./SwatchPicker.cjs");let p=require("react");p=e.__toESM(p,1);let m=require("react/jsx-runtime");var h=`#0f6cbd`,g={h:208,s:.92,v:.74},_={hex:`Hex`,hexInput:`Hex color value`,hexError:`Enter a hex color such as ${h}.`,presets:`Preset colors`,opacity:`Opacity`,area:`Saturation and brightness`,saturation:`Saturation`,brightness:`Brightness`,roleDescription:`2D slider`,hue:`Hue`,transparency:`Transparency`},v=p.createContext(null);v.displayName=`ColorPickerContext`;function y(){return p.useContext(v)}var b=()=>{};function x({value:e,defaultValue:t,onValueChange:n,disabled:r}){let i=y(),o=i!==null&&e===void 0&&t===void 0?i:null,s=t??g,[c,l]=a.useControllable(e,s,o?void 0:n);return o?{picker:o,color:o.hsv,setColor:e=>{o.setHsv(e),n?.(e)},reset:b,disabled:r||o.disabled}:{picker:null,color:c,setColor:l,reset:()=>{d.sameColor(c,s)||l(s)},disabled:r}}var S={hsv:g,setHsv:b,color:h,parsed:null,setColor:b,pickPreset:b,presetItems:[],shape:`rounded`,labels:_,disabled:!0,draftResetKey:0,field:null,groupInvalid:void 0,errorMessageId:void 0,registerHexInput:b};function C(e){return p.useContext(v)||(n.reportMissingContext(e,`<ColorPicker>`),S)}function w(e){let t=e.trim();return t===``||t===`#`}function T(e){let t=e.trim().replace(/^#/,``).length;return t===4||t===8}var E=({id:e,"aria-label":n,"aria-labelledby":a,"aria-describedby":f,"aria-invalid":h,"aria-errormessage":g,"aria-details":_,"aria-required":v,autoFocus:y,tabIndex:b,onFocus:x,onBlur:S,onKeyDown:E,onKeyUp:D,inputMode:O,enterKeyHint:k,autoCapitalize:ee,autoCorrect:te,spellCheck:ne,controlRef:re,className:A,ref:j,...M})=>{let N=C(`ColorPicker.HexField`),{color:P,parsed:ie,field:F,groupInvalid:I,errorMessageId:L,labels:R}=N,z=ie?.alpha??255,[B,V]=p.useState(null),[H,U]=p.useState(P);P!==H&&(U(P),B?.flagged&&V(null));let[W,G]=p.useState(N.draftResetKey);N.draftResetKey!==W&&(G(N.draftResetKey),V(null));let K=B?.text??P,q=B!==null&&!w(B.text)&&(B.flagged||!d.isHexDraft(B.text)),J=I!==void 0&&I!==!1&&I!==`false`,Y=o.useId(`wave-color-picker-error`),X=h??(q?!0:J?I:void 0),ae=u.isInvalidLook(!1,X),oe=p.useRef(null),se=s.useMergedRefs(oe,re,N.registerHexInput),Z=(e,t)=>N.setColor(d.formatHexColor(e,t)),Q=e=>{let t=e.target.value.trim();t!==``&&!t.startsWith(`#`)&&(t=`#${t}`),V({text:t,flagged:!1});let n=d.parseHexInput(t);n&&Z(n.rgb,T(t)?n.alpha:z)},$=()=>{if(B===null||B.flagged)return;let e=d.parseHexColor(B.text);if(e||w(B.text)){e&&!d.parseHexInput(B.text)&&Z(e.rgb,T(B.text)?e.alpha:z),V(null);return}V({text:B.text,flagged:!0})},ce=r.composeEventHandlers(S,$),le=r.composeEventHandlers(E,e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&$()});return(0,m.jsxs)(`label`,{ref:j,className:t.cn(i.colorPickerHexFieldClassNames.root,`flex min-w-0 flex-col gap-1`,A),...M,children:[(0,m.jsx)(`span`,{className:t.cn(i.colorPickerHexFieldClassNames.label,`text-caption-1 text-muted-foreground`),children:R.hex}),(0,m.jsx)(`input`,{ref:se,id:e,type:`text`,value:K,onChange:Q,onKeyDown:le,onKeyUp:D,onFocus:x,onBlur:ce,"aria-label":n??(a===void 0?R.hexInput:void 0),"aria-labelledby":a,"aria-invalid":X,"aria-errormessage":g??L,"aria-describedby":c.joinIds(q&&Y,F?.validationMessageId??(J?F?.errorId:void 0),L,f),"aria-details":_,"aria-required":v,autoFocus:y,tabIndex:b,inputMode:O,enterKeyHint:k,autoCapitalize:ee,autoCorrect:te,spellCheck:ne??!1,maxLength:9,autoComplete:`off`,className:t.cn(i.colorPickerHexFieldClassNames.input,`w-24 rounded border border-input border-b-stroke-accessible bg-background px-2 py-1 text-body-1 text-foreground`,l.inputFocus,ae&&`border-destructive`)}),q&&(0,m.jsx)(`span`,{id:Y,className:t.cn(i.colorPickerHexFieldClassNames.errorMessage,`text-caption-1 text-error`),children:R.hexError})]})};E.displayName=`ColorPickerHexField`;var D=({className:e,"aria-label":n,size:r=`small`,shape:a=`rounded`,...o})=>{let s=C(`ColorPicker.Swatches`);return s.presetItems.length===0?null:(0,m.jsx)(f.SwatchPicker,{"aria-label":n??(o[`aria-labelledby`]===void 0?s.labels.presets:void 0),size:r,shape:a,...o,className:t.cn(i.colorPickerSwatchesClassNames.root,e),items:s.presetItems,value:s.parsed?s.parsed.rgb:``,onValueChange:s.pickPreset})};D.displayName=`ColorPickerSwatches`;var O=({className:e,style:n,ref:r,...a})=>{let o=C(`ColorPicker.Preview`),s=o.parsed?d.formatHexColor(o.parsed.rgb,o.parsed.alpha):o.color;return(0,m.jsx)(`div`,{"data-color-preview":``,"aria-hidden":`true`,...a,ref:r,className:t.cn(i.colorPickerPreviewClassNames.root,`h-10 w-10 shrink-0 rounded border border-border forced-colors:forced-color-adjust-none`,o.shape===`square`&&`rounded-none`,e),style:{...n,backgroundColor:s}})};O.displayName=`ColorPickerPreview`,exports.ColorPickerContext=v,exports.ColorPickerHexField=E,exports.ColorPickerPreview=O,exports.ColorPickerSwatches=D,exports.DEFAULT_COLOR=h,exports.DEFAULT_COLOR_PICKER_LABELS=_,exports.DEFAULT_PART_COLOR=g,exports.useColorPartState=x,exports.useColorPickerContext=y,exports.usePickerPartContext=C;
|
|
2
2
|
//# sourceMappingURL=ColorPicker.parts.cjs.map
|