@teammodlr/ui-kit 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/env.d.ts +1 -0
- package/lib/__storybook__/argTypes.d.ts +31 -0
- package/lib/__storybook__/createStory.d.ts +8 -0
- package/lib/__storybook__/index.d.ts +2 -0
- package/lib/components/avatar/Avatar.vue.d.ts +70 -0
- package/lib/components/avatargroup/AvatarGroup.vue.d.ts +34 -0
- package/lib/components/breadcrumb/Breadcrumb.vue.d.ts +25 -0
- package/lib/components/breadcrumbitem/BreadcrumbItem.vue.d.ts +18 -0
- package/lib/components/breadcrumbitem/index.d.ts +1 -0
- package/lib/components/button/Button.vue.d.ts +121 -0
- package/lib/components/buttongroup/ButtonGroup.vue.d.ts +29 -0
- package/lib/components/checkbox/Checkbox.vue.d.ts +97 -0
- package/lib/components/dropdown/Dropdown.vue.d.ts +114 -0
- package/lib/components/dropdown/DropdownItem.vue.d.ts +61 -0
- package/lib/components/dropdown/DropdownList.vue.d.ts +2 -0
- package/lib/components/dropdown/DropdownWrapper.vue.d.ts +2 -0
- package/lib/components/dropdown/hooks.d.ts +2 -0
- package/lib/components/form/Form.vue.d.ts +67 -0
- package/lib/components/image/Image.vue.d.ts +50 -0
- package/lib/components/index.d.ts +26 -0
- package/lib/components/input/Input.vue.d.ts +126 -0
- package/lib/components/link/Link.vue.d.ts +51 -0
- package/lib/components/messageprovider/Message.vue.d.ts +61 -0
- package/lib/components/messageprovider/MessageProvider.vue.d.ts +51 -0
- package/lib/components/messageprovider/types.d.ts +28 -0
- package/lib/components/messageprovider/useMessage.d.ts +2 -0
- package/lib/components/select/Select.vue.d.ts +180 -0
- package/lib/components/skeleton/Skeleton.vue.d.ts +39 -0
- package/lib/components/tab/Tab.vue.d.ts +41 -0
- package/lib/components/tab/TabGroup.vue.d.ts +43 -0
- package/lib/components/table/Table.vue.d.ts +63 -0
- package/lib/components/table/TableBody.vue.d.ts +2 -0
- package/lib/components/table/TableCell.vue.d.ts +2 -0
- package/lib/components/table/TableHead.vue.d.ts +20 -0
- package/lib/components/table/TableHeadRow.vue.d.ts +2 -0
- package/lib/components/table/TableRow.vue.d.ts +2 -0
- package/lib/components/table/types/index.d.ts +5 -0
- package/lib/components/tooltip/Tooltip.vue.d.ts +54 -0
- package/lib/components/virtualscroll/VirtualScroll.vue.d.ts +43 -0
- package/lib/composables/element.d.ts +2 -0
- package/lib/composables/useCachedUid.d.ts +13 -0
- package/lib/composables/useEventListener.d.ts +1 -0
- package/lib/composables/useInput.d.ts +36 -0
- package/lib/composables/useIsServer.d.ts +1 -0
- package/lib/composables/useMount.d.ts +13 -0
- package/lib/composables/usePopper.d.ts +31 -0
- package/lib/create.d.ts +9 -0
- package/lib/index.cjs.js +5 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.es.js +3164 -0
- package/lib/install.d.ts +4 -0
- package/lib/nuxt.js +33 -0
- package/lib/nuxt.plugin.js +8 -0
- package/lib/style.css +1 -0
- package/lib/types/props.d.ts +2 -0
- package/package.json +75 -0
- package/src/__storybook__/argTypes.ts +42 -0
- package/src/__storybook__/createStory.ts +15 -0
- package/src/__storybook__/index.ts +2 -0
- package/src/components/avatar/Avatar.css +69 -0
- package/src/components/avatar/Avatar.vue +102 -0
- package/src/components/avatargroup/AvatarGroup.css +8 -0
- package/src/components/avatargroup/AvatarGroup.vue +32 -0
- package/src/components/breadcrumb/Breadcrumb.css +46 -0
- package/src/components/breadcrumb/Breadcrumb.vue +51 -0
- package/src/components/breadcrumbitem/BreadcrumbItem.vue +66 -0
- package/src/components/breadcrumbitem/index.ts +1 -0
- package/src/components/button/Button.css +378 -0
- package/src/components/button/Button.vue +108 -0
- package/src/components/buttongroup/ButtonGroup.vue +47 -0
- package/src/components/checkbox/Checkbox.css +185 -0
- package/src/components/checkbox/Checkbox.vue +140 -0
- package/src/components/dropdown/Dropdown.css +68 -0
- package/src/components/dropdown/Dropdown.vue +237 -0
- package/src/components/dropdown/DropdownItem.vue +118 -0
- package/src/components/dropdown/DropdownList.vue +20 -0
- package/src/components/dropdown/DropdownWrapper.vue +17 -0
- package/src/components/dropdown/hooks.ts +30 -0
- package/src/components/form/Form.vue +141 -0
- package/src/components/image/Image.vue +71 -0
- package/src/components/index.ts +27 -0
- package/src/components/input/Input.css +173 -0
- package/src/components/input/Input.vue +176 -0
- package/src/components/link/Link.css +147 -0
- package/src/components/link/Link.vue +54 -0
- package/src/components/messageprovider/Message.vue +76 -0
- package/src/components/messageprovider/MessageProvider.css +36 -0
- package/src/components/messageprovider/MessageProvider.vue +142 -0
- package/src/components/messageprovider/types.ts +39 -0
- package/src/components/messageprovider/useMessage.ts +12 -0
- package/src/components/select/Select.css +226 -0
- package/src/components/select/Select.vue +474 -0
- package/src/components/skeleton/Skeleton.css +73 -0
- package/src/components/skeleton/Skeleton.vue +47 -0
- package/src/components/tab/Tab.css +113 -0
- package/src/components/tab/Tab.vue +98 -0
- package/src/components/tab/TabGroup.vue +90 -0
- package/src/components/table/Table.css +45 -0
- package/src/components/table/Table.vue +108 -0
- package/src/components/table/TableBody.vue +13 -0
- package/src/components/table/TableCell.vue +13 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeadRow.vue +15 -0
- package/src/components/table/TableRow.vue +13 -0
- package/src/components/table/types/index.ts +5 -0
- package/src/components/tooltip/Tooltip.css +49 -0
- package/src/components/tooltip/Tooltip.vue +85 -0
- package/src/components/virtualscroll/VirtualScroll.css +13 -0
- package/src/components/virtualscroll/VirtualScroll.vue +61 -0
- package/src/composables/element.ts +13 -0
- package/src/composables/useCachedUid.ts +48 -0
- package/src/composables/useEventListener.ts +14 -0
- package/src/composables/useInput.ts +134 -0
- package/src/composables/useIsServer.ts +7 -0
- package/src/composables/useMount.ts +43 -0
- package/src/composables/usePopper.ts +194 -0
- package/src/create.ts +34 -0
- package/src/css/components.css +14 -0
- package/src/css/index.css +4 -0
- package/src/css/normalize.css +379 -0
- package/src/css/transitions.css +40 -0
- package/src/css/variables.css +80 -0
- package/src/exports/nuxt.js +33 -0
- package/src/exports/nuxt.plugin.js +8 -0
- package/src/index.ts +5 -0
- package/src/install.ts +8 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/types/props.ts +3 -0
- package/volar.d.ts +16 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<form :styles="computedStyles" :class="[
|
|
3
|
+
computedClasses
|
|
4
|
+
]" @submit.prevent="submit">
|
|
5
|
+
<slot />
|
|
6
|
+
</form>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { defineComponent, provide, reactive, computed, onMounted, watch, nextTick, ref } from 'vue';
|
|
11
|
+
import type { PropType } from 'vue';
|
|
12
|
+
|
|
13
|
+
const injectKey = "m-form";
|
|
14
|
+
|
|
15
|
+
export type FormError = {
|
|
16
|
+
field: string;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type Form = {
|
|
21
|
+
name: string;
|
|
22
|
+
focus: () => void;
|
|
23
|
+
validate: () => boolean;
|
|
24
|
+
setError: (error: string) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default defineComponent({
|
|
28
|
+
name: "MForm",
|
|
29
|
+
props: {
|
|
30
|
+
disabled: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
default: false,
|
|
33
|
+
},
|
|
34
|
+
loading: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: false,
|
|
37
|
+
},
|
|
38
|
+
errors: {
|
|
39
|
+
type: [Array, Object] as PropType<[FormError[], FormError]>,
|
|
40
|
+
default: () => ([]),
|
|
41
|
+
},
|
|
42
|
+
autoValidate: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: true,
|
|
45
|
+
},
|
|
46
|
+
autoFocus: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
emits: [
|
|
52
|
+
"submit"
|
|
53
|
+
],
|
|
54
|
+
setup(props, { emit }) {
|
|
55
|
+
const inputs: Form[] = [];
|
|
56
|
+
|
|
57
|
+
provide(injectKey, {
|
|
58
|
+
add: (name: string, focus: () => void, validate: () => boolean, setError: (error: string) => void) => {
|
|
59
|
+
const exists = inputs.find((input) => input.name === name);
|
|
60
|
+
|
|
61
|
+
if (exists) {
|
|
62
|
+
exists.focus = focus;
|
|
63
|
+
exists.validate = validate;
|
|
64
|
+
exists.setError = setError;
|
|
65
|
+
} else {
|
|
66
|
+
inputs.push({
|
|
67
|
+
name,
|
|
68
|
+
focus,
|
|
69
|
+
validate,
|
|
70
|
+
setError,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
remove: (name: string) => {
|
|
75
|
+
const index = inputs.findIndex((input) => input.name === name);
|
|
76
|
+
inputs.splice(index, 1);
|
|
77
|
+
},
|
|
78
|
+
insideForm: true,
|
|
79
|
+
disabled: ref(props.disabled),
|
|
80
|
+
loading: ref(props.loading),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
onMounted(() => {
|
|
84
|
+
if (props.autoFocus && inputs && inputs.length > 0) {
|
|
85
|
+
inputs[0].focus();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
watch(() => props.errors, (errors) => {
|
|
90
|
+
if (errors) {
|
|
91
|
+
nextTick(() => {
|
|
92
|
+
if (Array.isArray(errors)) {
|
|
93
|
+
errors.forEach((error: any) => {
|
|
94
|
+
const input = inputs.find((i) => i.name === error.field)
|
|
95
|
+
if (input) input.setError(error.message)
|
|
96
|
+
})
|
|
97
|
+
} else {
|
|
98
|
+
const input = inputs.find((i) => i.name === (errors as FormError).field)
|
|
99
|
+
if (input) input.setError((errors as FormError).message)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const validate = () => {
|
|
106
|
+
let isValid = true;
|
|
107
|
+
|
|
108
|
+
inputs.forEach((input) => {
|
|
109
|
+
if (!input.validate()) {
|
|
110
|
+
isValid = false;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return isValid;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const submit = (e: Event) => {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
|
|
121
|
+
emit("submit", props.autoValidate ? validate() : true);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const computedStyles = computed(() => {
|
|
125
|
+
return [];
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const computedClasses = computed(() => {
|
|
129
|
+
return [
|
|
130
|
+
"m-form"
|
|
131
|
+
];
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
submit,
|
|
136
|
+
computedStyles,
|
|
137
|
+
computedClasses
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
</script>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<img :class="computedClasses" :style="computedStyles" :src="source" :alt="alt" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { defineComponent, watch, ref, computed } from 'vue';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default defineComponent({
|
|
10
|
+
name: "MImage",
|
|
11
|
+
props: {
|
|
12
|
+
src: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
scrSet: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: "",
|
|
19
|
+
},
|
|
20
|
+
fit: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: "cover",
|
|
23
|
+
},
|
|
24
|
+
alt: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: "",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
emits: {
|
|
30
|
+
error: (e: Event) => true
|
|
31
|
+
},
|
|
32
|
+
setup(props, { emit }) {
|
|
33
|
+
const source = ref<string | undefined>("");
|
|
34
|
+
|
|
35
|
+
if (typeof window !== 'undefined' && Image) {
|
|
36
|
+
watch(() => props.src, (src) => {
|
|
37
|
+
if(!src) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const image = new Image();
|
|
42
|
+
image.onload = () => {
|
|
43
|
+
source.value = props.src;
|
|
44
|
+
};
|
|
45
|
+
image.onerror = () => {
|
|
46
|
+
emit('error', new Event('error'));
|
|
47
|
+
};
|
|
48
|
+
image.src = src;
|
|
49
|
+
},
|
|
50
|
+
{ immediate: true })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const computedClasses = computed(() => {
|
|
54
|
+
return {
|
|
55
|
+
"m-image": true,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const computedStyles = computed(() => {
|
|
60
|
+
return {
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
source,
|
|
66
|
+
computedClasses,
|
|
67
|
+
computedStyles,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
</script>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { default as MButton } from './button/Button.vue';
|
|
2
|
+
export { default as MButtonGroup } from './buttongroup/ButtonGroup.vue';
|
|
3
|
+
export { default as MForm } from './form/Form.vue';
|
|
4
|
+
export { default as MInput } from './input/Input.vue';
|
|
5
|
+
export { default as MSelect } from './select/Select.vue';
|
|
6
|
+
export { default as MCheckbox } from './checkbox/Checkbox.vue';
|
|
7
|
+
export { default as MBreadcrumb } from './breadcrumb/Breadcrumb.vue';
|
|
8
|
+
export { default as MBreadcrumbItem } from './breadcrumbitem/BreadcrumbItem.vue';
|
|
9
|
+
// export { default as MVirtualScroll } from './virtualscroll/VirtualScroll.vue';
|
|
10
|
+
export { default as MAvatar } from './avatar/Avatar.vue';
|
|
11
|
+
export { default as MAvatarGroup } from './avatargroup/AvatarGroup.vue';
|
|
12
|
+
export { default as MImage } from './image/Image.vue';
|
|
13
|
+
export { default as MSkeleton } from './skeleton/Skeleton.vue';
|
|
14
|
+
export { default as MLink } from './link/Link.vue';
|
|
15
|
+
export { default as MTooltip } from './tooltip/Tooltip.vue';
|
|
16
|
+
export { default as MTabGroup } from './tab/TabGroup.vue';
|
|
17
|
+
export { default as MTab } from './tab/Tab.vue';
|
|
18
|
+
export { default as MTable } from './table/Table.vue';
|
|
19
|
+
export { default as MTableBody } from './table/TableBody.vue';
|
|
20
|
+
export { default as MTableCell } from './table/TableCell.vue';
|
|
21
|
+
export { default as MTableHead } from './table/TableHead.vue';
|
|
22
|
+
export { default as MTableHeadRow } from './table/TableHeadRow.vue';
|
|
23
|
+
export { default as MTableRow } from './table/TableRow.vue';
|
|
24
|
+
export { default as MDropdown } from './dropdown/Dropdown.vue';
|
|
25
|
+
export { default as MDropdownWrapper } from './dropdown/DropdownWrapper.vue';
|
|
26
|
+
export { default as MDropdownList } from './dropdown/DropdownList.vue';
|
|
27
|
+
export { default as MDropdownItem } from './dropdown/DropdownItem.vue';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
.m-input__container {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.m-input {
|
|
9
|
+
--input-height: 40px;
|
|
10
|
+
--input-padding: 0 8px;
|
|
11
|
+
--input-font-size: 15px;
|
|
12
|
+
--input-border-radius: 4px;
|
|
13
|
+
--input-clear-size: 1.2rem;
|
|
14
|
+
--input-background-color: var(--white);
|
|
15
|
+
--input-border-color: var(--gray-200);
|
|
16
|
+
|
|
17
|
+
position: relative;
|
|
18
|
+
display: inline-flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
height: var(--input-height);
|
|
21
|
+
font-size: var(--input-font-size);
|
|
22
|
+
background-color: var(--input-background-color);
|
|
23
|
+
border: 1px solid var(--input-border-color);
|
|
24
|
+
box-shadow: none;
|
|
25
|
+
border-radius: var(--input-border-radius);
|
|
26
|
+
outline: 0;
|
|
27
|
+
cursor: text;
|
|
28
|
+
transition: color .3s cubic-bezier(0.4, 0, 0.2, 1), background-color .3s cubic-bezier(0.4, 0, 0.2, 1), border-color .3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow .3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.m-input.m-input--disabled {
|
|
32
|
+
--input-border-color: var(--gray-300);
|
|
33
|
+
--input-background-color: var(--gray-100);
|
|
34
|
+
opacity: 0.6;
|
|
35
|
+
cursor: not-allowed;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.m-input.m-input--disabled input {
|
|
39
|
+
cursor: not-allowed;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.m-input:not(.m-input--disabled):focus-within {
|
|
43
|
+
--input-border-color: var(--blue);
|
|
44
|
+
box-shadow: 0 0 0 2px var(--blue-outline);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.m-input:not(.m-input--disabled):not(:focus-within):hover {
|
|
48
|
+
--input-border-color: var(--gray-400);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.m-input input {
|
|
52
|
+
flex: 1 0 0;
|
|
53
|
+
min-width: 0;
|
|
54
|
+
height: 100%;
|
|
55
|
+
padding: var(--input-padding);
|
|
56
|
+
font-size: inherit;
|
|
57
|
+
color: var(--gray-600);
|
|
58
|
+
background-color: transparent;
|
|
59
|
+
border: 0;
|
|
60
|
+
outline: 0;
|
|
61
|
+
border-radius: var(--input-border-radius);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.m-input__clearable {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
justify-content: center;
|
|
68
|
+
padding: 0 6px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.m-input .m-input__clearable i.m-icon--close {
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
width: var(--input-clear-size);
|
|
74
|
+
height: var(--input-clear-size);
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
border-radius: 100%;
|
|
79
|
+
color: var(--gray-500);
|
|
80
|
+
background-color: transparent;
|
|
81
|
+
transition: background-color .125s cubic-bezier(0.4, 0, 0.2, 1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.m-input .m-input__clearable i.m-icon--close:hover {
|
|
85
|
+
color: var(--gray-500);
|
|
86
|
+
background-color: var(--gray-150);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.m-input i.m-icon--close::before {
|
|
90
|
+
--close-icon-size: 16px;
|
|
91
|
+
background-color: currentColor;
|
|
92
|
+
content: "";
|
|
93
|
+
width: var(--close-icon-size);
|
|
94
|
+
height: var(--close-icon-size);
|
|
95
|
+
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor' class='w-5 h-5'%3E%3Cpath d='M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z' /%3E%3C/svg%3E%0A");
|
|
96
|
+
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor' class='w-5 h-5'%3E%3Cpath d='M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z' /%3E%3C/svg%3E%0A");
|
|
97
|
+
-webkit-mask-position: center center;
|
|
98
|
+
mask-position: center center;
|
|
99
|
+
-webkit-mask-repeat: no-repeat;
|
|
100
|
+
mask-repeat: no-repeat;
|
|
101
|
+
-webkit-mask-size: var(--close-icon-size) var(--close-icon-size);
|
|
102
|
+
mask-size: var(--close-icon-size) var(--close-icon-size);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.m-input--xs {
|
|
106
|
+
--input-height: 32px;
|
|
107
|
+
--input-padding: 0 8px;
|
|
108
|
+
--input-font-size: 13px;
|
|
109
|
+
--input-border-radius: 4px;
|
|
110
|
+
--input-clear-size: 1.2rem;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.m-input--sm {
|
|
114
|
+
--input-height: 36px;
|
|
115
|
+
--input-padding: 0 8px;
|
|
116
|
+
--input-font-size: 14px;
|
|
117
|
+
--input-border-radius: 4px;
|
|
118
|
+
--input-clear-size: 1.2rem;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.m-input--md {
|
|
122
|
+
--input-height: 40px;
|
|
123
|
+
--input-padding: 0 8px;
|
|
124
|
+
--input-font-size: 15px;
|
|
125
|
+
--input-border-radius: 4px;
|
|
126
|
+
--input-clear-size: 1.2rem;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.m-input--lg {
|
|
130
|
+
--input-height: 42px;
|
|
131
|
+
--input-padding: 0 8px;
|
|
132
|
+
--input-font-size: 16px;
|
|
133
|
+
--input-border-radius: 4px;
|
|
134
|
+
--input-clear-size: 1.2rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.m-input--xl {
|
|
138
|
+
--input-height: 46px;
|
|
139
|
+
--input-padding: 0 8px;
|
|
140
|
+
--input-font-size: 18px;
|
|
141
|
+
--input-border-radius: 6px;
|
|
142
|
+
--input-clear-size: 1.2rem;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.m-input__label {
|
|
146
|
+
margin-bottom: 5px;
|
|
147
|
+
color: var(--gray-600);
|
|
148
|
+
font-size: 15px;
|
|
149
|
+
font-weight: 600;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.m-input__help {
|
|
153
|
+
margin-top: 4px;
|
|
154
|
+
color: var(--gray-500);
|
|
155
|
+
font-size: 15px;
|
|
156
|
+
font-weight: 400;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.m-input__error {
|
|
160
|
+
margin: 4px 0 8px 0;
|
|
161
|
+
color: var(--red);
|
|
162
|
+
font-size: 15px;
|
|
163
|
+
font-weight: 400;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.m-form .m-form__input {
|
|
167
|
+
margin-bottom: 16px;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.m-form .m-form__input .m-input__error {
|
|
171
|
+
margin: 4px 0 0 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="wrapperComputedClasses" ref="container">
|
|
3
|
+
<label v-if="label" :for="id" class="m-input__label" :id="`${id}-label`">
|
|
4
|
+
{{ label }}
|
|
5
|
+
</label>
|
|
6
|
+
|
|
7
|
+
<div :class="inputComputedClasses">
|
|
8
|
+
<div v-if="hasPrefix" class="m-input__prefix">
|
|
9
|
+
<slot name="prefix" />
|
|
10
|
+
</div>
|
|
11
|
+
<input
|
|
12
|
+
ref="input"
|
|
13
|
+
:id="id"
|
|
14
|
+
:type="inputType"
|
|
15
|
+
:placeholder="placeholder"
|
|
16
|
+
:name="name"
|
|
17
|
+
:value="modelValue || ''"
|
|
18
|
+
:readonly="readonly"
|
|
19
|
+
v-on="listeners"
|
|
20
|
+
v-bind="$attrs"
|
|
21
|
+
:disabled="disabled || loading"
|
|
22
|
+
:aria-disabled="disabled ? 'true' : 'false'"
|
|
23
|
+
:aria-labelledby="`${id}-label`"
|
|
24
|
+
/>
|
|
25
|
+
<div v-if="hasSuffix" class="m-input__suffix">
|
|
26
|
+
<slot name="suffix" />
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<p v-if="help && !inputError" class="m-input__help">
|
|
30
|
+
{{ help }}
|
|
31
|
+
</p>
|
|
32
|
+
<p v-else-if="inputError" class="m-input__error">
|
|
33
|
+
{{ inputError }}
|
|
34
|
+
</p>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script lang="ts">
|
|
39
|
+
import type { PropType } from "vue";
|
|
40
|
+
import type { Size } from "@/types/props";
|
|
41
|
+
import {
|
|
42
|
+
defineComponent,
|
|
43
|
+
ref,
|
|
44
|
+
computed,
|
|
45
|
+
toRef,
|
|
46
|
+
} from "vue";
|
|
47
|
+
import { useInput } from "@/composables/useInput";
|
|
48
|
+
export default defineComponent({
|
|
49
|
+
name: 'MInput',
|
|
50
|
+
emits: useInput.emits(),
|
|
51
|
+
props: {
|
|
52
|
+
...useInput.props(),
|
|
53
|
+
label: {
|
|
54
|
+
type: String
|
|
55
|
+
},
|
|
56
|
+
size: {
|
|
57
|
+
type: String as PropType<Size>,
|
|
58
|
+
default: 'md',
|
|
59
|
+
},
|
|
60
|
+
type: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: 'text',
|
|
63
|
+
validator: (value: string) => ['text', 'password', 'number'].includes(value)
|
|
64
|
+
},
|
|
65
|
+
placeholder: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: ''
|
|
68
|
+
},
|
|
69
|
+
loading: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false
|
|
72
|
+
},
|
|
73
|
+
readonly: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: false
|
|
76
|
+
},
|
|
77
|
+
disabled: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false
|
|
80
|
+
},
|
|
81
|
+
help: {
|
|
82
|
+
type: String,
|
|
83
|
+
default: ''
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
setup(props, { slots, emit }) {
|
|
87
|
+
const focus = () => {};
|
|
88
|
+
const {
|
|
89
|
+
id,
|
|
90
|
+
insideForm,
|
|
91
|
+
reset,
|
|
92
|
+
listeners,
|
|
93
|
+
validate,
|
|
94
|
+
setError,
|
|
95
|
+
formError,
|
|
96
|
+
formDisabled,
|
|
97
|
+
formLoading
|
|
98
|
+
} = useInput(props, { focus, emit });
|
|
99
|
+
|
|
100
|
+
const input = ref<HTMLInputElement>();
|
|
101
|
+
const focused = ref(false);
|
|
102
|
+
const showPassword = ref(false);
|
|
103
|
+
const name = toRef(props, 'name');
|
|
104
|
+
|
|
105
|
+
const hasPrefix = computed(() => !!(slots.prefix));
|
|
106
|
+
const hasSuffix = computed(() => !!(slots.suffix));
|
|
107
|
+
const disabled = computed(() => formDisabled || props.disabled);
|
|
108
|
+
const loading = computed(() => formLoading || props.loading);
|
|
109
|
+
|
|
110
|
+
const inputType = computed(() => {
|
|
111
|
+
const type = props.type;
|
|
112
|
+
if (type === 'password') {
|
|
113
|
+
return showPassword.value ? 'text' : 'password';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return type;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const readonly = computed(() => (props.loading || props.readonly));
|
|
120
|
+
|
|
121
|
+
const wrapperComputedClasses = computed(() => {
|
|
122
|
+
return [
|
|
123
|
+
'm-input__container',
|
|
124
|
+
{
|
|
125
|
+
'm-form__input': insideForm
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const inputComputedClasses = computed(() => {
|
|
131
|
+
return [
|
|
132
|
+
'm-input',
|
|
133
|
+
`m-input--${props.size}`,
|
|
134
|
+
{
|
|
135
|
+
'm-input--disabled': disabled.value || loading.value,
|
|
136
|
+
'm-input--readonly': readonly.value,
|
|
137
|
+
'm-input--focused': focused.value,
|
|
138
|
+
'm-input--error': inputError.value,
|
|
139
|
+
'm-input--prefix': hasPrefix.value,
|
|
140
|
+
'm-input--suffix': hasSuffix.value,
|
|
141
|
+
'm-input--loading': props.loading,
|
|
142
|
+
'm-input--password': props.type === 'password'
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const inputError = computed(() => {
|
|
148
|
+
return formError.value || props.error;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const onClear = () => {
|
|
152
|
+
emit('update:modelValue', '');
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
id,
|
|
157
|
+
inputType,
|
|
158
|
+
disabled,
|
|
159
|
+
loading,
|
|
160
|
+
readonly,
|
|
161
|
+
inputComputedClasses,
|
|
162
|
+
wrapperComputedClasses,
|
|
163
|
+
name,
|
|
164
|
+
hasPrefix,
|
|
165
|
+
hasSuffix,
|
|
166
|
+
inputError,
|
|
167
|
+
|
|
168
|
+
onClear,
|
|
169
|
+
focus,
|
|
170
|
+
validate,
|
|
171
|
+
setError,
|
|
172
|
+
listeners
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
</script>
|