2024-06-17 00:23:30 -07:00
|
|
|
<script setup lang="ts">
|
2024-09-18 00:19:33 -07:00
|
|
|
import { ElSelect } from 'element-plus';
|
2024-06-17 00:23:30 -07:00
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import { computed, ref, useAttrs } from 'vue';
|
2024-09-18 00:19:33 -07:00
|
|
|
|
2024-06-17 00:23:30 -07:00
|
|
|
import type { SelectSize } from 'n8n-design-system/types';
|
2024-09-18 00:19:33 -07:00
|
|
|
|
2024-06-17 00:23:30 -07:00
|
|
|
import { isEventBindingElementAttribute } from '../../utils';
|
|
|
|
|
|
|
|
type InnerSelectRef = InstanceType<typeof ElSelect>;
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
...ElSelect.props,
|
|
|
|
modelValue: {},
|
|
|
|
size: {
|
|
|
|
type: String as PropType<SelectSize>,
|
|
|
|
default: 'large',
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
filterable: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
defaultFirstOption: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
multiple: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
filterMethod: {
|
|
|
|
type: Function,
|
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
loadingText: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
popperClass: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
popperAppendToBody: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
limitPopperWidth: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
noDataText: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const attrs = useAttrs();
|
|
|
|
const innerSelect = ref<InnerSelectRef | null>(null);
|
|
|
|
|
|
|
|
const listeners = computed(() => {
|
|
|
|
return Object.entries(attrs).reduce<Record<string, unknown>>((acc, [key, value]) => {
|
|
|
|
if (isEventBindingElementAttribute(value, key)) {
|
|
|
|
acc[key] = value;
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
});
|
|
|
|
|
|
|
|
const computedSize = computed(() => {
|
|
|
|
if (props.size === 'mini') {
|
|
|
|
return 'small';
|
|
|
|
}
|
|
|
|
if (props.size === 'medium') {
|
|
|
|
return 'default';
|
|
|
|
}
|
|
|
|
if (props.size === 'xlarge') {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return props.size;
|
|
|
|
});
|
|
|
|
|
|
|
|
const classes = computed(() => {
|
|
|
|
return props.size === 'xlarge' ? 'xlarge' : '';
|
|
|
|
});
|
|
|
|
|
|
|
|
const focus = () => {
|
|
|
|
innerSelect.value?.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
const blur = () => {
|
|
|
|
innerSelect.value?.blur();
|
|
|
|
};
|
|
|
|
|
|
|
|
const focusOnInput = () => {
|
|
|
|
if (!innerSelect.value) return;
|
|
|
|
|
|
|
|
const inputRef = innerSelect.value.$refs.input as HTMLInputElement | undefined;
|
|
|
|
inputRef?.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
focus,
|
|
|
|
blur,
|
|
|
|
focusOnInput,
|
2024-09-02 06:20:08 -07:00
|
|
|
innerSelect,
|
2024-06-17 00:23:30 -07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-08-05 06:03:24 -07:00
|
|
|
<template>
|
2022-11-15 09:20:54 -08:00
|
|
|
<div
|
|
|
|
:class="{
|
|
|
|
'n8n-select': true,
|
|
|
|
[$style.container]: true,
|
|
|
|
[$style.withPrepend]: !!$slots.prepend,
|
|
|
|
}"
|
|
|
|
>
|
2022-04-11 06:12:13 -07:00
|
|
|
<div v-if="$slots.prepend" :class="$style.prepend">
|
|
|
|
<slot name="prepend" />
|
|
|
|
</div>
|
2023-12-28 00:49:58 -08:00
|
|
|
<ElSelect
|
2023-07-28 00:51:07 -07:00
|
|
|
v-bind="{ ...$props, ...listeners }"
|
2023-12-28 00:49:58 -08:00
|
|
|
ref="innerSelect"
|
2024-06-17 00:23:30 -07:00
|
|
|
:model-value="modelValue ?? undefined"
|
2022-08-05 06:03:24 -07:00
|
|
|
:size="computedSize"
|
|
|
|
:popper-class="popperClass"
|
2024-06-17 00:23:30 -07:00
|
|
|
:class="$style[classes]"
|
2022-04-11 06:12:13 -07:00
|
|
|
>
|
2023-12-28 00:49:58 -08:00
|
|
|
<template v-if="$slots.prefix" #prefix>
|
2022-04-11 06:12:13 -07:00
|
|
|
<slot name="prefix" />
|
|
|
|
</template>
|
2023-12-28 00:49:58 -08:00
|
|
|
<template v-if="$slots.suffix" #suffix>
|
2022-04-11 06:12:13 -07:00
|
|
|
<slot name="suffix" />
|
|
|
|
</template>
|
2023-07-28 00:51:07 -07:00
|
|
|
<slot></slot>
|
2023-12-28 00:49:58 -08:00
|
|
|
</ElSelect>
|
2022-04-11 06:12:13 -07:00
|
|
|
</div>
|
2021-08-29 04:36:17 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.xlarge {
|
|
|
|
--input-font-size: var(--font-size-m);
|
|
|
|
input {
|
|
|
|
height: 48px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 06:12:13 -07:00
|
|
|
.container {
|
|
|
|
display: inline-flex;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.withPrepend {
|
|
|
|
input {
|
|
|
|
border-top-left-radius: 0;
|
|
|
|
border-bottom-left-radius: 0;
|
2023-04-18 06:38:52 -07:00
|
|
|
@-moz-document url-prefix() {
|
|
|
|
padding: 0 var(--spacing-3xs);
|
|
|
|
}
|
2022-04-11 06:12:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.prepend {
|
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
border: var(--border-base);
|
|
|
|
border-right: none;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 var(--spacing-3xs);
|
|
|
|
background-color: var(--color-background-light);
|
|
|
|
border-bottom-left-radius: var(--input-border-radius, var(--border-radius-base));
|
|
|
|
border-top-left-radius: var(--input-border-radius, var(--border-radius-base));
|
|
|
|
color: var(--color-text-base);
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
2021-08-29 04:36:17 -07:00
|
|
|
</style>
|