@farm-investimentos/front-mfe-components 12.1.4 → 12.2.1

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.
Files changed (29) hide show
  1. package/dist/front-mfe-components.common.js +602 -5422
  2. package/dist/front-mfe-components.common.js.map +1 -1
  3. package/dist/front-mfe-components.css +1 -1
  4. package/dist/front-mfe-components.umd.js +602 -5422
  5. package/dist/front-mfe-components.umd.js.map +1 -1
  6. package/dist/front-mfe-components.umd.min.js +1 -1
  7. package/dist/front-mfe-components.umd.min.js.map +1 -1
  8. package/package.json +2 -2
  9. package/src/components/Chip/Chip.stories.js +6 -0
  10. package/src/components/Chip/Chip.vue +1 -1
  11. package/src/components/DialogHeader/DialogHeader.scss +3 -3
  12. package/src/components/IdCaption/IdCaption.scss +3 -3
  13. package/src/components/Select/Select.vue +8 -0
  14. package/src/components/SelectModalOptions/SelectModalOptions.scss +5 -0
  15. package/src/components/SelectModalOptions/SelectModalOptions.vue +81 -99
  16. package/src/components/SelectModalOptions/__tests__/SelectModalOptions.spec.js +1 -0
  17. package/src/components/TextArea/TextArea.scss +66 -0
  18. package/src/components/TextArea/TextArea.stories.js +136 -0
  19. package/src/components/TextArea/TextArea.vue +188 -0
  20. package/src/components/TextArea/__tests__/TextArea.spec.js +48 -0
  21. package/src/components/TextArea/index.ts +4 -0
  22. package/src/components/TextFieldV2/TextFieldV2.scss +4 -0
  23. package/src/components/TextFieldV2/TextFieldV2.stories.js +0 -24
  24. package/src/components/TextFieldV2/TextFieldV2.vue +21 -7
  25. package/src/components/Typography/Typography.scss +2 -5
  26. package/src/configurations/_mixins.scss +7 -0
  27. package/src/main.ts +1 -0
  28. package/src/examples/inputs/Password.stories.js +0 -42
  29. package/src/examples/inputs/Select.stories.js +0 -27
@@ -0,0 +1,188 @@
1
+ <template>
2
+ <div
3
+ class="farm-textarea"
4
+ :class="{
5
+ 'farm-textarea': true,
6
+ 'farm-textarea--validatable': rules.length > 0,
7
+ 'farm-textarea--touched': isTouched,
8
+ 'farm-textarea--blured': isBlured,
9
+ 'farm-textarea--error': hasError,
10
+ 'farm-textarea--disabled': disabled,
11
+ 'farm-textarea--hiddendetails': hideDetails,
12
+ }"
13
+ >
14
+ <div
15
+ :class="{
16
+ 'farm-textarea--textarea': true,
17
+ }"
18
+ >
19
+ <textarea
20
+ v-bind="$attrs"
21
+ v-model="innerValue"
22
+ :rows="$props.rows"
23
+ :disabled="disabled"
24
+ :readonly="readonly"
25
+ @click="$emit('click')"
26
+ @keyup="onKeyUp"
27
+ @blur="onBlur"
28
+ />
29
+ </div>
30
+ <farm-caption v-if="showErrorText" color="error" variation="regular">
31
+ {{ errorBucket[0] }}
32
+ </farm-caption>
33
+ <farm-caption v-if="hint && !showErrorText" color="gray" variation="regular">
34
+ {{ hint }}
35
+ </farm-caption>
36
+ </div>
37
+ </template>
38
+
39
+ <script lang="ts">
40
+ import Vue, { computed, onBeforeMount, PropType, ref, toRefs, watch } from 'vue';
41
+ import validateFormStateBuilder from '../../composition/validateFormStateBuilder';
42
+ import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
43
+ import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
44
+ import deepEqual from '../../composition/deepEqual';
45
+
46
+ export default Vue.extend({
47
+ name: 'farm-textarea',
48
+ inheritAttrs: true,
49
+ props: {
50
+ /**
51
+ * v-model binding
52
+ */
53
+ value: { type: [String, Number], default: '' },
54
+ /**
55
+ * Show hint text
56
+ */
57
+ hint: {
58
+ type: String,
59
+ default: null,
60
+ },
61
+ /**
62
+ * Disabled the input
63
+ */
64
+ disabled: {
65
+ type: Boolean,
66
+ default: false,
67
+ },
68
+ /**
69
+ * Puts input in readonly state
70
+ */
71
+ readonly: {
72
+ type: Boolean,
73
+ default: false,
74
+ },
75
+
76
+ errorMessage: String,
77
+ /**
78
+ * Array of rules used for validation
79
+ */
80
+ rules: {
81
+ type: Array as PropType<Array<Function>>,
82
+ default: () => [],
83
+ },
84
+ /**
85
+ * Textarea rows
86
+ */
87
+ rows: {
88
+ default: 5,
89
+ type: [String, Number],
90
+ },
91
+ /**
92
+ * Hides hint and validation errors
93
+ */
94
+ hideDetails: {
95
+ type: Boolean,
96
+ default: false,
97
+ },
98
+ },
99
+ setup(props, { emit }) {
100
+ const { rules } = toRefs(props);
101
+ const innerValue = ref(props.value);
102
+ const isTouched = ref(false);
103
+ const isBlured = ref(false);
104
+
105
+ const { errorBucket, valid, validatable } = validateFormStateBuilder();
106
+
107
+ let fieldValidator = validateFormFieldBuilder(rules.value);
108
+
109
+ const hasError = computed(() => {
110
+ return errorBucket.value.length > 0;
111
+ });
112
+
113
+ const showErrorText = computed(() => hasError.value && isTouched.value);
114
+
115
+ watch(
116
+ () => props.value,
117
+ () => {
118
+ innerValue.value = props.value;
119
+ validate(innerValue.value);
120
+ }
121
+ );
122
+
123
+ watch(
124
+ () => innerValue.value,
125
+ () => {
126
+ emit('input', innerValue.value);
127
+ emit('change', innerValue.value);
128
+ }
129
+ );
130
+
131
+ watch(
132
+ () => props.rules,
133
+ (newVal, oldVal) => {
134
+ if (deepEqual(newVal, oldVal)) return;
135
+ fieldValidator = validateFormFieldBuilder(rules.value);
136
+ validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
137
+ validate(innerValue.value);
138
+ }
139
+ );
140
+
141
+ onBeforeMount(() => {
142
+ validate(innerValue.value);
143
+ });
144
+
145
+ let validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
146
+
147
+ const onKeyUp = (event: Event) => {
148
+ isTouched.value = true;
149
+ emit('keyup', event);
150
+ };
151
+
152
+ const onBlur = (event: Event) => {
153
+ isBlured.value = true;
154
+ emit('blur', event);
155
+ };
156
+
157
+ const reset = () => {
158
+ innerValue.value = '';
159
+ isTouched.value = true;
160
+ emit('input', innerValue.value);
161
+ };
162
+
163
+ const makePristine = () => {
164
+ isTouched.value = false;
165
+ isBlured.value = false;
166
+ };
167
+
168
+ return {
169
+ innerValue,
170
+ errorBucket,
171
+ valid,
172
+ validatable,
173
+ hasError,
174
+ isTouched,
175
+ isBlured,
176
+ showErrorText,
177
+ validate,
178
+ onKeyUp,
179
+ onBlur,
180
+ reset,
181
+ makePristine,
182
+ };
183
+ },
184
+ });
185
+ </script>
186
+ <style lang="scss" scoped>
187
+ @import 'TextArea';
188
+ </style>
@@ -0,0 +1,48 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import TextArea from '../TextArea';
3
+
4
+ describe('TextArea component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(TextArea);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+
17
+ describe('mount component', () => {
18
+ it('renders correctly', () => {
19
+ expect(wrapper.element).toMatchSnapshot();
20
+ });
21
+ });
22
+
23
+ describe('methods', () => {
24
+ it('reset', () => {
25
+ component.reset();
26
+ expect(component.isTouched).toBeTruthy();
27
+ expect(component.innerValue).toEqual('');
28
+ });
29
+
30
+ it('onKeyUp', () => {
31
+ component.onKeyUp();
32
+ expect(component.isTouched).toBeTruthy();
33
+ });
34
+
35
+ it('onBlur', () => {
36
+ component.onBlur();
37
+ expect(component.isBlured).toBeTruthy();
38
+ });
39
+
40
+ it('makePristine', () => {
41
+ component.isTouched = true;
42
+ component.isBlured = true;
43
+ component.makePristine();
44
+ expect(component.isTouched).toBeFalsy();
45
+ expect(component.isBlured).toBeFalsy();
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,4 @@
1
+ import TextArea from './TextArea.vue';
2
+
3
+ export { TextArea };
4
+ export default TextArea;
@@ -1,6 +1,10 @@
1
1
  .farm-textfield {
2
2
  height: 64px;
3
3
 
4
+ &--hiddendetails {
5
+ height: 40px;
6
+ }
7
+
4
8
  &--input {
5
9
  display: flex;
6
10
  align-items: center;
@@ -230,27 +230,3 @@ export const ToggleVisibility = () => ({
230
230
  <farm-textfield-v2 v-model="v" :type="visible ? 'text' : 'password'" :icon="visible ? 'eye-off' : 'eye'" @onClickIcon="toggle" />
231
231
  </div>`,
232
232
  });
233
-
234
-
235
- export const Compare = () => ({
236
- data() {
237
- return {
238
- v1: '',
239
- rules: {
240
- required: value => !!value || 'Required field',
241
- email: v =>
242
- !v ||
243
- /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) ||
244
- 'Must be an e-mail',
245
- },
246
- };
247
- },
248
- template: `<div style="width: 480px">
249
-
250
- <farm-label required>Required and e-mail</farm-label>
251
- <farm-textfield-v2 v-model="v1" :rules="[rules.required, rules.email]" />
252
-
253
- <farm-textfield v-model="v1" :rules="[rules.required, rules.email]" />
254
-
255
- </div>`,
256
- });
@@ -8,12 +8,15 @@
8
8
  'farm-textfield--blured': isBlured,
9
9
  'farm-textfield--error': hasError,
10
10
  'farm-textfield--disabled': disabled,
11
+ 'farm-textfield--hiddendetails': hideDetails,
11
12
  }"
12
13
  >
13
- <div :class="{
14
- 'farm-textfield--input': true,
15
- 'farm-textfield--input--iconed': icon
16
- }">
14
+ <div
15
+ :class="{
16
+ 'farm-textfield--input': true,
17
+ 'farm-textfield--input--iconed': icon,
18
+ }"
19
+ >
17
20
  <button
18
21
  type="button"
19
22
  v-if="icon && iconPosition === 'left'"
@@ -24,7 +27,7 @@
24
27
  <input
25
28
  v-bind="$attrs"
26
29
  v-model="innerValue"
27
- v-mask="mask"
30
+ v-mask="mask"
28
31
  :disabled="disabled"
29
32
  :readonly="readonly"
30
33
  @click="$emit('click')"
@@ -39,10 +42,14 @@
39
42
  <farm-icon color="gray" size="20px">{{ icon }}</farm-icon>
40
43
  </button>
41
44
  </div>
42
- <farm-caption v-if="showErrorText" color="error" variation="regular">
45
+ <farm-caption v-if="!hideDetails && showErrorText" color="error" variation="regular">
43
46
  {{ errorBucket[0] }}
44
47
  </farm-caption>
45
- <farm-caption v-if="hint && !showErrorText" color="gray" variation="regular">
48
+ <farm-caption
49
+ v-if="!hideDetails && hint && !showErrorText"
50
+ color="gray"
51
+ variation="regular"
52
+ >
46
53
  {{ hint }}
47
54
  </farm-caption>
48
55
  </div>
@@ -111,6 +118,13 @@ export default Vue.extend({
111
118
  default: '',
112
119
  type: [String, Function],
113
120
  },
121
+ /**
122
+ * Hides hint and validation errors
123
+ */
124
+ hideDetails: {
125
+ type: Boolean,
126
+ default: false,
127
+ },
114
128
  },
115
129
  setup(props, { emit }) {
116
130
  const { rules } = toRefs(props);
@@ -4,6 +4,7 @@
4
4
 
5
5
  .farm-typography {
6
6
  font-size: 16px;
7
+ color: var(--farm-text-primary);
7
8
 
8
9
  &[bold] {
9
10
  font-weight: bold;
@@ -25,16 +26,12 @@
25
26
  margin-bottom: auto;
26
27
  }
27
28
 
28
- color: var(--farm-text-primary);
29
-
30
29
  &--lighten {
31
30
  color: var(--farm-text-secondary);
32
31
  }
33
32
 
34
33
  &.farm-typography--ellipsis {
35
- overflow: hidden;
36
- white-space: nowrap;
37
- text-overflow: ellipsis;
34
+ @include ellipsis;
38
35
  }
39
36
 
40
37
  @each $k in $theme-colors-list {
@@ -76,10 +76,17 @@
76
76
  }
77
77
  }
78
78
  }
79
+
79
80
  @mixin activateRipple {
80
81
  &:hover {
81
82
  .farm-ripple:before {
82
83
  opacity: 0.3;
83
84
  }
84
85
  }
86
+ }
87
+
88
+ @mixin ellipsis {
89
+ white-space: nowrap;
90
+ overflow: hidden;
91
+ text-overflow: ellipsis;
85
92
  }
package/src/main.ts CHANGED
@@ -87,6 +87,7 @@ export * from './components/RadioGroup';
87
87
  export * from './components/Select';
88
88
  export * from './components/Stepper';
89
89
  export * from './components/Switcher';
90
+ export * from './components/TextArea';
90
91
  export * from './components/TextField';
91
92
  export * from './components/TextFieldV2';
92
93
  export * from './components/Tooltip';
@@ -1,42 +0,0 @@
1
- export default {
2
- title: 'Form/Textfield/Examples/Password',
3
- component: Password,
4
- parameters: {
5
- docs: {
6
- description: {
7
- component: `How to toggle password visivility.<br />
8
- - Password visibility: hidden -> eye on icon (the click/tap will show the password)
9
- - Password visibility: show -> eye off icon (the click/tap will hide the password)`,
10
- },
11
- },
12
- },
13
- };
14
-
15
- export const Password = () => ({
16
- data() {
17
- return {
18
- password: '',
19
- showHidden: false,
20
- };
21
- },
22
- template: `
23
- <v-col cols="12" sm="12" md="4" class="v-col-fieldset-default pl-0">
24
- <label>
25
- Toggle visibility from password field
26
- </label>
27
- <v-text-field
28
- color="secondary"
29
- dense
30
- outlined
31
- v-model="password"
32
- :append-icon="showHidden ? 'mdi-eye-off' : 'mdi-eye'"
33
- :type="showHidden ? 'text' : 'password'"
34
- @click:append="showHidden = !showHidden"
35
- />
36
- </v-col>
37
- `,
38
- });
39
-
40
- Password.story = {
41
- name: 'Básico',
42
- };
@@ -1,27 +0,0 @@
1
- export default {
2
- title: 'Form/Select/Examples',
3
- parameters: {
4
- docs: {
5
- description: {
6
- component: `How to show select (v-select)<br />
7
- `,
8
- },
9
- },
10
- },
11
- };
12
-
13
- export const VSelect = () => ({
14
- data() {
15
- return {
16
- items: ['SP', 'RJ', 'MG', 'RS', 'BA'],
17
- };
18
- },
19
- template: `
20
- <v-col cols="12" sm="6" md="2" class="v-col-fieldset-default pl-0">
21
- <v-select dense outlined :items="items" />
22
- </v-col>`,
23
- });
24
-
25
- VSelect.story = {
26
- name: 'Básico',
27
- };