@finema/core 1.4.1 → 1.4.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/dist/module.json +1 -1
- package/dist/module.mjs +113 -112
- package/dist/runtime/components/Form/FieldWrapper.vue +6 -2
- package/dist/runtime/components/Form/InputCheckbox/index.vue +2 -3
- package/dist/runtime/components/Form/InputCheckbox/types.d.ts +1 -5
- package/dist/runtime/components/Form/InputDateTime/index.vue +2 -11
- package/dist/runtime/components/Form/InputRadio/index.vue +2 -2
- package/dist/runtime/components/Form/InputRadio/types.d.ts +1 -5
- package/dist/runtime/components/Form/InputSelect/index.vue +3 -3
- package/dist/runtime/components/Form/InputSelect/types.d.ts +0 -1
- package/dist/runtime/components/Form/InputStatic/index.vue +1 -1
- package/dist/runtime/components/Form/InputStatic/types.d.ts +1 -1
- package/dist/runtime/components/Form/InputText/index.vue +3 -7
- package/dist/runtime/components/Form/InputText/types.d.ts +2 -3
- package/dist/runtime/components/Form/InputTextarea/index.vue +2 -7
- package/dist/runtime/components/Form/InputTextarea/types.d.ts +1 -6
- package/dist/runtime/components/Form/InputToggle/index.vue +2 -2
- package/dist/runtime/components/Form/InputToggle/types.d.ts +1 -5
- package/dist/runtime/components/Form/types.d.ts +6 -7
- package/dist/runtime/composables/useForm.d.ts +3 -19
- package/dist/runtime/composables/useForm.mjs +2 -29
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, installModule, addPlugin, addComponentsDir, addImportsDir } from '@nuxt/kit';
|
|
2
|
-
import
|
|
2
|
+
import 'lodash-es';
|
|
3
3
|
|
|
4
4
|
const name = "@finema/core";
|
|
5
|
-
const version = "1.4.
|
|
5
|
+
const version = "1.4.2";
|
|
6
6
|
|
|
7
7
|
const colors = {
|
|
8
8
|
black: "#20243E",
|
|
@@ -67,7 +67,6 @@ const colors = {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
const _merge = merge;
|
|
71
70
|
const isObj = (item) => item && typeof item === "object" && !Array.isArray(item);
|
|
72
71
|
const _deepMerge = (target, ...sources) => {
|
|
73
72
|
if (!sources.length)
|
|
@@ -182,6 +181,101 @@ const button = {
|
|
|
182
181
|
|
|
183
182
|
const buttonGroup = {};
|
|
184
183
|
|
|
184
|
+
const colorModeOptions = {
|
|
185
|
+
preference: "light"
|
|
186
|
+
};
|
|
187
|
+
const veeValidateNuxtOptions = {
|
|
188
|
+
// disable or enable auto imports
|
|
189
|
+
autoImports: true,
|
|
190
|
+
// Use different names for components
|
|
191
|
+
componentNames: {
|
|
192
|
+
Form: "VForm",
|
|
193
|
+
Field: "VField",
|
|
194
|
+
FieldArray: "VFieldArray",
|
|
195
|
+
ErrorMessage: "VErrorMessage"
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const nuxtSecurityOptions = {
|
|
199
|
+
headers: {
|
|
200
|
+
xXSSProtection: "1; mode=block",
|
|
201
|
+
crossOriginEmbedderPolicy: "unsafe-none",
|
|
202
|
+
contentSecurityPolicy: {
|
|
203
|
+
"img-src": ["*", "'self'", "data:", "https"],
|
|
204
|
+
"script-src": [
|
|
205
|
+
"'self'",
|
|
206
|
+
"'unsafe-inline'",
|
|
207
|
+
"https://www.google-analytics.com",
|
|
208
|
+
"https://www.googletagmanager.com",
|
|
209
|
+
"https://fonts.googleapis.com",
|
|
210
|
+
"https://cdnjs.cloudflare.com"
|
|
211
|
+
],
|
|
212
|
+
"script-src-attr": [
|
|
213
|
+
"'unsafe-inline'",
|
|
214
|
+
"https://www.google-analytics.com",
|
|
215
|
+
"https://www.googletagmanager.com",
|
|
216
|
+
"https://fonts.googleapis.com",
|
|
217
|
+
"https://cdnjs.cloudflare.com"
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const nuxtAppOptions = {
|
|
223
|
+
head: {
|
|
224
|
+
htmlAttrs: {
|
|
225
|
+
lang: "en"
|
|
226
|
+
},
|
|
227
|
+
meta: [
|
|
228
|
+
{ charset: "utf-8" },
|
|
229
|
+
{
|
|
230
|
+
name: "viewport",
|
|
231
|
+
content: "width=device-width, initial-scale=1"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "description",
|
|
235
|
+
name: "description",
|
|
236
|
+
content: ""
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "format-detection",
|
|
240
|
+
content: "telephone=no"
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
link: [
|
|
244
|
+
{
|
|
245
|
+
rel: "preconnect",
|
|
246
|
+
href: "https://fonts.googleapis.com"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
rel: "preconnect",
|
|
250
|
+
href: "https://fonts.gstatic.com",
|
|
251
|
+
crossorigin: ""
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
rel: "dns-prefetch",
|
|
255
|
+
href: "https://www.google-analytics.com/"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
rel: "preconnect",
|
|
259
|
+
href: "https://www.google-analytics.com/",
|
|
260
|
+
crossorigin: ""
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
rel: "icon",
|
|
264
|
+
type: "image/x-icon",
|
|
265
|
+
href: "/favicon.ico"
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const nuxtRunTimeConfigOptions = {
|
|
271
|
+
public: {
|
|
272
|
+
baseAPI: process.env.APP_BASE_API,
|
|
273
|
+
baseAPIMock: process.env.APP_BASE_API_MOCK,
|
|
274
|
+
baseInternalAPI: process.env.APP_BASE_INTERNAL_API,
|
|
275
|
+
port: process.env.PORT || "3000"
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
185
279
|
const module = defineNuxtModule({
|
|
186
280
|
meta: {
|
|
187
281
|
name,
|
|
@@ -216,122 +310,29 @@ const module = defineNuxtModule({
|
|
|
216
310
|
await installModule("@nuxt/ui", {
|
|
217
311
|
safelistColors: ["secondary", "success", "info", "danger", "warning"]
|
|
218
312
|
});
|
|
219
|
-
nuxt.options.appConfig.ui =
|
|
220
|
-
table,
|
|
221
|
-
pagination,
|
|
222
|
-
alert,
|
|
223
|
-
button,
|
|
224
|
-
buttonGroup
|
|
225
|
-
});
|
|
226
|
-
nuxt.options.appConfig.ui.strategy = "override";
|
|
227
|
-
nuxt.options.runtimeConfig = _deepMerge(
|
|
228
|
-
{},
|
|
229
|
-
{
|
|
230
|
-
public: {
|
|
231
|
-
baseAPI: process.env.APP_BASE_API,
|
|
232
|
-
baseAPIMock: process.env.APP_BASE_API_MOCK,
|
|
233
|
-
baseInternalAPI: process.env.APP_BASE_INTERNAL_API,
|
|
234
|
-
port: process.env.PORT || "3000"
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
nuxt.options.runtimeConfig
|
|
238
|
-
);
|
|
239
|
-
nuxt.options.app = _deepMerge(
|
|
313
|
+
nuxt.options.appConfig.ui = _deepMerge(
|
|
240
314
|
{},
|
|
241
315
|
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
{ charset: "utf-8" },
|
|
248
|
-
{
|
|
249
|
-
name: "viewport",
|
|
250
|
-
content: "width=device-width, initial-scale=1"
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
id: "description",
|
|
254
|
-
name: "description",
|
|
255
|
-
content: ""
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
name: "format-detection",
|
|
259
|
-
content: "telephone=no"
|
|
260
|
-
}
|
|
261
|
-
],
|
|
262
|
-
link: [
|
|
263
|
-
{
|
|
264
|
-
rel: "preconnect",
|
|
265
|
-
href: "https://fonts.googleapis.com"
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
rel: "preconnect",
|
|
269
|
-
href: "https://fonts.gstatic.com",
|
|
270
|
-
crossorigin: ""
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
rel: "dns-prefetch",
|
|
274
|
-
href: "https://www.google-analytics.com/"
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
rel: "preconnect",
|
|
278
|
-
href: "https://www.google-analytics.com/",
|
|
279
|
-
crossorigin: ""
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
rel: "icon",
|
|
283
|
-
type: "image/x-icon",
|
|
284
|
-
href: "/favicon.ico"
|
|
285
|
-
}
|
|
286
|
-
]
|
|
287
|
-
}
|
|
316
|
+
table,
|
|
317
|
+
pagination,
|
|
318
|
+
alert,
|
|
319
|
+
button,
|
|
320
|
+
buttonGroup
|
|
288
321
|
},
|
|
289
|
-
nuxt.options.
|
|
322
|
+
nuxt.options.appConfig.ui
|
|
290
323
|
);
|
|
291
|
-
nuxt.options.
|
|
324
|
+
nuxt.options.appConfig.ui.strategy = "override";
|
|
325
|
+
nuxt.options.app = _deepMerge({}, nuxtAppOptions, nuxt.options.app);
|
|
326
|
+
nuxt.options.colorMode = _deepMerge({}, colorModeOptions, nuxt.options.colorMode);
|
|
327
|
+
nuxt.options.devtools = _deepMerge({}, { enabled: true }, nuxt.options.devtools);
|
|
328
|
+
nuxt.options.runtimeConfig = _deepMerge(
|
|
292
329
|
{},
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
},
|
|
296
|
-
nuxt.options.colorMode
|
|
330
|
+
nuxtRunTimeConfigOptions,
|
|
331
|
+
nuxt.options.runtimeConfig
|
|
297
332
|
);
|
|
298
|
-
nuxt.options.devtools = _deepMerge({}, { enabled: true }, nuxt.options.devtools);
|
|
299
333
|
await installModule("@pinia/nuxt");
|
|
300
|
-
await installModule("@vee-validate/nuxt",
|
|
301
|
-
|
|
302
|
-
autoImports: true,
|
|
303
|
-
// Use different names for components
|
|
304
|
-
componentNames: {
|
|
305
|
-
Form: "VForm",
|
|
306
|
-
Field: "VField",
|
|
307
|
-
FieldArray: "VFieldArray",
|
|
308
|
-
ErrorMessage: "VErrorMessage"
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
await installModule("nuxt-security", {
|
|
312
|
-
headers: {
|
|
313
|
-
xXSSProtection: "1; mode=block",
|
|
314
|
-
crossOriginEmbedderPolicy: "unsafe-none",
|
|
315
|
-
contentSecurityPolicy: {
|
|
316
|
-
"img-src": ["*", "'self'", "data:", "https"],
|
|
317
|
-
"script-src": [
|
|
318
|
-
"'self'",
|
|
319
|
-
"'unsafe-inline'",
|
|
320
|
-
"https://www.google-analytics.com",
|
|
321
|
-
"https://www.googletagmanager.com",
|
|
322
|
-
"https://fonts.googleapis.com",
|
|
323
|
-
"https://cdnjs.cloudflare.com"
|
|
324
|
-
],
|
|
325
|
-
"script-src-attr": [
|
|
326
|
-
"'unsafe-inline'",
|
|
327
|
-
"https://www.google-analytics.com",
|
|
328
|
-
"https://www.googletagmanager.com",
|
|
329
|
-
"https://fonts.googleapis.com",
|
|
330
|
-
"https://cdnjs.cloudflare.com"
|
|
331
|
-
]
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
});
|
|
334
|
+
await installModule("@vee-validate/nuxt", veeValidateNuxtOptions);
|
|
335
|
+
await installModule("nuxt-security", nuxtSecurityOptions);
|
|
335
336
|
addPlugin({
|
|
336
337
|
src: resolve(runtimeDir, "plugin")
|
|
337
338
|
});
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
<UFormGroup
|
|
3
3
|
:label="label"
|
|
4
4
|
:name="name"
|
|
5
|
+
:description="description"
|
|
6
|
+
:hint="hint"
|
|
7
|
+
:size="size"
|
|
8
|
+
:data-testid="name"
|
|
5
9
|
:help="help"
|
|
6
10
|
:error="errorMessage"
|
|
7
11
|
:required="!!isRequired"
|
|
@@ -10,7 +14,7 @@
|
|
|
10
14
|
</UFormGroup>
|
|
11
15
|
</template>
|
|
12
16
|
<script lang="ts" setup>
|
|
13
|
-
import { type
|
|
17
|
+
import { type IFieldProps } from '#core/components/Form/types'
|
|
14
18
|
|
|
15
|
-
defineProps<
|
|
19
|
+
defineProps<IFieldProps>()
|
|
16
20
|
</script>
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
<FieldWrapper v-bind="wrapperProps" label="">
|
|
3
3
|
<UCheckbox
|
|
4
4
|
v-model="value"
|
|
5
|
-
:disabled="
|
|
5
|
+
:disabled="wrapperProps.isDisabled"
|
|
6
6
|
:name="name"
|
|
7
7
|
:label="props.label"
|
|
8
8
|
:required="isRequired"
|
|
9
|
-
:color="color"
|
|
10
9
|
:ui="ui"
|
|
11
10
|
/>
|
|
12
11
|
</FieldWrapper>
|
|
@@ -18,5 +17,5 @@ import { type ICheckboxFieldProps } from '#core/components/Form/InputCheckbox/ty
|
|
|
18
17
|
|
|
19
18
|
const props = withDefaults(defineProps<ICheckboxFieldProps>(), {})
|
|
20
19
|
|
|
21
|
-
const { value, wrapperProps
|
|
20
|
+
const { value, wrapperProps } = useFieldHOC<boolean>(props)
|
|
22
21
|
</script>
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { type IFieldProps, type IFormFieldBase, type INPUT_TYPES } from '#core/components/Form/types';
|
|
2
2
|
export interface ICheckboxFieldProps extends IFieldProps {
|
|
3
|
-
color?: string;
|
|
4
|
-
ui?: object | any;
|
|
5
3
|
}
|
|
6
|
-
export type ICheckboxField = IFormFieldBase<INPUT_TYPES.CHECKBOX, ICheckboxFieldProps,
|
|
7
|
-
change?: (value: string) => void;
|
|
8
|
-
}>;
|
|
4
|
+
export type ICheckboxField = IFormFieldBase<INPUT_TYPES.CHECKBOX, ICheckboxFieldProps, never>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<FieldWrapper v-bind="wrapperProps">
|
|
3
3
|
<Datepicker
|
|
4
4
|
v-model="value"
|
|
5
|
-
:disabled="
|
|
5
|
+
:disabled="wrapperProps.isDisabled"
|
|
6
6
|
cancel-text="ยกเลิก"
|
|
7
7
|
select-text="เลือก"
|
|
8
8
|
locale="th"
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
:min-date="minDate"
|
|
13
13
|
:max-date="maxDate"
|
|
14
14
|
:required="isRequired"
|
|
15
|
-
@change="handleChange"
|
|
16
15
|
/>
|
|
17
16
|
</FieldWrapper>
|
|
18
17
|
</template>
|
|
@@ -24,9 +23,8 @@ import { TimeHelper, useFieldHOC } from '#imports'
|
|
|
24
23
|
import '@vuepic/vue-datepicker/dist/main.css'
|
|
25
24
|
|
|
26
25
|
const props = withDefaults(defineProps<IDateTimeFieldProps>(), {})
|
|
27
|
-
const emits = defineEmits<(event: 'change', value: string) => void>()
|
|
28
26
|
|
|
29
|
-
const { value, wrapperProps
|
|
27
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
30
28
|
|
|
31
29
|
const format = (date: Date) => {
|
|
32
30
|
if (props.disabledTime) {
|
|
@@ -35,11 +33,4 @@ const format = (date: Date) => {
|
|
|
35
33
|
|
|
36
34
|
return TimeHelper.getDateTimeFormTime(date as any)
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
const handleChange = (e: InputEvent) => {
|
|
40
|
-
onChange(e)
|
|
41
|
-
const target = e.target as HTMLInputElement
|
|
42
|
-
|
|
43
|
-
emits('change', target?.value)
|
|
44
|
-
}
|
|
45
36
|
</script>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<URadioGroup
|
|
4
4
|
v-model="value"
|
|
5
5
|
:options="options"
|
|
6
|
-
:disabled="
|
|
6
|
+
:disabled="wrapperProps.isDisabled"
|
|
7
7
|
:required="isRequired"
|
|
8
8
|
value-attribute="value"
|
|
9
9
|
option-attribute="label"
|
|
@@ -23,5 +23,5 @@ import { type ISelectFieldProps } from '#core/components/Form/InputSelect/types'
|
|
|
23
23
|
|
|
24
24
|
const props = withDefaults(defineProps<ISelectFieldProps>(), {})
|
|
25
25
|
|
|
26
|
-
const { value, wrapperProps
|
|
26
|
+
const { value, wrapperProps } = useFieldHOC<any>(props)
|
|
27
27
|
</script>
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { IFieldProps, IFormFieldBase, INPUT_TYPES } from '#core/components/Form/types';
|
|
2
2
|
import { type IOption } from '#core/types/common';
|
|
3
3
|
export interface IRadioFieldProps extends IFieldProps {
|
|
4
|
-
color?: string;
|
|
5
4
|
icon?: string;
|
|
6
5
|
size?: string;
|
|
7
|
-
ui?: object | any;
|
|
8
6
|
options: IOption[];
|
|
9
7
|
}
|
|
10
|
-
export type IRadioField = IFormFieldBase<INPUT_TYPES.RADIO, IRadioFieldProps,
|
|
11
|
-
change?: (value: string) => void;
|
|
12
|
-
}>;
|
|
8
|
+
export type IRadioField = IFormFieldBase<INPUT_TYPES.RADIO, IRadioFieldProps, never>;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
searchable
|
|
6
6
|
:options="options"
|
|
7
7
|
:placeholder="placeholder || label"
|
|
8
|
-
:disabled="
|
|
9
|
-
:loading="
|
|
8
|
+
:disabled="wrapperProps.isDisabled"
|
|
9
|
+
:loading="loading"
|
|
10
10
|
:searchable-placeholder="searchablePlaceholder"
|
|
11
11
|
value-attribute="value"
|
|
12
12
|
option-attribute="label"
|
|
@@ -33,5 +33,5 @@ import { type ISelectFieldProps } from '#core/components/Form/InputSelect/types'
|
|
|
33
33
|
|
|
34
34
|
const props = withDefaults(defineProps<ISelectFieldProps>(), {})
|
|
35
35
|
|
|
36
|
-
const { value, wrapperProps
|
|
36
|
+
const { value, wrapperProps } = useFieldHOC<any>(props)
|
|
37
37
|
</script>
|
|
@@ -12,5 +12,5 @@ import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
|
12
12
|
|
|
13
13
|
const props = withDefaults(defineProps<IStaticFieldProps>(), {})
|
|
14
14
|
|
|
15
|
-
const { value,
|
|
15
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
16
16
|
</script>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type IFieldProps, type IFormFieldBase, type INPUT_TYPES } from '#core/components/Form/types';
|
|
2
2
|
export interface IStaticFieldProps extends IFieldProps {
|
|
3
3
|
}
|
|
4
|
-
export type IStaticField = IFormFieldBase<INPUT_TYPES.STATIC, IStaticFieldProps>;
|
|
4
|
+
export type IStaticField = IFormFieldBase<INPUT_TYPES.STATIC, IStaticFieldProps, never>;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
<FieldWrapper v-bind="wrapperProps">
|
|
3
3
|
<UInput
|
|
4
4
|
v-model="value"
|
|
5
|
-
:disabled="
|
|
5
|
+
:disabled="wrapperProps.isDisabled"
|
|
6
6
|
:name="name"
|
|
7
7
|
:placeholder="placeholder ?? props.label"
|
|
8
8
|
:type="isShowPassword ? 'text' : props.type || 'text'"
|
|
9
9
|
:autofocus="!!autoFocus"
|
|
10
|
-
:
|
|
10
|
+
:icon="icon"
|
|
11
11
|
:ui="ui"
|
|
12
12
|
/>
|
|
13
13
|
</FieldWrapper>
|
|
@@ -19,12 +19,8 @@ import { useFieldHOC } from '#core/composables/useForm'
|
|
|
19
19
|
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
20
20
|
|
|
21
21
|
const props = withDefaults(defineProps<ITextFieldProps>(), {})
|
|
22
|
-
const emits = defineEmits<{
|
|
23
|
-
(event: 'change', value: string): void
|
|
24
|
-
(event: 'blur', value: string): void
|
|
25
|
-
}>()
|
|
26
22
|
|
|
27
|
-
const { value, wrapperProps
|
|
23
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
28
24
|
|
|
29
25
|
const isShowPassword = ref(false)
|
|
30
26
|
</script>
|
|
@@ -3,10 +3,9 @@ export interface ITextFieldProps extends IFieldProps {
|
|
|
3
3
|
type?: 'text' | 'password' | 'email';
|
|
4
4
|
prependIcon?: any;
|
|
5
5
|
appendIcon?: any;
|
|
6
|
-
|
|
7
|
-
ui?: object | any;
|
|
6
|
+
icon?: string;
|
|
8
7
|
}
|
|
9
|
-
export type ITextField = IFormFieldBase<INPUT_TYPES.TEXT | INPUT_TYPES.PASSWORD, ITextFieldProps, {
|
|
8
|
+
export type ITextField = IFormFieldBase<INPUT_TYPES.TEXT | INPUT_TYPES.PASSWORD | INPUT_TYPES.EMAIL, ITextFieldProps, {
|
|
10
9
|
change?: (value: string) => void;
|
|
11
10
|
blur?: (value: string) => void;
|
|
12
11
|
}>;
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
<FieldWrapper v-bind="wrapperProps">
|
|
3
3
|
<UTextarea
|
|
4
4
|
v-model="value"
|
|
5
|
-
:disabled="
|
|
5
|
+
:disabled="wrapperProps.isDisabled"
|
|
6
6
|
:name="name"
|
|
7
7
|
:resize="resize"
|
|
8
8
|
:placeholder="placeholder ?? props.label"
|
|
9
9
|
:autofocus="!!autoFocus"
|
|
10
10
|
:autoresize="autoresize"
|
|
11
11
|
:rows="rows"
|
|
12
|
-
:color="color"
|
|
13
12
|
:ui="ui"
|
|
14
13
|
/>
|
|
15
14
|
</FieldWrapper>
|
|
@@ -20,10 +19,6 @@ import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
|
20
19
|
import { type ITextareaFieldProps } from '#core/components/Form/InputTextarea/types'
|
|
21
20
|
|
|
22
21
|
const props = withDefaults(defineProps<ITextareaFieldProps>(), {})
|
|
23
|
-
const emits = defineEmits<{
|
|
24
|
-
(event: 'change', value: string): void
|
|
25
|
-
(event: 'blur', value: string): void
|
|
26
|
-
}>()
|
|
27
22
|
|
|
28
|
-
const { value, wrapperProps
|
|
23
|
+
const { value, wrapperProps } = useFieldHOC<string>(props)
|
|
29
24
|
</script>
|
|
@@ -3,10 +3,5 @@ export interface ITextareaFieldProps extends IFieldProps {
|
|
|
3
3
|
autoresize?: boolean;
|
|
4
4
|
resize?: boolean;
|
|
5
5
|
rows?: number;
|
|
6
|
-
color?: string;
|
|
7
|
-
ui?: object | any;
|
|
8
6
|
}
|
|
9
|
-
export type ITextareaField = IFormFieldBase<INPUT_TYPES.TEXTAREA, ITextareaFieldProps,
|
|
10
|
-
change?: (value: string) => void;
|
|
11
|
-
blur?: (value: string) => void;
|
|
12
|
-
}>;
|
|
7
|
+
export type ITextareaField = IFormFieldBase<INPUT_TYPES.TEXTAREA, ITextareaFieldProps, never>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<FieldWrapper v-bind="wrapperProps">
|
|
3
|
-
<UToggle v-model="value" :disabled="
|
|
3
|
+
<UToggle v-model="value" :disabled="wrapperProps.isDisabled" :name="name" :ui="ui" />
|
|
4
4
|
</FieldWrapper>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
@@ -10,5 +10,5 @@ import { type IToggleFieldProps } from '#core/components/Form/InputToggle/types'
|
|
|
10
10
|
import FieldWrapper from '#core/components/Form/FieldWrapper.vue'
|
|
11
11
|
|
|
12
12
|
const props = withDefaults(defineProps<IToggleFieldProps>(), {})
|
|
13
|
-
const { value, wrapperProps
|
|
13
|
+
const { value, wrapperProps } = useFieldHOC<boolean>(props)
|
|
14
14
|
</script>
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { type IFieldProps, type IFormFieldBase, type INPUT_TYPES } from '#core/components/Form/types';
|
|
2
2
|
export interface IToggleFieldProps extends IFieldProps {
|
|
3
|
-
color?: string;
|
|
4
|
-
ui?: object | any;
|
|
5
3
|
}
|
|
6
|
-
export type IToggleField = IFormFieldBase<INPUT_TYPES.TOGGLE, IToggleFieldProps,
|
|
7
|
-
change?: (value: string) => void;
|
|
8
|
-
}>;
|
|
4
|
+
export type IToggleField = IFormFieldBase<INPUT_TYPES.TOGGLE, IToggleFieldProps, never>;
|
|
@@ -24,23 +24,22 @@ export declare const enum INPUT_TYPES {
|
|
|
24
24
|
export interface IFieldProps {
|
|
25
25
|
form?: FormContext;
|
|
26
26
|
name: string;
|
|
27
|
+
errorMessage?: string;
|
|
27
28
|
label?: string | any;
|
|
29
|
+
description?: string;
|
|
30
|
+
hint?: string;
|
|
31
|
+
size?: string;
|
|
28
32
|
rules?: any;
|
|
29
33
|
autoFocus?: boolean;
|
|
30
34
|
class?: any;
|
|
31
35
|
classInner?: any;
|
|
32
|
-
classInputInner?: any;
|
|
33
36
|
placeholder?: string;
|
|
34
37
|
isDisabled?: boolean;
|
|
35
38
|
isRequired?: boolean;
|
|
36
|
-
isLoading?: boolean;
|
|
37
39
|
help?: string;
|
|
38
|
-
|
|
39
|
-
customErrorMessage?: string | any;
|
|
40
|
-
transform?: (value: any, oldValue: any, e: InputEvent) => any;
|
|
41
|
-
getInstance?: (el: HTMLElement) => void;
|
|
40
|
+
ui?: object | any;
|
|
42
41
|
}
|
|
43
|
-
export interface IFormFieldBase<I extends INPUT_TYPES, P, O> {
|
|
42
|
+
export interface IFormFieldBase<I extends INPUT_TYPES, P extends IFieldProps, O> {
|
|
44
43
|
type: I;
|
|
45
44
|
component?: Component;
|
|
46
45
|
class?: any;
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
2
|
import { type FieldContext, type FieldOptions } from 'vee-validate';
|
|
3
|
-
import { type IFormField } from '#core/components/Form/types';
|
|
4
|
-
export interface IFieldWrapperProps {
|
|
5
|
-
errorMessage?: string;
|
|
6
|
-
label?: string | any;
|
|
7
|
-
className?: any;
|
|
8
|
-
classInner?: any;
|
|
9
|
-
classInputInner?: any;
|
|
10
|
-
isRequired?: boolean;
|
|
11
|
-
isHideLabel?: boolean;
|
|
12
|
-
customErrorMessage?: string | DefineComponent;
|
|
13
|
-
name: string;
|
|
14
|
-
help?: string;
|
|
15
|
-
}
|
|
3
|
+
import { type IFieldProps, type IFormField } from '#core/components/Form/types';
|
|
16
4
|
interface IFieldContext<TValue> extends FieldContext<TValue> {
|
|
17
|
-
|
|
18
|
-
onChange: (e: InputEvent) => void;
|
|
19
|
-
fieldClassName: ComputedRef<any[]>;
|
|
20
|
-
disabled: boolean;
|
|
21
|
-
wrapperProps: ComputedRef<IFieldWrapperProps>;
|
|
5
|
+
wrapperProps: ComputedRef<IFieldProps>;
|
|
22
6
|
}
|
|
23
7
|
export declare const useFieldHOC: <TValue = unknown>(newFormProps: IFieldProps, opts?: Partial<FieldOptions<TValue>> | undefined) => IFieldContext<TValue>;
|
|
24
8
|
export declare const createFormFields: (fields: () => IFormField[]) => any;
|
|
@@ -6,38 +6,11 @@ export const useFieldHOC = (newFormProps, opts) => {
|
|
|
6
6
|
form: newFormProps.form,
|
|
7
7
|
...opts
|
|
8
8
|
});
|
|
9
|
-
const onChange = (e) => {
|
|
10
|
-
const target = e.target;
|
|
11
|
-
const newValue = newFormProps.transform ? newFormProps.transform(target.value, field.value, e) : target.value;
|
|
12
|
-
target.value = newValue;
|
|
13
|
-
field.handleChange(newValue);
|
|
14
|
-
};
|
|
15
|
-
const fieldClassName = computed(() => {
|
|
16
|
-
return [
|
|
17
|
-
"form-control peer",
|
|
18
|
-
{
|
|
19
|
-
"input-error": !field.meta.valid && field.meta.dirty,
|
|
20
|
-
"input-success": field.meta.valid && field.meta.dirty
|
|
21
|
-
}
|
|
22
|
-
];
|
|
23
|
-
});
|
|
24
9
|
return {
|
|
25
10
|
...field,
|
|
26
|
-
isRequired: !!newFormProps.isRequired,
|
|
27
|
-
onChange,
|
|
28
|
-
fieldClassName,
|
|
29
|
-
disabled: !!newFormProps.isDisabled,
|
|
30
11
|
wrapperProps: computed(() => ({
|
|
31
|
-
|
|
32
|
-
errorMessage: field.errorMessage.value
|
|
33
|
-
className: newFormProps.class,
|
|
34
|
-
classInner: newFormProps.classInner,
|
|
35
|
-
classInputInner: newFormProps.classInputInner,
|
|
36
|
-
isRequired: newFormProps.isRequired,
|
|
37
|
-
isHideLabel: newFormProps.isHideLabel,
|
|
38
|
-
customErrorMessage: newFormProps.customErrorMessage,
|
|
39
|
-
name: newFormProps.name,
|
|
40
|
-
help: newFormProps.help
|
|
12
|
+
...newFormProps,
|
|
13
|
+
errorMessage: field.errorMessage.value
|
|
41
14
|
}))
|
|
42
15
|
};
|
|
43
16
|
};
|