@public-ui/sample-react 4.5.0-rc.3 → 4.5.0-rc.6
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 +8 -8
- package/src/components/button-link/routes.ts +0 -2
- package/src/components/table/action-columns-performance.tsx +2 -0
- package/src/components/table/action-columns.tsx +1 -1
- package/src/components/table/action-render.tsx +1 -1
- package/src/components/table/multi-sort.tsx +6 -0
- package/src/components/table/predefined-settings.tsx +0 -1
- package/src/components/table/render-cell.tsx +4 -4
- package/src/components/table/routes.ts +2 -0
- package/src/components/table/stateful-settings-persistence.tsx +0 -1
- package/src/components/table/stateless-with-selection.tsx +3 -4
- package/src/components/table/stateless-with-single-selection.tsx +3 -4
- package/src/components/table/stateless.tsx +4 -4
- package/src/components/table/variant.tsx +11 -9
- package/src/components/table/with-toolbar.tsx +204 -0
- package/src/components/button-link/image.tsx +0 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@public-ui/sample-react",
|
|
3
|
-
"version": "4.5.0-rc.
|
|
3
|
+
"version": "4.5.0-rc.6",
|
|
4
4
|
"description": "This app contains samples for the KoliBri/Public UI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "EUPL-1.2",
|
|
@@ -19,25 +19,25 @@
|
|
|
19
19
|
"tslib": "2.8.1",
|
|
20
20
|
"typescript": "5.9.3",
|
|
21
21
|
"world_countries_lists": "3.3.0",
|
|
22
|
-
"zod": "4.
|
|
23
|
-
"@public-ui/react-
|
|
24
|
-
"@public-ui/react-
|
|
22
|
+
"zod": "4.6.5",
|
|
23
|
+
"@public-ui/react-hook-form-adapter": "4.5.0-rc.6",
|
|
24
|
+
"@public-ui/react-v19": "4.5.0-rc.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "19.2.18",
|
|
28
28
|
"@types/react-dom": "19.2.5",
|
|
29
29
|
"adopted-style-sheets": "1.1.9-rc.25",
|
|
30
30
|
"eslint": "9.39.5",
|
|
31
|
-
"knip": "6.
|
|
31
|
+
"knip": "6.39.0",
|
|
32
32
|
"prettier": "3.9.9",
|
|
33
33
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
34
|
-
"stylelint": "17.
|
|
34
|
+
"stylelint": "17.16.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "19.2.8",
|
|
38
38
|
"react-dom": "19.2.8",
|
|
39
|
-
"react-router": "8.
|
|
40
|
-
"@public-ui/components": "4.5.0-rc.
|
|
39
|
+
"react-router": "8.4.0",
|
|
40
|
+
"@public-ui/components": "4.5.0-rc.6"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"assets",
|
|
@@ -2,13 +2,11 @@ import type { Routes } from '../../shares/types';
|
|
|
2
2
|
import { ButtonLinkAriaDescription } from './aria-description';
|
|
3
3
|
import { ButtonLinkBasic } from './basic';
|
|
4
4
|
import { ButtonLinkIcons } from './icons';
|
|
5
|
-
import { ButtonLinkImage } from './image';
|
|
6
5
|
|
|
7
6
|
export const BUTTON_LINK_ROUTES: Routes = {
|
|
8
7
|
'button-link': {
|
|
9
8
|
basic: ButtonLinkBasic,
|
|
10
9
|
icons: ButtonLinkIcons,
|
|
11
|
-
image: ButtonLinkImage,
|
|
12
10
|
'aria-description': ButtonLinkAriaDescription,
|
|
13
11
|
},
|
|
14
12
|
};
|
|
@@ -95,6 +95,7 @@ const HEADERS: { horizontal: KoliBriTableHeaderCellWithLogic[][] } = {
|
|
|
95
95
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
96
96
|
(data0 as unknown as DataRow).name.localeCompare((data1 as unknown as DataRow).name, 'de'),
|
|
97
97
|
sortDirection: 'ASC',
|
|
98
|
+
width: 250,
|
|
98
99
|
},
|
|
99
100
|
{
|
|
100
101
|
key: 'email',
|
|
@@ -103,6 +104,7 @@ const HEADERS: { horizontal: KoliBriTableHeaderCellWithLogic[][] } = {
|
|
|
103
104
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
104
105
|
(data0 as unknown as DataRow).email.localeCompare((data1 as unknown as DataRow).email, 'de'),
|
|
105
106
|
sortDirection: 'ASC',
|
|
107
|
+
width: 350,
|
|
106
108
|
},
|
|
107
109
|
{
|
|
108
110
|
key: 'status',
|
|
@@ -15,7 +15,7 @@ const HEADERS: { horizontal: KoliBriTableHeaderCellWithLogic[][] } = {
|
|
|
15
15
|
horizontal: [
|
|
16
16
|
[
|
|
17
17
|
{ key: 'id', label: 'ID', width: 80 },
|
|
18
|
-
{ key: 'project', label: 'Project' },
|
|
18
|
+
{ key: 'project', label: 'Project', width: 200 },
|
|
19
19
|
{ key: 'owner', label: 'Owner', width: 140 },
|
|
20
20
|
{
|
|
21
21
|
type: 'action',
|
|
@@ -14,7 +14,7 @@ type ProjectTask = {
|
|
|
14
14
|
const HEADERS: { horizontal: KoliBriTableHeaderCellWithLogic[][] } = {
|
|
15
15
|
horizontal: [
|
|
16
16
|
[
|
|
17
|
-
{ key: 'project', label: 'Project' },
|
|
17
|
+
{ key: 'project', label: 'Project', width: 200 },
|
|
18
18
|
{ key: 'owner', label: 'Owner', width: 140 },
|
|
19
19
|
{
|
|
20
20
|
label: 'ID',
|
|
@@ -59,6 +59,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
59
59
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
60
60
|
(data0 as BacklogEntry).assignee.localeCompare((data1 as BacklogEntry).assignee, 'de'),
|
|
61
61
|
sortDirection: 'ASC',
|
|
62
|
+
width: 200,
|
|
62
63
|
},
|
|
63
64
|
{
|
|
64
65
|
label: 'Department',
|
|
@@ -66,6 +67,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
66
67
|
|
|
67
68
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
68
69
|
(data0 as BacklogEntry).department.localeCompare((data1 as BacklogEntry).department, 'de'),
|
|
70
|
+
width: 200,
|
|
69
71
|
},
|
|
70
72
|
{
|
|
71
73
|
label: 'Priority',
|
|
@@ -75,6 +77,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
75
77
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
76
78
|
PRIORITY_ORDER[(data0 as BacklogEntry).priority] - PRIORITY_ORDER[(data1 as BacklogEntry).priority],
|
|
77
79
|
sortDirection: 'DESC',
|
|
80
|
+
width: 150,
|
|
78
81
|
},
|
|
79
82
|
{
|
|
80
83
|
label: 'Status',
|
|
@@ -83,6 +86,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
83
86
|
textAlign: 'center',
|
|
84
87
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) =>
|
|
85
88
|
STATUS_ORDER[(data0 as BacklogEntry).status] - STATUS_ORDER[(data1 as BacklogEntry).status],
|
|
89
|
+
width: 150,
|
|
86
90
|
},
|
|
87
91
|
{
|
|
88
92
|
label: 'Open tickets',
|
|
@@ -90,6 +94,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
90
94
|
|
|
91
95
|
textAlign: 'right',
|
|
92
96
|
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) => (data0 as BacklogEntry).openTickets - (data1 as BacklogEntry).openTickets,
|
|
97
|
+
width: 100,
|
|
93
98
|
},
|
|
94
99
|
{
|
|
95
100
|
label: 'Last updated',
|
|
@@ -102,6 +107,7 @@ const TABLE_HEADER_CELLS: KoliBriTableHeaderCellWithLogic[] = [
|
|
|
102
107
|
else if ((data1 as BacklogEntry).date < (data0 as BacklogEntry).date) return 1;
|
|
103
108
|
else return 0;
|
|
104
109
|
},
|
|
110
|
+
width: 150,
|
|
105
111
|
},
|
|
106
112
|
];
|
|
107
113
|
|
|
@@ -85,7 +85,7 @@ const HEADERS: KoliBriTableHeaders = {
|
|
|
85
85
|
{
|
|
86
86
|
label: 'Date (string)',
|
|
87
87
|
key: 'date',
|
|
88
|
-
width:
|
|
88
|
+
width: 150,
|
|
89
89
|
textAlign: 'center',
|
|
90
90
|
|
|
91
91
|
/* Example 3: Render function using innerHTML. ⚠️Make sure to sanitize data to avoid XSS. */
|
|
@@ -98,7 +98,7 @@ const HEADERS: KoliBriTableHeaders = {
|
|
|
98
98
|
{
|
|
99
99
|
label: 'Action (react)',
|
|
100
100
|
key: 'action',
|
|
101
|
-
width:
|
|
101
|
+
width: 250,
|
|
102
102
|
|
|
103
103
|
/* Example 4: Render function using React */
|
|
104
104
|
render: (el) => {
|
|
@@ -108,8 +108,8 @@ const HEADERS: KoliBriTableHeaders = {
|
|
|
108
108
|
display: `grid`,
|
|
109
109
|
gridAutoFlow: `column`,
|
|
110
110
|
alignItems: `end`,
|
|
111
|
-
gap: `
|
|
112
|
-
|
|
111
|
+
gap: `4px`,
|
|
112
|
+
width: `190px`,
|
|
113
113
|
}}
|
|
114
114
|
>
|
|
115
115
|
<KolInputText _label="Input" />
|
|
@@ -35,6 +35,7 @@ import { TableStickyHeader } from './sticky-header';
|
|
|
35
35
|
import { TableVariant } from './variant';
|
|
36
36
|
import { TableWithFooter } from './with-footer';
|
|
37
37
|
import { TableWithPagination } from './with-pagination';
|
|
38
|
+
import { TableWithToolbar } from './with-toolbar';
|
|
38
39
|
|
|
39
40
|
export const TABLE_ROUTES: Routes = {
|
|
40
41
|
table: {
|
|
@@ -70,6 +71,7 @@ export const TABLE_ROUTES: Routes = {
|
|
|
70
71
|
'sticky-header': TableStickyHeader,
|
|
71
72
|
'with-footer': TableWithFooter,
|
|
72
73
|
'with-pagination': TableWithPagination,
|
|
74
|
+
'with-toolbar': TableWithToolbar,
|
|
73
75
|
big: TableBig,
|
|
74
76
|
'action-and-render': TableActionAndRenderColumns,
|
|
75
77
|
variant: TableVariant,
|
|
@@ -79,9 +79,9 @@ export const TableStatelessWithSelection: FC = () => {
|
|
|
79
79
|
_headers={{
|
|
80
80
|
horizontal: [
|
|
81
81
|
[
|
|
82
|
-
{ key: 'id', label: '#ID', textAlign: 'left' },
|
|
83
|
-
{ key: 'name', label: 'Name', textAlign: 'left' },
|
|
84
|
-
{ key: 'action', label: 'Action', textAlign: 'left', render: renderButton },
|
|
82
|
+
{ key: 'id', label: '#ID', textAlign: 'left', width: 70 },
|
|
83
|
+
{ key: 'name', label: 'Name', textAlign: 'left', width: 200 },
|
|
84
|
+
{ key: 'action', label: 'Action', textAlign: 'left', render: renderButton, width: 100 },
|
|
85
85
|
],
|
|
86
86
|
],
|
|
87
87
|
}}
|
|
@@ -89,7 +89,6 @@ export const TableStatelessWithSelection: FC = () => {
|
|
|
89
89
|
_selection={selection}
|
|
90
90
|
_on={{ onSelectionChange: handleSelectionChangeCallback }}
|
|
91
91
|
className="block"
|
|
92
|
-
style={{ maxWidth: '600px' }}
|
|
93
92
|
ref={kolTableStatelessRef}
|
|
94
93
|
/>
|
|
95
94
|
</SampleBlock>
|
|
@@ -79,9 +79,9 @@ export const TableStatelessWithSingleSelection: FC = () => {
|
|
|
79
79
|
_headers={{
|
|
80
80
|
horizontal: [
|
|
81
81
|
[
|
|
82
|
-
{ key: 'id', label: '#ID', textAlign: 'left' },
|
|
83
|
-
{ key: 'name', label: 'Name', textAlign: 'left' },
|
|
84
|
-
{ key: 'action', label: 'Action', textAlign: 'left', render: renderButton },
|
|
82
|
+
{ key: 'id', label: '#ID', textAlign: 'left', width: 100 },
|
|
83
|
+
{ key: 'name', label: 'Name', textAlign: 'left', width: 200 },
|
|
84
|
+
{ key: 'action', label: 'Action', textAlign: 'left', render: renderButton, width: 200 },
|
|
85
85
|
],
|
|
86
86
|
],
|
|
87
87
|
}}
|
|
@@ -89,7 +89,6 @@ export const TableStatelessWithSingleSelection: FC = () => {
|
|
|
89
89
|
_selection={selection}
|
|
90
90
|
_on={{ onSelectionChange: handleSelectionChangeCallback }}
|
|
91
91
|
className="block"
|
|
92
|
-
style={{ maxWidth: '600px' }}
|
|
93
92
|
ref={kolTableStatelessRef}
|
|
94
93
|
/>
|
|
95
94
|
</SampleBlock>
|
|
@@ -18,10 +18,10 @@ export const TableStateless: FC = () => (
|
|
|
18
18
|
_headers={{
|
|
19
19
|
horizontal: [
|
|
20
20
|
[
|
|
21
|
-
{ key: 'left', label: 'left', textAlign: 'left', sortDirection: 'ASC' },
|
|
22
|
-
{ key: 'center', label: 'center', textAlign: 'center', sortDirection: 'DESC' },
|
|
23
|
-
{ key: 'right', label: 'right', textAlign: 'right', sortDirection: 'NOS' },
|
|
24
|
-
{ key: 'nosort', label: 'no sort option' },
|
|
21
|
+
{ key: 'left', label: 'left', textAlign: 'left', sortDirection: 'ASC', width: 100 },
|
|
22
|
+
{ key: 'center', label: 'center', textAlign: 'center', sortDirection: 'DESC', width: 100 },
|
|
23
|
+
{ key: 'right', label: 'right', textAlign: 'right', sortDirection: 'NOS', width: 100 },
|
|
24
|
+
{ key: 'nosort', label: 'no sort option', width: 150 },
|
|
25
25
|
],
|
|
26
26
|
],
|
|
27
27
|
vertical: [
|
|
@@ -34,12 +34,14 @@ export const TableVariant: FC = () => {
|
|
|
34
34
|
<p>This sample shows KolTableStateful with different variants controlled by the theme.</p>
|
|
35
35
|
</SampleDescription>
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
{!Array.isArray(tableVariants) || tableVariants.length === 0 ? (
|
|
38
|
+
<SampleBlock id="variant-no">
|
|
39
39
|
<p>This theme has no variants for tables.</p>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
</SampleBlock>
|
|
41
|
+
) : (
|
|
42
|
+
tableVariants.map((element, index) => {
|
|
43
|
+
return (
|
|
44
|
+
<SampleBlock id={'variant-' + index} className="w-full flex flex-col gap-14">
|
|
43
45
|
<KolTableStateful
|
|
44
46
|
_label={'Table with variant: ' + element}
|
|
45
47
|
_data={DATA}
|
|
@@ -56,10 +58,10 @@ export const TableVariant: FC = () => {
|
|
|
56
58
|
_paginationPosition="bottom"
|
|
57
59
|
_variant={element}
|
|
58
60
|
></KolTableStateful>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
|
|
61
|
+
</SampleBlock>
|
|
62
|
+
);
|
|
63
|
+
})
|
|
64
|
+
)}
|
|
63
65
|
</div>
|
|
64
66
|
);
|
|
65
67
|
};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { KoliBriTableDataType, KoliBriTableHeaderCellWithLogic, KoliBriTableSelection, ToolbarItemsPropType } from '@public-ui/components';
|
|
2
|
+
import { KolButton, KolDrawer, KolInputCheckbox, KolInputText, KolTableStateful, KolToolbar } from '@public-ui/react-v19';
|
|
3
|
+
import type { FC } from 'react';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { SampleDescription } from '../SampleDescription';
|
|
6
|
+
|
|
7
|
+
type DataRow = {
|
|
8
|
+
id: number;
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const DATA: DataRow[] = [
|
|
14
|
+
{ id: 1001, name: 'Max Mustermann', email: 'max.mustermann@example.com' },
|
|
15
|
+
{ id: 1002, name: 'Erika Musterfrau', email: 'erika.musterfrau@example.com' },
|
|
16
|
+
{ id: 1003, name: 'John Doe', email: 'john.doe@example.com' },
|
|
17
|
+
{ id: 1004, name: 'Jane Doe', email: 'jane.doe@example.com' },
|
|
18
|
+
{ id: 1005, name: 'Peter Smith', email: 'peter.smith@example.com' },
|
|
19
|
+
{ id: 1006, name: 'Anna Smith', email: 'anna.smith@example.com' },
|
|
20
|
+
{ id: 1007, name: 'Michael Schmidt', email: 'michael.schmidt@example.com' },
|
|
21
|
+
{ id: 1008, name: 'Sarah Schmidt', email: 'sarah.schmidt@example.com' },
|
|
22
|
+
{ id: 1009, name: 'Thomas Müller', email: 'thomas.mueller@example.com' },
|
|
23
|
+
{ id: 1010, name: 'Lisa Müller', email: 'lisa.mueller@example.com' },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const HEADERS: { horizontal: KoliBriTableHeaderCellWithLogic[][] } = {
|
|
27
|
+
horizontal: [
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
key: 'id',
|
|
31
|
+
label: 'ID',
|
|
32
|
+
textAlign: 'left',
|
|
33
|
+
width: 80,
|
|
34
|
+
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) => (data0 as DataRow).id - (data1 as DataRow).id,
|
|
35
|
+
sortDirection: 'ASC',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: 'name',
|
|
39
|
+
label: 'Name',
|
|
40
|
+
textAlign: 'left',
|
|
41
|
+
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) => (data0 as DataRow).name.localeCompare((data1 as DataRow).name, 'en'),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: 'email',
|
|
45
|
+
label: 'Email',
|
|
46
|
+
textAlign: 'left',
|
|
47
|
+
compareFn: (data0: KoliBriTableDataType, data1: KoliBriTableDataType) => (data0 as DataRow).email.localeCompare((data1 as DataRow).email, 'en'),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const FIRST_NAMES = ['Ada', 'Bruno', 'Clara', 'Finn', 'Ida', 'Jonas', 'Lena', 'Nele', 'Otto', 'Sina'];
|
|
54
|
+
const LAST_NAMES = ['Bauer', 'Fuchs', 'Hirsch', 'Kraft', 'Lindner', 'Moor', 'Reuter', 'Schubert', 'Wagner', 'Winter'];
|
|
55
|
+
|
|
56
|
+
function pick<T>(values: T[]): T {
|
|
57
|
+
return values[Math.floor(Math.random() * values.length)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function nextId(rows: DataRow[]): number {
|
|
61
|
+
return rows.reduce((max, row) => Math.max(max, row.id), 1000) + 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createDummyRow(id: number): DataRow {
|
|
65
|
+
const firstName = pick(FIRST_NAMES);
|
|
66
|
+
const lastName = pick(LAST_NAMES);
|
|
67
|
+
return {
|
|
68
|
+
id,
|
|
69
|
+
name: `${firstName} ${lastName}`,
|
|
70
|
+
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const TableWithToolbar: FC = () => {
|
|
75
|
+
const [dataRows, setDataRows] = useState<DataRow[]>(DATA);
|
|
76
|
+
/** Keys (`DataRow.id`) of all selected rows. */
|
|
77
|
+
const [selectedKeys, setSelectedKeys] = useState<number[]>([]);
|
|
78
|
+
const [isMultiple, setIsMultiple] = useState(false);
|
|
79
|
+
/** The form is open while a draft exists; a draft whose ID already exists edits that row. */
|
|
80
|
+
const [draft, setDraft] = useState<DataRow | null>(null);
|
|
81
|
+
|
|
82
|
+
const isEditing = draft !== null && dataRows.some((row) => row.id === draft.id);
|
|
83
|
+
|
|
84
|
+
const selection: KoliBriTableSelection = {
|
|
85
|
+
keyPropertyName: 'id',
|
|
86
|
+
label: (row) => `Select row ${(row as DataRow).name}`,
|
|
87
|
+
multiple: isMultiple,
|
|
88
|
+
selectedKeys,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleSelectionChange = (_event: Event, selectedRows: KoliBriTableDataType[] | null) => {
|
|
92
|
+
setSelectedKeys((selectedRows ?? []).map((row) => (row as DataRow).id));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handleSelectionModeSwitch = (_event: Event, value: unknown) => {
|
|
96
|
+
setIsMultiple(value === true);
|
|
97
|
+
/* A multiple selection does not fit the single selection mode. */
|
|
98
|
+
if (value !== true && selectedKeys.length > 1) {
|
|
99
|
+
setSelectedKeys([]);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const openAddDrawer = () => {
|
|
104
|
+
setDraft(createDummyRow(nextId(dataRows)));
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const editSelectedRow = () => {
|
|
108
|
+
const selectedRow = dataRows.find((row) => row.id === selectedKeys[0]);
|
|
109
|
+
if (selectedRow !== undefined) {
|
|
110
|
+
setDraft({ ...selectedRow });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const closeDrawer = () => {
|
|
115
|
+
setDraft(null);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const saveDraft = () => {
|
|
119
|
+
if (draft !== null) {
|
|
120
|
+
setDataRows((rows) => (isEditing ? rows.map((row) => (row.id === draft.id ? draft : row)) : [...rows, draft]));
|
|
121
|
+
}
|
|
122
|
+
setDraft(null);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const deleteSelectedRows = () => {
|
|
126
|
+
if (selectedKeys.length === 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
setDataRows(dataRows.filter((row) => !selectedKeys.includes(row.id)));
|
|
130
|
+
setSelectedKeys([]);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const toolbarItems: ToolbarItemsPropType = [
|
|
134
|
+
{
|
|
135
|
+
type: 'button',
|
|
136
|
+
_label: 'Add',
|
|
137
|
+
_icons: { left: { icon: 'kolicon-plus' } },
|
|
138
|
+
_variant: 'primary',
|
|
139
|
+
_on: { onClick: openAddDrawer },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: 'button',
|
|
143
|
+
_label: 'Edit',
|
|
144
|
+
_variant: 'secondary',
|
|
145
|
+
_disabled: selectedKeys.length !== 1,
|
|
146
|
+
_on: { onClick: editSelectedRow },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'button',
|
|
150
|
+
_label: 'Delete',
|
|
151
|
+
_icons: { left: { icon: 'kolicon-cross' } },
|
|
152
|
+
_variant: 'danger',
|
|
153
|
+
_disabled: selectedKeys.length === 0,
|
|
154
|
+
_on: { onClick: deleteSelectedRows },
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<>
|
|
160
|
+
<SampleDescription>
|
|
161
|
+
<p>
|
|
162
|
+
This sample combines a toolbar with a table: a switch toggles between single and multiple selection. "Add" generates a new dummy record in a form and
|
|
163
|
+
inserts it via "Create". "Edit" opens the selected row in the same form when exactly one row is selected. "Delete" removes all selected rows and is
|
|
164
|
+
only enabled with a selection.
|
|
165
|
+
</p>
|
|
166
|
+
</SampleDescription>
|
|
167
|
+
|
|
168
|
+
<section className="w-full">
|
|
169
|
+
<KolToolbar _label="Table actions" _items={toolbarItems} />
|
|
170
|
+
|
|
171
|
+
<KolInputCheckbox
|
|
172
|
+
className="block w-fit py-2"
|
|
173
|
+
_label="Multiple selection"
|
|
174
|
+
_variant="switch"
|
|
175
|
+
_checked={isMultiple}
|
|
176
|
+
_value={true}
|
|
177
|
+
_on={{ onInput: handleSelectionModeSwitch }}
|
|
178
|
+
/>
|
|
179
|
+
|
|
180
|
+
<KolDrawer _label={isEditing ? 'Edit entry' : 'Add entry'} _align="right" _level={2} _open={draft !== null} _hasCloser _on={{ onClose: closeDrawer }}>
|
|
181
|
+
{draft !== null && (
|
|
182
|
+
<div className="flex flex-col gap-4 py-4">
|
|
183
|
+
<KolInputText _label="Name" _value={draft.name} _on={{ onInput: (_event, value) => setDraft({ ...draft, name: String(value) }) }} />
|
|
184
|
+
<KolInputText _label="Email" _value={draft.email} _on={{ onInput: (_event, value) => setDraft({ ...draft, email: String(value) }) }} />
|
|
185
|
+
<div className="flex flex-wrap gap-2">
|
|
186
|
+
<KolButton _label={isEditing ? 'Save' : 'Create'} _variant="primary" _on={{ onClick: saveDraft }} />
|
|
187
|
+
<KolButton _label="Cancel" _variant="secondary" _on={{ onClick: closeDrawer }} />
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
</KolDrawer>
|
|
192
|
+
|
|
193
|
+
<KolTableStateful
|
|
194
|
+
_label="User management"
|
|
195
|
+
_headers={HEADERS}
|
|
196
|
+
_data={dataRows}
|
|
197
|
+
className="block"
|
|
198
|
+
_selection={selection}
|
|
199
|
+
_on={{ onSelectionChange: handleSelectionChange }}
|
|
200
|
+
/>
|
|
201
|
+
</section>
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { KolButtonLink, KolImage } from '@public-ui/react-v19';
|
|
4
|
-
|
|
5
|
-
import type { FC } from 'react';
|
|
6
|
-
import { SampleBlock } from '../SampleBlock';
|
|
7
|
-
import { SampleDescription } from '../SampleDescription';
|
|
8
|
-
|
|
9
|
-
export const ButtonLinkImage: FC = () => (
|
|
10
|
-
<>
|
|
11
|
-
<SampleDescription>
|
|
12
|
-
<p>This sample shows KolButtonLink with slot-content instead of a label. The sample uses an image as content.</p>
|
|
13
|
-
</SampleDescription>
|
|
14
|
-
|
|
15
|
-
<SampleBlock id="image">
|
|
16
|
-
<KolButtonLink _label="I am a link that is rendered as text" />
|
|
17
|
-
<KolButtonLink _label="">
|
|
18
|
-
<KolImage
|
|
19
|
-
_alt="KoliBri design system illustration showing three people working on laptops surrounded by UI components, charts, and the KoliBri hummingbird logo"
|
|
20
|
-
_src="sample-image.png"
|
|
21
|
-
className="w-image"
|
|
22
|
-
slot="expert"
|
|
23
|
-
/>
|
|
24
|
-
</KolButtonLink>
|
|
25
|
-
</SampleBlock>
|
|
26
|
-
</>
|
|
27
|
-
);
|