@farm-investimentos/front-mfe-components 11.12.1 → 12.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "11.12.1",
3
+ "version": "12.0.1",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -1,14 +1,19 @@
1
1
  @import '../../configurations/theme-colors';
2
2
 
3
3
  .farm-alert-box {
4
- background-color: themeColor('primary', 'lighten');
5
4
  border-radius: 5px;
6
- color: themeColor('primary', 'darken');
7
5
  display: flex;
8
6
  padding: 8px 16px;
9
7
  position: relative;
10
8
  min-height: 40px;
11
9
 
10
+ @each $color in $theme-colors-list {
11
+ &#{'[color=' + $color + ']'} {
12
+ background-color: themeColor($color, 'lighten');
13
+ color: themeColor($color, 'darken');
14
+ }
15
+ }
16
+
12
17
  &__content {
13
18
  flex: 1;
14
19
 
@@ -1,4 +1,6 @@
1
1
  import AlertBox from './AlertBox.vue';
2
+ import baseThemeColors from '../../configurations/_theme-colors-base.scss';
3
+ const colors = Object.keys(baseThemeColors);
2
4
 
3
5
  export default {
4
6
  title: 'Feedback/AlertBox',
@@ -48,3 +50,15 @@ export const moreThanOneLine = () => ({
48
50
  },
49
51
  template: '<farm-alertbox icon="book" dismissable>{{text}}</farm-alertbox>',
50
52
  });
53
+
54
+ export const Colors = () => ({
55
+ data() {
56
+ return {
57
+ colors,
58
+ };
59
+ },
60
+ template: `
61
+ <div>
62
+ <farm-alertbox class="mt-3" v-for="color of colors" :key="'random_10_' + color" :color="color" icon="book" dismissable>alert box</farm-alertbox>
63
+ </div> `,
64
+ });
@@ -1,12 +1,16 @@
1
1
  <template>
2
2
  <transition name="fade">
3
- <div v-if="visible" :class="{ 'farm-alert-box': true, 'farm-alert-box--dense': dense }">
3
+ <div
4
+ v-if="visible"
5
+ :color="color"
6
+ :class="{ 'farm-alert-box': true, 'farm-alert-box--dense': dense }"
7
+ >
4
8
  <farm-icon
5
9
  v-if="icon"
6
10
  class="farm-alert-box__icon"
7
- color="primary"
8
11
  variation="darken"
9
12
  size="md"
13
+ :color="color"
10
14
  >{{ icon }}</farm-icon
11
15
  >
12
16
  <div
@@ -16,23 +20,30 @@
16
20
  }"
17
21
  >
18
22
  <farm-bodytext
19
- :type="1"
20
23
  variation="regular"
21
- color="primary"
22
24
  color-variation="darken"
25
+ :type="1"
26
+ :color="color"
23
27
  >
24
28
  <slot></slot>
25
29
  </farm-bodytext>
26
30
  </div>
27
- <farm-btn class="farm-alert-box__close" v-if="dismissable" icon size="md">
28
- <farm-icon color="primary" variation="darken" size="md">close</farm-icon>
31
+ <farm-btn
32
+ class="farm-alert-box__close"
33
+ v-if="dismissable"
34
+ icon
35
+ size="md"
36
+ :color="color"
37
+ @click="close"
38
+ >
39
+ <farm-icon variation="darken" size="md" :color="color">close</farm-icon>
29
40
  </farm-btn>
30
41
  </div>
31
42
  </transition>
32
43
  </template>
33
44
 
34
45
  <script lang="ts">
35
- import Vue, { ref } from 'vue';
46
+ import Vue, { ref, PropType } from 'vue';
36
47
 
37
48
  export default Vue.extend({
38
49
  name: 'farm-alertbox',
@@ -58,6 +69,24 @@ export default Vue.extend({
58
69
  type: Boolean,
59
70
  default: false,
60
71
  },
72
+ /**
73
+ * Color
74
+ */
75
+ color: {
76
+ type: String as PropType<
77
+ | 'primary'
78
+ | 'secondary'
79
+ | 'neutral'
80
+ | 'info'
81
+ | 'success'
82
+ | 'error'
83
+ | 'warning'
84
+ | 'success'
85
+ | 'extra-1'
86
+ | 'extra-2'
87
+ >,
88
+ default: 'primary',
89
+ },
61
90
  },
62
91
  setup() {
63
92
  const visible = ref(true);
@@ -3,9 +3,11 @@ import AlertBox from '../AlertBox';
3
3
 
4
4
  describe('AlertBox component', () => {
5
5
  let wrapper;
6
+ let component;
6
7
 
7
8
  beforeEach(() => {
8
9
  wrapper = shallowMount(AlertBox, {});
10
+ component = wrapper.vm;
9
11
  });
10
12
 
11
13
  test('Created hook', () => {
@@ -17,4 +19,14 @@ describe('AlertBox component', () => {
17
19
  expect(wrapper.element).toMatchSnapshot();
18
20
  });
19
21
  });
22
+
23
+ describe('Methods', () => {
24
+ describe('close', () => {
25
+ it('should close the AlertBox', () => {
26
+ expect(component.visible).toBeTruthy();
27
+ component.close();
28
+ expect(component.visible).toBeFalsy();
29
+ });
30
+ });
31
+ });
20
32
  });
@@ -24,4 +24,17 @@ export const Primary = () => ({
24
24
  `,
25
25
  });
26
26
 
27
-
27
+ export const Events = () => ({
28
+ methods: {
29
+ handleEvent(type) {
30
+ alert(type);
31
+ },
32
+ },
33
+ template: `
34
+ <farm-card
35
+ @click.stop="handleEvent('click')"
36
+ >
37
+ Card content
38
+ </farm-card>
39
+ `,
40
+ });
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <component class="farm-card" :is="tag">
2
+ <component class="farm-card" :is="tag" v-on="$listeners">
3
3
  <slot></slot>
4
4
  </component>
5
5
  </template>
@@ -42,15 +42,15 @@ export const Value = () => ({
42
42
  },
43
43
  template: `<div>
44
44
  <div class="d-flex">
45
- <farm-checkbox v-model="option1" value="1" class="mr-2" />
45
+ <farm-checkbox v-model="option1" value="option1" class="mr-2" />
46
46
  option1 : {{option1}}
47
47
  </div>
48
48
  <div class="d-flex align-center">
49
- <farm-checkbox v-model="option2" value="2" class="mr-2 my-2" />
49
+ <farm-checkbox v-model="option2" value="option2" class="mr-2 my-2" />
50
50
  option2 : {{option2}}
51
51
  </div>
52
52
  <div class="d-flex">
53
- <farm-checkbox v-model="option3" value="3" class="mr-2" />
53
+ <farm-checkbox v-model="option3" value="option3" class="mr-2" />
54
54
  option3 : {{option3}}
55
55
  </div>
56
56
  </div>`,
@@ -145,3 +145,29 @@ export const Indeterminate = () => ({
145
145
  <farm-checkbox :indeterminate="true" v-model="isChecked" :value="true" />
146
146
  </div>`,
147
147
  });
148
+
149
+ export const ResetByValue = () => ({
150
+ data() {
151
+ return {
152
+ isChecked: true,
153
+ };
154
+ },
155
+ template: `<div>
156
+ <farm-checkbox v-model="isChecked" :value="true" />
157
+ isChecked (value): {{ isChecked }}
158
+ <farm-btn @click="isChecked = null;">reset</farm-btn>
159
+ </div>`,
160
+ });
161
+
162
+ export const ResetByMethod = () => ({
163
+ data() {
164
+ return {
165
+ isChecked: true,
166
+ };
167
+ },
168
+ template: `<div>
169
+ <farm-checkbox v-model="isChecked" :value="true" ref="checkbox" />
170
+ isChecked (value): {{ isChecked }}
171
+ <farm-btn @click="$refs.checkbox.reset()">reset</farm-btn>
172
+ </div>`,
173
+ });
@@ -1,18 +1,14 @@
1
1
  <template>
2
2
  <div class="farm-checkbox__container" :color="$props.color">
3
- <span
4
- :class="{
5
- 'farm-checkbox': true,
6
- 'farm-checkbox--checked': isChecked,
7
- 'farm-checkbox--disabled': disabled,
8
- 'farm-checkbox--indeterminate': indeterminate,
9
- 'farm-checkbox--lighten': variation === 'lighten',
10
- 'farm-checkbox--darken': variation === 'darken',
11
- 'farm-checkbox--error': showError,
12
- }"
13
- :size="$props.size"
14
- @click="toggleValue"
15
- >
3
+ <span :class="{
4
+ 'farm-checkbox': true,
5
+ 'farm-checkbox--checked': isChecked,
6
+ 'farm-checkbox--disabled': disabled,
7
+ 'farm-checkbox--indeterminate': indeterminate,
8
+ 'farm-checkbox--lighten': variation === 'lighten',
9
+ 'farm-checkbox--darken': variation === 'darken',
10
+ 'farm-checkbox--error': showError,
11
+ }" :size="$props.size" @click="toggleValue">
16
12
  <farm-icon :size="$props.size" v-if="innerValue && !indeterminate">check</farm-icon>
17
13
  <farm-icon :size="$props.size" v-if="indeterminate">minus</farm-icon>
18
14
  </span>
@@ -123,14 +119,16 @@ export default Vue.extend({
123
119
 
124
120
  const showError = computed(() => hasError.value && isTouched.value);
125
121
 
122
+
126
123
  watch(
127
- () => props.value,
128
- () => {
124
+ () => props.modelValue,
125
+ (newValue) => {
129
126
  isTouched.value = true;
130
- innerValue.value = props.value;
127
+ innerValue.value = newValue;
131
128
  validate(innerValue.value);
132
129
  }
133
130
  );
131
+
134
132
 
135
133
  watch(
136
134
  () => props.rules,
@@ -31,3 +31,17 @@
31
31
  }
32
32
  }
33
33
  }
34
+
35
+ @each $color in $theme-colors-list {
36
+ .farm-btn.farm-btn--icon.farm-btn--#{$color}:not(.farm-btn--disabled)
37
+ .farm-btn__content
38
+ i.mdi.farm-icon--darken {
39
+ color: var(--farm-#{$color}-darken);
40
+ }
41
+
42
+ .farm-btn.farm-btn--icon.farm-btn--#{$color}:not(.farm-btn--disabled)
43
+ .farm-btn__content
44
+ i.mdi.farm-icon--lighten {
45
+ color: var(--farm-#{$color}-lighten);
46
+ }
47
+ }
@@ -18,6 +18,10 @@
18
18
  &--neutral .farm-icon.farm-icon {
19
19
  color: var(--farm-neutral-darken);
20
20
  }
21
+ &--secondary .farm-icon.farm-icon,
22
+ &--gray .farm-icon.farm-icon {
23
+ color: white;
24
+ }
21
25
  }
22
26
 
23
27
  .farm-icon-box--inverted.farm-icon-box {
@@ -1,12 +1,9 @@
1
1
  <template>
2
- <div
3
- :class="{
4
- 'farm-icon-box': true,
5
- [cssColorClass]: true,
6
- 'farm-icon-box--inverted': inverted,
7
- }"
8
- :size="size"
9
- >
2
+ <div :class="{
3
+ 'farm-icon-box': true,
4
+ [cssColorClass]: true,
5
+ 'farm-icon-box--inverted': inverted,
6
+ }" :size="size">
10
7
  <farm-icon :color="inverted ? 'white' : color" :size="size">{{ iconParsed }}</farm-icon>
11
8
  </div>
12
9
  </template>
@@ -57,10 +54,7 @@ export default Vue.extend({
57
54
  },
58
55
  computed: {
59
56
  iconParsed() {
60
- if (this.icon.indexOf('mdi-') === 0) {
61
- return this.icon.split('mdi-')[1];
62
- }
63
- return this.icon;
57
+ return this.icon.indexOf('mdi-') === 0 ? this.icon.split('mdi-')[1] : this.icon;
64
58
  },
65
59
  cssColorClass() {
66
60
  return `farm-icon-box--${this.color}`;
@@ -24,7 +24,10 @@ export const MaxFileSize = () => ({
24
24
  });
25
25
 
26
26
  export const MaxFilesNumber = () => ({
27
- template: '<farm-multiple-filepicker :maxFileSize="5" :maxFilesNumber="1" />',
27
+ template: `<div>
28
+ <farm-multiple-filepicker :maxFileSize="5" :maxFilesNumber="2" />
29
+ max files allowed: 2
30
+ </div>`,
28
31
  });
29
32
 
30
33
  export const Download = () => ({
@@ -79,16 +79,15 @@
79
79
  </div>
80
80
  </li>
81
81
  </ul>
82
-
83
82
  <farm-btn
84
- v-if="hasFiles"
83
+ v-if="canAddMoreFiles && hasFiles"
85
84
  outlined
86
- title="Escolher Outro"
85
+ title="Escolher Arquivo"
87
86
  class="farm-btn--responsive"
88
87
  :disabled="disabledButton"
89
88
  @click="addMoreFiles"
90
89
  >
91
- Escolher Outro
90
+ Escolher Arquivo
92
91
  </farm-btn>
93
92
  </section>
94
93
  </template>
@@ -145,6 +144,9 @@ export default Vue.extend({
145
144
  hasFiles(): boolean {
146
145
  return this.files.length > 0 || this.downloadFiles.length > 0;
147
146
  },
147
+ canAddMoreFiles(): boolean {
148
+ return this.filesLength < this.maxFilesNumber;
149
+ },
148
150
  filesLength(): number {
149
151
  return this.files.length + this.downloadFiles.length;
150
152
  },
@@ -143,6 +143,18 @@ describe('MultipleFilePicker component', () => {
143
143
  expect(component.disabledButton).toBeTruthy();
144
144
  });
145
145
  });
146
+
147
+ describe('canAddMoreFiles', () => {
148
+ it('should return files and downloadFiles length', async () => {
149
+ await wrapper.setProps({
150
+ maxFilesNumber: 2,
151
+ downloadFiles: [new File([], 'test')],
152
+ });
153
+ component.files = [new File([], 'test2')];
154
+
155
+ expect(component.canAddMoreFiles).toBeFalsy();
156
+ });
157
+ });
146
158
  });
147
159
 
148
160
  describe('Watch', () => {
@@ -1,63 +1,69 @@
1
1
  @import '../../configurations/variables';
2
+ @import '../../configurations/theme-colors';
2
3
 
3
- input[type="radio"] {
4
- -webkit-appearance: none;
5
- appearance: none;
6
- background-color: #ffffff;
7
- margin: 0;
8
- font: inherit;
9
- color: rgba(0, 0, 0, .6);
10
- border: 1.5px solid rgba(0, 0, 0, .6);
11
- border-radius: 50%;
12
- display: grid;
13
- place-content: center;
14
- cursor: pointer;
15
-
16
- &::before {
17
- content: "";
18
- border-radius: 50%;
19
- transform: scale(0);
20
- transition: 120ms transform ease-in-out;
21
- background-color: CanvasText;
22
- }
23
-
24
- &.farm-radio--checked::before {
25
- transform: scale(1);
26
- box-shadow: inset 16px 16px var(--farm-primary-base);
27
- }
28
-
29
- &.farm-radio--checked {
30
- border-color: var(--farm-primary-base);
31
- }
32
-
33
- &:focus {
34
- outline: none;
35
- outline-offset: none;
36
- }
37
-
38
- &:hover {
39
- box-shadow: 0px 0px 0px 8px rgba(0, 0, 0, 0.1);
40
- background-color: rgba(0, 0, 0, 0.1);
41
- border-radius: 50%;
42
- opacity: 1;
43
- }
44
-
45
- &:active {
46
- animation: pulse 0.2s 1 ease-out;
47
- }
48
- }
4
+ input[type='radio'] {
5
+ -webkit-appearance: none;
6
+ appearance: none;
7
+ background-color: #ffffff;
8
+ margin: 0;
9
+ font: inherit;
10
+ color: rgba(0, 0, 0, 0.6);
11
+ border: 1.5px solid rgba(0, 0, 0, 0.6);
12
+ border-radius: 50%;
13
+ display: grid;
14
+ place-content: center;
15
+ cursor: pointer;
16
+
17
+ &::before {
18
+ content: '';
19
+ border-radius: 50%;
20
+ transform: scale(0);
21
+ transition: 120ms transform ease-in-out;
22
+ background-color: CanvasText;
23
+ }
24
+
25
+ &.farm-radio--checked::before {
26
+ transform: scale(1);
27
+ }
28
+
29
+ &:focus {
30
+ outline: none;
31
+ outline-offset: none;
32
+ }
33
+
34
+ &:hover {
35
+ box-shadow: 0px 0px 0px 8px rgba(0, 0, 0, 0.1);
36
+ background-color: rgba(0, 0, 0, 0.1);
37
+ border-radius: 50%;
38
+ opacity: 1;
39
+ }
49
40
 
41
+ &:active {
42
+ animation: pulse 0.2s 1 ease-out;
43
+ }
50
44
 
51
- @each $size,
52
- $value in $sizes {
53
- #{'input[type="radio"][size=' + $size +']'} {
54
- width: $value;
55
- height: $value;
45
+ @each $color in $theme-colors-list {
46
+ &#{'[color=' + $color + ']'} {
47
+ &.farm-radio--checked::before {
48
+ box-shadow: inset 16px 16px themeColor($color, 'base');
49
+ }
56
50
 
57
- &::before {
58
- content: "";
59
- width: $value / 2;
60
- height: $value / 2;
61
- }
62
- }
63
- }
51
+ &.farm-radio--checked {
52
+ border-color: themeColor($color, 'base');
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ @each $size, $value in $sizes {
59
+ #{'input[type="radio"][size=' + $size + ']'} {
60
+ width: $value;
61
+ height: $value;
62
+
63
+ &::before {
64
+ content: '';
65
+ width: $value / 2;
66
+ height: $value / 2;
67
+ }
68
+ }
69
+ }
@@ -1,6 +1,8 @@
1
1
  import { withDesign } from 'storybook-addon-designs';
2
2
  import Radio from './Radio.vue';
3
3
  import sizes from '../../configurations/sizes';
4
+ import baseThemeColors from '../../configurations/_theme-colors-base.scss';
5
+ const colors = Object.keys(baseThemeColors);
4
6
 
5
7
  export default {
6
8
  title: 'Form/Radio',
@@ -96,3 +98,17 @@ export const Sizes = () => ({
96
98
  </div>
97
99
  </div>`,
98
100
  });
101
+
102
+ export const Colors = () => ({
103
+ data() {
104
+ return {
105
+ colors,
106
+ v: 1,
107
+ };
108
+ },
109
+ template: `<div style="width: 480px">
110
+ <div v-for="color in colors" :key="color" class="d-flex flex-row align-center mb-3">
111
+ <farm-radio v-model="v" :value="1" :color="color" />&nbsp;&nbsp;{{ color }}
112
+ </div>
113
+ </div>`,
114
+ });
@@ -5,6 +5,7 @@
5
5
  'farm-radio--checked': isChecked,
6
6
  }"
7
7
  type="radio"
8
+ :color="color"
8
9
  :size="$props.size"
9
10
  :checked="isChecked"
10
11
  :value="value"
@@ -35,6 +36,24 @@ export default Vue.extend({
35
36
  type: String as PropType<'xs' | 'sm' | 'md' | 'lg' | 'xl'>,
36
37
  default: 'md',
37
38
  },
39
+ /**
40
+ * Color
41
+ */
42
+ color: {
43
+ type: String as PropType<
44
+ | 'primary'
45
+ | 'secondary'
46
+ | 'neutral'
47
+ | 'info'
48
+ | 'success'
49
+ | 'error'
50
+ | 'warning'
51
+ | 'success'
52
+ | 'extra-1'
53
+ | 'extra-2'
54
+ >,
55
+ default: 'primary',
56
+ },
38
57
  },
39
58
  computed: {
40
59
  isChecked() {