@mortenbrudvik/waveui 0.4.0 → 0.7.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 +1221 -173
- package/dist/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/components/button/Button.cjs +2 -0
- package/dist/components/button/Button.cjs.map +1 -0
- package/dist/components/button/Button.mjs +50 -0
- package/dist/components/button/Button.mjs.map +1 -0
- package/dist/components/button/Button.semantics.cjs +2 -0
- package/dist/components/button/Button.semantics.cjs.map +1 -0
- package/dist/components/button/Button.semantics.mjs +61 -0
- package/dist/components/button/Button.semantics.mjs.map +1 -0
- package/dist/components/button/Button.slots.cjs +2 -0
- package/dist/components/button/Button.slots.cjs.map +1 -0
- package/dist/components/button/Button.slots.mjs +47 -0
- package/dist/components/button/Button.slots.mjs.map +1 -0
- package/dist/components/button/CompoundButton.cjs +2 -0
- package/dist/components/button/CompoundButton.cjs.map +1 -0
- package/dist/components/button/CompoundButton.mjs +53 -0
- package/dist/components/button/CompoundButton.mjs.map +1 -0
- package/dist/components/button/Link.cjs +2 -0
- package/dist/components/button/Link.cjs.map +1 -0
- package/dist/components/button/Link.mjs +37 -0
- package/dist/components/button/Link.mjs.map +1 -0
- package/dist/components/button/MenuButton.cjs +2 -0
- package/dist/components/button/MenuButton.cjs.map +1 -0
- package/dist/components/button/MenuButton.mjs +45 -0
- package/dist/components/button/MenuButton.mjs.map +1 -0
- package/dist/components/button/SplitButton.cjs +2 -0
- package/dist/components/button/SplitButton.cjs.map +1 -0
- package/dist/components/button/SplitButton.mjs +66 -0
- package/dist/components/button/SplitButton.mjs.map +1 -0
- package/dist/components/button/ToggleButton.cjs +2 -0
- package/dist/components/button/ToggleButton.cjs.map +1 -0
- package/dist/components/button/ToggleButton.mjs +65 -0
- package/dist/components/button/ToggleButton.mjs.map +1 -0
- package/dist/components/button/Toolbar.cjs +2 -0
- package/dist/components/button/Toolbar.cjs.map +1 -0
- package/dist/components/button/Toolbar.context.cjs +2 -0
- package/dist/components/button/Toolbar.context.cjs.map +1 -0
- package/dist/components/button/Toolbar.context.mjs +31 -0
- package/dist/components/button/Toolbar.context.mjs.map +1 -0
- package/dist/components/button/Toolbar.mjs +63 -0
- package/dist/components/button/Toolbar.mjs.map +1 -0
- package/dist/components/button/Toolbar.parts.cjs +2 -0
- package/dist/components/button/Toolbar.parts.cjs.map +1 -0
- package/dist/components/button/Toolbar.parts.mjs +131 -0
- package/dist/components/button/Toolbar.parts.mjs.map +1 -0
- package/dist/components/button/buttonStyles.cjs +2 -0
- package/dist/components/button/buttonStyles.cjs.map +1 -0
- package/dist/components/button/buttonStyles.mjs +39 -0
- package/dist/components/button/buttonStyles.mjs.map +1 -0
- package/dist/components/data-display/Avatar.cjs +2 -0
- package/dist/components/data-display/Avatar.cjs.map +1 -0
- package/dist/components/data-display/Avatar.mjs +157 -0
- package/dist/components/data-display/Avatar.mjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.cjs +2 -0
- package/dist/components/data-display/AvatarGroup.cjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.mjs +134 -0
- package/dist/components/data-display/AvatarGroup.mjs.map +1 -0
- package/dist/components/data-display/Badge.cjs +2 -0
- package/dist/components/data-display/Badge.cjs.map +1 -0
- package/dist/components/data-display/Badge.colors.cjs +2 -0
- package/dist/components/data-display/Badge.colors.cjs.map +1 -0
- package/dist/components/data-display/Badge.colors.mjs +58 -0
- package/dist/components/data-display/Badge.colors.mjs.map +1 -0
- package/dist/components/data-display/Badge.mjs +32 -0
- package/dist/components/data-display/Badge.mjs.map +1 -0
- package/dist/components/data-display/CounterBadge.cjs +2 -0
- package/dist/components/data-display/CounterBadge.cjs.map +1 -0
- package/dist/components/data-display/CounterBadge.mjs +28 -0
- package/dist/components/data-display/CounterBadge.mjs.map +1 -0
- package/dist/components/data-display/Divider.cjs +2 -0
- package/dist/components/data-display/Divider.cjs.map +1 -0
- package/dist/components/data-display/Divider.mjs +52 -0
- package/dist/components/data-display/Divider.mjs.map +1 -0
- package/dist/components/data-display/Image.cjs +2 -0
- package/dist/components/data-display/Image.cjs.map +1 -0
- package/dist/components/data-display/Image.mjs +32 -0
- package/dist/components/data-display/Image.mjs.map +1 -0
- package/dist/components/data-display/InfoLabel.cjs +2 -0
- package/dist/components/data-display/InfoLabel.cjs.map +1 -0
- package/dist/components/data-display/InfoLabel.mjs +104 -0
- package/dist/components/data-display/InfoLabel.mjs.map +1 -0
- package/dist/components/data-display/List.cjs +2 -0
- package/dist/components/data-display/List.cjs.map +1 -0
- package/dist/components/data-display/List.mjs +381 -0
- package/dist/components/data-display/List.mjs.map +1 -0
- package/dist/components/data-display/List.registry.cjs +2 -0
- package/dist/components/data-display/List.registry.cjs.map +1 -0
- package/dist/components/data-display/List.registry.mjs +101 -0
- package/dist/components/data-display/List.registry.mjs.map +1 -0
- package/dist/components/data-display/Persona.cjs +2 -0
- package/dist/components/data-display/Persona.cjs.map +1 -0
- package/dist/components/data-display/Persona.mjs +48 -0
- package/dist/components/data-display/Persona.mjs.map +1 -0
- package/dist/components/data-display/PresenceBadge.cjs +2 -0
- package/dist/components/data-display/PresenceBadge.cjs.map +1 -0
- package/dist/components/data-display/PresenceBadge.mjs +71 -0
- package/dist/components/data-display/PresenceBadge.mjs.map +1 -0
- package/dist/components/data-display/Tag.cjs +2 -0
- package/dist/components/data-display/Tag.cjs.map +1 -0
- package/dist/components/data-display/Tag.mjs +147 -0
- package/dist/components/data-display/Tag.mjs.map +1 -0
- package/dist/components/feedback/MessageBar.cjs +2 -0
- package/dist/components/feedback/MessageBar.cjs.map +1 -0
- package/dist/components/feedback/MessageBar.mjs +144 -0
- package/dist/components/feedback/MessageBar.mjs.map +1 -0
- package/dist/components/feedback/MessageBar.status.cjs +2 -0
- package/dist/components/feedback/MessageBar.status.cjs.map +1 -0
- package/dist/components/feedback/MessageBar.status.mjs +45 -0
- package/dist/components/feedback/MessageBar.status.mjs.map +1 -0
- package/dist/components/feedback/ProgressBar.cjs +2 -0
- package/dist/components/feedback/ProgressBar.cjs.map +1 -0
- package/dist/components/feedback/ProgressBar.mjs +72 -0
- package/dist/components/feedback/ProgressBar.mjs.map +1 -0
- package/dist/components/feedback/Skeleton.cjs +2 -0
- package/dist/components/feedback/Skeleton.cjs.map +1 -0
- package/dist/components/feedback/Skeleton.mjs +47 -0
- package/dist/components/feedback/Skeleton.mjs.map +1 -0
- package/dist/components/feedback/Spinner.cjs +2 -0
- package/dist/components/feedback/Spinner.cjs.map +1 -0
- package/dist/components/feedback/Spinner.mjs +60 -0
- package/dist/components/feedback/Spinner.mjs.map +1 -0
- package/dist/components/feedback/Toast.cjs +2 -0
- package/dist/components/feedback/Toast.cjs.map +1 -0
- package/dist/components/feedback/Toast.mjs +347 -0
- package/dist/components/feedback/Toast.mjs.map +1 -0
- package/dist/components/input/Checkbox.cjs +2 -0
- package/dist/components/input/Checkbox.cjs.map +1 -0
- package/dist/components/input/Checkbox.mjs +96 -0
- package/dist/components/input/Checkbox.mjs.map +1 -0
- package/dist/components/input/ColorPicker.cjs +6 -0
- package/dist/components/input/ColorPicker.cjs.map +1 -0
- package/dist/components/input/ColorPicker.mjs +236 -0
- package/dist/components/input/ColorPicker.mjs.map +1 -0
- package/dist/components/input/Combobox.cjs +2 -0
- package/dist/components/input/Combobox.cjs.map +1 -0
- package/dist/components/input/Combobox.expand.cjs +2 -0
- package/dist/components/input/Combobox.expand.cjs.map +1 -0
- package/dist/components/input/Combobox.expand.mjs +38 -0
- package/dist/components/input/Combobox.expand.mjs.map +1 -0
- package/dist/components/input/Combobox.mjs +187 -0
- package/dist/components/input/Combobox.mjs.map +1 -0
- package/dist/components/input/DatePicker.cjs +2 -0
- package/dist/components/input/DatePicker.cjs.map +1 -0
- package/dist/components/input/DatePicker.mjs +340 -0
- package/dist/components/input/DatePicker.mjs.map +1 -0
- package/dist/components/input/Dropdown.cjs +2 -0
- package/dist/components/input/Dropdown.cjs.map +1 -0
- package/dist/components/input/Dropdown.mjs +128 -0
- package/dist/components/input/Dropdown.mjs.map +1 -0
- package/dist/components/input/Field.cjs +2 -0
- package/dist/components/input/Field.cjs.map +1 -0
- package/dist/components/input/Field.mjs +200 -0
- package/dist/components/input/Field.mjs.map +1 -0
- package/dist/components/input/Input.cjs +2 -0
- package/dist/components/input/Input.cjs.map +1 -0
- package/dist/components/input/Input.mjs +81 -0
- package/dist/components/input/Input.mjs.map +1 -0
- package/dist/components/input/Label.cjs +2 -0
- package/dist/components/input/Label.cjs.map +1 -0
- package/dist/components/input/Label.mjs +28 -0
- package/dist/components/input/Label.mjs.map +1 -0
- package/dist/components/input/Option.cjs +2 -0
- package/dist/components/input/Option.cjs.map +1 -0
- package/dist/components/input/Option.mjs +169 -0
- package/dist/components/input/Option.mjs.map +1 -0
- package/dist/components/input/RadioGroup.cjs +2 -0
- package/dist/components/input/RadioGroup.cjs.map +1 -0
- package/dist/components/input/RadioGroup.mjs +139 -0
- package/dist/components/input/RadioGroup.mjs.map +1 -0
- package/dist/components/input/Rating.cjs +2 -0
- package/dist/components/input/Rating.cjs.map +1 -0
- package/dist/components/input/Rating.mjs +196 -0
- package/dist/components/input/Rating.mjs.map +1 -0
- package/dist/components/input/SearchBox.cjs +2 -0
- package/dist/components/input/SearchBox.cjs.map +1 -0
- package/dist/components/input/SearchBox.mjs +205 -0
- package/dist/components/input/SearchBox.mjs.map +1 -0
- package/dist/components/input/Select.cjs +2 -0
- package/dist/components/input/Select.cjs.map +1 -0
- package/dist/components/input/Select.mjs +33 -0
- package/dist/components/input/Select.mjs.map +1 -0
- package/dist/components/input/Slider.cjs +2 -0
- package/dist/components/input/Slider.cjs.map +1 -0
- package/dist/components/input/Slider.mjs +79 -0
- package/dist/components/input/Slider.mjs.map +1 -0
- package/dist/components/input/SpinButton.cjs +2 -0
- package/dist/components/input/SpinButton.cjs.map +1 -0
- package/dist/components/input/SpinButton.mjs +157 -0
- package/dist/components/input/SpinButton.mjs.map +1 -0
- package/dist/components/input/SwatchPicker.cjs +2 -0
- package/dist/components/input/SwatchPicker.cjs.map +1 -0
- package/dist/components/input/SwatchPicker.mjs +113 -0
- package/dist/components/input/SwatchPicker.mjs.map +1 -0
- package/dist/components/input/Switch.cjs +2 -0
- package/dist/components/input/Switch.cjs.map +1 -0
- package/dist/components/input/Switch.mjs +92 -0
- package/dist/components/input/Switch.mjs.map +1 -0
- package/dist/components/input/TagPicker.cjs +2 -0
- package/dist/components/input/TagPicker.cjs.map +1 -0
- package/dist/components/input/TagPicker.mjs +249 -0
- package/dist/components/input/TagPicker.mjs.map +1 -0
- package/dist/components/input/Textarea.cjs +2 -0
- package/dist/components/input/Textarea.cjs.map +1 -0
- package/dist/components/input/Textarea.mjs +32 -0
- package/dist/components/input/Textarea.mjs.map +1 -0
- package/dist/components/input/TimePicker.cjs +2 -0
- package/dist/components/input/TimePicker.cjs.map +1 -0
- package/dist/components/input/TimePicker.mjs +292 -0
- package/dist/components/input/TimePicker.mjs.map +1 -0
- package/dist/components/input/colorUtils.cjs +2 -0
- package/dist/components/input/colorUtils.cjs.map +1 -0
- package/dist/components/input/colorUtils.mjs +96 -0
- package/dist/components/input/colorUtils.mjs.map +1 -0
- package/dist/components/input/dateUtils.cjs +2 -0
- package/dist/components/input/dateUtils.cjs.map +1 -0
- package/dist/components/input/dateUtils.mjs +250 -0
- package/dist/components/input/dateUtils.mjs.map +1 -0
- package/dist/components/input/pickerStyles.cjs +2 -0
- package/dist/components/input/pickerStyles.cjs.map +1 -0
- package/dist/components/input/pickerStyles.mjs +10 -0
- package/dist/components/input/pickerStyles.mjs.map +1 -0
- package/dist/components/internal/HiddenInput.cjs +2 -0
- package/dist/components/internal/HiddenInput.cjs.map +1 -0
- package/dist/components/internal/HiddenInput.mjs +88 -0
- package/dist/components/internal/HiddenInput.mjs.map +1 -0
- package/dist/components/layout/Accordion.cjs +2 -0
- package/dist/components/layout/Accordion.cjs.map +1 -0
- package/dist/components/layout/Accordion.mjs +236 -0
- package/dist/components/layout/Accordion.mjs.map +1 -0
- package/dist/components/layout/Card.cjs +2 -0
- package/dist/components/layout/Card.cjs.map +1 -0
- package/dist/components/layout/Card.mjs +121 -0
- package/dist/components/layout/Card.mjs.map +1 -0
- package/dist/components/layout/Carousel.cjs +2 -0
- package/dist/components/layout/Carousel.cjs.map +1 -0
- package/dist/components/layout/Carousel.mjs +205 -0
- package/dist/components/layout/Carousel.mjs.map +1 -0
- package/dist/components/layout/Flex.cjs +2 -0
- package/dist/components/layout/Flex.cjs.map +1 -0
- package/dist/components/layout/Flex.mjs +54 -0
- package/dist/components/layout/Flex.mjs.map +1 -0
- package/dist/components/layout/Grid.cjs +2 -0
- package/dist/components/layout/Grid.cjs.map +1 -0
- package/dist/components/layout/Grid.mjs +62 -0
- package/dist/components/layout/Grid.mjs.map +1 -0
- package/dist/components/layout/Overflow.cjs +2 -0
- package/dist/components/layout/Overflow.cjs.map +1 -0
- package/dist/components/layout/Overflow.mjs +269 -0
- package/dist/components/layout/Overflow.mjs.map +1 -0
- package/dist/components/layout/Stack.cjs +2 -0
- package/dist/components/layout/Stack.cjs.map +1 -0
- package/dist/components/layout/Stack.mjs +39 -0
- package/dist/components/layout/Stack.mjs.map +1 -0
- package/dist/components/layout/TabList.cjs +2 -0
- package/dist/components/layout/TabList.cjs.map +1 -0
- package/dist/components/layout/TabList.mjs +238 -0
- package/dist/components/layout/TabList.mjs.map +1 -0
- package/dist/components/layout/Tree.cjs +2 -0
- package/dist/components/layout/Tree.cjs.map +1 -0
- package/dist/components/layout/Tree.mjs +220 -0
- package/dist/components/layout/Tree.mjs.map +1 -0
- package/dist/components/layout/disclosureIds.cjs +2 -0
- package/dist/components/layout/disclosureIds.cjs.map +1 -0
- package/dist/components/layout/disclosureIds.mjs +12 -0
- package/dist/components/layout/disclosureIds.mjs.map +1 -0
- package/dist/components/motion/Presence.cjs +2 -0
- package/dist/components/motion/Presence.cjs.map +1 -0
- package/dist/components/motion/Presence.mjs +35 -0
- package/dist/components/motion/Presence.mjs.map +1 -0
- package/dist/components/navigation/Breadcrumb.cjs +2 -0
- package/dist/components/navigation/Breadcrumb.cjs.map +1 -0
- package/dist/components/navigation/Breadcrumb.mjs +144 -0
- package/dist/components/navigation/Breadcrumb.mjs.map +1 -0
- package/dist/components/navigation/Menu.cjs +2 -0
- package/dist/components/navigation/Menu.cjs.map +1 -0
- package/dist/components/navigation/Menu.context.cjs +2 -0
- package/dist/components/navigation/Menu.context.cjs.map +1 -0
- package/dist/components/navigation/Menu.context.mjs +82 -0
- package/dist/components/navigation/Menu.context.mjs.map +1 -0
- package/dist/components/navigation/Menu.group.cjs +2 -0
- package/dist/components/navigation/Menu.group.cjs.map +1 -0
- package/dist/components/navigation/Menu.group.mjs +58 -0
- package/dist/components/navigation/Menu.group.mjs.map +1 -0
- package/dist/components/navigation/Menu.items.cjs +2 -0
- package/dist/components/navigation/Menu.items.cjs.map +1 -0
- package/dist/components/navigation/Menu.items.mjs +127 -0
- package/dist/components/navigation/Menu.items.mjs.map +1 -0
- package/dist/components/navigation/Menu.link.cjs +2 -0
- package/dist/components/navigation/Menu.link.cjs.map +1 -0
- package/dist/components/navigation/Menu.link.mjs +41 -0
- package/dist/components/navigation/Menu.link.mjs.map +1 -0
- package/dist/components/navigation/Menu.mjs +27 -0
- package/dist/components/navigation/Menu.mjs.map +1 -0
- package/dist/components/navigation/Menu.popover.cjs +2 -0
- package/dist/components/navigation/Menu.popover.cjs.map +1 -0
- package/dist/components/navigation/Menu.popover.mjs +231 -0
- package/dist/components/navigation/Menu.popover.mjs.map +1 -0
- package/dist/components/navigation/Menu.root.cjs +2 -0
- package/dist/components/navigation/Menu.root.cjs.map +1 -0
- package/dist/components/navigation/Menu.root.mjs +308 -0
- package/dist/components/navigation/Menu.root.mjs.map +1 -0
- package/dist/components/navigation/Menu.selectable.cjs +2 -0
- package/dist/components/navigation/Menu.selectable.cjs.map +1 -0
- package/dist/components/navigation/Menu.selectable.mjs +89 -0
- package/dist/components/navigation/Menu.selectable.mjs.map +1 -0
- package/dist/components/navigation/Menu.shared.cjs +2 -0
- package/dist/components/navigation/Menu.shared.cjs.map +1 -0
- package/dist/components/navigation/Menu.shared.mjs +23 -0
- package/dist/components/navigation/Menu.shared.mjs.map +1 -0
- package/dist/components/navigation/Menu.splitGroup.cjs +2 -0
- package/dist/components/navigation/Menu.splitGroup.cjs.map +1 -0
- package/dist/components/navigation/Menu.splitGroup.mjs +51 -0
- package/dist/components/navigation/Menu.splitGroup.mjs.map +1 -0
- package/dist/components/navigation/Menu.trigger.cjs +2 -0
- package/dist/components/navigation/Menu.trigger.cjs.map +1 -0
- package/dist/components/navigation/Menu.trigger.mjs +79 -0
- package/dist/components/navigation/Menu.trigger.mjs.map +1 -0
- package/dist/components/navigation/Nav.cjs +2 -0
- package/dist/components/navigation/Nav.cjs.map +1 -0
- package/dist/components/navigation/Nav.mjs +276 -0
- package/dist/components/navigation/Nav.mjs.map +1 -0
- package/dist/components/navigation/Pagination.cjs +2 -0
- package/dist/components/navigation/Pagination.cjs.map +1 -0
- package/dist/components/navigation/Pagination.mjs +110 -0
- package/dist/components/navigation/Pagination.mjs.map +1 -0
- package/dist/components/navigation/Stepper.cjs +2 -0
- package/dist/components/navigation/Stepper.cjs.map +1 -0
- package/dist/components/navigation/Stepper.mjs +204 -0
- package/dist/components/navigation/Stepper.mjs.map +1 -0
- package/dist/components/overlays/Dialog.cjs +2 -0
- package/dist/components/overlays/Dialog.cjs.map +1 -0
- package/dist/components/overlays/Dialog.mjs +180 -0
- package/dist/components/overlays/Dialog.mjs.map +1 -0
- package/dist/components/overlays/Dialog.shared.cjs +2 -0
- package/dist/components/overlays/Dialog.shared.cjs.map +1 -0
- package/dist/components/overlays/Dialog.shared.mjs +227 -0
- package/dist/components/overlays/Dialog.shared.mjs.map +1 -0
- package/dist/components/overlays/Drawer.cjs +2 -0
- package/dist/components/overlays/Drawer.cjs.map +1 -0
- package/dist/components/overlays/Drawer.mjs +192 -0
- package/dist/components/overlays/Drawer.mjs.map +1 -0
- package/dist/components/overlays/Popover.cjs +2 -0
- package/dist/components/overlays/Popover.cjs.map +1 -0
- package/dist/components/overlays/Popover.mjs +365 -0
- package/dist/components/overlays/Popover.mjs.map +1 -0
- package/dist/components/overlays/Popover.shared.cjs +2 -0
- package/dist/components/overlays/Popover.shared.cjs.map +1 -0
- package/dist/components/overlays/Popover.shared.mjs +182 -0
- package/dist/components/overlays/Popover.shared.mjs.map +1 -0
- package/dist/components/overlays/TeachingPopover.cjs +2 -0
- package/dist/components/overlays/TeachingPopover.cjs.map +1 -0
- package/dist/components/overlays/TeachingPopover.mjs +181 -0
- package/dist/components/overlays/TeachingPopover.mjs.map +1 -0
- package/dist/components/overlays/Tooltip.cjs +2 -0
- package/dist/components/overlays/Tooltip.cjs.map +1 -0
- package/dist/components/overlays/Tooltip.mjs +160 -0
- package/dist/components/overlays/Tooltip.mjs.map +1 -0
- package/dist/components/portal/Portal.cjs +2 -0
- package/dist/components/portal/Portal.cjs.map +1 -0
- package/dist/components/portal/Portal.mjs +45 -0
- package/dist/components/portal/Portal.mjs.map +1 -0
- package/dist/components/provider/WaveProvider.cjs +2 -0
- package/dist/components/provider/WaveProvider.cjs.map +1 -0
- package/dist/components/provider/WaveProvider.mjs +51 -0
- package/dist/components/provider/WaveProvider.mjs.map +1 -0
- package/dist/components/table/DataGrid.cjs +2 -0
- package/dist/components/table/DataGrid.cjs.map +1 -0
- package/dist/components/table/DataGrid.mjs +489 -0
- package/dist/components/table/DataGrid.mjs.map +1 -0
- package/dist/components/table/Table.cjs +2 -0
- package/dist/components/table/Table.cjs.map +1 -0
- package/dist/components/table/Table.mjs +99 -0
- package/dist/components/table/Table.mjs.map +1 -0
- package/dist/components/table/useGridNavigation.cjs +2 -0
- package/dist/components/table/useGridNavigation.cjs.map +1 -0
- package/dist/components/table/useGridNavigation.mjs +336 -0
- package/dist/components/table/useGridNavigation.mjs.map +1 -0
- package/dist/components/typography/Text.cjs +2 -0
- package/dist/components/typography/Text.cjs.map +1 -0
- package/dist/components/typography/Text.mjs +38 -0
- package/dist/components/typography/Text.mjs.map +1 -0
- package/dist/hooks/useAnnounce.cjs +2 -0
- package/dist/hooks/useAnnounce.cjs.map +1 -0
- package/dist/hooks/useAnnounce.mjs +88 -0
- package/dist/hooks/useAnnounce.mjs.map +1 -0
- package/dist/hooks/useCheckedValues.cjs +2 -0
- package/dist/hooks/useCheckedValues.cjs.map +1 -0
- package/dist/hooks/useCheckedValues.mjs +102 -0
- package/dist/hooks/useCheckedValues.mjs.map +1 -0
- package/dist/hooks/useContextMenuAnchor.cjs +2 -0
- package/dist/hooks/useContextMenuAnchor.cjs.map +1 -0
- package/dist/hooks/useContextMenuAnchor.mjs +132 -0
- package/dist/hooks/useContextMenuAnchor.mjs.map +1 -0
- package/dist/hooks/useControllable.cjs +2 -0
- package/dist/hooks/useControllable.cjs.map +1 -0
- package/dist/hooks/useControllable.mjs +37 -0
- package/dist/hooks/useControllable.mjs.map +1 -0
- package/dist/hooks/useDirection.cjs +2 -0
- package/dist/hooks/useDirection.cjs.map +1 -0
- package/dist/hooks/useDirection.mjs +57 -0
- package/dist/hooks/useDirection.mjs.map +1 -0
- package/dist/hooks/useDismiss.cjs +2 -0
- package/dist/hooks/useDismiss.cjs.map +1 -0
- package/dist/hooks/useDismiss.mjs +57 -0
- package/dist/hooks/useDismiss.mjs.map +1 -0
- package/dist/hooks/useEventCallback.cjs +2 -0
- package/dist/hooks/useEventCallback.cjs.map +1 -0
- package/dist/hooks/useEventCallback.mjs +16 -0
- package/dist/hooks/useEventCallback.mjs.map +1 -0
- package/dist/hooks/useFieldControl.cjs +2 -0
- package/dist/hooks/useFieldControl.cjs.map +1 -0
- package/dist/hooks/useFieldControl.mjs +62 -0
- package/dist/hooks/useFieldControl.mjs.map +1 -0
- package/dist/hooks/useFocusTrap.cjs +2 -0
- package/dist/hooks/useFocusTrap.cjs.map +1 -0
- package/dist/hooks/useFocusTrap.mjs +266 -0
- package/dist/hooks/useFocusTrap.mjs.map +1 -0
- package/dist/hooks/useFormReset.cjs +2 -0
- package/dist/hooks/useFormReset.cjs.map +1 -0
- package/dist/hooks/useFormReset.mjs +33 -0
- package/dist/hooks/useFormReset.mjs.map +1 -0
- package/dist/hooks/useHoverIntent.cjs +2 -0
- package/dist/hooks/useHoverIntent.cjs.map +1 -0
- package/dist/hooks/useHoverIntent.mjs +201 -0
- package/dist/hooks/useHoverIntent.mjs.map +1 -0
- package/dist/hooks/useId.cjs +2 -0
- package/dist/hooks/useId.cjs.map +1 -0
- package/dist/hooks/useId.mjs +11 -0
- package/dist/hooks/useId.mjs.map +1 -0
- package/dist/hooks/useIsClient.cjs +2 -0
- package/dist/hooks/useIsClient.cjs.map +1 -0
- package/dist/hooks/useIsClient.mjs +19 -0
- package/dist/hooks/useIsClient.mjs.map +1 -0
- package/dist/hooks/useListbox.cjs +2 -0
- package/dist/hooks/useListbox.cjs.map +1 -0
- package/dist/hooks/useListbox.mjs +492 -0
- package/dist/hooks/useListbox.mjs.map +1 -0
- package/dist/hooks/useMergedRefs.cjs +2 -0
- package/dist/hooks/useMergedRefs.cjs.map +1 -0
- package/dist/hooks/useMergedRefs.mjs +57 -0
- package/dist/hooks/useMergedRefs.mjs.map +1 -0
- package/dist/hooks/useModalIsolation.cjs +2 -0
- package/dist/hooks/useModalIsolation.cjs.map +1 -0
- package/dist/hooks/useModalIsolation.mjs +87 -0
- package/dist/hooks/useModalIsolation.mjs.map +1 -0
- package/dist/hooks/useModalLayer.cjs +2 -0
- package/dist/hooks/useModalLayer.cjs.map +1 -0
- package/dist/hooks/useModalLayer.mjs +30 -0
- package/dist/hooks/useModalLayer.mjs.map +1 -0
- package/dist/hooks/usePopupPosition.cjs +2 -0
- package/dist/hooks/usePopupPosition.cjs.map +1 -0
- package/dist/hooks/usePopupPosition.mjs +117 -0
- package/dist/hooks/usePopupPosition.mjs.map +1 -0
- package/dist/hooks/usePrefersReducedMotion.cjs +2 -0
- package/dist/hooks/usePrefersReducedMotion.cjs.map +1 -0
- package/dist/hooks/usePrefersReducedMotion.mjs +24 -0
- package/dist/hooks/usePrefersReducedMotion.mjs.map +1 -0
- package/dist/hooks/usePresence.cjs +2 -0
- package/dist/hooks/usePresence.cjs.map +1 -0
- package/dist/hooks/usePresence.mjs +136 -0
- package/dist/hooks/usePresence.mjs.map +1 -0
- package/dist/hooks/usePreserveFocus.cjs +2 -0
- package/dist/hooks/usePreserveFocus.cjs.map +1 -0
- package/dist/hooks/usePreserveFocus.mjs +50 -0
- package/dist/hooks/usePreserveFocus.mjs.map +1 -0
- package/dist/hooks/useRestoreFocus.cjs +2 -0
- package/dist/hooks/useRestoreFocus.cjs.map +1 -0
- package/dist/hooks/useRestoreFocus.mjs +271 -0
- package/dist/hooks/useRestoreFocus.mjs.map +1 -0
- package/dist/hooks/useRovingTabIndex.cjs +2 -0
- package/dist/hooks/useRovingTabIndex.cjs.map +1 -0
- package/dist/hooks/useRovingTabIndex.mjs +389 -0
- package/dist/hooks/useRovingTabIndex.mjs.map +1 -0
- package/dist/hooks/useScrollLock.cjs +2 -0
- package/dist/hooks/useScrollLock.cjs.map +1 -0
- package/dist/hooks/useScrollLock.mjs +71 -0
- package/dist/hooks/useScrollLock.mjs.map +1 -0
- package/dist/hooks/useTriggerElement.cjs +2 -0
- package/dist/hooks/useTriggerElement.cjs.map +1 -0
- package/dist/hooks/useTriggerElement.mjs +126 -0
- package/dist/hooks/useTriggerElement.mjs.map +1 -0
- package/dist/hooks/useTypeahead.cjs +2 -0
- package/dist/hooks/useTypeahead.cjs.map +1 -0
- package/dist/hooks/useTypeahead.mjs +38 -0
- package/dist/hooks/useTypeahead.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9099 -0
- package/dist/index.d.ts +7688 -1027
- package/dist/index.mjs +91 -5695
- package/dist/lib/aria.cjs +2 -0
- package/dist/lib/aria.cjs.map +1 -0
- package/dist/lib/aria.mjs +29 -0
- package/dist/lib/aria.mjs.map +1 -0
- package/dist/lib/children.cjs +2 -0
- package/dist/lib/children.cjs.map +1 -0
- package/dist/lib/children.mjs +37 -0
- package/dist/lib/children.mjs.map +1 -0
- package/dist/lib/cn.cjs +2 -0
- package/dist/lib/cn.cjs.map +1 -0
- package/dist/lib/cn.mjs +64 -0
- package/dist/lib/cn.mjs.map +1 -0
- package/dist/lib/composeEventHandlers.cjs +2 -0
- package/dist/lib/composeEventHandlers.cjs.map +1 -0
- package/dist/lib/composeEventHandlers.mjs +11 -0
- package/dist/lib/composeEventHandlers.mjs.map +1 -0
- package/dist/lib/dev.cjs +2 -0
- package/dist/lib/dev.cjs.map +1 -0
- package/dist/lib/dev.mjs +42 -0
- package/dist/lib/dev.mjs.map +1 -0
- package/dist/lib/direction.cjs +2 -0
- package/dist/lib/direction.cjs.map +1 -0
- package/dist/lib/direction.mjs +35 -0
- package/dist/lib/direction.mjs.map +1 -0
- package/dist/lib/events.cjs +2 -0
- package/dist/lib/events.cjs.map +1 -0
- package/dist/lib/events.mjs +31 -0
- package/dist/lib/events.mjs.map +1 -0
- package/dist/lib/focus.cjs +2 -0
- package/dist/lib/focus.cjs.map +1 -0
- package/dist/lib/focus.mjs +119 -0
- package/dist/lib/focus.mjs.map +1 -0
- package/dist/lib/globalRegistry.cjs +2 -0
- package/dist/lib/globalRegistry.cjs.map +1 -0
- package/dist/lib/globalRegistry.mjs +13 -0
- package/dist/lib/globalRegistry.mjs.map +1 -0
- package/dist/lib/icons.cjs +2 -0
- package/dist/lib/icons.cjs.map +1 -0
- package/dist/lib/icons.mjs +254 -0
- package/dist/lib/icons.mjs.map +1 -0
- package/dist/lib/labelInName.cjs +2 -0
- package/dist/lib/labelInName.cjs.map +1 -0
- package/dist/lib/labelInName.mjs +54 -0
- package/dist/lib/labelInName.mjs.map +1 -0
- package/dist/lib/layers.cjs +2 -0
- package/dist/lib/layers.cjs.map +1 -0
- package/dist/lib/layers.mjs +224 -0
- package/dist/lib/layers.mjs.map +1 -0
- package/dist/lib/mergeProps.cjs +2 -0
- package/dist/lib/mergeProps.cjs.map +1 -0
- package/dist/lib/mergeProps.mjs +21 -0
- package/dist/lib/mergeProps.mjs.map +1 -0
- package/dist/lib/mergeRefs.cjs +2 -0
- package/dist/lib/mergeRefs.cjs.map +1 -0
- package/dist/lib/mergeRefs.mjs +29 -0
- package/dist/lib/mergeRefs.mjs.map +1 -0
- package/dist/lib/renderTrigger.cjs +2 -0
- package/dist/lib/renderTrigger.cjs.map +1 -0
- package/dist/lib/renderTrigger.mjs +29 -0
- package/dist/lib/renderTrigger.mjs.map +1 -0
- package/dist/lib/slot.cjs +2 -0
- package/dist/lib/slot.cjs.map +1 -0
- package/dist/lib/slot.mjs +122 -0
- package/dist/lib/slot.mjs.map +1 -0
- package/dist/lib/styles.cjs +2 -0
- package/dist/lib/styles.cjs.map +1 -0
- package/dist/lib/styles.mjs +16 -0
- package/dist/lib/styles.mjs.map +1 -0
- package/dist/lib/theme.cjs +2 -0
- package/dist/lib/theme.cjs.map +1 -0
- package/dist/lib/theme.mjs +16 -0
- package/dist/lib/theme.mjs.map +1 -0
- package/dist/preflight.css +2 -0
- package/dist/styles.css +2 -0
- package/package.json +149 -100
- package/src/styles/animations.css +7 -39
- package/src/styles/base.css +103 -0
- package/src/styles/globals.css +10 -22
- package/src/styles/legacy-tokens.css +184 -0
- package/src/styles/preflight.css +7 -0
- package/src/styles/styles.css +32 -0
- package/src/styles/tailwind.css +17 -0
- package/src/styles/tokens.css +561 -221
- package/src/styles/variants.css +29 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn as e } from "../../lib/cn.mjs";
|
|
3
|
+
import { warnDeprecated as t } from "../../lib/dev.mjs";
|
|
4
|
+
import { composeEventHandlers as n } from "../../lib/composeEventHandlers.mjs";
|
|
5
|
+
import { useControllable as r } from "../../hooks/useControllable.mjs";
|
|
6
|
+
import { useMergedRefs as i } from "../../hooks/useMergedRefs.mjs";
|
|
7
|
+
import { useFieldContext as ee, useFieldControl as te } from "../../hooks/useFieldControl.mjs";
|
|
8
|
+
import { disabledStyles as a, inputFocus as o } from "../../lib/styles.mjs";
|
|
9
|
+
import { ChevronDownIcon as ne, DismissIcon as re } from "../../lib/icons.mjs";
|
|
10
|
+
import { isInvalidLook as s } from "./Input.mjs";
|
|
11
|
+
import { useFormReset as ie } from "../../hooks/useFormReset.mjs";
|
|
12
|
+
import { HiddenInput as ae } from "../internal/HiddenInput.mjs";
|
|
13
|
+
import { collectOptionLabels as oe, useListbox as se } from "../../hooks/useListbox.mjs";
|
|
14
|
+
import { pickerEndPadding as ce } from "./pickerStyles.mjs";
|
|
15
|
+
import { ListboxSurface as le, Option as c, OptionGroup as l, useListboxPopup as ue } from "./Option.mjs";
|
|
16
|
+
import * as u from "react";
|
|
17
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
18
|
+
//#region src/components/input/Dropdown.tsx
|
|
19
|
+
var p = (c) => {
|
|
20
|
+
let { value: l, defaultValue: p, onValueChange: m, onOptionSelect: h, open: g, defaultOpen: de, onOpenChange: fe, placeholder: pe = "Select an option", disabled: _ = !1, name: me, form: v, required: y, clearable: b = !1, labels: x, autoFocus: S, tabIndex: C, id: w, "aria-label": T, "aria-labelledby": E, "aria-describedby": D, "aria-invalid": O, "aria-required": k, "aria-errormessage": A, "aria-details": j, onFocus: M, onBlur: N, onKeyDown: P, onKeyUp: F, controlRef: I, className: L, children: R, ref: z, ...he } = c;
|
|
21
|
+
h !== void 0 && t("Dropdown", "onOptionSelect", "onValueChange");
|
|
22
|
+
let B = ee(), ge = y ?? B?.required ?? !1, V = te({
|
|
23
|
+
id: w,
|
|
24
|
+
"aria-label": T,
|
|
25
|
+
"aria-labelledby": E,
|
|
26
|
+
"aria-describedby": D,
|
|
27
|
+
"aria-invalid": O,
|
|
28
|
+
"aria-required": k ?? y
|
|
29
|
+
}), _e = s(!1, V["aria-invalid"]), [H, U] = r(l, p ?? "", m), [W, G] = r(g, (de ?? !1) && !_, fe), K = W && !_, q = _ && W;
|
|
30
|
+
u.useEffect(() => {
|
|
31
|
+
q && G(!1);
|
|
32
|
+
}, [q, G]);
|
|
33
|
+
let J = u.useRef(null), Y = u.useRef(null), ve = u.useMemo(() => oe(R), [R]), X = se({
|
|
34
|
+
open: K,
|
|
35
|
+
onOpenChange: (e) => G(e),
|
|
36
|
+
mode: "select-only",
|
|
37
|
+
selectedValues: H ? [H] : [],
|
|
38
|
+
onSelect: (e) => {
|
|
39
|
+
U(e), h?.(e);
|
|
40
|
+
},
|
|
41
|
+
idPrefix: "dropdown-listbox"
|
|
42
|
+
}), Z = K && X.items.length > 0, { layerId: ye, setReference: be, surfaceRef: xe, floatingProps: Se } = ue({
|
|
43
|
+
open: K,
|
|
44
|
+
surfaceOpen: Z,
|
|
45
|
+
onDismiss: () => G(!1),
|
|
46
|
+
rootRef: J,
|
|
47
|
+
anchorRef: Y
|
|
48
|
+
}), Ce = i(J, z), we = i(Y, I, be);
|
|
49
|
+
ie(Y, () => U(p ?? ""), v);
|
|
50
|
+
let Q = H ? X.getItem(H)?.label ?? ve.get(H) ?? "" : "", Te = (e) => {
|
|
51
|
+
if (e.key === "Escape" && K && !Z && !e.nativeEvent.isComposing) {
|
|
52
|
+
G(!1);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
X.onKeyDown(e);
|
|
56
|
+
}, Ee = () => {
|
|
57
|
+
U(""), G(!1), Y.current?.focus();
|
|
58
|
+
}, $ = b && H !== "", De = V["aria-label"] === void 0 ? V["aria-labelledby"] ?? B?.labelId : V["aria-labelledby"];
|
|
59
|
+
return /* @__PURE__ */ f("div", {
|
|
60
|
+
...he,
|
|
61
|
+
ref: Ce,
|
|
62
|
+
className: e("relative inline-flex flex-col", L),
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ f("div", {
|
|
65
|
+
className: "relative flex items-center",
|
|
66
|
+
children: [/* @__PURE__ */ f("button", {
|
|
67
|
+
type: "button",
|
|
68
|
+
...V,
|
|
69
|
+
...X.getComboboxProps(),
|
|
70
|
+
"aria-expanded": Z,
|
|
71
|
+
"aria-errormessage": A,
|
|
72
|
+
"aria-details": j,
|
|
73
|
+
ref: we,
|
|
74
|
+
disabled: _,
|
|
75
|
+
autoFocus: S,
|
|
76
|
+
tabIndex: C,
|
|
77
|
+
onClick: () => G((e) => !e),
|
|
78
|
+
onKeyDown: n(P, Te),
|
|
79
|
+
onKeyUp: n(F, X.onKeyUp),
|
|
80
|
+
onFocus: M,
|
|
81
|
+
onBlur: N,
|
|
82
|
+
className: e("relative flex h-8 w-full items-center justify-between rounded border border-input border-b-stroke-accessible bg-background px-3 py-0 text-start text-body-1 text-foreground", ce($ ? 2 : 1), o, a, _e && "border-destructive focus:border-b-destructive"),
|
|
83
|
+
children: [/* @__PURE__ */ d("span", {
|
|
84
|
+
className: e("truncate", !Q && "text-muted-foreground"),
|
|
85
|
+
children: Q || pe
|
|
86
|
+
}), /* @__PURE__ */ d(ne, { className: e("absolute end-3 transition-transform motion-reduce:transition-none", Z && "rotate-180") })]
|
|
87
|
+
}), $ && /* @__PURE__ */ d("button", {
|
|
88
|
+
type: "button",
|
|
89
|
+
"aria-label": x?.clear ?? "Clear selection",
|
|
90
|
+
disabled: _,
|
|
91
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
92
|
+
onClick: Ee,
|
|
93
|
+
className: e("absolute flex h-6 w-6 items-center justify-center rounded bg-transparent p-0 text-muted-foreground not-disabled:not-aria-disabled:hover:bg-subtle-hover not-disabled:not-aria-disabled:hover:text-foreground", "end-7", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", "disabled:cursor-not-allowed disabled:opacity-50 aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:focus-visible:opacity-100"),
|
|
94
|
+
children: /* @__PURE__ */ d(re, {})
|
|
95
|
+
})]
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ d(le, {
|
|
98
|
+
listbox: X,
|
|
99
|
+
layerId: ye,
|
|
100
|
+
surfaceRef: xe,
|
|
101
|
+
floatingProps: Se,
|
|
102
|
+
open: K,
|
|
103
|
+
expanded: Z,
|
|
104
|
+
"aria-label": V["aria-label"],
|
|
105
|
+
"aria-labelledby": De,
|
|
106
|
+
children: R
|
|
107
|
+
}),
|
|
108
|
+
/* @__PURE__ */ d(ae, {
|
|
109
|
+
name: me,
|
|
110
|
+
form: v,
|
|
111
|
+
disabled: _,
|
|
112
|
+
value: H,
|
|
113
|
+
type: "text",
|
|
114
|
+
required: ge,
|
|
115
|
+
onInvalid: () => Y.current?.focus()
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
p.displayName = "Dropdown";
|
|
121
|
+
var m = c, h = l, g = /* @__PURE__ */ Object.assign(p, {
|
|
122
|
+
Option: c,
|
|
123
|
+
OptionGroup: l
|
|
124
|
+
});
|
|
125
|
+
//#endregion
|
|
126
|
+
export { g as Dropdown, m as DropdownOption, h as DropdownOptionGroup };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=Dropdown.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dropdown.mjs","names":["React","DropdownRoot","valueProp","openProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","ariaErrorMessage","ariaDetails","rest","props","onOptionSelect","warnDeprecated","field","useFieldContext","isRequired","required","fieldProps","useFieldControl","invalidLook","isInvalidLook","value","setValue","useControllable","defaultValue","onValueChange","openState","setOpen","defaultOpen","disabled","onOpenChange","open","lockedOpen","rootRef","buttonRef","optionLabels","collectOptionLabels","children","listbox","useListbox","next","expanded","useListboxPopup","rootMergedRef","useMergedRefs","ref","buttonMergedRef","controlRef","setReference","form","displayText","handleKeyDown","event","handleClear","showClear","clearable","listLabelledBy","cn","className","current","composeEventHandlers","onKeyDown","onKeyUp","pickerEndPadding","inputFocus","disabledStyles","placeholder","ChevronDownIcon","labels","DismissIcon","ListboxSurface","HiddenInput","DropdownOption","Option","DropdownOptionGroup","OptionGroup","Dropdown"],"sources":["../../../src/components/input/Dropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnDeprecated } from '../../lib/dev';\nimport { ChevronDownIcon, DismissIcon } from '../../lib/icons';\nimport { disabledStyles, focusRing, inputFocus, inputInvalid } from '../../lib/styles';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { collectOptionLabels, useListbox } from '../../hooks/useListbox';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\nimport { isInvalidLook } from './Input';\nimport { ListboxSurface, Option, OptionGroup, useListboxPopup } from './Option';\nimport { PICKER_ICON_BUTTON_CLASSES, pickerEndPadding } from './pickerStyles';\nimport type { RoutedHandlers } from './routedHandlers';\n\n/* ------------------------------------------------------------------ */\n/* Dropdown */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Dropdown's built-in texts, for localization. Each member is optional and falls back to its\n * English default.\n */\nexport interface DropdownLabels {\n /** Name of the clear button (`clearable`).\n * @default 'Clear selection'\n */\n clear?: string;\n}\n\n/** Properties for the Dropdown component. */\nexport interface DropdownProps extends Omit<\n React.HTMLAttributes<HTMLDivElement>,\n 'onChange' | 'defaultValue' | RoutedHandlers\n> {\n /** Controlled selected value (`''` for none). */\n value?: string;\n /**\n * Initial selected value for uncontrolled usage.\n * @default ''\n */\n defaultValue?: string;\n /** Called with the new value when a different option is selected. */\n onValueChange?: (value: string) => void;\n /**\n * Called on every option activation, also when the current option is selected again.\n * @deprecated Use `onValueChange`.\n */\n onOptionSelect?: (value: string) => void;\n /**\n * Controlled open state of the listbox. The list renders only in the browser: an open dropdown\n * is closed in the server HTML and opens once it has hydrated.\n */\n open?: boolean;\n /**\n * Initial open state for uncontrolled usage. A dropdown that starts disabled starts closed. The\n * list renders only in the browser: it is closed in the server HTML and opens once the dropdown\n * has hydrated.\n * @default false\n */\n defaultOpen?: boolean;\n /** Called when the listbox opens or closes. */\n onOpenChange?: (open: boolean) => void;\n /**\n * Placeholder text shown when no value is selected. It is not an accessible name: label the\n * Dropdown with a `Field`, `aria-label` or `aria-labelledby`.\n * @default 'Select an option'\n */\n placeholder?: string;\n /**\n * Whether the dropdown is disabled and non-interactive. Turning it on while the listbox is open\n * closes it (`onOpenChange(false)`).\n * @default false\n */\n disabled?: boolean;\n /** Name of the value in form submissions (renders a hidden input). */\n name?: string;\n /** Id of the form the value belongs to, when the Dropdown is outside it. */\n form?: string;\n /** A value is required to submit the form (native constraint validation). */\n required?: boolean;\n /**\n * Shows a clear button while a value is selected (shown disabled while `disabled`). It clears\n * the value, closes the list and moves focus to the combobox button. It is a tab stop after it.\n * @default false\n */\n clearable?: boolean;\n /** The name of the clear button, for localization. Unset members keep their English defaults. */\n labels?: DropdownLabels;\n /** Called when the `<button role=\"combobox\">` receives focus (the root keeps other handlers). */\n onFocus?: React.FocusEventHandler<HTMLButtonElement>;\n /** Called when the `<button role=\"combobox\">` loses focus. */\n onBlur?: React.FocusEventHandler<HTMLButtonElement>;\n /**\n * Called on a key press on the `<button role=\"combobox\">`, before the built-in listbox keys;\n * `event.preventDefault()` skips them.\n */\n onKeyDown?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Called when a key is released on the `<button role=\"combobox\">`. */\n onKeyUp?: React.KeyboardEventHandler<HTMLButtonElement>;\n /** Ref to the `<button role=\"combobox\">` (the focusable element). */\n controlRef?: React.Ref<HTMLButtonElement>;\n /** Ref to the root `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\nconst DropdownRoot = (props: DropdownProps) => {\n const {\n value: valueProp,\n defaultValue,\n onValueChange,\n onOptionSelect,\n open: openProp,\n defaultOpen,\n onOpenChange,\n placeholder = 'Select an option',\n disabled = false,\n name,\n form,\n required,\n clearable = false,\n labels,\n autoFocus,\n tabIndex,\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 onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n controlRef,\n className,\n children,\n ref,\n ...rest\n } = props;\n\n if (onOptionSelect !== undefined) warnDeprecated('Dropdown', 'onOptionSelect', 'onValueChange');\n\n const field = useFieldContext();\n const isRequired = required ?? field?.required ?? false;\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 matches\n // `isRequired`.\n 'aria-required': ariaRequired ?? required,\n });\n // The error look follows the resolved state: the consumer's `aria-invalid` or the Field's.\n const invalidLook = isInvalidLook(false, fieldProps['aria-invalid']);\n\n const [value, setValue] = useControllable(valueProp, defaultValue ?? '', onValueChange);\n // A dropdown that starts disabled never shows its list, so it starts closed (no close to report\n // later).\n const [openState, setOpen] = useControllable(\n openProp,\n (defaultOpen ?? false) && !disabled,\n onOpenChange,\n );\n const open = openState && !disabled;\n // Disabling also closes the list itself, not only the derived `open`, so enabling it again does\n // not reopen it without a user action. The close is reported through onOpenChange (a consumer\n // callback from an effect, C-HOOKS); a controlled `open` that stays true is not shown meanwhile.\n const lockedOpen = disabled && openState;\n React.useEffect(() => {\n if (lockedOpen) setOpen(false);\n }, [lockedOpen, setOpen]);\n\n const rootRef = React.useRef<HTMLDivElement | null>(null);\n const buttonRef = React.useRef<HTMLButtonElement | null>(null);\n\n const optionLabels = React.useMemo(() => collectOptionLabels(children), [children]);\n\n const listbox = useListbox({\n open,\n onOpenChange: (next) => setOpen(next),\n mode: 'select-only',\n selectedValues: value ? [value] : [],\n onSelect: (next) => {\n setValue(next);\n onOptionSelect?.(next);\n },\n idPrefix: 'dropdown-listbox',\n });\n\n const expanded = open && listbox.items.length > 0;\n const { layerId, setReference, surfaceRef, floatingProps } = useListboxPopup({\n open,\n surfaceOpen: expanded,\n onDismiss: () => setOpen(false),\n rootRef,\n anchorRef: buttonRef,\n });\n\n const rootMergedRef = useMergedRefs<HTMLDivElement>(rootRef, ref);\n const buttonMergedRef = useMergedRefs<HTMLButtonElement>(buttonRef, controlRef, setReference);\n\n useFormReset(buttonRef, () => setValue(defaultValue ?? ''), form);\n\n const displayText = value ? (listbox.getItem(value)?.label ?? optionLabels.get(value) ?? '') : '';\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === 'Escape' && open && !expanded && !event.nativeEvent.isComposing) {\n // Open with nothing shown (no options): close, but leave Escape to an enclosing layer\n // (overlays#1) instead of consuming it for an invisible list.\n setOpen(false);\n return;\n }\n listbox.onKeyDown(event);\n };\n\n // The button disappears with the value, so focus moves to the combobox explicitly (C-DISABLED).\n const handleClear = () => {\n setValue('');\n setOpen(false);\n buttonRef.current?.focus();\n };\n\n const showClear = clearable && value !== '';\n\n const listLabelledBy =\n fieldProps['aria-label'] === undefined\n ? (fieldProps['aria-labelledby'] ?? field?.labelId)\n : fieldProps['aria-labelledby'];\n\n return (\n <div {...rest} ref={rootMergedRef} className={cn('relative inline-flex flex-col', className)}>\n <div className=\"relative flex items-center\">\n <button\n type=\"button\"\n {...fieldProps}\n {...listbox.getComboboxProps()}\n aria-expanded={expanded}\n aria-errormessage={ariaErrorMessage}\n aria-details={ariaDetails}\n ref={buttonMergedRef}\n disabled={disabled}\n autoFocus={autoFocus}\n tabIndex={tabIndex}\n onClick={() => setOpen((current) => !current)}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, listbox.onKeyUp)}\n onFocus={onFocus}\n onBlur={onBlur}\n className={cn(\n // Every padding is set here (C-NATIVE), not left to an app-wide `button` rule. The end\n // padding keeps the text clear of the chevron (and of the clear button while it shows).\n 'relative flex h-8 w-full items-center justify-between rounded border border-input border-b-stroke-accessible bg-background px-3 py-0 text-start text-body-1 text-foreground',\n pickerEndPadding(showClear ? 2 : 1),\n inputFocus,\n disabledStyles,\n invalidLook && inputInvalid,\n )}\n >\n <span className={cn('truncate', !displayText && 'text-muted-foreground')}>\n {displayText || placeholder}\n </span>\n <ChevronDownIcon\n className={cn(\n 'absolute end-3 transition-transform motion-reduce:transition-none',\n expanded && 'rotate-180',\n )}\n />\n </button>\n {showClear && (\n <button\n type=\"button\"\n aria-label={labels?.clear ?? 'Clear selection'}\n disabled={disabled}\n // Keeps focus on the combobox while the pointer clears it.\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n className={cn(PICKER_ICON_BUTTON_CLASSES, 'end-7', focusRing, disabledStyles)}\n >\n <DismissIcon />\n </button>\n )}\n </div>\n <ListboxSurface\n listbox={listbox}\n layerId={layerId}\n surfaceRef={surfaceRef}\n floatingProps={floatingProps}\n open={open}\n expanded={expanded}\n aria-label={fieldProps['aria-label']}\n aria-labelledby={listLabelledBy}\n >\n {children}\n </ListboxSurface>\n <HiddenInput\n name={name}\n form={form}\n disabled={disabled}\n value={value}\n type=\"text\"\n required={isRequired}\n onInvalid={() => buttonRef.current?.focus()}\n />\n </div>\n );\n};\nDropdownRoot.displayName = 'Dropdown';\n\n/** Flat name of `Dropdown.Option` for React Server Components. */\nexport const DropdownOption = Option;\n/** Flat name of `Dropdown.OptionGroup` for React Server Components. */\nexport const DropdownOptionGroup = OptionGroup;\n\n/**\n * A select-only combobox (APG): a button that opens a listbox of `Option`s. Enter, Space,\n * ArrowDown/ArrowUp, Home/End and typing a character open it and move the highlight\n * (`aria-activedescendant`); Enter/Space select, Tab selects the highlighted option and moves on,\n * Escape closes. `clearable` adds a clear button, a tab stop after the combobox button; both sit\n * in a wrapper `<div>` inside the root.\n *\n * The `<button>` receives `id`, `aria-label`, `aria-labelledby`, `aria-describedby`,\n * `aria-invalid`, `aria-required`, `aria-errormessage`, `aria-details`, `tabIndex`, `autoFocus`\n * and `onFocus`/`onBlur`/`onKeyDown`/`onKeyUp`. `ref`, `className`, `style`, other `aria-*`\n * attributes and the remaining props stay on the root `<div>`. Inside a `Field` the button is\n * labelled and described by it — otherwise give it an `aria-label`. It shows the error look\n * whenever it ends up `aria-invalid` (its own `aria-invalid` or a `Field` error). With\n * `name`/`required` the value takes part in form submission, validation and reset. The open\n * listbox renders in a portal; while closed it stays in the DOM, hidden.\n *\n * Sub-components: `Dropdown.Option`, `Dropdown.OptionGroup`. React Server Components import the\n * flat names `DropdownOption` / `DropdownOptionGroup` (dotted access needs a client file).\n */\nexport const Dropdown = /* @__PURE__ */ Object.assign(DropdownRoot, {\n Option,\n OptionGroup,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4GA,IAAMC,KAAgB,MAAyB;CAC7C,IAAM,EACJ,OAAOC,GACP,iBACA,kBACA,mBACA,MAAMC,GACN,iBACA,kBACA,kBAAc,oBACd,cAAW,IACX,UACA,SACA,aACA,eAAY,IACZ,WACA,cACA,aACA,OACA,cAAcC,GACd,mBAAmBC,GACnB,oBAAoBC,GACpB,gBAAgBC,GAChB,iBAAiBC,GACjB,qBAAqBC,GACrB,gBAAgBC,GAChB,YACA,WACA,cACA,YACA,eACA,cACA,aACA,QACA,GAAGC,OACDC;CAEJ,AAAIC,MAAmB,KAAA,KAAWC,EAAe,YAAY,kBAAkB,eAAe;CAE9F,IAAMC,IAAQC,GAAgB,GACxBC,KAAaC,KAAYH,GAAO,YAAY,IAC5CI,IAAaC,GAAgB;EACjC;EACA,cAAchB;EACd,mBAAmBC;EACnB,oBAAoBC;EACpB,gBAAgBC;EAGhB,iBAAiBC,KAAgBU;CACnC,CAAC,GAEKG,KAAcC,EAAc,IAAOH,EAAW,eAAe,GAE7D,CAACI,GAAOC,KAAYC,EAAgBvB,GAAWwB,KAAgB,IAAIC,CAAa,GAGhF,CAACC,GAAWC,KAAWJ,EAC3BtB,IACC2B,MAAe,OAAU,CAACC,GAC3BC,EACF,GACMC,IAAO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C,IAA2B,uBAAO,OAAO7E,GAAc;CAClE;CACA;AACF,CAAC"}
|
|
@@ -0,0 +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"),i=require("../../hooks/useId.cjs"),a=require("../../lib/aria.cjs"),o=require("../../hooks/useFieldControl.cjs"),s=require("../../lib/icons.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("react/jsx-runtime");var u=new Set([`button`,`input`,`meter`,`output`,`progress`,`select`,`textarea`]),d=new Set([`button`,`image`,`reset`,`submit`]),f=new Set([`caption`,`code`,`deletion`,`emphasis`,`generic`,`insertion`,`none`,`paragraph`,`presentation`,`strong`,`subscript`,`superscript`]),p=new Set([`checkbox`,`columnheader`,`combobox`,`gridcell`,`listbox`,`radiogroup`,`rowheader`,`searchbox`,`spinbutton`,`switch`,`textbox`,`tree`,`treegrid`]);function m(e){if(typeof e==`string`)return e.trim().split(/\s+/)[0]?.toLowerCase()||void 0}function h(e){return typeof e==`string`&&e.includes(`-`)}function g(e,t){return e===`select`||e===`textarea`?!0:e===`input`?typeof t!=`string`||!d.has(t.trim().toLowerCase()):!1}function _(e){if(typeof e.type!=`string`)return!0;let t=m(e.props.role);return t===void 0?g(e.type,e.props.type):p.has(t)}function v(e){if(e.type===c.Fragment)return;if(typeof e.type!=`string`||u.has(e.type))return`label-for`;let t=m(e.props.role);return t===void 0?h(e.type)?`label-for`:void 0:f.has(t)?void 0:`labelledby`}function y(e){let t,n=0;c.Children.forEach(e,e=>{c.isValidElement(e)&&(n+=1,t===void 0&&(t=e))});let r=t?v(t):void 0;return{target:r?t:void 0,mode:r,elementCount:n}}function b(e,t){let{target:n,mode:r}=y(e);if(!n||!r)return c.Children.map(e,e=>e);let i=n.props,o=!h(n.type)||`true`,s={};return r===`label-for`?i.id===void 0&&(s.id=t.controlId):t.labelId!==void 0&&i[`aria-label`]===void 0&&(s[`aria-labelledby`]=a.joinIds(i[`aria-labelledby`],t.labelId)),(t.messageId||t.hintId)&&(s[`aria-describedby`]=a.joinIds(i[`aria-describedby`],t.messageId,t.hintId)),t.invalid&&i[`aria-invalid`]===void 0&&(s[`aria-invalid`]=o),t.required&&i.required!==!1&&(i[`aria-required`]===void 0&&_(n)&&(s[`aria-required`]=o),typeof n.type==`string`&&g(n.type,i.type)&&i.required===void 0&&(s.required=!0)),c.Children.map(e,e=>e===n?c.cloneElement(n,s):e)}function x(e){let{target:t,mode:n,elementCount:r}=y(e),i=n===`label-for`;return{elementCount:r,targetId:i?t?.props.id:void 0,controlIdAssigned:i}}var S={error:s.ErrorIcon,warning:s.WarningIcon,success:s.SuccessIcon,none:null},C={error:`text-error`,warning:`text-warning-tint-foreground`,success:`text-success-tint-foreground`,none:`text-muted-foreground`},w=`[&>:first-child:has([role=checkbox],[role=switch],label>[role=radio])]:py-1.5`,T=`mt-0.5 inline-flex shrink-0`;function E(e,t){if(t!==void 0)return r.slotRendersContent(t)?r.renderSlot(t,`span`,T,{"aria-hidden":!0}):null;let n=S[e];return n?(0,l.jsx)(`span`,{"aria-hidden":`true`,className:T,children:(0,l.jsx)(n,{size:12})}):null}var D=({label:e,hint:a,error:s,validationState:u,validationMessage:d,validationMessageIcon:f,orientation:p=`vertical`,required:m=!1,htmlFor:h,className:g,children:_,ref:v,...y})=>{let S=i.useId(`field`),[T]=c.useState(o.createFieldControlIdClaim),{elementCount:D,targetId:O,controlIdAssigned:k}=x(_),A=r.slotRendersContent(s),j=s===!0||A,M=r.slotRendersContent(d),N=j?`error`:u??(M?`error`:`none`),P=j?A?s:void 0:d,F=j?A:M,I=N===`error`,L=r.slotRendersContent(a),R=j&&(M||u!==void 0&&u!==`error`),z=O??h??S,B=r.slotRendersContent(e),V=B?`${S}-label`:void 0,H=F?`${S}-${I?`error`:`message`}`:void 0,U=I?H:void 0,W=I&&F,G=L?`${S}-hint`:void 0;c.useEffect(()=>{D>1&&n.warnOnce(`Field:multiple-children`,`Field: only the first element child receives the Field's id and ARIA attributes; the other ${D-1} element child(ren) are rendered unchanged. Wrap each control in its own Field.`)},[D]),c.useEffect(()=>{R&&n.warnOnce(`Field:error-and-validation`,"Field: `error` and `validationMessage`/`validationState` are both set; `error` wins. Use one of them.")},[R]);let K=c.useMemo(()=>({controlId:z,labelId:V,hintId:G,errorId:U,invalid:I,required:m,hasErrorMessage:W,controlIdAssigned:k,controlIdClaim:T,validationState:N,validationMessageId:H}),[z,V,G,U,I,m,W,k,T,N,H]),q=b(_,{controlId:z,labelId:V,messageId:H,hintId:G,invalid:I,required:m}),J=p===`horizontal`,Y=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(o.FieldContext.Provider,{value:K,children:q}),F?(0,l.jsxs)(`p`,{id:H,role:N===`error`||N===`warning`?`alert`:void 0,"data-validation-state":N,className:t.cn(`mt-1 flex items-start gap-1 text-caption-1`,C[N]),children:[E(N,f),(0,l.jsx)(`span`,{children:r.materialiseSlotContent(P)})]},`message-${N}`):null,L?(0,l.jsx)(`p`,{id:G,className:`mt-1 text-caption-1 text-muted-foreground`,children:r.materialiseSlotContent(a)},`hint`):null]});return(0,l.jsxs)(`div`,{ref:v,"data-orientation":p,"data-validation-state":N,className:t.cn(`flex`,J?`flex-row items-start gap-x-3`:`flex-col`,g),...y,children:[B?(0,l.jsxs)(`label`,{id:V,htmlFor:z,className:t.cn(`mb-1 text-body-1 font-semibold text-foreground`,J&&`mb-0 shrink-0 basis-1/3 pt-1.5`),children:[r.materialiseSlotContent(e),m&&(0,l.jsx)(`span`,{"aria-hidden":`true`,className:`ms-0.5 text-error`,children:`*`})]}):null,J?(0,l.jsx)(`div`,{className:t.cn(`flex min-w-0 flex-1 flex-col`,w),children:Y}):Y]})};D.displayName=`Field`,exports.Field=D;
|
|
2
|
+
//# sourceMappingURL=Field.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.cjs","names":["React","joinIds","ErrorIcon","WarningIcon","SuccessIcon","slotRendersContent","renderSlot","useId","createFieldControlIdClaim","_Fragment","FieldContext","cn","materialiseSlotContent","require_runtime","require_cn","require_dev","require_slot","require_useId","require_aria","require_useFieldControl","require_icons","react","react_jsx_runtime","LABELABLE_ELEMENTS","BUTTON_INPUT_TYPES","UNNAMED_ROLES","ARIA_REQUIRED_ROLES","explicitRole","role","isCustomElement","type","isNativeValueControl","tag","inputType","supportsAriaRequired","child","getMergeMode","inspectChildren","first","elementCount","children","mode","mergeIntoFirstChild","target","childProps","ariaTrue","injected","state","getChildInfo","assigned","MESSAGE_ICONS","MESSAGE_COLORS","SHORT_ROW_FIRST_CHILD","MESSAGE_ICON_CLASSES","renderMessageIcon","icon","Icon","Field","rest","fieldId","controlIdClaim","errorRendersContent","error","usesError","validationMessageRendersContent","validationMessage","validationState","message","hasMessage","invalid","hasHint","hint","errorAndValidation","controlId","targetId","htmlFor","hasLabel","label","labelId","messageId","errorId","hasErrorMessage","hintId","context","required","controlIdAssigned","content","horizontal","orientation","control","validationMessageIcon","className"],"sources":["../../../src/components/input/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { joinIds } from '../../lib/aria';\nimport { warnOnce } from '../../lib/dev';\nimport { ErrorIcon, SuccessIcon, WarningIcon, type IconComponent } from '../../lib/icons';\nimport { materialiseSlotContent, renderSlot, slotRendersContent, type Slot } from '../../lib/slot';\nimport type { Orientation, ValidationState } from '../../lib/types';\nimport { useId } from '../../hooks/useId';\nimport {\n FieldContext,\n createFieldControlIdClaim,\n type FieldContextValue,\n} from '../../hooks/useFieldControl';\n\n/** Props Field reads from and merges into its first element child. */\ninterface InjectedFieldProps {\n id?: string;\n role?: string;\n type?: string;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n 'aria-required'?: React.AriaAttributes['aria-required'];\n required?: boolean;\n}\n\n/** Properties for the Field component. */\nexport interface FieldProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Label displayed above the control (beside it with `orientation=\"horizontal\"`); names the\n * control.\n */\n label?: React.ReactNode;\n /** Hint shown below the control, after any validation message; describes the control. */\n hint?: React.ReactNode;\n /**\n * Validation error. Content is rendered below the control in a `role=\"alert\"` element that\n * describes the control, and the control is marked `aria-invalid`. `true` marks the control\n * invalid without a message. A value that renders nothing (`null`, `false`, `''`, or an array of\n * only those, such as an empty `errors.map(…)`) is no error; `0` is content.\n *\n * Shorthand for `validationState=\"error\"` with this message; wins over `validationMessage` and\n * `validationState` (development warning when both are set).\n */\n error?: React.ReactNode;\n /**\n * Validation state of `validationMessage`: `error` marks the control invalid (`aria-invalid`) and\n * announces the message (`role=\"alert\"`); `warning` announces it without marking the control\n * invalid; `success` and `none` show it without announcing. Default: `'error'` when\n * `validationMessage` renders content, else `'none'`. Ignored while `error` is set.\n */\n validationState?: ValidationState;\n /**\n * Message below the control, styled and announced by `validationState`; it describes the control\n * (`aria-describedby`). `error` is the shorthand for an error message and wins over this prop.\n */\n validationMessage?: React.ReactNode;\n /**\n * Icon before the message. Default: an error, warning or success glyph per state; none for\n * `'none'`. `null` (or content that renders nothing) shows no icon. Decorative (`aria-hidden`).\n */\n validationMessageIcon?: Slot<'span'>;\n /**\n * `vertical`: the label above the control. `horizontal`: the label in a start column (a third\n * of the width) beside the control; the message and the hint stay below the control. The\n * label's first line lines up with a 32px control (Input, Select, …) and with the first line of\n * a Checkbox, Switch or RadioGroup, which gets 6px of padding above and below for it. The\n * horizontal layout wraps the control in a column, so changing `orientation` on a mounted Field\n * remounts the control: an uncontrolled control loses its state and focus (control it, or keep\n * one orientation while the Field is mounted).\n * @default 'vertical'\n */\n orientation?: Orientation;\n /**\n * Whether the field is required: shows a decorative asterisk next to the label, sets\n * `aria-required`, and turns on native constraint validation. `<input>`, `<select>`,\n * `<textarea>` and Input, Select, Textarea, Slider, SearchBox and SpinButton get the native\n * `required` attribute. Checkbox, Switch, RadioGroup, Rating, ColorPicker, SwatchPicker,\n * Combobox, Dropdown, TagPicker, DatePicker and TimePicker render a hidden required input (with\n * or without `name`), so submit is blocked until they are checked, switched on or have a value.\n * An explicit `required={false}` on the control wins, including for `aria-required`.\n */\n required?: boolean;\n /**\n * The id of the control the label points at, when the control has no `id` of its own\n * (default: a generated id).\n */\n htmlFor?: string;\n /** Ref to the root `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/** Intrinsic elements a `<label htmlFor>` can name (HTML \"labelable elements\"). */\nconst LABELABLE_ELEMENTS: ReadonlySet<string> = new Set([\n 'button',\n 'input',\n 'meter',\n 'output',\n 'progress',\n 'select',\n 'textarea',\n]);\n\n/** `<input>` types whose implicit role is `button`: they take neither `aria-required` nor `required`. */\nconst BUTTON_INPUT_TYPES: ReadonlySet<string> = new Set(['button', 'image', 'reset', 'submit']);\n\n/**\n * Roles that cannot be named (ARIA 1.2 \"name prohibited\") or that remove semantics: an element\n * with one of them is a layout wrapper, not a widget, and Field leaves it alone.\n */\nconst UNNAMED_ROLES: ReadonlySet<string> = new Set([\n 'caption',\n 'code',\n 'deletion',\n 'emphasis',\n 'generic',\n 'insertion',\n 'none',\n 'paragraph',\n 'presentation',\n 'strong',\n 'subscript',\n 'superscript',\n]);\n\n/** Roles that support `aria-required` (ARIA 1.2, including the roles that inherit it). */\nconst ARIA_REQUIRED_ROLES: ReadonlySet<string> = new Set([\n 'checkbox',\n 'columnheader',\n 'combobox',\n 'gridcell',\n 'listbox',\n 'radiogroup',\n 'rowheader',\n 'searchbox',\n 'spinbutton',\n 'switch',\n 'textbox',\n 'tree',\n 'treegrid',\n]);\n\n/**\n * How Field merges into its first element child:\n * - `label-for`: components (library controls, consumer inputs, wrappers such as Tooltip),\n * labelable intrinsic elements (`<input>`, `<select>`, `<button>`, …) and role-less custom\n * elements (`<my-text-field>`, possibly form-associated). The child receives the `id` the\n * `<label htmlFor>` points at (unless it has its own id, which the label then uses).\n * - `labelledby`: an intrinsic element with an explicit widget `role` (a consumer's own\n * `<div role=\"radiogroup\">`). A `<label htmlFor>` cannot name it, so it is named through\n * `aria-labelledby` and receives no `id` (a library control inside it keeps the control id).\n */\ntype MergeMode = 'label-for' | 'labelledby';\n\n/** The first token of an explicit `role` attribute (lower case), or `undefined`. */\nfunction explicitRole(role: unknown): string | undefined {\n if (typeof role !== 'string') return undefined;\n return role.trim().split(/\\s+/)[0]?.toLowerCase() || undefined;\n}\n\n/** Whether `type` is an autonomous custom element (`<my-text-field>`): its tag name has a hyphen. */\nfunction isCustomElement(type: unknown): type is string {\n return typeof type === 'string' && type.includes('-');\n}\n\n/**\n * Whether an intrinsic element is a native form control that takes a value (`<select>`,\n * `<textarea>`, or an `<input>` that is not a button): it takes the native `required` attribute\n * and, without an explicit role, `aria-required`.\n */\nfunction isNativeValueControl(tag: string, inputType: unknown): boolean {\n if (tag === 'select' || tag === 'textarea') return true;\n if (tag !== 'input') return false;\n return typeof inputType !== 'string' || !BUTTON_INPUT_TYPES.has(inputType.trim().toLowerCase());\n}\n\n/**\n * Whether Field may add `aria-required` to `child`: a component (it may render any control and\n * decides where the attribute goes), an element whose explicit role supports it, or a native form\n * control that takes a value. Never a `<button>`, `<meter>`, `<output>`, `<progress>`, button-type\n * `<input>` or role-less custom element, where axe reports `aria-allowed-attr`.\n */\nfunction supportsAriaRequired(child: React.ReactElement<InjectedFieldProps>): boolean {\n if (typeof child.type !== 'string') return true;\n const role = explicitRole(child.props.role);\n if (role !== undefined) return ARIA_REQUIRED_ROLES.has(role);\n return isNativeValueControl(child.type, child.props.type);\n}\n\n/**\n * Whether and how Field merges its props into `child` (see {@link MergeMode}). A Fragment and a\n * role-less (or presentational) non-labelable intrinsic wrapper (`<div>`, `<span>`) are left\n * alone; the library control inside them reads `FieldContext`. A role-less custom element\n * (`<my-text-field>`) is treated like a component: it may be a form-associated element, which a\n * `<label htmlFor>` names.\n */\nfunction getMergeMode(child: React.ReactElement<InjectedFieldProps>): MergeMode | undefined {\n if (child.type === React.Fragment) return undefined;\n if (typeof child.type !== 'string' || LABELABLE_ELEMENTS.has(child.type)) return 'label-for';\n const role = explicitRole(child.props.role);\n if (role !== undefined) return UNNAMED_ROLES.has(role) ? undefined : 'labelledby';\n return isCustomElement(child.type) ? 'label-for' : undefined;\n}\n\ninterface FieldChildren {\n /** The element child Field merges into, or `undefined`. */\n target: React.ReactElement<InjectedFieldProps> | undefined;\n /** How Field merges into `target` (`undefined` when there is no target). */\n mode: MergeMode | undefined;\n /** How many element children there are (only the first one is merged). */\n elementCount: number;\n}\n\nfunction inspectChildren(children: React.ReactNode): FieldChildren {\n let first: React.ReactElement<InjectedFieldProps> | undefined;\n let elementCount = 0;\n React.Children.forEach(children, (child) => {\n if (!React.isValidElement<InjectedFieldProps>(child)) return;\n elementCount += 1;\n if (first === undefined) first = child;\n });\n const mode = first ? getMergeMode(first) : undefined;\n return { target: mode ? first : undefined, mode, elementCount };\n}\n\n/** What Field merges into its first element child. */\ninterface FieldMergeState {\n controlId: string;\n labelId: string | undefined;\n /** The id of the rendered validation message, in any state. */\n messageId: string | undefined;\n hintId: string | undefined;\n /** Only the `error` validation state is invalid. */\n invalid: boolean;\n required: boolean;\n}\n\n/**\n * Returns `children` with Field's props merged into the merge target (only defined keys; the\n * child's own `id`, `aria-label`, `aria-invalid`, `aria-required` and `required` are kept, its\n * `aria-labelledby` and `aria-describedby` are joined with the message and the hint).\n */\nfunction mergeIntoFirstChild(children: React.ReactNode, state: FieldMergeState): React.ReactNode {\n const { target, mode } = inspectChildren(children);\n // Always map, so the children keep the same keys whether or not one of them is merged.\n if (!target || !mode) return React.Children.map(children, (child) => child);\n\n const childProps = target.props;\n // React renders a boolean `true` on a custom element as an empty attribute (`aria-invalid=\"\"`).\n const ariaTrue = isCustomElement(target.type) ? 'true' : true;\n const injected: InjectedFieldProps = {};\n if (mode === 'label-for') {\n if (childProps.id === undefined) injected.id = state.controlId;\n } else if (state.labelId !== undefined && childProps['aria-label'] === undefined) {\n injected['aria-labelledby'] = joinIds(childProps['aria-labelledby'], state.labelId);\n }\n if (state.messageId || state.hintId) {\n injected['aria-describedby'] = joinIds(\n childProps['aria-describedby'],\n state.messageId,\n state.hintId,\n );\n }\n // The child's own `aria-invalid` wins, as `useFieldControl` lets it win for a nested control.\n if (state.invalid && childProps['aria-invalid'] === undefined) {\n injected['aria-invalid'] = ariaTrue;\n }\n // A child's own `required={false}` wins: it gets neither `aria-required` nor `required`, so what\n // is announced matches what is validated.\n if (state.required && childProps.required !== false) {\n if (childProps['aria-required'] === undefined && supportsAriaRequired(target)) {\n injected['aria-required'] = ariaTrue;\n }\n if (\n typeof target.type === 'string' &&\n isNativeValueControl(target.type, childProps.type) &&\n childProps.required === undefined\n ) {\n injected.required = true;\n }\n }\n return React.Children.map(children, (child) =>\n child === target ? React.cloneElement(target, injected) : child,\n );\n}\n\n/** Primitive facts about the children, read during render (no element objects escape). */\nfunction getChildInfo(children: React.ReactNode): {\n elementCount: number;\n targetId: string | undefined;\n controlIdAssigned: boolean;\n} {\n const { target, mode, elementCount } = inspectChildren(children);\n // Only a label-for target holds the control id (Field merges it, or the target's own id becomes\n // the control id). A <label htmlFor> cannot name a role widget, so the library control inside\n // one keeps the control id. With `controlIdAssigned`, a library control that receives no id is\n // nested in the target or is a later sibling: useFieldControl gives it an id of its own and\n // names it through aria-labelledby.\n const assigned = mode === 'label-for';\n return {\n elementCount,\n targetId: assigned ? target?.props.id : undefined,\n controlIdAssigned: assigned,\n };\n}\n\n/** The default glyph of each message state (`none` has none). */\nconst MESSAGE_ICONS: Readonly<Record<ValidationState, IconComponent | null>> = {\n error: ErrorIcon,\n warning: WarningIcon,\n success: SuccessIcon,\n none: null,\n};\n\n/** Text color of each message state (the `*-tint-foreground` tokens keep 4.5:1 on page and card). */\nconst MESSAGE_COLORS: Readonly<Record<ValidationState, string>> = {\n error: 'text-error',\n warning: 'text-warning-tint-foreground',\n success: 'text-success-tint-foreground',\n none: 'text-muted-foreground',\n};\n\n/**\n * Horizontal layout: the label's first line is centred on a 32px row, the height of an Input, a\n * Select and the other text controls. Checkbox, Switch and RadioGroup rows are one 20px line, so a\n * first child that holds one (also a wrapper of several) gets 6px above and below: its first line\n * then lines up with the label's, also when its label wraps or a group lists its items one below\n * the other.\n */\nconst SHORT_ROW_FIRST_CHILD =\n '[&>:first-child:has([role=checkbox],[role=switch],label>[role=radio])]:py-1.5';\n\n/** The icon box before a message: 12px glyphs line up with the first line of caption text. */\nconst MESSAGE_ICON_CLASSES = 'mt-0.5 inline-flex shrink-0';\n\n/**\n * The icon before a message: the state's glyph while `icon` is `undefined`, else the consumer's\n * slot (`null` or content that renders nothing shows none).\n */\nfunction renderMessageIcon(state: ValidationState, icon: Slot<'span'> | undefined) {\n if (icon !== undefined) {\n return slotRendersContent(icon)\n ? renderSlot(icon, 'span', MESSAGE_ICON_CLASSES, { 'aria-hidden': true })\n : null;\n }\n const Icon = MESSAGE_ICONS[state];\n return Icon ? (\n <span aria-hidden=\"true\" className={MESSAGE_ICON_CLASSES}>\n <Icon size={12} />\n </span>\n ) : null;\n}\n\n/**\n * Lays out a form control with a label, a validation message, a hint and a required indicator,\n * and wires them to the control.\n *\n * - Validation: `validationMessage` with a `validationState` (`error`, `warning`, `success`,\n * `none`), or `error`, the shorthand for an error message. The message renders below the\n * control with the state's icon and color, followed by the hint (which stays visible); both\n * describe the control. Only the `error` state marks the control `aria-invalid`; `error` and\n * `warning` messages are announced (`role=\"alert\"`). The root carries `data-validation-state`\n * and `data-orientation`.\n * - `orientation=\"horizontal\"` puts the label in a start column beside the control, with the\n * message and the hint below the control. The label lines up with the first line of the\n * control (a Checkbox, Switch or RadioGroup gets 6px of padding above and below for it).\n * - Provides `FieldContext`: the library's inputs (Input, Select, Textarea, Slider, SearchBox,\n * Checkbox, Switch, RadioGroup, Rating, SpinButton, pickers, …) read it wherever they are inside\n * the Field and are named by the label, described by the message and the hint and marked\n * invalid/required.\n * - Merges into its **first** element child (a native `<input>`/`<select>`/`<textarea>`, a\n * library control or your own component): `id` (unless the child has one — the label then\n * points at the child's id), `aria-describedby` (joined with the child's own ids),\n * `aria-invalid` (in the error state), `aria-required` and, for native form controls that take a\n * value, `required`. Only defined values are merged; the child's own values are kept, so a\n * child's `aria-invalid={false}` stays valid while the Field error still describes it (as for a\n * library control nested deeper). Further element children are rendered as they are.\n * - `aria-required` is added only where it is allowed: components (Field cannot see what they\n * render, so they decide where it goes — see the wrapper note below), `<input>` (not\n * `type=\"button\"`/`\"submit\"`/`\"reset\"`/`\"image\"`), `<select>`, `<textarea>`, and elements\n * whose explicit `role` supports it (`checkbox`, `combobox`, `switch`, `textbox`, …). A\n * `<button>`, `<meter>`, `<output>` or `<progress>` is labelled and described but not marked\n * required.\n * - Your own widget built on an element with an explicit `role` (`<div role=\"radiogroup\">`) is\n * named through `aria-labelledby` (joined with its own; not added when it has an\n * `aria-label`), described, marked invalid, and gets `aria-required` when its role supports\n * it. It receives no `id`, because a `<label htmlFor>` cannot name it. A role-less `<div>` or\n * `<span>` wrapper (or a `role=\"presentation\"`/`\"none\"` one) is left alone: the library\n * control inside it reads `FieldContext`.\n * - A custom element (`<my-text-field>`) without a role is treated like a component: it receives\n * the `id`, the description and `aria-invalid` (a form-associated custom element is named by\n * the label). Field does not guess its semantics: pass `required`/`aria-required` or an\n * explicit `role` yourself.\n * - **One control per Field.** A Field labels and describes a single control; wrap each control\n * in its own Field (a development warning is logged when a Field has more than one element\n * child). Further element children are rendered as they are. A library control among them\n * still reads `FieldContext`, so it shares the Field's name and description (when the first\n * child holds the control id, it gets an id of its own and is named through\n * `aria-labelledby`). Several library controls inside one plain wrapper element (`<div>`) are\n * all named and described too: the first one takes the control id the label points at, the\n * others get ids of their own and are named through `aria-labelledby` (when the first one is\n * removed, the next one takes the control id over).\n * - **Wrapper and layout components around a library control** (a `Tooltip`, your own `Row`):\n * put them inside a plain element (`<div>`, `<div className=\"flex\">`), which Field leaves\n * alone; the library control inside then holds the control id and is labelled, described and\n * marked invalid/required through `FieldContext`. Field cannot see inside a component, so a\n * component **first child** is treated as the control (it may be your own input): it receives\n * the control `id`, `aria-describedby`, `aria-invalid` and, with `required`, `aria-required`,\n * and a wrapper puts them on its own element (Tooltip's `<span>`, the layout `<div>`). The\n * library control inside still gets an id of its own and is named by the label through\n * `aria-labelledby`, but clicking the label does not focus it, and with `required`,\n * `aria-required` on the wrapper's non-widget element is an ARIA error (axe\n * `aria-allowed-attr`), even though the control inside is correctly marked required.\n *\n * @example\n * <Field label=\"Email\" hint=\"We never share it\" error={errors.email} required>\n * <Input type=\"email\" value={email} onValueChange={setEmail} />\n * </Field>\n *\n * @example\n * <Field label=\"Password\" hint=\"At least 12 characters\" validationState=\"warning\"\n * validationMessage=\"This password is common\">\n * <Input type=\"password\" />\n * </Field>\n *\n * @example\n * // A wrapper component goes inside a plain element.\n * <Field label=\"Name\" required>\n * <div>\n * <Tooltip content=\"As on your passport\">\n * <Input />\n * </Tooltip>\n * </div>\n * </Field>\n */\nexport const Field = ({\n label,\n hint,\n error,\n validationState,\n validationMessage,\n validationMessageIcon,\n orientation = 'vertical',\n required = false,\n htmlFor,\n className,\n children,\n ref,\n ...rest\n}: FieldProps) => {\n const fieldId = useId('field');\n // Hands the control id to one library control when Field leaves its first child alone.\n const [controlIdClaim] = React.useState(createFieldControlIdClaim);\n const { elementCount, targetId, controlIdAssigned } = getChildInfo(children);\n\n // The library's \"renders nothing\" rule: nullish, booleans, '' and collections of only those (an\n // empty `errors.map(…)`) are no label, hint or message; `0` is content.\n const errorRendersContent = slotRendersContent(error);\n const usesError = error === true || errorRendersContent;\n const validationMessageRendersContent = slotRendersContent(validationMessage);\n // `error` is the shorthand for an error message and wins over the validation props.\n const state: ValidationState = usesError\n ? 'error'\n : (validationState ?? (validationMessageRendersContent ? 'error' : 'none'));\n const message = usesError ? (errorRendersContent ? error : undefined) : validationMessage;\n const hasMessage = usesError ? errorRendersContent : validationMessageRendersContent;\n const invalid = state === 'error';\n const hasHint = slotRendersContent(hint);\n const errorAndValidation =\n usesError &&\n (validationMessageRendersContent ||\n (validationState !== undefined && validationState !== 'error'));\n\n const controlId = targetId ?? htmlFor ?? fieldId;\n const hasLabel = slotRendersContent(label);\n const labelId = hasLabel ? `${fieldId}-label` : undefined;\n // The error message keeps its 0.5 id; the other states get their own.\n const messageId = hasMessage ? `${fieldId}-${invalid ? 'error' : 'message'}` : undefined;\n const errorId = invalid ? messageId : undefined;\n const hasErrorMessage = invalid && hasMessage;\n const hintId = hasHint ? `${fieldId}-hint` : undefined;\n\n React.useEffect(() => {\n if (elementCount > 1) {\n warnOnce(\n 'Field:multiple-children',\n \"Field: only the first element child receives the Field's id and ARIA attributes; the other \" +\n `${elementCount - 1} element child(ren) are rendered unchanged. Wrap each control in its own Field.`,\n );\n }\n }, [elementCount]);\n\n React.useEffect(() => {\n if (errorAndValidation) {\n warnOnce(\n 'Field:error-and-validation',\n 'Field: `error` and `validationMessage`/`validationState` are both set; `error` wins. Use one of them.',\n );\n }\n }, [errorAndValidation]);\n\n const context = React.useMemo<FieldContextValue>(\n () => ({\n controlId,\n labelId,\n hintId,\n errorId,\n invalid,\n required,\n hasErrorMessage,\n controlIdAssigned,\n controlIdClaim,\n validationState: state,\n validationMessageId: messageId,\n }),\n [\n controlId,\n labelId,\n hintId,\n errorId,\n invalid,\n required,\n hasErrorMessage,\n controlIdAssigned,\n controlIdClaim,\n state,\n messageId,\n ],\n );\n\n const content = mergeIntoFirstChild(children, {\n controlId,\n labelId,\n messageId,\n hintId,\n invalid,\n required,\n });\n\n const horizontal = orientation === 'horizontal';\n const control = (\n <>\n <FieldContext.Provider value={context}>{content}</FieldContext.Provider>\n {/* Keyed by state: a message whose state changes (a hint-only Field that gets an error, a\n warning that becomes an error) is a newly inserted element, which screen readers\n announce reliably as an alert, not an existing node with a new role. */}\n {hasMessage ? (\n <p\n key={`message-${state}`}\n id={messageId}\n role={state === 'error' || state === 'warning' ? 'alert' : undefined}\n data-validation-state={state}\n className={cn('mt-1 flex items-start gap-1 text-caption-1', MESSAGE_COLORS[state])}\n >\n {renderMessageIcon(state, validationMessageIcon)}\n <span>{materialiseSlotContent(message)}</span>\n </p>\n ) : null}\n {hasHint ? (\n <p key=\"hint\" id={hintId} className=\"mt-1 text-caption-1 text-muted-foreground\">\n {materialiseSlotContent(hint)}\n </p>\n ) : null}\n </>\n );\n\n return (\n <div\n ref={ref}\n data-orientation={orientation}\n data-validation-state={state}\n className={cn('flex', horizontal ? 'flex-row items-start gap-x-3' : 'flex-col', className)}\n {...rest}\n >\n {hasLabel ? (\n <label\n id={labelId}\n htmlFor={controlId}\n className={cn(\n 'mb-1 text-body-1 font-semibold text-foreground',\n // Beside the control: a third of the width, its first line centred on a 32px row.\n horizontal && 'mb-0 shrink-0 basis-1/3 pt-1.5',\n )}\n >\n {materialiseSlotContent(label)}\n {required && (\n <span aria-hidden=\"true\" className=\"ms-0.5 text-error\">\n *\n </span>\n )}\n </label>\n ) : null}\n {horizontal ? (\n <div className={cn('flex min-w-0 flex-1 flex-col', SHORT_ROW_FIRST_CHILD)}>{control}</div>\n ) : (\n control\n )}\n </div>\n );\n};\n\nField.displayName = 'Field';\n"],"mappings":"8XA8FA,IAAMuB,EAA0C,IAAI,IAAI,CACtD,SACA,QACA,QACA,SACA,WACA,SACA,UACF,CAAC,EAGKC,EAA0C,IAAI,IAAI,CAAC,SAAU,QAAS,QAAS,QAAQ,CAAC,EAMxFC,EAAqC,IAAI,IAAI,CACjD,UACA,OACA,WACA,WACA,UACA,YACA,OACA,YACA,eACA,SACA,YACA,aACF,CAAC,EAGKC,EAA2C,IAAI,IAAI,CACvD,WACA,eACA,WACA,WACA,UACA,aACA,YACA,YACA,aACA,SACA,UACA,OACA,UACF,CAAC,EAeD,SAASC,EAAa,EAAmC,CACvD,GAAI,OAAOC,GAAS,SACpB,OAAOA,EAAK,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,EAAE,YAAY,GAAK,IAAA,EACvD,CAGA,SAASC,EAAgB,EAA+B,CACtD,OAAO,OAAOC,GAAS,UA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zC,EACvB,UAAWpC,EAAAA,GAAG,OAAQ4E,EAAa,+BAAiC,WAAYI,CAAS,EACzF,GAAIjC,EALN,SAAA,CAOGkB,GACC,EAAAtD,EAAA,KAAA,CAAC,QAAD,CACE,GAAIwD,EACJ,QAASL,EACT,UAAW9D,EAAAA,GACT,iDAEA4E,GAAc,gCAChB,EAPF,SAAA,CASG3E,EAAAA,uBAAuBiE,CAAK,EAC5BO,IACC,EAAA9D,EAAA,IAAA,CAAC,OAAD,CAAM,cAAY,OAAO,UAAU,oBAAoB,SAAA,GAEjD,CAAA,CAEH,CACL,CAAA,EAAA,KACHiE,GACC,EAAAjE,EAAA,IAAA,CAAC,MAAD,CAAK,UAAWX,EAAAA,GAAG,+BAAgCyC,CAAqB,EAAI,SAAAqC,CAAa,CAAA,EAEzFA,CAEC,GAET,EAEA,EAAM,YAAc"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn as e } from "../../lib/cn.mjs";
|
|
3
|
+
import { warnOnce as t } from "../../lib/dev.mjs";
|
|
4
|
+
import { materialiseSlotContent as n, renderSlot as r, slotRendersContent as i } from "../../lib/slot.mjs";
|
|
5
|
+
import { useId as a } from "../../hooks/useId.mjs";
|
|
6
|
+
import { joinIds as o } from "../../lib/aria.mjs";
|
|
7
|
+
import { FieldContext as s, createFieldControlIdClaim as c } from "../../hooks/useFieldControl.mjs";
|
|
8
|
+
import { ErrorIcon as l, SuccessIcon as u, WarningIcon as d } from "../../lib/icons.mjs";
|
|
9
|
+
import * as f from "react";
|
|
10
|
+
import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
11
|
+
//#region src/components/input/Field.tsx
|
|
12
|
+
var g = /* @__PURE__ */ new Set([
|
|
13
|
+
"button",
|
|
14
|
+
"input",
|
|
15
|
+
"meter",
|
|
16
|
+
"output",
|
|
17
|
+
"progress",
|
|
18
|
+
"select",
|
|
19
|
+
"textarea"
|
|
20
|
+
]), _ = /* @__PURE__ */ new Set([
|
|
21
|
+
"button",
|
|
22
|
+
"image",
|
|
23
|
+
"reset",
|
|
24
|
+
"submit"
|
|
25
|
+
]), v = /* @__PURE__ */ new Set([
|
|
26
|
+
"caption",
|
|
27
|
+
"code",
|
|
28
|
+
"deletion",
|
|
29
|
+
"emphasis",
|
|
30
|
+
"generic",
|
|
31
|
+
"insertion",
|
|
32
|
+
"none",
|
|
33
|
+
"paragraph",
|
|
34
|
+
"presentation",
|
|
35
|
+
"strong",
|
|
36
|
+
"subscript",
|
|
37
|
+
"superscript"
|
|
38
|
+
]), y = /* @__PURE__ */ new Set([
|
|
39
|
+
"checkbox",
|
|
40
|
+
"columnheader",
|
|
41
|
+
"combobox",
|
|
42
|
+
"gridcell",
|
|
43
|
+
"listbox",
|
|
44
|
+
"radiogroup",
|
|
45
|
+
"rowheader",
|
|
46
|
+
"searchbox",
|
|
47
|
+
"spinbutton",
|
|
48
|
+
"switch",
|
|
49
|
+
"textbox",
|
|
50
|
+
"tree",
|
|
51
|
+
"treegrid"
|
|
52
|
+
]);
|
|
53
|
+
function b(e) {
|
|
54
|
+
if (typeof e == "string") return e.trim().split(/\s+/)[0]?.toLowerCase() || void 0;
|
|
55
|
+
}
|
|
56
|
+
function x(e) {
|
|
57
|
+
return typeof e == "string" && e.includes("-");
|
|
58
|
+
}
|
|
59
|
+
function S(e, t) {
|
|
60
|
+
return e === "select" || e === "textarea" ? !0 : e === "input" ? typeof t != "string" || !_.has(t.trim().toLowerCase()) : !1;
|
|
61
|
+
}
|
|
62
|
+
function C(e) {
|
|
63
|
+
if (typeof e.type != "string") return !0;
|
|
64
|
+
let t = b(e.props.role);
|
|
65
|
+
return t === void 0 ? S(e.type, e.props.type) : y.has(t);
|
|
66
|
+
}
|
|
67
|
+
function w(e) {
|
|
68
|
+
if (e.type === f.Fragment) return;
|
|
69
|
+
if (typeof e.type != "string" || g.has(e.type)) return "label-for";
|
|
70
|
+
let t = b(e.props.role);
|
|
71
|
+
return t === void 0 ? x(e.type) ? "label-for" : void 0 : v.has(t) ? void 0 : "labelledby";
|
|
72
|
+
}
|
|
73
|
+
function T(e) {
|
|
74
|
+
let t, n = 0;
|
|
75
|
+
f.Children.forEach(e, (e) => {
|
|
76
|
+
f.isValidElement(e) && (n += 1, t === void 0 && (t = e));
|
|
77
|
+
});
|
|
78
|
+
let r = t ? w(t) : void 0;
|
|
79
|
+
return {
|
|
80
|
+
target: r ? t : void 0,
|
|
81
|
+
mode: r,
|
|
82
|
+
elementCount: n
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function E(e, t) {
|
|
86
|
+
let { target: n, mode: r } = T(e);
|
|
87
|
+
if (!n || !r) return f.Children.map(e, (e) => e);
|
|
88
|
+
let i = n.props, a = !x(n.type) || "true", s = {};
|
|
89
|
+
return r === "label-for" ? i.id === void 0 && (s.id = t.controlId) : t.labelId !== void 0 && i["aria-label"] === void 0 && (s["aria-labelledby"] = o(i["aria-labelledby"], t.labelId)), (t.messageId || t.hintId) && (s["aria-describedby"] = o(i["aria-describedby"], t.messageId, t.hintId)), t.invalid && i["aria-invalid"] === void 0 && (s["aria-invalid"] = a), t.required && i.required !== !1 && (i["aria-required"] === void 0 && C(n) && (s["aria-required"] = a), typeof n.type == "string" && S(n.type, i.type) && i.required === void 0 && (s.required = !0)), f.Children.map(e, (e) => e === n ? f.cloneElement(n, s) : e);
|
|
90
|
+
}
|
|
91
|
+
function D(e) {
|
|
92
|
+
let { target: t, mode: n, elementCount: r } = T(e), i = n === "label-for";
|
|
93
|
+
return {
|
|
94
|
+
elementCount: r,
|
|
95
|
+
targetId: i ? t?.props.id : void 0,
|
|
96
|
+
controlIdAssigned: i
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var O = {
|
|
100
|
+
error: l,
|
|
101
|
+
warning: d,
|
|
102
|
+
success: u,
|
|
103
|
+
none: null
|
|
104
|
+
}, k = {
|
|
105
|
+
error: "text-error",
|
|
106
|
+
warning: "text-warning-tint-foreground",
|
|
107
|
+
success: "text-success-tint-foreground",
|
|
108
|
+
none: "text-muted-foreground"
|
|
109
|
+
}, A = "[&>:first-child:has([role=checkbox],[role=switch],label>[role=radio])]:py-1.5", j = "mt-0.5 inline-flex shrink-0";
|
|
110
|
+
function M(e, t) {
|
|
111
|
+
if (t !== void 0) return i(t) ? r(t, "span", j, { "aria-hidden": !0 }) : null;
|
|
112
|
+
let n = O[e];
|
|
113
|
+
return n ? /* @__PURE__ */ m("span", {
|
|
114
|
+
"aria-hidden": "true",
|
|
115
|
+
className: j,
|
|
116
|
+
children: /* @__PURE__ */ m(n, { size: 12 })
|
|
117
|
+
}) : null;
|
|
118
|
+
}
|
|
119
|
+
var N = ({ label: r, hint: o, error: l, validationState: u, validationMessage: d, validationMessageIcon: g, orientation: _ = "vertical", required: v = !1, htmlFor: y, className: b, children: x, ref: S, ...C }) => {
|
|
120
|
+
let w = a("field"), [T] = f.useState(c), { elementCount: O, targetId: j, controlIdAssigned: N } = D(x), P = i(l), F = l === !0 || P, I = i(d), L = F ? "error" : u ?? (I ? "error" : "none"), R = F ? P ? l : void 0 : d, z = F ? P : I, B = L === "error", V = i(o), H = F && (I || u !== void 0 && u !== "error"), U = j ?? y ?? w, W = i(r), G = W ? `${w}-label` : void 0, K = z ? `${w}-${B ? "error" : "message"}` : void 0, q = B ? K : void 0, J = B && z, Y = V ? `${w}-hint` : void 0;
|
|
121
|
+
f.useEffect(() => {
|
|
122
|
+
O > 1 && t("Field:multiple-children", `Field: only the first element child receives the Field's id and ARIA attributes; the other ${O - 1} element child(ren) are rendered unchanged. Wrap each control in its own Field.`);
|
|
123
|
+
}, [O]), f.useEffect(() => {
|
|
124
|
+
H && t("Field:error-and-validation", "Field: `error` and `validationMessage`/`validationState` are both set; `error` wins. Use one of them.");
|
|
125
|
+
}, [H]);
|
|
126
|
+
let X = f.useMemo(() => ({
|
|
127
|
+
controlId: U,
|
|
128
|
+
labelId: G,
|
|
129
|
+
hintId: Y,
|
|
130
|
+
errorId: q,
|
|
131
|
+
invalid: B,
|
|
132
|
+
required: v,
|
|
133
|
+
hasErrorMessage: J,
|
|
134
|
+
controlIdAssigned: N,
|
|
135
|
+
controlIdClaim: T,
|
|
136
|
+
validationState: L,
|
|
137
|
+
validationMessageId: K
|
|
138
|
+
}), [
|
|
139
|
+
U,
|
|
140
|
+
G,
|
|
141
|
+
Y,
|
|
142
|
+
q,
|
|
143
|
+
B,
|
|
144
|
+
v,
|
|
145
|
+
J,
|
|
146
|
+
N,
|
|
147
|
+
T,
|
|
148
|
+
L,
|
|
149
|
+
K
|
|
150
|
+
]), Z = E(x, {
|
|
151
|
+
controlId: U,
|
|
152
|
+
labelId: G,
|
|
153
|
+
messageId: K,
|
|
154
|
+
hintId: Y,
|
|
155
|
+
invalid: B,
|
|
156
|
+
required: v
|
|
157
|
+
}), Q = _ === "horizontal", $ = /* @__PURE__ */ h(p, { children: [
|
|
158
|
+
/* @__PURE__ */ m(s.Provider, {
|
|
159
|
+
value: X,
|
|
160
|
+
children: Z
|
|
161
|
+
}),
|
|
162
|
+
z ? /* @__PURE__ */ h("p", {
|
|
163
|
+
id: K,
|
|
164
|
+
role: L === "error" || L === "warning" ? "alert" : void 0,
|
|
165
|
+
"data-validation-state": L,
|
|
166
|
+
className: e("mt-1 flex items-start gap-1 text-caption-1", k[L]),
|
|
167
|
+
children: [M(L, g), /* @__PURE__ */ m("span", { children: n(R) })]
|
|
168
|
+
}, `message-${L}`) : null,
|
|
169
|
+
V ? /* @__PURE__ */ m("p", {
|
|
170
|
+
id: Y,
|
|
171
|
+
className: "mt-1 text-caption-1 text-muted-foreground",
|
|
172
|
+
children: n(o)
|
|
173
|
+
}, "hint") : null
|
|
174
|
+
] });
|
|
175
|
+
return /* @__PURE__ */ h("div", {
|
|
176
|
+
ref: S,
|
|
177
|
+
"data-orientation": _,
|
|
178
|
+
"data-validation-state": L,
|
|
179
|
+
className: e("flex", Q ? "flex-row items-start gap-x-3" : "flex-col", b),
|
|
180
|
+
...C,
|
|
181
|
+
children: [W ? /* @__PURE__ */ h("label", {
|
|
182
|
+
id: G,
|
|
183
|
+
htmlFor: U,
|
|
184
|
+
className: e("mb-1 text-body-1 font-semibold text-foreground", Q && "mb-0 shrink-0 basis-1/3 pt-1.5"),
|
|
185
|
+
children: [n(r), v && /* @__PURE__ */ m("span", {
|
|
186
|
+
"aria-hidden": "true",
|
|
187
|
+
className: "ms-0.5 text-error",
|
|
188
|
+
children: "*"
|
|
189
|
+
})]
|
|
190
|
+
}) : null, Q ? /* @__PURE__ */ m("div", {
|
|
191
|
+
className: e("flex min-w-0 flex-1 flex-col", A),
|
|
192
|
+
children: $
|
|
193
|
+
}) : $]
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
N.displayName = "Field";
|
|
197
|
+
//#endregion
|
|
198
|
+
export { N as Field };
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=Field.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.mjs","names":["useId","_Fragment","useId$1","React","LABELABLE_ELEMENTS","BUTTON_INPUT_TYPES","UNNAMED_ROLES","ARIA_REQUIRED_ROLES","explicitRole","role","isCustomElement","type","isNativeValueControl","tag","inputType","supportsAriaRequired","child","getMergeMode","inspectChildren","first","elementCount","children","mode","mergeIntoFirstChild","target","childProps","ariaTrue","injected","state","joinIds","getChildInfo","assigned","MESSAGE_ICONS","ErrorIcon","WarningIcon","SuccessIcon","MESSAGE_COLORS","SHORT_ROW_FIRST_CHILD","MESSAGE_ICON_CLASSES","renderMessageIcon","icon","slotRendersContent","renderSlot","Icon","Field","rest","fieldId","controlIdClaim","createFieldControlIdClaim","errorRendersContent","error","usesError","validationMessageRendersContent","validationMessage","validationState","message","hasMessage","invalid","hasHint","hint","errorAndValidation","controlId","targetId","htmlFor","hasLabel","label","labelId","messageId","errorId","hasErrorMessage","hintId","warnOnce","context","required","controlIdAssigned","content","horizontal","orientation","control","Fragment","FieldContext","cn","validationMessageIcon","materialiseSlotContent","className"],"sources":["../../../src/components/input/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { joinIds } from '../../lib/aria';\nimport { warnOnce } from '../../lib/dev';\nimport { ErrorIcon, SuccessIcon, WarningIcon, type IconComponent } from '../../lib/icons';\nimport { materialiseSlotContent, renderSlot, slotRendersContent, type Slot } from '../../lib/slot';\nimport type { Orientation, ValidationState } from '../../lib/types';\nimport { useId } from '../../hooks/useId';\nimport {\n FieldContext,\n createFieldControlIdClaim,\n type FieldContextValue,\n} from '../../hooks/useFieldControl';\n\n/** Props Field reads from and merges into its first element child. */\ninterface InjectedFieldProps {\n id?: string;\n role?: string;\n type?: string;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n 'aria-describedby'?: string;\n 'aria-invalid'?: React.AriaAttributes['aria-invalid'];\n 'aria-required'?: React.AriaAttributes['aria-required'];\n required?: boolean;\n}\n\n/** Properties for the Field component. */\nexport interface FieldProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Label displayed above the control (beside it with `orientation=\"horizontal\"`); names the\n * control.\n */\n label?: React.ReactNode;\n /** Hint shown below the control, after any validation message; describes the control. */\n hint?: React.ReactNode;\n /**\n * Validation error. Content is rendered below the control in a `role=\"alert\"` element that\n * describes the control, and the control is marked `aria-invalid`. `true` marks the control\n * invalid without a message. A value that renders nothing (`null`, `false`, `''`, or an array of\n * only those, such as an empty `errors.map(…)`) is no error; `0` is content.\n *\n * Shorthand for `validationState=\"error\"` with this message; wins over `validationMessage` and\n * `validationState` (development warning when both are set).\n */\n error?: React.ReactNode;\n /**\n * Validation state of `validationMessage`: `error` marks the control invalid (`aria-invalid`) and\n * announces the message (`role=\"alert\"`); `warning` announces it without marking the control\n * invalid; `success` and `none` show it without announcing. Default: `'error'` when\n * `validationMessage` renders content, else `'none'`. Ignored while `error` is set.\n */\n validationState?: ValidationState;\n /**\n * Message below the control, styled and announced by `validationState`; it describes the control\n * (`aria-describedby`). `error` is the shorthand for an error message and wins over this prop.\n */\n validationMessage?: React.ReactNode;\n /**\n * Icon before the message. Default: an error, warning or success glyph per state; none for\n * `'none'`. `null` (or content that renders nothing) shows no icon. Decorative (`aria-hidden`).\n */\n validationMessageIcon?: Slot<'span'>;\n /**\n * `vertical`: the label above the control. `horizontal`: the label in a start column (a third\n * of the width) beside the control; the message and the hint stay below the control. The\n * label's first line lines up with a 32px control (Input, Select, …) and with the first line of\n * a Checkbox, Switch or RadioGroup, which gets 6px of padding above and below for it. The\n * horizontal layout wraps the control in a column, so changing `orientation` on a mounted Field\n * remounts the control: an uncontrolled control loses its state and focus (control it, or keep\n * one orientation while the Field is mounted).\n * @default 'vertical'\n */\n orientation?: Orientation;\n /**\n * Whether the field is required: shows a decorative asterisk next to the label, sets\n * `aria-required`, and turns on native constraint validation. `<input>`, `<select>`,\n * `<textarea>` and Input, Select, Textarea, Slider, SearchBox and SpinButton get the native\n * `required` attribute. Checkbox, Switch, RadioGroup, Rating, ColorPicker, SwatchPicker,\n * Combobox, Dropdown, TagPicker, DatePicker and TimePicker render a hidden required input (with\n * or without `name`), so submit is blocked until they are checked, switched on or have a value.\n * An explicit `required={false}` on the control wins, including for `aria-required`.\n */\n required?: boolean;\n /**\n * The id of the control the label points at, when the control has no `id` of its own\n * (default: a generated id).\n */\n htmlFor?: string;\n /** Ref to the root `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/** Intrinsic elements a `<label htmlFor>` can name (HTML \"labelable elements\"). */\nconst LABELABLE_ELEMENTS: ReadonlySet<string> = new Set([\n 'button',\n 'input',\n 'meter',\n 'output',\n 'progress',\n 'select',\n 'textarea',\n]);\n\n/** `<input>` types whose implicit role is `button`: they take neither `aria-required` nor `required`. */\nconst BUTTON_INPUT_TYPES: ReadonlySet<string> = new Set(['button', 'image', 'reset', 'submit']);\n\n/**\n * Roles that cannot be named (ARIA 1.2 \"name prohibited\") or that remove semantics: an element\n * with one of them is a layout wrapper, not a widget, and Field leaves it alone.\n */\nconst UNNAMED_ROLES: ReadonlySet<string> = new Set([\n 'caption',\n 'code',\n 'deletion',\n 'emphasis',\n 'generic',\n 'insertion',\n 'none',\n 'paragraph',\n 'presentation',\n 'strong',\n 'subscript',\n 'superscript',\n]);\n\n/** Roles that support `aria-required` (ARIA 1.2, including the roles that inherit it). */\nconst ARIA_REQUIRED_ROLES: ReadonlySet<string> = new Set([\n 'checkbox',\n 'columnheader',\n 'combobox',\n 'gridcell',\n 'listbox',\n 'radiogroup',\n 'rowheader',\n 'searchbox',\n 'spinbutton',\n 'switch',\n 'textbox',\n 'tree',\n 'treegrid',\n]);\n\n/**\n * How Field merges into its first element child:\n * - `label-for`: components (library controls, consumer inputs, wrappers such as Tooltip),\n * labelable intrinsic elements (`<input>`, `<select>`, `<button>`, …) and role-less custom\n * elements (`<my-text-field>`, possibly form-associated). The child receives the `id` the\n * `<label htmlFor>` points at (unless it has its own id, which the label then uses).\n * - `labelledby`: an intrinsic element with an explicit widget `role` (a consumer's own\n * `<div role=\"radiogroup\">`). A `<label htmlFor>` cannot name it, so it is named through\n * `aria-labelledby` and receives no `id` (a library control inside it keeps the control id).\n */\ntype MergeMode = 'label-for' | 'labelledby';\n\n/** The first token of an explicit `role` attribute (lower case), or `undefined`. */\nfunction explicitRole(role: unknown): string | undefined {\n if (typeof role !== 'string') return undefined;\n return role.trim().split(/\\s+/)[0]?.toLowerCase() || undefined;\n}\n\n/** Whether `type` is an autonomous custom element (`<my-text-field>`): its tag name has a hyphen. */\nfunction isCustomElement(type: unknown): type is string {\n return typeof type === 'string' && type.includes('-');\n}\n\n/**\n * Whether an intrinsic element is a native form control that takes a value (`<select>`,\n * `<textarea>`, or an `<input>` that is not a button): it takes the native `required` attribute\n * and, without an explicit role, `aria-required`.\n */\nfunction isNativeValueControl(tag: string, inputType: unknown): boolean {\n if (tag === 'select' || tag === 'textarea') return true;\n if (tag !== 'input') return false;\n return typeof inputType !== 'string' || !BUTTON_INPUT_TYPES.has(inputType.trim().toLowerCase());\n}\n\n/**\n * Whether Field may add `aria-required` to `child`: a component (it may render any control and\n * decides where the attribute goes), an element whose explicit role supports it, or a native form\n * control that takes a value. Never a `<button>`, `<meter>`, `<output>`, `<progress>`, button-type\n * `<input>` or role-less custom element, where axe reports `aria-allowed-attr`.\n */\nfunction supportsAriaRequired(child: React.ReactElement<InjectedFieldProps>): boolean {\n if (typeof child.type !== 'string') return true;\n const role = explicitRole(child.props.role);\n if (role !== undefined) return ARIA_REQUIRED_ROLES.has(role);\n return isNativeValueControl(child.type, child.props.type);\n}\n\n/**\n * Whether and how Field merges its props into `child` (see {@link MergeMode}). A Fragment and a\n * role-less (or presentational) non-labelable intrinsic wrapper (`<div>`, `<span>`) are left\n * alone; the library control inside them reads `FieldContext`. A role-less custom element\n * (`<my-text-field>`) is treated like a component: it may be a form-associated element, which a\n * `<label htmlFor>` names.\n */\nfunction getMergeMode(child: React.ReactElement<InjectedFieldProps>): MergeMode | undefined {\n if (child.type === React.Fragment) return undefined;\n if (typeof child.type !== 'string' || LABELABLE_ELEMENTS.has(child.type)) return 'label-for';\n const role = explicitRole(child.props.role);\n if (role !== undefined) return UNNAMED_ROLES.has(role) ? undefined : 'labelledby';\n return isCustomElement(child.type) ? 'label-for' : undefined;\n}\n\ninterface FieldChildren {\n /** The element child Field merges into, or `undefined`. */\n target: React.ReactElement<InjectedFieldProps> | undefined;\n /** How Field merges into `target` (`undefined` when there is no target). */\n mode: MergeMode | undefined;\n /** How many element children there are (only the first one is merged). */\n elementCount: number;\n}\n\nfunction inspectChildren(children: React.ReactNode): FieldChildren {\n let first: React.ReactElement<InjectedFieldProps> | undefined;\n let elementCount = 0;\n React.Children.forEach(children, (child) => {\n if (!React.isValidElement<InjectedFieldProps>(child)) return;\n elementCount += 1;\n if (first === undefined) first = child;\n });\n const mode = first ? getMergeMode(first) : undefined;\n return { target: mode ? first : undefined, mode, elementCount };\n}\n\n/** What Field merges into its first element child. */\ninterface FieldMergeState {\n controlId: string;\n labelId: string | undefined;\n /** The id of the rendered validation message, in any state. */\n messageId: string | undefined;\n hintId: string | undefined;\n /** Only the `error` validation state is invalid. */\n invalid: boolean;\n required: boolean;\n}\n\n/**\n * Returns `children` with Field's props merged into the merge target (only defined keys; the\n * child's own `id`, `aria-label`, `aria-invalid`, `aria-required` and `required` are kept, its\n * `aria-labelledby` and `aria-describedby` are joined with the message and the hint).\n */\nfunction mergeIntoFirstChild(children: React.ReactNode, state: FieldMergeState): React.ReactNode {\n const { target, mode } = inspectChildren(children);\n // Always map, so the children keep the same keys whether or not one of them is merged.\n if (!target || !mode) return React.Children.map(children, (child) => child);\n\n const childProps = target.props;\n // React renders a boolean `true` on a custom element as an empty attribute (`aria-invalid=\"\"`).\n const ariaTrue = isCustomElement(target.type) ? 'true' : true;\n const injected: InjectedFieldProps = {};\n if (mode === 'label-for') {\n if (childProps.id === undefined) injected.id = state.controlId;\n } else if (state.labelId !== undefined && childProps['aria-label'] === undefined) {\n injected['aria-labelledby'] = joinIds(childProps['aria-labelledby'], state.labelId);\n }\n if (state.messageId || state.hintId) {\n injected['aria-describedby'] = joinIds(\n childProps['aria-describedby'],\n state.messageId,\n state.hintId,\n );\n }\n // The child's own `aria-invalid` wins, as `useFieldControl` lets it win for a nested control.\n if (state.invalid && childProps['aria-invalid'] === undefined) {\n injected['aria-invalid'] = ariaTrue;\n }\n // A child's own `required={false}` wins: it gets neither `aria-required` nor `required`, so what\n // is announced matches what is validated.\n if (state.required && childProps.required !== false) {\n if (childProps['aria-required'] === undefined && supportsAriaRequired(target)) {\n injected['aria-required'] = ariaTrue;\n }\n if (\n typeof target.type === 'string' &&\n isNativeValueControl(target.type, childProps.type) &&\n childProps.required === undefined\n ) {\n injected.required = true;\n }\n }\n return React.Children.map(children, (child) =>\n child === target ? React.cloneElement(target, injected) : child,\n );\n}\n\n/** Primitive facts about the children, read during render (no element objects escape). */\nfunction getChildInfo(children: React.ReactNode): {\n elementCount: number;\n targetId: string | undefined;\n controlIdAssigned: boolean;\n} {\n const { target, mode, elementCount } = inspectChildren(children);\n // Only a label-for target holds the control id (Field merges it, or the target's own id becomes\n // the control id). A <label htmlFor> cannot name a role widget, so the library control inside\n // one keeps the control id. With `controlIdAssigned`, a library control that receives no id is\n // nested in the target or is a later sibling: useFieldControl gives it an id of its own and\n // names it through aria-labelledby.\n const assigned = mode === 'label-for';\n return {\n elementCount,\n targetId: assigned ? target?.props.id : undefined,\n controlIdAssigned: assigned,\n };\n}\n\n/** The default glyph of each message state (`none` has none). */\nconst MESSAGE_ICONS: Readonly<Record<ValidationState, IconComponent | null>> = {\n error: ErrorIcon,\n warning: WarningIcon,\n success: SuccessIcon,\n none: null,\n};\n\n/** Text color of each message state (the `*-tint-foreground` tokens keep 4.5:1 on page and card). */\nconst MESSAGE_COLORS: Readonly<Record<ValidationState, string>> = {\n error: 'text-error',\n warning: 'text-warning-tint-foreground',\n success: 'text-success-tint-foreground',\n none: 'text-muted-foreground',\n};\n\n/**\n * Horizontal layout: the label's first line is centred on a 32px row, the height of an Input, a\n * Select and the other text controls. Checkbox, Switch and RadioGroup rows are one 20px line, so a\n * first child that holds one (also a wrapper of several) gets 6px above and below: its first line\n * then lines up with the label's, also when its label wraps or a group lists its items one below\n * the other.\n */\nconst SHORT_ROW_FIRST_CHILD =\n '[&>:first-child:has([role=checkbox],[role=switch],label>[role=radio])]:py-1.5';\n\n/** The icon box before a message: 12px glyphs line up with the first line of caption text. */\nconst MESSAGE_ICON_CLASSES = 'mt-0.5 inline-flex shrink-0';\n\n/**\n * The icon before a message: the state's glyph while `icon` is `undefined`, else the consumer's\n * slot (`null` or content that renders nothing shows none).\n */\nfunction renderMessageIcon(state: ValidationState, icon: Slot<'span'> | undefined) {\n if (icon !== undefined) {\n return slotRendersContent(icon)\n ? renderSlot(icon, 'span', MESSAGE_ICON_CLASSES, { 'aria-hidden': true })\n : null;\n }\n const Icon = MESSAGE_ICONS[state];\n return Icon ? (\n <span aria-hidden=\"true\" className={MESSAGE_ICON_CLASSES}>\n <Icon size={12} />\n </span>\n ) : null;\n}\n\n/**\n * Lays out a form control with a label, a validation message, a hint and a required indicator,\n * and wires them to the control.\n *\n * - Validation: `validationMessage` with a `validationState` (`error`, `warning`, `success`,\n * `none`), or `error`, the shorthand for an error message. The message renders below the\n * control with the state's icon and color, followed by the hint (which stays visible); both\n * describe the control. Only the `error` state marks the control `aria-invalid`; `error` and\n * `warning` messages are announced (`role=\"alert\"`). The root carries `data-validation-state`\n * and `data-orientation`.\n * - `orientation=\"horizontal\"` puts the label in a start column beside the control, with the\n * message and the hint below the control. The label lines up with the first line of the\n * control (a Checkbox, Switch or RadioGroup gets 6px of padding above and below for it).\n * - Provides `FieldContext`: the library's inputs (Input, Select, Textarea, Slider, SearchBox,\n * Checkbox, Switch, RadioGroup, Rating, SpinButton, pickers, …) read it wherever they are inside\n * the Field and are named by the label, described by the message and the hint and marked\n * invalid/required.\n * - Merges into its **first** element child (a native `<input>`/`<select>`/`<textarea>`, a\n * library control or your own component): `id` (unless the child has one — the label then\n * points at the child's id), `aria-describedby` (joined with the child's own ids),\n * `aria-invalid` (in the error state), `aria-required` and, for native form controls that take a\n * value, `required`. Only defined values are merged; the child's own values are kept, so a\n * child's `aria-invalid={false}` stays valid while the Field error still describes it (as for a\n * library control nested deeper). Further element children are rendered as they are.\n * - `aria-required` is added only where it is allowed: components (Field cannot see what they\n * render, so they decide where it goes — see the wrapper note below), `<input>` (not\n * `type=\"button\"`/`\"submit\"`/`\"reset\"`/`\"image\"`), `<select>`, `<textarea>`, and elements\n * whose explicit `role` supports it (`checkbox`, `combobox`, `switch`, `textbox`, …). A\n * `<button>`, `<meter>`, `<output>` or `<progress>` is labelled and described but not marked\n * required.\n * - Your own widget built on an element with an explicit `role` (`<div role=\"radiogroup\">`) is\n * named through `aria-labelledby` (joined with its own; not added when it has an\n * `aria-label`), described, marked invalid, and gets `aria-required` when its role supports\n * it. It receives no `id`, because a `<label htmlFor>` cannot name it. A role-less `<div>` or\n * `<span>` wrapper (or a `role=\"presentation\"`/`\"none\"` one) is left alone: the library\n * control inside it reads `FieldContext`.\n * - A custom element (`<my-text-field>`) without a role is treated like a component: it receives\n * the `id`, the description and `aria-invalid` (a form-associated custom element is named by\n * the label). Field does not guess its semantics: pass `required`/`aria-required` or an\n * explicit `role` yourself.\n * - **One control per Field.** A Field labels and describes a single control; wrap each control\n * in its own Field (a development warning is logged when a Field has more than one element\n * child). Further element children are rendered as they are. A library control among them\n * still reads `FieldContext`, so it shares the Field's name and description (when the first\n * child holds the control id, it gets an id of its own and is named through\n * `aria-labelledby`). Several library controls inside one plain wrapper element (`<div>`) are\n * all named and described too: the first one takes the control id the label points at, the\n * others get ids of their own and are named through `aria-labelledby` (when the first one is\n * removed, the next one takes the control id over).\n * - **Wrapper and layout components around a library control** (a `Tooltip`, your own `Row`):\n * put them inside a plain element (`<div>`, `<div className=\"flex\">`), which Field leaves\n * alone; the library control inside then holds the control id and is labelled, described and\n * marked invalid/required through `FieldContext`. Field cannot see inside a component, so a\n * component **first child** is treated as the control (it may be your own input): it receives\n * the control `id`, `aria-describedby`, `aria-invalid` and, with `required`, `aria-required`,\n * and a wrapper puts them on its own element (Tooltip's `<span>`, the layout `<div>`). The\n * library control inside still gets an id of its own and is named by the label through\n * `aria-labelledby`, but clicking the label does not focus it, and with `required`,\n * `aria-required` on the wrapper's non-widget element is an ARIA error (axe\n * `aria-allowed-attr`), even though the control inside is correctly marked required.\n *\n * @example\n * <Field label=\"Email\" hint=\"We never share it\" error={errors.email} required>\n * <Input type=\"email\" value={email} onValueChange={setEmail} />\n * </Field>\n *\n * @example\n * <Field label=\"Password\" hint=\"At least 12 characters\" validationState=\"warning\"\n * validationMessage=\"This password is common\">\n * <Input type=\"password\" />\n * </Field>\n *\n * @example\n * // A wrapper component goes inside a plain element.\n * <Field label=\"Name\" required>\n * <div>\n * <Tooltip content=\"As on your passport\">\n * <Input />\n * </Tooltip>\n * </div>\n * </Field>\n */\nexport const Field = ({\n label,\n hint,\n error,\n validationState,\n validationMessage,\n validationMessageIcon,\n orientation = 'vertical',\n required = false,\n htmlFor,\n className,\n children,\n ref,\n ...rest\n}: FieldProps) => {\n const fieldId = useId('field');\n // Hands the control id to one library control when Field leaves its first child alone.\n const [controlIdClaim] = React.useState(createFieldControlIdClaim);\n const { elementCount, targetId, controlIdAssigned } = getChildInfo(children);\n\n // The library's \"renders nothing\" rule: nullish, booleans, '' and collections of only those (an\n // empty `errors.map(…)`) are no label, hint or message; `0` is content.\n const errorRendersContent = slotRendersContent(error);\n const usesError = error === true || errorRendersContent;\n const validationMessageRendersContent = slotRendersContent(validationMessage);\n // `error` is the shorthand for an error message and wins over the validation props.\n const state: ValidationState = usesError\n ? 'error'\n : (validationState ?? (validationMessageRendersContent ? 'error' : 'none'));\n const message = usesError ? (errorRendersContent ? error : undefined) : validationMessage;\n const hasMessage = usesError ? errorRendersContent : validationMessageRendersContent;\n const invalid = state === 'error';\n const hasHint = slotRendersContent(hint);\n const errorAndValidation =\n usesError &&\n (validationMessageRendersContent ||\n (validationState !== undefined && validationState !== 'error'));\n\n const controlId = targetId ?? htmlFor ?? fieldId;\n const hasLabel = slotRendersContent(label);\n const labelId = hasLabel ? `${fieldId}-label` : undefined;\n // The error message keeps its 0.5 id; the other states get their own.\n const messageId = hasMessage ? `${fieldId}-${invalid ? 'error' : 'message'}` : undefined;\n const errorId = invalid ? messageId : undefined;\n const hasErrorMessage = invalid && hasMessage;\n const hintId = hasHint ? `${fieldId}-hint` : undefined;\n\n React.useEffect(() => {\n if (elementCount > 1) {\n warnOnce(\n 'Field:multiple-children',\n \"Field: only the first element child receives the Field's id and ARIA attributes; the other \" +\n `${elementCount - 1} element child(ren) are rendered unchanged. Wrap each control in its own Field.`,\n );\n }\n }, [elementCount]);\n\n React.useEffect(() => {\n if (errorAndValidation) {\n warnOnce(\n 'Field:error-and-validation',\n 'Field: `error` and `validationMessage`/`validationState` are both set; `error` wins. Use one of them.',\n );\n }\n }, [errorAndValidation]);\n\n const context = React.useMemo<FieldContextValue>(\n () => ({\n controlId,\n labelId,\n hintId,\n errorId,\n invalid,\n required,\n hasErrorMessage,\n controlIdAssigned,\n controlIdClaim,\n validationState: state,\n validationMessageId: messageId,\n }),\n [\n controlId,\n labelId,\n hintId,\n errorId,\n invalid,\n required,\n hasErrorMessage,\n controlIdAssigned,\n controlIdClaim,\n state,\n messageId,\n ],\n );\n\n const content = mergeIntoFirstChild(children, {\n controlId,\n labelId,\n messageId,\n hintId,\n invalid,\n required,\n });\n\n const horizontal = orientation === 'horizontal';\n const control = (\n <>\n <FieldContext.Provider value={context}>{content}</FieldContext.Provider>\n {/* Keyed by state: a message whose state changes (a hint-only Field that gets an error, a\n warning that becomes an error) is a newly inserted element, which screen readers\n announce reliably as an alert, not an existing node with a new role. */}\n {hasMessage ? (\n <p\n key={`message-${state}`}\n id={messageId}\n role={state === 'error' || state === 'warning' ? 'alert' : undefined}\n data-validation-state={state}\n className={cn('mt-1 flex items-start gap-1 text-caption-1', MESSAGE_COLORS[state])}\n >\n {renderMessageIcon(state, validationMessageIcon)}\n <span>{materialiseSlotContent(message)}</span>\n </p>\n ) : null}\n {hasHint ? (\n <p key=\"hint\" id={hintId} className=\"mt-1 text-caption-1 text-muted-foreground\">\n {materialiseSlotContent(hint)}\n </p>\n ) : null}\n </>\n );\n\n return (\n <div\n ref={ref}\n data-orientation={orientation}\n data-validation-state={state}\n className={cn('flex', horizontal ? 'flex-row items-start gap-x-3' : 'flex-col', className)}\n {...rest}\n >\n {hasLabel ? (\n <label\n id={labelId}\n htmlFor={controlId}\n className={cn(\n 'mb-1 text-body-1 font-semibold text-foreground',\n // Beside the control: a third of the width, its first line centred on a 32px row.\n horizontal && 'mb-0 shrink-0 basis-1/3 pt-1.5',\n )}\n >\n {materialiseSlotContent(label)}\n {required && (\n <span aria-hidden=\"true\" className=\"ms-0.5 text-error\">\n *\n </span>\n )}\n </label>\n ) : null}\n {horizontal ? (\n <div className={cn('flex min-w-0 flex-1 flex-col', SHORT_ROW_FIRST_CHILD)}>{control}</div>\n ) : (\n control\n )}\n </div>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AOsD,CAAqB,GAC/C,kBAAC,QAAD,EAAA,UAAOC,EAAuB5B,CAAO,EAAQ,CAAA,CAC5C;EARI,GAAA,WAAW3B,GAQf,IACD;EACH8B,IACC,kBAAC,KAAD;GAAc,IAAIY;GAAQ,WAAU;GACjC,UAAAa,EAAuBxB,CAAI;EAC3B,GAFI,MAEJ,IACD;CACJ,EAAA,CAAA;CAGJ,OACE,kBAAC,OAAD;EACO;EACL,oBAAkBkB;EAClB,yBAAuBjD;EACvB,WAAWqD,EAAG,QAAQL,IAAa,iCAAiC,YAAYQ,CAAS;EACzF,GAAIvC;EALN,UAAA,CAOGmB,IACC,kBAAC,SAAD;GACE,IAAIE;GACJ,SAASL;GACT,WAAWoB,EACT,kDAEAL,KAAc,gCAChB;GAPF,UAAA,CASGO,EAAuBlB,CAAK,GAC5BQ,KACC,kBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;IAAoB,UAAA;GAEjD,CAAA,CAEH;EACL,CAAA,IAAA,MACHG,IACC,kBAAC,OAAD;GAAK,WAAWK,EAAG,gCAAgC5C,CAAqB;GAAI,UAAAyC;EAAa,CAAA,IAEzFA,CAEC;;AAET;AAEA,EAAM,cAAc"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/slot.cjs"),r=require("../../hooks/useId.cjs"),i=require("../../lib/aria.cjs"),a=require("../../hooks/useFieldControl.cjs"),o=require("../../lib/styles.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("react/jsx-runtime");function l(e){return e===!1||e===`false`}function u(e,n,i){let o=a.useFieldContext(),s=r.useId(`error`),u=!l(i)&&(e===!0||typeof e==`string`&&e!==``);if(!u||typeof e!=`string`||o?.hasErrorMessage)return{invalid:u,messageId:void 0,message:null};let{id:d,className:f,...p}=n??{},m=d??s;return{invalid:u,messageId:m,message:(0,c.jsx)(`span`,{role:`alert`,...p,id:m,className:t.cn(`mt-1 block text-caption-1 text-error`,f),children:e})}}function d(e,t){return l(t)?!1:e||t===!0||t===`true`}var f=({error:e,errorMessageProps:r,contentBefore:s,contentAfter:l,onChange:f,onValueChange:p,className:m,ref:h,id:g,"aria-label":_,"aria-labelledby":v,"aria-describedby":y,"aria-invalid":b,"aria-required":x,"aria-errormessage":S,required:C,...w})=>{let{invalid:T,messageId:E,message:D}=u(e,r,b),O=a.useFieldControl({id:g,"aria-label":_,"aria-labelledby":v,"aria-describedby":i.joinIds(y,E),"aria-invalid":b??(T||void 0),"aria-required":x,required:C},{nativeRequired:!0}),k=d(T,O[`aria-invalid`]),A=f||p?e=>{f?.(e),p?.(e.currentTarget.value)}:void 0,j={...w,...O,"aria-errormessage":i.joinIds(S,E),onChange:A},M=n.slotRendersContent(s),N=n.slotRendersContent(l),P;if(M||N){let{style:e,hidden:r,...i}=j;P=(0,c.jsxs)(`span`,{hidden:r,style:e,className:t.cn(`inline-flex h-8 w-full items-center rounded border border-input border-b-stroke-accessible bg-background text-body-1 text-foreground`,o.inputFocusWithin,k&&`border-destructive focus-within:border-b-destructive`,w.disabled&&`cursor-not-allowed opacity-50 has-focus-visible:opacity-100`,m),children:[M&&n.renderSlot(s,`span`,`shrink-0 ps-2`),(0,c.jsx)(`input`,{ref:h,className:t.cn(`h-full w-full min-w-0 bg-transparent px-2 text-body-1 text-foreground`,`placeholder:text-muted-foreground`,`focus:outline-hidden`,`disabled:cursor-not-allowed`),...i}),N&&n.renderSlot(l,`span`,`shrink-0 pe-2`)]})}else P=(0,c.jsx)(`input`,{ref:h,className:t.cn(`h-8 w-full rounded border border-input border-b-stroke-accessible bg-background px-3 text-body-1 text-foreground`,`placeholder:text-muted-foreground`,o.inputFocus,`disabled:cursor-not-allowed disabled:opacity-50`,k&&`border-destructive focus:border-b-destructive`,m),...j});return D?(0,c.jsxs)(c.Fragment,{children:[P,D]}):P};f.displayName=`Input`,exports.Input=f,exports.isInvalidLook=d,exports.useControlErrorMessage=u;
|
|
2
|
+
//# sourceMappingURL=Input.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Input.cjs","names":["useFieldContext","useId","_jsx","cn","useFieldControl","joinIds","slotRendersContent","inputFocusWithin","renderSlot","inputFocus","_Fragment","require_runtime","require_cn","require_slot","require_useId","require_aria","require_useFieldControl","require_styles","react","react_jsx_runtime","isAriaValid","ariaInvalid","useControlErrorMessage","field","generatedId","invalid","consumerAriaInvalid","error","ownId","messageClassName","messageRest","errorMessageProps","messageId","isInvalidLook","ownError","Input","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaRequired","ariaErrorMessage","props","fieldProps","invalidLook","handleChange","onChange","onValueChange","event","controlProps","hasBefore","contentBefore","hasAfter","contentAfter","control","inputProps","className","message"],"sources":["../../../src/components/input/Input.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../lib/cn';\nimport { joinIds } from '../../lib/aria';\nimport { renderSlot, slotRendersContent } from '../../lib/slot';\nimport { inputFocus, inputFocusWithin, inputInvalid, inputInvalidWithin } from '../../lib/styles';\nimport type { Slot } from '../../lib/types';\nimport { useId } from '../../hooks/useId';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\n\n/**\n * Props of the error message element that {@link Input}, `Select` and `Textarea` render after the\n * control for a string `error` (`id`, `className`, `role`, data attributes, …).\n */\nexport interface InputErrorMessageProps extends React.HTMLAttributes<HTMLSpanElement> {\n /** Ref to the message `<span>`. */\n ref?: React.Ref<HTMLSpanElement>;\n /** Any `data-*` attribute. */\n [dataAttribute: `data-${string}`]: unknown;\n}\n\n/**\n * Result of {@link useControlErrorMessage}.\n *\n * @internal Not exported from the package.\n */\nexport interface ControlErrorMessage {\n /**\n * Whether `error` marks the control invalid (a non-empty string or `true`), unless the consumer\n * set `aria-invalid` to `false`/`\"false\"`.\n */\n invalid: boolean;\n /** The id of the rendered message, joined into `aria-describedby`/`aria-errormessage`. */\n messageId: string | undefined;\n /** The message element to render after the control, or `null`. */\n message: React.ReactElement | null;\n}\n\n/** Whether an `aria-invalid` value explicitly reports the control as valid. */\nfunction isAriaValid(ariaInvalid: React.AriaAttributes['aria-invalid']): boolean {\n return ariaInvalid === false || ariaInvalid === 'false';\n}\n\n/**\n * Shared by Input, Select and Textarea (internal): a non-empty string `error` renders a sibling\n * `<span role=\"alert\">` message, unless the surrounding `Field` already renders its own error\n * (`FieldContext.hasErrorMessage`); `true` only marks the control invalid. The consumer's\n * `aria-invalid` of `false`/`\"false\"` wins over `error`: the control is valid, so nothing is\n * marked invalid and no message is rendered or referenced (ARIA: an error message of a valid\n * control is hidden).\n *\n * @internal Not exported from the package.\n */\nexport function useControlErrorMessage(\n error: string | boolean | undefined,\n errorMessageProps: InputErrorMessageProps | undefined,\n consumerAriaInvalid?: React.AriaAttributes['aria-invalid'],\n): ControlErrorMessage {\n const field = useFieldContext();\n const generatedId = useId('error');\n const invalid =\n !isAriaValid(consumerAriaInvalid) &&\n (error === true || (typeof error === 'string' && error !== ''));\n const showMessage = invalid && typeof error === 'string' && !field?.hasErrorMessage;\n if (!showMessage) return { invalid, messageId: undefined, message: null };\n\n const { id: ownId, className: messageClassName, ...messageRest } = errorMessageProps ?? {};\n const messageId = ownId ?? generatedId;\n const message = (\n <span\n role=\"alert\"\n {...messageRest}\n id={messageId}\n className={cn('mt-1 block text-caption-1 text-error', messageClassName)}\n >\n {error}\n </span>\n );\n return { invalid, messageId, message };\n}\n\n/**\n * Whether a text control shows the invalid look (error border), shared by Input, Select, Textarea\n * and SearchBox (internal): its own `error`, or a resolved `aria-invalid` of `true`/`\"true\"` —\n * from the consumer or from the surrounding `Field` (`useFieldControl`) — so the look always\n * matches the state assistive technology reports. A resolved `false`/`\"false\"` (the consumer's\n * override) never shows it, even with an own `error`. `\"grammar\"`/`\"spelling\"` alone do not\n * count; with an own `error` they keep the look (the control is reported invalid).\n *\n * @internal Not exported from the package.\n */\nexport function isInvalidLook(\n ownError: boolean,\n ariaInvalid: React.AriaAttributes['aria-invalid'],\n): boolean {\n if (isAriaValid(ariaInvalid)) return false;\n return ownError || ariaInvalid === true || ariaInvalid === 'true';\n}\n\n/** Properties for the Input component. */\nexport interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {\n /**\n * Validation error.\n * - A non-empty string renders the message in a `role=\"alert\"` element **after** the field (a\n * sibling, so it does not change which element receives `ref`, `className` or `style`) and\n * links it through `aria-describedby` and `aria-errormessage`. Inside a `Field` that renders\n * its own `error`, the message is not repeated.\n * - `true` only marks the input invalid (`aria-invalid` and the error border), as in 0.4.\n *\n * The error border also shows whenever the input ends up `aria-invalid=\"true\"` without this\n * prop (an `error` on the surrounding `Field`, or your own `aria-invalid`).\n * Your own `aria-invalid={false}` (or `\"false\"`) wins over this prop: the input is reported\n * valid and shows neither the error border nor the message.\n * Use `Field` (`label`, `hint`, `error`) for a complete field layout.\n */\n error?: string | boolean;\n /** Props of the error message element (`id`, `className`, …) rendered for a string `error`. */\n errorMessageProps?: InputErrorMessageProps;\n /**\n * Slot rendered before the input text (e.g., an icon). With content in either slot, a bordered\n * `<span>` around the input draws the field: it receives `className`, `style` and `hidden`,\n * while `ref`, `id`, `aria-*`, `data-*`, handlers and native attributes stay on the `<input>`.\n * A value that renders nothing (`false`, `''`, `[]`) is no slot.\n */\n contentBefore?: Slot<'span'>;\n /** Slot rendered after the input text (e.g., a suffix). Same wrapper as `contentBefore`. */\n contentAfter?: Slot<'span'>;\n /**\n * Called with the new string value on every change, next to the native `onChange` event\n * handler (`onValueChange={setName}` instead of `onChange={(e) => setName(e.target.value)}`).\n */\n onValueChange?: (value: string) => void;\n /** Ref to the `<input>` element (also with `contentBefore`/`contentAfter`). */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n/**\n * A single-line text input with Fluent styling: a 1px border with an accessible bottom stroke, a\n * primary bottom border while focused, optional `contentBefore`/`contentAfter` slots and an\n * optional error message. Inside a `Field` it picks up the label, hint, error, `required` (native\n * attribute) and invalid state automatically.\n *\n * Every prop reaches the `<input>`, except with slot content: then a bordered `<span>` wrapper\n * draws the field and receives `className`, `style` and `hidden` (`ref` stays on the input).\n *\n * @example\n * <Field label=\"Email\" hint=\"We never share it\" required>\n * <Input type=\"email\" value={email} onValueChange={setEmail} />\n * </Field>\n */\nexport const Input = ({\n error,\n errorMessageProps,\n contentBefore,\n contentAfter,\n onChange,\n onValueChange,\n className,\n ref,\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 required,\n ...props\n}: InputProps) => {\n const { invalid, messageId, message } = useControlErrorMessage(\n error,\n errorMessageProps,\n ariaInvalid,\n );\n const fieldProps = useFieldControl(\n {\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': joinIds(ariaDescribedBy, messageId),\n 'aria-invalid': ariaInvalid ?? (invalid || undefined),\n 'aria-required': ariaRequired,\n required,\n },\n { nativeRequired: true },\n );\n const invalidLook = isInvalidLook(invalid, fieldProps['aria-invalid']);\n\n const handleChange =\n onChange || onValueChange\n ? (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event);\n onValueChange?.(event.currentTarget.value);\n }\n : undefined;\n\n const controlProps = {\n ...props,\n ...fieldProps,\n 'aria-errormessage': joinIds(ariaErrorMessage, messageId),\n onChange: handleChange,\n };\n\n const hasBefore = slotRendersContent(contentBefore);\n const hasAfter = slotRendersContent(contentAfter);\n\n let control: React.ReactElement;\n if (hasBefore || hasAfter) {\n // The bordered wrapper is the visible field: `className`, `style` and `hidden` size, style and\n // hide it; `ref`, `id`, `aria-*`, `data-*`, handlers and native attributes go to the input.\n const { style, hidden, ...inputProps } = controlProps;\n control = (\n <span\n hidden={hidden}\n style={style}\n className={cn(\n 'inline-flex h-8 w-full items-center rounded border border-input border-b-stroke-accessible bg-background text-body-1 text-foreground',\n inputFocusWithin,\n invalidLook && inputInvalidWithin,\n // The dimmed look lifts while a focus ring shows inside the wrapper (focusable slot\n // content; the disabled input never takes focus): opacity would dim the ring below 3:1.\n props.disabled && 'cursor-not-allowed opacity-50 has-focus-visible:opacity-100',\n className,\n )}\n >\n {hasBefore && renderSlot(contentBefore, 'span', 'shrink-0 ps-2')}\n <input\n ref={ref}\n className={cn(\n 'h-full w-full min-w-0 bg-transparent px-2 text-body-1 text-foreground',\n 'placeholder:text-muted-foreground',\n 'focus:outline-hidden',\n 'disabled:cursor-not-allowed',\n )}\n {...inputProps}\n />\n {hasAfter && renderSlot(contentAfter, 'span', 'shrink-0 pe-2')}\n </span>\n );\n } else {\n control = (\n <input\n ref={ref}\n className={cn(\n 'h-8 w-full rounded border border-input border-b-stroke-accessible bg-background px-3 text-body-1 text-foreground',\n 'placeholder:text-muted-foreground',\n inputFocus,\n 'disabled:cursor-not-allowed disabled:opacity-50',\n invalidLook && inputInvalid,\n className,\n )}\n {...controlProps}\n />\n );\n }\n\n if (!message) return control;\n return (\n <>\n {control}\n {message}\n </>\n );\n};\n\nInput.displayName = 'Input';\n"],"mappings":"gWAsCA,SAASoB,EAAY,EAA4D,CAC/E,OAAOC,IAAgB,IAASA,IAAgB,OAClD,CAYA,SAAgBC,EACd,EACA,EACA,EACqB,CACrB,IAAMC,EAAQvB,EAAAA,gBAAgB,EACxBwB,EAAcvB,EAAAA,MAAM,OAAO,EAC3BwB,EACJ,CAACL,EAAYM,CAAmB,IAC/BC,IAAU,IAAS,OAAOA,GAAU,UAAYA,IAAU,IAE7D,GADoB,IAAW,OAAOA,GAAU,UAAaJ,GAAO,gBAClD,MAAO,CAAE,UAAS,UAAW,IAAA,GAAW,QAAS,IAAK,EAExE,GAAM,CAAE,GAAIK,EAAO,UAAWC,EAAkB,GAAGC,GAAgBC,GAAqB,CAAC,EACnFC,EAAYJ,GAASJ,EAW3B,MAAO,CAAE,UAAS,YAAW,SAAA,EAT3BtB,EAAAA,IAAAA,CAAC,OAAD,CACE,KAAK,QACL,GAAI4B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