@ramathibodi/nuxt-commons 4.0.14 → 4.0.15

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.3.1"
6
6
  },
7
- "version": "4.0.14",
7
+ "version": "4.0.15",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -43,6 +43,9 @@ const computedRules = computed(() => {
43
43
  return ["DateHappen"];
44
44
  }
45
45
  });
46
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
47
+ const birthdateYearRange = computed(() => [currentYear - 120, currentYear]);
48
+ const maxBirthdate = /* @__PURE__ */ new Date();
46
49
  const dobFormat = computed(() => {
47
50
  let displayFormat = void 0;
48
51
  if (dobPrecisionSelected.value == "yearMonth") {
@@ -64,6 +67,10 @@ const dobFormat = computed(() => {
64
67
  :flow="props.flow"
65
68
  :format="dobFormat"
66
69
  :rules="computedRules"
70
+ :year-range="birthdateYearRange"
71
+ :max-date="maxBirthdate"
72
+ reverse-years
73
+ eager
67
74
  >
68
75
  <template #append="{ isReadonly, isDisabled, activatorProps, toggleMenuOpen }">
69
76
  <span
@@ -13,7 +13,7 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VCheckbox['$props'
13
13
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
14
14
  inline: boolean;
15
15
  }>>, {
16
- validate: () => boolean;
16
+ validate: () => Promise<boolean>;
17
17
  reset: () => void;
18
18
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
19
  "update:modelValue": (...args: any[]) => void;
@@ -1,7 +1,8 @@
1
1
  <script setup>
2
- import { ref, watch, computed } from "vue";
2
+ import { ref, watch, computed, nextTick } from "vue";
3
3
  import { VCheckbox } from "vuetify/components/VCheckbox";
4
- import { join, without, filter, head, reject } from "lodash-es";
4
+ import { VInput } from "vuetify/components/VInput";
5
+ import { filter, head, reject } from "lodash-es";
5
6
  const props = defineProps({
6
7
  items: { type: Array, required: true },
7
8
  label: { type: String, required: false },
@@ -12,26 +13,20 @@ const props = defineProps({
12
13
  const emit = defineEmits(["update:modelValue"]);
13
14
  const values = ref([]);
14
15
  const valuesOther = ref();
15
- const touched = ref(false);
16
- const onUserInput = () => {
17
- touched.value = true;
18
- };
19
- const validate = () => {
20
- touched.value = true;
21
- return !computedRules.value;
16
+ const inputRef = ref();
17
+ const validationValue = computed(() => values.value.length ? values.value : null);
18
+ const validate = async () => {
19
+ const errors = await inputRef.value?.validate() ?? [];
20
+ return errors.length === 0;
22
21
  };
23
22
  const reset = () => {
24
- touched.value = false;
23
+ inputRef.value?.resetValidation();
25
24
  };
26
25
  defineExpose({ validate, reset });
27
- const computedRules = computed(() => {
28
- if (props.rules) {
29
- let rules = props.rules.map((rule) => rule(values.value.length ? values.value : null));
30
- rules = without(rules, true);
31
- return join(rules, ",");
32
- }
33
- });
34
- const showError = computed(() => touched.value && !!computedRules.value);
26
+ const onInteract = async () => {
27
+ await nextTick();
28
+ inputRef.value?.validate();
29
+ };
35
30
  const computedOther = computed(() => {
36
31
  const itemOther = filter(props.items, { value: "other" });
37
32
  return head(itemOther);
@@ -59,33 +54,39 @@ watch(props.modelValue, () => {
59
54
  </script>
60
55
 
61
56
  <template>
62
- <label class="text-body-1 opacity-60">{{ props.label }}</label>
63
- <div :class="`d-flex ${inline ? 'flex-row' : 'flex-column'}`">
64
- <v-checkbox
65
- v-for="item in computeItems"
66
- v-model="values"
67
- :value="item.value"
68
- density="compact"
69
- hide-details
70
- :error="showError"
71
- :="$attrs"
72
- :label="item.label"
73
- @update:model-value="onUserInput"
74
- />
75
- </div>
76
- <v-text-field
77
- v-if="computedOther"
78
- v-model="valuesOther"
79
- hide-details
80
- :error="showError"
81
- :="$attrs"
82
- :label="computedOther.label"
83
- @update:model-value="onUserInput"
84
- />
85
- <label
86
- v-if="showError"
87
- class="text-error text-subtitle-2 ml-1"
57
+ <v-input
58
+ ref="inputRef"
59
+ :model-value="validationValue"
60
+ :rules="props.rules"
61
+ hide-details="auto"
88
62
  >
89
- {{ computedRules }}
90
- </label>
63
+ <template #default="{ isValid }">
64
+ <div class="w-100">
65
+ <label class="text-body-1 opacity-60">{{ props.label }}</label>
66
+ <div :class="`d-flex ${inline ? 'flex-row' : 'flex-column'}`">
67
+ <v-checkbox
68
+ v-for="item in computeItems"
69
+ :key="item.value"
70
+ v-model="values"
71
+ :value="item.value"
72
+ density="compact"
73
+ hide-details
74
+ :error="isValid === false"
75
+ :="$attrs"
76
+ :label="item.label"
77
+ @update:model-value="onInteract"
78
+ />
79
+ </div>
80
+ <v-text-field
81
+ v-if="computedOther"
82
+ v-model="valuesOther"
83
+ hide-details
84
+ :error="isValid === false"
85
+ :="$attrs"
86
+ :label="computedOther.label"
87
+ @update:model-value="onInteract"
88
+ />
89
+ </div>
90
+ </template>
91
+ </v-input>
91
92
  </template>
@@ -13,7 +13,7 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VCheckbox['$props'
13
13
  declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
14
14
  inline: boolean;
15
15
  }>>, {
16
- validate: () => boolean;
16
+ validate: () => Promise<boolean>;
17
17
  reset: () => void;
18
18
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
19
  "update:modelValue": (...args: any[]) => void;
@@ -12,6 +12,9 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VTextField['$props
12
12
  flow?: ('month' | 'year' | 'calendar' | 'time' | 'minutes' | 'hours' | 'seconds')[];
13
13
  rules?: typeof VTextField['rules'];
14
14
  defaultDate?: boolean | string;
15
+ yearRange?: [number, number];
16
+ reverseYears?: boolean;
17
+ eager?: boolean;
15
18
  }
16
19
  declare function resetDatePicker(): void;
17
20
  declare function toggleMenuOpen(trigger: string): void;
@@ -42,11 +45,13 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
42
45
  pickerOnly: boolean;
43
46
  flow: () => never[];
44
47
  defaultDate: boolean;
48
+ reverseYears: boolean;
49
+ eager: boolean;
45
50
  }>>, {
46
51
  reset: typeof resetDatePicker;
47
52
  validate: typeof validate;
48
53
  resetValidation: typeof resetValidation;
49
- isValid: boolean | null | undefined;
54
+ isValid: import("vue").ComputedRef<boolean | null | undefined>;
50
55
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
51
56
  "update:modelValue": (...args: any[]) => void;
52
57
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
@@ -55,6 +60,8 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
55
60
  pickerOnly: boolean;
56
61
  flow: () => never[];
57
62
  defaultDate: boolean;
63
+ reverseYears: boolean;
64
+ eager: boolean;
58
65
  }>>> & Readonly<{
59
66
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
60
67
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -17,7 +17,10 @@ const props = defineProps({
17
17
  pickerOnly: { type: Boolean, required: false, default: false },
18
18
  flow: { type: Array, required: false, default: () => [] },
19
19
  rules: { type: null, required: false },
20
- defaultDate: { type: [Boolean, String], required: false, default: false }
20
+ defaultDate: { type: [Boolean, String], required: false, default: false },
21
+ yearRange: { type: Array, required: false },
22
+ reverseYears: { type: Boolean, required: false, default: false },
23
+ eager: { type: Boolean, required: false, default: false }
21
24
  });
22
25
  const emit = defineEmits(["update:modelValue"]);
23
26
  const computedRules = computed(() => {
@@ -157,11 +160,12 @@ function validate() {
157
160
  function resetValidation() {
158
161
  textFieldRef.value?.resetValidation();
159
162
  }
163
+ const isValid = computed(() => textFieldRef.value?.isValid);
160
164
  defineExpose({
161
165
  reset: resetDatePicker,
162
166
  validate,
163
167
  resetValidation,
164
- isValid: textFieldRef.value?.isValid
168
+ isValid
165
169
  });
166
170
  </script>
167
171
 
@@ -169,6 +173,7 @@ defineExpose({
169
173
  <v-menu
170
174
  v-model="isMenuOpen"
171
175
  :open-on-click="false"
176
+ :eager="props.eager"
172
177
  >
173
178
  <template #activator="{ props: activatorProps }">
174
179
  <v-text-field
@@ -203,6 +208,8 @@ defineExpose({
203
208
  :flow="datepickerFlow"
204
209
  :min-date="props.minDate"
205
210
  :max-date="props.maxDate"
211
+ :year-range="props.yearRange"
212
+ :reverse-years="props.reverseYears"
206
213
  auto-apply
207
214
  inline
208
215
  :locale="datepickerLocale"
@@ -12,6 +12,9 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VTextField['$props
12
12
  flow?: ('month' | 'year' | 'calendar' | 'time' | 'minutes' | 'hours' | 'seconds')[];
13
13
  rules?: typeof VTextField['rules'];
14
14
  defaultDate?: boolean | string;
15
+ yearRange?: [number, number];
16
+ reverseYears?: boolean;
17
+ eager?: boolean;
15
18
  }
16
19
  declare function resetDatePicker(): void;
17
20
  declare function toggleMenuOpen(trigger: string): void;
@@ -42,11 +45,13 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
42
45
  pickerOnly: boolean;
43
46
  flow: () => never[];
44
47
  defaultDate: boolean;
48
+ reverseYears: boolean;
49
+ eager: boolean;
45
50
  }>>, {
46
51
  reset: typeof resetDatePicker;
47
52
  validate: typeof validate;
48
53
  resetValidation: typeof resetValidation;
49
- isValid: boolean | null | undefined;
54
+ isValid: import("vue").ComputedRef<boolean | null | undefined>;
50
55
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
51
56
  "update:modelValue": (...args: any[]) => void;
52
57
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
@@ -55,6 +60,8 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
55
60
  pickerOnly: boolean;
56
61
  flow: () => never[];
57
62
  defaultDate: boolean;
63
+ reverseYears: boolean;
64
+ eager: boolean;
58
65
  }>>> & Readonly<{
59
66
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
60
67
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -17,7 +17,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
17
17
  reset: typeof reset;
18
18
  validate: typeof validate;
19
19
  resetValidation: typeof resetValidation;
20
- isValid: boolean | null | undefined;
20
+ isValid: import("vue").ComputedRef<boolean | null | undefined>;
21
21
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
22
22
  "update:modelValue": (...args: any[]) => void;
23
23
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
@@ -96,11 +96,12 @@ function validate() {
96
96
  function resetValidation() {
97
97
  textFieldRef.value?.resetValidation();
98
98
  }
99
+ const isValid = computed(() => textFieldRef.value?.isValid);
99
100
  defineExpose({
100
101
  reset,
101
102
  validate,
102
103
  resetValidation,
103
- isValid: textFieldRef.value?.isValid
104
+ isValid
104
105
  });
105
106
  </script>
106
107
 
@@ -17,7 +17,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
17
17
  reset: typeof reset;
18
18
  validate: typeof validate;
19
19
  resetValidation: typeof resetValidation;
20
- isValid: boolean | null | undefined;
20
+ isValid: import("vue").ComputedRef<boolean | null | undefined>;
21
21
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
22
22
  "update:modelValue": (...args: any[]) => void;
23
23
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "4.0.14",
3
+ "version": "4.0.15",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",