add caret to combobox
This commit is contained in:
parent
1ae0e14e42
commit
7f71f83a59
3 changed files with 26 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
|
position: relative;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: inherit;
|
grid-template-columns: inherit;
|
||||||
place-items: center start;
|
place-items: center start;
|
||||||
|
@ -23,6 +24,22 @@
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--surface-700);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:has(> .caret) {
|
||||||
|
padding-inline-end: calc(1em + (2 * var(--padding-m)));
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .caret {
|
||||||
|
position: absolute;
|
||||||
|
inset-inline-end: var(--padding-m);
|
||||||
|
inset-block-start: 50%;
|
||||||
|
translate: 0 -50%;
|
||||||
|
inline-size: 1em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog {
|
.dialog {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { createMemo, createSignal, For, JSX, Setter, createEffect, Show } from "solid-js";
|
import { createMemo, createSignal, For, JSX, Setter, createEffect, Show } from "solid-js";
|
||||||
import css from './index.module.css';
|
import css from './index.module.css';
|
||||||
|
import { FaSolidAngleDown } from "solid-icons/fa";
|
||||||
|
|
||||||
interface ComboBoxProps<T, K extends string> {
|
interface ComboBoxProps<T, K extends string> {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -8,6 +9,7 @@ interface ComboBoxProps<T, K extends string> {
|
||||||
setValue?: Setter<K>;
|
setValue?: Setter<K>;
|
||||||
values: Record<K, T>;
|
values: Record<K, T>;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
|
showCaret?: boolean;
|
||||||
children: (key: K, value: T) => JSX.Element;
|
children: (key: K, value: T) => JSX.Element;
|
||||||
filter?: (query: string, key: K, value: T) => boolean;
|
filter?: (query: string, key: K, value: T) => boolean;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +32,8 @@ export function ComboBox<T, K extends string>(props: ComboBoxProps<T, K>) {
|
||||||
return entries;
|
return entries;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const showCaret = createMemo(() => props.showCaret ?? true);
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
props.setValue?.(() => value());
|
props.setValue?.(() => value());
|
||||||
});
|
});
|
||||||
|
@ -41,6 +45,10 @@ export function ComboBox<T, K extends string>(props: ComboBoxProps<T, K>) {
|
||||||
return <section class={`${css.box} ${props.class}`}>
|
return <section class={`${css.box} ${props.class}`}>
|
||||||
<button id={`${props.id}_button`} popoverTarget={`${props.id}_dialog`} class={css.button}>
|
<button id={`${props.id}_button`} popoverTarget={`${props.id}_dialog`} class={css.button}>
|
||||||
{props.children(value(), props.values[value()])}
|
{props.children(value(), props.values[value()])}
|
||||||
|
|
||||||
|
<Show when={showCaret()}>
|
||||||
|
<FaSolidAngleDown class={css.caret} />
|
||||||
|
</Show>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<dialog ref={setDialog} id={`${props.id}_dialog`} anchor={`${props.id}_button`} popover class={css.dialog} onToggle={e => setOpen(e.newState === 'open')}>
|
<dialog ref={setDialog} id={`${props.id}_dialog`} anchor={`${props.id}_button`} popover class={css.dialog} onToggle={e => setOpen(e.newState === 'open')}>
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const LocalePicker: Component<LocalePickerProps> = (props) => {
|
||||||
value={locale()}
|
value={locale()}
|
||||||
setValue={setLocale}
|
setValue={setLocale}
|
||||||
values={locales}
|
values={locales}
|
||||||
|
showCaret={false}
|
||||||
>
|
>
|
||||||
{(locale, { flag, label }) => <Dynamic component={flag} lang={locale} aria-label={label} class={css.flag} />}
|
{(locale, { flag, label }) => <Dynamic component={flag} lang={locale} aria-label={label} class={css.flag} />}
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue