Files
n8n-enterprise-unlocked/packages/design-system/src/components/N8nInput/Input.vue
Alex Grozav 430a8781e8 feat: Replace Vue.extend with defineComponent in design system (no-changelog) (#5918)
* refactor: replace new Vue() with custom event bus (no-changelog)

* fix: export types from design system main

* fix: update component types

* fix: update form inputs event bus

* refactor: replace global Vue references in design-system

* refactor: update prop types

* feat: improve types

* fix: further type improvements

* fix: further types improvements

* fix: further type improvements

* test: fix test snapshots

* test: fix snapshot

* chore: fix linting issues

* test: fix personalization modal snapshot
2023-04-12 17:39:45 +03:00

145 lines
2.5 KiB
Vue

<template>
<el-input
v-bind="$props"
:size="computedSize"
:class="['n8n-input', ...classes]"
:autoComplete="autocomplete"
ref="innerInput"
v-on="$listeners"
:name="name"
>
<template #prepend>
<slot name="prepend" />
</template>
<template #append>
<slot name="append" />
</template>
<template #prefix>
<slot name="prefix" />
</template>
<template #suffix>
<slot name="suffix" />
</template>
</el-input>
</template>
<script lang="ts">
import { Input as ElInput } from 'element-ui';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'n8n-input',
components: {
ElInput,
},
props: {
value: {},
type: {
type: String,
validator: (value: string): boolean =>
['text', 'textarea', 'number', 'password', 'email'].includes(value),
},
size: {
type: String,
default: 'large',
validator: (value: string): boolean =>
['mini', 'small', 'medium', 'large', 'xlarge'].includes(value),
},
placeholder: {
type: String,
},
disabled: {
type: Boolean,
},
readonly: {
type: Boolean,
},
clearable: {
type: Boolean,
},
rows: {
type: Number,
},
maxlength: {
type: Number,
},
title: {
type: String,
},
name: {
type: String,
},
autocomplete: {
type: String,
default: 'off',
},
},
computed: {
computedSize(): string | undefined {
if (this.size === 'xlarge') {
return undefined;
}
return this.size;
},
classes(): string[] {
if (this.size === 'xlarge') {
return ['xlarge'];
}
return [];
},
},
methods: {
focus() {
const innerInput = this.$refs.innerInput as Vue | undefined;
if (!innerInput) return;
const inputElement = innerInput.$el.querySelector(
this.type === 'textarea' ? 'textarea' : 'input',
);
if (!inputElement) return;
inputElement.focus();
},
blur() {
const innerInput = this.$refs.innerInput as Vue | undefined;
if (!innerInput) return;
const inputElement = innerInput.$el.querySelector(
this.type === 'textarea' ? 'textarea' : 'input',
);
if (!inputElement) return;
inputElement.blur();
},
select() {
const innerInput = this.$refs.innerInput as Vue | undefined;
if (!innerInput) return;
const inputElement = innerInput.$el.querySelector(
this.type === 'textarea' ? 'textarea' : 'input',
);
if (!inputElement) return;
inputElement.select();
},
},
});
</script>
<style lang="scss" module>
.xlarge {
--input-font-size: var(--font-size-m);
input {
height: 48px;
}
}
</style>