Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175<script lang="ts">/** One choice in a `UiSelect`. The value type is inferred from the options. */export interface SelectOption<T extends string = string> { value: T; label: string; disabled?: boolean;}</script>
<script setup lang="ts" generic="T extends string">defineOptions({ inheritAttrs: false });
withDefaults( defineProps<{ options: SelectOption<T>[]; /** Accessible name, since the trigger has no visible label. */ label: string; /** Shown when no value is selected. */ placeholder?: string; disabled?: boolean; size?: "default" | "small" | "large"; }>(), { placeholder: undefined, disabled: false, size: "default" },);
const model = defineModel<T>({ required: true });const open = ref(false);
// Back closes the list before it navigates.useBackLayer(open);</script>
<template> <SelectRoot v-model="model" v-model:open="open" :disabled="disabled"> <SelectTrigger v-bind="$attrs" class="ui-select__trigger" :class="{ 'ui-select__trigger--small': size === 'small', 'ui-select__trigger--large': size === 'large', }" :aria-label="label" > <SelectValue class="ui-select__value" :placeholder="placeholder" /> <SelectIcon class="ui-select__icon"> <MsIcon name="keyboard_arrow_down" :size="20" /> </SelectIcon> </SelectTrigger>
<SelectPortal> <SelectContent class="ui-select__content" position="popper"> <SelectViewport class="ui-select__viewport"> <SelectItem v-for="option in options" :key="option.value" :value="option.value" :disabled="option.disabled" class="ui-select__item" > <SelectItemText>{{ option.label }}</SelectItemText> <SelectItemIndicator class="ui-select__indicator"> <MsIcon name="check" :size="20" /> </SelectItemIndicator> </SelectItem> </SelectViewport> </SelectContent> </SelectPortal> </SelectRoot></template>
<style>.ui-select__content { z-index: var(--z-menu); min-width: var(--reka-select-trigger-width); max-height: calc(50dvh - var(--space-8)); padding: var(--space-1); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-2);}
.ui-select__content { animation: ui-overlay-fade-in var(--motion-fast);}
.ui-select__content[data-state="closed"] { animation: ui-overlay-fade-out var(--motion-exit);}
.ui-select__viewport { display: flex; flex-direction: column; gap: var(--space-0-5);}
.ui-select__item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-1-5) var(--space-2); font-size: var(--text-md); border-radius: max(0px, calc(var(--radius-md) - var(--space-1))); outline: none; cursor: pointer;}
.ui-select__item[data-highlighted] { background: var(--color-accent-soft);}
.ui-select__item[data-disabled] { opacity: 0.5; cursor: default;}
.ui-select__indicator { display: inline-flex; color: var(--color-accent);}
.ui-select__trigger { display: inline-flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-width: 0; height: var(--control-md); padding: 0 var(--space-3); font-family: inherit; font-size: var(--text-md); color: var(--color-text); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm); cursor: pointer;}
.ui-select__trigger:hover { background: var(--color-surface-2);}
.ui-select__trigger:disabled { opacity: 0.55; cursor: default;}
.ui-select__trigger--small { gap: var(--space-1-5); height: var(--control-sm); padding: 0 var(--space-2-5); font-size: var(--text-sm);}
.ui-select__trigger--large { gap: var(--space-2); height: var(--control-lg); padding: 0 var(--space-4); font-size: var(--text-lg); border-radius: var(--radius-md);}
.ui-select__value { text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}
.ui-select__icon { display: inline-flex; color: var(--color-text-secondary);}</style>