Skip to content

Commit 09ecf3a

Browse files
authored
Feature/data table search (#949)
#### Por favor, verifique se o seu pull request está de acordo com o checklist abaixo: - [x] A implementação feita possui testes (Caso haja um motivo para não haver testes/haver apenas testes de snapshot, descrever abaixo) - [x] A documentação no mdx foi feita ou atualizada, caso necessário - [x] O eslint passou localmente ### 1 - Resumo Adiciona opção de exibir um input de busca na parte superior da DataTable. ### 2 - Tipo de pull request - [ ] 🧱 Novo componente - [x] ✨ Nova feature ou melhoria - [ ] 🐛 Fix - [ ] 👨‍💻 Refatoração - [ ] 📝 Documentação - [ ] 🎨 Estilo - [ ] 🤖 Build ou CI/CD ### 3 - Esse PR fecha alguma issue? Favor referenciá-la Não ### 4 - Quais são os passos para avaliar o pull request? - Acesse a DataTable e ative a prop `withSearch`; - Verifique que será exibida uma barra de pesquisa na parte superior da tabela; - Verifique que, ao digitar e passar um intervalo de 500ms sem alterar o conteúdo da pesquisa, é emitido um evento de busca (verifique o console do storybook); - Deixe seu like e se inscreva no canal. ### 5 - Imagem ou exemplo de uso: ### 6 - Esse pull request adiciona _breaking changes_? - [ ] Sim - [x] Não
1 parent 1363285 commit 09ecf3a

4 files changed

Lines changed: 62 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sysvale/cuida",
3-
"version": "3.117.3",
3+
"version": "3.118.0",
44
"description": "A design system built by Sysvale, using storybook and Vue components",
55
"repository": {
66
"type": "git",

src/components/DataTable.vue

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,44 @@
22
<div>
33
<div class="data-table">
44
<div class="data-table__header">
5-
<div class="data-table__items-counter">
5+
<CdsSearchInput
6+
v-if="withSearch"
7+
v-model="internalSearch"
8+
hide-label
9+
fluid
10+
@update:model-value="handleSearchInput"
11+
/>
12+
<div
13+
v-else
14+
class="data-table__items-counter"
15+
>
616
{{ totalItems }} {{ totalItems === 1 ? 'registro encontrado' : 'registros encontrados' }}
717
</div>
818

919
<cds-flexbox
20+
class="data-table__actions"
1021
gap="3"
1122
align="center"
23+
justify="flex-end"
1224
>
1325
<!-- @slot Slot para renderização de conteúdo à direita do DataTable header. -->
1426
<slot name="right" />
1527

1628
<cds-button
1729
v-if="!hideCustomizeButton"
18-
size="sm"
30+
:size="withSearch ? 'md' : 'sm'"
1931
secondary
2032
@button-click="handleCustomizeButtonClick"
2133
>
2234
Personalizar tabela
2335
</cds-button>
2436
</cds-flexbox>
37+
<div
38+
v-if="withSearch"
39+
class="data-table__items-counter--below"
40+
>
41+
{{ totalItems }} {{ totalItems === 1 ? 'registro encontrado' : 'registros encontrados' }}
42+
</div>
2543
</div>
2644

2745
<div class="data-table__table-container">
@@ -68,12 +86,13 @@
6886

6987
<script setup>
7088
import { ref, watch, computed } from 'vue';
89+
import { cloneDeep } from 'lodash';
90+
import { useHasSlot } from '../utils/composables/useHasSlot';
7191
import CdsButton from './Button.vue';
7292
import CdsTable from './Table.vue';
7393
import CustomFieldsSideSheet from './InternalComponents/CustomFieldsSideSheet.vue';
7494
import CdsFlexbox from './Flexbox.vue';
75-
import { useHasSlot } from '../utils/composables/useHasSlot';
76-
import { cloneDeep } from 'lodash';
95+
import CdsSearchInput from './SearchInput.vue';
7796
7897
const hasHeaderSlot = useHasSlot('header-item');
7998
@@ -129,11 +148,20 @@ const props = defineProps({
129148
default: 0,
130149
validator: (value) => value >= 0,
131150
},
151+
/**
152+
* Especifica se a barra de busca da tabela deve ser exibida.
153+
*/
154+
withSearch: {
155+
type: Boolean,
156+
default: false,
157+
},
132158
});
133159
134-
const emits = defineEmits(['update-fields-list', 'customize-click']);
160+
const emits = defineEmits(['update-fields-list', 'customize-click', 'search']);
135161
136162
const showSideSheet = ref(false);
163+
const internalSearch = ref('');
164+
const searchTimeout = ref(null);
137165
const internalCustomFieldsList = ref(cloneDeep(props.customFieldsList));
138166
139167
const computedMaxVisibleFields = computed(() => {
@@ -162,6 +190,12 @@ function handleOk(fieldsList) {
162190
emits('update-fields-list', fieldsList);
163191
}
164192
193+
function handleSearchInput(value) {
194+
clearTimeout(searchTimeout.value);
195+
searchTimeout.value = setTimeout(() => {
196+
emits('search', value);
197+
}, 500);
198+
}
165199
</script>
166200

167201
<style lang="scss" scoped>
@@ -173,15 +207,28 @@ function handleOk(fieldsList) {
173207
justify-content: center;
174208
gap: tokens.spacer(3);
175209
210+
&__actions {
211+
width: 100%;
212+
}
213+
176214
&__header {
177-
display: flex;
178-
justify-content: space-between;
179-
align-items: flex-end;
215+
display: grid;
216+
grid-template-columns: 1fr auto;
217+
column-gap: spacer(4);
218+
width: 100%;
219+
align-items: center;
180220
}
181221
182222
&__items-counter {
183223
@include tokens.caption;
184224
color: tokens.$n-600;
225+
display: flex;
226+
align-items: flex-end;
227+
228+
&--below {
229+
@extend .data-table__items-counter;
230+
margin: mt(3);
231+
}
185232
}
186233
187234
&__table-container {

src/stories/components/DataTable.stories.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const Template = (args) => ({
5959
@customize-click="logCustomizeButtonClick"
6060
@update-fields-list="logUpdateCustomFields($event)"
6161
@cancel="logCancelClick"
62+
@search="logSearchInput"
6263
>
6364
</cds-data-table>
6465
<br>
@@ -73,6 +74,9 @@ export const Template = (args) => ({
7374
logUpdateCustomFields(event) {
7475
console.info('%cUpdate custom fields event: ', 'color:rgb(52, 207, 200);', event);
7576
},
77+
logSearchInput(event) {
78+
console.info('%cSearch input event: ', 'color:rgb(42, 124, 34);', event);
79+
},
7680
},
7781
updated() {
7882
console.info('%cv-model: ', 'color: #2C70CD;', this.selected);

src/tests/__snapshots__/DataTable.spec.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ exports[`DataTable > renders correctly 1`] = `
55
<div data-v-046d4556="" class="data-table">
66
<div data-v-046d4556="" class="data-table__header">
77
<div data-v-046d4556="" class="data-table__items-counter">200 registros encontrados</div>
8-
<cds-flexbox-stub data-v-046d4556="" direction="row" wrap="wrap" gap="3" justify="flex-start" align="center" tag="div" fluid="false"></cds-flexbox-stub>
8+
<cds-flexbox-stub data-v-046d4556="" direction="row" wrap="wrap" gap="3" justify="flex-end" align="center" tag="div" fluid="false" class="data-table__actions"></cds-flexbox-stub>
9+
<!--v-if-->
910
</div>
1011
<div data-v-046d4556="" class="data-table__table-container">
1112
<cds-table-stub data-v-046d4556="" modelvalue="" items="[object Object],[object Object]" fields="field1,field2,field3" hover="false" allowselection="false" selectionvariant="green" sortable="false" fixedheader="false" sortdesc="false" nowrap="false"></cds-table-stub>

0 commit comments

Comments
 (0)