@farm-investimentos/front-mfe-components 3.4.13 → 3.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "3.4.13",
3
+ "version": "3.5.0",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -37,13 +37,20 @@ export const MinMaxDates = () => ({
37
37
 
38
38
  export const RequiredDates = () => ({
39
39
  components: { DatePicker },
40
-
41
40
  template: `<div style='max-width: 320px'>
42
41
  <DatePicker inputId="input-custom-id-3" :required="true" />
43
42
  </div>`,
44
43
  });
45
44
 
45
+ export const readonlyFalse = () => ({
46
+ components: { DatePicker },
47
+ template: `<div style='max-width: 320px'>
48
+ <DatePicker :readonly="false" inputId="input-custom-id-3"/>
49
+ </div>`,
50
+ });
51
+
46
52
  Primary.storyName = 'Básico';
47
53
  InitValue.storyName = 'Data inicial';
48
54
  MinMaxDates.storyName = 'Data mínima e máxima';
49
55
  RequiredDates.storyName = 'Obrigatório';
56
+ readonlyFalse.storyName = 'Permitir digitação';
@@ -13,13 +13,16 @@
13
13
  <v-text-field
14
14
  color="secondary"
15
15
  append-icon="mdi-calendar"
16
- readonly
16
+ v-mask="`${readonly ? '' : '##/##/####'}`"
17
+ @keyup="keyUpInput"
18
+ :readonly="readonly"
19
+ autocomplete="off"
17
20
  outlined
18
21
  dense
19
22
  v-on="on"
20
23
  v-model="fieldRange"
21
24
  :id="inputId"
22
- :rules="required ? [requiredRule] : []"
25
+ :rules="[checkMax, checkMin, checkRequire]"
23
26
  >
24
27
  </v-text-field>
25
28
  </template>
@@ -54,7 +57,7 @@ import { VTextField } from 'vuetify/lib/components/VTextField';
54
57
  import { VMenu } from 'vuetify/lib/components/VMenu';
55
58
  import { VBtn } from 'vuetify/lib/components/VBtn';
56
59
  import { VDatePicker } from 'vuetify/lib/components/VDatePicker';
57
- import { defaultFormat as dateDefaultFormatter } from '../../helpers/date';
60
+ import { defaultFormat as dateDefaultFormatter, convertDate } from '../../helpers/date';
58
61
  /**
59
62
  * Componente de input com datepicker para data
60
63
  */
@@ -96,6 +99,10 @@ export default Vue.extend({
96
99
  type: Boolean,
97
100
  default: false,
98
101
  },
102
+ readonly: {
103
+ type: Boolean,
104
+ default: true,
105
+ },
99
106
  },
100
107
  data() {
101
108
  const s = this.formatDateRange(this.value);
@@ -103,9 +110,15 @@ export default Vue.extend({
103
110
  menuField: false,
104
111
  dateField: this.value,
105
112
  fieldRange: s,
106
- requiredRule: value => {
107
- return !!value || value != '' || 'Campo obrigatório';
113
+ checkRequire: value => {
114
+ return this.required ? !!value || value != '' || 'Campo obrigatório' : true;
115
+ },
116
+ checkMax: value => {
117
+ return this.max && new Date(convertDate(value)) > new Date(this.max) ? 'A data está fora do período permitido' : true;
108
118
  },
119
+ checkMin: value => {
120
+ return this.min && new Date(convertDate(value)) < new Date(this.min) ? 'A data está fora do período permitido' : true;
121
+ }
109
122
  };
110
123
  },
111
124
  watch: {
@@ -127,6 +140,18 @@ export default Vue.extend({
127
140
  this.dateField = '';
128
141
  this.save();
129
142
  },
143
+ validation(date){
144
+ const pattern = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/gm;
145
+ return pattern.test(date);
146
+ },
147
+ keyUpInput(event) {
148
+ let newValue = event.target.value;
149
+ if(this.validation(newValue) && newValue.length === 10) {
150
+ const [day, month, year] = newValue.split('/');
151
+ this.dateField = `${year}-${month}-${day}`;
152
+ this.save();
153
+ }
154
+ },
130
155
  },
131
156
  computed: {
132
157
  inputVal: {
@@ -4,3 +4,8 @@ export const defaultFormat = (data, UTCTimeZone = true) => {
4
4
  };
5
5
  return data ? new Date(data).toLocaleDateString('pt-BR', UTCTimeZone ? options : {}) : null;
6
6
  };
7
+
8
+ export const convertDate = (data) => {
9
+ let newdate = data.split("/").reverse().join("-");
10
+ return newdate;
11
+ }