@teammodlr/ui-kit 2.1.41 → 2.1.43
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 -1
- package/lib/components/checkbox/Checkbox.vue.d.ts +1 -0
- package/lib/components/checkbox/style/Checkbox.css.d.ts +1 -0
- package/lib/index.cjs.js +8 -8
- package/lib/index.es.js +1352 -1342
- package/lib/nuxt.js +35 -35
- package/lib/nuxt.plugin.js +8 -8
- package/lib/style.css +1 -1
- package/package.json +89 -89
- package/src/__storybook__/argTypes.ts +53 -53
- package/src/__storybook__/createStory.ts +15 -15
- package/src/__storybook__/index.ts +2 -2
- package/src/call.ts +34 -34
- package/src/components/avatar/Avatar.vue +110 -110
- package/src/components/avatar/examples/basic.vue +6 -6
- package/src/components/avatar/examples/custom-size.vue +7 -7
- package/src/components/avatar/examples/index.ts +5 -5
- package/src/components/avatar/examples/sizes.vue +33 -33
- package/src/components/avatar/examples/slots.vue +8 -8
- package/src/components/avatar/examples/variants.vue +18 -18
- package/src/components/avatar/style/Avatar.css.ts +92 -92
- package/src/components/avatar/style/index.ts +1 -1
- package/src/components/avatargroup/AvatarGroup.vue +72 -72
- package/src/components/avatargroup/examples/basic.vue +37 -37
- package/src/components/avatargroup/examples/index.ts +1 -1
- package/src/components/avatargroup/style/AvatarGroup.css.ts +26 -26
- package/src/components/avatargroup/style/index.ts +1 -1
- package/src/components/avatargroup/symbol.ts +17 -17
- package/src/components/badge/Badge.vue +43 -43
- package/src/components/badge/examples/basic.vue +10 -10
- package/src/components/badge/examples/index.ts +1 -1
- package/src/components/badge/style/Badge.css.ts +135 -135
- package/src/components/badge/style/index.ts +1 -1
- package/src/components/breadcrumb/Breadcrumb.vue +54 -54
- package/src/components/breadcrumb/BreadcrumbItem.vue +72 -72
- package/src/components/breadcrumb/examples/basic.vue +7 -7
- package/src/components/breadcrumb/examples/index.ts +1 -1
- package/src/components/breadcrumb/style/Breadcrumb.css.ts +40 -40
- package/src/components/breadcrumb/style/index.ts +1 -1
- package/src/components/breadcrumb/symbol.ts +18 -18
- package/src/components/button/Button.vue +203 -203
- package/src/components/button/examples/basic.vue +3 -3
- package/src/components/button/examples/disabled.vue +3 -3
- package/src/components/button/examples/icon-left.vue +12 -12
- package/src/components/button/examples/icon.vue +9 -9
- package/src/components/button/examples/index.ts +9 -9
- package/src/components/button/examples/link.vue +3 -3
- package/src/components/button/examples/rounded.vue +7 -7
- package/src/components/button/examples/size.vue +7 -7
- package/src/components/button/examples/variants-secondary.vue +10 -10
- package/src/components/button/examples/variants.vue +10 -10
- package/src/components/button/style/Button.css.ts +695 -695
- package/src/components/button/style/index.ts +1 -1
- package/src/components/buttongroup/ButtonGroup.vue +36 -36
- package/src/components/buttongroup/examples/basic.vue +9 -9
- package/src/components/buttongroup/examples/icon-group.vue +21 -21
- package/src/components/buttongroup/examples/index.ts +2 -2
- package/src/components/buttongroup/style/ButtonGroup.css.ts +42 -42
- package/src/components/buttongroup/style/index.ts +1 -1
- package/src/components/buttongroup/symbol.ts +9 -9
- package/src/components/checkbox/Checkbox.vue +149 -145
- package/src/components/checkbox/examples/basic.vue +9 -9
- package/src/components/checkbox/examples/index.ts +2 -2
- package/src/components/checkbox/examples/slot.vue +14 -11
- package/src/components/checkbox/style/Checkbox.css.ts +178 -161
- package/src/components/checkbox/style/index.ts +1 -1
- package/src/components/colorpicker/ColorPicker.vue +333 -333
- package/src/components/colorpicker/examples/basic.vue +2 -2
- package/src/components/colorpicker/examples/index.ts +1 -1
- package/src/components/colorpicker/style/ColorPicker.css.ts +127 -127
- package/src/components/colorpicker/style/index.ts +1 -1
- package/src/components/colorpicker/utils.ts +206 -206
- package/src/components/confirm/Confirm.vue +65 -65
- package/src/components/confirm/ConfirmProvider.vue +83 -83
- package/src/components/confirm/examples/basic.vue +48 -48
- package/src/components/confirm/examples/index.ts +1 -1
- package/src/components/confirm/examples/wrapper.vue +9 -9
- package/src/components/confirm/props.ts +24 -24
- package/src/components/confirm/providerProps.ts +10 -10
- package/src/components/confirm/types.ts +33 -33
- package/src/components/confirm/useConfirm.ts +14 -14
- package/src/components/dialog/Dialog.vue +118 -118
- package/src/components/dialog/examples/basic.vue +16 -16
- package/src/components/dialog/examples/index.ts +1 -1
- package/src/components/dialog/style/Dialog.css.ts +100 -100
- package/src/components/dialog/style/index.ts +1 -1
- package/src/components/dropdown/Dropdown.vue +308 -308
- package/src/components/dropdown/DropdownHeading.vue +23 -23
- package/src/components/dropdown/DropdownItem.vue +151 -151
- package/src/components/dropdown/DropdownList.vue +20 -20
- package/src/components/dropdown/DropdownSeperator.vue +22 -22
- package/src/components/dropdown/DropdownWrapper.vue +18 -18
- package/src/components/dropdown/examples/basic.vue +119 -119
- package/src/components/dropdown/examples/context.vue +71 -71
- package/src/components/dropdown/examples/index.ts +3 -3
- package/src/components/dropdown/hooks.ts +30 -30
- package/src/components/dropdown/style/Dropdown.css.ts +158 -158
- package/src/components/dropdown/style/index.ts +1 -1
- package/src/components/dropdown/symbol.ts +9 -9
- package/src/components/form/Form.vue +153 -153
- package/src/components/form/examples/basic.vue +75 -75
- package/src/components/form/examples/index.ts +1 -1
- package/src/components/form/style/Form.css.ts +28 -28
- package/src/components/form/style/index.ts +2 -2
- package/src/components/form/symbol.ts +16 -16
- package/src/components/image/Image.vue +71 -71
- package/src/components/image/examples/basic.vue +5 -5
- package/src/components/image/examples/index.ts +1 -1
- package/src/components/index.ts +47 -47
- package/src/components/input/Input.vue +233 -233
- package/src/components/input/examples/basic.vue +21 -21
- package/src/components/input/examples/index.ts +6 -6
- package/src/components/input/examples/left-icon.vue +9 -9
- package/src/components/input/examples/prefix.vue +5 -5
- package/src/components/input/examples/right-icon.vue +9 -9
- package/src/components/input/examples/sizes.vue +9 -9
- package/src/components/input/examples/suffix.vue +7 -7
- package/src/components/input/style/Input.css.ts +294 -294
- package/src/components/input/style/index.ts +1 -1
- package/src/components/link/Link.vue +53 -53
- package/src/components/link/examples/basic.vue +3 -3
- package/src/components/link/examples/index.ts +1 -1
- package/src/components/messageprovider/Message.vue +135 -135
- package/src/components/messageprovider/MessageProvider.vue +156 -156
- package/src/components/messageprovider/examples/basic.vue +70 -70
- package/src/components/messageprovider/examples/index.ts +2 -2
- package/src/components/messageprovider/examples/update.vue +34 -34
- package/src/components/messageprovider/examples/wrapper.vue +9 -9
- package/src/components/messageprovider/style/Message.css.ts +111 -111
- package/src/components/messageprovider/style/index.ts +1 -1
- package/src/components/messageprovider/types.ts +56 -56
- package/src/components/messageprovider/useMessage.ts +14 -14
- package/src/components/modal/Modal.vue +310 -310
- package/src/components/modal/examples/basic.vue +80 -80
- package/src/components/modal/examples/index.ts +3 -3
- package/src/components/modal/examples/modal-form.vue +99 -99
- package/src/components/modal/examples/sidebar.vue +79 -79
- package/src/components/modal/style/Modal.css.ts +318 -318
- package/src/components/modal/style/index.ts +1 -1
- package/src/components/pagination/Pagination.vue +296 -296
- package/src/components/pagination/examples/basic.vue +17 -17
- package/src/components/pagination/examples/index.ts +1 -1
- package/src/components/pagination/style/Pagination.css.ts +93 -93
- package/src/components/pagination/style/index.ts +1 -1
- package/src/components/radio/Radio.vue +136 -136
- package/src/components/radio/examples/basic.vue +8 -8
- package/src/components/radio/examples/group.vue +15 -15
- package/src/components/radio/examples/index.ts +2 -2
- package/src/components/radio/style/Checkbox.css.ts +130 -130
- package/src/components/radio/style/index.ts +1 -1
- package/src/components/radiobutton/RadioButton.vue +131 -131
- package/src/components/radiobutton/style/RadioButton.css.ts +189 -189
- package/src/components/radiobutton/style/index.ts +1 -1
- package/src/components/radiobuttongroup/RadioButtonGroup.vue +74 -74
- package/src/components/radiobuttongroup/examples/basic.vue +16 -16
- package/src/components/radiobuttongroup/examples/index.ts +1 -1
- package/src/components/radiobuttongroup/style/RadioButtonGroup.css.ts +37 -37
- package/src/components/radiobuttongroup/style/index.ts +1 -1
- package/src/components/radiobuttongroup/symbol.ts +12 -12
- package/src/components/renderer/examlpes/basic.vue +23 -23
- package/src/components/renderer/examlpes/index.ts +1 -1
- package/src/components/renderer/props.ts +14 -14
- package/src/components/renderer/renderer.ts +16 -16
- package/src/components/select/Select.vue +781 -781
- package/src/components/select/examples/basic.vue +21 -21
- package/src/components/select/examples/index.ts +3 -3
- package/src/components/select/examples/multiple.vue +21 -21
- package/src/components/select/examples/searchable.vue +20 -20
- package/src/components/select/style/Select.css.ts +368 -368
- package/src/components/select/style/index.ts +1 -1
- package/src/components/skeleton/Skeleton.vue +55 -55
- package/src/components/skeleton/examples/basic.vue +3 -3
- package/src/components/skeleton/examples/index.ts +2 -2
- package/src/components/skeleton/examples/post.vue +8 -8
- package/src/components/skeleton/style/Skeleton.css.ts +72 -72
- package/src/components/skeleton/style/index.ts +2 -2
- package/src/components/slider/Slider.vue +76 -76
- package/src/components/slider/style/Slider.css.ts +50 -50
- package/src/components/slider/style/index.ts +1 -1
- package/src/components/switch/Switch.vue +132 -132
- package/src/components/switch/examples/basic.vue +9 -9
- package/src/components/switch/examples/index.ts +2 -2
- package/src/components/switch/examples/slot.vue +11 -11
- package/src/components/switch/style/Switch.css.ts +135 -135
- package/src/components/switch/style/index.ts +1 -1
- package/src/components/tab/Tab.css +113 -113
- package/src/components/tab/Tab.vue +98 -98
- package/src/components/tab/TabGroup.vue +90 -90
- package/src/components/tab/examples/basic.vue +19 -19
- package/src/components/tab/examples/index.ts +2 -2
- package/src/components/tab/examples/vertical.vue +19 -19
- package/src/components/table/Table.vue +198 -198
- package/src/components/table/TableBody.vue +13 -13
- package/src/components/table/TableCell.vue +13 -13
- package/src/components/table/TableHead.vue +46 -46
- package/src/components/table/TableHeadRow.vue +15 -15
- package/src/components/table/TableRow.vue +19 -19
- package/src/components/table/examples/basic.vue +61 -61
- package/src/components/table/examples/empty.vue +44 -44
- package/src/components/table/examples/index.ts +3 -3
- package/src/components/table/examples/selected.vue +68 -68
- package/src/components/table/style/Table.css.ts +62 -62
- package/src/components/table/style/index.ts +1 -1
- package/src/components/table/types/index.ts +6 -6
- package/src/components/tag/Tag.vue +72 -72
- package/src/components/tag/examples/basic.vue +5 -5
- package/src/components/tag/examples/index.ts +1 -1
- package/src/components/tag/style/Tag.css.ts +83 -83
- package/src/components/tag/style/index.ts +1 -1
- package/src/components/textarea/Textarea.vue +180 -180
- package/src/components/textarea/examples/basic.vue +8 -8
- package/src/components/textarea/examples/index.ts +1 -1
- package/src/components/textarea/style/Textarea.css.ts +191 -191
- package/src/components/textarea/style/index.ts +1 -1
- package/src/components/tooltip/Tooltip.vue +196 -196
- package/src/components/tooltip/examples/basic.vue +5 -5
- package/src/components/tooltip/examples/index.ts +2 -2
- package/src/components/tooltip/examples/placement.vue +9 -9
- package/src/components/tooltip/style/Tooltip.css.ts +90 -90
- package/src/components/tooltip/style/index.ts +1 -1
- package/src/components/transfer/Transfer.vue +145 -145
- package/src/components/transfer/examples/basic.vue +21 -21
- package/src/components/transfer/examples/index.ts +1 -1
- package/src/components/transfer/style/Transfer.css.ts +81 -81
- package/src/components/transfer/style/index.ts +1 -1
- package/src/components/tree/Tree.vue +138 -138
- package/src/components/tree/TreeNode.vue +109 -109
- package/src/components/tree/TreeNodeToggle.vue +48 -48
- package/src/components/tree/examples/basic.vue +458 -458
- package/src/components/tree/examples/index.ts +1 -1
- package/src/components/tree/props.ts +97 -97
- package/src/components/tree/style/Tree.css.ts +75 -75
- package/src/components/tree/style/index.ts +1 -1
- package/src/components/tree/types.ts +103 -103
- package/src/components/virtualscroll/VirtualScroll.css +13 -13
- package/src/components/virtualscroll/VirtualScroll.vue +166 -166
- package/src/components/virtualscroll/examples/basic.vue +31 -31
- package/src/components/virtualscroll/examples/index.ts +1 -1
- package/src/components/virtualscroll/style/VirtualScroll.css.ts +17 -17
- package/src/components/virtualscroll/style/index.ts +1 -1
- package/src/composables/element.ts +13 -13
- package/src/composables/index.ts +4 -4
- package/src/composables/useCachedUid.ts +49 -49
- package/src/composables/useEventListener.ts +19 -19
- package/src/composables/useInput.ts +151 -151
- package/src/composables/useInteractive.ts +19 -19
- package/src/composables/useIsServer.ts +7 -7
- package/src/composables/useMergedState.ts +18 -18
- package/src/composables/useMount.ts +43 -43
- package/src/composables/usePopper.ts +215 -215
- package/src/composables/useZIndex.ts +33 -33
- package/src/create.ts +38 -38
- package/src/css/components.css +16 -16
- package/src/css/index.css +4 -4
- package/src/css/transitions.css +40 -40
- package/src/css/variables.css +80 -80
- package/src/examples/cards/sidebar.vue +262 -262
- package/src/examples/modal/modal.vue +52 -52
- package/src/exports/nuxt.js +35 -35
- package/src/exports/nuxt.plugin.js +8 -8
- package/src/index.ts +5 -5
- package/src/install.ts +8 -8
- package/src/shims-vue.d.ts +6 -6
- package/src/styles/theme.css.ts +181 -181
- package/src/styles/transitions.css.ts +97 -97
- package/src/types/props.ts +19 -19
- package/src/utils/injection.ts +5 -5
- package/volar.d.ts +16 -16
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<form :style="computedStyles" :class="[
|
|
3
|
-
computedClasses
|
|
4
|
-
]" @submit.prevent="submit">
|
|
5
|
-
<slot :loading="loading" />
|
|
6
|
-
</form>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script lang="ts">
|
|
10
|
-
import {defineComponent, provide, reactive, computed, onMounted, watch, nextTick, toRef} from 'vue';
|
|
11
|
-
import type { PropType } from 'vue';
|
|
12
|
-
import * as style from "./style";
|
|
13
|
-
import {FORM_STATE} from "./symbol";
|
|
14
|
-
import type { FormState } from "./symbol";
|
|
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
|
-
spacing: {
|
|
51
|
-
type: String
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
emits: [
|
|
55
|
-
"submit"
|
|
56
|
-
],
|
|
57
|
-
expose: ["submit"],
|
|
58
|
-
setup(props, { emit }) {
|
|
59
|
-
const inputs: Form[] = [];
|
|
60
|
-
|
|
61
|
-
const state: FormState = reactive({
|
|
62
|
-
add: (name: string, focus: () => void, validate: () => boolean, setError: (error: string) => void) => {
|
|
63
|
-
const exists = inputs.find((input) => input.name === name);
|
|
64
|
-
|
|
65
|
-
if (exists) {
|
|
66
|
-
exists.focus = focus;
|
|
67
|
-
exists.validate = validate;
|
|
68
|
-
exists.setError = setError;
|
|
69
|
-
} else {
|
|
70
|
-
inputs.push({
|
|
71
|
-
name,
|
|
72
|
-
focus,
|
|
73
|
-
validate,
|
|
74
|
-
setError,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
remove: (name: string) => {
|
|
79
|
-
const index = inputs.findIndex((input) => input.name === name);
|
|
80
|
-
inputs.splice(index, 1);
|
|
81
|
-
},
|
|
82
|
-
insideForm: true,
|
|
83
|
-
disabled: toRef(props, "disabled"),
|
|
84
|
-
loading: toRef(props, "loading"),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
provide(FORM_STATE, state);
|
|
88
|
-
|
|
89
|
-
onMounted(() => {
|
|
90
|
-
if (props.autoFocus && inputs && inputs.length > 0) {
|
|
91
|
-
inputs[0].focus();
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
watch(() => props.errors, (errors) => {
|
|
96
|
-
if (errors) {
|
|
97
|
-
nextTick(() => {
|
|
98
|
-
if (Array.isArray(errors)) {
|
|
99
|
-
errors.forEach((error: any) => {
|
|
100
|
-
const input = inputs.find((i) => i.name === error.field)
|
|
101
|
-
if (input) input.setError(error.message)
|
|
102
|
-
})
|
|
103
|
-
} else {
|
|
104
|
-
const input = inputs.find((i) => i.name === (errors as FormError).field)
|
|
105
|
-
if (input) input.setError((errors as FormError).message)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const validate = () => {
|
|
112
|
-
let isValid = true;
|
|
113
|
-
|
|
114
|
-
inputs.forEach((input) => {
|
|
115
|
-
if (!input.validate()) {
|
|
116
|
-
isValid = false;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return isValid;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const submit = (e: Event) => {
|
|
124
|
-
e.preventDefault();
|
|
125
|
-
e.stopPropagation();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
emit("submit", props.autoValidate ? validate() : true);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const computedStyles = computed(() => {
|
|
133
|
-
let styles = {} as Record<string, string>;
|
|
134
|
-
if (props.spacing) {
|
|
135
|
-
styles[style.vars.spacing] = props.spacing;
|
|
136
|
-
}
|
|
137
|
-
return style.assignInlineVars(styles);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const computedClasses = computed(() => {
|
|
141
|
-
return [
|
|
142
|
-
style.base
|
|
143
|
-
]
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
submit,
|
|
148
|
-
computedStyles,
|
|
149
|
-
computedClasses
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<form :style="computedStyles" :class="[
|
|
3
|
+
computedClasses
|
|
4
|
+
]" @submit.prevent="submit">
|
|
5
|
+
<slot :loading="loading" />
|
|
6
|
+
</form>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import {defineComponent, provide, reactive, computed, onMounted, watch, nextTick, toRef} from 'vue';
|
|
11
|
+
import type { PropType } from 'vue';
|
|
12
|
+
import * as style from "./style";
|
|
13
|
+
import {FORM_STATE} from "./symbol";
|
|
14
|
+
import type { FormState } from "./symbol";
|
|
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
|
+
spacing: {
|
|
51
|
+
type: String
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
emits: [
|
|
55
|
+
"submit"
|
|
56
|
+
],
|
|
57
|
+
expose: ["submit"],
|
|
58
|
+
setup(props, { emit }) {
|
|
59
|
+
const inputs: Form[] = [];
|
|
60
|
+
|
|
61
|
+
const state: FormState = reactive({
|
|
62
|
+
add: (name: string, focus: () => void, validate: () => boolean, setError: (error: string) => void) => {
|
|
63
|
+
const exists = inputs.find((input) => input.name === name);
|
|
64
|
+
|
|
65
|
+
if (exists) {
|
|
66
|
+
exists.focus = focus;
|
|
67
|
+
exists.validate = validate;
|
|
68
|
+
exists.setError = setError;
|
|
69
|
+
} else {
|
|
70
|
+
inputs.push({
|
|
71
|
+
name,
|
|
72
|
+
focus,
|
|
73
|
+
validate,
|
|
74
|
+
setError,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
remove: (name: string) => {
|
|
79
|
+
const index = inputs.findIndex((input) => input.name === name);
|
|
80
|
+
inputs.splice(index, 1);
|
|
81
|
+
},
|
|
82
|
+
insideForm: true,
|
|
83
|
+
disabled: toRef(props, "disabled"),
|
|
84
|
+
loading: toRef(props, "loading"),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
provide(FORM_STATE, state);
|
|
88
|
+
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
if (props.autoFocus && inputs && inputs.length > 0) {
|
|
91
|
+
inputs[0].focus();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
watch(() => props.errors, (errors) => {
|
|
96
|
+
if (errors) {
|
|
97
|
+
nextTick(() => {
|
|
98
|
+
if (Array.isArray(errors)) {
|
|
99
|
+
errors.forEach((error: any) => {
|
|
100
|
+
const input = inputs.find((i) => i.name === error.field)
|
|
101
|
+
if (input) input.setError(error.message)
|
|
102
|
+
})
|
|
103
|
+
} else {
|
|
104
|
+
const input = inputs.find((i) => i.name === (errors as FormError).field)
|
|
105
|
+
if (input) input.setError((errors as FormError).message)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const validate = () => {
|
|
112
|
+
let isValid = true;
|
|
113
|
+
|
|
114
|
+
inputs.forEach((input) => {
|
|
115
|
+
if (!input.validate()) {
|
|
116
|
+
isValid = false;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return isValid;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const submit = (e: Event) => {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
emit("submit", props.autoValidate ? validate() : true);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const computedStyles = computed(() => {
|
|
133
|
+
let styles = {} as Record<string, string>;
|
|
134
|
+
if (props.spacing) {
|
|
135
|
+
styles[style.vars.spacing] = props.spacing;
|
|
136
|
+
}
|
|
137
|
+
return style.assignInlineVars(styles);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const computedClasses = computed(() => {
|
|
141
|
+
return [
|
|
142
|
+
style.base
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
submit,
|
|
148
|
+
computedStyles,
|
|
149
|
+
computedClasses
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
</script>
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<MForm @submit="onSubmit" :loading="loading">
|
|
3
|
-
<MInput
|
|
4
|
-
label="Email"
|
|
5
|
-
placeholder="Email Address"
|
|
6
|
-
name="email"
|
|
7
|
-
v-model="email"
|
|
8
|
-
:rules="[rules.isRequired, rules.isEmail]"
|
|
9
|
-
/>
|
|
10
|
-
|
|
11
|
-
<MInput
|
|
12
|
-
label="Name"
|
|
13
|
-
placeholder="Name"
|
|
14
|
-
name="name"
|
|
15
|
-
v-model="name"
|
|
16
|
-
:rules="[rules.isRequired]"
|
|
17
|
-
/>
|
|
18
|
-
|
|
19
|
-
<MSelect
|
|
20
|
-
label="Option"
|
|
21
|
-
v-model="option"
|
|
22
|
-
:options="options"
|
|
23
|
-
:option-value="'id'"
|
|
24
|
-
:option-label="'name'"
|
|
25
|
-
:rules="[rules.isRequired]"
|
|
26
|
-
/>
|
|
27
|
-
|
|
28
|
-
<MCheckbox
|
|
29
|
-
label="Agree to terms"
|
|
30
|
-
v-model="agree"
|
|
31
|
-
:rules="[rules.isRequired]"
|
|
32
|
-
>
|
|
33
|
-
Something here!
|
|
34
|
-
</MCheckbox>
|
|
35
|
-
|
|
36
|
-
<MColorPicker />
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<MButton type="submit" color="blue">Submit</MButton>
|
|
40
|
-
</MForm>
|
|
41
|
-
</template>
|
|
42
|
-
|
|
43
|
-
<script lang="ts" setup>
|
|
44
|
-
import { MCheckbox, MSelect, MColorPicker } from '@/components';
|
|
45
|
-
import { ref } from 'vue';
|
|
46
|
-
|
|
47
|
-
const rules = {
|
|
48
|
-
isEmail: (v: any) => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || 'E-mail must be valid',
|
|
49
|
-
isRequired: (v: any) => !!v || 'Field is required',
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const options = Array.from({ length: 50 }, (_, i) => ({
|
|
53
|
-
id: i + 1,
|
|
54
|
-
name: `Option ${i+1}`
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
const loading = ref(false);
|
|
58
|
-
const email = ref('');
|
|
59
|
-
const name = ref('');
|
|
60
|
-
const option = ref('');
|
|
61
|
-
const agree = ref(false);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
function onSubmit(valid: boolean) {
|
|
65
|
-
if (valid) {
|
|
66
|
-
loading.value = true;
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
console.log('submit', { email: email.value, name: name.value });
|
|
69
|
-
loading.value = false;
|
|
70
|
-
}, 3000);
|
|
71
|
-
} else {
|
|
72
|
-
console.log('invalid');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<MForm @submit="onSubmit" :loading="loading">
|
|
3
|
+
<MInput
|
|
4
|
+
label="Email"
|
|
5
|
+
placeholder="Email Address"
|
|
6
|
+
name="email"
|
|
7
|
+
v-model="email"
|
|
8
|
+
:rules="[rules.isRequired, rules.isEmail]"
|
|
9
|
+
/>
|
|
10
|
+
|
|
11
|
+
<MInput
|
|
12
|
+
label="Name"
|
|
13
|
+
placeholder="Name"
|
|
14
|
+
name="name"
|
|
15
|
+
v-model="name"
|
|
16
|
+
:rules="[rules.isRequired]"
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<MSelect
|
|
20
|
+
label="Option"
|
|
21
|
+
v-model="option"
|
|
22
|
+
:options="options"
|
|
23
|
+
:option-value="'id'"
|
|
24
|
+
:option-label="'name'"
|
|
25
|
+
:rules="[rules.isRequired]"
|
|
26
|
+
/>
|
|
27
|
+
|
|
28
|
+
<MCheckbox
|
|
29
|
+
label="Agree to terms"
|
|
30
|
+
v-model="agree"
|
|
31
|
+
:rules="[rules.isRequired]"
|
|
32
|
+
>
|
|
33
|
+
Something here!
|
|
34
|
+
</MCheckbox>
|
|
35
|
+
|
|
36
|
+
<MColorPicker />
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<MButton type="submit" color="blue">Submit</MButton>
|
|
40
|
+
</MForm>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script lang="ts" setup>
|
|
44
|
+
import { MCheckbox, MSelect, MColorPicker } from '@/components';
|
|
45
|
+
import { ref } from 'vue';
|
|
46
|
+
|
|
47
|
+
const rules = {
|
|
48
|
+
isEmail: (v: any) => /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || 'E-mail must be valid',
|
|
49
|
+
isRequired: (v: any) => !!v || 'Field is required',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const options = Array.from({ length: 50 }, (_, i) => ({
|
|
53
|
+
id: i + 1,
|
|
54
|
+
name: `Option ${i+1}`
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const loading = ref(false);
|
|
58
|
+
const email = ref('');
|
|
59
|
+
const name = ref('');
|
|
60
|
+
const option = ref('');
|
|
61
|
+
const agree = ref(false);
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function onSubmit(valid: boolean) {
|
|
65
|
+
if (valid) {
|
|
66
|
+
loading.value = true;
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
console.log('submit', { email: email.value, name: name.value });
|
|
69
|
+
loading.value = false;
|
|
70
|
+
}, 3000);
|
|
71
|
+
} else {
|
|
72
|
+
console.log('invalid');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as MFormBasic } from './basic.vue';
|
|
1
|
+
export { default as MFormBasic } from './basic.vue';
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createVar,
|
|
3
|
-
globalKeyframes,
|
|
4
|
-
globalStyle,
|
|
5
|
-
style
|
|
6
|
-
} from '@vanilla-extract/css';
|
|
7
|
-
import { themeVars } from '../../../styles/theme.css';
|
|
8
|
-
|
|
9
|
-
const borderRadiuses = {
|
|
10
|
-
xs: '2px',
|
|
11
|
-
sm: '3px',
|
|
12
|
-
md: '4px',
|
|
13
|
-
lg: '6px',
|
|
14
|
-
xl: '8px'
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const vars = {
|
|
18
|
-
spacing: createVar()
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const base = style({
|
|
22
|
-
vars: {
|
|
23
|
-
[vars.spacing]: themeVars.space[4]
|
|
24
|
-
},
|
|
25
|
-
display: 'flex',
|
|
26
|
-
flexDirection: 'column',
|
|
27
|
-
gap: vars.spacing
|
|
28
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
createVar,
|
|
3
|
+
globalKeyframes,
|
|
4
|
+
globalStyle,
|
|
5
|
+
style
|
|
6
|
+
} from '@vanilla-extract/css';
|
|
7
|
+
import { themeVars } from '../../../styles/theme.css';
|
|
8
|
+
|
|
9
|
+
const borderRadiuses = {
|
|
10
|
+
xs: '2px',
|
|
11
|
+
sm: '3px',
|
|
12
|
+
md: '4px',
|
|
13
|
+
lg: '6px',
|
|
14
|
+
xl: '8px'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const vars = {
|
|
18
|
+
spacing: createVar()
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const base = style({
|
|
22
|
+
vars: {
|
|
23
|
+
[vars.spacing]: themeVars.space[4]
|
|
24
|
+
},
|
|
25
|
+
display: 'flex',
|
|
26
|
+
flexDirection: 'column',
|
|
27
|
+
gap: vars.spacing
|
|
28
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
2
|
-
export * from './Form.css';
|
|
1
|
+
export { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
2
|
+
export * from './Form.css';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { InjectionKey } from 'vue';
|
|
2
|
-
|
|
3
|
-
export interface FormState {
|
|
4
|
-
add: (
|
|
5
|
-
name: string,
|
|
6
|
-
focus: () => void,
|
|
7
|
-
validate: () => boolean,
|
|
8
|
-
setError: (error: string) => void
|
|
9
|
-
) => void;
|
|
10
|
-
remove: (name: string) => void;
|
|
11
|
-
insideForm: boolean;
|
|
12
|
-
disabled: boolean;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const FORM_STATE: InjectionKey<FormState> = Symbol('FORM_STATE');
|
|
1
|
+
import type { InjectionKey } from 'vue';
|
|
2
|
+
|
|
3
|
+
export interface FormState {
|
|
4
|
+
add: (
|
|
5
|
+
name: string,
|
|
6
|
+
focus: () => void,
|
|
7
|
+
validate: () => boolean,
|
|
8
|
+
setError: (error: string) => void
|
|
9
|
+
) => void;
|
|
10
|
+
remove: (name: string) => void;
|
|
11
|
+
insideForm: boolean;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const FORM_STATE: InjectionKey<FormState> = Symbol('FORM_STATE');
|