@farm-investimentos/front-mfe-components 11.4.5 → 11.4.7

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": "11.4.5",
3
+ "version": "11.4.7",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -33,13 +33,19 @@ export const Primary = () => ({
33
33
  document: 'Document',
34
34
  name: 'Name',
35
35
  checkbox: true,
36
- birthDate: new Date('1980/09/20').toISOString()
36
+ birthDate: new Date('1980/09/20').toISOString(),
37
+ selectId: 1,
37
38
  },
38
39
  validForm: false,
39
40
  rules: {
40
41
  required: value => !!value || 'Campo obrigatório',
41
42
  checked: value => !!value || 'Deve estar marcado',
42
43
  },
44
+ items: [
45
+ { value: null, text: '' },
46
+ { value: 1, text: 'label 1' },
47
+ { value: 2, text: 'label 2' },
48
+ ],
43
49
  styles,
44
50
  };
45
51
  },
@@ -55,6 +61,9 @@ export const Primary = () => ({
55
61
  <farm-label :required="true">True/false</farm-label>
56
62
  <farm-checkbox v-model="form.checkbox" :rules="[rules.checked]" />
57
63
 
64
+ <farm-label :required="true">Select</farm-label>
65
+ <v-select :rules="[rules.required]" :items="items" v-model="form.selectId"/>
66
+
58
67
  <farm-label :required="true">Birthdate:</farm-label>
59
68
  <DatePicker
60
69
  ref="birthDate"
@@ -87,6 +96,11 @@ export const Secondary = () => ({
87
96
  required: value => !!value || 'Campo obrigatório',
88
97
  },
89
98
  styles,
99
+ items: [
100
+ { value: null, text: '' },
101
+ { value: 1, text: 'label 1' },
102
+ { value: 2, text: 'label 2' },
103
+ ],
90
104
  };
91
105
  },
92
106
  template: `
@@ -220,4 +234,4 @@ export const DatePickers = () => ({
220
234
  </div>
221
235
  </farm-form>
222
236
  `,
223
- });
237
+ });
@@ -9,7 +9,7 @@ type ErrorsBag = Record<number, boolean>;
9
9
  export default Vue.extend({
10
10
  name: 'farm-form',
11
11
  props: {
12
- value: { type: [Boolean], required: true },
12
+ value: { type: [Boolean] },
13
13
  },
14
14
  inheritAttrs: true,
15
15
  setup(props, { emit }) {
@@ -42,7 +42,9 @@ export default Vue.extend({
42
42
 
43
43
  const recursiveFormField = $node => {
44
44
  $node.$children.forEach($leaf => {
45
- if ($leaf.$children.length > 1) {
45
+ if($leaf.validate) {
46
+ validationFields.push($leaf);
47
+ } else if ($leaf.$children.length > 1) {
46
48
  recursiveFormField($leaf);
47
49
  } else if ($leaf.$children[0] && $leaf.$children[0].validate) {
48
50
  validationFields.push($leaf.$children[0]);
@@ -17,10 +17,6 @@
17
17
  }
18
18
  }
19
19
 
20
- &--gray-base {
21
- color: var(--farm-neutral-darken);
22
- }
23
-
24
20
  @each $size,
25
21
  $value in $sizes {
26
22
  &#{'.farm-icon[size=' + $size +']'} {
@@ -1,4 +1,5 @@
1
1
  import { withDesign } from 'storybook-addon-designs';
2
+ import Icon from './Icon.vue';
2
3
  import sizes from '../../configurations/sizes';
3
4
  import baseThemeColors from '../../configurations/_theme-colors-base.scss';
4
5
  import iconsList from './icons_list';
@@ -9,6 +10,7 @@ import('./Icons.stories.scss');
9
10
  export default {
10
11
  title: 'Display/Icons',
11
12
  decorators: [withDesign],
13
+ component: Icon,
12
14
  parameters: {
13
15
  viewMode: 'docs',
14
16
  docs: {
@@ -32,7 +34,7 @@ export const Atom = () => ({
32
34
  export const Colors = () => ({
33
35
  data() {
34
36
  return {
35
- colors: [...colors, 'gray'],
37
+ colors: [...colors],
36
38
  };
37
39
  },
38
40
  template: `<div class="icons-container">
@@ -61,9 +61,7 @@ export default [
61
61
  'alpha',
62
62
  'alphabetical',
63
63
  'altimeter',
64
- 'amazon',
65
- 'amazon-alexa',
66
- 'amazon-drive',
64
+
67
65
  'ambulance',
68
66
  'amplifier',
69
67
  'anchor',
@@ -198,7 +196,6 @@ export default [
198
196
  'autorenew',
199
197
  'av-timer',
200
198
  'axe',
201
- 'azure',
202
199
  'baby',
203
200
  'baby-buggy',
204
201
  'backburger',
@@ -215,7 +212,6 @@ export default [
215
212
  'barrel',
216
213
  'baseball',
217
214
  'baseball-bat',
218
- 'basecamp',
219
215
  'basket',
220
216
  'basket-fill',
221
217
  'basket-unfill',
@@ -916,10 +912,7 @@ export default [
916
912
  'eye-settings-outline',
917
913
  'eyedropper',
918
914
  'eyedropper-variant',
919
- 'face',
920
- 'face-profile',
921
915
  'facebook',
922
- 'facebook-box',
923
916
  'facebook-messenger',
924
917
  'factory',
925
918
  'fan',
@@ -1550,8 +1543,6 @@ export default [
1550
1543
  'microphone-variant',
1551
1544
  'microphone-variant-off',
1552
1545
  'microscope',
1553
- 'microsoft',
1554
- 'microsoft-dynamics',
1555
1546
  'midi',
1556
1547
  'midi-port',
1557
1548
  'minecraft',
@@ -55,7 +55,7 @@ export default Vue.extend({
55
55
  default: 'primary',
56
56
  },
57
57
  /**
58
- * copy to clipboard
58
+ * Text to be copied to clipboard
59
59
  */
60
60
  copyText: {
61
61
  type: String,
@@ -52,9 +52,21 @@ export default Vue.extend({
52
52
  default: false,
53
53
  },
54
54
  color: {
55
- type: String,
55
+ type: String as PropType<
56
+ | 'primary'
57
+ | 'secondary'
58
+ | 'neutral'
59
+ | 'info'
60
+ | 'success'
61
+ | 'error'
62
+ | 'warning'
63
+ | 'success'
64
+ | 'extra-1'
65
+ | 'extra-2'
66
+ | 'gray'
67
+ >,
56
68
  default: 'primary',
57
- },
69
+ }
58
70
  },
59
71
  setup(props, { emit }) {
60
72
  const innerValue = ref(props.value);
@@ -40,6 +40,9 @@ export default Vue.extend({
40
40
  name: 'farm-context-menu',
41
41
  components: {},
42
42
  props: {
43
+ /**
44
+ * Items to populate the context menu
45
+ */
43
46
  items: {
44
47
  type: Array as PropType<Array<IContextMenuOption>>,
45
48
  required: true,
@@ -54,7 +57,6 @@ export default Vue.extend({
54
57
  onClick(handler) {
55
58
  if (handler !== undefined) {
56
59
  this.$emit(handler);
57
- // handler();
58
60
  }
59
61
  },
60
62
  toggleValue() {
@@ -0,0 +1,59 @@
1
+ .farm-textfield {
2
+ &--input {
3
+ display: flex;
4
+ align-items: center;
5
+ gap: 8px;
6
+ border: 1px solid;
7
+ border-color: var(--farm-gray-lighten);
8
+ height: 36px;
9
+ border-radius: 5px;
10
+ padding: 8px;
11
+ margin-bottom: 8px;
12
+
13
+ > button {
14
+ display: flex;
15
+ }
16
+
17
+ &>input {
18
+ flex: 1;
19
+ outline: none;
20
+ color: var(--farm-neutral-darken);
21
+ font-size: 12px;
22
+ font-weight: 400;
23
+ }
24
+
25
+ width: 100%;
26
+ }
27
+ }
28
+
29
+ .farm-textfield--touched.farm-textfield--validatable {
30
+ &.farm-textfield--error {
31
+ .farm-textfield {
32
+ &--input {
33
+ border-color: var(--farm-error-base);
34
+
35
+ &>input {
36
+ color: var(--farm-neutral-darken);
37
+ }
38
+
39
+ .farm-icon {
40
+ color: var(--farm-error-base);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ .farm-textfield--blured.farm-textfield--validatable:not(.farm-textfield--error) {
48
+ .farm-textfield--input {
49
+ border-color: var(--farm-primary-base);
50
+
51
+ &>input {
52
+ color: var(--farm-neutral-darken);
53
+ }
54
+
55
+ .farm-icon {
56
+ color: var(--farm-primary-base);
57
+ }
58
+ }
59
+ }
@@ -25,11 +25,75 @@ export default {
25
25
  export const Primary = () => ({
26
26
  data() {
27
27
  return {
28
- v: 'some text',
28
+ v: 'input text',
29
29
  };
30
30
  },
31
31
  template: `<div style="width: 480px">
32
32
  <farm-textfield-v2 v-model="v" />
33
- value: {{ v }}
33
+ v-model: {{ v }}
34
+ </div>`,
35
+ });
36
+
37
+ export const Validate = () => ({
38
+ data() {
39
+ return {
40
+ v: 'input',
41
+ rules: {
42
+ required: value => !!value || 'Campo obrigatório',
43
+ },
44
+ };
45
+ },
46
+ template: `<div style="width: 480px">
47
+ <farm-label required>Required field</farm-label>
48
+ <farm-textfield-v2 v-model="v" :rules="[rules.required]" />
49
+ </div>`,
50
+ });
51
+
52
+ export const Icon = () => ({
53
+ data() {
54
+ return {
55
+ v: '',
56
+ };
57
+ },
58
+ methods: {
59
+ show() {
60
+ alert('On icon click');
61
+ },
62
+ },
63
+ template: `<div style="width: 480px">
64
+ <farm-textfield-v2 v-model="v" icon="eye" onClickIcon="this.show" />
65
+ <farm-textfield-v2 v-model="v" icon="eye" icon-position="left" onClickIcon="this.show" />
66
+ </div>`,
67
+ });
68
+
69
+ export const HintText = () => ({
70
+ data() {
71
+ return {
72
+ v: 'input text',
73
+ };
74
+ },
75
+ template: `<div style="width: 480px">
76
+ <farm-textfield-v2 v-model="v" hintText="Hint text" />
77
+ </div>`,
78
+ });
79
+
80
+ export const UpdateValue = () => ({
81
+ data() {
82
+ return {
83
+ counter: 1,
84
+ v: '1',
85
+ };
86
+ },
87
+ methods: {
88
+ onClick() {
89
+ this.counter++;
90
+ this.v = this.counter;
91
+ },
92
+ },
93
+ template: `<div style="width: 480px">
94
+ <farm-textfield-v2 v-model="v" />
95
+ <farm-btn @click="onClick">Add 1 to counter and update v-model</farm-btn>
96
+ <br />counter: {{ counter }}
97
+ <br />v-model: {{ v }}
34
98
  </div>`,
35
99
  });
@@ -1,13 +1,47 @@
1
1
  <template>
2
- <div class="farm-textfield">
2
+ <div
3
+ class="farm-textfield"
4
+ :class="{
5
+ 'farm-textfield': true,
6
+ 'farm-textfield--validatable': rules.length > 0,
7
+ 'farm-textfield--touched': isTouched,
8
+ 'farm-textfield--blured': isBlured,
9
+ 'farm-textfield--error': hasError,
10
+ }"
11
+ >
3
12
  <div class="farm-textfield--input">
4
- <input v-bind="$attrs" v-model="innerValue" />
13
+ <button v-if="icon && iconPosition === 'left'" @click="$emit('onClickIcon')">
14
+ <farm-icon color="gray" size="20px">{{ icon }}</farm-icon>
15
+ </button>
16
+
17
+ <input
18
+ v-bind="$attrs"
19
+ v-model="innerValue"
20
+ :disabled="disabled"
21
+ @keyup="onKeyUp"
22
+ @blur="onBlur"
23
+ />
24
+
25
+ <button v-if="icon && iconPosition === 'right'" @click="$emit('onClickIcon')">
26
+ <farm-icon color="gray" size="20px">{{ icon }}</farm-icon>
27
+ </button>
5
28
  </div>
6
- <span class="farm-textfield--text"> hint text</span>
29
+
30
+ <farm-caption v-if="hasError && isTouched" color="error" variation="regular">
31
+ {{ errorBucket[0] }}
32
+ </farm-caption>
33
+ <farm-caption v-if="hintText && !errorMessage" color="gray" variation="regular">
34
+ {{ hintText }}
35
+ </farm-caption>
7
36
  </div>
8
37
  </template>
38
+
9
39
  <script lang="ts">
10
- import Vue, { ref, watch } from 'vue';
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';
11
45
 
12
46
  export default Vue.extend({
13
47
  name: 'farm-textfield-v2',
@@ -16,15 +50,61 @@ export default Vue.extend({
16
50
  /**
17
51
  * v-model binding
18
52
  */
19
- value: {},
53
+ value: { type: [String, Number], default: '' },
54
+ /**
55
+ * Show icon?
56
+ */
57
+ icon: {
58
+ type: String,
59
+ default: null,
60
+ },
61
+ /**
62
+ * Icon position
63
+ */
64
+ iconPosition: { type: String as PropType<'left' | 'right'>, default: 'right' },
65
+ /**
66
+ * Show hint text
67
+ */
68
+ hintText: {
69
+ type: String,
70
+ default: null,
71
+ },
72
+ /**
73
+ * Show input disable
74
+ */
75
+ disabled: {
76
+ type: Boolean,
77
+ default: false,
78
+ },
79
+
80
+ errorMessage: String,
81
+ /**
82
+ * Array of rules used for validation
83
+ */
84
+ rules: {
85
+ type: Array as PropType<Array<Function>>,
86
+ default: () => [],
87
+ },
20
88
  },
21
89
  setup(props, { emit }) {
90
+ const { rules } = toRefs(props);
22
91
  const innerValue = ref(props.value);
92
+ const isTouched = ref(false);
93
+ const isBlured = ref(false);
94
+
95
+ const { errorBucket, valid, validatable } = validateFormStateBuilder();
96
+
97
+ let fieldValidator = validateFormFieldBuilder(rules.value);
98
+
99
+ const hasError = computed(() => {
100
+ return errorBucket.value.length > 0;
101
+ });
23
102
 
24
103
  watch(
25
104
  () => props.value,
26
105
  () => {
27
106
  innerValue.value = props.value;
107
+ validate(innerValue.value);
28
108
  }
29
109
  );
30
110
 
@@ -35,8 +115,41 @@ export default Vue.extend({
35
115
  }
36
116
  );
37
117
 
118
+ watch(
119
+ () => props.rules,
120
+ (newVal, oldVal) => {
121
+ if (deepEqual(newVal, oldVal)) return;
122
+ fieldValidator = validateFormFieldBuilder(rules.value);
123
+ validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
124
+ validate(innerValue.value);
125
+ }
126
+ );
127
+
128
+ onBeforeMount(() => {
129
+ validate(innerValue.value);
130
+ });
131
+
132
+ let validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
133
+
134
+ const onKeyUp = () => {
135
+ isTouched.value = true;
136
+ };
137
+
138
+ const onBlur = () => {
139
+ isBlured.value = true;
140
+ };
141
+
38
142
  return {
39
143
  innerValue,
144
+ errorBucket,
145
+ valid,
146
+ validatable,
147
+ hasError,
148
+ isTouched,
149
+ isBlured,
150
+ validate,
151
+ onKeyUp,
152
+ onBlur,
40
153
  };
41
154
  },
42
155
  });
@@ -23,18 +23,30 @@ export default Vue.extend({
23
23
  inheritAttrs: true,
24
24
  name: 'farm-typography',
25
25
  props: {
26
+ /**
27
+ * Html tag
28
+ */
26
29
  tag: {
27
30
  type: String as PropType<
28
31
  'p' | 'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'legend' | 'label' | 'li'
29
32
  >,
30
33
  default: 'p',
31
34
  },
35
+ /**
36
+ * Size
37
+ */
32
38
  size: {
33
39
  type: String as PropType<'xs' | 'sm' | 'md' | 'lg' | 'xl'>,
34
40
  },
41
+ /**
42
+ * Line Height
43
+ */
35
44
  lineHeight: {
36
45
  type: String,
37
46
  },
47
+ /**
48
+ * Font-weight
49
+ */
38
50
  weight: {
39
51
  type: Number as PropType<100 | 200 | 300 | 400 | 500 | 600 | 700>,
40
52
  },
@@ -53,6 +65,7 @@ export default Vue.extend({
53
65
  | 'success'
54
66
  | 'extra-1'
55
67
  | 'extra-2'
68
+ | 'gray'
56
69
  >,
57
70
  default: 'default',
58
71
  },
@@ -6,7 +6,7 @@
6
6
  flex-basis: 0;
7
7
  flex-grow: 1;
8
8
  max-width: 100%;
9
- width: 100;
9
+ width: 100%;
10
10
 
11
11
  &--no-gutters {
12
12
  padding: 0;
@@ -8,6 +8,9 @@ import Vue from 'vue';
8
8
  export default Vue.extend({
9
9
  name: 'farm-line',
10
10
  props: {
11
+ /**
12
+ * Remove default margins
13
+ */
11
14
  noSpacing: {
12
15
  type: Boolean,
13
16
  default: false,
@@ -17,5 +20,5 @@ export default Vue.extend({
17
20
  </script>
18
21
 
19
22
  <style lang="scss" scoped>
20
- @import './Line.scss'
23
+ @import './Line'
21
24
  </style>
@@ -52,6 +52,12 @@ $extra-2: (
52
52
  darken: #880E4F,
53
53
  );
54
54
 
55
+ $gray: (
56
+ base: #858585,
57
+ lighten: #D6D6D6,
58
+ darken: #5C5C5C,
59
+ );
60
+
55
61
  $theme-colors: (
56
62
  "primary": $primary,
57
63
  "secondary": $secondary,
@@ -61,7 +67,8 @@ $theme-colors: (
61
67
  "warning": $warning,
62
68
  "success": $success,
63
69
  "extra-1": $extra-1,
64
- "extra-2": $extra-2
70
+ "extra-2": $extra-2,
71
+ "gray": $gray
65
72
  );
66
73
 
67
74
  $text-colors: (