@cube-dev/ui-kit 0.147.2 → 0.148.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/dist/CHANGELOG.md +22 -0
- package/dist/_internal/hooks/use-chained-callback.js +1 -1
- package/dist/_internal/hooks/use-debounced-value.js +1 -1
- package/dist/_internal/hooks/use-deprecation-warning.js +1 -1
- package/dist/_internal/hooks/use-event.js +1 -1
- package/dist/_internal/hooks/use-is-first-render.js +1 -1
- package/dist/_internal/hooks/use-sync-ref.js +1 -1
- package/dist/_internal/hooks/use-timer/timer.js +1 -1
- package/dist/_internal/hooks/use-timer/use-timer.js +1 -1
- package/dist/_internal/hooks/use-warn.js +1 -1
- package/dist/components/Block.js +1 -1
- package/dist/components/CollectionItem.js +1 -1
- package/dist/components/GlobalStyles.js +24 -3
- package/dist/components/GlobalStyles.js.map +1 -1
- package/dist/components/GridProvider.js +1 -1
- package/dist/components/HiddenInput.js +1 -1
- package/dist/components/Root.js +1 -1
- package/dist/components/actions/Action/Action.js +1 -1
- package/dist/components/actions/Banner/Banner.js +1 -1
- package/dist/components/actions/Button/Button.js +1 -1
- package/dist/components/actions/ButtonGroup/ButtonGroup.js +1 -1
- package/dist/components/actions/ButtonSplit/ButtonSplit.js +1 -1
- package/dist/components/actions/ButtonSplit/context.js +1 -1
- package/dist/components/actions/CommandMenu/CommandMenu.js +1 -1
- package/dist/components/actions/CommandMenu/styled.js +1 -1
- package/dist/components/actions/ItemAction/ItemAction.js +1 -1
- package/dist/components/actions/ItemActionContext.js +1 -1
- package/dist/components/actions/ItemButton/ItemButton.js +1 -1
- package/dist/components/actions/Link/Link.js +1 -1
- package/dist/components/actions/Menu/Menu.js +1 -1
- package/dist/components/actions/Menu/MenuItem.js +1 -1
- package/dist/components/actions/Menu/MenuSection.js +1 -1
- package/dist/components/actions/Menu/MenuTrigger.js +1 -1
- package/dist/components/actions/Menu/SubMenuTrigger.js +1 -1
- package/dist/components/actions/Menu/SubmenuTriggerContext.js +1 -1
- package/dist/components/actions/Menu/context.js +1 -1
- package/dist/components/actions/Menu/styled.js +1 -1
- package/dist/components/actions/index.js +1 -1
- package/dist/components/actions/use-action.js +1 -1
- package/dist/components/actions/use-anchored-menu.js +1 -1
- package/dist/components/actions/use-context-menu.js +1 -1
- package/dist/components/content/ActiveZone/ActiveZone.js +1 -1
- package/dist/components/content/Alert/Alert.js +1 -1
- package/dist/components/content/Alert/use-alert.js +1 -1
- package/dist/components/content/Avatar/Avatar.js +1 -1
- package/dist/components/content/Badge/Badge.js +1 -1
- package/dist/components/content/Card/Card.js +1 -1
- package/dist/components/content/Content.js +1 -1
- package/dist/components/content/CopyPasteBlock/CopyPasteBlock.js +1 -1
- package/dist/components/content/CopySnippet/CopySnippet.js +1 -1
- package/dist/components/content/Disclosure/Disclosure.js +1 -1
- package/dist/components/content/Divider.js +1 -1
- package/dist/components/content/Footer.js +1 -1
- package/dist/components/content/Header.js +1 -1
- package/dist/components/content/HotKeys/HotKeys.js +1 -1
- package/dist/components/content/InlineInput/InlineInput.js +1 -1
- package/dist/components/content/Item/Item.js +1 -1
- package/dist/components/content/ItemBadge/ItemBadge.js +1 -1
- package/dist/components/content/ItemCard/ItemCard.js +1 -1
- package/dist/components/content/Layout/GridLayout.js +1 -1
- package/dist/components/content/Layout/Layout.js +1 -1
- package/dist/components/content/Layout/LayoutBlock.js +1 -1
- package/dist/components/content/Layout/LayoutCenter.js +1 -1
- package/dist/components/content/Layout/LayoutContainer.js +1 -1
- package/dist/components/content/Layout/LayoutContent.js +1 -1
- package/dist/components/content/Layout/LayoutContext.js +1 -1
- package/dist/components/content/Layout/LayoutFlex.js +1 -1
- package/dist/components/content/Layout/LayoutFooter.js +1 -1
- package/dist/components/content/Layout/LayoutGrid.js +1 -1
- package/dist/components/content/Layout/LayoutHeader.js +1 -1
- package/dist/components/content/Layout/LayoutPane.js +1 -1
- package/dist/components/content/Layout/LayoutPanel.js +1 -1
- package/dist/components/content/Layout/LayoutPanelHeader.js +1 -1
- package/dist/components/content/Layout/LayoutToolbar.js +1 -1
- package/dist/components/content/Layout/hooks/useTinyScrollbar.js +1 -1
- package/dist/components/content/Layout/index.js +1 -1
- package/dist/components/content/Layout/utils.js +1 -1
- package/dist/components/content/Paragraph.js +1 -1
- package/dist/components/content/Placeholder/Placeholder.js +1 -1
- package/dist/components/content/PrismCode/PrismCode.d.ts +1 -0
- package/dist/components/content/PrismCode/PrismCode.js +2 -1
- package/dist/components/content/PrismCode/PrismCode.js.map +1 -1
- package/dist/components/content/PrismCode/prismSetup.js +1 -1
- package/dist/components/content/PrismDiffCode/PrismDiffCode.js +1 -1
- package/dist/components/content/Result/Result.js +1 -1
- package/dist/components/content/Skeleton/Skeleton.js +1 -1
- package/dist/components/content/Tag/Tag.js +1 -1
- package/dist/components/content/Text.js +1 -1
- package/dist/components/content/TextItem/TextItem.js +1 -1
- package/dist/components/content/Title.js +1 -1
- package/dist/components/content/Tree/Tree.js +1 -1
- package/dist/components/content/Tree/TreeNode.js +1 -1
- package/dist/components/content/Tree/styled.js +1 -1
- package/dist/components/content/Tree/tree-index.js +1 -1
- package/dist/components/content/Tree/use-checkbox-tree.js +1 -1
- package/dist/components/content/Tree/use-load-data.js +1 -1
- package/dist/components/content/highlightText.js +1 -1
- package/dist/components/content/use-auto-tooltip.js +1 -1
- package/dist/components/fields/Checkbox/Checkbox.js +17 -17
- package/dist/components/fields/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/fields/Checkbox/CheckboxGroup.js +5 -8
- package/dist/components/fields/Checkbox/CheckboxGroup.js.map +1 -1
- package/dist/components/fields/Checkbox/context.js +1 -1
- package/dist/components/fields/ComboBox/ComboBox.d.ts +0 -2
- package/dist/components/fields/ComboBox/ComboBox.js +26 -23
- package/dist/components/fields/ComboBox/ComboBox.js.map +1 -1
- package/dist/components/fields/CommandTextArea/CommandTextArea.js +1 -5
- package/dist/components/fields/CommandTextArea/CommandTextArea.js.map +1 -1
- package/dist/components/fields/CommandTextArea/caretPosition.js +1 -1
- package/dist/components/fields/CommandTextArea/useCaretAnchor.js +1 -1
- package/dist/components/fields/DatePicker/DateInput.d.ts +1 -2
- package/dist/components/fields/DatePicker/DateInput.js +4 -7
- package/dist/components/fields/DatePicker/DateInput.js.map +1 -1
- package/dist/components/fields/DatePicker/DateInputBase.js +21 -14
- package/dist/components/fields/DatePicker/DateInputBase.js.map +1 -1
- package/dist/components/fields/DatePicker/DatePicker.d.ts +1 -2
- package/dist/components/fields/DatePicker/DatePicker.js +4 -7
- package/dist/components/fields/DatePicker/DatePicker.js.map +1 -1
- package/dist/components/fields/DatePicker/DatePickerButton.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerElement.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerInput.js +1 -1
- package/dist/components/fields/DatePicker/DatePickerSegment.js +1 -1
- package/dist/components/fields/DatePicker/DateRangePicker.d.ts +1 -2
- package/dist/components/fields/DatePicker/DateRangePicker.js +4 -7
- package/dist/components/fields/DatePicker/DateRangePicker.js.map +1 -1
- package/dist/components/fields/DatePicker/DateRangeSeparatedPicker.d.ts +1 -2
- package/dist/components/fields/DatePicker/DateRangeSeparatedPicker.js +6 -8
- package/dist/components/fields/DatePicker/DateRangeSeparatedPicker.js.map +1 -1
- package/dist/components/fields/DatePicker/TimeInput.d.ts +1 -2
- package/dist/components/fields/DatePicker/TimeInput.js +4 -7
- package/dist/components/fields/DatePicker/TimeInput.js.map +1 -1
- package/dist/components/fields/DatePicker/parseDate.js +1 -1
- package/dist/components/fields/DatePicker/props.js +1 -1
- package/dist/components/fields/DatePicker/utils.js +1 -1
- package/dist/components/fields/FileInput/FileInput.js +26 -7
- package/dist/components/fields/FileInput/FileInput.js.map +1 -1
- package/dist/components/fields/FilterListBox/FilterListBox.js +11 -11
- package/dist/components/fields/FilterListBox/FilterListBox.js.map +1 -1
- package/dist/components/fields/FilterPicker/FilterPicker.js +20 -10
- package/dist/components/fields/FilterPicker/FilterPicker.js.map +1 -1
- package/dist/components/fields/Input/Input.js +1 -1
- package/dist/components/fields/ListBox/DraggableListBox.js +1 -1
- package/dist/components/fields/ListBox/ListBox.js +35 -27
- package/dist/components/fields/ListBox/ListBox.js.map +1 -1
- package/dist/components/fields/ListBoxPopover/ListBoxPopover.js +1 -1
- package/dist/components/fields/ListBoxPopover/listNavigation.js +1 -1
- package/dist/components/fields/ListBoxPopover/useCompositeFocus.js +1 -1
- package/dist/components/fields/NumberInput/NumberInput.js +1 -3
- package/dist/components/fields/NumberInput/NumberInput.js.map +1 -1
- package/dist/components/fields/NumberInput/StepButton.js +1 -1
- package/dist/components/fields/PasswordInput/PasswordInput.js +1 -3
- package/dist/components/fields/PasswordInput/PasswordInput.js.map +1 -1
- package/dist/components/fields/Picker/Picker.js +20 -10
- package/dist/components/fields/Picker/Picker.js.map +1 -1
- package/dist/components/fields/RadioGroup/Radio.d.ts +0 -1
- package/dist/components/fields/RadioGroup/Radio.js +14 -8
- package/dist/components/fields/RadioGroup/Radio.js.map +1 -1
- package/dist/components/fields/RadioGroup/RadioGroup.d.ts +0 -1
- package/dist/components/fields/RadioGroup/RadioGroup.js +4 -7
- package/dist/components/fields/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/fields/RadioGroup/context.js +1 -1
- package/dist/components/fields/SearchComboBox/SearchComboBox.d.ts +0 -2
- package/dist/components/fields/SearchComboBox/SearchComboBox.js +21 -12
- package/dist/components/fields/SearchComboBox/SearchComboBox.js.map +1 -1
- package/dist/components/fields/SearchInput/SearchInput.d.ts +1 -1
- package/dist/components/fields/SearchInput/SearchInput.js +11 -4
- package/dist/components/fields/SearchInput/SearchInput.js.map +1 -1
- package/dist/components/fields/Select/Select.js +22 -22
- package/dist/components/fields/Select/Select.js.map +1 -1
- package/dist/components/fields/Slider/Gradation.js +1 -1
- package/dist/components/fields/Slider/HueSlider.js +1 -1
- package/dist/components/fields/Slider/RangeSlider.js +10 -4
- package/dist/components/fields/Slider/RangeSlider.js.map +1 -1
- package/dist/components/fields/Slider/Slider.js +6 -2
- package/dist/components/fields/Slider/Slider.js.map +1 -1
- package/dist/components/fields/Slider/SliderBase.js +18 -8
- package/dist/components/fields/Slider/SliderBase.js.map +1 -1
- package/dist/components/fields/Slider/SliderThumb.js +11 -4
- package/dist/components/fields/Slider/SliderThumb.js.map +1 -1
- package/dist/components/fields/Slider/SliderTrack.js +15 -4
- package/dist/components/fields/Slider/SliderTrack.js.map +1 -1
- package/dist/components/fields/Slider/elements.js +5 -1
- package/dist/components/fields/Slider/elements.js.map +1 -1
- package/dist/components/fields/Slider/index.js +1 -1
- package/dist/components/fields/Switch/Switch.js +11 -9
- package/dist/components/fields/Switch/Switch.js.map +1 -1
- package/dist/components/fields/TextArea/TextArea.js +1 -3
- package/dist/components/fields/TextArea/TextArea.js.map +1 -1
- package/dist/components/fields/TextInput/TextInput.js +1 -3
- package/dist/components/fields/TextInput/TextInput.js.map +1 -1
- package/dist/components/fields/TextInput/TextInputBase.js +29 -33
- package/dist/components/fields/TextInput/TextInputBase.js.map +1 -1
- package/dist/components/fields/TextInputMapper/TextInputMapper.d.ts +2 -0
- package/dist/components/fields/TextInputMapper/TextInputMapper.js +13 -5
- package/dist/components/fields/TextInputMapper/TextInputMapper.js.map +1 -1
- package/dist/components/form/FieldWrapper/FieldWrapper.d.ts +29 -2
- package/dist/components/form/FieldWrapper/FieldWrapper.js +11 -7
- package/dist/components/form/FieldWrapper/FieldWrapper.js.map +1 -1
- package/dist/components/form/FieldWrapper/index.d.ts +1 -2
- package/dist/components/form/FieldWrapper/types.d.ts +2 -3
- package/dist/components/form/Form/Field.js +8 -5
- package/dist/components/form/Form/Field.js.map +1 -1
- package/dist/components/form/Form/Form.js +6 -4
- package/dist/components/form/Form/Form.js.map +1 -1
- package/dist/components/form/Form/ResetButton/ResetButton.js +1 -1
- package/dist/components/form/Form/SubmitButton/SubmitButton.js +1 -1
- package/dist/components/form/Form/SubmitError.js +1 -1
- package/dist/components/form/Form/index.js +1 -1
- package/dist/components/form/Form/use-field/types.d.ts +7 -5
- package/dist/components/form/Form/use-field/use-field-props.js +7 -1
- package/dist/components/form/Form/use-field/use-field-props.js.map +1 -1
- package/dist/components/form/Form/use-field/use-field.js +8 -6
- package/dist/components/form/Form/use-field/use-field.js.map +1 -1
- package/dist/components/form/Form/use-form.js +1 -1
- package/dist/components/form/Form/validation.js +1 -1
- package/dist/components/form/Label.d.ts +2 -3
- package/dist/components/form/Label.js +7 -4
- package/dist/components/form/Label.js.map +1 -1
- package/dist/components/form/index.d.ts +6 -3
- package/dist/components/form/validation/ValidationIndicator.d.ts +28 -0
- package/dist/components/form/validation/ValidationIndicator.js +37 -0
- package/dist/components/form/validation/ValidationIndicator.js.map +1 -0
- package/dist/components/form/validation/index.d.ts +4 -0
- package/dist/components/form/validation/resolve-validation-props.d.ts +51 -0
- package/dist/components/form/validation/resolve-validation-props.js +49 -0
- package/dist/components/form/validation/resolve-validation-props.js.map +1 -0
- package/dist/components/form/validation/use-validation-props.d.ts +16 -0
- package/dist/components/form/validation/use-validation-props.js +29 -0
- package/dist/components/form/validation/use-validation-props.js.map +1 -0
- package/dist/components/form/wrapper.d.ts +5 -1
- package/dist/components/form/wrapper.js +8 -3
- package/dist/components/form/wrapper.js.map +1 -1
- package/dist/components/helpers/DisplayTransition/DisplayTransition.js +1 -1
- package/dist/components/helpers/IconSwitch/IconSwitch.js +1 -1
- package/dist/components/layout/Board/Board.js +1 -1
- package/dist/components/layout/Board/BoardProvider.js +1 -1
- package/dist/components/layout/Board/BoardResponsive.js +1 -1
- package/dist/components/layout/Board/Widget.js +1 -1
- package/dist/components/layout/Board/WidgetHost.js +1 -1
- package/dist/components/layout/Board/board-context.js +1 -1
- package/dist/components/layout/Board/board-store.js +1 -1
- package/dist/components/layout/Board/grid-core/calculate.js +1 -1
- package/dist/components/layout/Board/grid-core/collision.js +1 -1
- package/dist/components/layout/Board/grid-core/compactors.js +1 -1
- package/dist/components/layout/Board/grid-core/constraints.js +1 -1
- package/dist/components/layout/Board/grid-core/layout.js +1 -1
- package/dist/components/layout/Board/grid-core/sort.js +1 -1
- package/dist/components/layout/Board/index.js +1 -1
- package/dist/components/layout/Board/responsive-utils.js +1 -1
- package/dist/components/layout/Board/use-board-layout.js +1 -1
- package/dist/components/layout/Board/use-board-registry.js +1 -1
- package/dist/components/layout/Flex.js +1 -1
- package/dist/components/layout/Flow.js +1 -1
- package/dist/components/layout/Grid.js +1 -1
- package/dist/components/layout/Panel.js +1 -1
- package/dist/components/layout/Prefix.js +1 -1
- package/dist/components/layout/ResizablePanel.js +1 -1
- package/dist/components/layout/Space.js +1 -1
- package/dist/components/layout/Suffix.js +1 -1
- package/dist/components/navigation/Tabs/DraggableTabList.js +1 -1
- package/dist/components/navigation/Tabs/TabButton.js +1 -1
- package/dist/components/navigation/Tabs/TabDropIndicator.js +1 -1
- package/dist/components/navigation/Tabs/TabPanel.js +1 -1
- package/dist/components/navigation/Tabs/TabPicker.js +1 -1
- package/dist/components/navigation/Tabs/Tabs.js +1 -1
- package/dist/components/navigation/Tabs/TabsAction.js +1 -1
- package/dist/components/navigation/Tabs/TabsContext.js +1 -1
- package/dist/components/navigation/Tabs/popover-placement.js +1 -1
- package/dist/components/navigation/Tabs/styled.js +1 -1
- package/dist/components/navigation/Tabs/types.js +1 -1
- package/dist/components/navigation/Tabs/use-tab-editing.js +1 -1
- package/dist/components/navigation/Tabs/use-tab-indicator.js +1 -1
- package/dist/components/organisms/FileTabs/FileTabs.js +1 -1
- package/dist/components/organisms/StatsCard/StatsCard.js +1 -1
- package/dist/components/other/Calendar/Calendar.js +1 -1
- package/dist/components/other/Calendar/CalendarCell.js +1 -1
- package/dist/components/other/Calendar/CalendarGrid.js +1 -1
- package/dist/components/other/Calendar/RangeCalendar.js +1 -1
- package/dist/components/other/CloudLogo/CloudLogo.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialog.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialogApiProvider.js +1 -1
- package/dist/components/overlays/AlertDialog/AlertDialogZone.js +1 -1
- package/dist/components/overlays/Dialog/Dialog.js +1 -1
- package/dist/components/overlays/Dialog/DialogContainer.js +1 -1
- package/dist/components/overlays/Dialog/DialogForm.js +4 -3
- package/dist/components/overlays/Dialog/DialogForm.js.map +1 -1
- package/dist/components/overlays/Dialog/DialogTrigger.js +1 -1
- package/dist/components/overlays/Dialog/context.js +1 -1
- package/dist/components/overlays/Dialog/use-dialog-container.js +1 -1
- package/dist/components/overlays/Modal/Modal.js +1 -1
- package/dist/components/overlays/Modal/OpenTransitionContext.js +1 -1
- package/dist/components/overlays/Modal/Overlay.js +1 -1
- package/dist/components/overlays/Modal/Popover.js +1 -1
- package/dist/components/overlays/Modal/Tray.js +1 -1
- package/dist/components/overlays/Modal/Underlay.js +1 -1
- package/dist/components/overlays/Notifications/Notification.js +1 -1
- package/dist/components/overlays/Notifications/NotificationAction.js +1 -1
- package/dist/components/overlays/Notifications/NotificationCard.js +1 -1
- package/dist/components/overlays/Notifications/NotificationContext.js +1 -1
- package/dist/components/overlays/Notifications/NotificationItem.js +1 -1
- package/dist/components/overlays/Notifications/OverlayContainer.js +1 -1
- package/dist/components/overlays/Notifications/OverlayProvider.js +1 -1
- package/dist/components/overlays/Notifications/PersistentNotificationsList.js +1 -1
- package/dist/components/overlays/Notifications/dismissed-storage.js +1 -1
- package/dist/components/overlays/Notifications/format-relative-time.js +1 -1
- package/dist/components/overlays/Notifications/index.js +1 -1
- package/dist/components/overlays/Notifications/use-notification-state.js +1 -1
- package/dist/components/overlays/Notifications/use-notifications.js +1 -1
- package/dist/components/overlays/Notifications/use-overlay-timers.js +1 -1
- package/dist/components/overlays/Notifications/use-persistent-notifications.js +1 -1
- package/dist/components/overlays/Notifications/use-persistent-state.js +1 -1
- package/dist/components/overlays/Notifications/use-toast-state.js +1 -1
- package/dist/components/overlays/Toast/ToastItem.js +1 -1
- package/dist/components/overlays/Toast/index.js +1 -1
- package/dist/components/overlays/Toast/useProgressToast.js +1 -1
- package/dist/components/overlays/Toast/useToast.js +1 -1
- package/dist/components/overlays/Tooltip/Tooltip.js +1 -1
- package/dist/components/overlays/Tooltip/TooltipProvider.js +1 -1
- package/dist/components/overlays/Tooltip/TooltipTrigger.js +1 -1
- package/dist/components/overlays/Tooltip/context.js +1 -1
- package/dist/components/portal/Portal.js +1 -1
- package/dist/components/portal/PortalProvider.js +1 -1
- package/dist/components/portal/usePortal.js +1 -1
- package/dist/components/shared/DraggableCollection.js +1 -1
- package/dist/components/shared/InvalidIcon.js +1 -1
- package/dist/components/shared/ValidIcon.js +1 -1
- package/dist/components/status/LoadingAnimation/LoadingAnimation.js +1 -1
- package/dist/components/status/Spin/Cube.js +1 -1
- package/dist/components/status/Spin/InternalSpinner.js +1 -1
- package/dist/components/status/Spin/Spin.js +1 -1
- package/dist/components/status/Spin/SpinsContainer.js +1 -1
- package/dist/data/item-themes.js +1 -1
- package/dist/data/themes.js +1 -1
- package/dist/i18n/I18nProvider.js +1 -1
- package/dist/i18n/createFormatter.js +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/instance.js +1 -1
- package/dist/i18n/locales/de-DE/uikit.js +1 -1
- package/dist/i18n/locales/en-US/uikit.js +1 -1
- package/dist/i18n/locales/es-ES/uikit.js +1 -1
- package/dist/i18n/locales/es-MX/uikit.js +1 -1
- package/dist/i18n/locales/fr-FR/uikit.js +1 -1
- package/dist/i18n/locales/it-IT/uikit.js +1 -1
- package/dist/i18n/locales/ja-JP/uikit.js +1 -1
- package/dist/i18n/locales/nb-NO/uikit.js +1 -1
- package/dist/i18n/locales/pt-BR/uikit.js +1 -1
- package/dist/i18n/locales/pt-PT/uikit.js +1 -1
- package/dist/i18n/locales/sv-SE/uikit.js +1 -1
- package/dist/i18n/locales/vi-VN/uikit.js +1 -1
- package/dist/i18n/locales.js +1 -1
- package/dist/i18n/useFormatter.js +1 -1
- package/dist/i18n/useI18n.js +1 -1
- package/dist/icons/AdjustmentsHorizontalIcon.js +1 -1
- package/dist/icons/AdjustmentsIcon.js +1 -1
- package/dist/icons/AiIcon.js +1 -1
- package/dist/icons/AreaChartIcon.js +1 -1
- package/dist/icons/BackwardIcon.js +1 -1
- package/dist/icons/BarChartIcon.js +1 -1
- package/dist/icons/BellFilledIcon.js +1 -1
- package/dist/icons/BellIcon.js +1 -1
- package/dist/icons/BooleanIcon.js +1 -1
- package/dist/icons/CalendarEditIcon.js +1 -1
- package/dist/icons/CalendarIcon.js +1 -1
- package/dist/icons/CaretDownIcon.js +1 -1
- package/dist/icons/CaretUpIcon.js +1 -1
- package/dist/icons/ChartAreaStackedIcon.js +1 -1
- package/dist/icons/ChartAreaStackedPercentageIcon.js +1 -1
- package/dist/icons/ChartBarGroupedHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarGroupedIcon.js +1 -1
- package/dist/icons/ChartBarHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarLineIcon.js +1 -1
- package/dist/icons/ChartBarStackedHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarStackedIcon.js +1 -1
- package/dist/icons/ChartBarStackedPercentageHorizontalIcon.js +1 -1
- package/dist/icons/ChartBarStackedPercentageIcon.js +1 -1
- package/dist/icons/ChartBoxPlot2Icon.js +1 -1
- package/dist/icons/ChartBoxPlotIcon.js +1 -1
- package/dist/icons/ChartBubbleIcon.js +1 -1
- package/dist/icons/ChartDonut2Icon.js +1 -1
- package/dist/icons/ChartFunnelIcon.js +1 -1
- package/dist/icons/ChartHeatmapIcon.js +1 -1
- package/dist/icons/ChartKPIIcon.js +1 -1
- package/dist/icons/ChartPie2Icon.js +1 -1
- package/dist/icons/ChartScatterIcon.js +1 -1
- package/dist/icons/CheckCircleFilledIcon.js +1 -1
- package/dist/icons/CheckCircleIcon.js +1 -1
- package/dist/icons/CheckIcon.js +1 -1
- package/dist/icons/CircleFilledIcon.js +1 -1
- package/dist/icons/ClearIcon.js +1 -1
- package/dist/icons/CloseCircleFilledIcon.js +1 -1
- package/dist/icons/CloseCircleIcon.js +1 -1
- package/dist/icons/CloseIcon.js +1 -1
- package/dist/icons/CodeIcon.js +1 -1
- package/dist/icons/ColumnTotalIcon.js +1 -1
- package/dist/icons/CopyIcon.js +1 -1
- package/dist/icons/CountIcon.js +1 -1
- package/dist/icons/CubeIcon.js +1 -1
- package/dist/icons/CubePauseIcon.js +1 -1
- package/dist/icons/CubePlayIcon.js +1 -1
- package/dist/icons/CurrencyDollarIcon.js +1 -1
- package/dist/icons/DangerIcon.js +1 -1
- package/dist/icons/DashboardIcon.js +1 -1
- package/dist/icons/DatabaseIcon.js +1 -1
- package/dist/icons/DecimalDecreaseIcon.js +1 -1
- package/dist/icons/DecimalIncreaseIcon.js +1 -1
- package/dist/icons/DirectionIcon.js +1 -1
- package/dist/icons/DonutIcon.js +1 -1
- package/dist/icons/DownIcon.js +1 -1
- package/dist/icons/EditIcon.js +1 -1
- package/dist/icons/ExclamationCircleFilledIcon.js +1 -1
- package/dist/icons/ExclamationCircleIcon.js +1 -1
- package/dist/icons/ExclamationIcon.js +1 -1
- package/dist/icons/EyeIcon.js +1 -1
- package/dist/icons/EyeInvisibleIcon.js +1 -1
- package/dist/icons/FilterIcon.js +1 -1
- package/dist/icons/FolderFilledIcon.js +1 -1
- package/dist/icons/FolderIcon.js +1 -1
- package/dist/icons/FolderOpenFilledIcon.js +1 -1
- package/dist/icons/FolderOpenIcon.js +1 -1
- package/dist/icons/ForwardIcon.js +1 -1
- package/dist/icons/GripVerticalIcon.js +1 -1
- package/dist/icons/HierarchyIcon.js +1 -1
- package/dist/icons/HierarchyOpenIcon.js +1 -1
- package/dist/icons/Icon.js +1 -1
- package/dist/icons/InfoCircleIcon.js +1 -1
- package/dist/icons/InfoIcon.js +1 -1
- package/dist/icons/KeyIcon.js +1 -1
- package/dist/icons/LeftIcon.js +1 -1
- package/dist/icons/LineChartIcon.js +1 -1
- package/dist/icons/LoadingIcon.js +1 -1
- package/dist/icons/LockFilledIcon.js +1 -1
- package/dist/icons/LockIcon.js +1 -1
- package/dist/icons/MoreIcon.js +1 -1
- package/dist/icons/NotAllowedIcon.js +1 -1
- package/dist/icons/Number123Icon.js +1 -1
- package/dist/icons/NumberIcon.js +1 -1
- package/dist/icons/PauseCircleFilledIcon.js +1 -1
- package/dist/icons/PauseCircleIcon.js +1 -1
- package/dist/icons/PauseIcon.js +1 -1
- package/dist/icons/PercentageIcon.js +1 -1
- package/dist/icons/PieChartIcon.js +1 -1
- package/dist/icons/PlayCircleIcon.js +1 -1
- package/dist/icons/PlayIcon.js +1 -1
- package/dist/icons/PlusIcon.js +1 -1
- package/dist/icons/ProgressBarIcon.js +1 -1
- package/dist/icons/ReloadIcon.js +1 -1
- package/dist/icons/ReportIcon.js +1 -1
- package/dist/icons/ReturnIcon.js +1 -1
- package/dist/icons/RightIcon.js +1 -1
- package/dist/icons/RowTotalsIcon.js +1 -1
- package/dist/icons/SchemeIcon.js +1 -1
- package/dist/icons/SearchIcon.js +1 -1
- package/dist/icons/SemanticQueryIcon.js +1 -1
- package/dist/icons/SettingsIcon.js +1 -1
- package/dist/icons/ShieldFilledIcon.js +1 -1
- package/dist/icons/ShieldIcon.js +1 -1
- package/dist/icons/SlashIcon.js +1 -1
- package/dist/icons/SparklesIcon.js +1 -1
- package/dist/icons/SqlIcon.js +1 -1
- package/dist/icons/StatsIcon.js +1 -1
- package/dist/icons/StopIcon.js +1 -1
- package/dist/icons/StringIcon.js +1 -1
- package/dist/icons/SubtotalsIcon.js +1 -1
- package/dist/icons/SwitchIcon.js +1 -1
- package/dist/icons/TableIcon.js +1 -1
- package/dist/icons/ThumbsDownIcon.js +1 -1
- package/dist/icons/ThumbsUpIcon.js +1 -1
- package/dist/icons/ThunderboltCrossedIcon.js +1 -1
- package/dist/icons/ThunderboltFilledIcon.js +1 -1
- package/dist/icons/ThunderboltIcon.js +1 -1
- package/dist/icons/TimeIcon.js +1 -1
- package/dist/icons/TrashIcon.js +1 -1
- package/dist/icons/UnlockIcon.js +1 -1
- package/dist/icons/UpIcon.js +1 -1
- package/dist/icons/UserGroupIcon.js +1 -1
- package/dist/icons/UserIcon.js +1 -1
- package/dist/icons/UserLockIcon.js +1 -1
- package/dist/icons/ViewIcon.js +1 -1
- package/dist/icons/WarningFilledIcon.js +1 -1
- package/dist/icons/WarningIcon.js +1 -1
- package/dist/icons/wrap-icon.js +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +6 -4
- package/dist/provider.js.map +1 -1
- package/dist/providers/TrackingProvider.js +1 -1
- package/dist/providers/navigationAdapter.default.js +1 -1
- package/dist/shared/form.d.ts +17 -4
- package/dist/shared/index.d.ts +1 -1
- package/dist/tokens/base.js +1 -1
- package/dist/tokens/colors.js +1 -1
- package/dist/tokens/index.js +1 -1
- package/dist/tokens/layout.js +1 -1
- package/dist/tokens/palette.js +1 -1
- package/dist/tokens/palette.js.map +1 -1
- package/dist/tokens/shadows.js +1 -1
- package/dist/tokens/sizes.js +1 -1
- package/dist/tokens/spacing.js +1 -1
- package/dist/tokens/typography.js +1 -1
- package/dist/utils/ResizeSensor.js +1 -1
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/modules.js +1 -1
- package/dist/utils/promise.js +1 -1
- package/dist/utils/raf.js +1 -1
- package/dist/utils/random.js +1 -1
- package/dist/utils/range.js +1 -1
- package/dist/utils/react/RenderCache.js +1 -1
- package/dist/utils/react/Slots.js +1 -1
- package/dist/utils/react/chain.js +1 -1
- package/dist/utils/react/forwardRefWithGenerics.js +1 -1
- package/dist/utils/react/index.js +1 -1
- package/dist/utils/react/interactions.js +1 -1
- package/dist/utils/react/isTextOnly.js +1 -1
- package/dist/utils/react/mapProps.js +1 -1
- package/dist/utils/react/mergeProps.js +1 -1
- package/dist/utils/react/nullableValue.js +1 -1
- package/dist/utils/react/resolveIcon.js +1 -1
- package/dist/utils/react/sharedStore.js +1 -1
- package/dist/utils/react/useCombinedRefs.js +1 -1
- package/dist/utils/react/useControlledFocusVisible.js +1 -1
- package/dist/utils/react/useEventBus.js +1 -1
- package/dist/utils/react/useId.js +1 -1
- package/dist/utils/react/useIsDarwin.js +1 -1
- package/dist/utils/react/useKeySymbols.js +1 -1
- package/dist/utils/react/useLayoutEffect.js +1 -1
- package/dist/utils/react/useLocalStorage.js +1 -1
- package/dist/utils/react/useMergeStyles.js +1 -1
- package/dist/utils/react/usePopoverSync.js +1 -1
- package/dist/utils/react/useQaProps.js +1 -1
- package/dist/utils/react/useViewportSize.js +1 -1
- package/dist/utils/react/wrapNodeIfPlain.js +1 -1
- package/dist/utils/selection.js +1 -1
- package/dist/utils/styles.js +1 -1
- package/dist/utils/tree.js +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/version.js +2 -2
- package/docs/FieldProperties.md +4 -2
- package/docs/Introduction.md +1 -1
- package/docs/components/content/CopySnippet.md +5 -0
- package/docs/components/content/PrismCode.md +2 -2
- package/docs/components/fields/Checkbox.md +1 -1
- package/docs/components/fields/CommandTextArea.md +1 -1
- package/docs/components/fields/DatePicker.md +1 -1
- package/docs/components/fields/FileInput.md +3 -1
- package/docs/components/fields/FilterListBox.md +2 -2
- package/docs/components/fields/ListBox.md +2 -2
- package/docs/components/fields/NumberInput.md +3 -3
- package/docs/components/fields/PasswordInput.md +3 -2
- package/docs/components/fields/Picker.md +5 -5
- package/docs/components/fields/SearchInput.md +5 -4
- package/docs/components/fields/Select.md +3 -3
- package/docs/components/fields/Slider.md +4 -0
- package/docs/components/fields/TextInput.md +3 -3
- package/docs/components/fields/TextInputMapper.md +5 -0
- package/docs/components/form/Field.md +10 -9
- package/docs/components/form/Form.md +3 -1
- package/docs/components/overlays/DialogForm.md +3 -1
- package/package.json +1 -1
- package/dist/components/form/FieldWrapper/extract-field-wrapper-props.d.ts +0 -12
- package/dist/components/form/FieldWrapper/extract-field-wrapper-props.js +0 -41
- package/dist/components/form/FieldWrapper/extract-field-wrapper-props.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps } from "../../../utils/react/mergeProps.js";
|
|
3
3
|
import { wrapNodeIfPlain } from "../../../utils/react/wrapNodeIfPlain.js";
|
|
4
4
|
import { _Text } from "../../content/Text.js";
|
|
@@ -6,6 +6,7 @@ import { Space } from "../../layout/Space.js";
|
|
|
6
6
|
import { _Item } from "../../content/Item/Item.js";
|
|
7
7
|
import { InfoCircleIcon } from "../../../icons/InfoCircleIcon.js";
|
|
8
8
|
import { Flex } from "../../layout/Flex.js";
|
|
9
|
+
import { getValidationMods } from "../validation/resolve-validation-props.js";
|
|
9
10
|
import { _Label } from "../Label.js";
|
|
10
11
|
import { tasty } from "@tenphi/tasty";
|
|
11
12
|
import { forwardRef } from "react";
|
|
@@ -86,7 +87,7 @@ const DescriptionElement = tasty({
|
|
|
86
87
|
* @internal Do not use this component directly.
|
|
87
88
|
*/
|
|
88
89
|
const FieldWrapper = forwardRef(function FieldWrapper(props, ref) {
|
|
89
|
-
const { as, labelPosition = "top", label, extra, styles, isRequired, isDisabled, labelStyles, necessityIndicator, labelProps, fieldProps, message, messageStyles, description, errorMessage, Component,
|
|
90
|
+
const { as, labelPosition = "top", label, extra, styles, isRequired, isDisabled, labelStyles, necessityIndicator, labelProps, fieldProps, message, messageStyles, description, errorMessage, Component, isInvalid, isValid, requiredMark = true, tooltip, isHidden, labelSuffix, children } = props;
|
|
90
91
|
const labelComponent = label ? /* @__PURE__ */ jsx(_Label, {
|
|
91
92
|
as: as === "label" ? "div" : "label",
|
|
92
93
|
styles: labelStyles,
|
|
@@ -94,7 +95,8 @@ const FieldWrapper = forwardRef(function FieldWrapper(props, ref) {
|
|
|
94
95
|
isRequired: requiredMark ? isRequired : false,
|
|
95
96
|
isDisabled,
|
|
96
97
|
necessityIndicator,
|
|
97
|
-
|
|
98
|
+
isInvalid,
|
|
99
|
+
isValid,
|
|
98
100
|
"aria-label": typeof label === "string" ? label : void 0,
|
|
99
101
|
...labelProps,
|
|
100
102
|
children: /* @__PURE__ */ jsxs(Flex, {
|
|
@@ -131,8 +133,10 @@ const FieldWrapper = forwardRef(function FieldWrapper(props, ref) {
|
|
|
131
133
|
"has-sider": labelPosition === "side",
|
|
132
134
|
"has-split": labelPosition === "split",
|
|
133
135
|
"has-description": !!description,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
...getValidationMods({
|
|
137
|
+
isInvalid,
|
|
138
|
+
isValid
|
|
139
|
+
})
|
|
136
140
|
};
|
|
137
141
|
const displayMessage = errorMessage || message;
|
|
138
142
|
const isErrorMessage = !!errorMessage;
|
|
@@ -154,10 +158,10 @@ const FieldWrapper = forwardRef(function FieldWrapper(props, ref) {
|
|
|
154
158
|
displayMessage && !isDisabled && /* @__PURE__ */ jsx(MessageElement, {
|
|
155
159
|
mods: {
|
|
156
160
|
...mods,
|
|
157
|
-
invalid: isErrorMessage ||
|
|
161
|
+
invalid: isErrorMessage || !!isInvalid
|
|
158
162
|
},
|
|
159
163
|
styles: messageStyles,
|
|
160
|
-
role: isErrorMessage ||
|
|
164
|
+
role: isErrorMessage || isInvalid ? "alert" : void 0,
|
|
161
165
|
children: displayMessage
|
|
162
166
|
})
|
|
163
167
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldWrapper.js","names":["Label","Item","Text"],"sources":["../../../../src/components/form/FieldWrapper/FieldWrapper.tsx"],"sourcesContent":["import { tasty } from '@tenphi/tasty';\nimport { forwardRef } from 'react';\n\nimport { InfoCircleIcon } from '../../../icons/index';\nimport { mergeProps, wrapNodeIfPlain } from '../../../utils/react/index';\nimport { Item } from '../../content/Item';\nimport { Text } from '../../content/Text';\nimport { Flex } from '../../layout/Flex';\nimport { Space } from '../../layout/Space';\nimport { Label } from '../Label';\n\nimport { CubeFieldWrapperProps } from './types';\n\nconst FieldElement = tasty({\n qa: 'Field',\n styles: {\n display: 'grid',\n width: 'auto',\n gridColumns: {\n '': 'minmax(0, 1fr)',\n 'has-sider': '($full-label-width, auto) minmax(0, 1fr)',\n 'has-split': 'auto auto',\n },\n gap: 0,\n placeItems: {\n '': 'baseline stretch',\n 'has-split': 'center',\n },\n placeContent: {\n '': 'initial',\n 'has-split': 'space-between',\n },\n '$full-label-width': '($label-width + 1x)',\n\n LabelArea: {\n display: 'block',\n width: {\n '': 'initial',\n 'has-sider': '$label-width',\n },\n margin: {\n '': '1x bottom',\n 'has-sider': '1x right',\n 'has-split': '1x right',\n ':empty': '0',\n },\n },\n\n InputArea: {\n display: 'block',\n flow: 'column',\n gap: '.5x',\n gridColumn: {\n '': 'initial',\n 'has-sider': 2,\n 'has-split': 2,\n },\n },\n },\n});\n\nif (process.env.NODE_ENV === 'development') {\n FieldElement.displayName = 'FieldWrapperElement';\n}\n\nconst MessageElement = tasty({\n qa: 'FieldMessage',\n styles: {\n preset: 't4',\n color: {\n '': '#dark-02',\n invalid: '#danger-text',\n valid: '#success-text',\n disabled: '#dark.40',\n },\n textAlign: 'left',\n userSelect: 'none',\n },\n});\n\nconst DescriptionElement = tasty({\n qa: 'FieldDescription',\n styles: {\n preset: 't4',\n color: '#dark-03',\n textAlign: 'left',\n userSelect: 'none',\n },\n});\n\n/**\n * A wrapper for form fields to provide additional decoration for inputs.\n * @internal Do not use this component directly.\n */\nexport const FieldWrapper = forwardRef(function FieldWrapper(\n props: CubeFieldWrapperProps,\n ref,\n) {\n const {\n as,\n labelPosition = 'top',\n label,\n extra,\n styles,\n isRequired,\n isDisabled,\n labelStyles,\n necessityIndicator,\n labelProps,\n fieldProps,\n message,\n messageStyles,\n description,\n errorMessage,\n Component,\n
|
|
1
|
+
{"version":3,"file":"FieldWrapper.js","names":["Label","Item","Text"],"sources":["../../../../src/components/form/FieldWrapper/FieldWrapper.tsx"],"sourcesContent":["import { tasty } from '@tenphi/tasty';\nimport { forwardRef } from 'react';\n\nimport { InfoCircleIcon } from '../../../icons/index';\nimport { mergeProps, wrapNodeIfPlain } from '../../../utils/react/index';\nimport { Item } from '../../content/Item';\nimport { Text } from '../../content/Text';\nimport { Flex } from '../../layout/Flex';\nimport { Space } from '../../layout/Space';\nimport { Label } from '../Label';\nimport { getValidationMods } from '../validation/index';\n\nimport { CubeFieldWrapperProps } from './types';\n\nconst FieldElement = tasty({\n qa: 'Field',\n styles: {\n display: 'grid',\n width: 'auto',\n gridColumns: {\n '': 'minmax(0, 1fr)',\n 'has-sider': '($full-label-width, auto) minmax(0, 1fr)',\n 'has-split': 'auto auto',\n },\n gap: 0,\n placeItems: {\n '': 'baseline stretch',\n 'has-split': 'center',\n },\n placeContent: {\n '': 'initial',\n 'has-split': 'space-between',\n },\n '$full-label-width': '($label-width + 1x)',\n\n LabelArea: {\n display: 'block',\n width: {\n '': 'initial',\n 'has-sider': '$label-width',\n },\n margin: {\n '': '1x bottom',\n 'has-sider': '1x right',\n 'has-split': '1x right',\n ':empty': '0',\n },\n },\n\n InputArea: {\n display: 'block',\n flow: 'column',\n gap: '.5x',\n gridColumn: {\n '': 'initial',\n 'has-sider': 2,\n 'has-split': 2,\n },\n },\n },\n});\n\nif (process.env.NODE_ENV === 'development') {\n FieldElement.displayName = 'FieldWrapperElement';\n}\n\nconst MessageElement = tasty({\n qa: 'FieldMessage',\n styles: {\n preset: 't4',\n color: {\n '': '#dark-02',\n invalid: '#danger-text',\n valid: '#success-text',\n disabled: '#dark.40',\n },\n textAlign: 'left',\n userSelect: 'none',\n },\n});\n\nconst DescriptionElement = tasty({\n qa: 'FieldDescription',\n styles: {\n preset: 't4',\n color: '#dark-03',\n textAlign: 'left',\n userSelect: 'none',\n },\n});\n\n/**\n * A wrapper for form fields to provide additional decoration for inputs.\n * @internal Do not use this component directly.\n */\nexport const FieldWrapper = forwardRef(function FieldWrapper(\n props: CubeFieldWrapperProps,\n ref,\n) {\n const {\n as,\n labelPosition = 'top',\n label,\n extra,\n styles,\n isRequired,\n isDisabled,\n labelStyles,\n necessityIndicator,\n labelProps,\n fieldProps,\n message,\n messageStyles,\n description,\n errorMessage,\n Component,\n isInvalid,\n isValid,\n requiredMark = true,\n tooltip,\n isHidden,\n labelSuffix,\n children,\n } = props;\n\n const labelComponent = label ? (\n <Label\n as={as === 'label' ? 'div' : 'label'}\n styles={labelStyles}\n labelPosition={labelPosition}\n isRequired={requiredMark ? isRequired : false}\n isDisabled={isDisabled}\n necessityIndicator={necessityIndicator}\n isInvalid={isInvalid}\n isValid={isValid}\n aria-label={typeof label === 'string' ? label : undefined}\n {...labelProps}\n >\n <Flex placeContent=\"baseline space-between\" width=\"100%\">\n <Space placeItems=\"center\" gap=\"0.75x\">\n <div>{label}</div>\n\n {tooltip ? (\n <Item\n icon={<InfoCircleIcon color=\"#primary-text\" />}\n size=\"inline\"\n tooltip={\n typeof tooltip === 'string' ? tooltip : { title: tooltip }\n }\n />\n ) : null}\n\n {labelSuffix ? <div>{labelSuffix}</div> : null}\n </Space>\n\n {extra && <Text preset=\"t3\">{extra}</Text>}\n </Flex>\n </Label>\n ) : null;\n\n // Create description component with proper styling\n const createDescriptionComponent = () => {\n if (!description) return null;\n\n return (\n <DescriptionElement data-element=\"Description\">\n {wrapNodeIfPlain(description, () => (\n <span>{description}</span>\n ))}\n </DescriptionElement>\n );\n };\n\n // Description positioning based on label position\n const descriptionForLabel =\n labelPosition === 'side' || labelPosition === 'split'\n ? createDescriptionComponent()\n : null;\n const descriptionForInput =\n labelPosition === 'top' ? createDescriptionComponent() : null;\n\n const mods = {\n 'has-sider': labelPosition === 'side',\n 'has-split': labelPosition === 'split',\n 'has-description': !!description,\n ...getValidationMods({ isInvalid, isValid }),\n };\n\n // Determine which message to display (errorMessage takes precedence, then message for backward compatibility)\n const displayMessage = errorMessage || message;\n const isErrorMessage = !!errorMessage;\n\n // Merge fieldProps with styles to ensure both are applied\n const mergedFieldProps = styles\n ? mergeProps(fieldProps, { styles })\n : fieldProps;\n\n return (\n <>\n <FieldElement\n ref={ref}\n as={as ?? 'div'}\n mods={mods}\n isHidden={isHidden}\n {...mergedFieldProps}\n >\n {labelComponent || descriptionForLabel ? (\n <div data-element=\"LabelArea\">\n {labelComponent}\n {descriptionForLabel}\n </div>\n ) : null}\n <div data-element=\"InputArea\">\n {Component}\n {descriptionForInput}\n {displayMessage && !isDisabled && (\n <MessageElement\n mods={{\n ...mods,\n // Force invalid state for errorMessage regardless of the validation state\n invalid: isErrorMessage || !!isInvalid,\n }}\n styles={messageStyles}\n role={isErrorMessage || isInvalid ? 'alert' : undefined}\n >\n {displayMessage}\n </MessageElement>\n )}\n </div>\n </FieldElement>\n {children}\n </>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,eAAe,MAAM;CACzB,IAAI;CACJ,QAAQ;EACN,SAAS;EACT,OAAO;EACP,aAAa;GACX,IAAI;GACJ,aAAa;GACb,aAAa;GACd;EACD,KAAK;EACL,YAAY;GACV,IAAI;GACJ,aAAa;GACd;EACD,cAAc;GACZ,IAAI;GACJ,aAAa;GACd;EACD,qBAAqB;EAErB,WAAW;GACT,SAAS;GACT,OAAO;IACL,IAAI;IACJ,aAAa;IACd;GACD,QAAQ;IACN,IAAI;IACJ,aAAa;IACb,aAAa;IACb,UAAU;IACX;GACF;EAED,WAAW;GACT,SAAS;GACT,MAAM;GACN,KAAK;GACL,YAAY;IACV,IAAI;IACJ,aAAa;IACb,aAAa;IACd;GACF;EACF;CACF,CAAC;AAGA,aAAa,cAAc;AAG7B,MAAM,iBAAiB,MAAM;CAC3B,IAAI;CACJ,QAAQ;EACN,QAAQ;EACR,OAAO;GACL,IAAI;GACJ,SAAS;GACT,OAAO;GACP,UAAU;GACX;EACD,WAAW;EACX,YAAY;EACb;CACF,CAAC;AAEF,MAAM,qBAAqB,MAAM;CAC/B,IAAI;CACJ,QAAQ;EACN,QAAQ;EACR,OAAO;EACP,WAAW;EACX,YAAY;EACb;CACF,CAAC;;;;;AAMF,MAAa,eAAe,WAAW,SAAS,aAC9C,OACA,KACA;CACA,MAAM,EACJ,IACA,gBAAgB,OAChB,O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BAAkB,sBACjB,qBAAC;GAAI,gBAAa;cACf,gBACA;IACG,GACJ,MACJ,qBAAC;GAAI,gBAAa;;IACf;IACA;IACA,kBAAkB,CAAC,cAClB,oBAAC;KACC,MAAM;MACJ,GAAG;MAEH,SAAS,kBAAkB,CAAC,CAAC;MAC9B;KACD,QAAQ;KACR,MAAM,kBAAkB,YAAY,UAAU;eAE7C;MACc;;IAEf;GACO,EACd,YACA;EAEL"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import { LabelPosition, NecessityIndicator,
|
|
2
|
+
import { LabelPosition, NecessityIndicator, ValidationProps } from "../../../shared/form.js";
|
|
3
3
|
import "../../../shared/index.js";
|
|
4
4
|
import { CubeLabelProps } from "../Label.js";
|
|
5
5
|
import { Props, Styles } from "@tenphi/tasty";
|
|
6
6
|
import { ReactElement, ReactNode } from "react";
|
|
7
7
|
|
|
8
8
|
//#region src/components/form/FieldWrapper/types.d.ts
|
|
9
|
-
type CubeFieldWrapperProps = {
|
|
9
|
+
type CubeFieldWrapperProps = ValidationProps & {
|
|
10
10
|
as?: keyof HTMLElementTagNameMap;
|
|
11
|
-
validationState?: ValidationState;
|
|
12
11
|
styles?: Styles; /** Whether the input is required */
|
|
13
12
|
isRequired?: boolean; /** Whether the input is disabled */
|
|
14
13
|
isDisabled?: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps } from "../../../utils/react/mergeProps.js";
|
|
3
3
|
import { warn } from "../../../utils/warnings.js";
|
|
4
|
+
import { useValidationProps } from "../validation/use-validation-props.js";
|
|
4
5
|
import { FieldWrapper } from "../FieldWrapper/FieldWrapper.js";
|
|
5
6
|
import { useFormProps } from "./Form.js";
|
|
6
7
|
import { useField } from "./use-field/use-field.js";
|
|
@@ -57,13 +58,13 @@ function getValueProps(type, value, onChange, allowsCustomValue) {
|
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
function Field(props) {
|
|
60
|
-
const allProps = useFormProps(props);
|
|
61
|
+
const allProps = useValidationProps(useFormProps(props));
|
|
61
62
|
let { children, form, label, extra, necessityLabel, necessityIndicator, tooltip, isHidden, isDisabled, isLoading, styles, labelProps, labelPosition = "top", labelStyles, labelSuffix } = allProps;
|
|
62
63
|
if (typeof children === "function") children = children(form);
|
|
63
64
|
let child = children == null ? null : Children.only(children);
|
|
64
65
|
const inputType = (child?.type)?.cubeInputType ?? "Text";
|
|
65
66
|
const __props = useField(allProps, { defaultValidationTrigger: getDefaultValidateTrigger(inputType) });
|
|
66
|
-
const {
|
|
67
|
+
const { isInvalid, isValid, message, description, errorMessage, isRequired, name, id } = __props;
|
|
67
68
|
if (!child) return null;
|
|
68
69
|
if (id) {
|
|
69
70
|
if (!labelProps) labelProps = {};
|
|
@@ -72,7 +73,8 @@ function Field(props) {
|
|
|
72
73
|
if (__props.nonInput) return /* @__PURE__ */ jsx(LegacyFieldProvider, { children: /* @__PURE__ */ jsx(FieldWrapper, {
|
|
73
74
|
isHidden,
|
|
74
75
|
isDisabled,
|
|
75
|
-
|
|
76
|
+
isInvalid,
|
|
77
|
+
isValid,
|
|
76
78
|
necessityIndicator,
|
|
77
79
|
necessityLabel,
|
|
78
80
|
isRequired,
|
|
@@ -106,7 +108,8 @@ function Field(props) {
|
|
|
106
108
|
};
|
|
107
109
|
if (necessityIndicator != null) newProps.necessityIndicator = necessityIndicator;
|
|
108
110
|
if (necessityLabel) newProps.necessityLabel = necessityLabel;
|
|
109
|
-
if (
|
|
111
|
+
if (isInvalid) newProps.isInvalid = isInvalid;
|
|
112
|
+
if (isValid) newProps.isValid = isValid;
|
|
110
113
|
if (isRequired) newProps.isRequired = isRequired;
|
|
111
114
|
if (label) newProps.label = label;
|
|
112
115
|
if (extra) newProps.extra = extra;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","names":[],"sources":["../../../../src/components/form/Form/Field.tsx"],"sourcesContent":["import { Styles } from '@tenphi/tasty';\nimport {\n Children,\n cloneElement,\n createContext,\n PropsWithChildren,\n ReactElement,\n useContext,\n useMemo,\n} from 'react';\n\nimport { FieldBaseProps, LabelPosition } from '../../../shared/index';\nimport { mergeProps } from '../../../utils/react/index';\nimport { warn } from '../../../utils/warnings';\nimport { FieldWrapper } from '../FieldWrapper/index';\n\nimport { useFormProps } from './Form';\nimport { FieldTypes } from './types';\nimport { useField } from './use-field/index';\nimport { CubeFormInstance } from './use-form';\n\nfunction getDefaultValidateTrigger(type) {\n type = type || '';\n\n return type === 'Number' || type.includes('Text') ? 'onBlur' : 'onChange';\n}\n\nfunction getValueProps(\n type?: string,\n value?,\n onChange?,\n allowsCustomValue?: boolean,\n) {\n type = type || '';\n\n if (type === 'Number') {\n return {\n value: value != null ? value : null,\n onChange: onChange,\n };\n } else if (type === 'Text') {\n return {\n value:\n typeof value === 'string' || typeof value === 'number'\n ? String(value)\n : '',\n onChange: onChange,\n };\n } else if (type === 'Checkbox') {\n return {\n isSelected: value != null ? value : false,\n isIndeterminate: false,\n onChange: onChange,\n };\n } else if (type === 'CheckboxGroup') {\n return {\n value: value != null ? value : [],\n onChange: onChange,\n };\n } else if (type === 'RangeSlider') {\n return {\n value: value != null ? value : undefined,\n onChange: onChange,\n };\n } else if (type === 'ComboBox') {\n return {\n selectedKey: !allowsCustomValue ? value ?? null : undefined,\n inputValue: allowsCustomValue ? value ?? '' : undefined,\n onInputChange(val) {\n if (!allowsCustomValue) {\n return;\n }\n\n onChange(val);\n },\n onSelectionChange(val: string) {\n if (val == null && allowsCustomValue) {\n return;\n }\n\n onChange(val);\n },\n };\n } else if (type === 'Select') {\n return {\n selectedKey: value ?? null,\n onSelectionChange: onChange,\n };\n }\n\n return {\n value: value != null ? value : null,\n onChange,\n };\n}\n\nexport interface CubeFieldProps<T extends FieldTypes> extends FieldBaseProps {\n /** The initial value of the input. */\n defaultValue?: any;\n styles?: Styles;\n children?: ReactElement | ((CubeFormInstance) => ReactElement);\n /** The form instance */\n form?: CubeFormInstance<T>;\n}\n\ninterface CubeFullFieldProps<T extends FieldTypes> extends CubeFieldProps<T> {\n form: CubeFormInstance<T>;\n}\n\ninterface CubeReplaceFieldProps<T extends FieldTypes>\n extends CubeFieldProps<T> {\n isRequired?: boolean;\n onChange?: (any) => void;\n onSelectionChange?: (any) => void;\n onBlur: () => void;\n labelPosition?: LabelPosition;\n}\n\nexport function Field<T extends FieldTypes>(props: CubeFieldProps<T>) {\n const allProps: CubeFullFieldProps<T> = useFormProps(props);\n\n let {\n children,\n form,\n label,\n extra,\n necessityLabel,\n necessityIndicator,\n tooltip,\n isHidden,\n isDisabled,\n isLoading,\n styles,\n labelProps,\n labelPosition = 'top',\n labelStyles,\n labelSuffix,\n } = allProps;\n\n if (typeof children === 'function') {\n children = children(form);\n }\n\n let child = children == null ? null : Children.only(children);\n\n const inputType = (child?.type as any)?.cubeInputType ?? 'Text';\n\n const __props = useField<T, CubeFullFieldProps<T>>(allProps, {\n defaultValidationTrigger: getDefaultValidateTrigger(inputType),\n });\n\n const {\n validationState,\n message,\n description,\n errorMessage,\n isRequired,\n name,\n id,\n } = __props;\n\n if (!child) return null;\n\n if (id) {\n if (!labelProps) {\n labelProps = {};\n }\n\n labelProps.for = id;\n }\n\n if (__props.nonInput) {\n return (\n <LegacyFieldProvider>\n <FieldWrapper\n isHidden={isHidden}\n isDisabled={isDisabled}\n validationState={__props.validationState}\n necessityIndicator={necessityIndicator}\n necessityLabel={necessityLabel}\n isRequired={isRequired}\n label={label}\n labelProps={labelProps}\n extra={extra}\n tooltip={tooltip}\n message={message}\n description={description}\n errorMessage={errorMessage}\n Component={child}\n styles={styles}\n labelPosition={labelPosition}\n labelStyles={labelStyles}\n labelSuffix={labelSuffix}\n />\n </LegacyFieldProvider>\n );\n }\n\n if (!form) {\n warn(\n 'Form Field requires declared form instance if field name is specified',\n );\n\n return null;\n }\n\n if (!__props.field) {\n return (\n <LegacyFieldProvider>\n {cloneElement(\n child,\n mergeProps(child.props as any, {\n ...getValueProps(inputType),\n label: name,\n name,\n id,\n }),\n )}\n </LegacyFieldProvider>\n );\n }\n\n const newProps: CubeReplaceFieldProps<T> = {\n id,\n name,\n onBlur: __props.onBlur,\n };\n\n if (necessityIndicator != null) {\n newProps.necessityIndicator = necessityIndicator;\n }\n\n if (necessityLabel) {\n newProps.necessityLabel = necessityLabel;\n }\n\n if (validationState) {\n newProps.validationState = validationState;\n }\n\n if (isRequired) {\n newProps.isRequired = isRequired;\n }\n\n if (label) {\n newProps.label = label;\n }\n\n if (extra) {\n newProps.extra = extra;\n }\n\n if (tooltip) {\n newProps.tooltip = tooltip;\n }\n\n if (message !== undefined) {\n newProps.message = message;\n }\n\n if (errorMessage !== undefined) {\n newProps.errorMessage = errorMessage;\n }\n\n if (description !== undefined) {\n newProps.description = description;\n }\n\n if (isHidden != null) {\n newProps.isHidden = isHidden;\n }\n\n if (isDisabled != null) {\n newProps.isDisabled = isDisabled;\n }\n\n if (isLoading != null) {\n newProps.isLoading = isLoading;\n }\n\n Object.assign(\n newProps,\n getValueProps(\n inputType,\n __props.field?.value,\n __props.onChange,\n (child.props as any).allowsCustomValue,\n ),\n );\n\n const { onChange, onSelectionChange, ...childProps } = child.props as any;\n\n // onChange event passed to the child should be executed after Form onChange logic\n return (\n <LegacyFieldProvider>\n {cloneElement(\n child,\n mergeProps(\n childProps,\n newProps,\n onChange ? { onChange: __props.onChange } : {},\n onSelectionChange ? { onSelectionChange: __props.onChange } : {},\n ),\n )}\n </LegacyFieldProvider>\n );\n}\n\ntype LegacyFieldContextValue = {\n insideLegacyField: boolean;\n};\n\nconst LegacyFieldContext = createContext<LegacyFieldContextValue>({\n insideLegacyField: false,\n});\n\nfunction LegacyFieldProvider(props: PropsWithChildren<unknown>) {\n const value = useMemo(() => ({ insideLegacyField: true }), []);\n return (\n <LegacyFieldContext.Provider value={value}>\n {props.children}\n </LegacyFieldContext.Provider>\n );\n}\n\nexport function useInsideLegacyField() {\n const { insideLegacyField = false } = useContext(LegacyFieldContext);\n\n return insideLegacyField;\n}\n"],"mappings":";;;;;;;;;;AAqBA,SAAS,0BAA0B,MAAM;AACvC,QAAO,QAAQ;AAEf,QAAO,SAAS,YAAY,KAAK,SAAS,OAAO,GAAG,WAAW;;AAGjE,SAAS,cACP,MACA,OACA,UACA,mBACA;AACA,QAAO,QAAQ;AAEf,KAAI,SAAS,SACX,QAAO;EACL,OAAO,SAAS,OAAO,QAAQ;EACrB;EACX;UACQ,SAAS,OAClB,QAAO;EACL,OACE,OAAO,UAAU,YAAY,OAAO,UAAU,WAC1C,OAAO,MAAM,GACb;EACI;EACX;UACQ,SAAS,WAClB,QAAO;EACL,YAAY,SAAS,OAAO,QAAQ;EACpC,iBAAiB;EACP;EACX;UACQ,SAAS,gBAClB,QAAO;EACL,OAAO,SAAS,OAAO,QAAQ,EAAE;EACvB;EACX;UACQ,SAAS,cAClB,QAAO;EACL,OAAO,SAAS,OAAO,QAAQ;EACrB;EACX;UACQ,SAAS,WAClB,QAAO;EACL,aAAa,CAAC,oBAAoB,SAAS,OAAO;EAClD,YAAY,oBAAoB,SAAS,KAAK;EAC9C,cAAc,KAAK;AACjB,OAAI,CAAC,kBACH;AAGF,YAAS,IAAI;;EAEf,kBAAkB,KAAa;AAC7B,OAAI,OAAO,QAAQ,kBACjB;AAGF,YAAS,IAAI;;EAEhB;UACQ,SAAS,SAClB,QAAO;EACL,aAAa,SAAS;EACtB,mBAAmB;EACpB;AAGH,QAAO;EACL,OAAO,SAAS,OAAO,QAAQ;EAC/B;EACD;;AAyBH,SAAgB,MAA4B,OAA0B;CACpE,MAAM,WAAkC,aAAa,MAAM;CAE3D,IAAI,EACF,UACA,MACA,OACA,OACA,gBACA,oBACA,SACA,UACA,YACA,WACA,QACA,YACA,gBAAgB,OAChB,aACA,gBACE;AAEJ,KAAI,OAAO,aAAa,WACtB,YAAW,SAAS,KAAK;CAG3B,IAA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,QAAQ,OAAO,OACf,QAAQ,UACP,MAAM,MAAc,kBACtB,CACF;CAED,MAAM,EAAE,UAAU,mBAAmB,GAAG,eAAe,MAAM;AAG7D,QACE,oBAAC,iCACE,aACC,OACA,WACE,YACA,UACA,WAAW,EAAE,UAAU,QAAQ,UAAU,GAAG,EAAE,EAC9C,oBAAoB,EAAE,mBAAmB,QAAQ,UAAU,GAAG,EAAE,CACjE,CACF,GACmB;;AAQ1B,MAAM,qBAAqB,cAAuC,EAChE,mBAAmB,OACpB,CAAC;AAEF,SAAS,oBAAoB,OAAmC;CAC9D,MAAM,QAAQ,eAAe,EAAE,mBAAmB,MAAM,GAAG,EAAE,CAAC;AAC9D,QACE,oBAAC,mBAAmB;EAAgB;YACjC,MAAM;GACqB;;AAIlC,SAAgB,uBAAuB;CACrC,MAAM,EAAE,oBAAoB,UAAU,WAAW,mBAAmB;AAEpE,QAAO"}
|
|
1
|
+
{"version":3,"file":"Field.js","names":[],"sources":["../../../../src/components/form/Form/Field.tsx"],"sourcesContent":["import { Styles } from '@tenphi/tasty';\nimport {\n Children,\n cloneElement,\n createContext,\n PropsWithChildren,\n ReactElement,\n useContext,\n useMemo,\n} from 'react';\n\nimport { FieldBaseProps, LabelPosition } from '../../../shared/index';\nimport { mergeProps } from '../../../utils/react/index';\nimport { warn } from '../../../utils/warnings';\nimport { FieldWrapper } from '../FieldWrapper/index';\nimport { useValidationProps } from '../validation/index';\n\nimport { useFormProps } from './Form';\nimport { FieldTypes } from './types';\nimport { useField } from './use-field/index';\nimport { CubeFormInstance } from './use-form';\n\nfunction getDefaultValidateTrigger(type) {\n type = type || '';\n\n return type === 'Number' || type.includes('Text') ? 'onBlur' : 'onChange';\n}\n\nfunction getValueProps(\n type?: string,\n value?,\n onChange?,\n allowsCustomValue?: boolean,\n) {\n type = type || '';\n\n if (type === 'Number') {\n return {\n value: value != null ? value : null,\n onChange: onChange,\n };\n } else if (type === 'Text') {\n return {\n value:\n typeof value === 'string' || typeof value === 'number'\n ? String(value)\n : '',\n onChange: onChange,\n };\n } else if (type === 'Checkbox') {\n return {\n isSelected: value != null ? value : false,\n isIndeterminate: false,\n onChange: onChange,\n };\n } else if (type === 'CheckboxGroup') {\n return {\n value: value != null ? value : [],\n onChange: onChange,\n };\n } else if (type === 'RangeSlider') {\n return {\n value: value != null ? value : undefined,\n onChange: onChange,\n };\n } else if (type === 'ComboBox') {\n return {\n selectedKey: !allowsCustomValue ? value ?? null : undefined,\n inputValue: allowsCustomValue ? value ?? '' : undefined,\n onInputChange(val) {\n if (!allowsCustomValue) {\n return;\n }\n\n onChange(val);\n },\n onSelectionChange(val: string) {\n if (val == null && allowsCustomValue) {\n return;\n }\n\n onChange(val);\n },\n };\n } else if (type === 'Select') {\n return {\n selectedKey: value ?? null,\n onSelectionChange: onChange,\n };\n }\n\n return {\n value: value != null ? value : null,\n onChange,\n };\n}\n\nexport interface CubeFieldProps<T extends FieldTypes> extends FieldBaseProps {\n /** The initial value of the input. */\n defaultValue?: any;\n styles?: Styles;\n children?: ReactElement | ((CubeFormInstance) => ReactElement);\n /** The form instance */\n form?: CubeFormInstance<T>;\n}\n\ninterface CubeFullFieldProps<T extends FieldTypes> extends CubeFieldProps<T> {\n form: CubeFormInstance<T>;\n}\n\ninterface CubeReplaceFieldProps<T extends FieldTypes>\n extends CubeFieldProps<T> {\n isRequired?: boolean;\n onChange?: (any) => void;\n onSelectionChange?: (any) => void;\n onBlur: () => void;\n labelPosition?: LabelPosition;\n}\n\nexport function Field<T extends FieldTypes>(props: CubeFieldProps<T>) {\n const allProps: CubeFullFieldProps<T> = useValidationProps(\n useFormProps(props),\n );\n\n let {\n children,\n form,\n label,\n extra,\n necessityLabel,\n necessityIndicator,\n tooltip,\n isHidden,\n isDisabled,\n isLoading,\n styles,\n labelProps,\n labelPosition = 'top',\n labelStyles,\n labelSuffix,\n } = allProps;\n\n if (typeof children === 'function') {\n children = children(form);\n }\n\n let child = children == null ? null : Children.only(children);\n\n const inputType = (child?.type as any)?.cubeInputType ?? 'Text';\n\n const __props = useField<T, CubeFullFieldProps<T>>(allProps, {\n defaultValidationTrigger: getDefaultValidateTrigger(inputType),\n });\n\n const {\n isInvalid,\n isValid,\n message,\n description,\n errorMessage,\n isRequired,\n name,\n id,\n } = __props;\n\n if (!child) return null;\n\n if (id) {\n if (!labelProps) {\n labelProps = {};\n }\n\n labelProps.for = id;\n }\n\n if (__props.nonInput) {\n return (\n <LegacyFieldProvider>\n <FieldWrapper\n isHidden={isHidden}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isValid={isValid}\n necessityIndicator={necessityIndicator}\n necessityLabel={necessityLabel}\n isRequired={isRequired}\n label={label}\n labelProps={labelProps}\n extra={extra}\n tooltip={tooltip}\n message={message}\n description={description}\n errorMessage={errorMessage}\n Component={child}\n styles={styles}\n labelPosition={labelPosition}\n labelStyles={labelStyles}\n labelSuffix={labelSuffix}\n />\n </LegacyFieldProvider>\n );\n }\n\n if (!form) {\n warn(\n 'Form Field requires declared form instance if field name is specified',\n );\n\n return null;\n }\n\n if (!__props.field) {\n return (\n <LegacyFieldProvider>\n {cloneElement(\n child,\n mergeProps(child.props as any, {\n ...getValueProps(inputType),\n label: name,\n name,\n id,\n }),\n )}\n </LegacyFieldProvider>\n );\n }\n\n const newProps: CubeReplaceFieldProps<T> = {\n id,\n name,\n onBlur: __props.onBlur,\n };\n\n if (necessityIndicator != null) {\n newProps.necessityIndicator = necessityIndicator;\n }\n\n if (necessityLabel) {\n newProps.necessityLabel = necessityLabel;\n }\n\n if (isInvalid) {\n newProps.isInvalid = isInvalid;\n }\n\n if (isValid) {\n newProps.isValid = isValid;\n }\n\n if (isRequired) {\n newProps.isRequired = isRequired;\n }\n\n if (label) {\n newProps.label = label;\n }\n\n if (extra) {\n newProps.extra = extra;\n }\n\n if (tooltip) {\n newProps.tooltip = tooltip;\n }\n\n if (message !== undefined) {\n newProps.message = message;\n }\n\n if (errorMessage !== undefined) {\n newProps.errorMessage = errorMessage;\n }\n\n if (description !== undefined) {\n newProps.description = description;\n }\n\n if (isHidden != null) {\n newProps.isHidden = isHidden;\n }\n\n if (isDisabled != null) {\n newProps.isDisabled = isDisabled;\n }\n\n if (isLoading != null) {\n newProps.isLoading = isLoading;\n }\n\n Object.assign(\n newProps,\n getValueProps(\n inputType,\n __props.field?.value,\n __props.onChange,\n (child.props as any).allowsCustomValue,\n ),\n );\n\n const { onChange, onSelectionChange, ...childProps } = child.props as any;\n\n // onChange event passed to the child should be executed after Form onChange logic\n return (\n <LegacyFieldProvider>\n {cloneElement(\n child,\n mergeProps(\n childProps,\n newProps,\n onChange ? { onChange: __props.onChange } : {},\n onSelectionChange ? { onSelectionChange: __props.onChange } : {},\n ),\n )}\n </LegacyFieldProvider>\n );\n}\n\ntype LegacyFieldContextValue = {\n insideLegacyField: boolean;\n};\n\nconst LegacyFieldContext = createContext<LegacyFieldContextValue>({\n insideLegacyField: false,\n});\n\nfunction LegacyFieldProvider(props: PropsWithChildren<unknown>) {\n const value = useMemo(() => ({ insideLegacyField: true }), []);\n return (\n <LegacyFieldContext.Provider value={value}>\n {props.children}\n </LegacyFieldContext.Provider>\n );\n}\n\nexport function useInsideLegacyField() {\n const { insideLegacyField = false } = useContext(LegacyFieldContext);\n\n return insideLegacyField;\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,0BAA0B,MAAM;AACvC,QAAO,QAAQ;AAEf,QAAO,SAAS,YAAY,KAAK,SAAS,OAAO,GAAG,WAAW;;AAGjE,SAAS,cACP,MACA,OACA,UACA,mBACA;AACA,QAAO,QAAQ;AAEf,KAAI,SAAS,SACX,QAAO;EACL,OAAO,SAAS,OAAO,QAAQ;EACrB;EACX;UACQ,SAAS,OAClB,QAAO;EACL,OACE,OAAO,UAAU,YAAY,OAAO,UAAU,WAC1C,OAAO,MAAM,GACb;EACI;EACX;UACQ,SAAS,WAClB,QAAO;EACL,YAAY,SAAS,OAAO,QAAQ;EACpC,iBAAiB;EACP;EACX;UACQ,SAAS,gBAClB,QAAO;EAC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BAAoB,UAAU,WAAW,mBAAmB;AAEpE,QAAO"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../../utils/styles.js";
|
|
3
3
|
import { useCombinedRefs } from "../../../utils/react/useCombinedRefs.js";
|
|
4
4
|
import { Provider, useProviderProps } from "../../../provider.js";
|
|
5
|
+
import { useValidationProps } from "../validation/use-validation-props.js";
|
|
5
6
|
import { timeout } from "../../../utils/promise.js";
|
|
6
7
|
import { useForm } from "./use-form.js";
|
|
7
8
|
import { CONTAINER_STYLES, filterBaseProps, tasty } from "@tenphi/tasty";
|
|
@@ -45,8 +46,8 @@ const formPropNames = new Set([
|
|
|
45
46
|
"target"
|
|
46
47
|
]);
|
|
47
48
|
function Form(props, ref) {
|
|
48
|
-
props = useProviderProps(props);
|
|
49
|
-
let { qa, name, children, labelPosition, orientation, necessityIndicator, isDisabled, isReadOnly,
|
|
49
|
+
props = useValidationProps(useProviderProps(props));
|
|
50
|
+
let { qa, name, children, labelPosition, orientation, necessityIndicator, isDisabled, isReadOnly, isInvalid, isValid, labelStyles, validateTrigger, showValid, defaultValues, onValuesChange, requiredMark = true, form, labelWidth, onSubmit, onSubmitFailed, ...otherProps } = props;
|
|
50
51
|
const defaultValuesRef = useRef(defaultValues);
|
|
51
52
|
const firstRunRef = useRef(true);
|
|
52
53
|
const isHorizontal = orientation === "horizontal";
|
|
@@ -133,7 +134,8 @@ function Form(props, ref) {
|
|
|
133
134
|
insideForm: true,
|
|
134
135
|
isDisabled,
|
|
135
136
|
isReadOnly,
|
|
136
|
-
|
|
137
|
+
isInvalid,
|
|
138
|
+
isValid,
|
|
137
139
|
children
|
|
138
140
|
})
|
|
139
141
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.js","names":[],"sources":["../../../../src/components/form/Form/Form.tsx"],"sourcesContent":["import { useObjectRef } from '@react-aria/utils';\nimport {\n BaseProps,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n tasty,\n} from '@tenphi/tasty';\nimport {\n createContext,\n FormHTMLAttributes,\n forwardRef,\n ReactElement,\n ReactNode,\n Ref,\n useContext,\n useRef,\n} from 'react';\n\nimport { Provider, useProviderProps } from '../../../provider';\nimport { FormBaseProps } from '../../../shared/index';\nimport { timeout } from '../../../utils/promise';\nimport { useCombinedRefs } from '../../../utils/react/index';\nimport { extractStyles } from '../../../utils/styles';\n\nimport { FieldTypes } from './types';\nimport { CubeFormData, CubeFormInstance, useForm } from './use-form';\n\nexport const FormContext = createContext({});\n\nconst FormElement = tasty({\n as: 'form',\n qa: 'Form',\n styles: {\n display: {\n '': 'block',\n horizontal: 'flex',\n },\n flow: {\n '': 'column',\n horizontal: 'row',\n },\n placeItems: {\n '': 'initial',\n horizontal: 'center',\n },\n gap: '2x',\n '$label-width': '25x',\n },\n});\n\nexport function useFormProps(props) {\n const ctx = useContext(FormContext);\n\n return { ...ctx, ...props };\n}\n\nconst formPropNames = new Set([\n 'action',\n 'autoComplete',\n 'encType',\n 'method',\n 'target',\n]);\n\nexport interface CubeFormProps<T extends FieldTypes = FieldTypes>\n extends FormBaseProps,\n BaseProps,\n ContainerStyleProps,\n Pick<\n FormHTMLAttributes<HTMLFormElement>,\n 'action' | 'autoComplete' | 'encType' | 'method' | 'target'\n > {\n /** Form name */\n name?: string;\n /** Default field values */\n defaultValues?: Partial<T>;\n /** Trigger when any value of the Field is changed */\n onValuesChange?: CubeFormInstance<T>['onValuesChange'];\n /** Trigger on form submit and success */\n onSubmit?: CubeFormInstance<T>['onSubmit'];\n /** Trigger on form submit and failed */\n onSubmitFailed?: (any?) => void | Promise<any>;\n /** Set form instance created by useForm */\n form?: CubeFormInstance<T, CubeFormData<T>>;\n /** The size of the side area with labels. Only for `labelPosition=\"side\"` */\n labelWidth?: Styles['width'];\n orientation?: 'vertical' | 'horizontal';\n}\n\nfunction Form<T extends FieldTypes>(\n props: CubeFormProps<T>,\n ref: Ref<HTMLFormElement>,\n) {\n props = useProviderProps(props);\n let {\n qa,\n name,\n children,\n labelPosition,\n orientation,\n necessityIndicator,\n isDisabled,\n isReadOnly,\n
|
|
1
|
+
{"version":3,"file":"Form.js","names":[],"sources":["../../../../src/components/form/Form/Form.tsx"],"sourcesContent":["import { useObjectRef } from '@react-aria/utils';\nimport {\n BaseProps,\n CONTAINER_STYLES,\n ContainerStyleProps,\n filterBaseProps,\n Styles,\n tasty,\n} from '@tenphi/tasty';\nimport {\n createContext,\n FormHTMLAttributes,\n forwardRef,\n ReactElement,\n ReactNode,\n Ref,\n useContext,\n useRef,\n} from 'react';\n\nimport { Provider, useProviderProps } from '../../../provider';\nimport { FormBaseProps } from '../../../shared/index';\nimport { timeout } from '../../../utils/promise';\nimport { useCombinedRefs } from '../../../utils/react/index';\nimport { extractStyles } from '../../../utils/styles';\nimport { useValidationProps } from '../validation/index';\n\nimport { FieldTypes } from './types';\nimport { CubeFormData, CubeFormInstance, useForm } from './use-form';\n\nexport const FormContext = createContext({});\n\nconst FormElement = tasty({\n as: 'form',\n qa: 'Form',\n styles: {\n display: {\n '': 'block',\n horizontal: 'flex',\n },\n flow: {\n '': 'column',\n horizontal: 'row',\n },\n placeItems: {\n '': 'initial',\n horizontal: 'center',\n },\n gap: '2x',\n '$label-width': '25x',\n },\n});\n\nexport function useFormProps(props) {\n const ctx = useContext(FormContext);\n\n return { ...ctx, ...props };\n}\n\nconst formPropNames = new Set([\n 'action',\n 'autoComplete',\n 'encType',\n 'method',\n 'target',\n]);\n\nexport interface CubeFormProps<T extends FieldTypes = FieldTypes>\n extends FormBaseProps,\n BaseProps,\n ContainerStyleProps,\n Pick<\n FormHTMLAttributes<HTMLFormElement>,\n 'action' | 'autoComplete' | 'encType' | 'method' | 'target'\n > {\n /** Form name */\n name?: string;\n /** Default field values */\n defaultValues?: Partial<T>;\n /** Trigger when any value of the Field is changed */\n onValuesChange?: CubeFormInstance<T>['onValuesChange'];\n /** Trigger on form submit and success */\n onSubmit?: CubeFormInstance<T>['onSubmit'];\n /** Trigger on form submit and failed */\n onSubmitFailed?: (any?) => void | Promise<any>;\n /** Set form instance created by useForm */\n form?: CubeFormInstance<T, CubeFormData<T>>;\n /** The size of the side area with labels. Only for `labelPosition=\"side\"` */\n labelWidth?: Styles['width'];\n orientation?: 'vertical' | 'horizontal';\n}\n\nfunction Form<T extends FieldTypes>(\n props: CubeFormProps<T>,\n ref: Ref<HTMLFormElement>,\n) {\n props = useValidationProps(useProviderProps(props));\n let {\n qa,\n name,\n children,\n labelPosition,\n orientation,\n necessityIndicator,\n isDisabled,\n isReadOnly,\n isInvalid,\n isValid,\n labelStyles,\n validateTrigger,\n showValid,\n defaultValues,\n onValuesChange,\n requiredMark = true,\n form,\n labelWidth,\n onSubmit,\n onSubmitFailed,\n ...otherProps\n } = props;\n const defaultValuesRef = useRef(defaultValues);\n const firstRunRef = useRef(true);\n const isHorizontal = orientation === 'horizontal';\n\n if (!orientation) {\n orientation = 'vertical';\n }\n\n if (!labelPosition) {\n labelPosition = isHorizontal ? 'side' : 'top';\n }\n\n if (!labelWidth) {\n labelWidth = isHorizontal ? 'auto' : undefined;\n }\n\n ref = useCombinedRefs(ref);\n\n let onSubmitCallback;\n\n if ((onSubmit || onSubmitFailed) && !otherProps.action) {\n onSubmitCallback = async (e) => {\n if (e && e?.preventDefault) {\n e && e?.preventDefault && e?.preventDefault();\n e && e?.stopPropagation && e?.stopPropagation();\n\n if (e.nativeEvent) {\n const evt = e.nativeEvent;\n\n if (\n evt.submitter &&\n evt.submitter.getAttribute('type') !== 'submit'\n ) {\n return;\n }\n }\n }\n\n if (!form || form.isSubmitting) return;\n\n form.submitError = null;\n form.setSubmitting(true);\n\n try {\n try {\n await form.validateFields();\n } catch (e) {\n form?.setSubmitting(false);\n\n return;\n }\n\n await timeout();\n await onSubmit?.(form.getFormData());\n } catch (e) {\n await timeout();\n\n // errors are shown\n form.submitError = e as ReactNode;\n // transfer errors to the callback\n onSubmitFailed?.(e);\n\n if (e instanceof Error) {\n throw e;\n }\n } finally {\n form?.setSubmitting(false);\n }\n\n // output data from form directly\n // onSubmit(Object.fromEntries(new FormData(e.target).entries()));\n };\n }\n\n [form] = useForm<T>(form, ref && ref.current, {\n onSubmit: onSubmitCallback,\n onValuesChange,\n });\n\n let styles = extractStyles(otherProps, CONTAINER_STYLES);\n\n if (labelWidth) {\n styles['$label-width'] = labelWidth;\n }\n\n let domRef = useObjectRef(ref);\n\n let ctx = {\n labelPosition,\n labelStyles,\n orientation,\n necessityIndicator,\n validateTrigger,\n requiredMark,\n showValid,\n form,\n submitError: form.submitError,\n idPrefix: name,\n };\n\n if (firstRunRef.current && form) {\n if (defaultValues) {\n form.setInitialFieldsValue(defaultValues);\n form.resetFields(undefined, true);\n firstRunRef.current = false;\n }\n }\n\n if (defaultValuesRef.current !== defaultValues) {\n form?.setInitialFieldsValue(defaultValues ?? {});\n defaultValuesRef.current = defaultValues;\n }\n\n return (\n <FormElement\n {...filterBaseProps(otherProps, { propNames: formPropNames })}\n ref={domRef}\n noValidate\n qa={qa}\n styles={styles}\n mods={{\n 'has-sider': labelPosition === 'side',\n 'has-split': labelPosition === 'split',\n horizontal: isHorizontal,\n }}\n onSubmit={onSubmitCallback}\n >\n <FormContext.Provider value={ctx}>\n <Provider\n insideForm={true}\n isDisabled={isDisabled}\n isReadOnly={isReadOnly}\n isInvalid={isInvalid}\n isValid={isValid}\n >\n {children}\n </Provider>\n </FormContext.Provider>\n </FormElement>\n );\n}\n\n/**\n * Forms allow users to enter data that can be submitted while providing alignment and styling for form fields.\n */\nconst _Form = forwardRef(Form) as unknown as <T extends FieldTypes>(\n props: CubeFormProps<T> & { ref?: Ref<HTMLFormElement> },\n) => ReactElement;\n\n(_Form as any).displayName = 'Form';\n\nexport { _Form as Form };\n"],"mappings":";;;;;;;;;;;;;AA8BA,MAAa,cAAc,cAAc,EAAE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ACF,UAAM,KAAK,gBAAgB;YACpB,GAAG;AACV,UAAM,cAAc,MAAM;AAE1B;;AAGF,SAAM,SAAS;AACf,SAAM,WAAW,KAAK,aAAa,CAAC;WAC7B,GAAG;AACV,SAAM,SAAS;AAGf,QAAK,cAAc;AAEnB,oBAAiB,EAAE;AAEnB,OAAI,aAAa,MACf,OAAM;YAEA;AACR,SAAM,cAAc,MAAM;;;AAQhC,EAAC,QAAQ,QAAW,MAAM,OAAO,IAAI,SAAS;EAC5C,UAAU;EACV;EACD,CAAC;CAEF,IAAI,SAAS,cAAc,YAAY,iBAAiB;AAExD,KAAI,WACF,QAAO,kBAAkB;CAG3B,IAAI,SAAS,aAAa,IAAI;CAE9B,IAAI,MAAM;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,KAAK;EAClB,UAAU;EACX;AAED,KAAI,YAAY,WAAW,MACzB;MAAI,eAAe;AACjB,QAAK,sBAAsB,cAAc;AACzC,QAAK,YAAY,QAAW,KAAK;AACjC,eAAY,UAAU;;;AAI1B,KAAI,iBAAiB,YAAY,eAAe;AAC9C,QAAM,sBAAsB,iBAAiB,EAAE,CAAC;AAChD,mBAAiB,UAAU;;AAG7B,QACE,oBAAC;EACC,GAAI,gBAAgB,YAAY,EAAE,WAAW,eAAe,CAAC;EAC7D,KAAK;EACL;EACI;EACI;EACR,MAAM;GACJ,aAAa,kBAAkB;GAC/B,aAAa,kBAAkB;GAC/B,YAAY;GACb;EACD,UAAU;YAEV,oBAAC,YAAY;GAAS,OAAO;aAC3B,oBAAC;IACC,YAAY;IACA;IACA;IACD;IACF;IAER;KACQ;IACU;GACX;;;;;AAOlB,MAAM,QAAQ,WAAW,KAAK;AAI9B,AAAC,MAAc,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps } from "../../../../utils/react/mergeProps.js";
|
|
3
3
|
import { useEvent } from "../../../../_internal/hooks/use-event.js";
|
|
4
4
|
import { useProviderProps } from "../../../../provider.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { useProviderProps } from "../../../../provider.js";
|
|
3
3
|
import { Button } from "../../../actions/Button/Button.js";
|
|
4
4
|
import { useFormProps } from "../Form.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { useI18n } from "../../../i18n/useI18n.js";
|
|
3
3
|
import { FormContext } from "./Form.js";
|
|
4
4
|
import { Alert } from "../../content/Alert/Alert.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { useForm } from "./use-form.js";
|
|
3
3
|
import { FormContext, _Form, useFormProps } from "./Form.js";
|
|
4
4
|
import { useField } from "./use-field/use-field.js";
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
|
|
2
|
-
import { FieldCoreProps, ValidateTrigger, ValidationState } from "../../../../shared/form.js";
|
|
2
|
+
import { FieldCoreProps, ValidateTrigger, ValidationProps, ValidationState } from "../../../../shared/form.js";
|
|
3
3
|
import "../../../../shared/index.js";
|
|
4
4
|
import { CubeFieldData, FieldTypes } from "../types.js";
|
|
5
5
|
import { CubeFormInstance } from "../use-form.js";
|
|
6
6
|
import { ReactNode } from "react";
|
|
7
7
|
|
|
8
8
|
//#region src/components/form/Form/use-field/types.d.ts
|
|
9
|
-
interface UseFieldProps<T extends FieldTypes> extends FieldCoreProps {
|
|
9
|
+
interface UseFieldProps<T extends FieldTypes> extends FieldCoreProps, ValidationProps {
|
|
10
10
|
/** The initial value of the input. */
|
|
11
11
|
defaultValue?: any;
|
|
12
12
|
/** The form instance */
|
|
13
13
|
form?: CubeFormInstance<T>;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The validation state of the field
|
|
16
|
+
* @deprecated Use `isInvalid` / `isValid` instead.
|
|
17
|
+
*/
|
|
15
18
|
validationState?: ValidationState;
|
|
16
19
|
/** Whether to show valid state */
|
|
17
20
|
showValid?: boolean;
|
|
18
21
|
/** On which event perform the validation for the field */
|
|
19
22
|
validateTrigger?: ValidateTrigger;
|
|
20
23
|
}
|
|
21
|
-
type FieldReturnValue<T extends FieldTypes> = {
|
|
24
|
+
type FieldReturnValue<T extends FieldTypes> = ValidationProps & {
|
|
22
25
|
id: string;
|
|
23
26
|
name: string;
|
|
24
27
|
value: any;
|
|
25
28
|
validateTrigger?: ValidateTrigger;
|
|
26
|
-
validationState?: ValidationState;
|
|
27
29
|
form?: CubeFormInstance<T>;
|
|
28
30
|
onChange?: (value: any, dontTouch: boolean, validateTrigger: ValidateTrigger) => void;
|
|
29
31
|
/**
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { mergeProps } from "../../../../utils/react/mergeProps.js";
|
|
3
3
|
import { useEvent } from "../../../../_internal/hooks/use-event.js";
|
|
4
4
|
import { warn } from "../../../../utils/warnings.js";
|
|
5
5
|
import { useChainedCallback } from "../../../../_internal/hooks/use-chained-callback.js";
|
|
6
|
+
import { useProviderProps } from "../../../../provider.js";
|
|
7
|
+
import { useValidationProps } from "../../validation/use-validation-props.js";
|
|
8
|
+
import { useFormProps } from "../Form.js";
|
|
6
9
|
import { useField } from "./use-field.js";
|
|
7
10
|
import { useInsideLegacyField } from "../Field.js";
|
|
8
11
|
import { useDebugValue, useId, useRef } from "react";
|
|
9
12
|
|
|
10
13
|
//#region src/components/form/Form/use-field/use-field-props.tsx
|
|
11
14
|
function useFieldProps(props, params = {}) {
|
|
15
|
+
props = useProviderProps(props);
|
|
16
|
+
props = useFormProps(props);
|
|
17
|
+
props = useValidationProps(props);
|
|
12
18
|
const isDisabledRef = useRef(params.unsafe__isDisabled ?? false);
|
|
13
19
|
const { valuePropsMapper = ({ value, onChange }) => {
|
|
14
20
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-field-props.js","names":[],"sources":["../../../../../src/components/form/Form/use-field/use-field-props.tsx"],"sourcesContent":["import { useDebugValue, useId, useRef } from 'react';\n\nimport { useChainedCallback, useEvent } from '../../../../_internal/index';\nimport { mergeProps } from '../../../../utils/react/index';\nimport { warn } from '../../../../utils/warnings';\nimport { useInsideLegacyField } from '../Field';\n\nimport { useField } from './use-field';\n\nimport type { ValidateTrigger } from '../../../../shared/index';\nimport type { FieldTypes } from '../types';\nimport type { UseFieldProps } from './types';\n\nexport type UseFieldPropsParams = {\n valuePropsMapper?: ({ value, onChange }) => any;\n /**\n * @default 'onBlur'\n */\n defaultValidationTrigger?: ValidateTrigger;\n /**\n * prop helps to prevent calling hook conditionally, but changing this prop during render is unsafe and forbidden\n * If you want to change this prop after mount, remount the component with a new value.\n */\n unsafe__isDisabled?: boolean;\n};\n\nexport function useFieldProps<\n T extends FieldTypes,\n Props extends UseFieldProps<T>,\n>(props: Props, params: UseFieldPropsParams = {}): Props {\n // We use ref here to \"memoize\" initial value\n const isDisabledRef = useRef(params.unsafe__isDisabled ?? false);\n\n const {\n valuePropsMapper = ({ value, onChange }) => {\n return {\n value: value ?? null,\n onChange,\n };\n },\n defaultValidationTrigger = 'onBlur',\n } = params;\n\n const isInsideLegacyField = useInsideLegacyField();\n\n // useWarn(isInsideLegacyField, {\n // key: 'use-field-props',\n // args: ['<Field /> is deprecated, use component without <Field /> instead.'],\n // });\n\n if (props.rules && !props.name) {\n warn(\n `The \"rules\" prop is not suitable for fields that are not part of a form. Use \"name\" prop to link the field to a form.`,\n );\n }\n\n if (isInsideLegacyField || isDisabledRef.current === true) {\n return props;\n }\n\n // For standalone fields (no name), just generate an ID without calling useField\n const hasName = props.name != null;\n const generatedId = useId();\n\n if (!hasName) {\n // Standalone field - just add generated ID if not provided\n if (!props.id) {\n const result = { ...props, id: generatedId };\n\n if (result.id && !result.labelProps) {\n result.labelProps = { for: result.id };\n } else if (result.id && result.labelProps && !result.labelProps.for) {\n result.labelProps = { ...result.labelProps, for: result.id };\n }\n\n return result as Props;\n }\n return props;\n }\n\n // Form-connected field - use full useField logic\n const field = useField<T, Props>(props, {\n defaultValidationTrigger: params.defaultValidationTrigger,\n });\n\n const isOutsideOfForm = field?.form == null;\n\n if (props.rules && isOutsideOfForm) {\n warn(\n `The \"rules\" prop is not supported for fields that are not part of a form. The \"${props.name}\" field is placed outside the form.`,\n );\n }\n\n const onBlurChained = useChainedCallback(\n field?.onBlur,\n 'onBlur' in props ? (props as any).onBlur : undefined,\n );\n\n const onChangeEvent = useEvent((value, dontTouch: boolean) => {\n field?.onChange?.(\n value,\n dontTouch,\n field?.validateTrigger ?? defaultValidationTrigger,\n );\n });\n\n const valueProps = !isOutsideOfForm\n ? valuePropsMapper({\n value: field.value,\n onChange: onChangeEvent,\n })\n : {};\n\n if (isInsideLegacyField && !isOutsideOfForm) {\n const valuePropEventNames = !isOutsideOfForm\n ? Object.keys(valueProps).filter((name) => name.startsWith('on'))\n : [];\n\n for (const valuePropName of valuePropEventNames) {\n if (valuePropName in props) {\n warn(\n `The \"${valuePropName}\" listener is not supported for input \"${props.name}\" that is linked to a form via a <Field> component. Remove the <Field> component and move its properties to the input itself.`,\n );\n }\n }\n }\n\n // Use errorMessage directly or fall back to validation errors\n const compiledErrorMessage =\n props.errorMessage !== undefined\n ? props.errorMessage\n : field?.field?.status === 'invalid' && field?.field?.errors?.length\n ? field.field.errors[0]\n : undefined;\n\n // Exclude 'form' from field to prevent it from being spread to DOM elements\n const { form: _form, ...fieldWithoutForm } = field ?? {};\n\n const result: Props = isOutsideOfForm\n ? props\n : mergeProps(props, fieldWithoutForm, valueProps, {\n validateTrigger: field.validateTrigger ?? defaultValidationTrigger,\n onBlur: onBlurChained,\n errorMessage: compiledErrorMessage,\n });\n\n if (result.id) {\n if (!result.labelProps) {\n result.labelProps = {};\n }\n\n result.labelProps.for = result.id;\n }\n\n if (process.env.NODE_ENV === 'development') {\n useDebugValue(result);\n }\n\n return result;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-field-props.js","names":[],"sources":["../../../../../src/components/form/Form/use-field/use-field-props.tsx"],"sourcesContent":["import { useDebugValue, useId, useRef } from 'react';\n\nimport { useChainedCallback, useEvent } from '../../../../_internal/index';\nimport { useProviderProps } from '../../../../provider';\nimport { mergeProps } from '../../../../utils/react/index';\nimport { warn } from '../../../../utils/warnings';\nimport { useValidationProps } from '../../validation/index';\nimport { useInsideLegacyField } from '../Field';\nimport { useFormProps } from '../Form';\n\nimport { useField } from './use-field';\n\nimport type { ValidateTrigger } from '../../../../shared/index';\nimport type { FieldTypes } from '../types';\nimport type { UseFieldProps } from './types';\n\nexport type UseFieldPropsParams = {\n valuePropsMapper?: ({ value, onChange }) => any;\n /**\n * @default 'onBlur'\n */\n defaultValidationTrigger?: ValidateTrigger;\n /**\n * prop helps to prevent calling hook conditionally, but changing this prop during render is unsafe and forbidden\n * If you want to change this prop after mount, remount the component with a new value.\n */\n unsafe__isDisabled?: boolean;\n};\n\nexport function useFieldProps<\n T extends FieldTypes,\n Props extends UseFieldProps<T>,\n>(props: Props, params: UseFieldPropsParams = {}): Props {\n // The single entry point for input components: provider defaults, then form context, then the\n // normalization of the deprecated `validationState` prop into `isInvalid`/`isValid`.\n props = useProviderProps(props);\n props = useFormProps(props);\n props = useValidationProps(props);\n\n // We use ref here to \"memoize\" initial value\n const isDisabledRef = useRef(params.unsafe__isDisabled ?? false);\n\n const {\n valuePropsMapper = ({ value, onChange }) => {\n return {\n value: value ?? null,\n onChange,\n };\n },\n defaultValidationTrigger = 'onBlur',\n } = params;\n\n const isInsideLegacyField = useInsideLegacyField();\n\n // useWarn(isInsideLegacyField, {\n // key: 'use-field-props',\n // args: ['<Field /> is deprecated, use component without <Field /> instead.'],\n // });\n\n if (props.rules && !props.name) {\n warn(\n `The \"rules\" prop is not suitable for fields that are not part of a form. Use \"name\" prop to link the field to a form.`,\n );\n }\n\n if (isInsideLegacyField || isDisabledRef.current === true) {\n return props;\n }\n\n // For standalone fields (no name), just generate an ID without calling useField\n const hasName = props.name != null;\n const generatedId = useId();\n\n if (!hasName) {\n // Standalone field - just add generated ID if not provided\n if (!props.id) {\n const result = { ...props, id: generatedId };\n\n if (result.id && !result.labelProps) {\n result.labelProps = { for: result.id };\n } else if (result.id && result.labelProps && !result.labelProps.for) {\n result.labelProps = { ...result.labelProps, for: result.id };\n }\n\n return result as Props;\n }\n return props;\n }\n\n // Form-connected field - use full useField logic\n const field = useField<T, Props>(props, {\n defaultValidationTrigger: params.defaultValidationTrigger,\n });\n\n const isOutsideOfForm = field?.form == null;\n\n if (props.rules && isOutsideOfForm) {\n warn(\n `The \"rules\" prop is not supported for fields that are not part of a form. The \"${props.name}\" field is placed outside the form.`,\n );\n }\n\n const onBlurChained = useChainedCallback(\n field?.onBlur,\n 'onBlur' in props ? (props as any).onBlur : undefined,\n );\n\n const onChangeEvent = useEvent((value, dontTouch: boolean) => {\n field?.onChange?.(\n value,\n dontTouch,\n field?.validateTrigger ?? defaultValidationTrigger,\n );\n });\n\n const valueProps = !isOutsideOfForm\n ? valuePropsMapper({\n value: field.value,\n onChange: onChangeEvent,\n })\n : {};\n\n if (isInsideLegacyField && !isOutsideOfForm) {\n const valuePropEventNames = !isOutsideOfForm\n ? Object.keys(valueProps).filter((name) => name.startsWith('on'))\n : [];\n\n for (const valuePropName of valuePropEventNames) {\n if (valuePropName in props) {\n warn(\n `The \"${valuePropName}\" listener is not supported for input \"${props.name}\" that is linked to a form via a <Field> component. Remove the <Field> component and move its properties to the input itself.`,\n );\n }\n }\n }\n\n // Use errorMessage directly or fall back to validation errors\n const compiledErrorMessage =\n props.errorMessage !== undefined\n ? props.errorMessage\n : field?.field?.status === 'invalid' && field?.field?.errors?.length\n ? field.field.errors[0]\n : undefined;\n\n // Exclude 'form' from field to prevent it from being spread to DOM elements\n const { form: _form, ...fieldWithoutForm } = field ?? {};\n\n const result: Props = isOutsideOfForm\n ? props\n : mergeProps(props, fieldWithoutForm, valueProps, {\n validateTrigger: field.validateTrigger ?? defaultValidationTrigger,\n onBlur: onBlurChained,\n errorMessage: compiledErrorMessage,\n });\n\n if (result.id) {\n if (!result.labelProps) {\n result.labelProps = {};\n }\n\n result.labelProps.for = result.id;\n }\n\n if (process.env.NODE_ENV === 'development') {\n useDebugValue(result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,SAAgB,cAGd,OAAc,SAA8B,EAAE,EAAS;AAGvD,SAAQ,iBAAiB,MAAM;AAC/B,SAAQ,aAAa,MAAM;AAC3B,SAAQ,mBAAmB,MAAM;CAGjC,MAAM,gBAAgB,OAAO,OAAO,sBAAsB,MAAM;CAEhE,MAAM,EACJ,oBAAoB,EAAE,OAAO,eAAe;AAC1C,SAAO;GACL,OAAO,SAAS;GAChB;GACD;IAEH,2BAA2B,aACzB;CAEJ,MAAM,sBAAsB,sBAAsB;AAOlD,KAAI,MAAM,SAAS,CAAC,MAAM,KACxB,MACE,wHACD;AAGH,KAAI,uBAAuB,cAAc,YAAY,KACnD,QAAO;CAIT,MAAM,UAAU,MAAM,QAAQ;CAC9B,MAAM,cAAc,OAAO;AAE3B,KAAI,CAAC,SAAS;AAEZ,MAAI,CAAC,MAAM,IAAI;GACb,MAAM,SAAS;IAAE,GAAG;IAAO,IAAI;IAAa;AAE5C,OAAI,OAAO,MAAM,CAAC,OAAO,WACvB,QAAO,aAAa,EAAE,KAAK,OAAO,IAAI;YAC7B,OAAO,MAAM,OAAO,cAAc,CA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 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { useEvent } from "../../../../_internal/hooks/use-event.js";
|
|
3
3
|
import { useIsFirstRender } from "../../../../_internal/hooks/use-is-first-render.js";
|
|
4
|
+
import { resolveValidationProps } from "../../validation/resolve-validation-props.js";
|
|
4
5
|
import { delayValidationRule } from "../validation.js";
|
|
5
6
|
import { useFormProps } from "../Form.js";
|
|
6
7
|
import { useEffect, useMemo, useState } from "react";
|
|
@@ -25,7 +26,8 @@ function removeId(name, id) {
|
|
|
25
26
|
}
|
|
26
27
|
function useField(props, params) {
|
|
27
28
|
props = useFormProps(props);
|
|
28
|
-
let { defaultValue, id, idPrefix, name, form, rules, message, description, errorMessage, validateTrigger = params.defaultValidationTrigger,
|
|
29
|
+
let { defaultValue, id, idPrefix, name, form, rules, message, description, errorMessage, validateTrigger = params.defaultValidationTrigger, validationDelay, showValid, shouldUpdate, isRequired: isRequiredProp } = props;
|
|
30
|
+
const { isInvalid: isInvalidProp, isValid: isValidProp } = resolveValidationProps(props);
|
|
29
31
|
const processedRules = useMemo(() => {
|
|
30
32
|
let finalRules = rules;
|
|
31
33
|
if (isRequiredProp) {
|
|
@@ -99,10 +101,9 @@ function useField(props, params) {
|
|
|
99
101
|
form,
|
|
100
102
|
field,
|
|
101
103
|
nonInput,
|
|
102
|
-
|
|
104
|
+
isInvalid: isInvalidProp ?? !!field?.errors?.length,
|
|
105
|
+
isValid: isValidProp ?? !!(showValid && field?.status === "valid"),
|
|
103
106
|
...isRequired && { isRequired },
|
|
104
|
-
isInvalid: field?.status === "invalid",
|
|
105
|
-
isValid: field?.status === "valid",
|
|
106
107
|
message: message !== void 0 ? message : field?.status === "invalid" && field?.errors?.[0],
|
|
107
108
|
description,
|
|
108
109
|
errorMessage: errorMessage !== void 0 ? errorMessage : field?.status === "invalid" && field?.errors?.length ? field.errors[0] : void 0,
|
|
@@ -123,7 +124,8 @@ function useField(props, params) {
|
|
|
123
124
|
onBlurHandler,
|
|
124
125
|
onChangeHandler,
|
|
125
126
|
validateTrigger,
|
|
126
|
-
|
|
127
|
+
isInvalidProp,
|
|
128
|
+
isValidProp,
|
|
127
129
|
showValid,
|
|
128
130
|
nonInput
|
|
129
131
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-field.js","names":[],"sources":["../../../../../src/components/form/Form/use-field/use-field.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\n\nimport { useEvent, useIsFirstRender } from '../../../../_internal/index';\nimport { ValidateTrigger } from '../../../../shared/index';\nimport { useFormProps } from '../Form';\nimport { FieldTypes } from '../types';\nimport { delayValidationRule } from '../validation';\n\nimport { FieldReturnValue, UseFieldProps } from './types';\n\nconst ID_MAP = {};\n\nfunction createId(name) {\n if (!name) return;\n\n if (!ID_MAP[name]) {\n ID_MAP[name] = [];\n }\n\n let i = 0;\n let id;\n\n do {\n id = i ? `${name}_${i}` : name;\n i++;\n } while (ID_MAP[name].includes(id));\n\n ID_MAP[name].push(id);\n\n return id;\n}\n\nfunction removeId(name, id) {\n if (!ID_MAP[name]) return;\n\n ID_MAP[name] = ID_MAP[name].filter((_id) => _id !== id);\n}\n\nexport type UseFieldParams = {\n defaultValidationTrigger?: ValidateTrigger;\n};\n\nexport function useField<T extends FieldTypes, Props extends UseFieldProps<T>>(\n props: Props,\n params: UseFieldParams,\n): FieldReturnValue<T> {\n props = useFormProps(props);\n\n let {\n defaultValue,\n id,\n idPrefix,\n name,\n form,\n rules,\n message,\n description,\n errorMessage,\n validateTrigger = params.defaultValidationTrigger,\n
|
|
1
|
+
{"version":3,"file":"use-field.js","names":[],"sources":["../../../../../src/components/form/Form/use-field/use-field.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\n\nimport { useEvent, useIsFirstRender } from '../../../../_internal/index';\nimport { ValidateTrigger } from '../../../../shared/index';\nimport { resolveValidationProps } from '../../validation/index';\nimport { useFormProps } from '../Form';\nimport { FieldTypes } from '../types';\nimport { delayValidationRule } from '../validation';\n\nimport { FieldReturnValue, UseFieldProps } from './types';\n\nconst ID_MAP = {};\n\nfunction createId(name) {\n if (!name) return;\n\n if (!ID_MAP[name]) {\n ID_MAP[name] = [];\n }\n\n let i = 0;\n let id;\n\n do {\n id = i ? `${name}_${i}` : name;\n i++;\n } while (ID_MAP[name].includes(id));\n\n ID_MAP[name].push(id);\n\n return id;\n}\n\nfunction removeId(name, id) {\n if (!ID_MAP[name]) return;\n\n ID_MAP[name] = ID_MAP[name].filter((_id) => _id !== id);\n}\n\nexport type UseFieldParams = {\n defaultValidationTrigger?: ValidateTrigger;\n};\n\nexport function useField<T extends FieldTypes, Props extends UseFieldProps<T>>(\n props: Props,\n params: UseFieldParams,\n): FieldReturnValue<T> {\n props = useFormProps(props);\n\n let {\n defaultValue,\n id,\n idPrefix,\n name,\n form,\n rules,\n message,\n description,\n errorMessage,\n validateTrigger = params.defaultValidationTrigger,\n validationDelay,\n showValid,\n shouldUpdate,\n isRequired: isRequiredProp,\n } = props;\n\n const { isInvalid: isInvalidProp, isValid: isValidProp } =\n resolveValidationProps(props);\n\n const processedRules = useMemo(() => {\n let finalRules = rules;\n\n // If isRequired prop is set, ensure there's a required rule\n if (isRequiredProp) {\n const hasRequiredRule = finalRules?.some(\n (rule) => 'required' in rule && rule.required === true,\n );\n\n if (!hasRequiredRule) {\n finalRules = finalRules\n ? [{ required: true }, ...finalRules]\n : [{ required: true }];\n }\n }\n\n // Add delay rule if needed\n if (finalRules && finalRules.length && validationDelay) {\n return [delayValidationRule(validationDelay), ...finalRules];\n }\n\n return finalRules;\n }, [rules, validationDelay, isRequiredProp]);\n\n const nonInput = !name;\n const fieldName: string = name != null ? name : '';\n\n const isFirstRender = useIsFirstRender();\n let [fieldId, setFieldId] = useState(\n id || (idPrefix ? `${idPrefix}_${fieldName}` : fieldName),\n );\n\n useEffect(() => {\n let newId;\n\n if (!id && !nonInput) {\n newId = createId(fieldId);\n\n setFieldId(newId);\n }\n\n return () => {\n if (!id) {\n removeId(idPrefix ? `${idPrefix}_${fieldName}` : fieldName, newId);\n }\n\n if (fieldName && form) {\n form.removeField(fieldName);\n }\n };\n }, [fieldName]);\n\n let field = form?.getFieldInstance(fieldName);\n\n if (field) {\n field.rules = processedRules;\n }\n\n let isRequired = !!processedRules?.find(\n (rule) => 'required' in rule && rule.required === true,\n );\n\n useEffect(() => {\n if (!form) return;\n\n if (field) {\n form.forceReRender();\n } else {\n field = form.createField(fieldName);\n }\n }, [field]);\n\n if (form) {\n if (isFirstRender) {\n if (!field) {\n field = form.createField(fieldName, true);\n }\n\n if (field?.value == null && defaultValue != null) {\n form.setFieldValue(fieldName, defaultValue, false, true);\n form.updateInitialFieldsValue({ [fieldName]: defaultValue });\n\n field = form?.getFieldInstance(fieldName);\n }\n }\n\n if (!field?.touched && defaultValue != null) {\n form.setFieldValue(fieldName, defaultValue, false, true);\n }\n }\n\n const onChangeHandler = useEvent((val: any, dontTouch: boolean) => {\n if (!form) return;\n\n const field = form.getFieldInstance(fieldName);\n\n if (shouldUpdate) {\n const fieldsValue = form.getFieldsValue();\n\n // check if we should update the value of the field\n const shouldNotBeUpdated =\n typeof shouldUpdate === 'boolean'\n ? !shouldUpdate\n : !shouldUpdate(fieldsValue, {\n ...fieldsValue,\n [fieldName]: val,\n });\n\n if (shouldNotBeUpdated) {\n return;\n }\n }\n\n form.setFieldValue(fieldName, val, !dontTouch);\n\n if (\n !dontTouch &&\n (validateTrigger === 'onChange' ||\n (field && field.errors && field.errors.length))\n ) {\n form.validateField(fieldName).catch(() => {}); // do nothing on fail\n }\n });\n\n const onBlurHandler = useEvent(() => {\n if (validateTrigger === 'onBlur') {\n // We need a timeout so the change event can be done.\n setTimeout(() => {\n form?.validateField(fieldName).catch(() => {}); // do nothing on fail\n });\n }\n });\n\n let value = field?.value;\n\n return useMemo(\n () => ({\n id: fieldId,\n name: fieldName,\n value,\n validateTrigger,\n form,\n field,\n nonInput,\n\n // Explicit validation props always win over the state derived from the form\n isInvalid: isInvalidProp ?? !!field?.errors?.length,\n isValid: isValidProp ?? !!(showValid && field?.status === 'valid'),\n ...(isRequired && { isRequired }),\n message:\n message !== undefined\n ? message\n : field?.status === 'invalid' && field?.errors?.[0],\n description,\n errorMessage:\n errorMessage !== undefined\n ? errorMessage\n : field?.status === 'invalid' && field?.errors?.length\n ? field.errors[0]\n : undefined,\n onBlur: onBlurHandler,\n onChange: onChangeHandler,\n }),\n [\n form,\n field,\n field?.value,\n field?.errors?.length,\n field?.status,\n fieldId,\n fieldName,\n isRequired,\n message,\n description,\n errorMessage,\n onBlurHandler,\n onChangeHandler,\n validateTrigger,\n isInvalidProp,\n isValidProp,\n showValid,\n nonInput,\n ],\n );\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAAS,EAAE;AAEjB,SAAS,SAAS,MAAM;AACtB,KAAI,CAAC,KAAM;AAEX,KAAI,CAAC,OAAO,MACV,QAAO,QAAQ,EAAE;CAGnB,IAAI,IAAI;CACR,IAAI;AAEJ,IAAG;AACD,OAAK,IAAI,GAAG,KAAK,GAAG,MAAM;AAC1B;UACO,OAAO,MAAM,SAAS,GAAG;AAElC,QAAO,MAAM,KAAK,GAAG;AAErB,QAAO;;AAGT,SAAS,SAAS,MAAM,IAAI;AAC1B,KAAI,CAAC,OAAO,MAAO;AAEnB,QAAO,QAAQ,OAAO,MAAM,QAAQ,QAAQ,QAAQ,GAAG;;AAOzD,SAAgB,SACd,OACA,QACqB;AACrB,SAAQ,aAAa,MAAM;CAE3B,IAAI,EACF,cACA,IACA,UACA,MACA,MACA,OACA,SACA,aACA,cACA,kBAAkB,OAAO,0BACzB,iBACA,WACA,cACA,YAAY,mBACV;CAEJ,MAAM,EAAE,WAAW,eAAe,SAAS,gBACzC,uBAAuB,MAAM;CAE/B,MAAM,iBAAiB,cAAc;EACnC,IAAI,aAAa;AAGjB,MAAI,gBAKF;OAAI,CAJoB,YAA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
2
|
+
import { LabelPosition, NecessityIndicator, ValidationProps } from "../../shared/form.js";
|
|
3
3
|
import "../../shared/index.js";
|
|
4
4
|
import { BaseProps, ContainerStyleProps, Styles } from "@tenphi/tasty";
|
|
5
5
|
import * as react from "react";
|
|
@@ -7,14 +7,13 @@ import * as react from "react";
|
|
|
7
7
|
//#region src/components/form/Label.d.ts
|
|
8
8
|
declare const INLINE_LABEL_STYLES: Styles;
|
|
9
9
|
declare const LABEL_STYLES: Styles;
|
|
10
|
-
interface CubeLabelProps extends BaseProps, ContainerStyleProps {
|
|
10
|
+
interface CubeLabelProps extends BaseProps, ContainerStyleProps, ValidationProps {
|
|
11
11
|
labelPosition?: LabelPosition;
|
|
12
12
|
necessityIndicator?: NecessityIndicator;
|
|
13
13
|
isRequired?: boolean;
|
|
14
14
|
includeNecessityIndicatorInAccessibilityName?: boolean;
|
|
15
15
|
htmlFor?: string;
|
|
16
16
|
for?: string;
|
|
17
|
-
validationState?: ValidationState;
|
|
18
17
|
size?: 'medium' | 'small';
|
|
19
18
|
}
|
|
20
19
|
declare let _Label: react.ForwardRefExoticComponent<CubeLabelProps & react.RefAttributes<unknown>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/** @license MIT | @cube-dev/ui-kit v0.
|
|
1
|
+
/** @license MIT | @cube-dev/ui-kit v0.148.0 | Cube Dev Team */
|
|
2
2
|
import { extractStyles } from "../../utils/styles.js";
|
|
3
3
|
import { useProviderProps } from "../../provider.js";
|
|
4
4
|
import { useI18n } from "../../i18n/useI18n.js";
|
|
5
|
+
import { getValidationMods } from "./validation/resolve-validation-props.js";
|
|
5
6
|
import { CONTAINER_STYLES, filterBaseProps, tasty } from "@tenphi/tasty";
|
|
6
7
|
import { forwardRef } from "react";
|
|
7
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -56,7 +57,7 @@ const LabelElement = tasty({
|
|
|
56
57
|
function Label(props, ref) {
|
|
57
58
|
props = useProviderProps(props);
|
|
58
59
|
const { t } = useI18n();
|
|
59
|
-
let { as, qa, children, labelPosition = "top", isRequired, necessityIndicator = isRequired != null ? "icon" : null, includeNecessityIndicatorInAccessibilityName = false, htmlFor, isDisabled,
|
|
60
|
+
let { as, qa, children, labelPosition = "top", isRequired, necessityIndicator = isRequired != null ? "icon" : null, includeNecessityIndicatorInAccessibilityName = false, htmlFor, isDisabled, isInvalid, isValid, size = "medium", for: labelFor, ...otherProps } = props;
|
|
60
61
|
let domRef = useObjectRef(ref);
|
|
61
62
|
const styles = extractStyles(otherProps, CONTAINER_STYLES);
|
|
62
63
|
let requiredLabel = t("form.required", "(required)");
|
|
@@ -74,8 +75,10 @@ function Label(props, ref) {
|
|
|
74
75
|
mods: {
|
|
75
76
|
side: labelPosition === "side",
|
|
76
77
|
disabled: isDisabled,
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
...getValidationMods({
|
|
79
|
+
isInvalid,
|
|
80
|
+
isValid
|
|
81
|
+
})
|
|
79
82
|
},
|
|
80
83
|
children: typeof children !== "string" ? children : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
81
84
|
children,
|