feat: add Checkbox and Radio field families

This commit is contained in:
maoyingjie
2026-10-22 09:15:27 +08:00
parent a4fb3c550a
commit bcadbeaf8c
75 changed files with 5293 additions and 22 deletions
@@ -0,0 +1,9 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
.hv-checkbox-group {
@apply flex flex-col;
[data-slot="checkbox"] {
@apply mt-4;
}
}
+269
View File
@@ -0,0 +1,269 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; native reduced-motion media. */
/* ==========================================================================
Base checkbox styles
========================================================================== */
.hv-checkbox {
@apply flex flex-col items-start gap-1 outline-none no-highlight;
cursor: var(--cursor-interactive);
/* Field-level help text (siblings of the button), indented to align under the label */
& > [data-slot="description"],
& > [data-slot="field-error"] {
@apply w-full min-w-0 cursor-default ps-7 text-xs text-wrap wrap-break-word text-muted select-none;
}
[data-slot="label"] {
@apply select-none;
}
.hv-checkbox__content [data-slot="label"] {
cursor: var(--cursor-interactive);
}
/* Disabled state */
&[data-disabled="true"] {
@apply status-disabled;
[data-slot="description"],
[data-slot="field-error"] {
@apply status-disabled;
}
}
/* Indicator styles */
&[data-selected="true"],
&[data-indeterminate="true"] {
.hv-checkbox__indicator {
border-color: var(--accent-foreground);
}
}
/* Checkmark SVG indicator */
[data-slot="checkbox-default-indicator--checkmark"] {
@apply size-2.5 stroke-[2.5px] text-accent-foreground;
/**
* Transitions
*/
@apply transition-all duration-200 motion-reduce:transition-none;
}
&[data-selected="true"] [data-slot="checkbox-default-indicator--checkmark"] {
transition: stroke-dashoffset 150ms linear 15ms;
}
/* Invalid + Selected: checkmark icon color */
&[data-invalid="true"][data-selected="true"]
[data-slot="checkbox-default-indicator--checkmark"],
&[data-invalid="true"][aria-checked="true"]
[data-slot="checkbox-default-indicator--checkmark"],
&[aria-invalid="true"][data-selected="true"]
[data-slot="checkbox-default-indicator--checkmark"],
&[aria-invalid="true"][aria-checked="true"]
[data-slot="checkbox-default-indicator--checkmark"] {
@apply text-danger-foreground;
}
/* Indeterminate line indicator */
&[data-indeterminate="true"] {
[data-slot="checkbox-default-indicator--indeterminate"] {
@apply size-3;
}
}
/* Invalid + Indeterminate: indeterminate icon color */
&[data-indeterminate="true"][data-invalid="true"]
[data-slot="checkbox-default-indicator--indeterminate"],
&[data-indeterminate="true"][aria-invalid="true"]
[data-slot="checkbox-default-indicator--indeterminate"] {
@apply text-danger-foreground;
}
}
/* ==========================================================================
Checkbox control (the square button)
========================================================================== */
.hv-checkbox__control {
@apply relative inline-flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-md border [border-width:var(--border-width-field)] border-field-border bg-field shadow-field outline-none no-highlight;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
background-color 200ms var(--ease-out),
border-color 200ms var(--ease-out),
transform 100ms var(--ease-out);
@media (prefers-reduced-motion: reduce) {
transition: none;
}
cursor: var(--cursor-interactive);
/* Background indicator pseudo-element */
&::before {
@apply pointer-events-none absolute inset-0 z-0 origin-center scale-70 rounded-md bg-accent opacity-0 content-[''];
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
scale 100ms var(--ease-linear),
opacity 200ms var(--ease-linear),
background-color 200ms var(--ease-out);
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
/* Interactive states */
/* Focus */
.hv-checkbox:focus-visible &,
.hv-checkbox:has([data-slot="checkbox-content"][data-focus-visible="true"]) &,
.hv-checkbox [data-slot="checkbox-content"][data-focus-visible="true"] & {
@apply status-focused;
}
/* Hover */
.hv-checkbox:hover &,
.hv-checkbox:has([data-slot="checkbox-content"][data-hovered="true"]) &,
.hv-checkbox [data-slot="checkbox-content"][data-hovered="true"] & {
@apply border-field-border-hover;
&::before {
@apply bg-accent-hover;
}
}
/* Pressed */
.hv-checkbox:active &,
.hv-checkbox:has([data-slot="checkbox-content"][data-pressed="true"]) &,
.hv-checkbox [data-slot="checkbox-content"][data-pressed="true"] & {
}
/* Selection states */
/* Selected */
.hv-checkbox[aria-checked="true"] &,
.hv-checkbox[data-selected="true"] & {
@apply border-transparent text-accent-foreground;
&::before {
@apply scale-100 opacity-100;
}
}
/* Indeterminate */
.hv-checkbox[data-indeterminate="true"] & {
@apply bg-accent text-accent-foreground;
}
/* Indeterminate + Pressed */
.hv-checkbox:active[data-indeterminate="true"] &,
.hv-checkbox[data-pressed="true"][data-indeterminate="true"] &,
.hv-checkbox:has(
[data-slot="checkbox-content"][data-pressed="true"]
)[data-indeterminate="true"]
& {
@apply bg-accent-hover;
}
/* Validation states */
/* Invalid (only when not selected/indeterminate) */
.hv-checkbox[data-invalid="true"]:not([aria-checked="true"]):not(
[data-selected="true"]
):not([data-indeterminate="true"])
&,
.hv-checkbox[aria-invalid="true"]:not([aria-checked="true"]):not(
[data-selected="true"]
):not([data-indeterminate="true"])
& {
@apply status-invalid-field;
}
/* Invalid + Selected */
.hv-checkbox[data-invalid="true"][aria-checked="true"] &,
.hv-checkbox[data-invalid="true"][data-selected="true"] &,
.hv-checkbox[aria-invalid="true"][aria-checked="true"] &,
.hv-checkbox[aria-invalid="true"][data-selected="true"] & {
@apply border-transparent bg-danger text-danger-foreground;
&::before {
@apply scale-100 bg-danger opacity-100;
}
}
/* Invalid + Indeterminate */
.hv-checkbox[data-indeterminate="true"][aria-invalid="true"] &,
.hv-checkbox[data-indeterminate="true"][data-invalid="true"] & {
@apply bg-danger text-danger-foreground;
}
}
/* ==========================================================================
Checkbox indicator
========================================================================== */
.hv-checkbox__indicator {
@apply relative z-10 flex size-3 items-center justify-center;
& svg {
@apply size-full transform-gpu;
}
}
/* ==========================================================================
Variant property definitions
========================================================================== */
.hv-checkbox--primary {
/* Default styles */
}
.hv-checkbox--secondary .hv-checkbox__control {
@apply shadow-none;
background-color: var(--checkbox-control-bg);
--checkbox-control-bg: var(--default);
/* Hover state */
.hv-checkbox:hover &,
.hv-checkbox:has([data-slot="checkbox-content"][data-hovered="true"]) &,
.hv-checkbox [data-slot="checkbox-content"][data-hovered="true"] & {
@apply border-field-border-hover;
}
}
/* Checkbox content — the clickable label (control + label text) */
.hv-checkbox__content {
@apply relative inline-flex cursor-[inherit] items-center gap-3 text-sm font-medium text-foreground outline-none select-none no-highlight;
}
/* Unselected state background for secondary variant */
.hv-checkbox--secondary:not([aria-checked="true"]):not(
[data-selected="true"]
):not([data-indeterminate="true"])
.hv-checkbox__control {
background-color: var(--checkbox-control-bg);
}
/* Selected state on secondary variant */
.hv-checkbox--secondary[aria-checked="true"] .hv-checkbox__control,
.hv-checkbox--secondary[data-selected="true"] .hv-checkbox__control {
&::before {
@apply bg-accent;
}
}
/* Indeterminate state on secondary variant */
.hv-checkbox--secondary[data-indeterminate="true"] .hv-checkbox__control {
@apply bg-accent;
&::before {
@apply bg-accent;
}
}
@@ -0,0 +1,53 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
/* Radio Group base styles */
.hv-radio-group {
@apply flex flex-col;
/* Default orientation */
&[data-orientation="vertical"] {
[data-slot="radio"] {
@apply mt-4;
}
}
&[data-orientation="horizontal"] {
@apply flex-row flex-wrap gap-4;
}
}
/* Variant property definitions */
.hv-radio-group--primary {
/* Default styles */
}
.hv-radio-group--secondary .hv-radio__control {
@apply shadow-none;
background-color: var(--radio-control-bg);
--radio-control-bg: var(--default);
--radio-control-bg-hover: var(--default-hover);
/* Hover state */
.hv-radio:has([data-slot="radio-content"][data-hovered="true"]) &,
.hv-radio [data-slot="radio-content"][data-hovered="true"] & {
@apply border-field-border-hover;
}
/* Default indicator color (unselected) */
.hv-radio:not([data-selected]):not(:has(input:checked))
&
.hv-radio__indicator:empty::before {
background-color: var(--radio-control-bg);
}
/* Hover indicator color (unselected) */
.hv-radio:has([data-slot="radio-content"][data-hovered="true"]):not(
[data-selected]
):not(:has(input:checked))
& {
.hv-radio__indicator:empty::before {
background-color: var(--radio-control-bg-hover);
}
}
}
+193
View File
@@ -0,0 +1,193 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; native reduced-motion media. */
/* ==========================================================================
Base radio styles
Structure (explicit composition):
.hv-radio → RadioField wrapper (column)
.hv-radio__content → RadioButton: the clickable row (control + label)
.hv-radio__control
[data-slot="label"]
[data-slot="description"] → field-level sibling, below the row
[data-slot="field-error"]
========================================================================== */
.hv-radio {
@apply flex flex-col items-start gap-1 outline-none no-highlight;
cursor: var(--cursor-interactive);
[data-slot="label"] {
@apply select-none;
}
.hv-radio__content [data-slot="label"] {
cursor: var(--cursor-interactive);
}
/* Field-level help text (siblings of the button), indented to align under the label */
& > [data-slot="description"],
& > [data-slot="field-error"] {
@apply w-full min-w-0 cursor-default ps-7 text-xs text-wrap wrap-break-word text-muted select-none;
}
/* Disabled state */
&:disabled,
&[data-disabled="true"],
&[aria-disabled="true"] {
@apply status-disabled;
[data-slot="description"],
[data-slot="field-error"] {
@apply status-disabled;
}
}
}
/* Radio content — the clickable label (control + label text) */
.hv-radio__content {
@apply relative inline-flex cursor-[inherit] items-center gap-3 text-sm font-medium text-foreground outline-none select-none no-highlight;
}
/* ==========================================================================
Radio control (the circular button)
========================================================================== */
.hv-radio__control {
@apply relative inline-flex size-4 shrink-0 items-center justify-center rounded-lg border [border-width:var(--border-width-field)] border-field-border bg-field shadow-field outline-none no-highlight;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
background-color 200ms var(--ease-out),
border-color 200ms var(--ease-out),
transform 100ms var(--ease-out);
@media (prefers-reduced-motion: reduce) {
transition: none;
}
cursor: var(--cursor-interactive);
/* Interactive states */
/* Focus */
.hv-radio:has([data-slot="radio-content"][data-focus-visible="true"]) &,
.hv-radio [data-slot="radio-content"][data-focus-visible="true"] & {
@apply status-focused;
}
/* Hover */
.hv-radio:has([data-slot="radio-content"][data-hovered="true"]) &,
.hv-radio [data-slot="radio-content"][data-hovered="true"] & {
@apply border-field-border-hover;
}
/* Hover - only when not selected */
.hv-radio:has([data-slot="radio-content"][data-hovered="true"]):not(
[data-selected]
):not(:has(input:checked))
& {
.hv-radio__indicator:empty::before {
@apply bg-field-hover;
}
}
/* Pressed */
.hv-radio:has([data-slot="radio-content"][data-pressed="true"]) &,
.hv-radio [data-slot="radio-content"][data-pressed="true"] & {
@apply scale-95;
}
/* Selection states */
/* Selected */
.hv-radio[data-selected] &,
.hv-radio:has([data-slot="radio-content"][aria-checked="true"]) &,
.hv-radio:has(input:checked) & {
@apply border-transparent bg-accent;
}
/* Selected + Pressed */
.hv-radio[data-selected]:has([data-slot="radio-content"][data-pressed="true"])
&,
.hv-radio:has(
[data-slot="radio-content"][data-pressed="true"][aria-checked="true"]
)
&,
.hv-radio:has(input:checked):has(
[data-slot="radio-content"][data-pressed="true"]
)
& {
@apply bg-accent-hover;
}
/* Validation states */
/* Invalid */
.hv-radio[data-invalid="true"] &,
.hv-radio[aria-invalid="true"] & {
@apply status-invalid-field;
}
/* Invalid + Selected */
.hv-radio[data-invalid="true"][data-selected] &,
.hv-radio[aria-invalid="true"][data-selected] &,
.hv-radio[data-invalid="true"]:has(input:checked) &,
.hv-radio[aria-invalid="true"]:has(input:checked) & {
@apply status-invalid-field;
}
}
/* ==========================================================================
Radio indicator (the inner dot)
========================================================================== */
.hv-radio__indicator {
@apply absolute inset-0 flex items-center justify-center;
pointer-events: none;
}
/* :empty pseudo-class ensures these styles only apply when the indicator has no custom children
(e.g., custom icon). When custom content is present, these default dot styles are not applied. */
.hv-radio__indicator:empty::before {
content: "";
@apply rounded-lg bg-field;
width: 100%;
height: 100%;
scale: 1;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
scale 200ms var(--ease-out),
background-color 200ms var(--ease-out);
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
/* Selected state */
.hv-radio[data-selected] .hv-radio__indicator:empty::before,
.hv-radio:has([data-slot="radio-content"][aria-checked="true"])
.hv-radio__indicator:empty::before,
.hv-radio:has(input:checked) .hv-radio__indicator:empty::before {
@apply bg-accent-foreground;
scale: 0.4286; /* 6px */
}
/* Selected + Pressed state */
.hv-radio[data-selected]:has([data-slot="radio-content"][data-pressed="true"])
.hv-radio__indicator:empty::before,
.hv-radio:has(
[data-slot="radio-content"][data-pressed="true"][aria-checked="true"]
)
.hv-radio__indicator:empty::before,
.hv-radio:has(input:checked):has(
[data-slot="radio-content"][data-pressed="true"]
)
.hv-radio__indicator:empty::before {
scale: 0.5714; /* 8px */
}