@farm-investimentos/front-mfe-components 9.3.0 → 9.3.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.
Files changed (33) hide show
  1. package/dist/front-mfe-components.common.js +426 -89
  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 +426 -89
  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 +1 -1
  9. package/src/components/Checkbox/Checkbox.scss +26 -5
  10. package/src/components/Checkbox/Checkbox.stories.js +31 -0
  11. package/src/components/Checkbox/Checkbox.vue +25 -4
  12. package/src/components/Chip/Chip.scss +29 -4
  13. package/src/components/Chip/Chip.stories.js +0 -2
  14. package/src/components/Form/Form.stories.js +134 -0
  15. package/src/components/Form/Form.vue +67 -0
  16. package/src/components/Form/__tests__/Form.spec.js +16 -0
  17. package/src/components/Form/index.ts +4 -0
  18. package/src/components/Modal/Modal.stories.js +0 -27
  19. package/src/components/RadioGroup/IRadioGroup.ts +6 -0
  20. package/src/components/RadioGroup/RadioGroup.scss +82 -0
  21. package/src/components/RadioGroup/RadioGroup.stories.js +34 -0
  22. package/src/components/RadioGroup/RadioGroup.vue +71 -0
  23. package/src/components/RadioGroup/__tests__/RadioGroup.spec.js +20 -0
  24. package/src/components/RadioGroup/index.ts +4 -0
  25. package/src/components/layout/Container/Container.stories.js +0 -1
  26. package/src/components/layout/Row/Row.scss +6 -0
  27. package/src/components/layout/Row/Row.stories.js +22 -0
  28. package/src/components/layout/Row/Row.vue +22 -0
  29. package/src/components/layout/Row/__tests__/Row.spec.js +22 -0
  30. package/src/components/layout/Row/index.ts +4 -0
  31. package/src/configurations/_theme-colors.scss +8 -8
  32. package/src/examples/Form/Full.stories.js +1 -1
  33. package/src/main.ts +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "9.3.0",
3
+ "version": "9.3.2",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -1,3 +1,5 @@
1
+ @import '../../configurations/theme-colors';
2
+
1
3
  .farm-checkbox__container {
2
4
  display: flex;
3
5
  flex-direction: row;
@@ -5,6 +7,29 @@
5
7
  .farm-label {
6
8
  margin-left: 8px;
7
9
  }
10
+
11
+ @each $color in $theme-colors-list {
12
+ &#{'[color=' + $color + ']'} {
13
+ .farm-checkbox--checked {
14
+ background-color: themeColor($color);
15
+ border-color: themeColor($color);
16
+
17
+ &.farm-checkbox--lighten {
18
+ background-color: themeColor($color, 'lighten');
19
+ border-color: themeColor($color, 'lighten');
20
+
21
+ .farm-icon {
22
+ color: themeColor($color, 'darken');
23
+ }
24
+ }
25
+
26
+ &.farm-checkbox--darken {
27
+ background-color: themeColor($color, 'darken');
28
+ border-color: themeColor($color, 'darken');
29
+ }
30
+ }
31
+ }
32
+ }
8
33
  }
9
34
 
10
35
  .farm-checkbox {
@@ -18,11 +43,6 @@
18
43
  line-height: 0;
19
44
  transition: all 0.4s;
20
45
 
21
- &--checked {
22
- background-color: var(--v-secondary-base);
23
- border-color: var(--v-secondary-base);
24
- }
25
-
26
46
  &--disabled {
27
47
  border-color: #dadada;
28
48
  cursor: default;
@@ -35,4 +55,5 @@
35
55
  .farm-icon {
36
56
  color: white;
37
57
  }
58
+
38
59
  }
@@ -1,4 +1,8 @@
1
1
  import Checkbox from './Checkbox';
2
+ import baseThemeColors from '../../configurations/_theme-colors-base.scss';
3
+
4
+ const colors = Object.keys(baseThemeColors);
5
+ const variations = ['', 'darken', 'lighten'];
2
6
 
3
7
  export default {
4
8
  title: 'Form/Checkbox',
@@ -60,3 +64,30 @@ export const Disabled = () => ({
60
64
  <farm-checkbox v-model="notIsChecked" :disabled="true" />
61
65
  </div>`,
62
66
  });
67
+
68
+ export const Colors = () => ({
69
+ data() {
70
+ return {
71
+ isChecked: true,
72
+ colors,
73
+ variations,
74
+ };
75
+ },
76
+ template: `<div style="display: flex; flex-direction: row; flex-wrap: wrap;">
77
+ <div v-for="color in colors" style="width: 33.3%;">
78
+ <h4>{{ color }}</h4>
79
+ <div
80
+ style="display: flex; flex-direction: column;"
81
+ v-for="variation in variations"
82
+ :key="color + '_' + variation"
83
+ >
84
+ <farm-checkbox
85
+ v-model="isChecked"
86
+ :color="color"
87
+ :variation="variation"
88
+ :label="variation || 'Base'"
89
+ />
90
+ </div>
91
+ </div>
92
+ </div>`,
93
+ });
@@ -1,7 +1,13 @@
1
1
  <template>
2
- <div class="farm-checkbox__container">
2
+ <div class="farm-checkbox__container" :color="$props.color">
3
3
  <span
4
- :class="{ 'farm-checkbox': true, 'farm-checkbox--checked': innerValue, 'farm-checkbox--disabled': disabled }"
4
+ :class="{
5
+ 'farm-checkbox': true,
6
+ 'farm-checkbox--checked': innerValue,
7
+ 'farm-checkbox--disabled': disabled,
8
+ 'farm-checkbox--lighten': variation === 'lighten',
9
+ 'farm-checkbox--darken': variation === 'darken',
10
+ }"
5
11
  @click="toggleValue"
6
12
  >
7
13
  <farm-icon size="sm" v-if="innerValue">check</farm-icon>
@@ -12,7 +18,7 @@
12
18
  </div>
13
19
  </template>
14
20
  <script lang="ts">
15
- import Vue, { ref, toRefs } from 'vue';
21
+ import Vue, { ref, toRefs, watch } from 'vue';
16
22
 
17
23
  export default Vue.extend({
18
24
  name: 'farm-checkbox',
@@ -29,19 +35,34 @@ export default Vue.extend({
29
35
  * disabled
30
36
  */
31
37
  disabled: { type: Boolean, default: false },
38
+ variation: {
39
+ type: String,
40
+ default: '',
41
+ },
42
+ color: {
43
+ type: String,
44
+ default: 'primary',
45
+ },
32
46
  },
33
47
  setup(props, { emit }) {
34
48
  const innerValue = ref(props.value);
35
49
  const { label, disabled } = toRefs(props);
36
50
 
37
51
  const toggleValue = () => {
38
- if(disabled.value) {
52
+ if (disabled.value) {
39
53
  return false;
40
54
  }
41
55
  innerValue.value = !innerValue.value;
42
56
  emit('input', innerValue.value);
43
57
  };
44
58
 
59
+ watch(
60
+ () => props.value,
61
+ () => {
62
+ innerValue.value = props.value;
63
+ }
64
+ );
65
+
45
66
  return {
46
67
  innerValue,
47
68
  label,
@@ -13,7 +13,7 @@
13
13
  align-items: center;
14
14
  color: white;
15
15
  width: 100%;
16
- border:1px solid themeColor('primary');
16
+ border: 1px solid themeColor('primary');
17
17
  font-size: 12px;
18
18
  font-weight: 500;
19
19
 
@@ -30,7 +30,7 @@
30
30
  &#{'[color=' + $color + ']'} {
31
31
  background-color: themeColor($color);
32
32
  border-color: themeColor($color);
33
-
33
+
34
34
  &.farm-chip--lighten {
35
35
  background-color: themeColor($color, 'lighten');
36
36
  border-color: themeColor($color, 'lighten');
@@ -44,18 +44,35 @@
44
44
  }
45
45
  }
46
46
 
47
+ &[color='neutral'] {
48
+ color: themeColor('secondary');
49
+
50
+ &.farm-chip--lighten {
51
+ color: themeColor('secondary');
52
+ }
53
+ &.farm-chip--darken {
54
+ color: white;
55
+ }
56
+ }
57
+
58
+ &[color='secondary'] {
59
+ &.farm-chip--lighten {
60
+ color: white;
61
+ }
62
+ }
63
+
47
64
  &--outlined {
48
65
  @each $color in $theme-colors-list {
49
66
  &#{'[color=' + $color + ']'} {
50
67
  background-color: transparent;
51
68
  color: themeColor($color);
52
-
69
+
53
70
  &.farm-chip--lighten {
54
71
  background-color: transparent;
55
72
  border-color: themeColor($color, 'lighten');
56
73
  color: themeColor($color);
57
74
  }
58
-
75
+
59
76
  &.farm-chip--darken {
60
77
  background-color: transparent;
61
78
  border-color: themeColor($color, 'darken');
@@ -63,5 +80,13 @@
63
80
  }
64
81
  }
65
82
  }
83
+
84
+ &[color='neutral'] {
85
+ color: themeColor('secondary');
86
+
87
+ &.farm-chip--lighten {
88
+ color: themeColor('secondary');
89
+ }
90
+ }
66
91
  }
67
92
  }
@@ -2,8 +2,6 @@ import Chip from './Chip.vue';
2
2
  import baseThemeColors from '../../configurations/_theme-colors-base.scss';
3
3
  import('./Chip.stories.scss');
4
4
 
5
- console.log(baseThemeColors);
6
-
7
5
  const colors = Object.keys(baseThemeColors);
8
6
  const variations = ['', 'darken', 'lighten'];
9
7
 
@@ -0,0 +1,134 @@
1
+ import Form from './Form.vue';
2
+
3
+ export default {
4
+ title: 'Form/Form',
5
+ component: Form,
6
+ parameters: {
7
+ docs: {
8
+ description: {
9
+ component: `Form<br />
10
+ selector: <em>farm-form</em>
11
+ `,
12
+ },
13
+ },
14
+ viewMode: 'docs',
15
+ },
16
+ };
17
+
18
+ const styles = {
19
+ vForm: {
20
+ maxWidth: '480px',
21
+ },
22
+ footer: {
23
+ display: 'flex',
24
+ justifyContent: 'end',
25
+ },
26
+ };
27
+
28
+ export const Primary = () => ({
29
+ data() {
30
+ return {
31
+ form: {
32
+ document: 'Document',
33
+ name: 'Name',
34
+ },
35
+ validForm: false,
36
+ rules: {
37
+ required: value => !!value || 'Campo obrigatório',
38
+ },
39
+ styles,
40
+ };
41
+ },
42
+ template: `
43
+ <farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
44
+ <section>
45
+ <div>
46
+ <farm-label :required="true">Documento</farm-label>
47
+ <farm-textfield v-model="form.document" :rules="[rules.required]" />
48
+ </div>
49
+ </section>
50
+ <section>
51
+ <div>
52
+ <farm-label :required="true">Nome</farm-label>
53
+ <farm-textfield v-model="form.name" :rules="[rules.required]" />
54
+ </div>
55
+ </section>
56
+ <div class="footer" :style="[styles.footer]">
57
+ <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
58
+ <farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
59
+ </div>
60
+ </farm-form>
61
+ `,
62
+ });
63
+
64
+ export const Secondary = () => ({
65
+ data() {
66
+ return {
67
+ form: {
68
+ document: 'Document',
69
+ not: 'Not required field',
70
+ },
71
+ validForm: false,
72
+ rules: {
73
+ required: value => !!value || 'Campo obrigatório',
74
+ },
75
+ styles,
76
+ };
77
+ },
78
+ template: `
79
+ <farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
80
+ <section>
81
+ <div>
82
+ <farm-label :required="true">Documento</farm-label>
83
+ <farm-textfield v-model="form.document" :rules="[rules.required]" />
84
+ </div>
85
+ </section>
86
+ <section>
87
+ <div>
88
+ <farm-label>not</farm-label>
89
+ <farm-textfield v-model="form.not" />
90
+ </div>
91
+ </section>
92
+ <div class="footer" :style="[styles.footer]">
93
+ <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
94
+ <farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
95
+ </div>
96
+ </farm-form>
97
+ `,
98
+ });
99
+
100
+ export const InitInvalid = () => ({
101
+ data() {
102
+ return {
103
+ form: {
104
+ document: '',
105
+ name: '',
106
+ },
107
+ validForm: false,
108
+ rules: {
109
+ required: value => !!value || 'Campo obrigatório',
110
+ },
111
+ styles,
112
+ };
113
+ },
114
+ template: `
115
+ <farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
116
+ <section>
117
+ <div>
118
+ <farm-label :required="true">Documento</farm-label>
119
+ <farm-textfield v-model="form.document" :rules="[rules.required]" />
120
+ </div>
121
+ </section>
122
+ <section>
123
+ <div>
124
+ <farm-label :required="true">Nome</farm-label>
125
+ <farm-textfield v-model="form.name" :rules="[rules.required]" />
126
+ </div>
127
+ </section>
128
+ <div class="footer" :style="[styles.footer]">
129
+ <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
130
+ <farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
131
+ </div>
132
+ </farm-form>
133
+ `,
134
+ });
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <form class="farm-form"><slot></slot></form>
3
+ </template>
4
+ <script lang="ts">
5
+ import Vue, { onMounted, reactive, ref, getCurrentInstance } from 'vue';
6
+
7
+ type ErrorsBag = Record<number, boolean>;
8
+
9
+ export default Vue.extend({
10
+ name: 'farm-form',
11
+ props: {
12
+ value: { type: [Array, Boolean], required: true },
13
+ },
14
+ inheritAttrs: true,
15
+ setup(props, { emit }) {
16
+ const innerValue = ref(props.value);
17
+ const errorsBag = reactive({} as ErrorsBag);
18
+ let validationFields = [];
19
+
20
+ const dispatchError = () => {
21
+ const keys = Object.keys(errorsBag);
22
+ const errorsIds = keys.filter(key => !errorsBag[key]);
23
+ emit('input', errorsIds.length === 0);
24
+ };
25
+
26
+ const watchInput = (field: any) => {
27
+ field.$watch(
28
+ 'hasError',
29
+ () => {
30
+ errorsBag[field._uid] = field.valid;
31
+ dispatchError();
32
+ },
33
+ { immediate: true }
34
+ );
35
+ };
36
+
37
+ const reset = () => {
38
+ validationFields.forEach(field => {
39
+ field.reset();
40
+ });
41
+ };
42
+
43
+ const recursiveFormField = $node => {
44
+ $node.$children.forEach($leaf => {
45
+ if ($leaf.$children.length > 1) {
46
+ recursiveFormField($leaf);
47
+ } else if ($leaf.$children[0] && $leaf.$children[0].validate) {
48
+ validationFields.push($leaf.$children[0]);
49
+ }
50
+ });
51
+ };
52
+
53
+ onMounted(() => {
54
+ recursiveFormField(getCurrentInstance().proxy);
55
+ validationFields.forEach(field => {
56
+ watchInput(field);
57
+ });
58
+ });
59
+
60
+ return {
61
+ innerValue,
62
+ errorsBag,
63
+ reset,
64
+ };
65
+ },
66
+ });
67
+ </script>
@@ -0,0 +1,16 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Form from '../Form';
3
+
4
+ describe('Form component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(Form);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+ });
@@ -0,0 +1,4 @@
1
+ import Form from './Form.vue';
2
+
3
+ export { Form };
4
+ export default Form;
@@ -131,30 +131,6 @@ export const HeaderAndBottom = () => ({
131
131
  </div>`,
132
132
  });
133
133
 
134
- export const Persistent = () => ({
135
- data() {
136
- return {
137
- value: false,
138
- text,
139
- };
140
- },
141
- template: `<div>
142
- <farm-btn color="secondary" @click="value = true">abrir</farm-btn>
143
- <farm-modal v-model="value" :offsetTop="48" :offsetBottom="68" :persistent="true">
144
- <template v-slot:header>
145
- <farm-dialog-header title="Título" @onClose="() => value = false" />
146
- </template>
147
- <template v-slot:content>
148
- <br />persistent modal<br />
149
- </template>
150
-
151
- <template v-slot:footer>
152
- <farm-dialog-footer @onConfirm="() => value = false" @onClose="() => value = false" />
153
- </template>
154
- </farm-modal>
155
- </div>`,
156
- });
157
-
158
134
  export const HorizontalScroll = () => ({
159
135
  data() {
160
136
  return {
@@ -202,7 +178,6 @@ export const CustomHeader = () => ({
202
178
  </div>`,
203
179
  });
204
180
 
205
- <<<<<<< HEAD
206
181
  export const Persistent = () => ({
207
182
  data() {
208
183
  return {
@@ -227,8 +202,6 @@ export const Persistent = () => ({
227
202
  </div>`,
228
203
  });
229
204
 
230
- =======
231
- >>>>>>> develop
232
205
  const text = `inicio!<br />
233
206
  teste!<br />
234
207
  teste!<br />
@@ -0,0 +1,6 @@
1
+ interface IRadioGroup {
2
+ id: Number;
3
+ label: String;
4
+ }
5
+
6
+ export default IRadioGroup;
@@ -0,0 +1,82 @@
1
+ .farm-radio-group {
2
+ border: none;
3
+ cursor: default;
4
+ display: flex;
5
+ width: 100%;
6
+ &__item {
7
+ font-size: 16px;
8
+ line-height: 1.1;
9
+ cursor: pointer;
10
+ display: grid;
11
+ grid-template-columns: 16px auto;
12
+ gap: 8px;
13
+ color: rgba(0,0,0,.6);
14
+ margin-top: 16px;
15
+ margin-right: 16px;
16
+ }
17
+ }
18
+
19
+ .farm-radio-group--column {
20
+ flex-direction: column;
21
+ }
22
+
23
+ input[type="radio"] {
24
+ -webkit-appearance: none;
25
+ appearance: none;
26
+ background-color: #ffffff;
27
+ margin: 0;
28
+ font: inherit;
29
+ color: rgba(0,0,0,.6);
30
+ width: 18px;
31
+ height: 18px;
32
+ border: 1.5px solid rgba(0,0,0,.6);
33
+ border-radius: 50%;
34
+ transform: translate(-12px);
35
+ display: grid;
36
+ place-content: center;
37
+ cursor: pointer;
38
+ }
39
+
40
+ input[type="radio"]::before {
41
+ content: "";
42
+ width: 10px;
43
+ height: 10px;
44
+ border-radius: 50%;
45
+ transform: scale(0);
46
+ transition: 120ms transform ease-in-out;
47
+ box-shadow: inset 16px 16px var(--radio-group-color);
48
+ background-color: CanvasText;
49
+ }
50
+
51
+ input[type="radio"]:checked::before {
52
+ transform: scale(1);
53
+ }
54
+
55
+ input[type="radio"]:focus {
56
+ outline: none;
57
+ outline-offset: none;
58
+ }
59
+
60
+ input[type="radio"]:checked {
61
+ border: 1.5px solid var(--radio-group-color);
62
+ }
63
+
64
+ input[type='radio']:hover {
65
+ box-shadow: 0px 0px 0px 8px rgba(0, 0, 0, 0.1);
66
+ background-color: rgba(0, 0, 0, 0.1);
67
+ border-radius: 50%;
68
+ opacity: 1;
69
+ }
70
+
71
+ input[type='radio']:active {
72
+ animation: pulse 0.2s 1 ease-out;
73
+ }
74
+
75
+ @keyframes pulse {
76
+ from {
77
+ box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(0, 0, 0, 0.2);
78
+ }
79
+ to {
80
+ box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(0, 0, 0, 0.2);
81
+ }
82
+ }
@@ -0,0 +1,34 @@
1
+ import RadioGroup from './RadioGroup';
2
+
3
+ export default {
4
+ title: 'Form/RadioGroup',
5
+ component: RadioGroup,
6
+ parameters: {
7
+ docs: {
8
+ description: {
9
+ component: `RadioGroup<br />
10
+ selector: <em>farm-radio-group</em>
11
+ `,
12
+ },
13
+ },
14
+ viewMode: 'docs',
15
+ },
16
+ };
17
+
18
+ export const Primary = () => ({
19
+ data() {
20
+ return {
21
+ buttons: [
22
+ { label: 'Button 1', id: 1 },
23
+ { label: 'Button 2', id: 2 },
24
+ { label: 'Button 3', id: 3 }
25
+ ],
26
+ checkedValue: 1
27
+ };
28
+ },
29
+ template: `<div>
30
+ <farm-radio-group v-model="checkedValue" column :buttons="buttons" />
31
+ </div>`,
32
+ });
33
+
34
+ Primary.storyName = 'Basic';