feat: add Disclosure DisclosureGroup and Accordion
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||
|
||||
/* Base accordion styles */
|
||||
.hv-accordion {
|
||||
@apply w-full;
|
||||
|
||||
/* Performance optimization - contain layout changes */
|
||||
contain: layout style;
|
||||
}
|
||||
|
||||
/* Accordion elements */
|
||||
.hv-accordion__body {
|
||||
@apply text-sm;
|
||||
}
|
||||
|
||||
.hv-accordion__body-inner {
|
||||
@apply px-4 pt-0 pb-4 text-muted;
|
||||
}
|
||||
|
||||
.hv-accordion__heading {
|
||||
@apply flex;
|
||||
}
|
||||
|
||||
.hv-accordion__indicator {
|
||||
@apply ms-auto size-4 shrink-0 text-muted;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
@apply transition duration-250 motion-reduce:transition-none;
|
||||
|
||||
/* Expanded state for indicator rotation */
|
||||
&[data-expanded="true"] {
|
||||
@apply -rotate-180;
|
||||
}
|
||||
}
|
||||
|
||||
/* Accordion Item - Separator styles */
|
||||
.hv-accordion__item {
|
||||
@apply relative border-none;
|
||||
}
|
||||
|
||||
.hv-accordion__item::after {
|
||||
content: "";
|
||||
@apply absolute start-0 bottom-0 h-px w-full rounded-xs bg-separator;
|
||||
}
|
||||
|
||||
.hv-accordion__item:last-child::after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
/* Hide separator when hideSeparator prop is set */
|
||||
.hv-accordion__item[data-hide-separator="true"]::after {
|
||||
display: none;
|
||||
}
|
||||
/* ------------------------------------ */
|
||||
|
||||
.hv-accordion__trigger {
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Base Styles */
|
||||
@apply flex flex-1 items-center justify-between px-4 py-4 text-start text-sm font-medium no-highlight;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
opacity 150ms var(--ease-out),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/**
|
||||
* Hover state
|
||||
* CRITICAL: inside `@media (hover: hover)` this keys off `:hover` alone. React Aria writes
|
||||
* `data-hovered` on a render tick, so on pointer leave the attribute outlives the native
|
||||
* `:hover` by at least a frame; including it here keeps this background painted for that frame,
|
||||
* after a custom `hover:bg-*` override has already stopped matching, and the default color
|
||||
* flashes on top. `:hover` is the same signal Tailwind's `hover:` variant compiles to, so the
|
||||
* default and any override switch in lockstep. `data-hovered` is still on the element for
|
||||
* consumers who want to key their own styles off it.
|
||||
*/
|
||||
@media (hover: hover) {
|
||||
&:hover:not([aria-expanded="true"]) {
|
||||
background-color: color-mix(
|
||||
in oklab,
|
||||
var(--foreground) 3%,
|
||||
transparent 90%
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled State */
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-accordion__panel {
|
||||
opacity: 0;
|
||||
height: var(--disclosure-panel-height);
|
||||
overflow: clip;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
height 200ms var(--ease-out-quad),
|
||||
opacity 200ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
&[data-expanded="true"] {
|
||||
will-change: height, opacity;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Surface variant */
|
||||
.hv-accordion--surface {
|
||||
@apply bg-surface;
|
||||
border-radius: min(32px, var(--radius-3xl));
|
||||
|
||||
.hv-accordion__trigger {
|
||||
/* See the base trigger hover state for why `data-hovered` is left out here. */
|
||||
@media (hover: hover) {
|
||||
&:hover:not([aria-expanded="true"]) {
|
||||
@apply bg-default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-accordion__item::after {
|
||||
@apply bg-surface-foreground/6;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-accordion--surface .hv-accordion__item {
|
||||
/* Surface variant separator styling */
|
||||
&::after {
|
||||
@apply start-[3%] w-[94%];
|
||||
}
|
||||
|
||||
/* Special rounding for first and last items in surface variant */
|
||||
&:first-child [data-slot="accordion-trigger"] {
|
||||
border-start-start-radius: min(32px, var(--radius-3xl));
|
||||
border-start-end-radius: min(32px, var(--radius-3xl));
|
||||
}
|
||||
|
||||
&:last-child:not(:has([data-slot="accordion-trigger"][aria-expanded="true"]))
|
||||
[data-slot="accordion-trigger"] {
|
||||
border-end-start-radius: min(32px, var(--radius-3xl));
|
||||
border-end-end-radius: min(32px, var(--radius-3xl));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||
|
||||
/* Base disclosure-group styles */
|
||||
.hv-disclosure-group {
|
||||
@apply w-full;
|
||||
|
||||
/* Performance optimization - contain layout changes */
|
||||
contain: layout style;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||
|
||||
/* Base disclosure styles */
|
||||
.hv-disclosure {
|
||||
@apply relative;
|
||||
}
|
||||
|
||||
.hv-disclosure__heading {
|
||||
@apply flex;
|
||||
}
|
||||
|
||||
.hv-disclosure__trigger {
|
||||
cursor: var(--cursor-interactive);
|
||||
/*
|
||||
* Baseline uses inline-block. Button is inline-flex; a later inline-block
|
||||
* would override it and break icon/text/indicator row layout when asChild
|
||||
* merges trigger styles onto Button. inline-flex keeps both cases aligned.
|
||||
*/
|
||||
@apply inline-flex items-center no-highlight;
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-disclosure__indicator {
|
||||
@apply ms-auto size-4 shrink-0 text-inherit;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
@apply transition duration-250 motion-reduce:transition-none;
|
||||
|
||||
/* Expanded state for indicator rotation */
|
||||
&[data-expanded="true"] {
|
||||
@apply -rotate-180;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Button's generic svg rule (specificity 0,2,2) sets margin-inline/-size on
|
||||
* every svg except spinner/link-icon. Beat it and restore end-alignment when
|
||||
* asChild merges the trigger onto Button.
|
||||
*/
|
||||
.hv-button svg.hv-disclosure__indicator[data-slot="disclosure-indicator"] {
|
||||
margin-block: 0;
|
||||
margin-inline: 0;
|
||||
margin-inline-start: auto;
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
/*
|
||||
* Height is always var(--disclosure-panel-height). The variable is driven
|
||||
* by useDisclosurePanelHeight (0px ↔ scrollHeight px → auto) so the CSS
|
||||
* transition matches React Aria / HeroUI. data-expanded only changes opacity.
|
||||
*/
|
||||
.hv-disclosure__content {
|
||||
opacity: 0;
|
||||
height: var(--disclosure-panel-height);
|
||||
overflow: clip;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
height 200ms var(--ease-out-quad),
|
||||
opacity 200ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
&[data-expanded="true"] {
|
||||
will-change: height, opacity;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-disclosure__body {
|
||||
@apply p-2;
|
||||
}
|
||||
|
||||
.hv-disclosure__body-inner {
|
||||
/* Inner wrapper keeps caller class on the scrolling/inner box. */
|
||||
}
|
||||
Reference in New Issue
Block a user