2024-11-12 09:18:07 +00:00
|
|
|
<template>
|
2024-11-13 16:09:13 +00:00
|
|
|
<div>
|
|
|
|
<label :for="inputId" class="text-sm">{{ label }}</label>
|
|
|
|
<div :id="id" class="relative">
|
2024-11-14 07:25:06 +00:00
|
|
|
<AutoComplete
|
|
|
|
:modelValue="modelValue"
|
2024-11-13 16:17:03 +00:00
|
|
|
@input="onInput"
|
2024-11-14 07:25:06 +00:00
|
|
|
:inputId="inputId"
|
|
|
|
:suggestions="items"
|
|
|
|
@complete="search"
|
|
|
|
unstyled
|
2024-11-14 08:16:00 +00:00
|
|
|
optionLabel="label"
|
2024-11-14 07:25:06 +00:00
|
|
|
:showEmptyMessage="false"
|
|
|
|
:pt="{
|
|
|
|
pcInputText: {
|
|
|
|
root: ['border border-surface-300 dark:border-surface-600 rounded-lg py-2 px-2 w-full', { 'pr-8': type === 'color' }]
|
|
|
|
},
|
|
|
|
overlay: 'border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-950 shadow-2 rounded-md',
|
|
|
|
listContainer: 'max-h-40 overflow-auto',
|
2024-11-14 08:18:07 +00:00
|
|
|
list: 'm-0 py-2 px-2 list-none',
|
|
|
|
option: 'cursor-pointer py-1 text-sm text-surface-700 dark:text-white/80 data-[p-focus=true]:bg-surface-100 data-[p-focus=true]:dark:bg-surface-800 rounded-md'
|
2024-11-14 07:25:06 +00:00
|
|
|
}"
|
|
|
|
@option-select="onOptionSelect"
|
2024-11-14 08:16:00 +00:00
|
|
|
>
|
|
|
|
<template #option="slotProps">
|
2024-11-14 08:18:07 +00:00
|
|
|
<div v-tooltip.left="slotProps.option.value" class="flex items-center justify-between gap-4 px-2">
|
2024-11-14 08:16:00 +00:00
|
|
|
<span>{{ slotProps.option.token }}</span>
|
|
|
|
<div v-if="slotProps.option.isColor" class="border border-surface-200 dark:border-surface-700 w-4 h-4 rounded-full" :style="{ backgroundColor: slotProps.option.variable }"></div>
|
|
|
|
<div v-else class="text-xs max-w-16 text-ellipsis whitespace-nowrap overflow-hidden">
|
|
|
|
{{ slotProps.option.value }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</AutoComplete>
|
2024-11-13 16:09:13 +00:00
|
|
|
<div v-if="type === 'color'" class="absolute right-[4px] top-1/2 -mt-3 w-6 h-6 rounded-md border border-surface-300 dark:border-surface-600" :style="{ backgroundColor: previewColor }"></div>
|
|
|
|
</div>
|
2024-11-12 09:18:07 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-11-13 16:09:13 +00:00
|
|
|
import { UniqueComponentId } from '@primevue/core/utils';
|
2024-11-12 09:18:07 +00:00
|
|
|
import { $dt } from '@primevue/themes';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
emits: ['update:modelValue'],
|
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
|
|
|
modelValue: {
|
|
|
|
type: null,
|
|
|
|
default: undefined
|
|
|
|
}
|
|
|
|
},
|
2024-11-12 23:14:58 +00:00
|
|
|
inject: ['$acTokens'],
|
2024-11-12 13:44:52 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2024-11-13 16:09:13 +00:00
|
|
|
id: null,
|
|
|
|
items: null
|
2024-11-12 13:44:52 +00:00
|
|
|
};
|
|
|
|
},
|
2024-11-13 16:09:13 +00:00
|
|
|
mounted() {
|
|
|
|
this.id = 'dt_field_' + UniqueComponentId();
|
|
|
|
},
|
2024-11-12 09:18:07 +00:00
|
|
|
methods: {
|
2024-11-14 07:25:06 +00:00
|
|
|
onOptionSelect(event) {
|
|
|
|
this.$emit('update:modelValue', event.value);
|
|
|
|
event.originalEvent.stopPropagation();
|
|
|
|
},
|
2024-11-12 09:18:07 +00:00
|
|
|
onInput(event) {
|
2024-11-14 07:25:06 +00:00
|
|
|
this.$emit('update:modelValue', event.target.value);
|
|
|
|
},
|
|
|
|
search(event) {
|
|
|
|
const query = event.query;
|
2024-11-12 13:44:52 +00:00
|
|
|
|
2024-11-14 07:25:06 +00:00
|
|
|
if (query.startsWith('{')) {
|
2024-11-14 08:16:00 +00:00
|
|
|
this.items = this.$acTokens.filter((t) => t.label.startsWith(query));
|
2024-11-12 13:44:52 +00:00
|
|
|
} else {
|
2024-11-13 16:09:13 +00:00
|
|
|
this.items = null;
|
2024-11-12 13:44:52 +00:00
|
|
|
}
|
2024-11-12 09:18:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
previewColor() {
|
2024-11-12 14:33:35 +00:00
|
|
|
return this.modelValue && this.modelValue.startsWith('{') && this.modelValue.endsWith('}') ? $dt(this.modelValue).variable : this.modelValue;
|
2024-11-13 16:09:13 +00:00
|
|
|
},
|
|
|
|
inputId() {
|
|
|
|
return this.id + '_input';
|
2024-11-12 09:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|