@llselect/core
Version:
Low-level select: a minimal, flexible, framework-agnostic replacement for the native HTML select element.
487 lines (425 loc) • 19.2 kB
CSS
/* llselect - Tailwind CSS theme. Uses Tailwind v4 CSS custom properties
(`--color-*`) so users on v4 get their actual palette; falls back to the
default Tailwind values so this file works standalone on v3 or with no
Tailwind installed at all. */
/* Color variables: the light values. Every color below reads one of these,
so a host page restyles the select component by redefining them in a rule
that targets .llselect-root (README "Your own colors"). The dark values
are in the block at the end of this file. Roles, one per line. */
.llselect-root {
--llselect-fg: var(--color-slate-900, #0f172a); /* text inside the popup: header and footer slot content */
--llselect-control-fg: var(--llselect-fg); /* text of the trigger and of the filter input */
--llselect-fg-soft: var(--color-slate-500, #64748b); /* the arrow and the group labels */
--llselect-fg-muted: var(--color-slate-400, #94a3b8); /* the placeholder, the no-results text, the clear button at rest */
--llselect-bg: var(--color-white, #fff); /* surface of the trigger wrapper, the popup, the filter input, the pinned rows */
--llselect-bg-muted: var(--color-slate-50, #f8fafc); /* surface of the group labels */
--llselect-trigger-wrapper-line: var(--color-slate-300, #cbd5e1); /* border of the trigger wrapper */
--llselect-trigger-wrapper-hover-line: var(--color-slate-400, #94a3b8); /* border of the hovered trigger wrapper */
--llselect-popup-line: var(--color-slate-200, #e2e8f0); /* border of the popup */
--llselect-filter-line: var(--color-slate-300, #cbd5e1); /* border of the filter input */
--llselect-divider: rgba(0, 0, 0, 0.12); /* dividers before and after action rows and the choose-all row; header, footer and pinned-row edges */
--llselect-focus-line: var(--color-blue-500, #3b82f6); /* border of the trigger wrapper while focus is in it or the popup is open (vanilla: an outline, while focus is in it); outline of a focused trigger button */
--llselect-filter-focus-line: var(--color-blue-500, #3b82f6); /* border of the focused filter input */
--llselect-focus-ring: rgba(59, 130, 246, 0.3); /* ring shadow of the trigger wrapper while focus is in it or the popup is open (vanilla: unused) */
--llselect-filter-focus-ring: var(--color-blue-100, #dbeafe); /* ring shadow of the focused filter input (vanilla: unused) */
--llselect-shadow: rgba(0, 0, 0, 0.1); /* color of the popup shadow */
--llselect-control-shadow: transparent; /* color of the inset shadow of the trigger wrapper (read by bootstrap-3 only) */
--llselect-row-fg: var(--color-slate-700, #334155); /* text of a row */
--llselect-row-hover-bg: var(--color-slate-100, #f1f5f9); /* surface of a hovered row */
--llselect-row-hover-fg: var(--color-slate-900, #0f172a); /* text of a hovered row */
--llselect-row-focused-bg: var(--color-blue-50, #eff6ff); /* surface of the row that keyboard focus is on */
--llselect-row-focused-fg: var(--color-blue-700, #1d4ed8); /* text of that row */
--llselect-row-focused-hover-bg: var(--color-blue-100, #dbeafe); /* surface of that row while hovered */
--llselect-row-chosen-fg: var(--color-blue-600, #2563eb); /* text of a chosen row */
--llselect-tag-bg: var(--color-blue-50, #eff6ff); /* surface of a tag */
--llselect-tag-fg: var(--color-blue-700, #1d4ed8); /* text of a tag */
--llselect-tag-line: transparent; /* border of a tag */
--llselect-tag-remove-fg: var(--color-blue-400, #60a5fa); /* the x button of a tag */
--llselect-tag-remove-hover-bg: var(--color-blue-100, #dbeafe); /* surface of the hovered x button */
--llselect-tag-remove-hover-fg: var(--color-blue-700, #1d4ed8); /* the hovered x button */
--llselect-clear-hover-fg: var(--color-slate-600, #475569); /* the hovered clear button */
--llselect-clear-hover-bg: var(--color-slate-100, #f1f5f9); /* surface of the hovered clear button */
}
.llselect-root {
position: relative;
display: inline-block;
min-width: 14rem;
font-family:
var(--font-sans, ui-sans-serif, system-ui, sans-serif);
font-size: 0.875rem; /* text-sm */
color: var(--llselect-control-fg);
line-height: 1.25rem;
}
/* --- trigger -------------------------------------------------- */
.llselect-trigger-wrapper {
display: flex;
align-items: center;
padding: 0.5rem 0.75rem; /* py-2 px-3 */
border: 1px solid var(--llselect-trigger-wrapper-line);
border-radius: 0.375rem; /* rounded-md */
background-color: var(--llselect-bg);
color: inherit;
cursor: pointer;
user-select: none;
transition:
border-color 150ms,
box-shadow 150ms;
}
.llselect-trigger-wrapper:hover {
border-color: var(--llselect-trigger-wrapper-hover-line);
}
.llselect-trigger-wrapper:focus-within,
.llselect-trigger-wrapper[data-state='open'] {
border-color: var(--llselect-focus-line);
/* ring-2 ring-blue-500/30 -- Tailwind's focus-ring style */
box-shadow: 0 0 0 3px var(--llselect-focus-ring);
}
/* The trigger takes focus; the wrapper draws the focus ring. */
.llselect-trigger {
display: flex;
flex: 1 1 auto;
min-width: 0;
outline: 0;
}
.llselect-trigger-content {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.llselect-trigger-wrapper[data-empty='true'] .llselect-trigger-content {
color: var(--llselect-fg-muted);
}
.llselect-trigger-arrow {
display: inline-flex;
align-items: center;
margin-inline-start: 0.5rem;
color: var(--llselect-fg-soft);
transition: transform 150ms;
}
.llselect-trigger-arrow:empty { display: none; }
.llselect-trigger-wrapper[data-state='open'] .llselect-trigger-arrow {
transform: rotate(180deg);
}
/* An arrow that carries data-llselect-no-rotate, such as the up-down icons,
stays still. Browsers without :has() still turn it. The first rule stops
the slot from turning such an arrow back when it replaces a turned arrow,
on a close or a rerender(). */
.llselect-trigger-arrow:has(> [data-llselect-no-rotate]) {
transition: none;
}
.llselect-trigger-wrapper[data-state='open'] .llselect-trigger-arrow:has(> [data-llselect-no-rotate]) {
transform: none;
}
/* --- popup ---------------------------------------------------- */
.llselect-popup {
background-color: var(--llselect-bg);
border: 1px solid var(--llselect-popup-line);
border-radius: 0.5rem; /* rounded-lg */
/* shadow-lg */
box-shadow: 0 10px 15px -3px var(--llselect-shadow),
0 4px 6px -4px var(--llselect-shadow);
color: var(--llselect-fg);
z-index: 1000;
padding: 0.25rem 0; /* py-1 */
}
/* --- items ---------------------------------------------------- */
.llselect-popup-list-row {
padding: 0.375rem 0.75rem; /* py-1.5 px-3 */
cursor: pointer;
color: var(--llselect-row-fg);
background-color: transparent;
transition: background-color 100ms;
}
.llselect-popup-list-row:hover {
background-color: var(--llselect-row-hover-bg);
color: var(--llselect-row-hover-fg);
}
.llselect-popup-list-row-focused {
background-color: var(--llselect-row-focused-bg);
color: var(--llselect-row-focused-fg);
}
.llselect-popup-list-row-focused:hover {
background-color: var(--llselect-row-focused-hover-bg);
color: var(--llselect-row-focused-fg);
}
.llselect-popup-list-row[aria-selected='true'] {
font-weight: 600;
color: var(--llselect-row-chosen-fg);
}
/* --- choose-all row (multi, opt-in) ----------------------------- */
/* The default row content is just the counting text (its numbers carry the
tri-state); data-chosen-state is the hook if a theme wants to draw its own
indicator, createChooseAllRowContentElFn the way to add a real one. The
row also carries the popup-list-row class, so hover / focused styling comes
from there. Its divider is drawn by the block-edge rules under "dividers
around the command rows": one line where the block above the items ends,
none between the row and a command row that follows it. */
/* --- groups (Phase 10) ---------------------------------------- */
/* Static label by default; rect-based scroll math (keyboard.ts) is
offsetParent-independent, so a theme MAY make this `position: sticky; top:0`. */
.llselect-group-label {
padding: 0.375rem 0.75rem;
font-size: 0.75rem; /* text-xs */
font-weight: 600;
color: var(--llselect-fg-soft);
background-color: var(--llselect-bg-muted);
}
.llselect-group[data-disabled='true'] .llselect-group-label {
opacity: 0.55;
cursor: not-allowed;
}
/* --- filter input (Phase 8) ------------------------------------ */
.llselect-filter-input {
flex: none;
margin: 0.5rem;
padding: 0.375rem 0.75rem;
border: 1px solid var(--llselect-filter-line);
border-radius: 0.375rem;
font: inherit;
outline: none;
background-color: var(--llselect-bg);
color: var(--llselect-control-fg);
}
.llselect-filter-input:focus {
border-color: var(--llselect-filter-focus-line);
box-shadow: 0 0 0 3px var(--llselect-filter-focus-ring);
}
/* --- no-results message ----------------------------------------- */
.llselect-popup-list-no-results {
padding: 0.375rem 0.75rem;
color: var(--llselect-fg-muted);
}
/* --- dividers around the command rows --------------------------- */
/* The choose-all row and the action rows form one block above the items and
one below; they carry .llselect-popup-list-row too, so hover / focused / disabled
styling comes from there. Exactly one line marks each block's edge with
the items, drawn as the next element's border-top through sibling
combinators (`:has` is above the browser floor). No line inside a block:
choose-all followed by a command row reads as one group, like the header
blocks of ng-select, Element Plus and Vuetify's select-all recipe. */
.llselect-choose-all-row + .llselect-popup-list-row:not(.llselect-popup-list-action-row),
.llselect-choose-all-row + .llselect-group,
.llselect-popup-list-action-row + .llselect-popup-list-row:not(.llselect-popup-list-action-row),
.llselect-popup-list-action-row + .llselect-group,
.llselect-popup-list-row:not(.llselect-popup-list-action-row):not(.llselect-choose-all-row) + .llselect-popup-list-action-row,
.llselect-group + .llselect-popup-list-action-row {
border-top: 1px solid var(--llselect-divider);
}
/* --- pinned command blocks --------------------------------------- */
/* popupListLeadingRowsPinned / popupListTrailingRowsPinned wrap a block in a
presentational div that the library makes sticky. The theme gives it an
opaque background (the items scroll under it) and the block's edge line,
because the sibling rules above cannot see through the wrapper. The line
is drawn only toward items: the library sets data-edge-to-items on every
render, so two blocks that touch (nothing listed) draw no line at all. */
.llselect-popup-list-pinned-leading-rows,
.llselect-popup-list-pinned-trailing-rows {
background: var(--llselect-bg);
z-index: 1;
}
.llselect-popup-list-pinned-leading-rows[data-edge-to-items='true'] {
border-bottom: 1px solid var(--llselect-divider);
}
.llselect-popup-list-pinned-trailing-rows[data-edge-to-items='true'] {
border-top: 1px solid var(--llselect-divider);
}
/* --- popup header / footer slots -------------------------------- */
/* Pinned above / below the list, outside the scroll area. The elements exist
only when their content settings return an element; the divider matches
the choose-all row. */
.llselect-popup-header {
padding: 0.375rem 0.75rem;
border-bottom: 1px solid var(--llselect-divider);
}
.llselect-popup-footer {
padding: 0.375rem 0.75rem;
border-top: 1px solid var(--llselect-divider);
}
/* --- disabled (Phase 9) ---------------------------------------- */
/* aria-disabled + data-disabled, never native `disabled`. Keep pointer
events alive (no `pointer-events: none`) so hover/focus tooltips work. */
.llselect-trigger-wrapper[data-disabled='true'] {
opacity: 0.55;
cursor: not-allowed;
}
/* Embedded buttons are inert while the control is disabled: show not-allowed,
not the pointer cursor their own rule sets. */
.llselect-trigger-wrapper[data-disabled='true'] .llselect-tag-remove-button,
.llselect-trigger-wrapper[data-disabled='true'] .llselect-trigger-clear-button {
cursor: not-allowed;
}
.llselect-popup-list-row-disabled {
opacity: 0.45;
cursor: not-allowed;
}
.llselect-popup-list-row-disabled:hover {
background: none;
}
/* --- trigger buttons strip (clearable, triggerDisplay: 'tags') ---- */
/* Beside the trigger, before the arrow. The library sets `hidden` on it
while nothing is chosen. */
.llselect-trigger-buttons {
display: flex;
align-items: center;
gap: 0.5rem;
margin-inline-start: 0.5rem;
}
.llselect-trigger-buttons[hidden] { display: none; }
/* Tags mode, where the strip is a toolbar: the trigger is empty while chips
show, so the chips take the free space and start where the text would.
The large growth factor leaves the empty trigger next to nothing. */
.llselect-trigger-buttons[role='toolbar'] {
flex: 9999 1 auto;
margin-inline-start: 0;
}
/* A pointer press never focuses these buttons, so :focus is keyboard focus. */
.llselect-trigger-buttons button:focus {
outline: 2px solid var(--llselect-focus-line);
outline-offset: 1px;
}
/* --- tags (triggerDisplay: 'tags') ---------------------------- */
.llselect-tags {
display: flex;
flex: 1 1 auto;
flex-wrap: wrap;
gap: 0.25rem;
}
.llselect-tag {
display: inline-flex;
align-items: center;
gap: 0.2rem;
/* Logical: mirrors under dir="rtl" (text side start, x-button side end). */
padding-block: 0.05rem;
padding-inline: 0.5rem 0.15rem;
background-color: var(--llselect-tag-bg);
color: var(--llselect-tag-fg);
border-radius: 0.25rem;
font-size: 0.8rem;
line-height: 1.5;
}
.llselect-tag-remove-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1.15em;
height: 1.15em;
padding: 0;
border: none;
border-radius: 0.2rem;
background: transparent;
color: var(--llselect-tag-remove-fg);
cursor: pointer;
font: inherit;
line-height: 1;
}
.llselect-tag-remove-button:empty::before { content: '\00d7'; font-size: 1.15em; }
.llselect-tag-remove-button:hover {
background-color: var(--llselect-tag-remove-hover-bg);
color: var(--llselect-tag-remove-hover-fg);
}
/* A disabled item's chip: greyed, its x inert (the JS click guard is the real block). */
.llselect-tag-disabled {
opacity: 0.45;
cursor: not-allowed;
}
.llselect-tag-disabled .llselect-tag-remove-button {
cursor: not-allowed;
}
/* --- clear button (clearable) --------------------------------- */
/* :empty::before draws the x only when createTriggerClearButtonContentElFn gave no icon. */
.llselect-trigger-clear-button {
display: inline-flex;
align-items: center;
justify-content: center;
flex: none;
width: 1.2em;
height: 1.2em;
padding: 0;
border: none;
border-radius: 0.2rem;
background: transparent;
color: var(--llselect-fg-muted);
cursor: pointer;
font: inherit;
line-height: 1;
}
.llselect-trigger-clear-button:empty::before { content: '\00d7'; font-size: 1.2em; }
.llselect-trigger-clear-button:hover {
color: var(--llselect-clear-hover-fg);
background-color: var(--llselect-clear-hover-bg);
}
/* --- dark color scheme ----------------------------------------------------- */
/* The library resolves the scheme and writes data-llselect-color-scheme on the
root (DESIGN.md "Color scheme (light / dark) in the themes"); hosts never
write that attribute. Variables not listed here keep their light value or
their alias. */
.llselect-root[data-llselect-color-scheme='dark'] {
--llselect-fg: var(--color-slate-100, #f1f5f9);
--llselect-fg-soft: var(--color-slate-400, #94a3b8);
--llselect-fg-muted: var(--color-slate-400, #94a3b8);
--llselect-bg: var(--color-slate-900, #0f172a);
--llselect-bg-muted: var(--color-slate-800, #1e293b);
--llselect-trigger-wrapper-line: var(--color-slate-500, #64748b);
--llselect-trigger-wrapper-hover-line: var(--color-slate-400, #94a3b8);
--llselect-popup-line: var(--color-slate-500, #64748b);
--llselect-filter-line: var(--color-slate-500, #64748b);
--llselect-divider: rgba(255, 255, 255, 0.12);
--llselect-focus-line: var(--color-blue-400, #60a5fa);
--llselect-filter-focus-line: var(--color-blue-400, #60a5fa);
--llselect-focus-ring: rgba(96, 165, 250, 0.35);
--llselect-filter-focus-ring: rgba(96, 165, 250, 0.35);
--llselect-shadow: rgba(0, 0, 0, 0.5);
--llselect-row-fg: var(--color-slate-300, #cbd5e1);
--llselect-row-hover-bg: var(--color-slate-800, #1e293b);
--llselect-row-hover-fg: var(--color-slate-100, #f1f5f9);
--llselect-row-focused-bg: var(--color-blue-950, #172554);
--llselect-row-focused-fg: var(--color-blue-200, #bfdbfe);
--llselect-row-focused-hover-bg: var(--color-blue-900, #1e3a8a);
--llselect-row-chosen-fg: var(--color-blue-400, #60a5fa);
--llselect-tag-bg: var(--color-blue-950, #172554);
--llselect-tag-fg: var(--color-blue-200, #bfdbfe);
--llselect-tag-remove-fg: var(--color-blue-400, #60a5fa);
--llselect-tag-remove-hover-bg: var(--color-blue-900, #1e3a8a);
--llselect-tag-remove-hover-fg: var(--color-blue-100, #dbeafe);
--llselect-clear-hover-fg: var(--color-slate-200, #e2e8f0);
--llselect-clear-hover-bg: var(--color-slate-800, #1e293b);
}
/* Browser-painted parts, such as the popup scrollbar and a native control a
host puts in the trigger or the popup, follow the resolved scheme. Never
on .llselect-root: the resolver reads the computed color-scheme there. The
child combinator keeps an outer select component's scheme off the trigger
and the popup of a select component nested in it. */
.llselect-root[data-llselect-color-scheme='light'] > .llselect-trigger-wrapper,
.llselect-root[data-llselect-color-scheme='light'] > .llselect-popup {
color-scheme: light;
}
.llselect-root[data-llselect-color-scheme='dark'] > .llselect-trigger-wrapper,
.llselect-root[data-llselect-color-scheme='dark'] > .llselect-popup {
color-scheme: dark;
}
/* --- built-in dark marks ---------------------------------------------------- */
/* Each rule sets the CSS variable the resolver reads on the element that
carries the mark; the nearest ancestor wins by inheritance. Rule order
settles two marks on one element: an attribute beats a class name, and
data-color-scheme beats everything. Origins: .dark Tailwind CSS and
VitePress; .theme-dark Bulma 1; .dark-mode the Nuxt color-mode module;
data-theme daisyUI, Pico CSS 2 and Bulma 1; data-bs-theme Bootstrap 5.3;
data-color-scheme this project's pages, and any element a host marks. */
.dark,
.theme-dark,
.dark-mode {
--llselect-color-scheme: dark;
}
.theme-light,
.light-mode {
--llselect-color-scheme: light;
}
[data-theme='dark'] { --llselect-color-scheme: dark; }
[data-theme='light'] { --llselect-color-scheme: light; }
[data-bs-theme='dark'] { --llselect-color-scheme: dark; }
[data-bs-theme='light'] { --llselect-color-scheme: light; }
[data-color-scheme='dark'] { --llselect-color-scheme: dark; }
[data-color-scheme='light'] { --llselect-color-scheme: light; }
[data-color-scheme='auto'] { --llselect-color-scheme: auto; }