@middag-io/react 0.45.0 → 0.45.2
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/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- package/src/theme.css +71 -0
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FormField -- router component that renders the correct input based on field type.
|
|
3
|
+
*
|
|
4
|
+
* Receives a field descriptor and delegates to the matching field component.
|
|
5
|
+
* Wraps each field in a consistent layout: label, help text, input, error message.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { lazy, Suspense, useId, type ReactElement, type ReactNode } from "react";
|
|
9
|
+
import type { TFunction } from "i18next";
|
|
10
|
+
|
|
11
|
+
import { CheckboxField } from "@/base/form/fields/CheckboxField";
|
|
12
|
+
import { ColorField } from "@/base/form/fields/ColorField";
|
|
13
|
+
import { CurrencyField } from "@/base/form/fields/CurrencyField";
|
|
14
|
+
// DateField, DocumentField, PhoneField are lazy-loaded — see below
|
|
15
|
+
import { EntityPickerField } from "@/base/form/fields/EntityPickerField";
|
|
16
|
+
import { FileUploadField } from "@/base/form/fields/FileUploadField";
|
|
17
|
+
import { MultiSelectField } from "@/base/form/fields/MultiSelectField";
|
|
18
|
+
import { NativeSelectField } from "@/base/form/fields/NativeSelectField";
|
|
19
|
+
import { NumberFieldComponent } from "@/base/form/fields/NumberField";
|
|
20
|
+
import { OtpField } from "@/base/form/fields/OtpField";
|
|
21
|
+
import { PasswordField } from "@/base/form/fields/PasswordField";
|
|
22
|
+
import { RadioField } from "@/base/form/fields/RadioField";
|
|
23
|
+
import { RatingField } from "@/base/form/fields/RatingField";
|
|
24
|
+
import { SelectField } from "@/base/form/fields/SelectField";
|
|
25
|
+
import { SliderField } from "@/base/form/fields/SliderField";
|
|
26
|
+
import { SlugField } from "@/base/form/fields/SlugField";
|
|
27
|
+
import { StaticField } from "@/base/form/fields/StaticField";
|
|
28
|
+
import { SwitchField } from "@/base/form/fields/SwitchField";
|
|
29
|
+
import { TagsField } from "@/base/form/fields/TagsField";
|
|
30
|
+
import { TextareaField } from "@/base/form/fields/TextareaField";
|
|
31
|
+
import { TextField } from "@/base/form/fields/TextField";
|
|
32
|
+
import { isFieldDisabled, isFieldRequired } from "@/base/form/form-utils";
|
|
33
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
34
|
+
import { fieldTestId } from "@/lib/test-ids";
|
|
35
|
+
import { Label } from "@/primitives/reui/label";
|
|
36
|
+
import { Skeleton } from "@/primitives/reui/skeleton";
|
|
37
|
+
|
|
38
|
+
import { resolveFieldComponent } from "./fields/field-registry";
|
|
39
|
+
|
|
40
|
+
/** Lazy-loaded PhoneField — libphonenumber-js (~40KB) loads only when a phone field renders. */
|
|
41
|
+
const LazyPhoneField = lazy(() =>
|
|
42
|
+
import("@/base/form/fields/PhoneField").then((m) => ({ default: m.PhoneField })),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** Lazy-loaded DateField — date-fns + react-day-picker (~115KB) load only when a date field renders. */
|
|
46
|
+
const LazyDateField = lazy(() =>
|
|
47
|
+
import("@/base/form/fields/DateField").then((m) => ({ default: m.DateField })),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** Lazy-loaded DocumentField — validator.js (~28KB) loads only when a document field renders. */
|
|
51
|
+
const LazyDocumentField = lazy(() =>
|
|
52
|
+
import("@/base/form/fields/DocumentField").then((m) => ({ default: m.DocumentField })),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** Lazy-loaded DateRangeField — date-fns + ReUI DateSelector loads only when a date_range field renders. */
|
|
56
|
+
const LazyDateRangeField = lazy(() =>
|
|
57
|
+
import("@/base/form/fields/DateRangeField").then((m) => ({ default: m.DateRangeField })),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function InputSkeleton() {
|
|
61
|
+
return <Skeleton className="h-9 w-full rounded-md" />;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FieldOption {
|
|
65
|
+
value: string;
|
|
66
|
+
label: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* FieldDescriptor — type alias for the discriminated union FormFieldNode
|
|
71
|
+
* used by FormField component. Narrow by `component` for type-specific props.
|
|
72
|
+
*/
|
|
73
|
+
export type FieldDescriptor = import("@/contracts/block-data").FormFieldNode;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Flattened props union for internal use in renderField().
|
|
77
|
+
* This is the union of ALL possible props across all field variants —
|
|
78
|
+
* used only in the field switch where props are accessed after manual narrowing.
|
|
79
|
+
* Consumer code should use the discriminated union for type-safe narrowing.
|
|
80
|
+
*/
|
|
81
|
+
type AnyFieldProps = import("@/contracts/block-data").FieldPropsBase &
|
|
82
|
+
Partial<{
|
|
83
|
+
options: Array<{ value: string; label: string }>;
|
|
84
|
+
min: number;
|
|
85
|
+
max: number;
|
|
86
|
+
step: number;
|
|
87
|
+
rows: number;
|
|
88
|
+
accept: string;
|
|
89
|
+
multiple: boolean;
|
|
90
|
+
maxFiles: number;
|
|
91
|
+
maxSize: number;
|
|
92
|
+
documentType: string;
|
|
93
|
+
documentScope: "person" | "company" | "any";
|
|
94
|
+
documentMasks: Record<string, { pattern: string; maxLength: number; placeholder?: string }>;
|
|
95
|
+
defaultCountry: string;
|
|
96
|
+
fixedCountry: boolean;
|
|
97
|
+
currency: string;
|
|
98
|
+
currencyLocale: string;
|
|
99
|
+
autocompleteHref: string;
|
|
100
|
+
autocompleteMinChars: number;
|
|
101
|
+
initialOption: { value: string; label: string; subtitle?: string; avatarUrl?: string };
|
|
102
|
+
entityDisplayField: string;
|
|
103
|
+
entitySubtitleField: string;
|
|
104
|
+
entityAvatarField: string;
|
|
105
|
+
sourceField: string;
|
|
106
|
+
prefix: string;
|
|
107
|
+
maxTags: number;
|
|
108
|
+
maxRating: number;
|
|
109
|
+
operator: string;
|
|
110
|
+
maxLength: number;
|
|
111
|
+
pattern: "digits" | "alphanumeric";
|
|
112
|
+
groupSize: number;
|
|
113
|
+
}>;
|
|
114
|
+
|
|
115
|
+
export interface FormFieldProps {
|
|
116
|
+
field: FieldDescriptor;
|
|
117
|
+
value: unknown;
|
|
118
|
+
onChange: (value: unknown) => void;
|
|
119
|
+
error?: string;
|
|
120
|
+
sourceValues?: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Renders a header separator (non-interactive, no label wrapper).
|
|
125
|
+
*/
|
|
126
|
+
function HeaderField({ label }: { label: string }): ReactElement {
|
|
127
|
+
return (
|
|
128
|
+
<div className="pt-4 pb-1">
|
|
129
|
+
<h4 className="text-foreground text-sm font-semibold">{label}</h4>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Renders the input element for the hidden type.
|
|
136
|
+
*/
|
|
137
|
+
function HiddenField({ id, value }: { id: string; value: unknown }): ReactElement {
|
|
138
|
+
return <input type="hidden" id={id} value={String(value ?? "")} />;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function FormField({
|
|
142
|
+
field,
|
|
143
|
+
value,
|
|
144
|
+
onChange,
|
|
145
|
+
error,
|
|
146
|
+
sourceValues = {},
|
|
147
|
+
}: FormFieldProps): ReactElement {
|
|
148
|
+
const { t } = useTranslation();
|
|
149
|
+
const generatedId = useId();
|
|
150
|
+
const fieldId = `field-${field.key}-${generatedId}`;
|
|
151
|
+
const helpTextId = `${fieldId}-help`;
|
|
152
|
+
const errorId = `${fieldId}-error`;
|
|
153
|
+
|
|
154
|
+
const { component, props } = field;
|
|
155
|
+
|
|
156
|
+
// Header -- renders just a heading, no label/help/error wrapper.
|
|
157
|
+
if (component === "header") {
|
|
158
|
+
return <HeaderField label={props.label} />;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Hidden -- renders a hidden input, no visible wrapper.
|
|
162
|
+
if (component === "hidden") {
|
|
163
|
+
return <HiddenField id={fieldId} value={value} />;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Resolve conditional state against the current sibling field values.
|
|
167
|
+
// `sourceValues` carries the full form value map, so disabled_when /
|
|
168
|
+
// required_when can be evaluated here.
|
|
169
|
+
const effectiveDisabled = isFieldDisabled(field, sourceValues);
|
|
170
|
+
const effectiveRequired = isFieldRequired(field, sourceValues);
|
|
171
|
+
|
|
172
|
+
// For checkbox and switch, the label is rendered inline by the field itself.
|
|
173
|
+
const isInlineLabel = component === "checkbox" || component === "switch";
|
|
174
|
+
|
|
175
|
+
const fieldContent = renderField(
|
|
176
|
+
component,
|
|
177
|
+
fieldId,
|
|
178
|
+
value,
|
|
179
|
+
onChange,
|
|
180
|
+
props as AnyFieldProps,
|
|
181
|
+
error,
|
|
182
|
+
helpTextId,
|
|
183
|
+
errorId,
|
|
184
|
+
t,
|
|
185
|
+
sourceValues,
|
|
186
|
+
effectiveDisabled,
|
|
187
|
+
effectiveRequired,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div className="space-y-1.5" data-testid={fieldTestId(field.key)}>
|
|
192
|
+
{/* Label */}
|
|
193
|
+
{!isInlineLabel && (
|
|
194
|
+
<Label htmlFor={fieldId}>
|
|
195
|
+
{props.label}
|
|
196
|
+
{effectiveRequired && <span className="text-destructive ml-0.5">*</span>}
|
|
197
|
+
</Label>
|
|
198
|
+
)}
|
|
199
|
+
|
|
200
|
+
{/* Help text */}
|
|
201
|
+
{props.helpText && (
|
|
202
|
+
<p id={helpTextId} className="text-muted-foreground text-xs">
|
|
203
|
+
{props.helpText}
|
|
204
|
+
</p>
|
|
205
|
+
)}
|
|
206
|
+
|
|
207
|
+
{/* Field component */}
|
|
208
|
+
{fieldContent}
|
|
209
|
+
|
|
210
|
+
{/* Error message */}
|
|
211
|
+
{error && (
|
|
212
|
+
<p id={errorId} className="text-destructive text-xs" aria-live="polite">
|
|
213
|
+
{error}
|
|
214
|
+
</p>
|
|
215
|
+
)}
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Switches on component type and renders the correct field component.
|
|
222
|
+
*/
|
|
223
|
+
function renderField(
|
|
224
|
+
component: string,
|
|
225
|
+
id: string,
|
|
226
|
+
value: unknown,
|
|
227
|
+
onChange: (value: unknown) => void,
|
|
228
|
+
props: AnyFieldProps,
|
|
229
|
+
error: string | undefined,
|
|
230
|
+
helpTextId: string,
|
|
231
|
+
errorId: string,
|
|
232
|
+
_t: TFunction,
|
|
233
|
+
sourceValues: Record<string, unknown>,
|
|
234
|
+
disabled: boolean,
|
|
235
|
+
required: boolean,
|
|
236
|
+
): ReactNode {
|
|
237
|
+
const common = {
|
|
238
|
+
id,
|
|
239
|
+
error,
|
|
240
|
+
helpTextId,
|
|
241
|
+
errorId,
|
|
242
|
+
disabled,
|
|
243
|
+
required,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
switch (component) {
|
|
247
|
+
case "text":
|
|
248
|
+
return (
|
|
249
|
+
<TextField
|
|
250
|
+
{...common}
|
|
251
|
+
type="text"
|
|
252
|
+
value={value as string}
|
|
253
|
+
onChange={onChange as (v: string) => void}
|
|
254
|
+
placeholder={props.placeholder}
|
|
255
|
+
readOnly={props.readOnly}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
case "email":
|
|
260
|
+
return (
|
|
261
|
+
<TextField
|
|
262
|
+
{...common}
|
|
263
|
+
type="email"
|
|
264
|
+
value={value as string}
|
|
265
|
+
onChange={onChange as (v: string) => void}
|
|
266
|
+
placeholder={props.placeholder}
|
|
267
|
+
readOnly={props.readOnly}
|
|
268
|
+
/>
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
case "url":
|
|
272
|
+
return (
|
|
273
|
+
<TextField
|
|
274
|
+
{...common}
|
|
275
|
+
type="url"
|
|
276
|
+
value={value as string}
|
|
277
|
+
onChange={onChange as (v: string) => void}
|
|
278
|
+
placeholder={props.placeholder}
|
|
279
|
+
readOnly={props.readOnly}
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
case "textarea":
|
|
284
|
+
return (
|
|
285
|
+
<TextareaField
|
|
286
|
+
{...common}
|
|
287
|
+
value={value as string}
|
|
288
|
+
onChange={onChange as (v: string) => void}
|
|
289
|
+
placeholder={props.placeholder}
|
|
290
|
+
rows={props.rows}
|
|
291
|
+
readOnly={props.readOnly}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
case "password":
|
|
296
|
+
return (
|
|
297
|
+
<PasswordField
|
|
298
|
+
{...common}
|
|
299
|
+
value={value as string}
|
|
300
|
+
onChange={onChange as (v: string) => void}
|
|
301
|
+
placeholder={props.placeholder}
|
|
302
|
+
/>
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
case "otp":
|
|
306
|
+
return (
|
|
307
|
+
<OtpField
|
|
308
|
+
{...common}
|
|
309
|
+
value={value as string}
|
|
310
|
+
onChange={onChange as (v: string) => void}
|
|
311
|
+
maxLength={props.maxLength}
|
|
312
|
+
pattern={props.pattern}
|
|
313
|
+
groupSize={props.groupSize}
|
|
314
|
+
/>
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
case "select":
|
|
318
|
+
return (
|
|
319
|
+
<SelectField
|
|
320
|
+
{...common}
|
|
321
|
+
value={value as string}
|
|
322
|
+
onChange={onChange as (v: string) => void}
|
|
323
|
+
options={props.options ?? []}
|
|
324
|
+
placeholder={props.placeholder}
|
|
325
|
+
/>
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
case "native_select":
|
|
329
|
+
return (
|
|
330
|
+
<NativeSelectField
|
|
331
|
+
{...common}
|
|
332
|
+
value={value as string}
|
|
333
|
+
onChange={onChange as (v: string) => void}
|
|
334
|
+
options={props.options ?? []}
|
|
335
|
+
placeholder={props.placeholder}
|
|
336
|
+
/>
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
case "multiselect":
|
|
340
|
+
return (
|
|
341
|
+
<MultiSelectField
|
|
342
|
+
{...common}
|
|
343
|
+
value={value as string[]}
|
|
344
|
+
onChange={onChange as (v: string[]) => void}
|
|
345
|
+
options={props.options ?? []}
|
|
346
|
+
placeholder={props.placeholder}
|
|
347
|
+
variant={(props as { variant?: "auto" | "combobox" | "checkbox" }).variant}
|
|
348
|
+
/>
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
case "radio":
|
|
352
|
+
return (
|
|
353
|
+
<RadioField
|
|
354
|
+
{...common}
|
|
355
|
+
value={value as string}
|
|
356
|
+
onChange={onChange as (v: string) => void}
|
|
357
|
+
options={props.options ?? []}
|
|
358
|
+
/>
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
case "int":
|
|
362
|
+
return (
|
|
363
|
+
<NumberFieldComponent
|
|
364
|
+
{...common}
|
|
365
|
+
value={value as number | null}
|
|
366
|
+
onChange={onChange as (v: number | null) => void}
|
|
367
|
+
min={props.min}
|
|
368
|
+
max={props.max}
|
|
369
|
+
step={1}
|
|
370
|
+
/>
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
case "float":
|
|
374
|
+
return (
|
|
375
|
+
<NumberFieldComponent
|
|
376
|
+
{...common}
|
|
377
|
+
value={value as number | null}
|
|
378
|
+
onChange={onChange as (v: number | null) => void}
|
|
379
|
+
min={props.min}
|
|
380
|
+
max={props.max}
|
|
381
|
+
step={props.step ?? 0.1}
|
|
382
|
+
/>
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
case "slider":
|
|
386
|
+
return (
|
|
387
|
+
<SliderField
|
|
388
|
+
{...common}
|
|
389
|
+
value={value as number | number[] | null}
|
|
390
|
+
onChange={onChange as (v: number | number[]) => void}
|
|
391
|
+
min={props.min}
|
|
392
|
+
max={props.max}
|
|
393
|
+
step={props.step}
|
|
394
|
+
multiple={props.multiple}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
case "checkbox":
|
|
399
|
+
return (
|
|
400
|
+
<CheckboxField
|
|
401
|
+
{...common}
|
|
402
|
+
value={value as boolean}
|
|
403
|
+
onChange={onChange as (v: boolean) => void}
|
|
404
|
+
label={props.label}
|
|
405
|
+
/>
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
case "switch":
|
|
409
|
+
return (
|
|
410
|
+
<SwitchField
|
|
411
|
+
{...common}
|
|
412
|
+
value={value as boolean}
|
|
413
|
+
onChange={onChange as (v: boolean) => void}
|
|
414
|
+
label={props.label}
|
|
415
|
+
/>
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
case "date":
|
|
419
|
+
return (
|
|
420
|
+
<Suspense fallback={<InputSkeleton />}>
|
|
421
|
+
<LazyDateField
|
|
422
|
+
{...common}
|
|
423
|
+
mode="date"
|
|
424
|
+
value={value as string}
|
|
425
|
+
onChange={onChange as (v: string) => void}
|
|
426
|
+
placeholder={props.placeholder}
|
|
427
|
+
/>
|
|
428
|
+
</Suspense>
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
case "datetime":
|
|
432
|
+
return (
|
|
433
|
+
<Suspense fallback={<InputSkeleton />}>
|
|
434
|
+
<LazyDateField
|
|
435
|
+
{...common}
|
|
436
|
+
mode="datetime"
|
|
437
|
+
value={value as string}
|
|
438
|
+
onChange={onChange as (v: string) => void}
|
|
439
|
+
placeholder={props.placeholder}
|
|
440
|
+
/>
|
|
441
|
+
</Suspense>
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
case "file":
|
|
445
|
+
return (
|
|
446
|
+
<FileUploadField
|
|
447
|
+
{...common}
|
|
448
|
+
value={value}
|
|
449
|
+
onChange={onChange as (v: File[] | File | null) => void}
|
|
450
|
+
accept={props.accept}
|
|
451
|
+
multiple={props.multiple}
|
|
452
|
+
maxFiles={props.maxFiles}
|
|
453
|
+
maxSize={props.maxSize}
|
|
454
|
+
/>
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
case "entity_picker":
|
|
458
|
+
return (
|
|
459
|
+
<EntityPickerField
|
|
460
|
+
{...common}
|
|
461
|
+
value={value as string}
|
|
462
|
+
onChange={onChange as (v: string) => void}
|
|
463
|
+
options={
|
|
464
|
+
props.options as
|
|
465
|
+
| Array<{ value: string; label: string; subtitle?: string; avatarUrl?: string }>
|
|
466
|
+
| undefined
|
|
467
|
+
}
|
|
468
|
+
autocompleteHref={props.autocompleteHref}
|
|
469
|
+
autocompleteMinChars={props.autocompleteMinChars}
|
|
470
|
+
initialOption={props.initialOption}
|
|
471
|
+
entityAvatarField={props.entityAvatarField}
|
|
472
|
+
entitySubtitleField={props.entitySubtitleField}
|
|
473
|
+
placeholder={props.placeholder}
|
|
474
|
+
/>
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
case "static":
|
|
478
|
+
return <StaticField id={id} value={value} />;
|
|
479
|
+
|
|
480
|
+
case "phone":
|
|
481
|
+
return (
|
|
482
|
+
<Suspense fallback={<InputSkeleton />}>
|
|
483
|
+
<LazyPhoneField
|
|
484
|
+
{...common}
|
|
485
|
+
value={value as string}
|
|
486
|
+
onChange={onChange as (v: string) => void}
|
|
487
|
+
placeholder={props.placeholder}
|
|
488
|
+
defaultCountry={props.defaultCountry}
|
|
489
|
+
fixedCountry={props.fixedCountry}
|
|
490
|
+
/>
|
|
491
|
+
</Suspense>
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
case "document":
|
|
495
|
+
return (
|
|
496
|
+
<Suspense fallback={<InputSkeleton />}>
|
|
497
|
+
<LazyDocumentField
|
|
498
|
+
{...common}
|
|
499
|
+
value={value as string}
|
|
500
|
+
onChange={onChange as (v: string) => void}
|
|
501
|
+
documentType={props.documentType}
|
|
502
|
+
documentScope={props.documentScope}
|
|
503
|
+
documentMasks={props.documentMasks}
|
|
504
|
+
placeholder={props.placeholder}
|
|
505
|
+
/>
|
|
506
|
+
</Suspense>
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
case "currency":
|
|
510
|
+
return (
|
|
511
|
+
<CurrencyField
|
|
512
|
+
{...common}
|
|
513
|
+
value={value as number | null}
|
|
514
|
+
onChange={onChange as (v: number | null) => void}
|
|
515
|
+
currency={props.currency}
|
|
516
|
+
placeholder={props.placeholder}
|
|
517
|
+
min={props.min}
|
|
518
|
+
max={props.max}
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
case "color":
|
|
523
|
+
return (
|
|
524
|
+
<ColorField
|
|
525
|
+
{...common}
|
|
526
|
+
value={value as string}
|
|
527
|
+
onChange={onChange as (v: string) => void}
|
|
528
|
+
placeholder={props.placeholder}
|
|
529
|
+
/>
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
case "slug":
|
|
533
|
+
return (
|
|
534
|
+
<SlugField
|
|
535
|
+
{...common}
|
|
536
|
+
value={value as string}
|
|
537
|
+
onChange={onChange as (v: string) => void}
|
|
538
|
+
sourceValue={
|
|
539
|
+
props.sourceField !== undefined
|
|
540
|
+
? String(sourceValues[props.sourceField] ?? "")
|
|
541
|
+
: undefined
|
|
542
|
+
}
|
|
543
|
+
prefix={props.prefix}
|
|
544
|
+
placeholder={props.placeholder}
|
|
545
|
+
/>
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
case "tags":
|
|
549
|
+
return (
|
|
550
|
+
<TagsField
|
|
551
|
+
{...common}
|
|
552
|
+
value={value as string[]}
|
|
553
|
+
onChange={onChange as (v: string[]) => void}
|
|
554
|
+
placeholder={props.placeholder}
|
|
555
|
+
maxTags={props.maxTags}
|
|
556
|
+
/>
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
case "date_range":
|
|
560
|
+
return (
|
|
561
|
+
<Suspense fallback={<InputSkeleton />}>
|
|
562
|
+
<LazyDateRangeField
|
|
563
|
+
{...common}
|
|
564
|
+
value={value}
|
|
565
|
+
onChange={onChange}
|
|
566
|
+
operator={props.operator}
|
|
567
|
+
/>
|
|
568
|
+
</Suspense>
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
case "rating":
|
|
572
|
+
return (
|
|
573
|
+
<RatingField
|
|
574
|
+
{...common}
|
|
575
|
+
value={value as number | null}
|
|
576
|
+
onChange={onChange as (v: number) => void}
|
|
577
|
+
maxRating={props.maxRating}
|
|
578
|
+
/>
|
|
579
|
+
);
|
|
580
|
+
|
|
581
|
+
default: {
|
|
582
|
+
/**
|
|
583
|
+
* A component this file has never heard of, resolved from the registry.
|
|
584
|
+
*
|
|
585
|
+
* `registerFieldComponent` has been public, and documented as the way to
|
|
586
|
+
* add a field without editing this file, while nothing ever read the
|
|
587
|
+
* registry back — registering one had no effect at all. This is where that
|
|
588
|
+
* promise comes true.
|
|
589
|
+
*
|
|
590
|
+
* The lookup belongs *here* and not before the switch, even though earlier
|
|
591
|
+
* would also let a consumer replace a built-in: `registerDefaultFields`
|
|
592
|
+
* puts every shipped field in the same registry, and those expect their own
|
|
593
|
+
* explicit props, which the cases above supply. Resolving from the registry
|
|
594
|
+
* first would hand `select` a `fieldProps` bag instead of its `options` and
|
|
595
|
+
* break every form in the library.
|
|
596
|
+
*
|
|
597
|
+
* A custom field gets the whole bag, per `FieldComponentProps` — this file
|
|
598
|
+
* cannot know what a field it does not recognise needs.
|
|
599
|
+
*/
|
|
600
|
+
const Registered = resolveFieldComponent(component);
|
|
601
|
+
if (Registered) {
|
|
602
|
+
return <Registered {...common} value={value} onChange={onChange} fieldProps={props} />;
|
|
603
|
+
}
|
|
604
|
+
return <p className="text-destructive text-xs">Unknown field component: {component}</p>;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckboxField -- single boolean checkbox with label.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Checkbox (Radix) primitive with form-field aria plumbing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
import { Checkbox } from "@/primitives/reui/checkbox";
|
|
10
|
+
import { Label } from "@/primitives/reui/label";
|
|
11
|
+
|
|
12
|
+
export interface CheckboxFieldProps {
|
|
13
|
+
id: string;
|
|
14
|
+
value: boolean;
|
|
15
|
+
onChange: (value: boolean) => void;
|
|
16
|
+
label?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
helpTextId?: string;
|
|
21
|
+
errorId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function CheckboxField({
|
|
25
|
+
id,
|
|
26
|
+
value,
|
|
27
|
+
onChange,
|
|
28
|
+
label,
|
|
29
|
+
disabled,
|
|
30
|
+
required,
|
|
31
|
+
error,
|
|
32
|
+
helpTextId,
|
|
33
|
+
errorId,
|
|
34
|
+
}: CheckboxFieldProps): ReactElement {
|
|
35
|
+
const describedBy =
|
|
36
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="flex items-center gap-2">
|
|
40
|
+
<Checkbox
|
|
41
|
+
id={id}
|
|
42
|
+
checked={!!value}
|
|
43
|
+
onCheckedChange={(checked) => onChange(checked === true)}
|
|
44
|
+
disabled={disabled}
|
|
45
|
+
aria-invalid={error ? true : undefined}
|
|
46
|
+
aria-required={required || undefined}
|
|
47
|
+
aria-describedby={describedBy}
|
|
48
|
+
/>
|
|
49
|
+
{label && (
|
|
50
|
+
<Label htmlFor={id} className="text-sm font-normal">
|
|
51
|
+
{label}
|
|
52
|
+
</Label>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|