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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user