@farm-investimentos/front-mfe-components 3.1.0 → 3.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -0,0 +1,17 @@
1
+ .v-btn.v-btn--import {
2
+ background: var(--v-extra-lighten2);
3
+ color: var(--v-gray-lighten5);
4
+ .v-icon {
5
+ margin-right: 1rem;
6
+ }
7
+ }
8
+
9
+ .v-list-item {
10
+ border-bottom: 1px solid var(--v-gray-lighten2);
11
+ &:last-child {
12
+ border-bottom: none;
13
+ }
14
+ }
15
+ .v-list-item--link {
16
+ font-size: 0.875rem;
17
+ }
@@ -0,0 +1,19 @@
1
+ import MultiImport from './MultiImportButton.vue';
2
+
3
+ export default {
4
+ title: 'Example/Buttons/MultiImport',
5
+ component: MultiImport,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ components: { MultiImport },
10
+ template: '<MultiImport />',
11
+ });
12
+
13
+ export const List = () => ({
14
+ components: { MultiImport },
15
+ template: `<MultiImport :optionsList="[{ listenerKey: 1, title: 'XLS teste'}, { listenerKey: 2, title: 'CSV teste novo'}]" />`,
16
+ });
17
+
18
+ Primary.storyName = 'Básico';
19
+ List.storyName = 'Lista';
@@ -0,0 +1,78 @@
1
+ <template>
2
+ <v-menu
3
+ content-class="elevation-1"
4
+ v-model="togglePopover"
5
+ :offset-y="true"
6
+ :rounded="'b t-0'"
7
+ >
8
+ <template v-slot:activator="{ on, attrs }">
9
+ <v-btn
10
+ v-bind="attrs"
11
+ v-on="on"
12
+ dense
13
+ @onClick="togglePopover = true"
14
+ class="v-btn--responsive v-btn--import"
15
+ outlined
16
+ title="Importar"
17
+ >
18
+ Importar
19
+ <v-icon class="ml-2 mr-0">
20
+ {{ togglePopover ? 'mdi-chevron-up' : 'mdi-chevron-down' }}
21
+ </v-icon>
22
+ </v-btn>
23
+ </template>
24
+
25
+ <v-list dense class="pa-0">
26
+ <v-list-item
27
+ v-for="option in optionsList"
28
+ :key="option.listenerKey"
29
+ link
30
+ :title="option.title"
31
+ @click="$emit('onClick', option.listenerKey)"
32
+ >
33
+ <v-list-item-content>
34
+ <v-list-item-title>{{ option.title }}</v-list-item-title>
35
+ </v-list-item-content>
36
+ </v-list-item>
37
+ </v-list>
38
+ </v-menu>
39
+ </template>
40
+ <script>
41
+ import Vue from 'vue';
42
+ import VBtn from 'vuetify/lib/components/VBtn';
43
+ import VIcon from 'vuetify/lib/components/VIcon';
44
+ import VList from 'vuetify/lib/components/VList/VList';
45
+ import VMenu from 'vuetify/lib/components/VMenu';
46
+ import VListItem from 'vuetify/lib/components/VList/VListItem';
47
+ import { VListItemContent, VListItemTitle } from 'vuetify/lib';
48
+
49
+ export default Vue.extend({
50
+ name: 'farm-btn-multipleimport',
51
+ components: {
52
+ VBtn,
53
+ VIcon,
54
+ VList,
55
+ VListItem,
56
+ VMenu,
57
+ VListItemContent,
58
+ VListItemTitle,
59
+ },
60
+ props: {
61
+ /**
62
+ * Lista de opções para o menu dropdown
63
+ */
64
+ optionsList: {
65
+ type: Array,
66
+ default: () => [],
67
+ },
68
+ },
69
+ data() {
70
+ return {
71
+ togglePopover: false,
72
+ };
73
+ },
74
+ });
75
+ </script>
76
+ <style scoped lang="scss">
77
+ @import './MultiImportButton.scss';
78
+ </style>
@@ -0,0 +1,16 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import MultiImportButton from '../MultiImportButton';
3
+
4
+ describe('MultiImportButton component', () => {
5
+ let wrapper;
6
+ let component;
7
+
8
+ beforeEach(() => {
9
+ wrapper = shallowMount(MultiImportButton);
10
+ component = wrapper.vm;
11
+ });
12
+
13
+ test('Created hook', () => {
14
+ expect(wrapper).toBeDefined();
15
+ });
16
+ });
@@ -0,0 +1,4 @@
1
+ import MultiImportButton from './MultiImportButton';
2
+
3
+ export { MultiImportButton };
4
+ export default MultiImportButton;
@@ -1,19 +1,43 @@
1
1
  import DefaultTextField from './DefaultTextField.vue';
2
2
 
3
3
  export default {
4
- title: 'Example/Form/DefaultTextField',
5
- component: DefaultTextField,
4
+ title: 'Example/Form/DefaultTextField',
5
+ component: DefaultTextField,
6
6
  };
7
7
 
8
8
  export const Primary = () => ({
9
- components: { DefaultTextField },
10
- template: '<DefaultTextField :item="{ label: \'Nome do campo\'}" />',
9
+ components: { DefaultTextField },
10
+ data() {
11
+ return {
12
+ model: 'primary',
13
+ item: { label: 'Nome do campo', key: 'key' },
14
+ };
15
+ },
16
+ template: '<DefaultTextField v-model="model" :item="item" />',
11
17
  });
12
18
 
13
19
  export const Secondary = () => ({
14
- components: { DefaultTextField },
15
- template: '<DefaultTextField :item="{ label: \'Nome do campo\'} :required="true" />',
20
+ components: { DefaultTextField },
21
+ data() {
22
+ return {
23
+ model: 'secondary',
24
+ item: { label: 'Nome do campo', key: 'key' },
25
+ };
26
+ },
27
+ template: '<DefaultTextField :item="item" v-model="model" required="true" />',
28
+ });
29
+
30
+ export const ReadOnly = () => ({
31
+ components: { DefaultTextField },
32
+ data() {
33
+ return {
34
+ model: 'readonly',
35
+ item: { label: 'Nome do campo', key: 'key' },
36
+ };
37
+ },
38
+ template: '<DefaultTextField :item="item" v-model="model" :readonly="true" />',
16
39
  });
17
40
 
18
41
  Primary.storyName = 'Básico';
19
42
  Secondary.storyName = 'Label de obrigatório';
43
+ ReadOnly.storyName = 'Input readonly';
@@ -1,18 +1,19 @@
1
1
  <template>
2
2
  <v-col cols="12" sm="12" :md="item.md ? item.md : 2" class="v-col-fieldset-default pl-0">
3
- <label :for="`${forKey}-${item.key}`">
3
+ <label :for="inputId">
4
4
  {{ item.label }}
5
5
  <span class="required" v-if="required && !disabled">*</span>
6
6
  </label>
7
7
  <v-text-field
8
- :id="`${forKey}-${item.key}`"
9
8
  color="secondary"
10
9
  v-model="inputVal"
11
10
  outlined
12
11
  dense
13
12
  v-mask="`${mask ? mask : ''}`"
13
+ :id="inputId"
14
14
  :rules="inputRules"
15
15
  :disabled="disabled"
16
+ :readonly="readonly"
16
17
  ></v-text-field>
17
18
  </v-col>
18
19
  </template>
@@ -38,16 +39,20 @@ export default {
38
39
  forKey: {
39
40
  type: String,
40
41
  required: false,
42
+ default: 'form',
41
43
  },
42
44
  required: {
43
45
  type: Boolean,
44
46
  default: false,
45
- required: false,
46
47
  },
47
48
  mask: {
48
49
  type: String,
49
50
  default: null,
50
51
  },
52
+ readonly: {
53
+ type: Boolean,
54
+ default: false,
55
+ },
51
56
  },
52
57
  components: {
53
58
  VCol,
@@ -71,6 +76,9 @@ export default {
71
76
  }
72
77
  return [];
73
78
  },
79
+ inputId() {
80
+ return `${this.forKey}-${this.item.key}`;
81
+ },
74
82
  },
75
83
  };
76
84
  </script>
@@ -3,14 +3,16 @@ import DefaultTextField from '../DefaultTextField';
3
3
 
4
4
  describe('DefaultTextField component', () => {
5
5
  let wrapper;
6
+ let component;
6
7
 
7
8
  beforeEach(() => {
8
9
  wrapper = shallowMount(DefaultTextField, {
9
10
  propsData: {
10
- item: {},
11
+ item: { key: 'key' },
11
12
  value: false,
12
13
  },
13
14
  });
15
+ component = wrapper.vm;
14
16
  });
15
17
 
16
18
  test('Created hook', () => {
@@ -22,4 +24,10 @@ describe('DefaultTextField component', () => {
22
24
  expect(wrapper.element).toMatchSnapshot();
23
25
  });
24
26
  });
27
+
28
+ describe('Computed properties', () => {
29
+ it('Should have inputId', () => {
30
+ expect(component.inputId).toEqual('form-key');
31
+ });
32
+ });
25
33
  });
@@ -1,11 +1,9 @@
1
1
  <template>
2
2
  <div class="align-center">
3
- <div>
4
- <span class="mr-1" v-if="index === 0">{{ item[labelKey] }}</span>
5
- <span v-if="index === 1">
6
- (+{{ itemsLength - 1 }} {{ itemsLength > 2 ? 'outros' : 'outro' }} )
7
- </span>
8
- </div>
3
+ <span class="mr-1 label" v-if="index === 0">{{ item[labelKey] }}</span>
4
+ <span class="label" v-if="index === 1">
5
+ (+{{ itemsLength - 1 }} {{ itemsLength > 2 ? 'outros' : 'outro' }} )
6
+ </span>
9
7
  </div>
10
8
  </template>
11
9
 
@@ -42,3 +40,9 @@ export default Vue.extend({
42
40
  },
43
41
  });
44
42
  </script>
43
+
44
+ <style scoped>
45
+ .label {
46
+ font-size: 0.75rem;
47
+ }
48
+ </style>
@@ -0,0 +1,29 @@
1
+ import SelectModalOptions from './SelectModalOptions';
2
+
3
+ export default {
4
+ title: 'Example/SelectModalOptions',
5
+ component: SelectModalOptions,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ components: { SelectModalOptions },
10
+ data() {
11
+ return {
12
+ items: [
13
+ { id: 1, name: 'name 1' },
14
+ { id: 2, name: 'name 2' },
15
+ ],
16
+ selectedValue: null,
17
+ };
18
+ },
19
+ template: `<div>
20
+ <SelectModalOptions
21
+ :items="items"
22
+ v-model="selectedValue"
23
+ label="label"
24
+ inputId="some-id" />
25
+ <br />selected value: {{ selectedValue }}
26
+ </div>`,
27
+ });
28
+
29
+ Primary.storyName = 'Básico';
@@ -0,0 +1,273 @@
1
+ <template>
2
+ <v-col cols="12" sm="12" :md="config.md ? config.md : 2" class="v-col-fieldset-default">
3
+ <label :for="inputId">
4
+ {{ label }}
5
+ <span class="required" v-if="config.required">*</span>
6
+ </label>
7
+ <v-text-field
8
+ append-icon="mdi-magnify "
9
+ color="secondary"
10
+ outlined
11
+ dense
12
+ readonly
13
+ :id="inputId"
14
+ :value="selectedValueText"
15
+ @click="openModal"
16
+ ></v-text-field>
17
+
18
+ <v-dialog content-class="modal-default modal-default-small" v-model="showModal">
19
+ <DialogHeader class="dialog-header" :title="modalTitle" @onClose="closeModal" />
20
+
21
+ <v-main class="mt-9">
22
+ <Loader class="text-center mb-2" v-if="isLoading" />
23
+ <fieldset class="fieldset-default mx-4 mb-3" v-if="!isLoading">
24
+ <label for="searchInput"> {{ label }} </label>
25
+ <v-text-field
26
+ color="secondary"
27
+ id="searchInput"
28
+ outlined
29
+ dense
30
+ hide-details
31
+ :placeholder="placeholder"
32
+ v-model="searchValue"
33
+ />
34
+ </fieldset>
35
+
36
+ <v-data-table
37
+ v-if="!isLoading"
38
+ id="inputModalOptionsTable"
39
+ class="v-data-table__clickable v-data-table__select-modal"
40
+ hide-default-footer
41
+ hide-default-header
42
+ :items="items"
43
+ :headers="headers"
44
+ :options.sync="pagination"
45
+ :search="searchValue"
46
+ :custom-filter="customFilter"
47
+ @click:row="handleClick"
48
+ @pagination="handlePagination"
49
+ >
50
+ <template slot="no-data">
51
+ <DataTableEmptyWrapper />
52
+ </template>
53
+ <template slot="no-results">
54
+ <DataTableEmptyWrapper />
55
+ </template>
56
+ <template v-slot:[`item.label`]="{ item }">
57
+ <td :title="getItemLabel(item)" aria-role="button">
58
+ {{ getItemLabel(item) }}
59
+ </td>
60
+ </template>
61
+
62
+ <template v-slot:footer>
63
+ <DataTablePaginator
64
+ class="my-6"
65
+ hidePerPageOptions
66
+ :initialLimitPerPage="pagination.itemsPerPage"
67
+ :page="pagination.page"
68
+ :totalPages="pagination.pages"
69
+ @onChangePage="onChangePage"
70
+ />
71
+ </template>
72
+ </v-data-table>
73
+ </v-main>
74
+ <DialogFooter :hasConfirm="false" @onClose="closeModal" />
75
+ </v-dialog>
76
+ </v-col>
77
+ </template>
78
+ <script>
79
+ import Vue from 'vue';
80
+ import VTextField from 'vuetify/lib/components/VTextField';
81
+ import { VCol } from 'vuetify/lib/components/VGrid';
82
+ import { VMain } from 'vuetify/lib/components/VMain';
83
+ import { VDataTable } from 'vuetify/lib/components/VDataTable/';
84
+ import { VDialog } from 'vuetify/lib/components/VDialog/';
85
+ import { DialogHeader, DialogFooter, DataTableEmptyWrapper, DataTablePaginator } from '../../main';
86
+
87
+ export default Vue.extend({
88
+ name: 'farm-select-modal-options',
89
+ components: {
90
+ VTextField,
91
+ VCol,
92
+ VMain,
93
+ VDataTable,
94
+ VDialog,
95
+ DialogHeader,
96
+ DialogFooter,
97
+ DataTableEmptyWrapper,
98
+ DataTablePaginator,
99
+ },
100
+ props: {
101
+ /**
102
+ * Input Label
103
+ */
104
+ label: {
105
+ type: String,
106
+ required: true,
107
+ },
108
+ /**
109
+ * Input ID
110
+ */
111
+ inputId: {
112
+ type: String,
113
+ required: true,
114
+ },
115
+ /**
116
+ * Key used to get value from selected item
117
+ */
118
+ selectIdentifier: {
119
+ type: String,
120
+ default: 'id',
121
+ },
122
+ /**
123
+ * Format label from each item
124
+ * If value is a function, it is evaluted (use it to build complex strings)
125
+ * Otherwise, will get item value from the key with the prop value
126
+ */
127
+ itemLabelFormatter: {
128
+ default: 'name',
129
+ },
130
+ /**
131
+ * Items to be shown in the table
132
+ */
133
+ items: {
134
+ type: Array,
135
+ default: () => [],
136
+ },
137
+ /**
138
+ * Function that will be called when user focus/click the input
139
+ */
140
+ loadFn: {
141
+ type: Function,
142
+ default: () => {},
143
+ },
144
+ /**
145
+ * Request Status from the loader function
146
+ */
147
+ loadingRequestStatus: {
148
+ default: 'IDLE',
149
+ },
150
+ /**
151
+ * Title from the modal
152
+ */
153
+ modalTitle: {
154
+ type: String,
155
+ default: 'Selecione um item',
156
+ },
157
+ /**
158
+ * General configuration
159
+ */
160
+ config: {
161
+ default: () => ({ md: 2, required: false }),
162
+ },
163
+ /**
164
+ * Placeholder from the search input
165
+ */
166
+ placeholder: {
167
+ type: String,
168
+ default: 'Pesquise',
169
+ },
170
+ /**
171
+ * v-model
172
+ */
173
+ value: {
174
+ required: true,
175
+ },
176
+ },
177
+ computed: {
178
+ inputVal: {
179
+ get() {
180
+ return this.value;
181
+ },
182
+ set(val) {
183
+ this.$emit('input', val);
184
+ },
185
+ },
186
+ isLoading() {
187
+ return this.loadingRequestStatus === 'START';
188
+ },
189
+ selectedValueText: {
190
+ get() {
191
+ return this.selectedItem ? this.getItemLabel(this.selectedItem) : '';
192
+ },
193
+ },
194
+ totalPages() {
195
+ if (this.items !== undefined) {
196
+ return Math.ceil(this.items.length / 10);
197
+ }
198
+ return 0;
199
+ },
200
+ },
201
+ data() {
202
+ return {
203
+ selectedValue: {},
204
+ showModal: false,
205
+ selectedItem: null,
206
+ searchValue: '',
207
+ headers: [
208
+ {
209
+ text: 'Label',
210
+ sortable: false,
211
+ value: 'label',
212
+ align: 'left',
213
+ },
214
+ ],
215
+ pagination: {
216
+ page: 1,
217
+ itemsPerPage: 10,
218
+ pages: 0,
219
+ },
220
+ };
221
+ },
222
+ watch: {
223
+ value(newValue) {
224
+ if (!newValue || newValue === undefined) {
225
+ this.selectedItem = null;
226
+ }
227
+ },
228
+ items(newValue) {
229
+ this.pagination.pages = Math.ceil(newValue.length / 10);
230
+ },
231
+ },
232
+ methods: {
233
+ handlePagination(tablePagination) {
234
+ if (
235
+ tablePagination.page === 1 &&
236
+ tablePagination.itemsLength !== this.pagination.pages
237
+ ) {
238
+ this.pagination.pages = Math.ceil(tablePagination.itemsLength / 10);
239
+ }
240
+ },
241
+ openModal() {
242
+ this.loadFn();
243
+ this.showModal = true;
244
+ },
245
+ closeModal() {
246
+ this.showModal = false;
247
+ },
248
+ onChangePage(newPage) {
249
+ this.pagination.page = newPage;
250
+ },
251
+ getItemLabel(item) {
252
+ if (typeof this.itemLabelFormatter === 'function') {
253
+ return this.itemLabelFormatter(item);
254
+ }
255
+ return item[this.itemLabelFormatter];
256
+ },
257
+ handleClick(item) {
258
+ this.inputVal = item[this.selectIdentifier];
259
+ this.showModal = false;
260
+ this.selectedItem = item;
261
+ },
262
+ customFilter(_, search, item) {
263
+ const label = this.getItemLabel(item);
264
+ return label.toLowerCase().includes(search.toLowerCase());
265
+ },
266
+ },
267
+ });
268
+ </script>
269
+ <style lang="scss" scoped>
270
+ .v-text-field {
271
+ cursor: pointer;
272
+ }
273
+ </style>