feat(ui): suggest input on Combobox replaces datalists, RadioGroup for task pickers
Also records the combobox and radio-group components added in 63476393.
This commit is contained in:
1 parent
63476393d7
commit
ca597c3678
16 files changed
+192
-165
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import type { HTMLAttributes } from "vue";
|
||||
import { useVModel } from "@vueuse/core";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { inputClass } from "./classes";
|
||||
|
||||
const props = defineProps<{
|
||||
defaultValue?: string | number;
|
||||
@@ -25,7 +26,7 @@ const modelValue = useVModel(props, "modelValue", emits, {
|
||||
data-slot="input"
|
||||
:class="
|
||||
cn(
|
||||
'dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 h-9 rounded-lg border bg-card px-2.5 py-1 text-sm transition-colors pointer-coarse:text-base file:h-6 file:text-sm file:font-medium focus-visible:ring-3 aria-invalid:ring-3 w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent file:text-foreground placeholder:text-fg-muted disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||
inputClass,
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export const inputClass =
|
||||
"dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 h-9 rounded-lg border bg-card px-2.5 py-1 text-sm transition-colors pointer-coarse:text-base file:h-6 file:text-sm file:font-medium focus-visible:ring-3 aria-invalid:ring-3 w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent file:text-foreground placeholder:text-fg-muted disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50";
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { ComboboxAnchor, ComboboxContent, ComboboxInput, ComboboxItem, ComboboxPortal, ComboboxRoot, ComboboxViewport } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { inputClass } from "@/components/ui/input/classes";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<{ options: string[]; class?: string }>();
|
||||
const model = defineModel<string>({ default: "" });
|
||||
const typed = ref(false);
|
||||
|
||||
const shown = computed(() => {
|
||||
const needle = typed.value ? model.value.toLowerCase() : "";
|
||||
return props.options.filter((o) => o.toLowerCase().includes(needle)).slice(0, 50);
|
||||
});
|
||||
|
||||
function type(value: string) {
|
||||
typed.value = true;
|
||||
model.value = value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboboxRoot v-model="model" ignore-filter open-on-focus :display-value="(v: string) => v" @update:open="typed = false">
|
||||
<ComboboxAnchor as-child>
|
||||
<ComboboxInput as-child :model-value="model" @update:model-value="type">
|
||||
<input v-bind="$attrs" data-slot="input" autocomplete="off" :class="cn(inputClass, props.class)" />
|
||||
</ComboboxInput>
|
||||
</ComboboxAnchor>
|
||||
<ComboboxPortal>
|
||||
<ComboboxContent
|
||||
v-if="shown.length"
|
||||
position="popper"
|
||||
:side-offset="4"
|
||||
class="z-50 max-h-60 w-(--reka-combobox-trigger-width) overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10"
|
||||
>
|
||||
<ComboboxViewport class="max-h-60 overflow-y-auto p-1">
|
||||
<ComboboxItem
|
||||
v-for="option in shown"
|
||||
:key="option"
|
||||
:value="option"
|
||||
class="relative flex w-full cursor-default items-center rounded-md px-1.5 py-1 font-mono text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground"
|
||||
>{{ option }}</ComboboxItem>
|
||||
</ComboboxViewport>
|
||||
</ComboboxContent>
|
||||
</ComboboxPortal>
|
||||
</ComboboxRoot>
|
||||
</template>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as SuggestInput } from './SuggestInput.vue'
|
||||
Reference in new issue
Block a user