@middag-io/react 0.44.1 → 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/README.md +7 -0
- package/dist-lib/{FormField-Bj43PjHH.js → FormField-Csx8hGAW.js} +1956 -1936
- package/dist-lib/{FormPanelBlock-C6eDfGoI.js → FormPanelBlock-Bmd0DpiX.js} +337 -337
- package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
- package/dist-lib/base/blocks/LinkListBlock.d.ts +2 -1
- package/dist-lib/base/blocks/LinkListBlock.d.ts.map +1 -1
- package/dist-lib/base/form/FormField.d.ts.map +1 -1
- package/dist-lib/base/layout/DashboardLayout.d.ts.map +1 -1
- package/dist-lib/base/partials/ConfirmationDialog/index.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/cell-renderers.d.ts +1 -1
- package/dist-lib/base/partials/DataTable/cell-renderers.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/index.d.ts +1 -1
- package/dist-lib/base/partials/DataTable/index.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/sanitize-html.d.ts +17 -0
- package/dist-lib/base/partials/DataTable/sanitize-html.d.ts.map +1 -0
- package/dist-lib/base/partials/DataTable/types.d.ts +15 -0
- package/dist-lib/base/partials/DataTable/types.d.ts.map +1 -1
- package/dist-lib/base/partials/FilterBar/index.d.ts.map +1 -1
- package/dist-lib/base/shell/BasicShell.js +1 -1
- package/dist-lib/base/shell/partials/InlineEditablePanel.js +38 -24
- package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
- package/dist-lib/base/shell/partials/PageActionButton.js +1 -1
- package/dist-lib/chunks/subpath-Bh1MAmBT.js +165 -0
- package/dist-lib/chunks/{subpath-AeMdleNB.js → subpath-fEhy6n_U.js} +10 -6
- package/dist-lib/contracts/block-data/data-display.d.ts +51 -2
- package/dist-lib/contracts/block-data/data-display.d.ts.map +1 -1
- package/dist-lib/contracts/generated/contract-schema.d.ts +1 -1
- package/dist-lib/contracts/generated/contract-types.d.ts +4 -2
- package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
- package/dist-lib/contracts/generated/index.d.ts +1 -1
- package/dist-lib/i18n/I18nProvider.js +1 -1
- package/dist-lib/i18n/instance.js +1 -1
- package/dist-lib/i18n/locales/en/ui.json +5 -3
- package/dist-lib/i18n/locales/pt-BR/ui.json +5 -3
- package/dist-lib/i18n/register-strings.js +1 -1
- package/dist-lib/index.d.ts +1 -1
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/middag-react.css +1 -1
- package/dist-lib/middag-react.js +18641 -13317
- package/dist-lib/primitives/reui/chart.d.ts.map +1 -1
- package/dist-lib/primitives/reui/chart.js +35 -31
- 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
- package/dist-lib/chunks/subpath-q4Q2zg_p.js +0 -153
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RatingField — star rating input using ReUI Rating component.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ReactElement } from "react";
|
|
6
|
+
|
|
7
|
+
import { Rating } from "@/primitives/reui/rating";
|
|
8
|
+
|
|
9
|
+
export interface RatingFieldProps {
|
|
10
|
+
id: string;
|
|
11
|
+
value: number | null;
|
|
12
|
+
onChange: (value: number) => void;
|
|
13
|
+
maxRating?: number;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
helpTextId?: string;
|
|
18
|
+
errorId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function RatingField({
|
|
22
|
+
id,
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
maxRating = 5,
|
|
26
|
+
disabled,
|
|
27
|
+
required,
|
|
28
|
+
error,
|
|
29
|
+
helpTextId,
|
|
30
|
+
errorId,
|
|
31
|
+
}: RatingFieldProps): ReactElement {
|
|
32
|
+
const describedBy =
|
|
33
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
id={id}
|
|
38
|
+
role="radiogroup"
|
|
39
|
+
aria-required={required || undefined}
|
|
40
|
+
aria-invalid={error ? true : undefined}
|
|
41
|
+
aria-describedby={describedBy}
|
|
42
|
+
>
|
|
43
|
+
<Rating
|
|
44
|
+
rating={value ?? 0}
|
|
45
|
+
maxRating={maxRating}
|
|
46
|
+
editable={!disabled}
|
|
47
|
+
showValue
|
|
48
|
+
onRatingChange={onChange}
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SelectField -- single-value select dropdown.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Select (Radix) primitive with form-field aria plumbing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
10
|
+
import {
|
|
11
|
+
Select,
|
|
12
|
+
SelectContent,
|
|
13
|
+
SelectItem,
|
|
14
|
+
SelectTrigger,
|
|
15
|
+
SelectValue,
|
|
16
|
+
} from "@/primitives/reui/select";
|
|
17
|
+
|
|
18
|
+
export interface SelectOption {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SelectFieldProps {
|
|
24
|
+
id: string;
|
|
25
|
+
value: string;
|
|
26
|
+
onChange: (value: string) => void;
|
|
27
|
+
options: SelectOption[];
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
helpTextId?: string;
|
|
33
|
+
errorId?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function SelectField({
|
|
37
|
+
id,
|
|
38
|
+
value,
|
|
39
|
+
onChange,
|
|
40
|
+
options,
|
|
41
|
+
placeholder,
|
|
42
|
+
disabled,
|
|
43
|
+
required,
|
|
44
|
+
error,
|
|
45
|
+
helpTextId,
|
|
46
|
+
errorId,
|
|
47
|
+
}: SelectFieldProps): ReactElement {
|
|
48
|
+
const { t } = useTranslation();
|
|
49
|
+
const describedBy =
|
|
50
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Select value={value ?? ""} onValueChange={onChange} disabled={disabled} required={required}>
|
|
54
|
+
<SelectTrigger
|
|
55
|
+
id={id}
|
|
56
|
+
className="w-full"
|
|
57
|
+
aria-invalid={error ? true : undefined}
|
|
58
|
+
aria-required={required || undefined}
|
|
59
|
+
aria-describedby={describedBy}
|
|
60
|
+
>
|
|
61
|
+
<SelectValue placeholder={placeholder ?? t("middag.ui.form.select_placeholder")} />
|
|
62
|
+
</SelectTrigger>
|
|
63
|
+
{/* popper, not the primitive's item-aligned default: item-aligned lays the
|
|
64
|
+
list over the trigger (aligning the selected option to it), so in a form
|
|
65
|
+
the open menu covers the field it belongs to and reads as a misplaced
|
|
66
|
+
overlay. A form field should drop its options below itself. */}
|
|
67
|
+
<SelectContent position="popper" sideOffset={4} align="start" className="w-full">
|
|
68
|
+
{options.map((opt) => (
|
|
69
|
+
<SelectItem key={opt.value} value={opt.value}>
|
|
70
|
+
{opt.label}
|
|
71
|
+
</SelectItem>
|
|
72
|
+
))}
|
|
73
|
+
</SelectContent>
|
|
74
|
+
</Select>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SliderField -- numeric range input (single value or two-thumb range).
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Slider (Radix) primitive with form-field aria plumbing.
|
|
5
|
+
* Radix works in arrays internally; this field accepts/returns a scalar for
|
|
6
|
+
* single mode and a [from, to] tuple when `multiple` is set.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ReactElement } from "react";
|
|
10
|
+
|
|
11
|
+
import { Slider } from "@/primitives/reui/slider";
|
|
12
|
+
|
|
13
|
+
export interface SliderFieldProps {
|
|
14
|
+
id: string;
|
|
15
|
+
value: number | number[] | null;
|
|
16
|
+
onChange: (value: number | number[]) => void;
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
step?: number;
|
|
20
|
+
multiple?: boolean;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
error?: string;
|
|
24
|
+
helpTextId?: string;
|
|
25
|
+
errorId?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function SliderField({
|
|
29
|
+
id,
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
min = 0,
|
|
33
|
+
max = 100,
|
|
34
|
+
step = 1,
|
|
35
|
+
multiple = false,
|
|
36
|
+
disabled,
|
|
37
|
+
required,
|
|
38
|
+
error,
|
|
39
|
+
helpTextId,
|
|
40
|
+
errorId,
|
|
41
|
+
}: SliderFieldProps): ReactElement {
|
|
42
|
+
const describedBy =
|
|
43
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
44
|
+
|
|
45
|
+
const arrayValue = Array.isArray(value)
|
|
46
|
+
? value
|
|
47
|
+
: value == null
|
|
48
|
+
? multiple
|
|
49
|
+
? [min, max]
|
|
50
|
+
: [min]
|
|
51
|
+
: [value];
|
|
52
|
+
|
|
53
|
+
const display = multiple ? arrayValue.join(" – ") : String(arrayValue[0] ?? min);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div className="flex items-center gap-4">
|
|
57
|
+
<Slider
|
|
58
|
+
id={id}
|
|
59
|
+
value={arrayValue}
|
|
60
|
+
min={min}
|
|
61
|
+
max={max}
|
|
62
|
+
step={step}
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
onValueChange={(vals: number[]) => onChange(multiple ? vals : (vals[0] ?? min))}
|
|
65
|
+
aria-invalid={error ? true : undefined}
|
|
66
|
+
aria-required={required || undefined}
|
|
67
|
+
aria-describedby={describedBy}
|
|
68
|
+
/>
|
|
69
|
+
<span
|
|
70
|
+
aria-hidden="true"
|
|
71
|
+
className="text-muted-foreground min-w-12 text-right text-sm tabular-nums"
|
|
72
|
+
>
|
|
73
|
+
{display}
|
|
74
|
+
</span>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SlugField — URL-friendly slug input with auto-generation.
|
|
3
|
+
*
|
|
4
|
+
* Normalizes input: lowercase, replaces spaces/special chars with hyphens,
|
|
5
|
+
* removes consecutive hyphens. Uses ReUI InputGroup for the URL prefix.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useCallback, useEffect, useState, type ReactElement } from "react";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
InputGroup,
|
|
12
|
+
InputGroupAddon,
|
|
13
|
+
InputGroupInput,
|
|
14
|
+
InputGroupText,
|
|
15
|
+
} from "@/primitives/reui/input-group";
|
|
16
|
+
|
|
17
|
+
/** Convert a string to a URL-friendly slug. */
|
|
18
|
+
function toSlug(text: string): string {
|
|
19
|
+
return text
|
|
20
|
+
.normalize("NFD")
|
|
21
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
24
|
+
.replace(/^-+|-+$/g, "")
|
|
25
|
+
.replace(/-{2,}/g, "-");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SlugFieldProps {
|
|
29
|
+
id: string;
|
|
30
|
+
value: string;
|
|
31
|
+
onChange: (value: string) => void;
|
|
32
|
+
/** Source value to auto-generate slug from (e.g. title field). */
|
|
33
|
+
sourceValue?: string;
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
required?: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
helpTextId?: string;
|
|
39
|
+
errorId?: string;
|
|
40
|
+
prefix?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function SlugField({
|
|
44
|
+
id,
|
|
45
|
+
value,
|
|
46
|
+
onChange,
|
|
47
|
+
sourceValue,
|
|
48
|
+
placeholder,
|
|
49
|
+
disabled,
|
|
50
|
+
required,
|
|
51
|
+
error,
|
|
52
|
+
helpTextId,
|
|
53
|
+
errorId,
|
|
54
|
+
prefix,
|
|
55
|
+
}: SlugFieldProps): ReactElement {
|
|
56
|
+
const [manualEdit, setManualEdit] = useState(false);
|
|
57
|
+
const describedBy =
|
|
58
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
59
|
+
|
|
60
|
+
// Auto-generate from source unless user has manually edited
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!manualEdit && sourceValue !== undefined) {
|
|
63
|
+
const next = toSlug(sourceValue);
|
|
64
|
+
if (next !== value) {
|
|
65
|
+
onChange(next);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, [sourceValue, manualEdit, onChange, value]);
|
|
69
|
+
|
|
70
|
+
const handleChange = useCallback(
|
|
71
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
72
|
+
setManualEdit(true);
|
|
73
|
+
onChange(toSlug(e.target.value));
|
|
74
|
+
},
|
|
75
|
+
[onChange],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if (!prefix) {
|
|
79
|
+
return (
|
|
80
|
+
<InputGroup data-disabled={disabled || undefined}>
|
|
81
|
+
<InputGroupInput
|
|
82
|
+
id={id}
|
|
83
|
+
type="text"
|
|
84
|
+
value={value ?? ""}
|
|
85
|
+
onChange={handleChange}
|
|
86
|
+
placeholder={placeholder ?? "url-friendly-slug"}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
aria-invalid={error ? true : undefined}
|
|
89
|
+
aria-required={required || undefined}
|
|
90
|
+
aria-describedby={describedBy}
|
|
91
|
+
/>
|
|
92
|
+
</InputGroup>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<InputGroup data-disabled={disabled || undefined}>
|
|
98
|
+
<InputGroupAddon align="inline-start">
|
|
99
|
+
<InputGroupText>{prefix}</InputGroupText>
|
|
100
|
+
</InputGroupAddon>
|
|
101
|
+
<InputGroupInput
|
|
102
|
+
id={id}
|
|
103
|
+
type="text"
|
|
104
|
+
value={value ?? ""}
|
|
105
|
+
onChange={handleChange}
|
|
106
|
+
placeholder={placeholder ?? "url-friendly-slug"}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
aria-invalid={error ? true : undefined}
|
|
109
|
+
aria-required={required || undefined}
|
|
110
|
+
aria-describedby={describedBy}
|
|
111
|
+
/>
|
|
112
|
+
</InputGroup>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StaticField -- read-only display of a value.
|
|
3
|
+
*
|
|
4
|
+
* Renders the value as a paragraph, not as an interactive control.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
export interface StaticFieldProps {
|
|
10
|
+
id: string;
|
|
11
|
+
value: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function StaticField({ id, value }: StaticFieldProps): ReactElement {
|
|
15
|
+
const displayValue = value === null || value === undefined ? "\u2014" : String(value);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<p
|
|
19
|
+
id={id}
|
|
20
|
+
className="border-input bg-muted/50 text-foreground rounded-md border px-3 py-2 text-sm"
|
|
21
|
+
>
|
|
22
|
+
{displayValue}
|
|
23
|
+
</p>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SwitchField -- boolean toggle switch with label.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Switch (Radix) primitive with form-field aria plumbing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
import { Label } from "@/primitives/reui/label";
|
|
10
|
+
import { Switch } from "@/primitives/reui/switch";
|
|
11
|
+
|
|
12
|
+
export interface SwitchFieldProps {
|
|
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 SwitchField({
|
|
25
|
+
id,
|
|
26
|
+
value,
|
|
27
|
+
onChange,
|
|
28
|
+
label,
|
|
29
|
+
disabled,
|
|
30
|
+
required,
|
|
31
|
+
error,
|
|
32
|
+
helpTextId,
|
|
33
|
+
errorId,
|
|
34
|
+
}: SwitchFieldProps): 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
|
+
<Switch
|
|
41
|
+
id={id}
|
|
42
|
+
checked={!!value}
|
|
43
|
+
onCheckedChange={onChange}
|
|
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
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TagsField -- chip-based tag input with keyboard support.
|
|
3
|
+
*
|
|
4
|
+
* Enter or comma adds a tag. Backspace removes the last tag.
|
|
5
|
+
* Tags are stored as string array.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
useCallback,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
type KeyboardEvent,
|
|
14
|
+
type ReactElement,
|
|
15
|
+
} from "react";
|
|
16
|
+
|
|
17
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
18
|
+
|
|
19
|
+
export interface TagsFieldProps {
|
|
20
|
+
id: string;
|
|
21
|
+
value: string[];
|
|
22
|
+
onChange: (value: string[]) => void;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
helpTextId?: string;
|
|
28
|
+
errorId?: string;
|
|
29
|
+
maxTags?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function TagsField({
|
|
33
|
+
id,
|
|
34
|
+
value,
|
|
35
|
+
onChange,
|
|
36
|
+
placeholder,
|
|
37
|
+
disabled,
|
|
38
|
+
required,
|
|
39
|
+
error,
|
|
40
|
+
helpTextId,
|
|
41
|
+
errorId,
|
|
42
|
+
maxTags,
|
|
43
|
+
}: TagsFieldProps): ReactElement {
|
|
44
|
+
const { t } = useTranslation();
|
|
45
|
+
const [input, setInput] = useState("");
|
|
46
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
47
|
+
const tags = useMemo(() => value ?? [], [value]);
|
|
48
|
+
|
|
49
|
+
const describedBy =
|
|
50
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
51
|
+
|
|
52
|
+
const addTag = useCallback(
|
|
53
|
+
(tag: string) => {
|
|
54
|
+
const trimmed = tag.trim();
|
|
55
|
+
if (!trimmed) return;
|
|
56
|
+
if (tags.includes(trimmed)) return;
|
|
57
|
+
if (maxTags && tags.length >= maxTags) return;
|
|
58
|
+
onChange([...tags, trimmed]);
|
|
59
|
+
setInput("");
|
|
60
|
+
},
|
|
61
|
+
[tags, onChange, maxTags],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const removeTag = useCallback(
|
|
65
|
+
(idx: number) => {
|
|
66
|
+
onChange(tags.filter((_, i) => i !== idx));
|
|
67
|
+
},
|
|
68
|
+
[tags, onChange],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const handleKeyDown = useCallback(
|
|
72
|
+
(e: KeyboardEvent<HTMLInputElement>) => {
|
|
73
|
+
if (e.key === "Enter" || e.key === ",") {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
addTag(input);
|
|
76
|
+
} else if (e.key === "Backspace" && !input && tags.length > 0) {
|
|
77
|
+
removeTag(tags.length - 1);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[input, tags, addTag, removeTag],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div
|
|
85
|
+
className={`focus-within:ring-ring flex min-h-9 w-full flex-wrap items-center gap-1.5 rounded-md border px-2 py-1.5 text-sm transition-colors focus-within:ring-1 ${
|
|
86
|
+
error ? "border-destructive" : "border-input"
|
|
87
|
+
} ${disabled ? "opacity-50" : ""}`}
|
|
88
|
+
onClick={() => inputRef.current?.focus()}
|
|
89
|
+
>
|
|
90
|
+
{tags.map((tag, idx) => (
|
|
91
|
+
<span
|
|
92
|
+
key={`${tag}-${idx}`}
|
|
93
|
+
className="bg-secondary text-secondary-foreground inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium"
|
|
94
|
+
>
|
|
95
|
+
{tag}
|
|
96
|
+
{!disabled && (
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
onClick={(e) => {
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
removeTag(idx);
|
|
102
|
+
}}
|
|
103
|
+
className="text-muted-foreground hover:text-foreground ml-0.5"
|
|
104
|
+
aria-label={`${t("middag.ui.form.tags_remove")} ${tag}`}
|
|
105
|
+
>
|
|
106
|
+
×
|
|
107
|
+
</button>
|
|
108
|
+
)}
|
|
109
|
+
</span>
|
|
110
|
+
))}
|
|
111
|
+
<input
|
|
112
|
+
ref={inputRef}
|
|
113
|
+
id={id}
|
|
114
|
+
type="text"
|
|
115
|
+
value={input}
|
|
116
|
+
onChange={(e) => setInput(e.target.value)}
|
|
117
|
+
onKeyDown={handleKeyDown}
|
|
118
|
+
onBlur={() => addTag(input)}
|
|
119
|
+
placeholder={tags.length === 0 ? (placeholder ?? t("middag.ui.form.tags_placeholder")) : ""}
|
|
120
|
+
disabled={disabled}
|
|
121
|
+
aria-invalid={error ? true : undefined}
|
|
122
|
+
aria-required={required || undefined}
|
|
123
|
+
aria-describedby={describedBy}
|
|
124
|
+
className="placeholder:text-muted-foreground min-w-[80px] flex-1 bg-transparent outline-none"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TextField -- text/email/url input field.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Input primitive with form-field aria plumbing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
import { Input } from "@/primitives/reui/input";
|
|
10
|
+
|
|
11
|
+
export interface TextFieldProps {
|
|
12
|
+
id: string;
|
|
13
|
+
value: string;
|
|
14
|
+
onChange: (value: string) => void;
|
|
15
|
+
type?: "text" | "email" | "url";
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
error?: string;
|
|
21
|
+
helpTextId?: string;
|
|
22
|
+
errorId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function TextField({
|
|
26
|
+
id,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
type = "text",
|
|
30
|
+
placeholder,
|
|
31
|
+
disabled,
|
|
32
|
+
readOnly,
|
|
33
|
+
required,
|
|
34
|
+
error,
|
|
35
|
+
helpTextId,
|
|
36
|
+
errorId,
|
|
37
|
+
}: TextFieldProps): ReactElement {
|
|
38
|
+
const describedBy =
|
|
39
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Input
|
|
43
|
+
id={id}
|
|
44
|
+
type={type}
|
|
45
|
+
value={value ?? ""}
|
|
46
|
+
onChange={(e) => onChange(e.target.value)}
|
|
47
|
+
placeholder={placeholder}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
readOnly={readOnly}
|
|
50
|
+
aria-invalid={error ? true : undefined}
|
|
51
|
+
aria-required={required || undefined}
|
|
52
|
+
aria-describedby={describedBy}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TextareaField -- multiline text input.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the ReUI Textarea primitive with form-field aria plumbing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
import { Textarea } from "@/primitives/reui/textarea";
|
|
10
|
+
|
|
11
|
+
export interface TextareaFieldProps {
|
|
12
|
+
id: string;
|
|
13
|
+
value: string;
|
|
14
|
+
onChange: (value: string) => void;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
rows?: number;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
error?: string;
|
|
21
|
+
helpTextId?: string;
|
|
22
|
+
errorId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function TextareaField({
|
|
26
|
+
id,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
placeholder,
|
|
30
|
+
rows = 4,
|
|
31
|
+
disabled,
|
|
32
|
+
readOnly,
|
|
33
|
+
required,
|
|
34
|
+
error,
|
|
35
|
+
helpTextId,
|
|
36
|
+
errorId,
|
|
37
|
+
}: TextareaFieldProps): ReactElement {
|
|
38
|
+
const describedBy =
|
|
39
|
+
[error ? errorId : undefined, helpTextId].filter(Boolean).join(" ") || undefined;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Textarea
|
|
43
|
+
id={id}
|
|
44
|
+
value={value ?? ""}
|
|
45
|
+
onChange={(e) => onChange(e.target.value)}
|
|
46
|
+
placeholder={placeholder}
|
|
47
|
+
rows={rows}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
readOnly={readOnly}
|
|
50
|
+
aria-invalid={error ? true : undefined}
|
|
51
|
+
aria-required={required || undefined}
|
|
52
|
+
aria-describedby={describedBy}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|