banhaten 0.5.0 → 0.6.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/CHANGELOG.md +177 -139
- package/CONTRIBUTING.md +46 -46
- package/README.md +192 -192
- package/SECURITY.md +15 -15
- package/banhaten.config.example.json +11 -11
- package/docs/design-spacing.md +13 -13
- package/docs/design-system/README.md +22 -22
- package/docs/design-system/adoption-quality-remediation.md +87 -87
- package/docs/design-system/agent-usage.md +13 -13
- package/docs/design-system/appearance-presets.md +189 -189
- package/docs/design-system/appearances/default.md +94 -94
- package/docs/design-system/appearances/rounded.md +95 -95
- package/docs/design-system/appearances/sharp.md +95 -95
- package/docs/design-system/component-docs-pattern.md +81 -81
- package/docs/design-system/component-implementation-ownership-audit.md +245 -245
- package/docs/design-system/component-quality-audit-2026-08-20.md +225 -225
- package/docs/design-system/component-showcase-consistency-report.md +219 -219
- package/docs/design-system/component-token-consistency-audit.md +173 -173
- package/docs/design-system/components/README.md +91 -90
- package/docs/design-system/components/accordion.md +52 -52
- package/docs/design-system/components/activity-feed.md +93 -93
- package/docs/design-system/components/activity-heatmap.md +56 -56
- package/docs/design-system/components/alert-dialog.md +71 -71
- package/docs/design-system/components/alert.md +103 -97
- package/docs/design-system/components/app-header.md +97 -0
- package/docs/design-system/components/aspect-ratio.md +45 -45
- package/docs/design-system/components/attribute.md +101 -89
- package/docs/design-system/components/autocomplete.md +75 -75
- package/docs/design-system/components/avatar.md +53 -53
- package/docs/design-system/components/badge.md +55 -55
- package/docs/design-system/components/banner.md +86 -86
- package/docs/design-system/components/breadcrumbs.md +181 -177
- package/docs/design-system/components/button-group.md +97 -97
- package/docs/design-system/components/button.md +80 -80
- package/docs/design-system/components/card.md +102 -88
- package/docs/design-system/components/carousel.md +46 -46
- package/docs/design-system/components/catalog-components.md +46 -46
- package/docs/design-system/components/checkbox.md +53 -53
- package/docs/design-system/components/collapsible.md +63 -63
- package/docs/design-system/components/command.md +61 -61
- package/docs/design-system/components/context-menu.md +45 -45
- package/docs/design-system/components/date-picker.md +80 -80
- package/docs/design-system/components/divider.md +102 -102
- package/docs/design-system/components/empty-state.md +56 -56
- package/docs/design-system/components/field.md +70 -70
- package/docs/design-system/components/file-upload.md +186 -186
- package/docs/design-system/components/hover-card.md +47 -47
- package/docs/design-system/components/icons.md +48 -48
- package/docs/design-system/components/input-group.md +57 -57
- package/docs/design-system/components/input-otp.md +56 -56
- package/docs/design-system/components/input.md +111 -109
- package/docs/design-system/components/item.md +58 -58
- package/docs/design-system/components/kbd.md +49 -49
- package/docs/design-system/components/label.md +49 -49
- package/docs/design-system/components/menu.md +94 -73
- package/docs/design-system/components/menubar.md +46 -46
- package/docs/design-system/components/modal.md +104 -104
- package/docs/design-system/components/native-select.md +53 -53
- package/docs/design-system/components/navigation-menu.md +49 -49
- package/docs/design-system/components/onboarding-step-list-item.md +81 -81
- package/docs/design-system/components/page-header.md +127 -93
- package/docs/design-system/components/pagination.md +56 -56
- package/docs/design-system/components/popover.md +59 -59
- package/docs/design-system/components/progress-slider.md +49 -49
- package/docs/design-system/components/progress.md +76 -76
- package/docs/design-system/components/radio-card.md +50 -50
- package/docs/design-system/components/radio-group.md +56 -56
- package/docs/design-system/components/resizable.md +43 -43
- package/docs/design-system/components/scroll-area.md +50 -50
- package/docs/design-system/components/segmented-control.md +54 -54
- package/docs/design-system/components/select.md +68 -64
- package/docs/design-system/components/sheet.md +66 -66
- package/docs/design-system/components/sidebar.md +167 -111
- package/docs/design-system/components/skeleton.md +74 -74
- package/docs/design-system/components/slideout.md +64 -64
- package/docs/design-system/components/slider.md +62 -62
- package/docs/design-system/components/social-button.md +49 -49
- package/docs/design-system/components/spinner.md +62 -62
- package/docs/design-system/components/steps.md +65 -65
- package/docs/design-system/components/table.md +499 -422
- package/docs/design-system/components/tabs.md +74 -59
- package/docs/design-system/components/tag.md +79 -79
- package/docs/design-system/components/textarea.md +49 -49
- package/docs/design-system/components/timeline.md +82 -82
- package/docs/design-system/components/toast.md +57 -57
- package/docs/design-system/components/toggle.md +80 -80
- package/docs/design-system/components/toolbar.md +89 -89
- package/docs/design-system/components/tooltip.md +92 -92
- package/docs/design-system/components/typography.md +18 -18
- package/docs/design-system/density-and-elevation.md +65 -65
- package/docs/design-system/design-system-test-missing-items.md +368 -368
- package/docs/design-system/direction-and-localization.md +23 -23
- package/docs/design-system/form-recipes.md +73 -73
- package/docs/design-system/gap-promotion-policy.md +21 -21
- package/docs/design-system/icons.md +74 -74
- package/docs/design-system/installation.md +70 -70
- package/docs/design-system/launch-comparison-shadcn.md +98 -98
- package/docs/design-system/registry-and-cli.md +64 -64
- package/docs/design-system/release-policy.md +30 -30
- package/docs/design-system/roadmap.md +14 -14
- package/docs/design-system/support-matrix.md +23 -23
- package/docs/design-system/tabs.md +54 -54
- package/docs/design-system/template-gap-audit.md +32 -32
- package/docs/design-system/templates.md +59 -59
- package/docs/design-system/token-governance.md +72 -72
- package/package.json +98 -98
- package/registry/component-contract.json +40 -40
- package/registry/components/accordion.tsx +155 -155
- package/registry/components/alert-dialog.tsx +297 -297
- package/registry/components/alert.tsx +309 -293
- package/registry/components/app-header.tsx +151 -0
- package/registry/components/aspect-ratio.tsx +30 -30
- package/registry/components/attribute.tsx +489 -454
- package/registry/components/autocomplete.tsx +598 -598
- package/registry/components/avatar.tsx +385 -385
- package/registry/components/badge.tsx +630 -629
- package/registry/components/button-group.tsx +565 -565
- package/registry/components/button.tsx +128 -127
- package/registry/components/card.tsx +651 -638
- package/registry/components/carousel.tsx +296 -296
- package/registry/components/chart.tsx +203 -203
- package/registry/components/checkbox.tsx +247 -247
- package/registry/components/collapsible.tsx +109 -109
- package/registry/components/command.tsx +208 -208
- package/registry/components/context-menu.tsx +236 -236
- package/registry/components/date-picker.tsx +1289 -1289
- package/registry/components/expanded/ActivityFeed.tsx +227 -227
- package/registry/components/expanded/ActivityHeatmap.tsx +64 -64
- package/registry/components/expanded/Banner.tsx +179 -179
- package/registry/components/expanded/Breadcrumbs.tsx +135 -131
- package/registry/components/expanded/CatalogComponentsShowcase.tsx +205 -205
- package/registry/components/expanded/CatalogDivider.tsx +49 -49
- package/registry/components/expanded/EmptyState.tsx +155 -155
- package/registry/components/expanded/FileUpload.tsx +543 -543
- package/registry/components/expanded/OnboardingStepListItem.tsx +60 -60
- package/registry/components/expanded/PageHeader.tsx +209 -179
- package/registry/components/expanded/Slideout.tsx +108 -108
- package/registry/components/expanded/Steps.tsx +402 -402
- package/registry/components/expanded/Table.tsx +1109 -1092
- package/registry/components/expanded/Timeline.tsx +203 -203
- package/registry/components/expanded/activityFeed.css +248 -248
- package/registry/components/expanded/activityHeatmap.css +66 -66
- package/registry/components/expanded/banner.css +260 -260
- package/registry/components/expanded/breadcrumbs.css +157 -140
- package/registry/components/expanded/catalogComponentsShowcase.css +87 -87
- package/registry/components/expanded/divider.css +75 -75
- package/registry/components/expanded/emptyState.css +111 -111
- package/registry/components/expanded/fileUpload.css +457 -457
- package/registry/components/expanded/onboardingStepListItem.css +135 -135
- package/registry/components/expanded/pageHeader.css +284 -248
- package/registry/components/expanded/slideout.css +276 -276
- package/registry/components/expanded/steps.css +356 -356
- package/registry/components/expanded/table.css +655 -606
- package/registry/components/expanded/timeline.css +286 -286
- package/registry/components/field.tsx +283 -283
- package/registry/components/hover-card.tsx +48 -48
- package/registry/components/input-content.ts +107 -107
- package/registry/components/input-group.tsx +130 -130
- package/registry/components/input-otp.tsx +584 -584
- package/registry/components/input.tsx +992 -990
- package/registry/components/item.tsx +189 -189
- package/registry/components/kbd.tsx +246 -246
- package/registry/components/label.tsx +78 -78
- package/registry/components/menu.tsx +1091 -978
- package/registry/components/menubar.tsx +226 -226
- package/registry/components/modal.tsx +872 -872
- package/registry/components/native-select.tsx +205 -205
- package/registry/components/navigation-menu.tsx +171 -171
- package/registry/components/pagination.css +36 -36
- package/registry/components/pagination.tsx +560 -560
- package/registry/components/popover.tsx +338 -338
- package/registry/components/progress-slider.tsx +216 -216
- package/registry/components/radio-card.tsx +676 -676
- package/registry/components/radio-group.tsx +570 -570
- package/registry/components/resizable.tsx +108 -108
- package/registry/components/scroll-area.tsx +91 -91
- package/registry/components/segmented-control.tsx +87 -87
- package/registry/components/select-content.tsx +218 -218
- package/registry/components/select.tsx +937 -937
- package/registry/components/sheet.tsx +305 -305
- package/registry/components/sidebar.tsx +1535 -1433
- package/registry/components/skeleton.css +54 -54
- package/registry/components/skeleton.tsx +482 -482
- package/registry/components/slider.tsx +380 -380
- package/registry/components/social-button.tsx +387 -387
- package/registry/components/spinner.tsx +78 -78
- package/registry/components/table-elements.tsx +287 -128
- package/registry/components/tabs.css +246 -222
- package/registry/components/tabs.tsx +245 -241
- package/registry/components/tag.tsx +423 -423
- package/registry/components/textarea.tsx +610 -610
- package/registry/components/toast.tsx +136 -136
- package/registry/components/toggle.tsx +256 -256
- package/registry/components/toolbar.tsx +539 -539
- package/registry/components/tooltip.tsx +433 -433
- package/registry/examples/alert-demo.tsx +34 -34
- package/registry/examples/alert-dialog-demo.tsx +42 -42
- package/registry/examples/app-header-demo.tsx +40 -0
- package/registry/examples/aspect-ratio-demo.tsx +11 -11
- package/registry/examples/attribute-demo.tsx +65 -65
- package/registry/examples/autocomplete-demo.tsx +109 -109
- package/registry/examples/avatar-demo.tsx +132 -132
- package/registry/examples/badge-demo.tsx +69 -69
- package/registry/examples/button-demo.tsx +86 -86
- package/registry/examples/button-group-demo.tsx +63 -63
- package/registry/examples/card-demo.tsx +86 -86
- package/registry/examples/carousel-demo.tsx +43 -43
- package/registry/examples/chart-demo.tsx +18 -18
- package/registry/examples/checkbox-demo.tsx +62 -62
- package/registry/examples/collapsible-demo.tsx +16 -16
- package/registry/examples/collection-filter-bar-demo.tsx +135 -135
- package/registry/examples/command-demo.tsx +42 -42
- package/registry/examples/command-palette-demo.tsx +235 -235
- package/registry/examples/context-menu-demo.tsx +29 -29
- package/registry/examples/control-density-contract-demo.tsx +65 -65
- package/registry/examples/date-picker-demo.tsx +127 -127
- package/registry/examples/divider-demo.tsx +17 -17
- package/registry/examples/expanded/activity-heatmap-demo.tsx +29 -29
- package/registry/examples/expanded/banner-demo.tsx +48 -48
- package/registry/examples/expanded/breadcrumbs-demo.tsx +59 -59
- package/registry/examples/expanded/empty-state-demo.tsx +39 -39
- package/registry/examples/expanded/file-upload-demo.tsx +60 -60
- package/registry/examples/expanded/onboarding-step-demo.tsx +11 -11
- package/registry/examples/expanded/slideout-demo.tsx +15 -15
- package/registry/examples/expanded/steps-demo.tsx +29 -29
- package/registry/examples/expanded/tabs-demo.tsx +13 -13
- package/registry/examples/expanded/timeline-demo.tsx +18 -18
- package/registry/examples/field-demo.tsx +51 -51
- package/registry/examples/hover-card-demo.tsx +23 -23
- package/registry/examples/input-actions-demo.tsx +36 -36
- package/registry/examples/input-demo.tsx +87 -87
- package/registry/examples/input-group-demo.tsx +16 -16
- package/registry/examples/input-otp-demo.tsx +72 -72
- package/registry/examples/item-demo.tsx +46 -46
- package/registry/examples/kbd-demo.tsx +12 -12
- package/registry/examples/label-demo.tsx +20 -20
- package/registry/examples/menu-demo.tsx +122 -122
- package/registry/examples/menubar-demo.tsx +34 -34
- package/registry/examples/modal-demo.tsx +74 -74
- package/registry/examples/native-select-demo.tsx +16 -16
- package/registry/examples/navigation-menu-demo.tsx +29 -29
- package/registry/examples/pagination-demo.tsx +20 -20
- package/registry/examples/popover-demo.tsx +547 -547
- package/registry/examples/progress-demo.tsx +37 -37
- package/registry/examples/progress-slider-demo.tsx +29 -29
- package/registry/examples/radio-card-demo.tsx +51 -51
- package/registry/examples/radio-group-demo.tsx +62 -62
- package/registry/examples/resizable-demo.tsx +22 -22
- package/registry/examples/results-toolbar-demo.tsx +44 -44
- package/registry/examples/scroll-area-demo.tsx +15 -15
- package/registry/examples/segmented-control-demo.tsx +39 -39
- package/registry/examples/select-demo.tsx +87 -87
- package/registry/examples/sheet-demo.tsx +47 -47
- package/registry/examples/sidebar-demo.tsx +101 -101
- package/registry/examples/slider-demo.tsx +31 -31
- package/registry/examples/social-button-demo.tsx +61 -61
- package/registry/examples/spinner-demo.tsx +59 -59
- package/registry/examples/tabs-demo.tsx +13 -13
- package/registry/examples/tag-demo.tsx +29 -29
- package/registry/examples/textarea-demo.tsx +79 -79
- package/registry/examples/toast-demo.tsx +35 -35
- package/registry/examples/toggle-demo.tsx +59 -59
- package/registry/examples/tooltip-demo.tsx +115 -115
- package/registry/guidance/USAGE.md +27 -27
- package/registry/hooks/use-direction.ts +207 -207
- package/registry/index.json +387 -17
- package/registry/styles/globals.css +46 -0
- package/registry.json +24 -2
- package/schema/config.schema.json +51 -51
- package/schema/registry.schema.json +194 -194
- package/schema/tokens.schema.json +167 -167
- package/src/cli/command-line.js +194 -194
- package/src/cli/config-editors.js +9 -9
- package/src/cli/doctor.js +399 -399
- package/src/cli/file-transaction.js +302 -302
- package/src/cli/global-css.js +153 -153
- package/src/cli/index.js +1002 -1002
- package/src/cli/install-plan.js +592 -592
- package/src/cli/install-receipt.js +171 -171
- package/src/cli/jsonc.js +203 -203
- package/src/cli/package-install-state.js +254 -254
- package/src/cli/package-manager.js +238 -238
- package/src/cli/package-plan.js +185 -185
- package/src/cli/package-version.js +97 -97
- package/src/cli/registry-query.js +207 -207
- package/src/cli/reporting.js +55 -55
- package/src/cli/schema-validation.js +19 -19
- package/src/cli/source-scanner.js +686 -686
- package/src/cli/vite-config.js +478 -478
- package/tokens/banhaten.tokens.json +184 -0
|
@@ -1,937 +1,937 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import * as React from "react"
|
|
4
|
-
import * as SelectPrimitive from "@radix-ui/react-select"
|
|
5
|
-
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
|
-
|
|
7
|
-
import { cn } from "@/lib/utils"
|
|
8
|
-
import {
|
|
9
|
-
getDefaultSelectItemMedia,
|
|
10
|
-
SelectIcon,
|
|
11
|
-
SelectItemAvatar,
|
|
12
|
-
SelectItemCompanyLogo,
|
|
13
|
-
SelectItemPaymentIcon,
|
|
14
|
-
SelectItemStatusDot,
|
|
15
|
-
type SelectItemType,
|
|
16
|
-
type SelectStatusTone,
|
|
17
|
-
} from "./select-content"
|
|
18
|
-
|
|
19
|
-
type ControlDensity = "compact" | "default" | "comfortable"
|
|
20
|
-
type SelectSize = "lg" | "md" | "comfortable"
|
|
21
|
-
type SelectVisualState = "default" | "filled" | "error" | "disabled"
|
|
22
|
-
type SelectVariant = "default" | "soft"
|
|
23
|
-
type SelectSelectionType = "default" | "checkbox"
|
|
24
|
-
|
|
25
|
-
const selectRoot = cva(
|
|
26
|
-
"relative grid w-[var(--bh-select-width)] max-w-full gap-[var(--bh-select-field-gap)]"
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
const selectTrigger = cva(
|
|
30
|
-
[
|
|
31
|
-
"group/select-trigger relative flex w-full items-center gap-[var(--bh-select-trigger-gap)] rounded-[var(--bh-select-trigger-radius)]",
|
|
32
|
-
"select-none px-[var(--bh-select-trigger-padding-x)] text-start outline-none",
|
|
33
|
-
"transition-[background-color,box-shadow]",
|
|
34
|
-
"[--bh-select-trigger-border-current:var(--bh-select-trigger-border)] [--elevation-select-trigger:inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-current,var(--bh-select-trigger-border)),var(--elevation-component-default)]",
|
|
35
|
-
"focus-visible:[--bh-select-trigger-border-current:var(--bh-select-trigger-border-focus)] focus-visible:shadow-[var(--elevation-select-focus-ring)]",
|
|
36
|
-
"aria-invalid:[--bh-select-trigger-border-current:var(--bh-select-trigger-border-error)]",
|
|
37
|
-
"disabled:pointer-events-none disabled:bg-[var(--bh-select-trigger-bg-disabled)] disabled:shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-disabled)]",
|
|
38
|
-
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
39
|
-
],
|
|
40
|
-
{
|
|
41
|
-
variants: {
|
|
42
|
-
size: {
|
|
43
|
-
comfortable: "py-[var(--bh-select-trigger-padding-y-comfortable)]",
|
|
44
|
-
lg: "py-[var(--bh-select-trigger-padding-y-lg)]",
|
|
45
|
-
md: "py-[var(--bh-select-trigger-padding-y-md)]",
|
|
46
|
-
},
|
|
47
|
-
variant: {
|
|
48
|
-
default:
|
|
49
|
-
"bg-[var(--bh-select-trigger-bg)] shadow-[var(--elevation-select-trigger)]",
|
|
50
|
-
soft:
|
|
51
|
-
"bg-[var(--bh-select-trigger-bg-soft)] shadow-none",
|
|
52
|
-
},
|
|
53
|
-
state: {
|
|
54
|
-
default: "",
|
|
55
|
-
filled: "",
|
|
56
|
-
error:
|
|
57
|
-
"[--bh-select-trigger-border-current:var(--bh-select-trigger-border-error)] shadow-[var(--elevation-select-trigger)] focus-visible:shadow-[var(--elevation-select-danger-focus-ring)]",
|
|
58
|
-
disabled:
|
|
59
|
-
"pointer-events-none bg-[var(--bh-select-trigger-bg-disabled)] shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-disabled)]",
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
defaultVariants: {
|
|
63
|
-
size: "lg",
|
|
64
|
-
variant: "default",
|
|
65
|
-
state: "default",
|
|
66
|
-
},
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
const selectMenu = cva(
|
|
71
|
-
[
|
|
72
|
-
"w-[var(--radix-popper-anchor-width,var(--bh-select-menu-width))] max-w-[var(--radix-popper-available-width,100vw)] overflow-hidden rounded-[var(--bh-select-menu-radius)]",
|
|
73
|
-
"select-none bg-[var(--bh-select-menu-bg)] py-[var(--bh-select-menu-padding-y)]",
|
|
74
|
-
"shadow-[var(--elevation-select-menu)]",
|
|
75
|
-
].join(" ")
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
const selectMenuList = cva(
|
|
79
|
-
"flex w-full flex-col gap-[var(--bh-select-menu-list-gap)]"
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
const selectMenuItem = cva(
|
|
83
|
-
[
|
|
84
|
-
"group/select-menu-item relative flex min-h-[var(--bh-select-item-min-height)] w-full items-center bg-transparent",
|
|
85
|
-
"select-none px-[var(--bh-select-item-padding-x)] text-start outline-none",
|
|
86
|
-
"disabled:pointer-events-none data-[disabled=true]:pointer-events-none",
|
|
87
|
-
"focus-visible:[&>[data-slot=select-menu-item-content]]:bg-[var(--bh-select-item-hover-bg)]",
|
|
88
|
-
],
|
|
89
|
-
{
|
|
90
|
-
variants: {
|
|
91
|
-
state: {
|
|
92
|
-
default: "",
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
defaultVariants: {
|
|
96
|
-
state: "default",
|
|
97
|
-
},
|
|
98
|
-
}
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
const selectMenuItemContent = cva(
|
|
102
|
-
[
|
|
103
|
-
"relative flex min-w-0 flex-1 items-center gap-[var(--bh-select-item-gap)] rounded-[var(--bh-select-item-radius)]",
|
|
104
|
-
"p-[var(--bh-select-item-content-padding)] transition-colors",
|
|
105
|
-
"group-hover/select-menu-item:bg-[var(--bh-select-item-hover-bg)] group-data-[disabled=true]/select-menu-item:bg-transparent",
|
|
106
|
-
],
|
|
107
|
-
{
|
|
108
|
-
variants: {
|
|
109
|
-
selected: {
|
|
110
|
-
true: "pe-[var(--bh-select-item-selected-padding-end)]",
|
|
111
|
-
false: "",
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
defaultVariants: {
|
|
115
|
-
selected: false,
|
|
116
|
-
},
|
|
117
|
-
}
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
const SelectRadixItemContext = React.createContext(false)
|
|
121
|
-
|
|
122
|
-
type SelectProps = Omit<React.ComponentProps<"div">, "children" | "dir"> & {
|
|
123
|
-
children?: React.ReactNode
|
|
124
|
-
defaultSelectValue?: string
|
|
125
|
-
density?: ControlDensity
|
|
126
|
-
dir?: "ltr" | "rtl" | "auto"
|
|
127
|
-
errorMessage?: React.ReactNode
|
|
128
|
-
expandIcon?: React.ReactNode | false
|
|
129
|
-
hasHelperIcon?: boolean
|
|
130
|
-
hasHelperText?: boolean
|
|
131
|
-
hasInformationIcon?: boolean
|
|
132
|
-
hasLabel?: boolean
|
|
133
|
-
hasLeadingIcon?: boolean
|
|
134
|
-
hasTrailingIcon?: boolean
|
|
135
|
-
helperText?: React.ReactNode
|
|
136
|
-
isOptional?: boolean
|
|
137
|
-
isRequired?: boolean
|
|
138
|
-
label?: React.ReactNode
|
|
139
|
-
leadingIcon?: React.ReactNode | false
|
|
140
|
-
onOpenChange?: (open: boolean) => void
|
|
141
|
-
onTriggerClick?: React.MouseEventHandler<HTMLButtonElement>
|
|
142
|
-
onValueChange?: (value: string) => void
|
|
143
|
-
open?: boolean
|
|
144
|
-
optionalText?: React.ReactNode
|
|
145
|
-
placeholder?: React.ReactNode
|
|
146
|
-
selectValue?: string
|
|
147
|
-
size?: SelectSize
|
|
148
|
-
state?: SelectVisualState
|
|
149
|
-
triggerClassName?: string
|
|
150
|
-
triggerId?: string
|
|
151
|
-
triggerProps?: Omit<
|
|
152
|
-
SelectTriggerProps,
|
|
153
|
-
| "children"
|
|
154
|
-
| "className"
|
|
155
|
-
| "expandIcon"
|
|
156
|
-
| "leadingIcon"
|
|
157
|
-
| "placeholder"
|
|
158
|
-
| "size"
|
|
159
|
-
| "state"
|
|
160
|
-
| "trailingIcon"
|
|
161
|
-
| "value"
|
|
162
|
-
| "variant"
|
|
163
|
-
>
|
|
164
|
-
trailingIcon?: React.ReactNode | false
|
|
165
|
-
value?: React.ReactNode
|
|
166
|
-
variant?: SelectVariant
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const Select = React.forwardRef<HTMLDivElement, SelectProps>(function Select({
|
|
170
|
-
"aria-label": ariaLabel,
|
|
171
|
-
"aria-labelledby": ariaLabelledBy,
|
|
172
|
-
children,
|
|
173
|
-
className,
|
|
174
|
-
defaultSelectValue,
|
|
175
|
-
density,
|
|
176
|
-
dir,
|
|
177
|
-
errorMessage,
|
|
178
|
-
expandIcon,
|
|
179
|
-
hasHelperIcon = false,
|
|
180
|
-
hasHelperText,
|
|
181
|
-
hasInformationIcon = false,
|
|
182
|
-
hasLabel,
|
|
183
|
-
hasLeadingIcon,
|
|
184
|
-
hasTrailingIcon,
|
|
185
|
-
helperText,
|
|
186
|
-
isOptional = false,
|
|
187
|
-
isRequired = false,
|
|
188
|
-
label,
|
|
189
|
-
leadingIcon,
|
|
190
|
-
onOpenChange,
|
|
191
|
-
onTriggerClick,
|
|
192
|
-
onValueChange,
|
|
193
|
-
open,
|
|
194
|
-
optionalText,
|
|
195
|
-
placeholder,
|
|
196
|
-
selectValue,
|
|
197
|
-
size,
|
|
198
|
-
state = "default",
|
|
199
|
-
triggerClassName,
|
|
200
|
-
triggerId,
|
|
201
|
-
triggerProps,
|
|
202
|
-
trailingIcon,
|
|
203
|
-
value,
|
|
204
|
-
variant = "default",
|
|
205
|
-
...props
|
|
206
|
-
}, ref) {
|
|
207
|
-
const generatedId = React.useId()
|
|
208
|
-
const resolvedSize = resolveSelectSize(density, size)
|
|
209
|
-
const resolvedDir = dir
|
|
210
|
-
const triggerVisualState = triggerProps?.disabled ? "disabled" : state
|
|
211
|
-
const isError = triggerVisualState === "error"
|
|
212
|
-
const selectedValue = value
|
|
213
|
-
const selectedPlaceholder = placeholder
|
|
214
|
-
const selectedLabel = label
|
|
215
|
-
const selectedOptional = optionalText
|
|
216
|
-
const selectedHelper = isError ? errorMessage : helperText
|
|
217
|
-
const shouldRenderLabel = hasLabel ?? hasRenderableContent(selectedLabel)
|
|
218
|
-
const shouldRenderHelperText =
|
|
219
|
-
hasHelperText ?? hasRenderableContent(selectedHelper)
|
|
220
|
-
const shouldShowLeadingIcon =
|
|
221
|
-
leadingIcon !== false &&
|
|
222
|
-
(hasLeadingIcon ?? hasRenderableContent(leadingIcon))
|
|
223
|
-
const shouldShowTrailingIcon =
|
|
224
|
-
trailingIcon !== false &&
|
|
225
|
-
(hasTrailingIcon ?? hasRenderableContent(trailingIcon))
|
|
226
|
-
const shouldRenderMenu = React.Children.count(children) > 0
|
|
227
|
-
const selectId = triggerId || generatedId
|
|
228
|
-
const helperId = `${selectId}-helper`
|
|
229
|
-
const triggerAccessibleLabel =
|
|
230
|
-
ariaLabel ??
|
|
231
|
-
(!shouldRenderLabel && !ariaLabelledBy
|
|
232
|
-
? getAccessibleText(selectedLabel)
|
|
233
|
-
: undefined)
|
|
234
|
-
const rootOpenProps =
|
|
235
|
-
open === undefined ? { onOpenChange } : { open, onOpenChange }
|
|
236
|
-
|
|
237
|
-
return (
|
|
238
|
-
<SelectPrimitive.Root
|
|
239
|
-
defaultValue={defaultSelectValue}
|
|
240
|
-
dir={resolvedDir === "auto" ? undefined : resolvedDir}
|
|
241
|
-
disabled={triggerVisualState === "disabled"}
|
|
242
|
-
onValueChange={onValueChange}
|
|
243
|
-
value={selectValue}
|
|
244
|
-
{...rootOpenProps}
|
|
245
|
-
>
|
|
246
|
-
<SelectRoot
|
|
247
|
-
data-density={density}
|
|
248
|
-
data-size={resolvedSize}
|
|
249
|
-
data-state={triggerVisualState}
|
|
250
|
-
data-variant={variant}
|
|
251
|
-
dir={resolvedDir}
|
|
252
|
-
ref={ref}
|
|
253
|
-
className={className}
|
|
254
|
-
{...props}
|
|
255
|
-
>
|
|
256
|
-
{shouldRenderLabel ? (
|
|
257
|
-
<SelectLabel
|
|
258
|
-
hasInformationIcon={hasInformationIcon}
|
|
259
|
-
htmlFor={selectId}
|
|
260
|
-
isOptional={isOptional}
|
|
261
|
-
isRequired={isRequired}
|
|
262
|
-
optionalText={selectedOptional}
|
|
263
|
-
>
|
|
264
|
-
{selectedLabel}
|
|
265
|
-
</SelectLabel>
|
|
266
|
-
) : null}
|
|
267
|
-
|
|
268
|
-
<div data-slot="select-control" className="relative w-full">
|
|
269
|
-
<SelectPrimitive.Trigger asChild>
|
|
270
|
-
<SelectTrigger
|
|
271
|
-
aria-label={triggerAccessibleLabel}
|
|
272
|
-
aria-labelledby={ariaLabelledBy}
|
|
273
|
-
aria-describedby={shouldRenderHelperText ? helperId : undefined}
|
|
274
|
-
aria-haspopup="listbox"
|
|
275
|
-
aria-invalid={isError || undefined}
|
|
276
|
-
expandIcon={expandIcon}
|
|
277
|
-
id={selectId}
|
|
278
|
-
leadingIcon={
|
|
279
|
-
shouldShowLeadingIcon
|
|
280
|
-
? (leadingIcon ?? <SelectIcon name="user" />)
|
|
281
|
-
: false
|
|
282
|
-
}
|
|
283
|
-
onClick={onTriggerClick}
|
|
284
|
-
placeholder={selectedPlaceholder}
|
|
285
|
-
size={resolvedSize}
|
|
286
|
-
state={triggerVisualState}
|
|
287
|
-
trailingIcon={
|
|
288
|
-
shouldShowTrailingIcon
|
|
289
|
-
? (trailingIcon ?? <SelectIcon name="info" />)
|
|
290
|
-
: false
|
|
291
|
-
}
|
|
292
|
-
value={selectedValue}
|
|
293
|
-
variant={variant}
|
|
294
|
-
className={triggerClassName}
|
|
295
|
-
{...triggerProps}
|
|
296
|
-
/>
|
|
297
|
-
</SelectPrimitive.Trigger>
|
|
298
|
-
|
|
299
|
-
{shouldRenderMenu ? (
|
|
300
|
-
<RadixSelectMenuContent forceMount={open === true || undefined}>
|
|
301
|
-
{children}
|
|
302
|
-
</RadixSelectMenuContent>
|
|
303
|
-
) : null}
|
|
304
|
-
</div>
|
|
305
|
-
|
|
306
|
-
{shouldRenderHelperText ? (
|
|
307
|
-
<SelectHelperText
|
|
308
|
-
hasIcon={hasHelperIcon}
|
|
309
|
-
id={helperId}
|
|
310
|
-
type={isError ? "error" : "default"}
|
|
311
|
-
>
|
|
312
|
-
{selectedHelper}
|
|
313
|
-
</SelectHelperText>
|
|
314
|
-
) : null}
|
|
315
|
-
</SelectRoot>
|
|
316
|
-
</SelectPrimitive.Root>
|
|
317
|
-
)
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
type RadixSelectMenuContentProps = React.ComponentProps<typeof SelectPrimitive.Content>
|
|
321
|
-
// Radix sideOffset requires a number; this mirrors --bh-select-menu-offset.
|
|
322
|
-
const SELECT_MENU_SIDE_OFFSET_PX = 4
|
|
323
|
-
// Radix collisionPadding requires a number; this mirrors --bh-space-md-8.
|
|
324
|
-
const SELECT_MENU_COLLISION_PADDING_PX = 8
|
|
325
|
-
|
|
326
|
-
function RadixSelectMenuContent({
|
|
327
|
-
children,
|
|
328
|
-
className,
|
|
329
|
-
collisionPadding = SELECT_MENU_COLLISION_PADDING_PX,
|
|
330
|
-
position = "popper",
|
|
331
|
-
sideOffset = SELECT_MENU_SIDE_OFFSET_PX,
|
|
332
|
-
...props
|
|
333
|
-
}: RadixSelectMenuContentProps) {
|
|
334
|
-
return (
|
|
335
|
-
<SelectPrimitive.Content
|
|
336
|
-
asChild
|
|
337
|
-
collisionPadding={collisionPadding}
|
|
338
|
-
position={position}
|
|
339
|
-
sideOffset={sideOffset}
|
|
340
|
-
{...props}
|
|
341
|
-
>
|
|
342
|
-
<div
|
|
343
|
-
data-slot="select-menu"
|
|
344
|
-
className={cn(
|
|
345
|
-
selectMenu(),
|
|
346
|
-
"absolute start-0 top-[calc(100%+var(--bh-select-menu-offset))] z-[var(--bh-z-popover)]",
|
|
347
|
-
className
|
|
348
|
-
)}
|
|
349
|
-
>
|
|
350
|
-
<SelectPrimitive.Viewport asChild>
|
|
351
|
-
<div data-slot="select-menu-list" className={selectMenuList()}>
|
|
352
|
-
<SelectRadixItemContext.Provider value>
|
|
353
|
-
{children}
|
|
354
|
-
</SelectRadixItemContext.Provider>
|
|
355
|
-
</div>
|
|
356
|
-
</SelectPrimitive.Viewport>
|
|
357
|
-
</div>
|
|
358
|
-
</SelectPrimitive.Content>
|
|
359
|
-
)
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
type SelectRootProps = React.ComponentProps<"div">
|
|
363
|
-
|
|
364
|
-
const SelectRoot = React.forwardRef<HTMLDivElement, SelectRootProps>(function SelectRoot(
|
|
365
|
-
{ className, ...props },
|
|
366
|
-
ref
|
|
367
|
-
) {
|
|
368
|
-
return (
|
|
369
|
-
<div
|
|
370
|
-
data-slot="select-root"
|
|
371
|
-
ref={ref}
|
|
372
|
-
className={cn(selectRoot(), className)}
|
|
373
|
-
{...props}
|
|
374
|
-
/>
|
|
375
|
-
)
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
type SelectLabelProps = React.ComponentProps<"label"> & {
|
|
379
|
-
hasInformationIcon?: boolean
|
|
380
|
-
isOptional?: boolean
|
|
381
|
-
isRequired?: boolean
|
|
382
|
-
optionalText?: React.ReactNode
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
function SelectLabel({
|
|
386
|
-
children,
|
|
387
|
-
className,
|
|
388
|
-
hasInformationIcon = false,
|
|
389
|
-
isOptional = false,
|
|
390
|
-
isRequired = false,
|
|
391
|
-
optionalText,
|
|
392
|
-
...props
|
|
393
|
-
}: SelectLabelProps) {
|
|
394
|
-
return (
|
|
395
|
-
<label
|
|
396
|
-
data-slot="select-label"
|
|
397
|
-
className={cn(
|
|
398
|
-
"flex w-full items-center gap-[var(--bh-select-label-gap)] text-start",
|
|
399
|
-
className
|
|
400
|
-
)}
|
|
401
|
-
{...props}
|
|
402
|
-
>
|
|
403
|
-
<span
|
|
404
|
-
data-slot="select-label-text"
|
|
405
|
-
dir="auto"
|
|
406
|
-
className="min-w-0 shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-sm-medium-font-size)] font-[var(--bh-text-body-sm-medium-font-weight)] leading-[var(--bh-text-body-sm-medium-line-height)] tracking-[var(--bh-text-body-sm-medium-letter-spacing)] text-[var(--bh-content-default)] rtl:text-[length:var(--bh-text-body-xs-medium-font-size)] rtl:font-[var(--bh-text-body-xs-medium-font-weight)] rtl:leading-[var(--bh-text-body-xs-medium-line-height)] rtl:tracking-[var(--bh-text-body-xs-medium-letter-spacing)]"
|
|
407
|
-
>
|
|
408
|
-
{children}
|
|
409
|
-
</span>
|
|
410
|
-
{isRequired ? (
|
|
411
|
-
<span
|
|
412
|
-
aria-hidden="true"
|
|
413
|
-
data-slot="select-label-required"
|
|
414
|
-
className="shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)] text-[var(--bh-content-danger-default)]"
|
|
415
|
-
>
|
|
416
|
-
*
|
|
417
|
-
</span>
|
|
418
|
-
) : null}
|
|
419
|
-
{isOptional && hasRenderableContent(optionalText) ? (
|
|
420
|
-
<span
|
|
421
|
-
data-slot="select-label-optional"
|
|
422
|
-
dir="auto"
|
|
423
|
-
className="min-w-0 shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)] text-[var(--bh-content-subtle)]"
|
|
424
|
-
>
|
|
425
|
-
{optionalText}
|
|
426
|
-
</span>
|
|
427
|
-
) : null}
|
|
428
|
-
{hasInformationIcon ? (
|
|
429
|
-
<SelectIcon
|
|
430
|
-
name="info"
|
|
431
|
-
className="text-[var(--bh-select-trigger-icon-color)]"
|
|
432
|
-
/>
|
|
433
|
-
) : null}
|
|
434
|
-
</label>
|
|
435
|
-
)
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function hasRenderableContent(content: React.ReactNode) {
|
|
439
|
-
return (
|
|
440
|
-
content !== undefined &&
|
|
441
|
-
content !== null &&
|
|
442
|
-
content !== false &&
|
|
443
|
-
content !== ""
|
|
444
|
-
)
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function getAccessibleText(content: React.ReactNode) {
|
|
448
|
-
return typeof content === "string" || typeof content === "number"
|
|
449
|
-
? String(content)
|
|
450
|
-
: undefined
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
type SelectHelperTextProps = React.ComponentProps<"p"> & {
|
|
454
|
-
hasIcon?: boolean
|
|
455
|
-
type?: "default" | "error"
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
function SelectHelperText({
|
|
459
|
-
children,
|
|
460
|
-
className,
|
|
461
|
-
hasIcon = false,
|
|
462
|
-
type = "default",
|
|
463
|
-
...props
|
|
464
|
-
}: SelectHelperTextProps) {
|
|
465
|
-
const isError = type === "error"
|
|
466
|
-
|
|
467
|
-
return (
|
|
468
|
-
<p
|
|
469
|
-
data-slot="select-helper-text"
|
|
470
|
-
data-type={type}
|
|
471
|
-
className={cn(
|
|
472
|
-
"flex w-full items-center gap-[var(--bh-select-label-gap)] text-start text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)]",
|
|
473
|
-
isError
|
|
474
|
-
? "text-[var(--bh-content-danger-default)]"
|
|
475
|
-
: "text-[var(--bh-content-subtle)]",
|
|
476
|
-
className
|
|
477
|
-
)}
|
|
478
|
-
{...props}
|
|
479
|
-
>
|
|
480
|
-
{hasIcon ? (
|
|
481
|
-
<SelectIcon
|
|
482
|
-
name={isError ? "error" : "info"}
|
|
483
|
-
className={
|
|
484
|
-
isError
|
|
485
|
-
? "text-[var(--bh-content-danger-default)]"
|
|
486
|
-
: "text-[var(--bh-select-trigger-icon-color)]"
|
|
487
|
-
}
|
|
488
|
-
/>
|
|
489
|
-
) : null}
|
|
490
|
-
<span data-slot="select-helper-label" dir="auto" className="min-w-0 flex-1">
|
|
491
|
-
{children}
|
|
492
|
-
</span>
|
|
493
|
-
</p>
|
|
494
|
-
)
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
type SelectTriggerProps = Omit<
|
|
498
|
-
React.ComponentProps<"button">,
|
|
499
|
-
"children" | "value"
|
|
500
|
-
> &
|
|
501
|
-
VariantProps<typeof selectTrigger> & {
|
|
502
|
-
density?: ControlDensity
|
|
503
|
-
expandIcon?: React.ReactNode | false
|
|
504
|
-
leadingIcon?: React.ReactNode | false
|
|
505
|
-
placeholder?: React.ReactNode
|
|
506
|
-
trailingIcon?: React.ReactNode | false
|
|
507
|
-
value?: React.ReactNode
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
const SelectTrigger = React.forwardRef<HTMLButtonElement, SelectTriggerProps>(
|
|
511
|
-
(
|
|
512
|
-
{
|
|
513
|
-
className,
|
|
514
|
-
density,
|
|
515
|
-
disabled,
|
|
516
|
-
expandIcon,
|
|
517
|
-
leadingIcon,
|
|
518
|
-
placeholder,
|
|
519
|
-
size,
|
|
520
|
-
state,
|
|
521
|
-
trailingIcon,
|
|
522
|
-
type = "button",
|
|
523
|
-
value,
|
|
524
|
-
variant = "default",
|
|
525
|
-
...props
|
|
526
|
-
},
|
|
527
|
-
ref
|
|
528
|
-
) => {
|
|
529
|
-
const resolvedSize = resolveSelectSize(density, size)
|
|
530
|
-
const hasValue = value !== undefined && value !== null && value !== ""
|
|
531
|
-
const visualState = disabled ? "disabled" : state ?? (hasValue ? "filled" : "default")
|
|
532
|
-
const isDisabled = visualState === "disabled"
|
|
533
|
-
|
|
534
|
-
return (
|
|
535
|
-
<button
|
|
536
|
-
data-density={density}
|
|
537
|
-
data-size={resolvedSize}
|
|
538
|
-
data-slot="select-trigger"
|
|
539
|
-
data-state={visualState}
|
|
540
|
-
data-variant={variant}
|
|
541
|
-
disabled={isDisabled}
|
|
542
|
-
ref={ref}
|
|
543
|
-
type={type}
|
|
544
|
-
className={cn(
|
|
545
|
-
selectTrigger({ size: resolvedSize, state: visualState, variant }),
|
|
546
|
-
className
|
|
547
|
-
)}
|
|
548
|
-
{...props}
|
|
549
|
-
>
|
|
550
|
-
<span
|
|
551
|
-
data-slot="select-trigger-main"
|
|
552
|
-
className="flex min-w-0 flex-1 items-center gap-[var(--bh-select-content-gap)]"
|
|
553
|
-
>
|
|
554
|
-
{hasRenderableContent(leadingIcon) ? (
|
|
555
|
-
<span
|
|
556
|
-
data-slot="select-leading-icon"
|
|
557
|
-
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
558
|
-
>
|
|
559
|
-
{leadingIcon}
|
|
560
|
-
</span>
|
|
561
|
-
) : null}
|
|
562
|
-
|
|
563
|
-
<span
|
|
564
|
-
data-slot="select-value-wrap"
|
|
565
|
-
className="flex min-w-0 flex-1 items-center ps-[var(--bh-select-value-padding-inline)]"
|
|
566
|
-
>
|
|
567
|
-
<span
|
|
568
|
-
data-slot="select-value"
|
|
569
|
-
dir="auto"
|
|
570
|
-
className={cn(
|
|
571
|
-
"min-w-0 flex-1 truncate text-start text-[length:var(--bh-text-body-md-regular-font-size)] font-[var(--bh-text-body-md-regular-font-weight)] leading-[var(--bh-text-body-md-regular-line-height)] tracking-[var(--bh-text-body-md-regular-letter-spacing)]",
|
|
572
|
-
hasValue || visualState === "filled"
|
|
573
|
-
? "text-[var(--bh-content-default)]"
|
|
574
|
-
: "text-[var(--bh-content-subtle)]",
|
|
575
|
-
isDisabled && "text-[var(--bh-content-disabled)]"
|
|
576
|
-
)}
|
|
577
|
-
>
|
|
578
|
-
{hasValue ? value : placeholder}
|
|
579
|
-
</span>
|
|
580
|
-
</span>
|
|
581
|
-
</span>
|
|
582
|
-
|
|
583
|
-
{hasRenderableContent(trailingIcon) ? (
|
|
584
|
-
<span
|
|
585
|
-
data-slot="select-trailing-icon"
|
|
586
|
-
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
587
|
-
>
|
|
588
|
-
{trailingIcon}
|
|
589
|
-
</span>
|
|
590
|
-
) : null}
|
|
591
|
-
|
|
592
|
-
{expandIcon !== false ? (
|
|
593
|
-
<span
|
|
594
|
-
data-slot="select-expand-icon"
|
|
595
|
-
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
596
|
-
>
|
|
597
|
-
{expandIcon ?? <SelectIcon name="chevron-down" />}
|
|
598
|
-
</span>
|
|
599
|
-
) : null}
|
|
600
|
-
</button>
|
|
601
|
-
)
|
|
602
|
-
}
|
|
603
|
-
)
|
|
604
|
-
SelectTrigger.displayName = "SelectTrigger"
|
|
605
|
-
|
|
606
|
-
type SelectMenuProps = React.ComponentProps<"div">
|
|
607
|
-
|
|
608
|
-
const SelectMenu = React.forwardRef<HTMLDivElement, SelectMenuProps>(function SelectMenu(
|
|
609
|
-
{
|
|
610
|
-
"aria-label": ariaLabel = "Options",
|
|
611
|
-
children,
|
|
612
|
-
className,
|
|
613
|
-
onKeyDown,
|
|
614
|
-
role,
|
|
615
|
-
...props
|
|
616
|
-
},
|
|
617
|
-
ref
|
|
618
|
-
) {
|
|
619
|
-
const handleKeyDown = React.useCallback(
|
|
620
|
-
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
621
|
-
onKeyDown?.(event)
|
|
622
|
-
if (event.defaultPrevented) return
|
|
623
|
-
|
|
624
|
-
if (event.key === "Escape") {
|
|
625
|
-
event.currentTarget.blur()
|
|
626
|
-
return
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (
|
|
630
|
-
event.key !== "ArrowDown" &&
|
|
631
|
-
event.key !== "ArrowUp" &&
|
|
632
|
-
event.key !== "Home" &&
|
|
633
|
-
event.key !== "End"
|
|
634
|
-
) {
|
|
635
|
-
return
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const items = getFocusableSelectItems(event.currentTarget)
|
|
639
|
-
if (items.length === 0) return
|
|
640
|
-
|
|
641
|
-
event.preventDefault()
|
|
642
|
-
|
|
643
|
-
const activeItem = event.currentTarget.ownerDocument.activeElement
|
|
644
|
-
const currentIndex =
|
|
645
|
-
activeItem instanceof HTMLElement ? items.indexOf(activeItem) : -1
|
|
646
|
-
let nextIndex = currentIndex
|
|
647
|
-
|
|
648
|
-
if (event.key === "Home") nextIndex = 0
|
|
649
|
-
if (event.key === "End") nextIndex = items.length - 1
|
|
650
|
-
if (event.key === "ArrowDown") nextIndex = (currentIndex + 1) % items.length
|
|
651
|
-
if (event.key === "ArrowUp") {
|
|
652
|
-
nextIndex = currentIndex <= 0 ? items.length - 1 : currentIndex - 1
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
items[nextIndex]?.focus()
|
|
656
|
-
},
|
|
657
|
-
[onKeyDown]
|
|
658
|
-
)
|
|
659
|
-
|
|
660
|
-
return (
|
|
661
|
-
<div
|
|
662
|
-
aria-label={ariaLabel}
|
|
663
|
-
data-slot="select-menu"
|
|
664
|
-
onKeyDown={handleKeyDown}
|
|
665
|
-
ref={ref}
|
|
666
|
-
role={role || "listbox"}
|
|
667
|
-
className={cn(selectMenu(), className)}
|
|
668
|
-
{...props}
|
|
669
|
-
>
|
|
670
|
-
<div
|
|
671
|
-
data-slot="select-menu-list"
|
|
672
|
-
role="presentation"
|
|
673
|
-
className={selectMenuList()}
|
|
674
|
-
>
|
|
675
|
-
{children}
|
|
676
|
-
</div>
|
|
677
|
-
</div>
|
|
678
|
-
)
|
|
679
|
-
})
|
|
680
|
-
|
|
681
|
-
type SelectMenuItemBaseProps = Omit<
|
|
682
|
-
React.ComponentProps<"button">,
|
|
683
|
-
"children" | "type" | "value"
|
|
684
|
-
> & {
|
|
685
|
-
addonText?: React.ReactNode
|
|
686
|
-
children?: React.ReactNode
|
|
687
|
-
label?: React.ReactNode
|
|
688
|
-
type?: "button" | "submit" | "reset"
|
|
689
|
-
value?: string
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
type SelectMenuItemMediaProps =
|
|
693
|
-
| { itemType?: "default"; media?: React.ReactNode | false }
|
|
694
|
-
| {
|
|
695
|
-
itemType: Exclude<SelectItemType, "default">
|
|
696
|
-
media?: React.ReactNode | false
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
type SelectMenuItemSelectionProps =
|
|
700
|
-
| { selected?: boolean; selectionType?: "default" }
|
|
701
|
-
| { selected?: boolean; selectionType: "checkbox" }
|
|
702
|
-
|
|
703
|
-
type SelectMenuItemDynamicProps = {
|
|
704
|
-
itemType?: SelectItemType
|
|
705
|
-
media?: React.ReactNode | false
|
|
706
|
-
selected?: boolean
|
|
707
|
-
selectionType?: SelectSelectionType
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
type SelectMenuItemProps = SelectMenuItemBaseProps &
|
|
711
|
-
(
|
|
712
|
-
| (SelectMenuItemMediaProps & SelectMenuItemSelectionProps)
|
|
713
|
-
| SelectMenuItemDynamicProps
|
|
714
|
-
)
|
|
715
|
-
|
|
716
|
-
const SelectMenuItem = React.forwardRef<HTMLButtonElement, SelectMenuItemProps>(function SelectMenuItem({
|
|
717
|
-
addonText,
|
|
718
|
-
"aria-checked": ariaChecked,
|
|
719
|
-
"aria-selected": ariaSelected,
|
|
720
|
-
children,
|
|
721
|
-
className,
|
|
722
|
-
disabled,
|
|
723
|
-
itemType = "default",
|
|
724
|
-
label,
|
|
725
|
-
media,
|
|
726
|
-
role,
|
|
727
|
-
selected = false,
|
|
728
|
-
selectionType = "default",
|
|
729
|
-
type = "button",
|
|
730
|
-
value,
|
|
731
|
-
...props
|
|
732
|
-
}, ref) {
|
|
733
|
-
const inRadixSelect = React.useContext(SelectRadixItemContext)
|
|
734
|
-
const generatedValue = React.useId()
|
|
735
|
-
const isDisabled = disabled
|
|
736
|
-
const selectedWithEndCheck = selected && selectionType === "default"
|
|
737
|
-
const resolvedRole = role || "option"
|
|
738
|
-
const usesCheckedState =
|
|
739
|
-
resolvedRole === "checkbox" ||
|
|
740
|
-
resolvedRole === "menuitemcheckbox" ||
|
|
741
|
-
resolvedRole === "radio" ||
|
|
742
|
-
resolvedRole === "menuitemradio"
|
|
743
|
-
const selectedMedia =
|
|
744
|
-
media === false ? null : media ?? getDefaultSelectItemMedia(itemType)
|
|
745
|
-
const content = label ?? children
|
|
746
|
-
const itemValue =
|
|
747
|
-
value ??
|
|
748
|
-
(typeof content === "string" || typeof content === "number"
|
|
749
|
-
? String(content)
|
|
750
|
-
: generatedValue)
|
|
751
|
-
const itemTextValue =
|
|
752
|
-
typeof content === "string" || typeof content === "number"
|
|
753
|
-
? String(content)
|
|
754
|
-
: undefined
|
|
755
|
-
|
|
756
|
-
const item = (
|
|
757
|
-
<button
|
|
758
|
-
aria-checked={usesCheckedState ? (ariaChecked ?? Boolean(selected)) : undefined}
|
|
759
|
-
aria-disabled={isDisabled || undefined}
|
|
760
|
-
aria-selected={resolvedRole === "option" ? (ariaSelected ?? Boolean(selected)) : undefined}
|
|
761
|
-
data-disabled={isDisabled ? "true" : undefined}
|
|
762
|
-
data-item-type={itemType}
|
|
763
|
-
data-selected={selected ? "true" : "false"}
|
|
764
|
-
data-selection-type={selectionType}
|
|
765
|
-
data-slot="select-menu-item"
|
|
766
|
-
disabled={isDisabled}
|
|
767
|
-
ref={ref}
|
|
768
|
-
role={resolvedRole}
|
|
769
|
-
type={type}
|
|
770
|
-
className={cn(selectMenuItem(), className)}
|
|
771
|
-
{...props}
|
|
772
|
-
>
|
|
773
|
-
<span
|
|
774
|
-
data-slot="select-menu-item-content"
|
|
775
|
-
className={selectMenuItemContent({
|
|
776
|
-
selected: selectedWithEndCheck,
|
|
777
|
-
})}
|
|
778
|
-
>
|
|
779
|
-
{selectionType === "checkbox" ? (
|
|
780
|
-
<span
|
|
781
|
-
data-slot="select-menu-item-checkbox-wrap"
|
|
782
|
-
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center"
|
|
783
|
-
>
|
|
784
|
-
<SelectCheckboxIndicator checked={selected} disabled={isDisabled} />
|
|
785
|
-
</span>
|
|
786
|
-
) : null}
|
|
787
|
-
|
|
788
|
-
{selectedMedia ? (
|
|
789
|
-
<span
|
|
790
|
-
data-slot="select-menu-item-media"
|
|
791
|
-
className="flex shrink-0 items-center ps-[var(--bh-select-media-inset)] text-[var(--bh-content-subtle)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)] group-data-[disabled=true]/select-menu-item:opacity-[var(--bh-opacity-60)] [&_svg:not([class*='size-'])]:size-[var(--bh-icon-size-default)]"
|
|
792
|
-
>
|
|
793
|
-
{selectedMedia}
|
|
794
|
-
</span>
|
|
795
|
-
) : null}
|
|
796
|
-
|
|
797
|
-
<span
|
|
798
|
-
data-slot="select-menu-item-value"
|
|
799
|
-
className="flex min-w-0 items-center px-[var(--bh-select-item-value-padding-x)]"
|
|
800
|
-
>
|
|
801
|
-
<span
|
|
802
|
-
data-slot="select-menu-item-label"
|
|
803
|
-
dir="auto"
|
|
804
|
-
className="min-w-0 truncate text-start text-[length:var(--bh-text-body-md-regular-font-size)] font-[var(--bh-text-body-md-regular-font-weight)] leading-[var(--bh-text-body-md-regular-line-height)] tracking-[var(--bh-text-body-md-regular-letter-spacing)] text-[var(--bh-content-default)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)]"
|
|
805
|
-
>
|
|
806
|
-
{content}
|
|
807
|
-
</span>
|
|
808
|
-
</span>
|
|
809
|
-
|
|
810
|
-
{addonText !== undefined && addonText !== null ? (
|
|
811
|
-
<span
|
|
812
|
-
data-slot="select-menu-item-addon"
|
|
813
|
-
dir="auto"
|
|
814
|
-
className="min-w-0 shrink-0 truncate text-start text-[length:var(--bh-text-body-2xs-regular-font-size)] font-[var(--bh-text-body-2xs-regular-font-weight)] leading-[var(--bh-text-body-2xs-regular-line-height)] tracking-[var(--bh-text-body-2xs-regular-letter-spacing)] text-[var(--bh-content-muted)] group-hover/select-menu-item:text-[var(--bh-content-subtle)] group-focus-visible/select-menu-item:text-[var(--bh-content-subtle)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)]"
|
|
815
|
-
>
|
|
816
|
-
{addonText}
|
|
817
|
-
</span>
|
|
818
|
-
) : null}
|
|
819
|
-
</span>
|
|
820
|
-
|
|
821
|
-
{selectedWithEndCheck ? (
|
|
822
|
-
<span
|
|
823
|
-
aria-hidden="true"
|
|
824
|
-
data-slot="select-menu-item-check"
|
|
825
|
-
className="pointer-events-none absolute end-[var(--bh-select-item-check-offset)] top-1/2 flex size-[var(--bh-select-icon-slot-size)] -translate-y-1/2 items-center justify-center text-[var(--bh-select-check-color)]"
|
|
826
|
-
>
|
|
827
|
-
<SelectIcon name="check-line" />
|
|
828
|
-
</span>
|
|
829
|
-
) : null}
|
|
830
|
-
</button>
|
|
831
|
-
)
|
|
832
|
-
|
|
833
|
-
if (!inRadixSelect) return item
|
|
834
|
-
|
|
835
|
-
return (
|
|
836
|
-
<SelectPrimitive.Item
|
|
837
|
-
asChild
|
|
838
|
-
disabled={isDisabled}
|
|
839
|
-
textValue={itemTextValue}
|
|
840
|
-
value={itemValue}
|
|
841
|
-
>
|
|
842
|
-
{item}
|
|
843
|
-
</SelectPrimitive.Item>
|
|
844
|
-
)
|
|
845
|
-
})
|
|
846
|
-
|
|
847
|
-
function getFocusableSelectItems(root: HTMLElement) {
|
|
848
|
-
return Array.from(
|
|
849
|
-
root.querySelectorAll<HTMLElement>(
|
|
850
|
-
'[role="option"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"])'
|
|
851
|
-
)
|
|
852
|
-
).filter((item) => !item.hasAttribute("disabled"))
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
function resolveSelectSize(
|
|
856
|
-
density: ControlDensity | undefined,
|
|
857
|
-
size: SelectSize | null | undefined
|
|
858
|
-
): SelectSize {
|
|
859
|
-
if (density === "compact") return "md"
|
|
860
|
-
if (density === "default") return "lg"
|
|
861
|
-
if (density === "comfortable") return "comfortable"
|
|
862
|
-
return size ?? "lg"
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
type SelectCheckboxIndicatorProps = {
|
|
866
|
-
checked?: boolean
|
|
867
|
-
className?: string
|
|
868
|
-
disabled?: boolean
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
function SelectCheckboxIndicator({
|
|
872
|
-
checked = false,
|
|
873
|
-
className,
|
|
874
|
-
disabled = false,
|
|
875
|
-
}: SelectCheckboxIndicatorProps) {
|
|
876
|
-
return (
|
|
877
|
-
<span
|
|
878
|
-
aria-hidden="true"
|
|
879
|
-
data-checked={checked ? "true" : "false"}
|
|
880
|
-
data-disabled={disabled ? "true" : undefined}
|
|
881
|
-
data-slot="select-checkbox"
|
|
882
|
-
className={cn(
|
|
883
|
-
"relative size-[var(--bh-select-icon-slot-size)] shrink-0 overflow-hidden",
|
|
884
|
-
className
|
|
885
|
-
)}
|
|
886
|
-
>
|
|
887
|
-
<span
|
|
888
|
-
data-slot="select-checkbox-control"
|
|
889
|
-
className={cn(
|
|
890
|
-
"pointer-events-none absolute left-1/2 top-1/2 size-[var(--bh-select-checkbox-size)] -translate-x-1/2 -translate-y-1/2 rounded-[var(--bh-select-checkbox-radius)] shadow-[var(--elevation-select-checkbox)] [--bh-select-checkbox-border:var(--bh-border-input)] [--elevation-select-checkbox:inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-checkbox-border,var(--bh-border-input)),var(--elevation-component-default)]",
|
|
891
|
-
checked
|
|
892
|
-
? "bg-[var(--bh-interactive-checkbox-default)] [--bh-select-checkbox-border:transparent]"
|
|
893
|
-
: "bg-[var(--bh-bg-default)]",
|
|
894
|
-
disabled &&
|
|
895
|
-
"bg-[var(--bh-bg-disabled)] shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-border-disabled)]"
|
|
896
|
-
)}
|
|
897
|
-
/>
|
|
898
|
-
{checked ? (
|
|
899
|
-
<span className="absolute left-1/2 top-1/2 flex size-[var(--bh-select-checkbox-icon-size)] -translate-x-1/2 -translate-y-1/2 items-center justify-center text-[var(--bh-interactive-checkbox-content)]">
|
|
900
|
-
<SelectIcon name="check-fill" />
|
|
901
|
-
</span>
|
|
902
|
-
) : null}
|
|
903
|
-
</span>
|
|
904
|
-
)
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
export {
|
|
908
|
-
Select,
|
|
909
|
-
SelectCheckboxIndicator,
|
|
910
|
-
SelectHelperText,
|
|
911
|
-
SelectItemAvatar,
|
|
912
|
-
SelectItemCompanyLogo,
|
|
913
|
-
SelectItemPaymentIcon,
|
|
914
|
-
SelectItemStatusDot,
|
|
915
|
-
SelectLabel,
|
|
916
|
-
SelectMenu,
|
|
917
|
-
SelectMenuItem,
|
|
918
|
-
SelectRoot,
|
|
919
|
-
SelectTrigger,
|
|
920
|
-
selectMenu,
|
|
921
|
-
selectMenuItem,
|
|
922
|
-
selectRoot,
|
|
923
|
-
selectTrigger,
|
|
924
|
-
}
|
|
925
|
-
export type {
|
|
926
|
-
ControlDensity,
|
|
927
|
-
SelectItemType,
|
|
928
|
-
SelectMenuItemProps,
|
|
929
|
-
SelectProps,
|
|
930
|
-
SelectRootProps,
|
|
931
|
-
SelectSelectionType,
|
|
932
|
-
SelectSize,
|
|
933
|
-
SelectStatusTone,
|
|
934
|
-
SelectTriggerProps,
|
|
935
|
-
SelectVariant,
|
|
936
|
-
SelectVisualState,
|
|
937
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as SelectPrimitive from "@radix-ui/react-select"
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
import {
|
|
9
|
+
getDefaultSelectItemMedia,
|
|
10
|
+
SelectIcon,
|
|
11
|
+
SelectItemAvatar,
|
|
12
|
+
SelectItemCompanyLogo,
|
|
13
|
+
SelectItemPaymentIcon,
|
|
14
|
+
SelectItemStatusDot,
|
|
15
|
+
type SelectItemType,
|
|
16
|
+
type SelectStatusTone,
|
|
17
|
+
} from "./select-content"
|
|
18
|
+
|
|
19
|
+
type ControlDensity = "compact" | "default" | "comfortable"
|
|
20
|
+
type SelectSize = "lg" | "md" | "comfortable"
|
|
21
|
+
type SelectVisualState = "default" | "filled" | "error" | "disabled"
|
|
22
|
+
type SelectVariant = "default" | "soft"
|
|
23
|
+
type SelectSelectionType = "default" | "checkbox"
|
|
24
|
+
|
|
25
|
+
const selectRoot = cva(
|
|
26
|
+
"relative grid w-[var(--bh-select-width)] max-w-full gap-[var(--bh-select-field-gap)]"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const selectTrigger = cva(
|
|
30
|
+
[
|
|
31
|
+
"group/select-trigger relative flex w-full items-center gap-[var(--bh-select-trigger-gap)] rounded-[var(--bh-select-trigger-radius)]",
|
|
32
|
+
"select-none px-[var(--bh-select-trigger-padding-x)] text-start outline-none",
|
|
33
|
+
"transition-[background-color,box-shadow]",
|
|
34
|
+
"[--bh-select-trigger-border-current:var(--bh-select-trigger-border)] [--elevation-select-trigger:inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-current,var(--bh-select-trigger-border)),var(--elevation-component-default)]",
|
|
35
|
+
"focus-visible:[--bh-select-trigger-border-current:var(--bh-select-trigger-border-focus)] focus-visible:shadow-[var(--elevation-select-focus-ring)]",
|
|
36
|
+
"aria-invalid:[--bh-select-trigger-border-current:var(--bh-select-trigger-border-error)]",
|
|
37
|
+
"disabled:pointer-events-none disabled:bg-[var(--bh-select-trigger-bg-disabled)] disabled:shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-disabled)]",
|
|
38
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
39
|
+
],
|
|
40
|
+
{
|
|
41
|
+
variants: {
|
|
42
|
+
size: {
|
|
43
|
+
comfortable: "py-[var(--bh-select-trigger-padding-y-comfortable)]",
|
|
44
|
+
lg: "py-[var(--bh-select-trigger-padding-y-lg)]",
|
|
45
|
+
md: "py-[var(--bh-select-trigger-padding-y-md)]",
|
|
46
|
+
},
|
|
47
|
+
variant: {
|
|
48
|
+
default:
|
|
49
|
+
"bg-[var(--bh-select-trigger-bg)] shadow-[var(--elevation-select-trigger)]",
|
|
50
|
+
soft:
|
|
51
|
+
"bg-[var(--bh-select-trigger-bg-soft)] shadow-none",
|
|
52
|
+
},
|
|
53
|
+
state: {
|
|
54
|
+
default: "",
|
|
55
|
+
filled: "",
|
|
56
|
+
error:
|
|
57
|
+
"[--bh-select-trigger-border-current:var(--bh-select-trigger-border-error)] shadow-[var(--elevation-select-trigger)] focus-visible:shadow-[var(--elevation-select-danger-focus-ring)]",
|
|
58
|
+
disabled:
|
|
59
|
+
"pointer-events-none bg-[var(--bh-select-trigger-bg-disabled)] shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-trigger-border-disabled)]",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
defaultVariants: {
|
|
63
|
+
size: "lg",
|
|
64
|
+
variant: "default",
|
|
65
|
+
state: "default",
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
const selectMenu = cva(
|
|
71
|
+
[
|
|
72
|
+
"w-[var(--radix-popper-anchor-width,var(--bh-select-menu-width))] max-w-[var(--radix-popper-available-width,100vw)] overflow-hidden rounded-[var(--bh-select-menu-radius)]",
|
|
73
|
+
"select-none bg-[var(--bh-select-menu-bg)] py-[var(--bh-select-menu-padding-y)]",
|
|
74
|
+
"shadow-[var(--elevation-select-menu)]",
|
|
75
|
+
].join(" ")
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const selectMenuList = cva(
|
|
79
|
+
"flex w-full flex-col gap-[var(--bh-select-menu-list-gap)]"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
const selectMenuItem = cva(
|
|
83
|
+
[
|
|
84
|
+
"group/select-menu-item relative flex min-h-[var(--bh-select-item-min-height)] w-full items-center bg-transparent",
|
|
85
|
+
"select-none px-[var(--bh-select-item-padding-x)] text-start outline-none",
|
|
86
|
+
"disabled:pointer-events-none data-[disabled=true]:pointer-events-none",
|
|
87
|
+
"focus-visible:[&>[data-slot=select-menu-item-content]]:bg-[var(--bh-select-item-hover-bg)]",
|
|
88
|
+
],
|
|
89
|
+
{
|
|
90
|
+
variants: {
|
|
91
|
+
state: {
|
|
92
|
+
default: "",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
defaultVariants: {
|
|
96
|
+
state: "default",
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const selectMenuItemContent = cva(
|
|
102
|
+
[
|
|
103
|
+
"relative flex min-w-0 flex-1 items-center gap-[var(--bh-select-item-gap)] rounded-[var(--bh-select-item-radius)]",
|
|
104
|
+
"p-[var(--bh-select-item-content-padding)] transition-colors",
|
|
105
|
+
"group-hover/select-menu-item:bg-[var(--bh-select-item-hover-bg)] group-data-[disabled=true]/select-menu-item:bg-transparent",
|
|
106
|
+
],
|
|
107
|
+
{
|
|
108
|
+
variants: {
|
|
109
|
+
selected: {
|
|
110
|
+
true: "pe-[var(--bh-select-item-selected-padding-end)]",
|
|
111
|
+
false: "",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
defaultVariants: {
|
|
115
|
+
selected: false,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const SelectRadixItemContext = React.createContext(false)
|
|
121
|
+
|
|
122
|
+
type SelectProps = Omit<React.ComponentProps<"div">, "children" | "dir"> & {
|
|
123
|
+
children?: React.ReactNode
|
|
124
|
+
defaultSelectValue?: string
|
|
125
|
+
density?: ControlDensity
|
|
126
|
+
dir?: "ltr" | "rtl" | "auto"
|
|
127
|
+
errorMessage?: React.ReactNode
|
|
128
|
+
expandIcon?: React.ReactNode | false
|
|
129
|
+
hasHelperIcon?: boolean
|
|
130
|
+
hasHelperText?: boolean
|
|
131
|
+
hasInformationIcon?: boolean
|
|
132
|
+
hasLabel?: boolean
|
|
133
|
+
hasLeadingIcon?: boolean
|
|
134
|
+
hasTrailingIcon?: boolean
|
|
135
|
+
helperText?: React.ReactNode
|
|
136
|
+
isOptional?: boolean
|
|
137
|
+
isRequired?: boolean
|
|
138
|
+
label?: React.ReactNode
|
|
139
|
+
leadingIcon?: React.ReactNode | false
|
|
140
|
+
onOpenChange?: (open: boolean) => void
|
|
141
|
+
onTriggerClick?: React.MouseEventHandler<HTMLButtonElement>
|
|
142
|
+
onValueChange?: (value: string) => void
|
|
143
|
+
open?: boolean
|
|
144
|
+
optionalText?: React.ReactNode
|
|
145
|
+
placeholder?: React.ReactNode
|
|
146
|
+
selectValue?: string
|
|
147
|
+
size?: SelectSize
|
|
148
|
+
state?: SelectVisualState
|
|
149
|
+
triggerClassName?: string
|
|
150
|
+
triggerId?: string
|
|
151
|
+
triggerProps?: Omit<
|
|
152
|
+
SelectTriggerProps,
|
|
153
|
+
| "children"
|
|
154
|
+
| "className"
|
|
155
|
+
| "expandIcon"
|
|
156
|
+
| "leadingIcon"
|
|
157
|
+
| "placeholder"
|
|
158
|
+
| "size"
|
|
159
|
+
| "state"
|
|
160
|
+
| "trailingIcon"
|
|
161
|
+
| "value"
|
|
162
|
+
| "variant"
|
|
163
|
+
>
|
|
164
|
+
trailingIcon?: React.ReactNode | false
|
|
165
|
+
value?: React.ReactNode
|
|
166
|
+
variant?: SelectVariant
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const Select = React.forwardRef<HTMLDivElement, SelectProps>(function Select({
|
|
170
|
+
"aria-label": ariaLabel,
|
|
171
|
+
"aria-labelledby": ariaLabelledBy,
|
|
172
|
+
children,
|
|
173
|
+
className,
|
|
174
|
+
defaultSelectValue,
|
|
175
|
+
density,
|
|
176
|
+
dir,
|
|
177
|
+
errorMessage,
|
|
178
|
+
expandIcon,
|
|
179
|
+
hasHelperIcon = false,
|
|
180
|
+
hasHelperText,
|
|
181
|
+
hasInformationIcon = false,
|
|
182
|
+
hasLabel,
|
|
183
|
+
hasLeadingIcon,
|
|
184
|
+
hasTrailingIcon,
|
|
185
|
+
helperText,
|
|
186
|
+
isOptional = false,
|
|
187
|
+
isRequired = false,
|
|
188
|
+
label,
|
|
189
|
+
leadingIcon,
|
|
190
|
+
onOpenChange,
|
|
191
|
+
onTriggerClick,
|
|
192
|
+
onValueChange,
|
|
193
|
+
open,
|
|
194
|
+
optionalText,
|
|
195
|
+
placeholder,
|
|
196
|
+
selectValue,
|
|
197
|
+
size,
|
|
198
|
+
state = "default",
|
|
199
|
+
triggerClassName,
|
|
200
|
+
triggerId,
|
|
201
|
+
triggerProps,
|
|
202
|
+
trailingIcon,
|
|
203
|
+
value,
|
|
204
|
+
variant = "default",
|
|
205
|
+
...props
|
|
206
|
+
}, ref) {
|
|
207
|
+
const generatedId = React.useId()
|
|
208
|
+
const resolvedSize = resolveSelectSize(density, size)
|
|
209
|
+
const resolvedDir = dir
|
|
210
|
+
const triggerVisualState = triggerProps?.disabled ? "disabled" : state
|
|
211
|
+
const isError = triggerVisualState === "error"
|
|
212
|
+
const selectedValue = value
|
|
213
|
+
const selectedPlaceholder = placeholder
|
|
214
|
+
const selectedLabel = label
|
|
215
|
+
const selectedOptional = optionalText
|
|
216
|
+
const selectedHelper = isError ? errorMessage : helperText
|
|
217
|
+
const shouldRenderLabel = hasLabel ?? hasRenderableContent(selectedLabel)
|
|
218
|
+
const shouldRenderHelperText =
|
|
219
|
+
hasHelperText ?? hasRenderableContent(selectedHelper)
|
|
220
|
+
const shouldShowLeadingIcon =
|
|
221
|
+
leadingIcon !== false &&
|
|
222
|
+
(hasLeadingIcon ?? hasRenderableContent(leadingIcon))
|
|
223
|
+
const shouldShowTrailingIcon =
|
|
224
|
+
trailingIcon !== false &&
|
|
225
|
+
(hasTrailingIcon ?? hasRenderableContent(trailingIcon))
|
|
226
|
+
const shouldRenderMenu = React.Children.count(children) > 0
|
|
227
|
+
const selectId = triggerId || generatedId
|
|
228
|
+
const helperId = `${selectId}-helper`
|
|
229
|
+
const triggerAccessibleLabel =
|
|
230
|
+
ariaLabel ??
|
|
231
|
+
(!shouldRenderLabel && !ariaLabelledBy
|
|
232
|
+
? getAccessibleText(selectedLabel)
|
|
233
|
+
: undefined)
|
|
234
|
+
const rootOpenProps =
|
|
235
|
+
open === undefined ? { onOpenChange } : { open, onOpenChange }
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<SelectPrimitive.Root
|
|
239
|
+
defaultValue={defaultSelectValue}
|
|
240
|
+
dir={resolvedDir === "auto" ? undefined : resolvedDir}
|
|
241
|
+
disabled={triggerVisualState === "disabled"}
|
|
242
|
+
onValueChange={onValueChange}
|
|
243
|
+
value={selectValue}
|
|
244
|
+
{...rootOpenProps}
|
|
245
|
+
>
|
|
246
|
+
<SelectRoot
|
|
247
|
+
data-density={density}
|
|
248
|
+
data-size={resolvedSize}
|
|
249
|
+
data-state={triggerVisualState}
|
|
250
|
+
data-variant={variant}
|
|
251
|
+
dir={resolvedDir}
|
|
252
|
+
ref={ref}
|
|
253
|
+
className={className}
|
|
254
|
+
{...props}
|
|
255
|
+
>
|
|
256
|
+
{shouldRenderLabel ? (
|
|
257
|
+
<SelectLabel
|
|
258
|
+
hasInformationIcon={hasInformationIcon}
|
|
259
|
+
htmlFor={selectId}
|
|
260
|
+
isOptional={isOptional}
|
|
261
|
+
isRequired={isRequired}
|
|
262
|
+
optionalText={selectedOptional}
|
|
263
|
+
>
|
|
264
|
+
{selectedLabel}
|
|
265
|
+
</SelectLabel>
|
|
266
|
+
) : null}
|
|
267
|
+
|
|
268
|
+
<div data-slot="select-control" className="relative w-full">
|
|
269
|
+
<SelectPrimitive.Trigger asChild>
|
|
270
|
+
<SelectTrigger
|
|
271
|
+
aria-label={triggerAccessibleLabel}
|
|
272
|
+
aria-labelledby={ariaLabelledBy}
|
|
273
|
+
aria-describedby={shouldRenderHelperText ? helperId : undefined}
|
|
274
|
+
aria-haspopup="listbox"
|
|
275
|
+
aria-invalid={isError || undefined}
|
|
276
|
+
expandIcon={expandIcon}
|
|
277
|
+
id={selectId}
|
|
278
|
+
leadingIcon={
|
|
279
|
+
shouldShowLeadingIcon
|
|
280
|
+
? (leadingIcon ?? <SelectIcon name="user" />)
|
|
281
|
+
: false
|
|
282
|
+
}
|
|
283
|
+
onClick={onTriggerClick}
|
|
284
|
+
placeholder={selectedPlaceholder}
|
|
285
|
+
size={resolvedSize}
|
|
286
|
+
state={triggerVisualState}
|
|
287
|
+
trailingIcon={
|
|
288
|
+
shouldShowTrailingIcon
|
|
289
|
+
? (trailingIcon ?? <SelectIcon name="info" />)
|
|
290
|
+
: false
|
|
291
|
+
}
|
|
292
|
+
value={selectedValue}
|
|
293
|
+
variant={variant}
|
|
294
|
+
className={triggerClassName}
|
|
295
|
+
{...triggerProps}
|
|
296
|
+
/>
|
|
297
|
+
</SelectPrimitive.Trigger>
|
|
298
|
+
|
|
299
|
+
{shouldRenderMenu ? (
|
|
300
|
+
<RadixSelectMenuContent forceMount={open === true || undefined}>
|
|
301
|
+
{children}
|
|
302
|
+
</RadixSelectMenuContent>
|
|
303
|
+
) : null}
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
{shouldRenderHelperText ? (
|
|
307
|
+
<SelectHelperText
|
|
308
|
+
hasIcon={hasHelperIcon}
|
|
309
|
+
id={helperId}
|
|
310
|
+
type={isError ? "error" : "default"}
|
|
311
|
+
>
|
|
312
|
+
{selectedHelper}
|
|
313
|
+
</SelectHelperText>
|
|
314
|
+
) : null}
|
|
315
|
+
</SelectRoot>
|
|
316
|
+
</SelectPrimitive.Root>
|
|
317
|
+
)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
type RadixSelectMenuContentProps = React.ComponentProps<typeof SelectPrimitive.Content>
|
|
321
|
+
// Radix sideOffset requires a number; this mirrors --bh-select-menu-offset.
|
|
322
|
+
const SELECT_MENU_SIDE_OFFSET_PX = 4
|
|
323
|
+
// Radix collisionPadding requires a number; this mirrors --bh-space-md-8.
|
|
324
|
+
const SELECT_MENU_COLLISION_PADDING_PX = 8
|
|
325
|
+
|
|
326
|
+
function RadixSelectMenuContent({
|
|
327
|
+
children,
|
|
328
|
+
className,
|
|
329
|
+
collisionPadding = SELECT_MENU_COLLISION_PADDING_PX,
|
|
330
|
+
position = "popper",
|
|
331
|
+
sideOffset = SELECT_MENU_SIDE_OFFSET_PX,
|
|
332
|
+
...props
|
|
333
|
+
}: RadixSelectMenuContentProps) {
|
|
334
|
+
return (
|
|
335
|
+
<SelectPrimitive.Content
|
|
336
|
+
asChild
|
|
337
|
+
collisionPadding={collisionPadding}
|
|
338
|
+
position={position}
|
|
339
|
+
sideOffset={sideOffset}
|
|
340
|
+
{...props}
|
|
341
|
+
>
|
|
342
|
+
<div
|
|
343
|
+
data-slot="select-menu"
|
|
344
|
+
className={cn(
|
|
345
|
+
selectMenu(),
|
|
346
|
+
"absolute start-0 top-[calc(100%+var(--bh-select-menu-offset))] z-[var(--bh-z-popover)]",
|
|
347
|
+
className
|
|
348
|
+
)}
|
|
349
|
+
>
|
|
350
|
+
<SelectPrimitive.Viewport asChild>
|
|
351
|
+
<div data-slot="select-menu-list" className={selectMenuList()}>
|
|
352
|
+
<SelectRadixItemContext.Provider value>
|
|
353
|
+
{children}
|
|
354
|
+
</SelectRadixItemContext.Provider>
|
|
355
|
+
</div>
|
|
356
|
+
</SelectPrimitive.Viewport>
|
|
357
|
+
</div>
|
|
358
|
+
</SelectPrimitive.Content>
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
type SelectRootProps = React.ComponentProps<"div">
|
|
363
|
+
|
|
364
|
+
const SelectRoot = React.forwardRef<HTMLDivElement, SelectRootProps>(function SelectRoot(
|
|
365
|
+
{ className, ...props },
|
|
366
|
+
ref
|
|
367
|
+
) {
|
|
368
|
+
return (
|
|
369
|
+
<div
|
|
370
|
+
data-slot="select-root"
|
|
371
|
+
ref={ref}
|
|
372
|
+
className={cn(selectRoot(), className)}
|
|
373
|
+
{...props}
|
|
374
|
+
/>
|
|
375
|
+
)
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
type SelectLabelProps = React.ComponentProps<"label"> & {
|
|
379
|
+
hasInformationIcon?: boolean
|
|
380
|
+
isOptional?: boolean
|
|
381
|
+
isRequired?: boolean
|
|
382
|
+
optionalText?: React.ReactNode
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function SelectLabel({
|
|
386
|
+
children,
|
|
387
|
+
className,
|
|
388
|
+
hasInformationIcon = false,
|
|
389
|
+
isOptional = false,
|
|
390
|
+
isRequired = false,
|
|
391
|
+
optionalText,
|
|
392
|
+
...props
|
|
393
|
+
}: SelectLabelProps) {
|
|
394
|
+
return (
|
|
395
|
+
<label
|
|
396
|
+
data-slot="select-label"
|
|
397
|
+
className={cn(
|
|
398
|
+
"flex w-full items-center gap-[var(--bh-select-label-gap)] text-start",
|
|
399
|
+
className
|
|
400
|
+
)}
|
|
401
|
+
{...props}
|
|
402
|
+
>
|
|
403
|
+
<span
|
|
404
|
+
data-slot="select-label-text"
|
|
405
|
+
dir="auto"
|
|
406
|
+
className="min-w-0 shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-sm-medium-font-size)] font-[var(--bh-text-body-sm-medium-font-weight)] leading-[var(--bh-text-body-sm-medium-line-height)] tracking-[var(--bh-text-body-sm-medium-letter-spacing)] text-[var(--bh-content-default)] rtl:text-[length:var(--bh-text-body-xs-medium-font-size)] rtl:font-[var(--bh-text-body-xs-medium-font-weight)] rtl:leading-[var(--bh-text-body-xs-medium-line-height)] rtl:tracking-[var(--bh-text-body-xs-medium-letter-spacing)]"
|
|
407
|
+
>
|
|
408
|
+
{children}
|
|
409
|
+
</span>
|
|
410
|
+
{isRequired ? (
|
|
411
|
+
<span
|
|
412
|
+
aria-hidden="true"
|
|
413
|
+
data-slot="select-label-required"
|
|
414
|
+
className="shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)] text-[var(--bh-content-danger-default)]"
|
|
415
|
+
>
|
|
416
|
+
*
|
|
417
|
+
</span>
|
|
418
|
+
) : null}
|
|
419
|
+
{isOptional && hasRenderableContent(optionalText) ? (
|
|
420
|
+
<span
|
|
421
|
+
data-slot="select-label-optional"
|
|
422
|
+
dir="auto"
|
|
423
|
+
className="min-w-0 shrink-0 whitespace-nowrap text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)] text-[var(--bh-content-subtle)]"
|
|
424
|
+
>
|
|
425
|
+
{optionalText}
|
|
426
|
+
</span>
|
|
427
|
+
) : null}
|
|
428
|
+
{hasInformationIcon ? (
|
|
429
|
+
<SelectIcon
|
|
430
|
+
name="info"
|
|
431
|
+
className="text-[var(--bh-select-trigger-icon-color)]"
|
|
432
|
+
/>
|
|
433
|
+
) : null}
|
|
434
|
+
</label>
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function hasRenderableContent(content: React.ReactNode) {
|
|
439
|
+
return (
|
|
440
|
+
content !== undefined &&
|
|
441
|
+
content !== null &&
|
|
442
|
+
content !== false &&
|
|
443
|
+
content !== ""
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function getAccessibleText(content: React.ReactNode) {
|
|
448
|
+
return typeof content === "string" || typeof content === "number"
|
|
449
|
+
? String(content)
|
|
450
|
+
: undefined
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
type SelectHelperTextProps = React.ComponentProps<"p"> & {
|
|
454
|
+
hasIcon?: boolean
|
|
455
|
+
type?: "default" | "error"
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function SelectHelperText({
|
|
459
|
+
children,
|
|
460
|
+
className,
|
|
461
|
+
hasIcon = false,
|
|
462
|
+
type = "default",
|
|
463
|
+
...props
|
|
464
|
+
}: SelectHelperTextProps) {
|
|
465
|
+
const isError = type === "error"
|
|
466
|
+
|
|
467
|
+
return (
|
|
468
|
+
<p
|
|
469
|
+
data-slot="select-helper-text"
|
|
470
|
+
data-type={type}
|
|
471
|
+
className={cn(
|
|
472
|
+
"flex w-full items-center gap-[var(--bh-select-label-gap)] text-start text-[length:var(--bh-text-body-xs-regular-font-size)] font-[var(--bh-text-body-xs-regular-font-weight)] leading-[var(--bh-text-body-xs-regular-line-height)] tracking-[var(--bh-text-body-xs-regular-letter-spacing)]",
|
|
473
|
+
isError
|
|
474
|
+
? "text-[var(--bh-content-danger-default)]"
|
|
475
|
+
: "text-[var(--bh-content-subtle)]",
|
|
476
|
+
className
|
|
477
|
+
)}
|
|
478
|
+
{...props}
|
|
479
|
+
>
|
|
480
|
+
{hasIcon ? (
|
|
481
|
+
<SelectIcon
|
|
482
|
+
name={isError ? "error" : "info"}
|
|
483
|
+
className={
|
|
484
|
+
isError
|
|
485
|
+
? "text-[var(--bh-content-danger-default)]"
|
|
486
|
+
: "text-[var(--bh-select-trigger-icon-color)]"
|
|
487
|
+
}
|
|
488
|
+
/>
|
|
489
|
+
) : null}
|
|
490
|
+
<span data-slot="select-helper-label" dir="auto" className="min-w-0 flex-1">
|
|
491
|
+
{children}
|
|
492
|
+
</span>
|
|
493
|
+
</p>
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
type SelectTriggerProps = Omit<
|
|
498
|
+
React.ComponentProps<"button">,
|
|
499
|
+
"children" | "value"
|
|
500
|
+
> &
|
|
501
|
+
VariantProps<typeof selectTrigger> & {
|
|
502
|
+
density?: ControlDensity
|
|
503
|
+
expandIcon?: React.ReactNode | false
|
|
504
|
+
leadingIcon?: React.ReactNode | false
|
|
505
|
+
placeholder?: React.ReactNode
|
|
506
|
+
trailingIcon?: React.ReactNode | false
|
|
507
|
+
value?: React.ReactNode
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const SelectTrigger = React.forwardRef<HTMLButtonElement, SelectTriggerProps>(
|
|
511
|
+
(
|
|
512
|
+
{
|
|
513
|
+
className,
|
|
514
|
+
density,
|
|
515
|
+
disabled,
|
|
516
|
+
expandIcon,
|
|
517
|
+
leadingIcon,
|
|
518
|
+
placeholder,
|
|
519
|
+
size,
|
|
520
|
+
state,
|
|
521
|
+
trailingIcon,
|
|
522
|
+
type = "button",
|
|
523
|
+
value,
|
|
524
|
+
variant = "default",
|
|
525
|
+
...props
|
|
526
|
+
},
|
|
527
|
+
ref
|
|
528
|
+
) => {
|
|
529
|
+
const resolvedSize = resolveSelectSize(density, size)
|
|
530
|
+
const hasValue = value !== undefined && value !== null && value !== ""
|
|
531
|
+
const visualState = disabled ? "disabled" : state ?? (hasValue ? "filled" : "default")
|
|
532
|
+
const isDisabled = visualState === "disabled"
|
|
533
|
+
|
|
534
|
+
return (
|
|
535
|
+
<button
|
|
536
|
+
data-density={density}
|
|
537
|
+
data-size={resolvedSize}
|
|
538
|
+
data-slot="select-trigger"
|
|
539
|
+
data-state={visualState}
|
|
540
|
+
data-variant={variant}
|
|
541
|
+
disabled={isDisabled}
|
|
542
|
+
ref={ref}
|
|
543
|
+
type={type}
|
|
544
|
+
className={cn(
|
|
545
|
+
selectTrigger({ size: resolvedSize, state: visualState, variant }),
|
|
546
|
+
className
|
|
547
|
+
)}
|
|
548
|
+
{...props}
|
|
549
|
+
>
|
|
550
|
+
<span
|
|
551
|
+
data-slot="select-trigger-main"
|
|
552
|
+
className="flex min-w-0 flex-1 items-center gap-[var(--bh-select-content-gap)]"
|
|
553
|
+
>
|
|
554
|
+
{hasRenderableContent(leadingIcon) ? (
|
|
555
|
+
<span
|
|
556
|
+
data-slot="select-leading-icon"
|
|
557
|
+
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
558
|
+
>
|
|
559
|
+
{leadingIcon}
|
|
560
|
+
</span>
|
|
561
|
+
) : null}
|
|
562
|
+
|
|
563
|
+
<span
|
|
564
|
+
data-slot="select-value-wrap"
|
|
565
|
+
className="flex min-w-0 flex-1 items-center ps-[var(--bh-select-value-padding-inline)]"
|
|
566
|
+
>
|
|
567
|
+
<span
|
|
568
|
+
data-slot="select-value"
|
|
569
|
+
dir="auto"
|
|
570
|
+
className={cn(
|
|
571
|
+
"min-w-0 flex-1 truncate text-start text-[length:var(--bh-text-body-md-regular-font-size)] font-[var(--bh-text-body-md-regular-font-weight)] leading-[var(--bh-text-body-md-regular-line-height)] tracking-[var(--bh-text-body-md-regular-letter-spacing)]",
|
|
572
|
+
hasValue || visualState === "filled"
|
|
573
|
+
? "text-[var(--bh-content-default)]"
|
|
574
|
+
: "text-[var(--bh-content-subtle)]",
|
|
575
|
+
isDisabled && "text-[var(--bh-content-disabled)]"
|
|
576
|
+
)}
|
|
577
|
+
>
|
|
578
|
+
{hasValue ? value : placeholder}
|
|
579
|
+
</span>
|
|
580
|
+
</span>
|
|
581
|
+
</span>
|
|
582
|
+
|
|
583
|
+
{hasRenderableContent(trailingIcon) ? (
|
|
584
|
+
<span
|
|
585
|
+
data-slot="select-trailing-icon"
|
|
586
|
+
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
587
|
+
>
|
|
588
|
+
{trailingIcon}
|
|
589
|
+
</span>
|
|
590
|
+
) : null}
|
|
591
|
+
|
|
592
|
+
{expandIcon !== false ? (
|
|
593
|
+
<span
|
|
594
|
+
data-slot="select-expand-icon"
|
|
595
|
+
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center text-[var(--bh-select-trigger-icon-color)] group-data-[state=disabled]/select-trigger:text-[var(--bh-content-disabled)] [&_svg:not([class*='size-'])]:size-[var(--bh-select-icon-size)]"
|
|
596
|
+
>
|
|
597
|
+
{expandIcon ?? <SelectIcon name="chevron-down" />}
|
|
598
|
+
</span>
|
|
599
|
+
) : null}
|
|
600
|
+
</button>
|
|
601
|
+
)
|
|
602
|
+
}
|
|
603
|
+
)
|
|
604
|
+
SelectTrigger.displayName = "SelectTrigger"
|
|
605
|
+
|
|
606
|
+
type SelectMenuProps = React.ComponentProps<"div">
|
|
607
|
+
|
|
608
|
+
const SelectMenu = React.forwardRef<HTMLDivElement, SelectMenuProps>(function SelectMenu(
|
|
609
|
+
{
|
|
610
|
+
"aria-label": ariaLabel = "Options",
|
|
611
|
+
children,
|
|
612
|
+
className,
|
|
613
|
+
onKeyDown,
|
|
614
|
+
role,
|
|
615
|
+
...props
|
|
616
|
+
},
|
|
617
|
+
ref
|
|
618
|
+
) {
|
|
619
|
+
const handleKeyDown = React.useCallback(
|
|
620
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
621
|
+
onKeyDown?.(event)
|
|
622
|
+
if (event.defaultPrevented) return
|
|
623
|
+
|
|
624
|
+
if (event.key === "Escape") {
|
|
625
|
+
event.currentTarget.blur()
|
|
626
|
+
return
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (
|
|
630
|
+
event.key !== "ArrowDown" &&
|
|
631
|
+
event.key !== "ArrowUp" &&
|
|
632
|
+
event.key !== "Home" &&
|
|
633
|
+
event.key !== "End"
|
|
634
|
+
) {
|
|
635
|
+
return
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
const items = getFocusableSelectItems(event.currentTarget)
|
|
639
|
+
if (items.length === 0) return
|
|
640
|
+
|
|
641
|
+
event.preventDefault()
|
|
642
|
+
|
|
643
|
+
const activeItem = event.currentTarget.ownerDocument.activeElement
|
|
644
|
+
const currentIndex =
|
|
645
|
+
activeItem instanceof HTMLElement ? items.indexOf(activeItem) : -1
|
|
646
|
+
let nextIndex = currentIndex
|
|
647
|
+
|
|
648
|
+
if (event.key === "Home") nextIndex = 0
|
|
649
|
+
if (event.key === "End") nextIndex = items.length - 1
|
|
650
|
+
if (event.key === "ArrowDown") nextIndex = (currentIndex + 1) % items.length
|
|
651
|
+
if (event.key === "ArrowUp") {
|
|
652
|
+
nextIndex = currentIndex <= 0 ? items.length - 1 : currentIndex - 1
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
items[nextIndex]?.focus()
|
|
656
|
+
},
|
|
657
|
+
[onKeyDown]
|
|
658
|
+
)
|
|
659
|
+
|
|
660
|
+
return (
|
|
661
|
+
<div
|
|
662
|
+
aria-label={ariaLabel}
|
|
663
|
+
data-slot="select-menu"
|
|
664
|
+
onKeyDown={handleKeyDown}
|
|
665
|
+
ref={ref}
|
|
666
|
+
role={role || "listbox"}
|
|
667
|
+
className={cn(selectMenu(), className)}
|
|
668
|
+
{...props}
|
|
669
|
+
>
|
|
670
|
+
<div
|
|
671
|
+
data-slot="select-menu-list"
|
|
672
|
+
role="presentation"
|
|
673
|
+
className={selectMenuList()}
|
|
674
|
+
>
|
|
675
|
+
{children}
|
|
676
|
+
</div>
|
|
677
|
+
</div>
|
|
678
|
+
)
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
type SelectMenuItemBaseProps = Omit<
|
|
682
|
+
React.ComponentProps<"button">,
|
|
683
|
+
"children" | "type" | "value"
|
|
684
|
+
> & {
|
|
685
|
+
addonText?: React.ReactNode
|
|
686
|
+
children?: React.ReactNode
|
|
687
|
+
label?: React.ReactNode
|
|
688
|
+
type?: "button" | "submit" | "reset"
|
|
689
|
+
value?: string
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
type SelectMenuItemMediaProps =
|
|
693
|
+
| { itemType?: "default"; media?: React.ReactNode | false }
|
|
694
|
+
| {
|
|
695
|
+
itemType: Exclude<SelectItemType, "default">
|
|
696
|
+
media?: React.ReactNode | false
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
type SelectMenuItemSelectionProps =
|
|
700
|
+
| { selected?: boolean; selectionType?: "default" }
|
|
701
|
+
| { selected?: boolean; selectionType: "checkbox" }
|
|
702
|
+
|
|
703
|
+
type SelectMenuItemDynamicProps = {
|
|
704
|
+
itemType?: SelectItemType
|
|
705
|
+
media?: React.ReactNode | false
|
|
706
|
+
selected?: boolean
|
|
707
|
+
selectionType?: SelectSelectionType
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
type SelectMenuItemProps = SelectMenuItemBaseProps &
|
|
711
|
+
(
|
|
712
|
+
| (SelectMenuItemMediaProps & SelectMenuItemSelectionProps)
|
|
713
|
+
| SelectMenuItemDynamicProps
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
const SelectMenuItem = React.forwardRef<HTMLButtonElement, SelectMenuItemProps>(function SelectMenuItem({
|
|
717
|
+
addonText,
|
|
718
|
+
"aria-checked": ariaChecked,
|
|
719
|
+
"aria-selected": ariaSelected,
|
|
720
|
+
children,
|
|
721
|
+
className,
|
|
722
|
+
disabled,
|
|
723
|
+
itemType = "default",
|
|
724
|
+
label,
|
|
725
|
+
media,
|
|
726
|
+
role,
|
|
727
|
+
selected = false,
|
|
728
|
+
selectionType = "default",
|
|
729
|
+
type = "button",
|
|
730
|
+
value,
|
|
731
|
+
...props
|
|
732
|
+
}, ref) {
|
|
733
|
+
const inRadixSelect = React.useContext(SelectRadixItemContext)
|
|
734
|
+
const generatedValue = React.useId()
|
|
735
|
+
const isDisabled = disabled
|
|
736
|
+
const selectedWithEndCheck = selected && selectionType === "default"
|
|
737
|
+
const resolvedRole = role || "option"
|
|
738
|
+
const usesCheckedState =
|
|
739
|
+
resolvedRole === "checkbox" ||
|
|
740
|
+
resolvedRole === "menuitemcheckbox" ||
|
|
741
|
+
resolvedRole === "radio" ||
|
|
742
|
+
resolvedRole === "menuitemradio"
|
|
743
|
+
const selectedMedia =
|
|
744
|
+
media === false ? null : media ?? getDefaultSelectItemMedia(itemType)
|
|
745
|
+
const content = label ?? children
|
|
746
|
+
const itemValue =
|
|
747
|
+
value ??
|
|
748
|
+
(typeof content === "string" || typeof content === "number"
|
|
749
|
+
? String(content)
|
|
750
|
+
: generatedValue)
|
|
751
|
+
const itemTextValue =
|
|
752
|
+
typeof content === "string" || typeof content === "number"
|
|
753
|
+
? String(content)
|
|
754
|
+
: undefined
|
|
755
|
+
|
|
756
|
+
const item = (
|
|
757
|
+
<button
|
|
758
|
+
aria-checked={usesCheckedState ? (ariaChecked ?? Boolean(selected)) : undefined}
|
|
759
|
+
aria-disabled={isDisabled || undefined}
|
|
760
|
+
aria-selected={resolvedRole === "option" ? (ariaSelected ?? Boolean(selected)) : undefined}
|
|
761
|
+
data-disabled={isDisabled ? "true" : undefined}
|
|
762
|
+
data-item-type={itemType}
|
|
763
|
+
data-selected={selected ? "true" : "false"}
|
|
764
|
+
data-selection-type={selectionType}
|
|
765
|
+
data-slot="select-menu-item"
|
|
766
|
+
disabled={isDisabled}
|
|
767
|
+
ref={ref}
|
|
768
|
+
role={resolvedRole}
|
|
769
|
+
type={type}
|
|
770
|
+
className={cn(selectMenuItem(), className)}
|
|
771
|
+
{...props}
|
|
772
|
+
>
|
|
773
|
+
<span
|
|
774
|
+
data-slot="select-menu-item-content"
|
|
775
|
+
className={selectMenuItemContent({
|
|
776
|
+
selected: selectedWithEndCheck,
|
|
777
|
+
})}
|
|
778
|
+
>
|
|
779
|
+
{selectionType === "checkbox" ? (
|
|
780
|
+
<span
|
|
781
|
+
data-slot="select-menu-item-checkbox-wrap"
|
|
782
|
+
className="flex size-[var(--bh-select-icon-slot-size)] shrink-0 items-center justify-center"
|
|
783
|
+
>
|
|
784
|
+
<SelectCheckboxIndicator checked={selected} disabled={isDisabled} />
|
|
785
|
+
</span>
|
|
786
|
+
) : null}
|
|
787
|
+
|
|
788
|
+
{selectedMedia ? (
|
|
789
|
+
<span
|
|
790
|
+
data-slot="select-menu-item-media"
|
|
791
|
+
className="flex shrink-0 items-center ps-[var(--bh-select-media-inset)] text-[var(--bh-content-subtle)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)] group-data-[disabled=true]/select-menu-item:opacity-[var(--bh-opacity-60)] [&_svg:not([class*='size-'])]:size-[var(--bh-icon-size-default)]"
|
|
792
|
+
>
|
|
793
|
+
{selectedMedia}
|
|
794
|
+
</span>
|
|
795
|
+
) : null}
|
|
796
|
+
|
|
797
|
+
<span
|
|
798
|
+
data-slot="select-menu-item-value"
|
|
799
|
+
className="flex min-w-0 items-center px-[var(--bh-select-item-value-padding-x)]"
|
|
800
|
+
>
|
|
801
|
+
<span
|
|
802
|
+
data-slot="select-menu-item-label"
|
|
803
|
+
dir="auto"
|
|
804
|
+
className="min-w-0 truncate text-start text-[length:var(--bh-text-body-md-regular-font-size)] font-[var(--bh-text-body-md-regular-font-weight)] leading-[var(--bh-text-body-md-regular-line-height)] tracking-[var(--bh-text-body-md-regular-letter-spacing)] text-[var(--bh-content-default)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)]"
|
|
805
|
+
>
|
|
806
|
+
{content}
|
|
807
|
+
</span>
|
|
808
|
+
</span>
|
|
809
|
+
|
|
810
|
+
{addonText !== undefined && addonText !== null ? (
|
|
811
|
+
<span
|
|
812
|
+
data-slot="select-menu-item-addon"
|
|
813
|
+
dir="auto"
|
|
814
|
+
className="min-w-0 shrink-0 truncate text-start text-[length:var(--bh-text-body-2xs-regular-font-size)] font-[var(--bh-text-body-2xs-regular-font-weight)] leading-[var(--bh-text-body-2xs-regular-line-height)] tracking-[var(--bh-text-body-2xs-regular-letter-spacing)] text-[var(--bh-content-muted)] group-hover/select-menu-item:text-[var(--bh-content-subtle)] group-focus-visible/select-menu-item:text-[var(--bh-content-subtle)] group-data-[disabled=true]/select-menu-item:text-[var(--bh-content-disabled)]"
|
|
815
|
+
>
|
|
816
|
+
{addonText}
|
|
817
|
+
</span>
|
|
818
|
+
) : null}
|
|
819
|
+
</span>
|
|
820
|
+
|
|
821
|
+
{selectedWithEndCheck ? (
|
|
822
|
+
<span
|
|
823
|
+
aria-hidden="true"
|
|
824
|
+
data-slot="select-menu-item-check"
|
|
825
|
+
className="pointer-events-none absolute end-[var(--bh-select-item-check-offset)] top-1/2 flex size-[var(--bh-select-icon-slot-size)] -translate-y-1/2 items-center justify-center text-[var(--bh-select-check-color)]"
|
|
826
|
+
>
|
|
827
|
+
<SelectIcon name="check-line" />
|
|
828
|
+
</span>
|
|
829
|
+
) : null}
|
|
830
|
+
</button>
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
if (!inRadixSelect) return item
|
|
834
|
+
|
|
835
|
+
return (
|
|
836
|
+
<SelectPrimitive.Item
|
|
837
|
+
asChild
|
|
838
|
+
disabled={isDisabled}
|
|
839
|
+
textValue={itemTextValue}
|
|
840
|
+
value={itemValue}
|
|
841
|
+
>
|
|
842
|
+
{item}
|
|
843
|
+
</SelectPrimitive.Item>
|
|
844
|
+
)
|
|
845
|
+
})
|
|
846
|
+
|
|
847
|
+
function getFocusableSelectItems(root: HTMLElement) {
|
|
848
|
+
return Array.from(
|
|
849
|
+
root.querySelectorAll<HTMLElement>(
|
|
850
|
+
'[role="option"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"])'
|
|
851
|
+
)
|
|
852
|
+
).filter((item) => !item.hasAttribute("disabled"))
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function resolveSelectSize(
|
|
856
|
+
density: ControlDensity | undefined,
|
|
857
|
+
size: SelectSize | null | undefined
|
|
858
|
+
): SelectSize {
|
|
859
|
+
if (density === "compact") return "md"
|
|
860
|
+
if (density === "default") return "lg"
|
|
861
|
+
if (density === "comfortable") return "comfortable"
|
|
862
|
+
return size ?? "lg"
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
type SelectCheckboxIndicatorProps = {
|
|
866
|
+
checked?: boolean
|
|
867
|
+
className?: string
|
|
868
|
+
disabled?: boolean
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function SelectCheckboxIndicator({
|
|
872
|
+
checked = false,
|
|
873
|
+
className,
|
|
874
|
+
disabled = false,
|
|
875
|
+
}: SelectCheckboxIndicatorProps) {
|
|
876
|
+
return (
|
|
877
|
+
<span
|
|
878
|
+
aria-hidden="true"
|
|
879
|
+
data-checked={checked ? "true" : "false"}
|
|
880
|
+
data-disabled={disabled ? "true" : undefined}
|
|
881
|
+
data-slot="select-checkbox"
|
|
882
|
+
className={cn(
|
|
883
|
+
"relative size-[var(--bh-select-icon-slot-size)] shrink-0 overflow-hidden",
|
|
884
|
+
className
|
|
885
|
+
)}
|
|
886
|
+
>
|
|
887
|
+
<span
|
|
888
|
+
data-slot="select-checkbox-control"
|
|
889
|
+
className={cn(
|
|
890
|
+
"pointer-events-none absolute left-1/2 top-1/2 size-[var(--bh-select-checkbox-size)] -translate-x-1/2 -translate-y-1/2 rounded-[var(--bh-select-checkbox-radius)] shadow-[var(--elevation-select-checkbox)] [--bh-select-checkbox-border:var(--bh-border-input)] [--elevation-select-checkbox:inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-select-checkbox-border,var(--bh-border-input)),var(--elevation-component-default)]",
|
|
891
|
+
checked
|
|
892
|
+
? "bg-[var(--bh-interactive-checkbox-default)] [--bh-select-checkbox-border:transparent]"
|
|
893
|
+
: "bg-[var(--bh-bg-default)]",
|
|
894
|
+
disabled &&
|
|
895
|
+
"bg-[var(--bh-bg-disabled)] shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-border-disabled)]"
|
|
896
|
+
)}
|
|
897
|
+
/>
|
|
898
|
+
{checked ? (
|
|
899
|
+
<span className="absolute left-1/2 top-1/2 flex size-[var(--bh-select-checkbox-icon-size)] -translate-x-1/2 -translate-y-1/2 items-center justify-center text-[var(--bh-interactive-checkbox-content)]">
|
|
900
|
+
<SelectIcon name="check-fill" />
|
|
901
|
+
</span>
|
|
902
|
+
) : null}
|
|
903
|
+
</span>
|
|
904
|
+
)
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
export {
|
|
908
|
+
Select,
|
|
909
|
+
SelectCheckboxIndicator,
|
|
910
|
+
SelectHelperText,
|
|
911
|
+
SelectItemAvatar,
|
|
912
|
+
SelectItemCompanyLogo,
|
|
913
|
+
SelectItemPaymentIcon,
|
|
914
|
+
SelectItemStatusDot,
|
|
915
|
+
SelectLabel,
|
|
916
|
+
SelectMenu,
|
|
917
|
+
SelectMenuItem,
|
|
918
|
+
SelectRoot,
|
|
919
|
+
SelectTrigger,
|
|
920
|
+
selectMenu,
|
|
921
|
+
selectMenuItem,
|
|
922
|
+
selectRoot,
|
|
923
|
+
selectTrigger,
|
|
924
|
+
}
|
|
925
|
+
export type {
|
|
926
|
+
ControlDensity,
|
|
927
|
+
SelectItemType,
|
|
928
|
+
SelectMenuItemProps,
|
|
929
|
+
SelectProps,
|
|
930
|
+
SelectRootProps,
|
|
931
|
+
SelectSelectionType,
|
|
932
|
+
SelectSize,
|
|
933
|
+
SelectStatusTone,
|
|
934
|
+
SelectTriggerProps,
|
|
935
|
+
SelectVariant,
|
|
936
|
+
SelectVisualState,
|
|
937
|
+
}
|