|
| 1 | + |
| 2 | +### Full example |
| 3 | +Full fledged table: |
| 4 | +```js |
| 5 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS, TABLE_MOCK_FILTER } = require('./src/mocks/Table.mock.js'); |
| 6 | + |
| 7 | +const [sorting, setSorting] = React.useState(); |
| 8 | +const [pagination, setPagination] = React.useState({ |
| 9 | + itemsPerPage: 10, |
| 10 | + totalItems: 1829, |
| 11 | + currentPage: 1 |
| 12 | +}); |
| 13 | + |
| 14 | +<Table |
| 15 | + tableId="1" |
| 16 | + columns={TABLE_MOCK_COLUMNS()} |
| 17 | + rows={TABLE_MOCK_ROWS.slice(0, 10)} |
| 18 | + filters={TABLE_MOCK_FILTER} |
| 19 | + sorting={sorting} |
| 20 | + sortingChanged={(e) => console.log('sorting changed', e) || setSorting(e)} |
| 21 | + paginationChanged={(e) => console.log('pagination changed', e) || setPagination(e)} |
| 22 | + filtersChanged={(e) => console.log('filters changed', e)} |
| 23 | + itemsPerPage={pagination.itemsPerPage} |
| 24 | + totalItems={pagination.totalItems} |
| 25 | + currentPage={pagination.currentPage} |
| 26 | +/> |
| 27 | +``` |
| 28 | + |
| 29 | +### Filter examples |
| 30 | +Filters values: |
| 31 | + |
| 32 | +| Key | Value | Description | |
| 33 | +|-------------|-----------------------------------------------------------|------------------------------------------------------------------| |
| 34 | +| id | _string_ | ID to identify the filter when returning data | |
| 35 | +| display | "generic" / "optional" | "generic" to show as the main filter, "optional" if the filter should appear under the extra filter dropdown | |
| 36 | +| type | "input" / "datepicker" / "select" / "telephone-number" | Type of field to show | |
| 37 | +| label | _string_ | Label of the field | |
| 38 | +| placeholder | _string_ | Placeholder of the field | |
| 39 | +| options | _{ id: string; label: string; }[]_ | Options to use if "select" type | |
| 40 | + |
| 41 | +Table with only 1 `generic` filter: |
| 42 | +```js static |
| 43 | +const FILTERS = [{ |
| 44 | + id: "smartfilter", |
| 45 | + display: "generic", |
| 46 | + type: "input", |
| 47 | + label: "Zoek op voornaam", |
| 48 | + placeholder: "Zoek op voornaam", |
| 49 | +}] |
| 50 | +``` |
| 51 | + |
| 52 | +```js |
| 53 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS, TABLE_MOCK_FILTER } = require('./src/mocks/Table.mock.js'); |
| 54 | + |
| 55 | +<Table |
| 56 | + tableId="1" |
| 57 | + columns={TABLE_MOCK_COLUMNS()} |
| 58 | + rows={TABLE_MOCK_ROWS.slice(0, 2)} |
| 59 | + filters={[{ |
| 60 | + id: "smartfilter", |
| 61 | + display: "generic", |
| 62 | + type: "input", |
| 63 | + label: "Zoek op voornaam", |
| 64 | + placeholder: "Zoek op voornaam", |
| 65 | + }]} |
| 66 | +/> |
| 67 | +``` |
| 68 | + |
| 69 | +Only optional filters: |
| 70 | +```js static |
| 71 | +const FILTERS = [{ |
| 72 | + id: "firstName", |
| 73 | + type: "input", |
| 74 | + label: "Zoek op voornaam", |
| 75 | + placeholder: "Zoek op voornaam", |
| 76 | +}, { |
| 77 | + id: "lastName", |
| 78 | + type: "input", |
| 79 | + label: "Zoek op achternaam", |
| 80 | + placeholder: "Zoek op achternaam", |
| 81 | +}] |
| 82 | +``` |
| 83 | + |
| 84 | +```js |
| 85 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS, TABLE_MOCK_FILTER } = require('./src/mocks/Table.mock.js'); |
| 86 | + |
| 87 | +<Table |
| 88 | + tableId="1" |
| 89 | + columns={TABLE_MOCK_COLUMNS()} |
| 90 | + rows={TABLE_MOCK_ROWS.slice(0, 2)} |
| 91 | + filters={[{ |
| 92 | + id: "firstName", |
| 93 | + type: "input", |
| 94 | + label: "Zoek op voornaam", |
| 95 | + placeholder: "Zoek op voornaam", |
| 96 | + }, { |
| 97 | + id: "lastName", |
| 98 | + type: "input", |
| 99 | + label: "Zoek op achternaam", |
| 100 | + placeholder: "Zoek op achternaam", |
| 101 | + }]} |
| 102 | +/> |
| 103 | +``` |
| 104 | + |
| 105 | +### State examples |
| 106 | +Loading table |
| 107 | +```js |
| 108 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS } = require('./src/mocks/Table.mock.js'); |
| 109 | + |
| 110 | +<Table tableId="2" columns={TABLE_MOCK_COLUMNS()} rows={TABLE_MOCK_ROWS.slice(0, 5)} loading={true} /> |
| 111 | +``` |
| 112 | + |
| 113 | +Without column sorting |
| 114 | +```js |
| 115 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS } = require('./src/mocks/Table.mock.js'); |
| 116 | + |
| 117 | +<Table tableId="2" columns={TABLE_MOCK_COLUMNS()} rows={TABLE_MOCK_ROWS.slice(0, 2)} disableColumnSorting={true} /> |
| 118 | +``` |
| 119 | + |
| 120 | +Styles |
| 121 | +```js |
| 122 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS } = require('./src/mocks/Table.mock.js'); |
| 123 | + |
| 124 | +<> |
| 125 | + <div className="u-margin-bottom"> |
| 126 | + <Table tableId="3" columns={TABLE_MOCK_COLUMNS()} rows={TABLE_MOCK_ROWS.slice(0, 4)} striped={false} /> |
| 127 | + </div> |
| 128 | + |
| 129 | + <div className="u-margin-bottom"> |
| 130 | + <Table tableId="4" columns={TABLE_MOCK_COLUMNS()} rows={TABLE_MOCK_ROWS.slice(0, 2)} type="primary" /> |
| 131 | + </div> |
| 132 | + |
| 133 | + <Table tableId="5" columns={TABLE_MOCK_COLUMNS()} rows={TABLE_MOCK_ROWS.slice(0, 2)} type="secondary" /> |
| 134 | +</> |
| 135 | +``` |
| 136 | + |
| 137 | +Extra table actions |
| 138 | +```js |
| 139 | +const { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_FILTER } = require('./src/mocks/Table.mock.js'); |
| 140 | +const Button = require('../button').default; |
| 141 | + |
| 142 | +<Table |
| 143 | + tableId="5" |
| 144 | + columns={TABLE_MOCK_COLUMNS()} |
| 145 | + rows={TABLE_MOCK_ROWS.slice(0, 2)} |
| 146 | + extraTableActions={( |
| 147 | + <Button icon="ai-pencil-1" className="u-margin-right-xs" /> |
| 148 | + )} |
| 149 | + filters={TABLE_MOCK_FILTER} |
| 150 | +/> |
| 151 | +``` |
0 commit comments