diff --git a/.playground/pages/tests/form/autocomplete.vue b/.playground/pages/tests/form/autocomplete.vue index bcfb23b2..6b5ebfb2 100644 --- a/.playground/pages/tests/form/autocomplete.vue +++ b/.playground/pages/tests/form/autocomplete.vue @@ -5,6 +5,8 @@ definePageMeta({ description: 'SVG icons', section: 'form', }) + +const items = ref(['Javascript', 'Vue.js', 'React.js', 'Angular']) diff --git a/components/form/BaseAutocomplete.vue b/components/form/BaseAutocomplete.vue index 0313667b..940ac638 100644 --- a/components/form/BaseAutocomplete.vue +++ b/components/form/BaseAutocomplete.vue @@ -23,7 +23,7 @@ const props = withDefaults( /** * The shape of the component. */ - shape?: 'straight' | 'rounded' | 'curved' | 'full' + shape?: 'straight' | 'rounded' | 'smooth' | 'curved' | 'full' /** * The label to display for the component. @@ -59,9 +59,14 @@ const props = withDefaults( error?: string /** - * Whether the component is condensed. + * The size of the autocomplete component. */ - condensed?: boolean + size?: 'sm' | 'md' | 'lg' + + /** + * The kind of autocomplete component. + */ + kind?: 'default' | 'default-contrast' | 'muted' | 'muted-contrast' /** * Whether the component is in a loading state. @@ -147,6 +152,8 @@ const props = withDefaults( placeholder: '', label: '', error: '', + size: 'md', + kind: 'default', i18n: () => ({ pending: 'Loading ...', empty: 'Nothing found.', @@ -194,42 +201,52 @@ const pendingFilter = ref(false) const pendingDebounce = computed(() => query.value !== debounced.value) const pending = computed(() => pendingFilter.value || pendingDebounce.value) -const shapeListStyle = { +const shapeStyle = { straight: '', - rounded: 'rounded-lg', - curved: 'rounded-xl', - full: 'rounded-full', + rounded: 'nui-autocomplete-rounded', + smooth: 'nui-autocomplete-smooth', + curved: 'nui-autocomplete-curved', + full: 'nui-autocomplete-full', } -const shapeInputStyle = { - straight: '', - rounded: 'rounded', - curved: 'rounded-xl', - full: 'rounded-full', +const sizeStyle = { + sm: 'nui-autocomplete-sm', + md: 'nui-autocomplete-md', + lg: 'nui-autocomplete-lg', } -const shapeOptionStyle = { - straight: '', - rounded: 'rounded-lg', - curved: 'rounded-xl', - full: 'rounded-2xl', +const kindStyle = { + default: 'nui-autocomplete-default', + 'default-contrast': 'nui-autocomplete-default-contrast', + muted: 'nui-autocomplete-muted', + 'muted-contrast': 'nui-autocomplete-muted-contrast', } -const condensedInputStyle = computed(() => - props.condensed - ? props.icon === undefined - ? 'h-8 py-1 text-xs leading-4 px-2' - : 'h-8 py-1 text-xs leading-4 pe-3 ps-7' - : props.icon === undefined - ? 'h-10 py-2 text-sm leading-5 px-3' - : 'h-10 py-2 text-sm leading-5 pe-4 ps-9' +const wrapperStyle = computed(() => + props.classes?.wrapper + ? Array.isArray(props.classes?.wrapper) + ? [...props.classes?.wrapper] + : props.classes?.wrapper + : '' +) +const labelStyle = computed(() => + props.classes?.label + ? Array.isArray(props.classes?.label) + ? [...props.classes?.label] + : props.classes?.label + : '' +) +const inputStyle = computed(() => + props.classes?.input + ? Array.isArray(props.classes?.input) + ? [...props.classes?.input] + : props.classes?.input + : '' ) -const condensedLabelStyle = computed(() => - props.condensed - ? props.icon === undefined - ? 'start-3 -ms-3 -mt-7 text-xs peer-placeholder-shown:ms-0 peer-placeholder-shown:mt-0 peer-focus-visible:-ms-3 peer-focus-visible:-mt-7' - : 'start-8 -ms-8 -mt-7 text-xs peer-placeholder-shown:ms-0 peer-placeholder-shown:mt-0 peer-focus-visible:-ms-8 peer-focus-visible:-mt-7' - : props.icon === undefined - ? 'start-3 -ms-3 -mt-8 text-xs peer-placeholder-shown:ms-0 peer-placeholder-shown:mt-0 peer-placeholder-shown:text-[0.825rem] peer-focus-visible:-ms-3 peer-focus-visible:-mt-8 peer-focus-visible:text-xs' - : 'start-10 -ms-10 -mt-8 text-xs peer-placeholder-shown:ms-0 peer-placeholder-shown:mt-0 peer-placeholder-shown:text-[0.825rem] peer-focus-visible:-ms-10 peer-focus-visible:-mt-8 peer-focus-visible:text-xs' +const iconStyle = computed(() => + props.classes?.icon + ? Array.isArray(props.classes?.icon) + ? [...props.classes?.icon] + : props.classes?.icon + : '' ) provide( @@ -305,8 +322,16 @@ function removeItem(item: any) { v-model="value" :multiple="props.multiple" :disabled="props.disabled" - class="relative w-full" - :class="props.classes?.wrapper" + :class="[ + 'nui-autocomplete', + ...wrapperStyle, + sizeStyle[props.size], + kindStyle[props.kind], + shape && shapeStyle[shape], + props.icon && 'nui-has-icon', + props.labelFloat && 'nui-autocomplete-label-float', + props.loading && 'nui-autocomplete-loading', + ]" as="div" > {{ props.label }} -
+
  • -
    +
    {{ props.displayValue(item) }}
-
+ +
{{ props.label }} -
- +
+
-
- +
+
+ {{ props.error }} + - +
- + {{ props.i18n.pending }}
-
+
- + {{ props.i18n.empty }}