banhaten 0.1.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/LICENSE +21 -0
- package/README.md +361 -0
- package/banhaten.config.example.json +13 -0
- package/package.json +59 -0
- package/registry/assets/activity-feed-avatar.png +0 -0
- package/registry/assets/avatars/avatar-01.jpg +0 -0
- package/registry/assets/avatars/avatar-02.jpg +0 -0
- package/registry/assets/avatars/avatar-03.jpg +0 -0
- package/registry/assets/avatars/avatar-04.jpg +0 -0
- package/registry/assets/avatars/avatar-05.jpg +0 -0
- package/registry/assets/avatars/avatar-06.jpg +0 -0
- package/registry/assets/avatars/avatar-07.jpg +0 -0
- package/registry/assets/avatars/avatar-08.jpg +0 -0
- package/registry/assets/avatars/avatar-09.jpg +0 -0
- package/registry/assets/avatars/avatar-10.jpg +0 -0
- package/registry/assets/avatars/avatar-11.jpg +0 -0
- package/registry/assets/avatars/avatar-12.jpg +0 -0
- package/registry/assets/avatars/avatar-13.jpg +0 -0
- package/registry/assets/avatars/avatar-14.jpg +0 -0
- package/registry/assets/avatars/avatar-15.jpg +0 -0
- package/registry/assets/avatars/avatar-16.jpg +0 -0
- package/registry/assets/avatars/avatar-17.jpg +0 -0
- package/registry/assets/avatars/avatar-18.jpg +0 -0
- package/registry/assets/avatars/avatar-19.jpg +0 -0
- package/registry/assets/avatars/avatar-20.jpg +0 -0
- package/registry/assets/avatars/avatar-21.jpg +0 -0
- package/registry/assets/avatars/avatar-22.jpg +0 -0
- package/registry/assets/avatars/avatar-23.jpg +0 -0
- package/registry/assets/avatars/avatar-24.jpg +0 -0
- package/registry/assets/avatars/avatar-25.jpg +0 -0
- package/registry/assets/avatars/avatar-26.jpg +0 -0
- package/registry/assets/avatars/avatar-27.jpg +0 -0
- package/registry/assets/avatars/avatar-28.jpg +0 -0
- package/registry/assets/avatars/avatar-29.jpg +0 -0
- package/registry/assets/avatars/avatar-30.jpg +0 -0
- package/registry/assets/avatars/avatar-31.jpg +0 -0
- package/registry/assets/avatars/avatar-32.jpg +0 -0
- package/registry/assets/avatars/avatar-33.jpg +0 -0
- package/registry/assets/avatars/avatar-34.jpg +0 -0
- package/registry/assets/avatars/avatar-35.jpg +0 -0
- package/registry/assets/image-assets.json +744 -0
- package/registry/assets/images/art-01.jpg +0 -0
- package/registry/assets/images/art-02.jpg +0 -0
- package/registry/assets/images/art-03.jpg +0 -0
- package/registry/assets/images/art-04.jpg +0 -0
- package/registry/assets/images/art-05.jpg +0 -0
- package/registry/assets/images/art-06.jpg +0 -0
- package/registry/assets/images/art-07.jpg +0 -0
- package/registry/assets/images/art-08.jpg +0 -0
- package/registry/assets/images/art-09.jpg +0 -0
- package/registry/assets/images/art-10.jpg +0 -0
- package/registry/assets/images/art-11.jpg +0 -0
- package/registry/assets/images/art-12.jpg +0 -0
- package/registry/assets/images/art-13.jpg +0 -0
- package/registry/assets/images/art-14.jpg +0 -0
- package/registry/assets/images/art-15.jpg +0 -0
- package/registry/assets/images/art-16.jpg +0 -0
- package/registry/assets/images/art-17.jpg +0 -0
- package/registry/assets/images/art-18.jpg +0 -0
- package/registry/assets/images/art-19.jpg +0 -0
- package/registry/assets/images/art-20.jpg +0 -0
- package/registry/assets/images/art-21.jpg +0 -0
- package/registry/assets/images/art-22.jpg +0 -0
- package/registry/assets/images/art-23.jpg +0 -0
- package/registry/assets/images/art-24.jpg +0 -0
- package/registry/assets/images/art-25.jpg +0 -0
- package/registry/assets/images/art-26.jpg +0 -0
- package/registry/assets/images/art-27.jpg +0 -0
- package/registry/assets/images/nature-01.jpg +0 -0
- package/registry/assets/images/nature-02.jpg +0 -0
- package/registry/assets/images/nature-03.jpg +0 -0
- package/registry/assets/images/nature-04.jpg +0 -0
- package/registry/assets/images/nature-05.jpg +0 -0
- package/registry/assets/images/nature-06.jpg +0 -0
- package/registry/assets/images/nature-07.jpg +0 -0
- package/registry/assets/images/nature-08.jpg +0 -0
- package/registry/assets/images/nature-09.jpg +0 -0
- package/registry/assets/images/nature-10.jpg +0 -0
- package/registry/assets/images/nature-11.jpg +0 -0
- package/registry/assets/images/nature-12.jpg +0 -0
- package/registry/assets/images/nature-13.jpg +0 -0
- package/registry/assets/images/nature-14.jpg +0 -0
- package/registry/assets/images/nature-15.jpg +0 -0
- package/registry/assets/images/nature-16.jpg +0 -0
- package/registry/assets/images/nature-17.jpg +0 -0
- package/registry/assets/images/nature-18.jpg +0 -0
- package/registry/assets/images/nature-19.jpg +0 -0
- package/registry/assets/images/nature-20.jpg +0 -0
- package/registry/components/accordion.tsx +119 -0
- package/registry/components/alert.tsx +282 -0
- package/registry/components/attribute.tsx +452 -0
- package/registry/components/avatar.tsx +142 -0
- package/registry/components/badge.tsx +567 -0
- package/registry/components/button-group.tsx +246 -0
- package/registry/components/button.tsx +102 -0
- package/registry/components/card.tsx +613 -0
- package/registry/components/checkbox.tsx +244 -0
- package/registry/components/date-picker.tsx +1143 -0
- package/registry/components/divider.tsx +82 -0
- package/registry/components/expanded/ActivityFeed.tsx +226 -0
- package/registry/components/expanded/Banner.tsx +145 -0
- package/registry/components/expanded/BannerBoard.tsx +225 -0
- package/registry/components/expanded/Breadcrumbs.tsx +156 -0
- package/registry/components/expanded/CatalogComponentsShowcase.tsx +211 -0
- package/registry/components/expanded/CatalogDivider.tsx +48 -0
- package/registry/components/expanded/CatalogTag.tsx +92 -0
- package/registry/components/expanded/CommandBar.tsx +406 -0
- package/registry/components/expanded/FileUpload.tsx +231 -0
- package/registry/components/expanded/IconExplorer.tsx +612 -0
- package/registry/components/expanded/OnboardingStepListItem.tsx +67 -0
- package/registry/components/expanded/PageHeader.tsx +184 -0
- package/registry/components/expanded/Slideout.tsx +514 -0
- package/registry/components/expanded/Steps.tsx +266 -0
- package/registry/components/expanded/Table.tsx +1014 -0
- package/registry/components/expanded/Tabs.tsx +86 -0
- package/registry/components/expanded/Timeline.tsx +235 -0
- package/registry/components/expanded/TimelineShowcase.tsx +158 -0
- package/registry/components/expanded/activityFeed.css +292 -0
- package/registry/components/expanded/banner.css +312 -0
- package/registry/components/expanded/breadcrumbs.css +140 -0
- package/registry/components/expanded/catalogComponentsShowcase.css +87 -0
- package/registry/components/expanded/commandBar.css +473 -0
- package/registry/components/expanded/divider.css +75 -0
- package/registry/components/expanded/fileUpload.css +228 -0
- package/registry/components/expanded/iconExplorer.css +764 -0
- package/registry/components/expanded/iconPacks.ts +866 -0
- package/registry/components/expanded/onboardingStepListItem.css +126 -0
- package/registry/components/expanded/pageHeader.css +287 -0
- package/registry/components/expanded/slideout.css +955 -0
- package/registry/components/expanded/steps.css +329 -0
- package/registry/components/expanded/table.css +607 -0
- package/registry/components/expanded/tabs.css +197 -0
- package/registry/components/expanded/tag.css +148 -0
- package/registry/components/expanded/timeline.css +282 -0
- package/registry/components/input-content.ts +106 -0
- package/registry/components/input.tsx +866 -0
- package/registry/components/menu.tsx +758 -0
- package/registry/components/modal.tsx +799 -0
- package/registry/components/pagination.tsx +543 -0
- package/registry/components/progress-slider.tsx +216 -0
- package/registry/components/progress.tsx +367 -0
- package/registry/components/radio-card.tsx +654 -0
- package/registry/components/radio-group.tsx +570 -0
- package/registry/components/select-content.tsx +313 -0
- package/registry/components/select.tsx +871 -0
- package/registry/components/slider.tsx +380 -0
- package/registry/components/social-button.tsx +360 -0
- package/registry/components/spinner.tsx +31 -0
- package/registry/components/tag.tsx +423 -0
- package/registry/components/textarea.tsx +625 -0
- package/registry/components/toggle.tsx +272 -0
- package/registry/components/toolbar.tsx +467 -0
- package/registry/components/tooltip.tsx +427 -0
- package/registry/examples/accordion-demo.tsx +34 -0
- package/registry/examples/alert-demo.tsx +14 -0
- package/registry/examples/attribute-demo.tsx +65 -0
- package/registry/examples/avatar-demo.tsx +74 -0
- package/registry/examples/badge-demo.tsx +53 -0
- package/registry/examples/button-demo.tsx +83 -0
- package/registry/examples/button-group-demo.tsx +42 -0
- package/registry/examples/card-demo.tsx +48 -0
- package/registry/examples/checkbox-demo.tsx +67 -0
- package/registry/examples/date-picker-demo.tsx +74 -0
- package/registry/examples/divider-demo.tsx +17 -0
- package/registry/examples/expanded/activity-feed-demo.tsx +22 -0
- package/registry/examples/expanded/banner-demo.tsx +23 -0
- package/registry/examples/expanded/catalog-components-demo.tsx +5 -0
- package/registry/examples/expanded/command-bar-demo.tsx +10 -0
- package/registry/examples/expanded/icons-demo.tsx +5 -0
- package/registry/examples/expanded/onboarding-step-demo.tsx +11 -0
- package/registry/examples/expanded/page-header-demo.tsx +19 -0
- package/registry/examples/expanded/slideout-demo.tsx +15 -0
- package/registry/examples/expanded/steps-demo.tsx +18 -0
- package/registry/examples/expanded/tabs-demo.tsx +13 -0
- package/registry/examples/expanded/timeline-demo.tsx +18 -0
- package/registry/examples/input-demo.tsx +87 -0
- package/registry/examples/menu-demo.tsx +109 -0
- package/registry/examples/modal-demo.tsx +16 -0
- package/registry/examples/pagination-demo.tsx +17 -0
- package/registry/examples/progress-demo.tsx +37 -0
- package/registry/examples/progress-slider-demo.tsx +29 -0
- package/registry/examples/radio-card-demo.tsx +51 -0
- package/registry/examples/radio-group-demo.tsx +62 -0
- package/registry/examples/select-demo.tsx +73 -0
- package/registry/examples/slider-demo.tsx +31 -0
- package/registry/examples/social-button-demo.tsx +51 -0
- package/registry/examples/tag-demo.tsx +29 -0
- package/registry/examples/textarea-demo.tsx +79 -0
- package/registry/examples/toggle-demo.tsx +59 -0
- package/registry/examples/toolbar-demo.tsx +80 -0
- package/registry/examples/tooltip-demo.tsx +115 -0
- package/registry/hooks/use-direction.ts +27 -0
- package/registry/index.json +1213 -0
- package/registry/styles/globals.css +4600 -0
- package/registry/utils/cn.ts +6 -0
- package/src/cli/index.js +826 -0
- package/tokens/Color mode.zip +0 -0
- package/tokens/Numbers.zip +0 -0
- package/tokens/Radius.zip +0 -0
- package/tokens/Theme.zip +0 -0
- package/tokens/banhaten.tokens.json +5525 -0
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
|
|
8
|
+
type RadioGroupOrientation = "vertical" | "horizontal"
|
|
9
|
+
type RadioGroupVisualState = "default" | "error" | "disabled"
|
|
10
|
+
type RadioFieldControlPosition = "start" | "end"
|
|
11
|
+
|
|
12
|
+
const radioRoot = cva(
|
|
13
|
+
"group/radio relative inline-grid size-[var(--bh-space-4xl-20)] shrink-0 place-items-center rounded-[var(--bh-radius-full)]"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const radioControl = cva([
|
|
17
|
+
"pointer-events-none flex size-[var(--bh-space-3xl-16)] items-center justify-center rounded-[var(--bh-radius-full)]",
|
|
18
|
+
"bg-[var(--bh-bg-default)] shadow-[var(--shadow-radio-control)] transition-[background-color,box-shadow]",
|
|
19
|
+
"[--bh-radio-control-border:var(--bh-border-input)]",
|
|
20
|
+
"group-data-[invalid=true]/radio:[--bh-radio-control-border:var(--bh-border-danger-strong)]",
|
|
21
|
+
"group-hover/radio-field:[--bh-radio-control-border:var(--bh-border-brand-strong)]",
|
|
22
|
+
"peer-checked:bg-[var(--bh-interactive-radiobutton-default)] peer-checked:[--bh-radio-control-border:transparent]",
|
|
23
|
+
"peer-focus-visible:shadow-[var(--shadow-radio-control),var(--shadow-button-focus)]",
|
|
24
|
+
"peer-disabled:bg-[var(--bh-bg-disabled)] peer-disabled:shadow-[inset_0px_0px_0px_var(--bh-border-width-default)_var(--bh-border-disabled)]",
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
const radioGroupRoot = cva(
|
|
28
|
+
"m-0 grid min-w-0 border-0 p-0 text-start [min-inline-size:0]",
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
state: {
|
|
32
|
+
default: "",
|
|
33
|
+
error: "",
|
|
34
|
+
disabled: "",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
state: "default",
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const radioGroupItems = cva("flex min-w-0", {
|
|
44
|
+
variants: {
|
|
45
|
+
orientation: {
|
|
46
|
+
vertical: "flex-col gap-[var(--bh-space-xl-12)]",
|
|
47
|
+
horizontal:
|
|
48
|
+
"flex-row flex-wrap items-start gap-x-[var(--bh-space-3xl-16)] gap-y-[var(--bh-space-xl-12)]",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
defaultVariants: {
|
|
52
|
+
orientation: "vertical",
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const radioField = cva(
|
|
57
|
+
"group/radio-field inline-flex min-w-0 max-w-full gap-[var(--bh-space-lg-10)] text-start",
|
|
58
|
+
{
|
|
59
|
+
variants: {
|
|
60
|
+
controlPosition: {
|
|
61
|
+
start: "",
|
|
62
|
+
end: "justify-between",
|
|
63
|
+
},
|
|
64
|
+
density: {
|
|
65
|
+
compact: "items-center",
|
|
66
|
+
stacked: "items-start",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
defaultVariants: {
|
|
70
|
+
controlPosition: "start",
|
|
71
|
+
density: "compact",
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
type RadioProps = Omit<React.ComponentProps<"input">, "size" | "type"> &
|
|
77
|
+
VariantProps<typeof radioRoot> & {
|
|
78
|
+
controlClassName?: string
|
|
79
|
+
indicatorClassName?: string
|
|
80
|
+
inputClassName?: string
|
|
81
|
+
invalid?: boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const Radio = React.forwardRef<HTMLInputElement, RadioProps>(function Radio({
|
|
85
|
+
className,
|
|
86
|
+
controlClassName,
|
|
87
|
+
indicatorClassName,
|
|
88
|
+
inputClassName,
|
|
89
|
+
invalid = false,
|
|
90
|
+
...props
|
|
91
|
+
}, ref) {
|
|
92
|
+
return (
|
|
93
|
+
<span
|
|
94
|
+
data-invalid={invalid ? "true" : undefined}
|
|
95
|
+
data-slot="radio"
|
|
96
|
+
className={cn(radioRoot({ className }))}
|
|
97
|
+
>
|
|
98
|
+
<input
|
|
99
|
+
data-slot="radio-input"
|
|
100
|
+
ref={ref}
|
|
101
|
+
type="radio"
|
|
102
|
+
className={cn(
|
|
103
|
+
"peer absolute inset-0 z-[var(--bh-z-raised)] m-0 size-full cursor-pointer appearance-none rounded-[var(--bh-radius-full)] opacity-0 outline-none disabled:cursor-not-allowed",
|
|
104
|
+
inputClassName
|
|
105
|
+
)}
|
|
106
|
+
{...props}
|
|
107
|
+
/>
|
|
108
|
+
<span
|
|
109
|
+
aria-hidden="true"
|
|
110
|
+
data-slot="radio-control"
|
|
111
|
+
className={cn(radioControl(), controlClassName)}
|
|
112
|
+
>
|
|
113
|
+
<span
|
|
114
|
+
data-slot="radio-indicator"
|
|
115
|
+
className={cn(
|
|
116
|
+
"size-[var(--bh-space-sm-6)] rounded-[var(--bh-radius-full)] bg-[var(--bh-bg-always-white)] opacity-[var(--bh-opacity-0)] transition-opacity peer-checked:opacity-[var(--bh-opacity-100)] peer-disabled:bg-[var(--bh-content-disabled)]",
|
|
117
|
+
indicatorClassName
|
|
118
|
+
)}
|
|
119
|
+
/>
|
|
120
|
+
</span>
|
|
121
|
+
</span>
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
Radio.displayName = "Radio"
|
|
125
|
+
|
|
126
|
+
type RadioGroupContextValue = {
|
|
127
|
+
disabled?: boolean
|
|
128
|
+
invalid?: boolean
|
|
129
|
+
name: string
|
|
130
|
+
onValueChange: (value: string) => void
|
|
131
|
+
required?: boolean
|
|
132
|
+
value?: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const RadioGroupContext = React.createContext<RadioGroupContextValue | null>(
|
|
136
|
+
null
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
type RadioGroupProps = Omit<
|
|
140
|
+
React.ComponentProps<"fieldset">,
|
|
141
|
+
"children" | "defaultValue" | "onChange"
|
|
142
|
+
> &
|
|
143
|
+
VariantProps<typeof radioGroupRoot> & {
|
|
144
|
+
children?: React.ReactNode
|
|
145
|
+
defaultValue?: string
|
|
146
|
+
description?: React.ReactNode
|
|
147
|
+
errorMessage?: React.ReactNode
|
|
148
|
+
hasDescription?: boolean
|
|
149
|
+
hasLabel?: boolean
|
|
150
|
+
isOptional?: boolean
|
|
151
|
+
isRequired?: boolean
|
|
152
|
+
itemsClassName?: string
|
|
153
|
+
label?: React.ReactNode
|
|
154
|
+
name?: string
|
|
155
|
+
onValueChange?: (value: string) => void
|
|
156
|
+
optionalText?: React.ReactNode
|
|
157
|
+
orientation?: RadioGroupOrientation
|
|
158
|
+
required?: boolean
|
|
159
|
+
state?: RadioGroupVisualState
|
|
160
|
+
value?: string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const RadioGroup = React.forwardRef<HTMLFieldSetElement, RadioGroupProps>(
|
|
164
|
+
function RadioGroup({
|
|
165
|
+
children,
|
|
166
|
+
className,
|
|
167
|
+
defaultValue,
|
|
168
|
+
description,
|
|
169
|
+
disabled,
|
|
170
|
+
errorMessage,
|
|
171
|
+
hasDescription,
|
|
172
|
+
hasLabel,
|
|
173
|
+
isOptional = false,
|
|
174
|
+
isRequired = false,
|
|
175
|
+
itemsClassName,
|
|
176
|
+
label,
|
|
177
|
+
name,
|
|
178
|
+
onValueChange,
|
|
179
|
+
optionalText,
|
|
180
|
+
orientation = "vertical",
|
|
181
|
+
required,
|
|
182
|
+
state = "default",
|
|
183
|
+
value,
|
|
184
|
+
...props
|
|
185
|
+
}, ref) {
|
|
186
|
+
const generatedId = React.useId()
|
|
187
|
+
const groupName = name ?? `radio-group-${generatedId.replace(/:/g, "")}`
|
|
188
|
+
const isControlled = value !== undefined
|
|
189
|
+
const [uncontrolledValue, setUncontrolledValue] =
|
|
190
|
+
React.useState(defaultValue)
|
|
191
|
+
const selectedValue = isControlled ? value : uncontrolledValue
|
|
192
|
+
const visualState: RadioGroupVisualState = disabled
|
|
193
|
+
? "disabled"
|
|
194
|
+
: errorMessage
|
|
195
|
+
? "error"
|
|
196
|
+
: state
|
|
197
|
+
const invalid = visualState === "error"
|
|
198
|
+
const labelId = `${generatedId}-label`
|
|
199
|
+
const descriptionId = `${generatedId}-description`
|
|
200
|
+
const errorId = `${generatedId}-error`
|
|
201
|
+
const shouldRenderLabel = hasLabel ?? hasRenderableContent(label)
|
|
202
|
+
const shouldRenderDescription =
|
|
203
|
+
hasDescription ?? hasRenderableContent(description)
|
|
204
|
+
const shouldRenderError = hasRenderableContent(errorMessage)
|
|
205
|
+
const describedBy = joinIds(
|
|
206
|
+
shouldRenderDescription ? descriptionId : undefined,
|
|
207
|
+
shouldRenderError ? errorId : undefined
|
|
208
|
+
)
|
|
209
|
+
const context = React.useMemo<RadioGroupContextValue>(
|
|
210
|
+
() => ({
|
|
211
|
+
disabled,
|
|
212
|
+
invalid,
|
|
213
|
+
name: groupName,
|
|
214
|
+
onValueChange: (nextValue) => {
|
|
215
|
+
if (!isControlled) setUncontrolledValue(nextValue)
|
|
216
|
+
onValueChange?.(nextValue)
|
|
217
|
+
},
|
|
218
|
+
required: isRequired || required,
|
|
219
|
+
value: selectedValue,
|
|
220
|
+
}),
|
|
221
|
+
[
|
|
222
|
+
disabled,
|
|
223
|
+
groupName,
|
|
224
|
+
invalid,
|
|
225
|
+
isControlled,
|
|
226
|
+
isRequired,
|
|
227
|
+
onValueChange,
|
|
228
|
+
required,
|
|
229
|
+
selectedValue,
|
|
230
|
+
]
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<fieldset
|
|
235
|
+
aria-describedby={describedBy}
|
|
236
|
+
aria-invalid={invalid || undefined}
|
|
237
|
+
data-orientation={orientation}
|
|
238
|
+
data-slot="radio-group"
|
|
239
|
+
data-state={visualState}
|
|
240
|
+
disabled={disabled}
|
|
241
|
+
ref={ref}
|
|
242
|
+
className={cn(radioGroupRoot({ state: visualState }), className)}
|
|
243
|
+
{...props}
|
|
244
|
+
>
|
|
245
|
+
{shouldRenderLabel ? (
|
|
246
|
+
<legend
|
|
247
|
+
data-slot="radio-group-label"
|
|
248
|
+
id={labelId}
|
|
249
|
+
className="m-0 flex max-w-full items-center gap-[var(--bh-space-xs-4)] p-0 text-start"
|
|
250
|
+
>
|
|
251
|
+
<span
|
|
252
|
+
data-slot="radio-group-label-text"
|
|
253
|
+
dir="auto"
|
|
254
|
+
className="min-w-0 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)]"
|
|
255
|
+
>
|
|
256
|
+
{label}
|
|
257
|
+
</span>
|
|
258
|
+
{isRequired || required ? (
|
|
259
|
+
<span
|
|
260
|
+
aria-hidden="true"
|
|
261
|
+
data-slot="radio-group-required"
|
|
262
|
+
className="shrink-0 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)]"
|
|
263
|
+
>
|
|
264
|
+
*
|
|
265
|
+
</span>
|
|
266
|
+
) : null}
|
|
267
|
+
{isOptional && hasRenderableContent(optionalText) ? (
|
|
268
|
+
<span
|
|
269
|
+
data-slot="radio-group-optional"
|
|
270
|
+
dir="auto"
|
|
271
|
+
className="min-w-0 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)]"
|
|
272
|
+
>
|
|
273
|
+
{optionalText}
|
|
274
|
+
</span>
|
|
275
|
+
) : null}
|
|
276
|
+
</legend>
|
|
277
|
+
) : null}
|
|
278
|
+
|
|
279
|
+
{shouldRenderDescription ? (
|
|
280
|
+
<p
|
|
281
|
+
data-slot="radio-group-description"
|
|
282
|
+
dir="auto"
|
|
283
|
+
id={descriptionId}
|
|
284
|
+
className={cn(
|
|
285
|
+
shouldRenderLabel && "mt-[var(--bh-space-xxs-2)]",
|
|
286
|
+
"m-0 max-w-[var(--bh-radio-group-message-max-width)] 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)]"
|
|
287
|
+
)}
|
|
288
|
+
>
|
|
289
|
+
{description}
|
|
290
|
+
</p>
|
|
291
|
+
) : null}
|
|
292
|
+
|
|
293
|
+
<RadioGroupContext.Provider value={context}>
|
|
294
|
+
<div
|
|
295
|
+
data-orientation={orientation}
|
|
296
|
+
data-slot="radio-group-items"
|
|
297
|
+
className={cn(
|
|
298
|
+
(shouldRenderLabel || shouldRenderDescription) &&
|
|
299
|
+
"mt-[var(--bh-space-md-8)]",
|
|
300
|
+
radioGroupItems({ orientation }),
|
|
301
|
+
itemsClassName
|
|
302
|
+
)}
|
|
303
|
+
>
|
|
304
|
+
{children}
|
|
305
|
+
</div>
|
|
306
|
+
</RadioGroupContext.Provider>
|
|
307
|
+
|
|
308
|
+
{shouldRenderError ? (
|
|
309
|
+
<p
|
|
310
|
+
data-slot="radio-group-error"
|
|
311
|
+
dir="auto"
|
|
312
|
+
id={errorId}
|
|
313
|
+
className="m-0 mt-[var(--bh-space-md-8)] max-w-[var(--bh-radio-group-message-max-width)] 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)]"
|
|
314
|
+
>
|
|
315
|
+
{errorMessage}
|
|
316
|
+
</p>
|
|
317
|
+
) : null}
|
|
318
|
+
</fieldset>
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
)
|
|
322
|
+
RadioGroup.displayName = "RadioGroup"
|
|
323
|
+
|
|
324
|
+
type RadioFieldInputProps = Omit<
|
|
325
|
+
RadioProps,
|
|
326
|
+
| "checked"
|
|
327
|
+
| "className"
|
|
328
|
+
| "controlClassName"
|
|
329
|
+
| "defaultChecked"
|
|
330
|
+
| "disabled"
|
|
331
|
+
| "indicatorClassName"
|
|
332
|
+
| "inputClassName"
|
|
333
|
+
| "invalid"
|
|
334
|
+
| "name"
|
|
335
|
+
| "onChange"
|
|
336
|
+
| "required"
|
|
337
|
+
| "type"
|
|
338
|
+
| "value"
|
|
339
|
+
>
|
|
340
|
+
|
|
341
|
+
type RadioFieldProps = Omit<
|
|
342
|
+
React.ComponentProps<"label">,
|
|
343
|
+
"children" | "onChange"
|
|
344
|
+
> &
|
|
345
|
+
VariantProps<typeof radioField> & {
|
|
346
|
+
checked?: boolean
|
|
347
|
+
controlPosition?: RadioFieldControlPosition
|
|
348
|
+
defaultChecked?: boolean
|
|
349
|
+
description?: React.ReactNode
|
|
350
|
+
disabled?: boolean
|
|
351
|
+
inputClassName?: string
|
|
352
|
+
inputProps?: RadioFieldInputProps
|
|
353
|
+
invalid?: boolean
|
|
354
|
+
label: React.ReactNode
|
|
355
|
+
name?: string
|
|
356
|
+
onCheckedChange?: (checked: boolean) => void
|
|
357
|
+
radioClassName?: string
|
|
358
|
+
required?: boolean
|
|
359
|
+
value?: string
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const RadioField = React.forwardRef<HTMLLabelElement, RadioFieldProps>(
|
|
363
|
+
function RadioField(props, ref) {
|
|
364
|
+
return <RadioFieldBase ref={ref} {...props} />
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
RadioField.displayName = "RadioField"
|
|
368
|
+
|
|
369
|
+
type RadioGroupItemProps = Omit<
|
|
370
|
+
React.ComponentProps<"label">,
|
|
371
|
+
"children" | "onChange"
|
|
372
|
+
> &
|
|
373
|
+
VariantProps<typeof radioField> & {
|
|
374
|
+
controlPosition?: RadioFieldControlPosition
|
|
375
|
+
description?: React.ReactNode
|
|
376
|
+
disabled?: boolean
|
|
377
|
+
inputClassName?: string
|
|
378
|
+
inputProps?: RadioFieldInputProps
|
|
379
|
+
label: React.ReactNode
|
|
380
|
+
onCheckedChange?: (checked: boolean) => void
|
|
381
|
+
radioClassName?: string
|
|
382
|
+
value: string
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const RadioGroupItem = React.forwardRef<HTMLLabelElement, RadioGroupItemProps>(
|
|
386
|
+
function RadioGroupItem({
|
|
387
|
+
disabled,
|
|
388
|
+
inputProps,
|
|
389
|
+
onCheckedChange,
|
|
390
|
+
value,
|
|
391
|
+
...props
|
|
392
|
+
}, ref) {
|
|
393
|
+
const group = React.useContext(RadioGroupContext)
|
|
394
|
+
const isChecked = group?.value === value
|
|
395
|
+
const isDisabled = disabled || group?.disabled
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<RadioFieldBase
|
|
399
|
+
ref={ref}
|
|
400
|
+
checked={group ? isChecked : undefined}
|
|
401
|
+
disabled={isDisabled}
|
|
402
|
+
inputProps={inputProps}
|
|
403
|
+
invalid={group?.invalid}
|
|
404
|
+
name={group?.name}
|
|
405
|
+
onCheckedChange={(checked) => {
|
|
406
|
+
if (checked) group?.onValueChange(value)
|
|
407
|
+
onCheckedChange?.(checked)
|
|
408
|
+
}}
|
|
409
|
+
required={group?.required}
|
|
410
|
+
value={value}
|
|
411
|
+
{...props}
|
|
412
|
+
/>
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
)
|
|
416
|
+
RadioGroupItem.displayName = "RadioGroupItem"
|
|
417
|
+
|
|
418
|
+
type RadioFieldBaseProps = RadioFieldProps
|
|
419
|
+
|
|
420
|
+
const RadioFieldBase = React.forwardRef<HTMLLabelElement, RadioFieldBaseProps>(
|
|
421
|
+
function RadioFieldBase({
|
|
422
|
+
checked,
|
|
423
|
+
className,
|
|
424
|
+
controlPosition = "start",
|
|
425
|
+
defaultChecked,
|
|
426
|
+
description,
|
|
427
|
+
disabled,
|
|
428
|
+
inputClassName,
|
|
429
|
+
inputProps,
|
|
430
|
+
invalid = false,
|
|
431
|
+
label,
|
|
432
|
+
name,
|
|
433
|
+
onCheckedChange,
|
|
434
|
+
radioClassName,
|
|
435
|
+
required,
|
|
436
|
+
value,
|
|
437
|
+
...props
|
|
438
|
+
}, ref) {
|
|
439
|
+
const generatedId = React.useId()
|
|
440
|
+
const descriptionId = `${generatedId}-description`
|
|
441
|
+
const hasDescription = hasRenderableContent(description)
|
|
442
|
+
const isDisabled = disabled
|
|
443
|
+
const density = hasDescription ? "stacked" : "compact"
|
|
444
|
+
const ariaDescribedBy = joinIds(
|
|
445
|
+
inputProps?.["aria-describedby"],
|
|
446
|
+
hasDescription ? descriptionId : undefined
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
const control = (
|
|
450
|
+
<span
|
|
451
|
+
data-slot="radio-field-control"
|
|
452
|
+
className={cn(
|
|
453
|
+
"inline-flex shrink-0",
|
|
454
|
+
hasDescription && "pt-[var(--bh-space-xxs-2)]"
|
|
455
|
+
)}
|
|
456
|
+
>
|
|
457
|
+
<Radio
|
|
458
|
+
{...inputProps}
|
|
459
|
+
aria-describedby={ariaDescribedBy}
|
|
460
|
+
aria-invalid={invalid || undefined}
|
|
461
|
+
checked={checked}
|
|
462
|
+
className={radioClassName}
|
|
463
|
+
defaultChecked={defaultChecked}
|
|
464
|
+
disabled={isDisabled}
|
|
465
|
+
inputClassName={inputClassName}
|
|
466
|
+
invalid={invalid}
|
|
467
|
+
name={name}
|
|
468
|
+
onChange={(event) => {
|
|
469
|
+
if (event.currentTarget.checked) onCheckedChange?.(true)
|
|
470
|
+
}}
|
|
471
|
+
required={required}
|
|
472
|
+
value={value}
|
|
473
|
+
/>
|
|
474
|
+
</span>
|
|
475
|
+
)
|
|
476
|
+
const content = (
|
|
477
|
+
<span
|
|
478
|
+
data-slot="radio-field-content"
|
|
479
|
+
className="flex min-w-0 flex-1 flex-col items-start gap-[var(--bh-space-xxs-2)]"
|
|
480
|
+
>
|
|
481
|
+
<span
|
|
482
|
+
data-slot="radio-field-label"
|
|
483
|
+
dir="auto"
|
|
484
|
+
className={cn(
|
|
485
|
+
"min-w-0 break-words text-[length:var(--bh-text-body-md-regular-font-size)] 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]/radio-field:text-[var(--bh-content-disabled)]",
|
|
486
|
+
hasDescription
|
|
487
|
+
? "font-[var(--bh-text-body-md-medium-font-weight)]"
|
|
488
|
+
: "font-[var(--bh-text-body-md-regular-font-weight)]"
|
|
489
|
+
)}
|
|
490
|
+
>
|
|
491
|
+
{label}
|
|
492
|
+
</span>
|
|
493
|
+
{hasDescription ? (
|
|
494
|
+
<span
|
|
495
|
+
data-slot="radio-field-description"
|
|
496
|
+
dir="auto"
|
|
497
|
+
id={descriptionId}
|
|
498
|
+
className="min-w-0 break-words text-[length:var(--bh-text-body-sm-regular-font-size)] font-[var(--bh-text-body-sm-regular-font-weight)] leading-[var(--bh-text-body-sm-regular-line-height)] tracking-[var(--bh-text-body-sm-regular-letter-spacing)] text-[var(--bh-content-subtle)] group-data-[disabled=true]/radio-field:text-[var(--bh-content-disabled)]"
|
|
499
|
+
>
|
|
500
|
+
{description}
|
|
501
|
+
</span>
|
|
502
|
+
) : null}
|
|
503
|
+
</span>
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
return (
|
|
507
|
+
<label
|
|
508
|
+
data-checked={checked ? "true" : "false"}
|
|
509
|
+
data-disabled={isDisabled ? "true" : undefined}
|
|
510
|
+
data-invalid={invalid ? "true" : undefined}
|
|
511
|
+
data-slot="radio-field"
|
|
512
|
+
ref={ref}
|
|
513
|
+
className={cn(
|
|
514
|
+
radioField({ controlPosition, density }),
|
|
515
|
+
isDisabled ? "cursor-not-allowed" : "cursor-pointer",
|
|
516
|
+
className
|
|
517
|
+
)}
|
|
518
|
+
{...props}
|
|
519
|
+
>
|
|
520
|
+
{controlPosition === "start" ? (
|
|
521
|
+
<>
|
|
522
|
+
{control}
|
|
523
|
+
{content}
|
|
524
|
+
</>
|
|
525
|
+
) : (
|
|
526
|
+
<>
|
|
527
|
+
{content}
|
|
528
|
+
{control}
|
|
529
|
+
</>
|
|
530
|
+
)}
|
|
531
|
+
</label>
|
|
532
|
+
)
|
|
533
|
+
}
|
|
534
|
+
)
|
|
535
|
+
RadioFieldBase.displayName = "RadioFieldBase"
|
|
536
|
+
|
|
537
|
+
function hasRenderableContent(content: React.ReactNode) {
|
|
538
|
+
return (
|
|
539
|
+
content !== undefined &&
|
|
540
|
+
content !== null &&
|
|
541
|
+
content !== false &&
|
|
542
|
+
content !== ""
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function joinIds(...ids: Array<string | undefined | false>) {
|
|
547
|
+
const value = ids.filter(Boolean).join(" ")
|
|
548
|
+
return value || undefined
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export {
|
|
552
|
+
Radio,
|
|
553
|
+
RadioField,
|
|
554
|
+
RadioGroup,
|
|
555
|
+
RadioGroupItem,
|
|
556
|
+
radioControl,
|
|
557
|
+
radioField,
|
|
558
|
+
radioGroupItems,
|
|
559
|
+
radioGroupRoot,
|
|
560
|
+
radioRoot,
|
|
561
|
+
}
|
|
562
|
+
export type {
|
|
563
|
+
RadioFieldControlPosition,
|
|
564
|
+
RadioFieldProps,
|
|
565
|
+
RadioGroupItemProps,
|
|
566
|
+
RadioGroupOrientation,
|
|
567
|
+
RadioGroupProps,
|
|
568
|
+
RadioGroupVisualState,
|
|
569
|
+
RadioProps,
|
|
570
|
+
}
|