@farm-investimentos/front-mfe-components 2.0.0 → 2.2.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.
Files changed (30) hide show
  1. package/README.md +1 -0
  2. package/dist/front-mfe-components.common.js +429 -20
  3. package/dist/front-mfe-components.common.js.map +1 -1
  4. package/dist/front-mfe-components.css +1 -1
  5. package/dist/front-mfe-components.umd.js +429 -20
  6. package/dist/front-mfe-components.umd.js.map +1 -1
  7. package/dist/front-mfe-components.umd.min.js +1 -1
  8. package/dist/front-mfe-components.umd.min.js.map +1 -1
  9. package/package.json +7 -3
  10. package/src/components/Buttons/ConfirmButton/ConfirmButton.stories.js +48 -0
  11. package/src/components/Buttons/ConfirmButton/ConfirmButton.vue +46 -0
  12. package/src/components/Buttons/ConfirmButton/__tests__/ConfirmButton.spec.js +33 -0
  13. package/src/components/Buttons/ConfirmButton/index.js +4 -0
  14. package/src/components/Buttons/DangerButton/DangerButton.stories.js +48 -0
  15. package/src/components/Buttons/DangerButton/DangerButton.vue +46 -0
  16. package/src/components/Buttons/DangerButton/__tests__/DangerButton.spec.js +33 -0
  17. package/src/components/Buttons/DangerButton/index.js +4 -0
  18. package/src/components/Buttons/DefaultButton/DefaultButton.stories.js +38 -0
  19. package/src/components/Buttons/DefaultButton/DefaultButton.vue +19 -0
  20. package/src/components/Buttons/DefaultButton/__tests__/DefaultButton.spec.js +14 -0
  21. package/src/components/Buttons/DefaultButton/index.js +4 -0
  22. package/src/components/DataTableHeader/DataTableHeader.scss +22 -0
  23. package/src/components/DataTableHeader/DataTableHeader.stories.js +8 -0
  24. package/src/components/DataTableHeader/DataTableHeader.vue +117 -0
  25. package/src/components/DataTableHeader/index.js +3 -0
  26. package/src/components/FilePicker/__tests__/FilePicker.spec.js +52 -0
  27. package/src/components/Loader/__tests__/Loader.spec.js +20 -0
  28. package/src/main.js +7 -0
  29. package/src/components/FilePicker/FilePicker.spec.js +0 -52
  30. package/src/components/Loader/Loader.spec.js +0 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -12,7 +12,9 @@
12
12
  "build:components": "vue-cli-service build --target lib --name front-mfe-components src/main.js",
13
13
  "lint": "vue-cli-service lint",
14
14
  "storybook": "start-storybook -p 6006",
15
- "build-storybook": "build-storybook"
15
+ "build-storybook": "build-storybook",
16
+ "test:unit": "jest --updateSnapshot",
17
+ "test:coverage": "jest --updateSnapshot --coverage"
16
18
  },
17
19
  "files": [
18
20
  "dist/*",
@@ -21,6 +23,7 @@
21
23
  "dependencies": {
22
24
  "@socheatsok78/storybook-addon-vuetify": "^0.1.8",
23
25
  "@vue/cli-service-global": "^4.5.13",
26
+ "@vue/test-utils": "^1.3.0",
24
27
  "core-js": "^3.6.5",
25
28
  "sass": "~1.32.0",
26
29
  "sass-loader": "^10.2.0",
@@ -35,12 +38,13 @@
35
38
  "@storybook/vue": "^6.3.6",
36
39
  "@vue/cli-plugin-babel": "~4.5.0",
37
40
  "@vue/cli-plugin-eslint": "~4.5.0",
41
+ "@vue/cli-plugin-unit-jest": "^4.5.15",
38
42
  "@vue/cli-service": "~4.5.0",
39
43
  "babel-eslint": "^10.1.0",
40
44
  "babel-loader": "^8.2.2",
41
45
  "eslint": "^6.7.2",
42
46
  "eslint-plugin-vue": "^6.2.2",
43
- "jest": "^27.2.5",
47
+ "jest": "^25.5.4",
44
48
  "jsdoc": "^3.6.7",
45
49
  "vue-template-compiler": "^2.6.11",
46
50
  "webpack-cli": "^4.9.0"
@@ -0,0 +1,48 @@
1
+ import ConfirmButton from './ConfirmButton.vue';
2
+
3
+ export default {
4
+ title: 'Example/Buttons/Confirm',
5
+ component: ConfirmButton,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ components: { ConfirmButton },
10
+ template: '<ConfirmButton>Confirm Button</ConfirmButton>',
11
+ });
12
+
13
+ export const HtmlMarkup = () => ({
14
+ components: { ConfirmButton },
15
+ template: '<ConfirmButton><em>I am italic</strong></em></ConfirmButton>',
16
+ });
17
+
18
+ export const Props = () => ({
19
+ components: { ConfirmButton },
20
+ template: '<ConfirmButton title="custom title">custom title (hover me)</ConfirmButton>',
21
+ });
22
+
23
+ export const Listener = () => ({
24
+ components: { ConfirmButton },
25
+ data() {
26
+ return {
27
+ x: 1,
28
+ };
29
+ },
30
+ template: `
31
+ <ConfirmButton color="error" @click="x = 2">click me to change: {{ x }}</ConfirmButton>
32
+ `,
33
+ });
34
+
35
+ export const Iconed = () => ({
36
+ components: { ConfirmButton },
37
+ template: `<div>
38
+ <ConfirmButton :icon="true">default icon</ConfirmButton>
39
+ <ConfirmButton :icon="true" customIcon="information-outline">information-outline</ConfirmButton>
40
+ <ConfirmButton :icon="true" customIcon="account-search">account-search</ConfirmButton>
41
+ </div>`,
42
+ });
43
+
44
+ Primary.storyName = 'Básico';
45
+ HtmlMarkup.storyName = 'Html Markup';
46
+ Props.storyName = 'Props';
47
+ Listener.storyName = 'Listener';
48
+ Iconed.storyName = 'Icon';
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <v-btn v-bind="$attrs" v-on="$listeners" color="secondary">
3
+ <v-icon v-if="icon" class="mr-3">
4
+ {{ iconPath }}
5
+ </v-icon>
6
+ <slot></slot>
7
+ </v-btn>
8
+ </template>
9
+ <script>
10
+ import Vue from 'vue';
11
+ import VBtn from 'vuetify/lib/components/VBtn';
12
+ import VIcon from 'vuetify/lib/components/VIcon';
13
+
14
+ export default Vue.extend({
15
+ name: 'farm-btn-confirm',
16
+ components: {
17
+ VBtn,
18
+ VIcon,
19
+ },
20
+ inheritAttrs: true,
21
+ props: {
22
+ /**
23
+ * Show icon
24
+ */
25
+ icon: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ /**
30
+ * Custom icon
31
+ */
32
+ customIcon: {
33
+ type: String,
34
+ default: '',
35
+ },
36
+ },
37
+ computed: {
38
+ iconPath() {
39
+ if (!this.customIcon) {
40
+ return 'mdi-check';
41
+ }
42
+ return `mdi-${this.customIcon}`;
43
+ },
44
+ },
45
+ });
46
+ </script>
@@ -0,0 +1,33 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import ConfirmButton from '../ConfirmButton';
3
+
4
+ describe('ConfirmButton component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(ConfirmButton);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+
17
+ describe('Computed properties', () => {
18
+ it('Should return default icon', () => {
19
+ wrapper.setProps({
20
+ icon: true,
21
+ });
22
+ expect(component.iconPath).toEqual('mdi-check');
23
+ });
24
+
25
+ it('Should return custom icon', async () => {
26
+ await wrapper.setProps({
27
+ icon: true,
28
+ customIcon: 'information',
29
+ });
30
+ expect(component.iconPath).toEqual('mdi-information');
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,4 @@
1
+ import ConfirmButton from './ConfirmButton';
2
+
3
+ export { ConfirmButton };
4
+ export default ConfirmButton;
@@ -0,0 +1,48 @@
1
+ import DangerButton from './DangerButton.vue';
2
+
3
+ export default {
4
+ title: 'Example/Buttons/DangerButton',
5
+ component: DangerButton,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ components: { DangerButton },
10
+ template: '<DangerButton>Danger Button</DangerButton>',
11
+ });
12
+
13
+ export const HtmlMarkup = () => ({
14
+ components: { DangerButton },
15
+ template: '<DangerButton><em>I am italic</strong></em></DangerButton>',
16
+ });
17
+
18
+ export const Props = () => ({
19
+ components: { DangerButton },
20
+ template: '<DangerButton title="custom title">custom title (hover me)</DangerButton>',
21
+ });
22
+
23
+ export const Listener = () => ({
24
+ components: { DangerButton },
25
+ data() {
26
+ return {
27
+ x: 1,
28
+ };
29
+ },
30
+ template: `
31
+ <DangerButton color="error" @click="x = 2">click me to change: {{ x }}</DangerButton>
32
+ `,
33
+ });
34
+
35
+ export const Iconed = () => ({
36
+ components: { DangerButton },
37
+ template: `<div>
38
+ <DangerButton :icon="true">default icon</DangerButton>
39
+ <DangerButton :icon="true" customIcon="information-outline">information-outline</DangerButton>
40
+ <DangerButton :icon="true" customIcon="account-search">account-search</DangerButton>
41
+ </div>`,
42
+ });
43
+
44
+ Primary.storyName = 'Básico';
45
+ HtmlMarkup.storyName = 'Html Markup';
46
+ Props.storyName = 'Props';
47
+ Listener.storyName = 'Listener';
48
+ Iconed.storyName = 'Icon';
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <v-btn v-bind="$attrs" v-on="$listeners" color="error">
3
+ <v-icon v-if="icon" class="mr-3">
4
+ {{ iconPath }}
5
+ </v-icon>
6
+ <slot></slot>
7
+ </v-btn>
8
+ </template>
9
+ <script>
10
+ import Vue from 'vue';
11
+ import VBtn from 'vuetify/lib/components/VBtn';
12
+ import VIcon from 'vuetify/lib/components/VIcon';
13
+
14
+ export default Vue.extend({
15
+ name: 'farm-btn-danger',
16
+ components: {
17
+ VBtn,
18
+ VIcon,
19
+ },
20
+ inheritAttrs: true,
21
+ props: {
22
+ /**
23
+ * Show icon
24
+ */
25
+ icon: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ /**
30
+ * Custom icon
31
+ */
32
+ customIcon: {
33
+ type: String,
34
+ default: '',
35
+ },
36
+ },
37
+ computed: {
38
+ iconPath() {
39
+ if (!this.customIcon) {
40
+ return 'mdi-trash-can-outline';
41
+ }
42
+ return `mdi-${this.customIcon}`;
43
+ },
44
+ },
45
+ });
46
+ </script>
@@ -0,0 +1,33 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import DangerButton from '../DangerButton';
3
+
4
+ describe('DangerButton component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(DangerButton);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+
17
+ describe('Computed properties', () => {
18
+ it('Should return default icon', () => {
19
+ wrapper.setProps({
20
+ icon: true,
21
+ });
22
+ expect(component.iconPath).toEqual('mdi-trash-can-outline');
23
+ });
24
+
25
+ it('Should return custom icon', async () => {
26
+ await wrapper.setProps({
27
+ icon: true,
28
+ customIcon: 'information',
29
+ });
30
+ expect(component.iconPath).toEqual('mdi-information');
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,4 @@
1
+ import DangerButton from './DangerButton';
2
+
3
+ export { DangerButton };
4
+ export default DangerButton;
@@ -0,0 +1,38 @@
1
+ import DefaultButton from './DefaultButton.vue';
2
+
3
+ export default {
4
+ title: 'Example/Buttons/Default',
5
+ component: DefaultButton,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ components: { DefaultButton },
10
+ template: '<DefaultButton>Pass text as slot</DefaultButton>',
11
+ });
12
+
13
+ export const HtmlMarkup = () => ({
14
+ components: { DefaultButton },
15
+ template: '<DefaultButton><em>I am italic</strong></em></DefaultButton>',
16
+ });
17
+
18
+ export const Props = () => ({
19
+ components: { DefaultButton },
20
+ template: '<DefaultButton color="secondary">props</DefaultButton>',
21
+ });
22
+
23
+ export const Listener = () => ({
24
+ components: { DefaultButton },
25
+ data() {
26
+ return {
27
+ x: 1,
28
+ };
29
+ },
30
+ template: `
31
+ <DefaultButton color="error" @click="x = 2">click me to change: {{ x }}</DefaultButton>
32
+ `,
33
+ });
34
+
35
+ Primary.storyName = 'Básico';
36
+ HtmlMarkup.storyName = 'Html Markup';
37
+ Props.storyName = 'Props';
38
+ Listener.storyName = 'Listener';
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <v-btn v-bind="$attrs" v-on="$listeners">
3
+ <slot></slot>
4
+ </v-btn>
5
+ </template>
6
+ <script>
7
+ import Vue from 'vue';
8
+ import VBtn from 'vuetify/lib/components/VBtn';
9
+
10
+ export default Vue.extend({
11
+ name: 'farm-btn',
12
+ inheritAttrs: true,
13
+ props: ['props'],
14
+
15
+ components: {
16
+ VBtn,
17
+ },
18
+ });
19
+ </script>
@@ -0,0 +1,14 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import DefaultButton from '../DefaultButton';
3
+
4
+ describe('DefaultButton component', () => {
5
+ let wrapper;
6
+
7
+ beforeEach(() => {
8
+ wrapper = shallowMount(DefaultButton);
9
+ });
10
+
11
+ test('Created hook', () => {
12
+ expect(wrapper).toBeDefined();
13
+ });
14
+ });
@@ -0,0 +1,4 @@
1
+ import DefaultButton from './DefaultButton';
2
+
3
+ export { DefaultButton };
4
+ export default DefaultButton;
@@ -0,0 +1,22 @@
1
+ .header-text {
2
+ position: relative;
3
+ i {
4
+ position: absolute;
5
+ right: -20px;
6
+ top: -1px;
7
+ }
8
+
9
+ .v-icon {
10
+ &.v-icon--asc {
11
+ transform: rotateX(180deg);
12
+ }
13
+ }
14
+ }
15
+
16
+ th.sortable:not(.active) {
17
+ &:hover {
18
+ .v-icon {
19
+ opacity: 0.5 !important;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,8 @@
1
+ import DataTableHeader from './DataTableHeader.vue';
2
+
3
+ export default {
4
+ title: 'Example/Table/DataTableHeader',
5
+ component: DataTableHeader,
6
+ };
7
+
8
+ Primary.storyName = 'Básico';
@@ -0,0 +1,117 @@
1
+ <template>
2
+ <thead>
3
+ <tr>
4
+ <th
5
+ v-for="(item, $index) in headers"
6
+ :key="item.value"
7
+ v-bind:class="[
8
+ item.sortable ? 'sortable' : '',
9
+ sortClick[$index].clicked ? 'active' : '',
10
+ item.sortable && sortClick[$index].descending === 'DESC' ? 'DESC' : 'ASC',
11
+ ]"
12
+ v-bind:style="{
13
+ textAlign: item.align,
14
+ width: thWidth(item),
15
+ }"
16
+ @click="item.sortable ? clickSort(item.value, $index) : ''"
17
+ @mouseover="changeShow($index)"
18
+ @mouseout="changeHidden($index)"
19
+ >
20
+ <span class="header-text">
21
+ {{ item.text }}
22
+
23
+ <v-icon
24
+ v-if="item.sortable && sortClick[$index].show"
25
+ v-bind:class="[
26
+ sortClick[$index][item.value] ? 'v-icon--desc' : 'v-icon--asc',
27
+ ]"
28
+ small
29
+ >
30
+ mdi-sort-descending
31
+ </v-icon>
32
+ </span>
33
+ </th>
34
+ </tr>
35
+ </thead>
36
+ </template>
37
+
38
+ <script>
39
+ import Vue from 'vue';
40
+ import VIcon from 'vuetify/lib/components/VIcon';
41
+ export default Vue.extend({
42
+ name: 'farm-datatable-header',
43
+ components: {
44
+ VIcon,
45
+ },
46
+ props: {
47
+ headers: {
48
+ type: Array,
49
+ require: true,
50
+ },
51
+ sortClick: {
52
+ type: Array,
53
+ require: true,
54
+ },
55
+ fistSelected: {
56
+ type: Boolean,
57
+ default: () => false,
58
+ },
59
+ },
60
+ methods: {
61
+ getTypeSort(value) {
62
+ return value ? 'DESC' : 'ASC';
63
+ },
64
+ clickSort(value, index) {
65
+ this.removeClicked();
66
+ this.sortClick[index].clicked = true;
67
+ this.sortClick[index].show = true;
68
+ this.sortClick[index][value] = !this.sortClick[index][value];
69
+ this.sortClick[index].descending = this.getTypeSort(this.sortClick[index][value]);
70
+ this.$emit('onClickSort', this.sortClick[index]);
71
+ },
72
+ changeShow(index) {
73
+ setTimeout(() => {
74
+ this.sortClick[index].show = true;
75
+ }, 10);
76
+ },
77
+ changeHidden(index) {
78
+ setTimeout(() => {
79
+ if (this.sortClick[index].clicked) {
80
+ return;
81
+ }
82
+ this.sortClick[index].show = false;
83
+ }, 10);
84
+ },
85
+ removeClicked() {
86
+ for (let i = 0; i < this.sortClick.length; i += 1) {
87
+ this.sortClick[i].clicked = false;
88
+ this.sortClick[i].show = false;
89
+ }
90
+ },
91
+ checkFistSelected(index) {
92
+ if (index === 0) {
93
+ return this.fistSelected;
94
+ }
95
+ return false;
96
+ },
97
+ thWidth(item) {
98
+ return item.width ? item.width + 'px' : 'auto';
99
+ },
100
+ },
101
+ created() {
102
+ for (let i = 0; i < this.headers.length; i += 1) {
103
+ this.sortClick.push({
104
+ [this.headers[i].value]: false,
105
+ descending: 'ASC',
106
+ field: this.headers[i].value,
107
+ clicked: this.checkFistSelected(i),
108
+ show: this.checkFistSelected(i),
109
+ });
110
+ }
111
+ },
112
+ });
113
+ </script>
114
+
115
+ <style lang="scss" scoped>
116
+ @import './DataTableHeader.scss';
117
+ </style>
@@ -0,0 +1,3 @@
1
+ import DataTableHeader from './DataTableHeader';
2
+
3
+ export default DataTableHeader;
@@ -0,0 +1,52 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import FilePicker from '../FilePicker';
3
+
4
+ describe('FilePicker component', () => {
5
+ let wrapper;
6
+
7
+ beforeEach(() => {
8
+ wrapper = shallowMount(FilePicker);
9
+ });
10
+
11
+ test('Created hook', () => {
12
+ expect(wrapper).toBeDefined();
13
+ });
14
+
15
+ describe('Component methods', () => {
16
+ describe('fileChange', () => {
17
+ it('Should emit event with a file', () => {
18
+ wrapper.vm.fileChange([1]);
19
+ expect(wrapper.emitted().onFileChange[0]).toBeDefined();
20
+ });
21
+
22
+ it('Should not emit', () => {
23
+ wrapper.vm.fileChange([]);
24
+ expect(wrapper.emitted().onFileChange).toBeUndefined();
25
+ });
26
+ });
27
+
28
+ describe('handlerFunctionHighlight', () => {
29
+ it('Should add class', () => {
30
+ const spyObj = jest.spyOn(wrapper.vm.dropArea.classList, 'add');
31
+ wrapper.vm.handlerFunctionHighlight();
32
+ expect(spyObj).toHaveBeenCalled();
33
+ });
34
+ });
35
+
36
+ describe('handlerFunctionUnhighlight', () => {
37
+ it('Should add class', () => {
38
+ const spyObj = jest.spyOn(wrapper.vm.dropArea.classList, 'remove');
39
+ wrapper.vm.handlerFunctionUnhighlight();
40
+ expect(spyObj).toHaveBeenCalled();
41
+ });
42
+ });
43
+
44
+ describe('addListeners', () => {
45
+ it('Should add listeners', () => {
46
+ const spyObj = jest.spyOn(wrapper.vm.dropArea, 'addEventListener');
47
+ wrapper.vm.addListeners();
48
+ expect(spyObj).toHaveBeenCalled();
49
+ });
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,20 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import Loader from '../Loader';
3
+
4
+ describe('Loader component', () => {
5
+ let wrapper;
6
+
7
+ beforeEach(() => {
8
+ wrapper = shallowMount(Loader);
9
+ });
10
+
11
+ test('Created hook', () => {
12
+ expect(wrapper).toBeDefined();
13
+ });
14
+
15
+ describe('mount component', () => {
16
+ it('renders correctly', () => {
17
+ expect(wrapper.element).toMatchSnapshot();
18
+ });
19
+ });
20
+ });
package/src/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import DataTableEmptyWrapper from './components/DataTableEmptyWrapper';
2
2
  import DataTablePaginator from './components/DataTablePaginator';
3
+ import DataTableHeader from './components/DataTableHeader';
3
4
  import AlertReload from './components/AlertReload';
4
5
  import MainFilter from './components/MainFilter';
5
6
  import Loader from './components/Loader';
@@ -15,10 +16,12 @@ import PromptUserToConfirm from './components/PromptUserToConfirm';
15
16
  import ModalPromptUser from './components/ModalPromptUser';
16
17
 
17
18
  import TableContextMenu from './components/TableContextMenu';
19
+ import DefaultButton from './components/Buttons/DefaultButton/DefaultButton.vue';
18
20
 
19
21
  export {
20
22
  DataTableEmptyWrapper,
21
23
  DataTablePaginator,
24
+ DataTableHeader,
22
25
  MainFilter,
23
26
  Loader,
24
27
  FilePicker,
@@ -33,8 +36,12 @@ export {
33
36
  PromptUserToConfirm,
34
37
  TableContextMenu,
35
38
  ModalPromptUser,
39
+ DefaultButton,
36
40
  };
37
41
 
42
+ export * from './components/Buttons/DefaultButton/';
43
+ export * from './components/Buttons/DangerButton/';
44
+ export * from './components/Buttons/ConfirmButton';
38
45
  export * from './components/Buttons/ExportButton/';
39
46
  export * from './components/Buttons/ImportButton/';
40
47
  export * from './components/Buttons/ToggleButton/';