Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149<script setup lang="ts">import type { MaterialSymbol } from "material-symbols";
import { searchSymbols, type SymbolEntry } from "~/lib/symbols";
const props = withDefaults( defineProps<{ modelValue: string; /** How many results render before "refine your search" is shown. */ limit?: number; }>(), { limit: 350 },);
const emit = defineEmits<{ (e: "update:modelValue", value: MaterialSymbol): void;}>();
const query = ref("");const gridRef = useTemplateRef<HTMLElement>("grid");
const result = computed(() => searchSymbols(query.value, props.limit));
watch(query, () => { gridRef.value?.scrollTo({ top: 0 });});
function pick(entry: SymbolEntry) { emit("update:modelValue", entry.id);}
const selected = computed(() => props.modelValue as MaterialSymbol);</script>
<template> <div class="icon-picker"> <UiTextField v-model="query" type="search" :placeholder="$t('switcher.iconSearch')" :aria-label="$t('switcher.iconSearch')" @keydown.enter.prevent > <template #leading> <MsIcon name="search" :size="20" class="icon-picker__search-icon" /> </template> </UiTextField>
<div v-if="result.entries.length" ref="grid" class="icon-picker__grid"> <UiTooltip v-for="entry in result.entries" :key="entry.id" :text="entry.title"> <button type="button" class="icon-picker__cell" :class="{ 'icon-picker__cell--selected': entry.id === selected }" :aria-pressed="entry.id === selected" :aria-label="entry.title" @click="pick(entry)" > <MsIcon :name="entry.id" :size="22" /> </button> </UiTooltip> </div>
<div v-else class="icon-picker__empty" role="status"> <MsIcon name="search_off" :size="22" /> <span> {{ query.trim() ? $t("switcher.iconEmpty", { query: query.trim() }) : $t("switcher.iconEmptyAll") }} </span> </div>
<!-- <p v-if="result.total > result.entries.length" class="icon-picker__hint"> {{ $t("switcher.iconMore", { shown: result.entries.length, total: result.total }) }} </p> --> </div></template>
<style>.icon-picker { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0;}
.icon-picker__search-icon { color: var(--color-text-secondary);}
.icon-picker__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); gap: var(--space-1); height: 14rem; align-content: start; align-items: start; overflow-y: auto; padding: var(--space-1); border: 1px solid var(--color-border); border-radius: var(--radius-sm);}
.icon-picker__cell { display: grid; place-content: center; aspect-ratio: 1; padding: var(--space-1); color: var(--color-text); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;}
.icon-picker__cell:hover { background: var(--color-surface-3);}
.icon-picker__cell--selected { background: var(--color-accent-soft); border-color: var(--color-accent);}
.icon-picker__hint { margin: 0; font-size: var(--text-xs); color: var(--color-text-secondary);}
/* Search came back empty: same box as the grid so the dialog does not resize. */.icon-picker__empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2); height: 14rem; padding: var(--space-4); color: var(--color-text-secondary); font-size: var(--text-sm); text-align: center; border: 1px solid var(--color-border); border-radius: var(--radius-sm);}</style>