feat: migrate button groups and toggle buttons with focus regressions

This commit is contained in:
maoyingjie
2026-10-23 09:57:41 +08:00
parent 99df0f1c91
commit 9c93647ad2
61 changed files with 4535 additions and 10 deletions
+148
View File
@@ -0,0 +1,148 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* ==========================================================================
ButtonGroup - Groups related buttons together
========================================================================== */
/* Base button group styles */
.hv-button-group {
@apply inline-flex h-auto items-center justify-center gap-0;
}
/* ==========================================================================
Orientation variants
========================================================================== */
.hv-button-group--horizontal {
@apply flex-row;
}
.hv-button-group--vertical {
@apply flex-col;
}
/* Remove border radius from all buttons in group */
.hv-button-group .hv-button {
@apply rounded-none;
}
/* Apply border radius to first button (start edge) */
.hv-button-group--horizontal .hv-button:first-child {
@apply rounded-s-3xl;
}
/* Apply border radius to last button (end edge) */
.hv-button-group--horizontal .hv-button:last-child {
@apply rounded-e-3xl;
}
/* If only one button, apply both rounded edges */
.hv-button-group--horizontal .hv-button:first-child:last-child {
@apply rounded-3xl;
}
/* Apply border radius to first button (top edge) in vertical */
.hv-button-group--vertical .hv-button:first-child {
@apply rounded-t-3xl;
}
/* Apply border radius to last button (bottom edge) in vertical */
.hv-button-group--vertical .hv-button:last-child {
@apply rounded-b-3xl;
}
/* If only one button in vertical, apply all rounded edges */
.hv-button-group--vertical .hv-button:first-child:last-child {
@apply rounded-3xl;
}
/* Remove scale transform on active/pressed state for buttons in group */
.hv-button-group .hv-button:active,
.hv-button-group .hv-button[data-pressed="true"] {
transform: none;
}
/* Raise focused button so its outward focus ring + gap shows above adjacent buttons */
.hv-button-group .hv-button:focus-visible:not([data-focused]),
.hv-button-group .hv-button[data-focus-visible="true"] {
@apply z-10;
}
/* ==========================================================================
Separator (compound component)
========================================================================== */
.hv-button-group__separator {
@apply rounded-sm bg-current opacity-15;
position: absolute;
pointer-events: none;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
/* Horizontal orientation - vertical divider */
.hv-button-group--horizontal & {
inset-inline-start: -1px;
top: 25%;
width: 1px;
height: 50%;
}
/* Vertical orientation - horizontal divider */
.hv-button-group--vertical & {
inset-inline-start: 25%;
top: -1px;
width: 50%;
height: 1px;
}
}
/* ==========================================================================
Outline button border handling
========================================================================== */
/* Remove adjacent borders from outline buttons in horizontal group */
/* First button: remove end border (right in LTR, left in RTL) */
.hv-button-group--horizontal .hv-button--outline:first-child {
@apply border-e-0;
}
/* Last button: remove start border (left in LTR, right in RTL) */
.hv-button-group--horizontal .hv-button--outline:last-child {
@apply border-s-0;
}
/* Middle buttons: remove both inline borders */
.hv-button-group--horizontal
.hv-button--outline:not(:first-child):not(:last-child) {
@apply border-x-0;
}
/* Remove adjacent borders from outline buttons in vertical group */
/* First button: remove bottom border */
.hv-button-group--vertical .hv-button--outline:first-child {
@apply border-b-0;
}
/* Last button: remove top border */
.hv-button-group--vertical .hv-button--outline:last-child {
@apply border-t-0;
}
/* Middle buttons: remove both block borders */
.hv-button-group--vertical
.hv-button--outline:not(:first-child):not(:last-child) {
@apply border-y-0;
}
/* ==========================================================================
Full width modifier
========================================================================== */
.hv-button-group--full-width {
@apply w-full;
}
@@ -0,0 +1,138 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* ==========================================================================
ToggleButtonGroup - Groups multiple ToggleButtons into a unified control
========================================================================== */
/* Base styles */
.hv-toggle-button-group {
@apply inline-flex h-auto w-fit items-center justify-center gap-0;
}
/* ==========================================================================
Orientation variants
========================================================================== */
.hv-toggle-button-group--horizontal {
@apply flex-row;
}
.hv-toggle-button-group--vertical {
@apply flex-col;
}
/* ==========================================================================
Full width modifier
========================================================================== */
.hv-toggle-button-group--full-width {
@apply w-full;
}
/* ==========================================================================
Attached mode (default) - buttons connected with dividers
========================================================================== */
/* Remove border radius from all toggle buttons in attached group */
.hv-toggle-button-group .hv-toggle-button {
@apply rounded-none;
}
/* Apply border radius to first button (start edge) */
.hv-toggle-button-group--horizontal .hv-toggle-button:first-child {
@apply rounded-s-3xl;
}
/* Apply border radius to last button (end edge) */
.hv-toggle-button-group--horizontal .hv-toggle-button:last-child {
@apply rounded-e-3xl;
}
/* If only one button, apply both rounded edges */
.hv-toggle-button-group--horizontal .hv-toggle-button:first-child:last-child {
@apply rounded-3xl;
}
/* Apply border radius to first button (top edge) in vertical */
.hv-toggle-button-group--vertical .hv-toggle-button:first-child {
@apply rounded-t-3xl;
}
/* Apply border radius to last button (bottom edge) in vertical */
.hv-toggle-button-group--vertical .hv-toggle-button:last-child {
@apply rounded-b-3xl;
}
/* If only one button in vertical, apply all rounded edges */
.hv-toggle-button-group--vertical .hv-toggle-button:first-child:last-child {
@apply rounded-3xl;
}
/* Remove scale transform on active/pressed state for buttons in group */
.hv-toggle-button-group .hv-toggle-button:active,
.hv-toggle-button-group .hv-toggle-button[data-pressed="true"] {
transform: none;
}
/* Override focus ring to use inset style so it stays within button bounds */
.hv-toggle-button-group .hv-toggle-button:focus-visible:not([data-focused]),
.hv-toggle-button-group .hv-toggle-button[data-focus-visible="true"] {
--tw-ring-offset-width: 0px;
@apply ring-inset;
}
/* Full width: stretch each toggle button */
.hv-toggle-button-group--full-width .hv-toggle-button {
@apply flex-1;
}
/* ==========================================================================
Separator (compound component)
========================================================================== */
.hv-toggle-button-group__separator {
@apply rounded-sm bg-current opacity-15;
position: absolute;
pointer-events: none;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: opacity 150ms var(--ease-smooth);
@apply motion-reduce:transition-none;
/* Horizontal orientation - vertical divider */
.hv-toggle-button-group--horizontal & {
inset-inline-start: -1px;
top: 25%;
width: 1px;
height: 50%;
}
/* Vertical orientation - horizontal divider */
.hv-toggle-button-group--vertical & {
inset-inline-start: 25%;
top: -1px;
width: 50%;
height: 1px;
}
}
/* ==========================================================================
Detached mode - buttons separated with gaps
========================================================================== */
.hv-toggle-button-group--detached {
@apply gap-1;
}
/* Restore border radius in detached mode */
.hv-toggle-button-group--detached .hv-toggle-button {
@apply rounded-3xl;
}
/* Hide separators in detached mode */
.hv-toggle-button-group--detached .hv-toggle-button-group__separator {
display: none;
}
@@ -0,0 +1,151 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* ==========================================================================
ToggleButton - Interactive toggle control for on/off states
========================================================================== */
/* Base styles */
.hv-toggle-button {
@apply relative isolate inline-flex h-10 w-fit origin-center items-center justify-center gap-2 rounded-3xl px-4 text-sm font-medium whitespace-nowrap outline-none select-none no-highlight md:h-9;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
transform 250ms var(--ease-smooth),
background-color 100ms var(--ease-out),
box-shadow 100ms var(--ease-out);
@apply transform-gpu motion-reduce:transition-none;
/* Cursor */
cursor: var(--cursor-interactive);
/* Default tokens (unselected state) */
--toggle-button-bg: var(--default);
--toggle-button-bg-hover: var(--default-hover);
--toggle-button-bg-pressed: var(--default-hover);
--toggle-button-fg: currentColor;
/* Selected state tokens */
--toggle-button-bg-selected: var(--accent-soft);
--toggle-button-bg-selected-hover: var(--accent-soft-hover);
--toggle-button-bg-selected-pressed: var(--accent-soft-hover);
--toggle-button-fg-selected: var(--accent-soft-foreground);
background-color: var(--toggle-button-bg);
color: var(--toggle-button-fg);
/* Focus state */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
/* Disabled state */
&:disabled,
&[aria-disabled="true"] {
@apply status-disabled;
}
/* Hover */
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
background-color: var(--toggle-button-bg-hover);
}
}
/* Active / pressed */
&:active,
&[data-pressed="true"] {
background-color: var(--toggle-button-bg-pressed);
transform: scale(0.97);
}
/* Selected state */
&[data-selected="true"] {
background-color: var(--toggle-button-bg-selected);
color: var(--toggle-button-fg-selected);
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
background-color: var(--toggle-button-bg-selected-hover);
}
}
&:active,
&[data-pressed="true"] {
background-color: var(--toggle-button-bg-selected-pressed);
}
}
/* SVG icon styling */
& svg {
@apply pointer-events-none -mx-0.5 my-0.5 size-5 shrink-0 self-center sm:my-1 sm:size-4;
}
}
/* ==========================================================================
Size variants
========================================================================== */
.hv-toggle-button--sm {
@apply h-9 px-3 md:h-8;
& svg {
@apply size-4;
}
&:active,
&[data-pressed="true"] {
transform: scale(0.98);
}
}
.hv-toggle-button--md {
/* No styles as this is the default size */
}
.hv-toggle-button--lg {
@apply h-11 text-base md:h-10;
&:active,
&[data-pressed="true"] {
transform: scale(0.96);
}
}
/* ==========================================================================
Variant styles
========================================================================== */
.hv-toggle-button--default {
--toggle-button-bg: var(--default);
--toggle-button-bg-hover: var(--default-hover);
--toggle-button-bg-pressed: var(--default-hover);
}
.hv-toggle-button--ghost {
--toggle-button-bg: transparent;
--toggle-button-bg-hover: var(--default);
--toggle-button-bg-pressed: var(--default);
--toggle-button-fg: var(--default-foreground);
}
/* ==========================================================================
Icon-only modifier
========================================================================== */
.hv-toggle-button--icon-only {
@apply w-10 p-0 md:w-9;
}
.hv-toggle-button--icon-only.hv-toggle-button--sm {
@apply w-9 md:w-8;
}
.hv-toggle-button--icon-only.hv-toggle-button--lg {
@apply w-11 md:w-10;
}
+3
View File
@@ -130,3 +130,6 @@
@import "./components/scroll-shadow.css";
@import "./components/tabs.css";
@import "./components/button-group.css" layer(components);
@import "./components/toggle-button.css" layer(components);
@import "./components/toggle-button-group.css" layer(components);
+92
View File
@@ -1056,3 +1056,95 @@ export type TabsVariants = Omit<
VariantProps<typeof tabsVariants>,
TabsRenderPropsKeys
>;
export const buttonGroupVariants = tv({
defaultVariants: {
fullWidth: false,
orientation: "horizontal",
},
slots: {
base: "hv-button-group",
separator: "hv-button-group__separator",
},
variants: {
fullWidth: {
false: {},
true: {
base: "hv-button-group--full-width",
},
},
orientation: {
horizontal: {
base: "hv-button-group--horizontal",
},
vertical: {
base: "hv-button-group--vertical",
},
},
},
});
export type ButtonGroupVariants = VariantProps<typeof buttonGroupVariants>;
export const toggleButtonVariants = tv({
base: "hv-toggle-button",
defaultVariants: {
isIconOnly: false,
size: "md",
variant: "default",
},
variants: {
isIconOnly: {
true: "hv-toggle-button--icon-only",
},
size: {
lg: "hv-toggle-button--lg",
md: "hv-toggle-button--md",
sm: "hv-toggle-button--sm",
},
variant: {
default: "hv-toggle-button--default",
ghost: "hv-toggle-button--ghost",
},
},
});
export type ToggleButtonVariants = VariantProps<typeof toggleButtonVariants>;
export const toggleButtonGroupVariants = tv({
defaultVariants: {
fullWidth: false,
isDetached: false,
orientation: "horizontal",
},
slots: {
base: "hv-toggle-button-group",
separator: "hv-toggle-button-group__separator",
},
variants: {
fullWidth: {
false: {},
true: {
base: "hv-toggle-button-group--full-width",
},
},
isDetached: {
false: {},
true: {
base: "hv-toggle-button-group--detached",
},
},
orientation: {
horizontal: {
base: "hv-toggle-button-group--horizontal",
},
vertical: {
base: "hv-toggle-button-group--vertical",
},
},
},
});
export type ToggleButtonGroupVariants = VariantProps<
typeof toggleButtonGroupVariants
>;