feat: migrate ListBox with virtual collection and accessible parts
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/* Adapted from HeroUI ce90ea3. Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* ==========================================================================
|
||||
Base list-box item styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-list-box-item {
|
||||
@apply relative flex min-h-9 w-full items-center justify-start gap-3 rounded-2xl px-2 py-1.5 outline-none no-highlight;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out-quart),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/* Cursor */
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply pointer-events-none w-fit select-none;
|
||||
}
|
||||
|
||||
[data-slot="description"] {
|
||||
@apply pointer-events-none text-wrap select-none;
|
||||
}
|
||||
|
||||
/* Add inline-end padding when indicator is present */
|
||||
&:has(.hv-list-box-item__indicator) {
|
||||
@apply pe-7;
|
||||
}
|
||||
|
||||
/* Focus visible state (keyboard focus only).
|
||||
React Aria always sets data-focused when it owns the item, so the native
|
||||
fallback is scoped to consumers rendering this class outside React Aria. */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus,
|
||||
&[data-focus="true"] {
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
/* Hover state */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-default;
|
||||
}
|
||||
}
|
||||
|
||||
/* Selected state */
|
||||
&[aria-selected="true"],
|
||||
&[data-selected="true"] {
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
List-box item indicator
|
||||
========================================================================== */
|
||||
|
||||
.hv-list-box-item__indicator {
|
||||
@apply absolute end-2 top-1/2 flex size-4 shrink-0 -translate-y-1/2 items-center justify-center text-default-foreground;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
@apply transition duration-250 motion-reduce:transition-none;
|
||||
|
||||
/* Checkmark SVG indicator */
|
||||
[data-slot="list-box-item-indicator--checkmark"] {
|
||||
@apply size-2.5;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
*/
|
||||
@apply transition-all duration-300 motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
.hv-list-box-item[aria-selected="true"]
|
||||
[data-slot="list-box-item-indicator--checkmark"],
|
||||
.hv-list-box-item[data-selected="true"]
|
||||
[data-slot="list-box-item-indicator--checkmark"] {
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition: stroke-dashoffset 250ms linear;
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Default variant */
|
||||
.hv-list-box-item--default {
|
||||
}
|
||||
|
||||
/* Danger variant */
|
||||
.hv-list-box-item--danger {
|
||||
.hv-list-box-item__indicator {
|
||||
@apply text-danger;
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply text-danger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/* Adapted from HeroUI ce90ea3. Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* ==========================================================================
|
||||
Base list-box section styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-list-box-section {
|
||||
@apply flex flex-col items-start gap-0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Adapted from HeroUI ce90ea3. Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* ==========================================================================
|
||||
Base list-box styles
|
||||
========================================================================== */
|
||||
|
||||
.hv-list-box {
|
||||
@apply relative w-full overflow-clip p-1;
|
||||
|
||||
/**
|
||||
* Spacing between direct children.
|
||||
*
|
||||
* NOTE: We intentionally avoid `display: flex` + `gap` here because
|
||||
* react-aria's Virtualizer renders a `position: relative` content
|
||||
* div with an explicit large height (e.g. 50000px) as the only child
|
||||
* of the ListBox. Flex shrinking would collapse that height and break
|
||||
* scrollbar sizing during virtualized scroll.
|
||||
*/
|
||||
& > * + * {
|
||||
@apply mt-1;
|
||||
}
|
||||
|
||||
/* This makes the horizontal separator take up 94% of the width and be centered */
|
||||
[data-slot="separator"][data-orientation="horizontal"] {
|
||||
@apply ms-[3%] w-[94%];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user