@brightlocal/ui-components 3.1.0 → 3.3.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/AI_USAGE.md +10 -0
- package/README.md +8 -1
- package/component-meta.json +1591 -123
- package/deprecations.json +45 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.js +73 -102
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +36 -5
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +83 -128
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts +4 -4
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +116 -177
- package/dist/aspect-ratio.cjs +1 -1
- package/dist/aspect-ratio.js +13 -16
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.js +30 -45
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +32 -1
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +90 -71
- package/dist/banner.cjs +1 -0
- package/dist/banner.d.ts +81 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +130 -0
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +24 -6
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +74 -140
- package/dist/blocks/input-list.cjs +2 -2
- package/dist/blocks/input-list.d.ts +2 -2
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +136 -176
- package/dist/blocks/progress-state.cjs +1 -1
- package/dist/blocks/progress-state.d.ts +2 -2
- package/dist/blocks/progress-state.js +223 -347
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +28 -6
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +763 -1086
- package/dist/brand-illustration-motif.cjs +1 -1
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/brand-illustration-motif.js +40 -61
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.js +62 -102
- package/dist/button-group.cjs +1 -1
- package/dist/button-group.js +23 -31
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts +4 -2
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +149 -189
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts +87 -3
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +116 -173
- package/dist/callout.cjs +1 -1
- package/dist/callout.js +73 -96
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +92 -6
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +240 -234
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +3 -3
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +174 -268
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.js +27 -48
- package/dist/chart-empty.cjs +1 -1
- package/dist/chart-empty.js +18 -27
- package/dist/chart.cjs +7 -7
- package/dist/chart.d.ts +253 -25
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +465 -511
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +1 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +37 -69
- package/dist/chip.cjs +1 -1
- package/dist/chip.js +116 -173
- package/dist/collapsible.cjs +1 -1
- package/dist/collapsible.d.ts.map +1 -1
- package/dist/collapsible.js +35 -41
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +14 -4
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +440 -639
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +273 -420
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts +5 -5
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +121 -191
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +442 -144
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +708 -835
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +15 -4
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +156 -231
- package/dist/delta.cjs +1 -0
- package/dist/delta.d.ts +79 -0
- package/dist/delta.d.ts.map +1 -0
- package/dist/delta.js +62 -0
- package/dist/description.cjs +1 -1
- package/dist/description.js +11 -20
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +1 -1
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +76 -116
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +11 -11
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +76 -134
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts +6 -6
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +179 -300
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +9 -9
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +166 -286
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.js +203 -342
- package/dist/grid.cjs +1 -1
- package/dist/grid.d.ts +24 -1
- package/dist/grid.d.ts.map +1 -1
- package/dist/grid.js +16 -29
- package/dist/header.cjs +1 -1
- package/dist/header.js +21 -38
- package/dist/height-transition.cjs +1 -1
- package/dist/height-transition.js +38 -55
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +10 -9
- package/dist/hooks/use-debounce.cjs +1 -1
- package/dist/hooks/use-debounce.js +12 -11
- package/dist/hooks/use-delayed-pending.cjs +1 -1
- package/dist/hooks/use-delayed-pending.js +8 -9
- package/dist/hooks/use-filter-search-params.cjs +1 -0
- package/dist/hooks/use-filter-search-params.d.ts +93 -0
- package/dist/hooks/use-filter-search-params.d.ts.map +1 -0
- package/dist/hooks/use-filter-search-params.js +122 -0
- package/dist/hooks/use-mobile.cjs +1 -1
- package/dist/hooks/use-mobile.js +6 -6
- package/dist/hooks/use-overlay-pointer-lock.cjs +1 -1
- package/dist/hooks/use-overlay-pointer-lock.js +8 -9
- package/dist/hooks/use-prefers-reduced-motion.cjs +1 -1
- package/dist/hooks/use-prefers-reduced-motion.js +5 -8
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +1 -1
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +30 -62
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +636 -582
- package/dist/info-tooltip.cjs +1 -0
- package/dist/info-tooltip.d.ts +39 -0
- package/dist/info-tooltip.d.ts.map +1 -0
- package/dist/info-tooltip.js +27 -0
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +32 -3
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +182 -231
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +33 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +188 -122
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.d.ts +3 -3
- package/dist/input-otp.d.ts.map +1 -1
- package/dist/input-otp.js +102 -146
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +26 -8
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +139 -171
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +51 -73
- package/dist/label.cjs +1 -1
- package/dist/label.js +20 -38
- package/dist/lib/block-illustration.cjs +1 -1
- package/dist/lib/block-illustration.d.ts +5 -2
- package/dist/lib/block-illustration.d.ts.map +1 -1
- package/dist/lib/block-illustration.js +16 -17
- package/dist/lib/compose-event-handlers.cjs +1 -0
- package/dist/lib/compose-event-handlers.d.ts +9 -0
- package/dist/lib/compose-event-handlers.d.ts.map +1 -0
- package/dist/lib/compose-event-handlers.js +8 -0
- package/dist/lib/download-file.cjs +1 -0
- package/dist/lib/download-file.d.ts +14 -0
- package/dist/lib/download-file.d.ts.map +1 -0
- package/dist/lib/download-file.js +40 -0
- package/dist/lib/empty-canvas.cjs +1 -1
- package/dist/lib/empty-canvas.js +28 -56
- package/dist/lib/empty-chip.cjs +1 -1
- package/dist/lib/empty-chip.d.ts +14 -3
- package/dist/lib/empty-chip.d.ts.map +1 -1
- package/dist/lib/empty-chip.js +15 -11
- package/dist/lib/field-aria.cjs +1 -0
- package/dist/lib/field-aria.d.ts +34 -0
- package/dist/lib/field-aria.d.ts.map +1 -0
- package/dist/lib/field-aria.js +52 -0
- package/dist/lib/image-file-info.cjs +1 -0
- package/dist/lib/image-file-info.d.ts +25 -0
- package/dist/lib/image-file-info.d.ts.map +1 -0
- package/dist/lib/image-file-info.js +67 -0
- package/dist/lib/media-viewer-content.cjs +1 -0
- package/dist/lib/media-viewer-content.d.ts +102 -0
- package/dist/lib/media-viewer-content.d.ts.map +1 -0
- package/dist/lib/media-viewer-content.js +650 -0
- package/dist/lib/media-viewer-internal.cjs +1 -0
- package/dist/lib/media-viewer-internal.d.ts +98 -0
- package/dist/lib/media-viewer-internal.d.ts.map +1 -0
- package/dist/lib/media-viewer-internal.js +61 -0
- package/dist/lib/media-viewer-motion.cjs +1 -0
- package/dist/lib/media-viewer-motion.d.ts +40 -0
- package/dist/lib/media-viewer-motion.d.ts.map +1 -0
- package/dist/lib/media-viewer-motion.js +37 -0
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.d.ts +8 -0
- package/dist/lib/motion.d.ts.map +1 -1
- package/dist/lib/motion.js +11 -10
- package/dist/lib/optical-center.cjs +1 -1
- package/dist/lib/optical-center.d.ts +1 -1
- package/dist/lib/optical-center.d.ts.map +1 -1
- package/dist/lib/optical-center.js +12 -5
- package/dist/lib/spring-settle.cjs +1 -1
- package/dist/lib/spring-settle.js +1 -1
- package/dist/lib/table-internal.cjs +1 -0
- package/dist/lib/table-internal.d.ts +62 -0
- package/dist/lib/table-internal.d.ts.map +1 -0
- package/dist/lib/table-internal.js +18 -0
- package/dist/lib/use-controllable.cjs +1 -0
- package/dist/lib/use-controllable.d.ts +12 -0
- package/dist/lib/use-controllable.d.ts.map +1 -0
- package/dist/lib/use-controllable.js +15 -0
- package/dist/lib/use-dev-warning.cjs +1 -1
- package/dist/lib/utils.cjs +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +29 -35
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +1 -1
- package/dist/link.js +78 -124
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +8 -0
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +94 -156
- package/dist/loading.cjs +1 -1
- package/dist/loading.js +124 -151
- package/dist/logo-mark.cjs +1 -0
- package/dist/logo-mark.d.ts +79 -0
- package/dist/logo-mark.d.ts.map +1 -0
- package/dist/logo-mark.js +219 -0
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +1 -1
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +51 -87
- package/dist/map.cjs +1 -1
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +390 -586
- package/dist/media-empty.cjs +1 -1
- package/dist/media-empty.js +27 -42
- package/dist/media-viewer.cjs +1 -0
- package/dist/media-viewer.d.ts +224 -0
- package/dist/media-viewer.d.ts.map +1 -0
- package/dist/media-viewer.js +295 -0
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts +14 -14
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +130 -267
- package/dist/multi-select-filter.cjs +1 -0
- package/dist/multi-select-filter.d.ts +186 -0
- package/dist/multi-select-filter.d.ts.map +1 -0
- package/dist/multi-select-filter.js +374 -0
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.js +108 -172
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +36 -12
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +208 -281
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts +1 -1
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +34 -45
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +139 -17
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +116 -148
- package/dist/radio-group.cjs +1 -1
- package/dist/radio-group.js +90 -146
- package/dist/rating.cjs +1 -1
- package/dist/rating.d.ts +80 -13
- package/dist/rating.d.ts.map +1 -1
- package/dist/rating.js +70 -65
- package/dist/relative-date.cjs +1 -0
- package/dist/relative-date.d.ts +65 -0
- package/dist/relative-date.d.ts.map +1 -0
- package/dist/relative-date.js +112 -0
- package/dist/resizable.cjs +1 -1
- package/dist/resizable.d.ts +39 -23
- package/dist/resizable.d.ts.map +1 -1
- package/dist/resizable.js +42 -44
- package/dist/result-count.cjs +1 -0
- package/dist/result-count.d.ts +110 -0
- package/dist/result-count.d.ts.map +1 -0
- package/dist/result-count.js +49 -0
- package/dist/route-progress.cjs +1 -1
- package/dist/route-progress.js +58 -102
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +9 -1
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +44 -79
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +20 -10
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +132 -236
- package/dist/separator.cjs +1 -1
- package/dist/separator.js +90 -78
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +86 -7
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +275 -235
- package/dist/single-select-filter.cjs +1 -0
- package/dist/single-select-filter.d.ts +113 -0
- package/dist/single-select-filter.d.ts.map +1 -0
- package/dist/single-select-filter.js +224 -0
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.js +24 -38
- package/dist/slider.cjs +1 -1
- package/dist/slider.js +51 -81
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +113 -137
- package/dist/spinner.cjs +1 -1
- package/dist/spinner.js +22 -31
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +1 -1
- package/dist/split-layout.js +53 -102
- package/dist/status.cjs +1 -0
- package/dist/status.d.ts +51 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +60 -0
- package/dist/stepper.cjs +1 -1
- package/dist/stepper.js +184 -316
- package/dist/switch.cjs +1 -1
- package/dist/switch.js +17 -32
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +127 -13
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +170 -192
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +12 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +123 -146
- package/dist/text-reveal-motion.cjs +1 -1
- package/dist/text-reveal-motion.js +307 -363
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +23 -36
- package/dist/toggle-group.cjs +1 -1
- package/dist/toggle-group.js +43 -62
- package/dist/toggle.cjs +1 -1
- package/dist/toggle.js +34 -46
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts +38 -36
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +175 -78
- package/dist/typography-heading.cjs +1 -1
- package/dist/typography-heading.js +25 -61
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +1 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +27 -57
- package/dist/typography.cjs +1 -1
- package/dist/typography.d.ts +1 -1
- package/dist/typography.js +132 -340
- package/package.json +45 -46
- package/src/blocks/empty-state.tsx +42 -21
- package/src/blocks/progress-state.tsx +2 -2
- package/src/blocks/sidebar.tsx +111 -32
- package/src/components/accordion.tsx +1 -1
- package/src/components/alert-dialog.tsx +52 -5
- package/src/components/alert.tsx +16 -8
- package/src/components/badge.tsx +152 -3
- package/src/components/banner.tsx +288 -0
- package/src/components/brand-illustration-motif.tsx +1 -1
- package/src/components/breadcrumb.tsx +1 -1
- package/src/components/button.tsx +8 -6
- package/src/components/calendar.tsx +155 -9
- package/src/components/card.tsx +266 -26
- package/src/components/carousel.tsx +4 -1
- package/src/components/chart.tsx +664 -42
- package/src/components/checkbox.tsx +2 -2
- package/src/components/collapsible.tsx +4 -1
- package/src/components/combobox.tsx +42 -9
- package/src/components/command.tsx +10 -11
- package/src/components/context-menu.tsx +4 -4
- package/src/components/data-table.tsx +1363 -398
- package/src/components/date-picker.tsx +31 -4
- package/src/components/delta.tsx +217 -0
- package/src/components/drawer.tsx +5 -5
- package/src/components/dropdown-menu.tsx +4 -4
- package/src/components/field.tsx +36 -15
- package/src/components/global-layout.tsx +1 -1
- package/src/components/grid.tsx +32 -1
- package/src/components/info-tooltip.tsx +94 -0
- package/src/components/input-chip.tsx +52 -8
- package/src/components/input-group.tsx +247 -12
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input-password.tsx +29 -11
- package/src/components/input.tsx +11 -2
- package/src/components/list.tsx +15 -3
- package/src/components/logo-mark.tsx +345 -0
- package/src/components/map.tsx +18 -20
- package/src/components/media-viewer.tsx +908 -0
- package/src/components/multi-select-filter.tsx +1046 -0
- package/src/components/navigation-menu.tsx +2 -2
- package/src/components/pagination.tsx +86 -26
- package/src/components/progress.tsx +281 -54
- package/src/components/rating.tsx +200 -74
- package/src/components/relative-date.tsx +238 -0
- package/src/components/resizable.tsx +86 -33
- package/src/components/result-count.tsx +253 -0
- package/src/components/scroll-area.tsx +31 -5
- package/src/components/select.tsx +37 -7
- package/src/components/sheet.tsx +252 -6
- package/src/components/single-select-filter.tsx +538 -0
- package/src/components/slider.tsx +2 -2
- package/src/components/sonner.tsx +16 -5
- package/src/components/split-layout.tsx +2 -2
- package/src/components/status.tsx +162 -0
- package/src/components/switch.tsx +1 -1
- package/src/components/table.tsx +305 -73
- package/src/components/tabs.tsx +94 -46
- package/src/components/textarea.tsx +21 -3
- package/src/components/toggle.tsx +2 -2
- package/src/components/tooltip.tsx +431 -68
- package/src/components/typography-text.tsx +1 -2
- package/src/components/typography.tsx +1 -1
- package/src/hooks/use-breakpoint.ts +2 -1
- package/src/hooks/use-filter-search-params.ts +302 -0
- package/src/index.ts +11 -0
- package/src/lib/block-illustration.tsx +5 -1
- package/src/lib/compose-event-handlers.ts +14 -0
- package/src/lib/download-file.ts +61 -0
- package/src/lib/empty-chip.tsx +52 -0
- package/src/lib/field-aria.tsx +97 -0
- package/src/lib/image-file-info.ts +102 -0
- package/src/lib/media-viewer-content.tsx +1587 -0
- package/src/lib/media-viewer-internal.tsx +191 -0
- package/src/lib/media-viewer-motion.ts +120 -0
- package/src/lib/motion.ts +9 -0
- package/src/lib/table-internal.ts +74 -0
- package/src/lib/use-controllable.ts +43 -0
- package/src/lib/utils.ts +1 -0
- package/src/lib/empty-chip.ts +0 -24
|
@@ -103,6 +103,13 @@ export interface InputChipProps {
|
|
|
103
103
|
defaultValue?: string[];
|
|
104
104
|
/** Callback when value changes */
|
|
105
105
|
onValueChange?: (value: string[]) => void;
|
|
106
|
+
/**
|
|
107
|
+
* Synchronous validation hook called before a typed value is added.
|
|
108
|
+
* Return `false` to reject the add — the typed text stays in the input
|
|
109
|
+
* so the user can correct it. Any other return (including `undefined`)
|
|
110
|
+
* lets the add proceed.
|
|
111
|
+
*/
|
|
112
|
+
onBeforeAdd?: (item: string) => boolean | void;
|
|
106
113
|
/** Disabled state */
|
|
107
114
|
disabled?: boolean;
|
|
108
115
|
/** Allow duplicate values (default: false) */
|
|
@@ -136,6 +143,7 @@ function InputChip({
|
|
|
136
143
|
value: controlledValue,
|
|
137
144
|
defaultValue = [],
|
|
138
145
|
onValueChange: controlledOnValueChange,
|
|
146
|
+
onBeforeAdd,
|
|
139
147
|
disabled = false,
|
|
140
148
|
allowDuplicates = false,
|
|
141
149
|
children,
|
|
@@ -152,10 +160,12 @@ function InputChip({
|
|
|
152
160
|
|
|
153
161
|
const valueRef = React.useRef(value);
|
|
154
162
|
const controlledOnValueChangeRef = React.useRef(controlledOnValueChange);
|
|
163
|
+
const onBeforeAddRef = React.useRef(onBeforeAdd);
|
|
155
164
|
const disabledRef = React.useRef(disabled);
|
|
156
165
|
React.useLayoutEffect(() => {
|
|
157
166
|
valueRef.current = value;
|
|
158
167
|
controlledOnValueChangeRef.current = controlledOnValueChange;
|
|
168
|
+
onBeforeAddRef.current = onBeforeAdd;
|
|
159
169
|
disabledRef.current = disabled;
|
|
160
170
|
});
|
|
161
171
|
|
|
@@ -165,6 +175,7 @@ function InputChip({
|
|
|
165
175
|
chipRefs.current.length = value.length;
|
|
166
176
|
}
|
|
167
177
|
if (focusedChipIndex >= value.length) {
|
|
178
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- reset stale focus index; refactor tracked in DS-1070
|
|
168
179
|
setFocusedChipIndex(-1);
|
|
169
180
|
}
|
|
170
181
|
}, [value.length, focusedChipIndex]);
|
|
@@ -183,10 +194,11 @@ function InputChip({
|
|
|
183
194
|
(item: string) => {
|
|
184
195
|
if (disabledRef.current) return;
|
|
185
196
|
const trimmed = item.trim();
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
if (!trimmed) return;
|
|
198
|
+
if (onBeforeAddRef.current?.(trimmed) === false) return;
|
|
199
|
+
if (!allowDuplicates && valueRef.current.includes(trimmed)) return;
|
|
200
|
+
onValueChange([...valueRef.current, trimmed]);
|
|
201
|
+
setInputValue("");
|
|
190
202
|
},
|
|
191
203
|
[allowDuplicates, onValueChange]
|
|
192
204
|
);
|
|
@@ -276,7 +288,7 @@ const inputStyles = [
|
|
|
276
288
|
"bg-transparent",
|
|
277
289
|
"border-0 outline-none",
|
|
278
290
|
// Typography
|
|
279
|
-
"text-
|
|
291
|
+
"text-field",
|
|
280
292
|
"text-foreground",
|
|
281
293
|
// Placeholder
|
|
282
294
|
"placeholder:text-muted-foreground",
|
|
@@ -325,13 +337,35 @@ export interface InputChipInputProps
|
|
|
325
337
|
* ID of element that labels the input
|
|
326
338
|
*/
|
|
327
339
|
"aria-labelledby"?: string;
|
|
340
|
+
/**
|
|
341
|
+
* ID(s) of elements that describe the input (hint text, error message).
|
|
342
|
+
* Passed to the inner text input for screen-reader announcement.
|
|
343
|
+
*/
|
|
344
|
+
"aria-describedby"?: string;
|
|
345
|
+
/**
|
|
346
|
+
* Marks the input as invalid for assistive technology.
|
|
347
|
+
* Also derived from the `error` prop — either source triggers the
|
|
348
|
+
* invalid state on the inner text input.
|
|
349
|
+
*/
|
|
350
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
351
|
+
/**
|
|
352
|
+
* Ref to the wrapper div (the bordered container).
|
|
353
|
+
* Use when you need to anchor a Popover or measure the container box.
|
|
354
|
+
* The primary `ref` now points to the inner text input for form
|
|
355
|
+
* integration (focus, ARIA).
|
|
356
|
+
*/
|
|
357
|
+
wrapperRef?: React.Ref<HTMLDivElement>;
|
|
328
358
|
}
|
|
329
359
|
|
|
330
360
|
/**
|
|
331
361
|
* Input container with bordered styling.
|
|
332
362
|
* Place Chip components or InputChipItems inside as children.
|
|
363
|
+
*
|
|
364
|
+
* The forwarded `ref` points to the inner text input (for focus, ARIA
|
|
365
|
+
* wiring, and form integration). Use `wrapperRef` when you need the
|
|
366
|
+
* bordered container element (e.g. for Popover anchoring).
|
|
333
367
|
*/
|
|
334
|
-
const InputChipInput = React.forwardRef<
|
|
368
|
+
const InputChipInput = React.forwardRef<HTMLInputElement, InputChipInputProps>(
|
|
335
369
|
(
|
|
336
370
|
{
|
|
337
371
|
className,
|
|
@@ -343,6 +377,9 @@ const InputChipInput = React.forwardRef<HTMLDivElement, InputChipInputProps>(
|
|
|
343
377
|
inputId,
|
|
344
378
|
"aria-label": ariaLabel,
|
|
345
379
|
"aria-labelledby": ariaLabelledby,
|
|
380
|
+
"aria-describedby": ariaDescribedby,
|
|
381
|
+
"aria-invalid": ariaInvalid,
|
|
382
|
+
wrapperRef,
|
|
346
383
|
children,
|
|
347
384
|
...props
|
|
348
385
|
},
|
|
@@ -353,6 +390,11 @@ const InputChipInput = React.forwardRef<HTMLDivElement, InputChipInputProps>(
|
|
|
353
390
|
const { value, disabled } = useInputChipValue();
|
|
354
391
|
const { inputValue } = useInputChipInput();
|
|
355
392
|
|
|
393
|
+
// Expose the inner text input through the consumer's ref
|
|
394
|
+
React.useImperativeHandle(ref, () => inputRef.current!, [inputRef]);
|
|
395
|
+
|
|
396
|
+
const hasError = error || ariaInvalid === true || ariaInvalid === "true";
|
|
397
|
+
|
|
356
398
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
357
399
|
setInputValue(e.target.value);
|
|
358
400
|
};
|
|
@@ -382,8 +424,8 @@ const InputChipInput = React.forwardRef<HTMLDivElement, InputChipInputProps>(
|
|
|
382
424
|
|
|
383
425
|
return (
|
|
384
426
|
<div
|
|
385
|
-
ref={
|
|
386
|
-
className={cn(inputChipInputVariants({ error }), className)}
|
|
427
|
+
ref={wrapperRef}
|
|
428
|
+
className={cn(inputChipInputVariants({ error: hasError }), className)}
|
|
387
429
|
data-hook={dataHook}
|
|
388
430
|
data-slot="input-chip"
|
|
389
431
|
data-tracking-el={trackingEl}
|
|
@@ -393,6 +435,8 @@ const InputChipInput = React.forwardRef<HTMLDivElement, InputChipInputProps>(
|
|
|
393
435
|
{children}
|
|
394
436
|
<input
|
|
395
437
|
ref={inputRef as React.RefObject<HTMLInputElement>}
|
|
438
|
+
aria-describedby={ariaDescribedby || undefined}
|
|
439
|
+
aria-invalid={hasError ? "true" : undefined}
|
|
396
440
|
aria-label={ariaLabel}
|
|
397
441
|
aria-labelledby={ariaLabelledby}
|
|
398
442
|
className={cn(inputStyles)}
|
|
@@ -3,10 +3,38 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
|
+
import { X } from "@brightlocal/icons";
|
|
6
7
|
|
|
7
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
9
|
import { Input, type InputProps } from "./input";
|
|
9
10
|
|
|
11
|
+
interface InputGroupContextValue {
|
|
12
|
+
/** Snapshot of the composed input's DOM state, kept fresh by InputGroupInput. */
|
|
13
|
+
inputState: { hasValue: boolean; disabled: boolean };
|
|
14
|
+
/** Re-reads the composed input into `inputState`; cheap and safe to call often. */
|
|
15
|
+
syncInputState: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Registers the composed input element with the group. A callback rather
|
|
18
|
+
* than a ref write because context values are immutable to the compiler.
|
|
19
|
+
*/
|
|
20
|
+
registerInput: (node: HTMLInputElement | null) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Registers the input's clear routine (owned by InputGroupInput, which
|
|
23
|
+
* holds the consumer's `onChange`).
|
|
24
|
+
*/
|
|
25
|
+
registerClearHandler: (
|
|
26
|
+
fn: ((event: React.SyntheticEvent) => void) | null
|
|
27
|
+
) => void;
|
|
28
|
+
/** Clears the composed input through its React onChange and refocuses it. */
|
|
29
|
+
clearInput: (event: React.SyntheticEvent) => void;
|
|
30
|
+
/** The composed input element. */
|
|
31
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const InputGroupContext = React.createContext<InputGroupContextValue | null>(
|
|
35
|
+
null
|
|
36
|
+
);
|
|
37
|
+
|
|
10
38
|
const inputGroupVariants = cva(
|
|
11
39
|
"relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50",
|
|
12
40
|
{
|
|
@@ -58,16 +86,70 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
|
|
|
58
86
|
{ className, size, error, dataHook, trackingEl, trackingLabel, ...props },
|
|
59
87
|
ref
|
|
60
88
|
) => {
|
|
89
|
+
const [inputState, setInputState] = React.useState({
|
|
90
|
+
hasValue: false,
|
|
91
|
+
disabled: false,
|
|
92
|
+
});
|
|
93
|
+
const inputRef = React.useRef<HTMLInputElement | null>(null);
|
|
94
|
+
const syncInputState = React.useCallback(() => {
|
|
95
|
+
const input = inputRef.current;
|
|
96
|
+
// readOnly counts as disabled here: a field the user cannot edit must
|
|
97
|
+
// not offer a clear affordance either.
|
|
98
|
+
const next = {
|
|
99
|
+
hasValue: !!input && input.value.length > 0,
|
|
100
|
+
disabled: !!input && (input.disabled || input.readOnly),
|
|
101
|
+
};
|
|
102
|
+
setInputState((prev) =>
|
|
103
|
+
prev.hasValue === next.hasValue && prev.disabled === next.disabled
|
|
104
|
+
? prev
|
|
105
|
+
: next
|
|
106
|
+
);
|
|
107
|
+
}, []);
|
|
108
|
+
const registerInput = React.useCallback((node: HTMLInputElement | null) => {
|
|
109
|
+
inputRef.current = node;
|
|
110
|
+
}, []);
|
|
111
|
+
const clearHandlerRef = React.useRef<
|
|
112
|
+
((event: React.SyntheticEvent) => void) | null
|
|
113
|
+
>(null);
|
|
114
|
+
const registerClearHandler = React.useCallback(
|
|
115
|
+
(fn: ((event: React.SyntheticEvent) => void) | null) => {
|
|
116
|
+
clearHandlerRef.current = fn;
|
|
117
|
+
},
|
|
118
|
+
[]
|
|
119
|
+
);
|
|
120
|
+
const clearInput = React.useCallback((event: React.SyntheticEvent) => {
|
|
121
|
+
clearHandlerRef.current?.(event);
|
|
122
|
+
}, []);
|
|
123
|
+
const contextValue = React.useMemo(
|
|
124
|
+
() => ({
|
|
125
|
+
inputState,
|
|
126
|
+
syncInputState,
|
|
127
|
+
registerInput,
|
|
128
|
+
registerClearHandler,
|
|
129
|
+
clearInput,
|
|
130
|
+
inputRef,
|
|
131
|
+
}),
|
|
132
|
+
[
|
|
133
|
+
inputState,
|
|
134
|
+
syncInputState,
|
|
135
|
+
registerInput,
|
|
136
|
+
registerClearHandler,
|
|
137
|
+
clearInput,
|
|
138
|
+
]
|
|
139
|
+
);
|
|
140
|
+
|
|
61
141
|
return (
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
142
|
+
<InputGroupContext.Provider value={contextValue}>
|
|
143
|
+
<div
|
|
144
|
+
ref={ref}
|
|
145
|
+
className={cn(inputGroupVariants({ size, error }), className)}
|
|
146
|
+
data-hook={dataHook}
|
|
147
|
+
data-slot="input-group"
|
|
148
|
+
data-tracking-el={trackingEl}
|
|
149
|
+
data-tracking-label={trackingLabel}
|
|
150
|
+
{...props}
|
|
151
|
+
/>
|
|
152
|
+
</InputGroupContext.Provider>
|
|
71
153
|
);
|
|
72
154
|
}
|
|
73
155
|
);
|
|
@@ -81,10 +163,73 @@ type InputGroupInputProps = Omit<
|
|
|
81
163
|
const InputGroupInput = React.forwardRef<
|
|
82
164
|
HTMLInputElement,
|
|
83
165
|
InputGroupInputProps
|
|
84
|
-
>(({ className, ...props }, ref) => {
|
|
166
|
+
>(({ className, onChange, ...props }, ref) => {
|
|
167
|
+
const context = React.useContext(InputGroupContext);
|
|
168
|
+
const localRef = React.useRef<HTMLInputElement | null>(null);
|
|
169
|
+
|
|
170
|
+
const registerInput = context?.registerInput;
|
|
171
|
+
const setRefs = React.useCallback(
|
|
172
|
+
(node: HTMLInputElement | null) => {
|
|
173
|
+
localRef.current = node;
|
|
174
|
+
registerInput?.(node);
|
|
175
|
+
if (typeof ref === "function") ref(node);
|
|
176
|
+
else if (ref) ref.current = node;
|
|
177
|
+
},
|
|
178
|
+
[registerInput, ref]
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Re-read the DOM after every render (no dep array): covers mount
|
|
182
|
+
// (defaultValue), controlled updates, disabled/readOnly toggles, and a
|
|
183
|
+
// controlled parent rejecting or transforming a change — React restores
|
|
184
|
+
// the DOM value on that render and this re-read follows it.
|
|
185
|
+
const syncInputState = context?.syncInputState;
|
|
186
|
+
React.useEffect(() => {
|
|
187
|
+
syncInputState?.();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// form.reset() restores defaultValue without firing input/change events;
|
|
191
|
+
// re-read once the reset steps have run.
|
|
192
|
+
React.useEffect(() => {
|
|
193
|
+
const form = localRef.current?.form;
|
|
194
|
+
if (!form || !syncInputState) return;
|
|
195
|
+
const handleReset = () => queueMicrotask(syncInputState);
|
|
196
|
+
form.addEventListener("reset", handleReset);
|
|
197
|
+
return () => form.removeEventListener("reset", handleReset);
|
|
198
|
+
}, [syncInputState]);
|
|
199
|
+
|
|
200
|
+
// The clear routine lives here because this component holds the consumer's
|
|
201
|
+
// onChange. Assigning through the element keeps React's value tracker in
|
|
202
|
+
// sync, and calling onChange directly with a retargeted event (instead of
|
|
203
|
+
// dispatching a DOM input event) keeps React's controlled-input restoration
|
|
204
|
+
// out of the picture — a dispatched event raced it and could resurrect the
|
|
205
|
+
// cleared value. Re-registered every render so the closure stays fresh.
|
|
206
|
+
const registerClearHandler = context?.registerClearHandler;
|
|
207
|
+
React.useEffect(() => {
|
|
208
|
+
registerClearHandler?.((event: React.SyntheticEvent) => {
|
|
209
|
+
const input = localRef.current;
|
|
210
|
+
if (!input) return;
|
|
211
|
+
input.value = "";
|
|
212
|
+
const changeEvent = Object.create(event, {
|
|
213
|
+
target: { value: input, enumerable: true },
|
|
214
|
+
currentTarget: { value: input, enumerable: true },
|
|
215
|
+
}) as React.ChangeEvent<HTMLInputElement>;
|
|
216
|
+
onChange?.(changeEvent);
|
|
217
|
+
syncInputState?.();
|
|
218
|
+
input.focus();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
return () => registerClearHandler?.(null);
|
|
223
|
+
}, [registerClearHandler]);
|
|
224
|
+
|
|
225
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
226
|
+
syncInputState?.();
|
|
227
|
+
onChange?.(event);
|
|
228
|
+
};
|
|
229
|
+
|
|
85
230
|
return (
|
|
86
231
|
<Input
|
|
87
|
-
ref={
|
|
232
|
+
ref={setRefs}
|
|
88
233
|
className={cn(
|
|
89
234
|
// Override border and focus styles since InputGroup handles them
|
|
90
235
|
"border-0 focus-visible:border-0 focus-visible:shadow-[none]",
|
|
@@ -92,6 +237,7 @@ const InputGroupInput = React.forwardRef<
|
|
|
92
237
|
className
|
|
93
238
|
)}
|
|
94
239
|
dataHook="input-group-input"
|
|
240
|
+
onChange={handleChange}
|
|
95
241
|
{...props}
|
|
96
242
|
/>
|
|
97
243
|
);
|
|
@@ -139,7 +285,7 @@ const inputGroupButtonVariants = cva(
|
|
|
139
285
|
"inline-flex items-center justify-center gap-2",
|
|
140
286
|
"text-label transition-colors duration-fast ease-out",
|
|
141
287
|
"outline-none focus-visible:shadow-default rounded-sm",
|
|
142
|
-
"disabled:pointer-events-none disabled:opacity-50",
|
|
288
|
+
"cursor-pointer disabled:pointer-events-none disabled:opacity-50",
|
|
143
289
|
"text-muted-foreground hover:text-foreground",
|
|
144
290
|
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
145
291
|
],
|
|
@@ -195,11 +341,99 @@ const InputGroupButton = React.forwardRef<
|
|
|
195
341
|
});
|
|
196
342
|
InputGroupButton.displayName = "InputGroupButton";
|
|
197
343
|
|
|
344
|
+
interface InputGroupClearProps extends Omit<
|
|
345
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
346
|
+
"onClick" | "children"
|
|
347
|
+
> {
|
|
348
|
+
/**
|
|
349
|
+
* Accessible label for the clear button.
|
|
350
|
+
* @default "Clear search"
|
|
351
|
+
*/
|
|
352
|
+
clearSearchAriaLabel?: string;
|
|
353
|
+
/**
|
|
354
|
+
* Called after the input has been cleared.
|
|
355
|
+
*/
|
|
356
|
+
onClear?: () => void;
|
|
357
|
+
/**
|
|
358
|
+
* Data hook for automated testing.
|
|
359
|
+
* @default "input-group-clear"
|
|
360
|
+
*/
|
|
361
|
+
dataHook?: string;
|
|
362
|
+
/**
|
|
363
|
+
* Tracking element identifier for analytics
|
|
364
|
+
*/
|
|
365
|
+
trackingEl?: string;
|
|
366
|
+
/**
|
|
367
|
+
* Tracking label for analytics context
|
|
368
|
+
*/
|
|
369
|
+
trackingLabel?: string;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Opt-in clear button for InputGroup. Renders only while the composed
|
|
374
|
+
* `InputGroupInput` holds content and is editable (not disabled or
|
|
375
|
+
* read-only); clicking it clears the input (firing the input's `onChange`,
|
|
376
|
+
* so controlled and uncontrolled usage both work) and returns focus to it.
|
|
377
|
+
*/
|
|
378
|
+
const InputGroupClear = React.forwardRef<
|
|
379
|
+
HTMLButtonElement,
|
|
380
|
+
InputGroupClearProps
|
|
381
|
+
>(
|
|
382
|
+
(
|
|
383
|
+
{
|
|
384
|
+
className,
|
|
385
|
+
clearSearchAriaLabel,
|
|
386
|
+
onClear,
|
|
387
|
+
dataHook,
|
|
388
|
+
trackingEl,
|
|
389
|
+
trackingLabel,
|
|
390
|
+
...props
|
|
391
|
+
},
|
|
392
|
+
ref
|
|
393
|
+
) => {
|
|
394
|
+
const context = React.useContext(InputGroupContext);
|
|
395
|
+
if (!context) {
|
|
396
|
+
throw new Error("InputGroupClear must be used within <InputGroup>");
|
|
397
|
+
}
|
|
398
|
+
const { inputState, clearInput } = context;
|
|
399
|
+
if (!inputState.hasValue || inputState.disabled) return null;
|
|
400
|
+
|
|
401
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
402
|
+
// Delegates to InputGroupInput's registered routine: it clears the
|
|
403
|
+
// element, fires the consumer's onChange, and refocuses the input.
|
|
404
|
+
clearInput(event);
|
|
405
|
+
onClear?.();
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
return (
|
|
409
|
+
<InputGroupButton
|
|
410
|
+
ref={ref}
|
|
411
|
+
aria-label={clearSearchAriaLabel ?? "Clear search"}
|
|
412
|
+
// The button is the rendered root: alignment lives here so the
|
|
413
|
+
// consumer's className, ref, and data attributes reach the real element.
|
|
414
|
+
// Fully rounded to match Button's icon shape.
|
|
415
|
+
className={cn("mr-1 ml-auto shrink-0 rounded-full", className)}
|
|
416
|
+
data-hook={dataHook ?? "input-group-clear"}
|
|
417
|
+
data-slot="input-group-clear"
|
|
418
|
+
data-tracking-el={trackingEl}
|
|
419
|
+
data-tracking-label={trackingLabel}
|
|
420
|
+
size="icon-xs"
|
|
421
|
+
onClick={handleClick}
|
|
422
|
+
{...props}
|
|
423
|
+
>
|
|
424
|
+
<X size={14} />
|
|
425
|
+
</InputGroupButton>
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
);
|
|
429
|
+
InputGroupClear.displayName = "InputGroupClear";
|
|
430
|
+
|
|
198
431
|
export {
|
|
199
432
|
InputGroup,
|
|
200
433
|
InputGroupInput,
|
|
201
434
|
InputGroupAddon,
|
|
202
435
|
InputGroupButton,
|
|
436
|
+
InputGroupClear,
|
|
203
437
|
inputGroupVariants,
|
|
204
438
|
inputGroupButtonVariants,
|
|
205
439
|
};
|
|
@@ -208,4 +442,5 @@ export type {
|
|
|
208
442
|
InputGroupInputProps,
|
|
209
443
|
InputGroupAddonProps,
|
|
210
444
|
InputGroupButtonProps,
|
|
445
|
+
InputGroupClearProps,
|
|
211
446
|
};
|
|
@@ -137,7 +137,7 @@ function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
|
|
|
137
137
|
// Base styles
|
|
138
138
|
"relative flex h-9 w-9 items-center justify-center",
|
|
139
139
|
"border-input bg-background border-y border-r",
|
|
140
|
-
"text-foreground duration-fast text-
|
|
140
|
+
"text-foreground duration-fast text-field transition-[border-color,box-shadow] ease-out outline-none",
|
|
141
141
|
"first:rounded-l-md first:border-l last:rounded-r-md",
|
|
142
142
|
// Focus state
|
|
143
143
|
"data-[active=true]:border-ring data-[active=true]:z-10",
|
|
@@ -26,23 +26,41 @@ type DefaultPasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
|
|
|
26
26
|
* Configuration for a single strength level
|
|
27
27
|
*/
|
|
28
28
|
interface StrengthLevelConfig {
|
|
29
|
+
/** Text shown beside the bar for this level, e.g. `"Weak"` */
|
|
29
30
|
label: string;
|
|
31
|
+
/** Bar fill as a percentage, 0–100 */
|
|
30
32
|
value: number;
|
|
33
|
+
/**
|
|
34
|
+
* Background utility for the bar fill. Use the Progress bar palette
|
|
35
|
+
* (`bg-score-strong`, `bg-score-poor`, `bg-score-weak`, `bg-score-moderate`,
|
|
36
|
+
* `bg-muted`) so custom levels stay consistent with Progress (DS-773).
|
|
37
|
+
*/
|
|
31
38
|
color: string;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Default strength levels configuration
|
|
43
|
+
*
|
|
44
|
+
* DESIGN DECISION (DS-293, kept in DS-666): every level shares one fill. The
|
|
45
|
+
* bar's length and the label ("Weak" … "Great") carry the strength, so colour
|
|
46
|
+
* is never the only indicator of state. Per-level red/amber/green would also
|
|
47
|
+
* have to come from the alert-surface tokens (`success-background` is green-200
|
|
48
|
+
* in light, green-950 in dark) — tints tuned as a backdrop, which read as a
|
|
49
|
+
* washed-out or near-black 8px bar.
|
|
50
|
+
*
|
|
51
|
+
* The fill is `score-strong` — the same fill the green Progress bar uses
|
|
52
|
+
* (the score scale, DS-774). The meter IS a Progress, so its green must match,
|
|
53
|
+
* and the track beneath is Progress's own `score-strong/20`.
|
|
36
54
|
*/
|
|
37
55
|
const DEFAULT_STRENGTH_LEVELS: Record<
|
|
38
56
|
DefaultPasswordStrength,
|
|
39
57
|
StrengthLevelConfig
|
|
40
58
|
> = {
|
|
41
|
-
meter: { label: "Meter", value: 0, color: "bg-
|
|
42
|
-
weak: { label: "Weak", value: 25, color: "bg-
|
|
43
|
-
ok: { label: "Ok", value: 50, color: "bg-
|
|
44
|
-
good: { label: "Good", value: 75, color: "bg-
|
|
45
|
-
great: { label: "Great", value: 100, color: "bg-
|
|
59
|
+
meter: { label: "Meter", value: 0, color: "bg-score-strong" },
|
|
60
|
+
weak: { label: "Weak", value: 25, color: "bg-score-strong" },
|
|
61
|
+
ok: { label: "Ok", value: 50, color: "bg-score-strong" },
|
|
62
|
+
good: { label: "Good", value: 75, color: "bg-score-strong" },
|
|
63
|
+
great: { label: "Great", value: 100, color: "bg-score-strong" },
|
|
46
64
|
};
|
|
47
65
|
|
|
48
66
|
/**
|
|
@@ -161,9 +179,9 @@ export interface InputPasswordProps<
|
|
|
161
179
|
* @example
|
|
162
180
|
* strengthLevels={{
|
|
163
181
|
* empty: { label: "Enter password", value: 0, color: "bg-muted" },
|
|
164
|
-
* slow: { label: "Slow", value: 33, color: "bg-
|
|
165
|
-
* medium: { label: "Medium", value: 66, color: "bg-
|
|
166
|
-
* fast: { label: "Fast", value: 100, color: "bg-
|
|
182
|
+
* slow: { label: "Slow", value: 33, color: "bg-score-poor" },
|
|
183
|
+
* medium: { label: "Medium", value: 66, color: "bg-score-moderate" },
|
|
184
|
+
* fast: { label: "Fast", value: 100, color: "bg-score-strong" },
|
|
167
185
|
* }}
|
|
168
186
|
*/
|
|
169
187
|
strengthLevels?: Record<T, StrengthLevelConfig>;
|
|
@@ -205,9 +223,9 @@ export interface InputPasswordProps<
|
|
|
205
223
|
* dataHook="password"
|
|
206
224
|
* strengthLevels={{
|
|
207
225
|
* empty: { label: "Enter password", value: 0, color: "bg-muted" },
|
|
208
|
-
* slow: { label: "Slow", value: 33, color: "bg-
|
|
209
|
-
* medium: { label: "Medium", value: 66, color: "bg-
|
|
210
|
-
* fast: { label: "Fast", value: 100, color: "bg-
|
|
226
|
+
* slow: { label: "Slow", value: 33, color: "bg-score-poor" },
|
|
227
|
+
* medium: { label: "Medium", value: 66, color: "bg-score-moderate" },
|
|
228
|
+
* fast: { label: "Fast", value: 100, color: "bg-score-strong" },
|
|
211
229
|
* }}
|
|
212
230
|
* calculateStrength={(password) => {
|
|
213
231
|
* if (!password) return "empty";
|
package/src/components/input.tsx
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
5
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
6
|
+
import { useFieldDescribedBy } from "../lib/field-aria";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Shared input variant styles
|
|
@@ -16,7 +17,7 @@ export const inputVariants = cva(
|
|
|
16
17
|
"border border-input bg-background rounded-sm",
|
|
17
18
|
"outline-none transition-[border-color,box-shadow,background-color] duration-fast ease-out",
|
|
18
19
|
// Typography
|
|
19
|
-
"text-
|
|
20
|
+
"text-field",
|
|
20
21
|
"text-foreground",
|
|
21
22
|
"overflow-hidden text-ellipsis",
|
|
22
23
|
// States - Focus
|
|
@@ -101,6 +102,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
101
102
|
error,
|
|
102
103
|
trackingEl,
|
|
103
104
|
trackingLabel,
|
|
105
|
+
"aria-describedby": ariaDescribedBy,
|
|
104
106
|
...props
|
|
105
107
|
},
|
|
106
108
|
ref
|
|
@@ -111,14 +113,21 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
111
113
|
props["aria-invalid"] === true ||
|
|
112
114
|
props["aria-invalid"] === "true";
|
|
113
115
|
|
|
116
|
+
// Inside a Field, point aria-describedby at the FieldError and
|
|
117
|
+
// FieldDescription automatically; a hand-wired value is kept and merged.
|
|
118
|
+
const describedBy = useFieldDescribedBy(ariaDescribedBy);
|
|
119
|
+
|
|
114
120
|
return (
|
|
115
121
|
<input
|
|
116
122
|
ref={ref}
|
|
123
|
+
aria-describedby={describedBy}
|
|
117
124
|
aria-invalid={hasError ? "true" : undefined}
|
|
118
125
|
className={cn(
|
|
119
126
|
inputVariants({ hasIcon, hasSecondaryIcon }),
|
|
127
|
+
// scroll-mb-16 reserves room for a two-line error message under the
|
|
128
|
+
// field, so a phone keyboard scrolls the message into view with it
|
|
120
129
|
hasError &&
|
|
121
|
-
"border-destructive-40 focus-visible:border-destructive-40 focus-visible:shadow-destructive",
|
|
130
|
+
"border-destructive-40 focus-visible:border-destructive-40 focus-visible:shadow-destructive scroll-mb-16",
|
|
122
131
|
className
|
|
123
132
|
)}
|
|
124
133
|
data-hook={dataHook}
|
package/src/components/list.tsx
CHANGED
|
@@ -12,7 +12,6 @@ import { Skeleton } from "@brightlocal/ui-components/skeleton";
|
|
|
12
12
|
const itemVariants = cva(
|
|
13
13
|
[
|
|
14
14
|
"flex",
|
|
15
|
-
"items-center",
|
|
16
15
|
"gap-4",
|
|
17
16
|
"rounded-lg",
|
|
18
17
|
"py-2",
|
|
@@ -26,13 +25,18 @@ const itemVariants = cva(
|
|
|
26
25
|
variants: {
|
|
27
26
|
variant: {
|
|
28
27
|
default: [],
|
|
29
|
-
filled: ["bg-
|
|
28
|
+
filled: ["bg-muted"],
|
|
30
29
|
outline: ["bg-background", "border", "border-border"],
|
|
31
30
|
loading: ["p-0"],
|
|
32
31
|
},
|
|
32
|
+
align: {
|
|
33
|
+
center: ["items-center"],
|
|
34
|
+
start: ["items-start"],
|
|
35
|
+
},
|
|
33
36
|
},
|
|
34
37
|
defaultVariants: {
|
|
35
38
|
variant: "filled",
|
|
39
|
+
align: "center",
|
|
36
40
|
},
|
|
37
41
|
}
|
|
38
42
|
);
|
|
@@ -115,6 +119,13 @@ export type ItemProps = React.ComponentProps<"li"> & {
|
|
|
115
119
|
* @default "filled"
|
|
116
120
|
*/
|
|
117
121
|
variant?: "default" | "filled" | "outline" | "loading";
|
|
122
|
+
/**
|
|
123
|
+
* Cross-axis alignment of the row's children (media, content, actions).
|
|
124
|
+
* Use `"start"` when ItemMedia (icon, avatar, step number) should pin to the
|
|
125
|
+
* first line of multi-line content instead of centering vertically.
|
|
126
|
+
* @default "center"
|
|
127
|
+
*/
|
|
128
|
+
align?: "center" | "start";
|
|
118
129
|
/**
|
|
119
130
|
* Data hook for automated testing.
|
|
120
131
|
*/
|
|
@@ -139,6 +150,7 @@ const Item = React.forwardRef<HTMLLIElement, ItemProps>(
|
|
|
139
150
|
asChild = false,
|
|
140
151
|
className,
|
|
141
152
|
variant,
|
|
153
|
+
align,
|
|
142
154
|
dataHook,
|
|
143
155
|
trackingEl,
|
|
144
156
|
trackingLabel,
|
|
@@ -152,7 +164,7 @@ const Item = React.forwardRef<HTMLLIElement, ItemProps>(
|
|
|
152
164
|
return (
|
|
153
165
|
<Comp
|
|
154
166
|
ref={ref}
|
|
155
|
-
className={cn(itemVariants({ variant }), className)}
|
|
167
|
+
className={cn(itemVariants({ variant, align }), className)}
|
|
156
168
|
data-hook={dataHook}
|
|
157
169
|
data-slot="item"
|
|
158
170
|
data-tracking-el={trackingEl}
|