@stack-spot/citric-react 0.32.0 → 0.34.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/dist/components/Link.d.ts +7 -1
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +2 -2
- package/dist/components/Link.js.map +1 -1
- package/dist/components/SmartTable.d.ts +13 -27
- package/dist/components/SmartTable.d.ts.map +1 -1
- package/dist/components/SmartTable.js +13 -4
- package/dist/components/SmartTable.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Link.tsx +8 -2
- package/src/components/SmartTable.tsx +25 -33
|
@@ -14,6 +14,12 @@ export interface BaseLinkProps extends WithColor {
|
|
|
14
14
|
* @default false
|
|
15
15
|
*/
|
|
16
16
|
metadata?: any;
|
|
17
|
+
/**
|
|
18
|
+
* Whether or not to underline the link.
|
|
19
|
+
*
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
underline?: boolean;
|
|
17
23
|
}
|
|
18
24
|
export type LinkProps = React.JSX.IntrinsicElements['a'] & BaseLinkProps;
|
|
19
25
|
/**
|
|
@@ -22,5 +28,5 @@ export type LinkProps = React.JSX.IntrinsicElements['a'] & BaseLinkProps;
|
|
|
22
28
|
* Whenever a link is clicked, the function `onClickLink` of the nearest CitricController is called with the event and the value of the
|
|
23
29
|
* prop `metadata`.
|
|
24
30
|
*/
|
|
25
|
-
export declare const Link: ({ appearance, color, style, className, children, onClick, metadata, ...props }: LinkProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export declare const Link: ({ appearance, color, style, className, children, onClick, metadata, underline, ...props }: LinkProps) => import("react/jsx-runtime").JSX.Element;
|
|
26
32
|
//# sourceMappingURL=Link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/components/Link.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKpD,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/components/Link.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKpD,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,aAAa,CAAA;AAExE;;;;;GAKG;AACH,eAAO,MAAM,IAAI,8FAAuG,SAAS,4CAe/H,CAAA"}
|
package/dist/components/Link.js
CHANGED
|
@@ -9,11 +9,11 @@ import { asCitricProps, CitricComponent } from './CitricComponent.js';
|
|
|
9
9
|
* Whenever a link is clicked, the function `onClickLink` of the nearest CitricController is called with the event and the value of the
|
|
10
10
|
* prop `metadata`.
|
|
11
11
|
*/
|
|
12
|
-
export const Link = withRef(({ appearance, color, style, className, children, onClick, metadata, ...props }) => {
|
|
12
|
+
export const Link = withRef(({ appearance, color, style, className, children, onClick, metadata, underline, ...props }) => {
|
|
13
13
|
const citric = useCitricController();
|
|
14
14
|
const linkProps = {
|
|
15
15
|
component: 'link',
|
|
16
|
-
style: applyColor(style, color),
|
|
16
|
+
style: applyColor({ ...style, textDecoration: underline ? undefined : 'none' }, color),
|
|
17
17
|
className: applyTextAppearance(className, appearance),
|
|
18
18
|
onClick: (e) => {
|
|
19
19
|
onClick?.(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/components/Link.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../src/components/Link.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AA2BlE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,EAAa,EAAE,EAAE;IACnI,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAA;IACpC,MAAM,SAAS,GAAG;QAChB,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE,UAAU,CAAC,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC;QACtF,SAAS,EAAE,mBAAmB,CAAC,SAAS,EAAE,UAAU,CAAC;QACrD,OAAO,EAAE,CAAC,CAAsC,EAAE,EAAE;YAClD,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;YACZ,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,QAAQ,IAAI,KAAK,CAAC,CAAA;QAC7C,CAAC;QACD,GAAG,KAAK;KACA,CAAA;IACV,OAAO,MAAM,EAAE,UAAU;QACvB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC,KAAC,eAAe,IAAC,GAAG,EAAC,GAAG,KAAK,SAAS,YAAG,QAAQ,GAAmB,CAAA;AAC1E,CAAC,CAAC,CAAA"}
|
|
@@ -86,39 +86,25 @@ interface ExtraSmartTableProps<T extends Record<string, any>> {
|
|
|
86
86
|
*/
|
|
87
87
|
headless?: boolean;
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* Making a row clickable is not accessible, i.e. it creates an unfriendly UI for people who rely on assistive technologies.
|
|
90
90
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
91
|
+
* Instead you should place the action in an element inside the row, e.g. an anchor or a button.
|
|
92
|
+
*
|
|
93
|
+
* For users who don't rely on assistive technologies we may still want the click on the row to mimic the behavior of the element with
|
|
94
|
+
* the actual action. This property does exactly this!
|
|
95
|
+
*
|
|
96
|
+
* The value of this property must be a CSS selector relative to this row, it must refer to the element with the click listener that
|
|
97
|
+
* should be triggered when this row is clicked.
|
|
98
|
+
*
|
|
99
|
+
* When this property is set, the row cursor becomes a pointer.
|
|
94
100
|
*
|
|
95
101
|
* @example
|
|
96
102
|
*
|
|
97
103
|
* ```
|
|
98
|
-
*
|
|
99
|
-
* onClick: item => console.log(item),
|
|
100
|
-
* description: 'log the item to the console',
|
|
101
|
-
* }}
|
|
104
|
+
* rowClickElement="a" // the first anchor element inside the row will be triggered when the row is clicked.
|
|
102
105
|
* ```
|
|
103
106
|
*/
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Function to run when the row is clicked. Receives the item corresponding to the row as the first parameter and the click event as the
|
|
107
|
-
* second.
|
|
108
|
-
* @param item
|
|
109
|
-
* @param event
|
|
110
|
-
*/
|
|
111
|
-
onClick: (item: T, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
|
|
112
|
-
/**
|
|
113
|
-
* A description of the action clicking the row does. Can be either a static string or a function that receives the item and returns the
|
|
114
|
-
* description.
|
|
115
|
-
*
|
|
116
|
-
* This is required for addressing accessibility.
|
|
117
|
-
*/
|
|
118
|
-
description: string | ((item: T) => string);
|
|
119
|
-
};
|
|
120
|
-
tabIndex?: number;
|
|
121
|
-
'aria-label'?: string;
|
|
107
|
+
rowClickElement?: string;
|
|
122
108
|
}
|
|
123
109
|
export type BaseSmartTableProps<T extends Record<string, any>> = BaseTableProps & ExtraSmartTableProps<T>;
|
|
124
110
|
export type SmartTableProps<T extends Record<string, any>> = Omit<TableProps, 'children'> & ExtraSmartTableProps<T>;
|
|
@@ -157,6 +143,6 @@ export type SmartTableProps<T extends Record<string, any>> = Omit<TableProps, 'c
|
|
|
157
143
|
* return <SmartTable data={data} columns={columns} />
|
|
158
144
|
* ```
|
|
159
145
|
*/
|
|
160
|
-
export declare const SmartTable: <T extends Record<string, any>>({ data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id,
|
|
146
|
+
export declare const SmartTable: <T extends Record<string, any>>({ data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id, rowClickElement, headless, ...props }: SmartTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
161
147
|
export {};
|
|
162
148
|
//# sourceMappingURL=SmartTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTable.d.ts","sourceRoot":"","sources":["../../src/components/SmartTable.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAS,UAAU,EAAU,MAAM,SAAS,CAAA;AAErF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,KA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e,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,cAAc,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAEzG,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAanH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,UAAU,GACD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,6HAE9C,eAAe,CAAC,CAAC,CAAC,4CA4DtB,CAAA"}
|
|
@@ -3,6 +3,17 @@ import { createElement as _createElement } from "react";
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { withRef } from '../utils/react.js';
|
|
5
5
|
import { Table, Th, Tr } from './Table.js';
|
|
6
|
+
function createRowClickListener(elementQuerySelector) {
|
|
7
|
+
return (event) => {
|
|
8
|
+
const target = event.target instanceof HTMLElement ? event.target : undefined;
|
|
9
|
+
const row = target instanceof HTMLTableRowElement ? target : target?.closest('tr');
|
|
10
|
+
if (row) {
|
|
11
|
+
const element = row.querySelector(elementQuerySelector);
|
|
12
|
+
if (element instanceof HTMLElement)
|
|
13
|
+
element.click();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
6
17
|
/**
|
|
7
18
|
* Renders a table. Always prefer using this component over the raw Table component.
|
|
8
19
|
*
|
|
@@ -38,15 +49,13 @@ import { Table, Th, Tr } from './Table.js';
|
|
|
38
49
|
* return <SmartTable data={data} columns={columns} />
|
|
39
50
|
* ```
|
|
40
51
|
*/
|
|
41
|
-
export const SmartTable = withRef(function SmartTable({ data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id,
|
|
52
|
+
export const SmartTable = withRef(function SmartTable({ data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id, rowClickElement, headless, ...props }) {
|
|
42
53
|
id = useMemo(() => id || `${Math.random()}`, [id]);
|
|
43
54
|
const headers = useMemo(() => headless ? [] : columns.map((c) => (_createElement(Th, { ...c.th, key: c.key, onSort: c.onSort, direction: c.direction, tabIndex: c.onSort ? 0 : undefined }, c.label ?? c.key))), [columns, headless]);
|
|
44
55
|
const rows = useMemo(() => data.map((item, index) => {
|
|
45
56
|
const key = keygen ? keygen(item) : index;
|
|
46
57
|
const accordionContent = renderAccordion?.(item);
|
|
47
|
-
const row = (_jsxs(Tr, { accordionTrigger: accordionContent ? accordionTrigger : undefined, onClick:
|
|
48
|
-
? (typeof rowClick.description === 'function' ? rowClick.description(item) : rowClick.description)
|
|
49
|
-
: undefined, children: [columns.map(c => _createElement("td", { ...c.td, key: c.key }, c.render ? c.render(item) : (item[c.key] || ''))), renderAccordion && (_jsx("td", { children: accordionContent && (_jsx("input", { type: "checkbox", "aria-controls": `${id}-${key}`, onKeyDown: e => e.key === 'Enter' && e.target instanceof HTMLElement && e.target.click() })) }))] }, key));
|
|
58
|
+
const row = (_jsxs(Tr, { accordionTrigger: accordionContent ? accordionTrigger : undefined, onClick: rowClickElement ? createRowClickListener(rowClickElement) : undefined, children: [columns.map(c => _createElement("td", { ...c.td, key: c.key }, c.render ? c.render(item) : (item[c.key] || ''))), renderAccordion && (_jsx("td", { children: accordionContent && (_jsx("input", { type: "checkbox", "aria-controls": `${id}-${key}`, onKeyDown: e => e.key === 'Enter' && e.target instanceof HTMLElement && e.target.click() })) }))] }, key));
|
|
50
59
|
return renderAccordion ? (_jsxs("tbody", { children: [row, _jsx(Tr, { id: `${id}-${key}`, accordion: true, accordionMaxHeight: accordionMaxHeight, children: _jsx("td", { colSpan: columns.length + 1, children: _jsx("div", { children: accordionContent }) }) })] }, `${key}-group`)) : row;
|
|
51
60
|
}), [columns, data, !!renderAccordion, accordionTrigger]);
|
|
52
61
|
return (_jsxs(Table, { id: id, accordionRows: !!renderAccordion, ...props, children: [!headless && _jsx("thead", { children: _jsxs("tr", { children: [headers, renderAccordion && _jsx("th", {})] }) }), renderAccordion ? rows : _jsx("tbody", { children: rows })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartTable.js","sourceRoot":"","sources":["../../src/components/SmartTable.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAoC,KAAK,EAAc,EAAE,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"SmartTable.js","sourceRoot":"","sources":["../../src/components/SmartTable.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAoC,KAAK,EAAc,EAAE,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAmHrF,SAAS,sBAAsB,CAAC,oBAA4B;IAC1D,OAAO,CAAC,KAAuB,EAAE,EAAE;QACjC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;QAC7E,MAAM,GAAG,GAAG,MAAM,YAAY,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAClF,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,OAAO,GAAG,GAAG,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAA;YACvD,IAAI,OAAO,YAAY,WAAW;gBAAE,OAAO,CAAC,KAAK,EAAE,CAAA;QACrD,CAAC;IACH,CAAC,CAAA;AACH,CAAC;AAED;;;;;;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AE,CAAC,CAAC,eAAe,KAAM,KAAK,aACvD,CAAC,QAAQ,IAAI,0BACZ,yBACG,OAAO,EACP,eAAe,IAAI,cAAS,IAC1B,GACC,EACP,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,0BAAQ,IAAI,GAAS,IACzC,CACT,CAAA;AACH,CAAC,CACF,CAAA"}
|
package/package.json
CHANGED
package/src/components/Link.tsx
CHANGED
|
@@ -19,6 +19,12 @@ export interface BaseLinkProps extends WithColor {
|
|
|
19
19
|
* @default false
|
|
20
20
|
*/
|
|
21
21
|
metadata?: any,
|
|
22
|
+
/**
|
|
23
|
+
* Whether or not to underline the link.
|
|
24
|
+
*
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
underline?: boolean,
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export type LinkProps = React.JSX.IntrinsicElements['a'] & BaseLinkProps
|
|
@@ -29,11 +35,11 @@ export type LinkProps = React.JSX.IntrinsicElements['a'] & BaseLinkProps
|
|
|
29
35
|
* Whenever a link is clicked, the function `onClickLink` of the nearest CitricController is called with the event and the value of the
|
|
30
36
|
* prop `metadata`.
|
|
31
37
|
*/
|
|
32
|
-
export const Link = withRef(({ appearance, color, style, className, children, onClick, metadata, ...props }: LinkProps) => {
|
|
38
|
+
export const Link = withRef(({ appearance, color, style, className, children, onClick, metadata, underline, ...props }: LinkProps) => {
|
|
33
39
|
const citric = useCitricController()
|
|
34
40
|
const linkProps = {
|
|
35
41
|
component: 'link',
|
|
36
|
-
style: applyColor(style, color),
|
|
42
|
+
style: applyColor({ ...style, textDecoration: underline ? undefined : 'none' }, color),
|
|
37
43
|
className: applyTextAppearance(className, appearance),
|
|
38
44
|
onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
39
45
|
onClick?.(e)
|
|
@@ -90,45 +90,42 @@ interface ExtraSmartTableProps<T extends Record<string, any>> {
|
|
|
90
90
|
*/
|
|
91
91
|
headless?: boolean,
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
93
|
+
* Making a row clickable is not accessible, i.e. it creates an unfriendly UI for people who rely on assistive technologies.
|
|
94
94
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
95
|
+
* Instead you should place the action in an element inside the row, e.g. an anchor or a button.
|
|
96
|
+
*
|
|
97
|
+
* For users who don't rely on assistive technologies we may still want the click on the row to mimic the behavior of the element with
|
|
98
|
+
* the actual action. This property does exactly this!
|
|
99
|
+
*
|
|
100
|
+
* The value of this property must be a CSS selector relative to this row, it must refer to the element with the click listener that
|
|
101
|
+
* should be triggered when this row is clicked.
|
|
102
|
+
*
|
|
103
|
+
* When this property is set, the row cursor becomes a pointer.
|
|
98
104
|
*
|
|
99
105
|
* @example
|
|
100
106
|
*
|
|
101
107
|
* ```
|
|
102
|
-
*
|
|
103
|
-
* onClick: item => console.log(item),
|
|
104
|
-
* description: 'log the item to the console',
|
|
105
|
-
* }}
|
|
108
|
+
* rowClickElement="a" // the first anchor element inside the row will be triggered when the row is clicked.
|
|
106
109
|
* ```
|
|
107
110
|
*/
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Function to run when the row is clicked. Receives the item corresponding to the row as the first parameter and the click event as the
|
|
111
|
-
* second.
|
|
112
|
-
* @param item
|
|
113
|
-
* @param event
|
|
114
|
-
*/
|
|
115
|
-
onClick: (item: T, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void,
|
|
116
|
-
/**
|
|
117
|
-
* A description of the action clicking the row does. Can be either a static string or a function that receives the item and returns the
|
|
118
|
-
* description.
|
|
119
|
-
*
|
|
120
|
-
* This is required for addressing accessibility.
|
|
121
|
-
*/
|
|
122
|
-
description: string | ((item: T) => string),
|
|
123
|
-
},
|
|
124
|
-
tabIndex?: number,
|
|
125
|
-
'aria-label'?: string,
|
|
111
|
+
rowClickElement?: string,
|
|
126
112
|
}
|
|
127
113
|
|
|
128
114
|
export type BaseSmartTableProps<T extends Record<string, any>> = BaseTableProps & ExtraSmartTableProps<T>
|
|
129
115
|
|
|
130
116
|
export type SmartTableProps<T extends Record<string, any>> = Omit<TableProps, 'children'> & ExtraSmartTableProps<T>
|
|
131
117
|
|
|
118
|
+
function createRowClickListener(elementQuerySelector: string) {
|
|
119
|
+
return (event: React.MouseEvent) => {
|
|
120
|
+
const target = event.target instanceof HTMLElement ? event.target : undefined
|
|
121
|
+
const row = target instanceof HTMLTableRowElement ? target : target?.closest('tr')
|
|
122
|
+
if (row) {
|
|
123
|
+
const element = row.querySelector(elementQuerySelector)
|
|
124
|
+
if (element instanceof HTMLElement) element.click()
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
132
129
|
/**
|
|
133
130
|
* Renders a table. Always prefer using this component over the raw Table component.
|
|
134
131
|
*
|
|
@@ -166,7 +163,7 @@ export type SmartTableProps<T extends Record<string, any>> = Omit<TableProps, 'c
|
|
|
166
163
|
*/
|
|
167
164
|
export const SmartTable = withRef(
|
|
168
165
|
function SmartTable<T extends Record<string, any>>({
|
|
169
|
-
data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id,
|
|
166
|
+
data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id, rowClickElement, headless, ...props
|
|
170
167
|
}: SmartTableProps<T>) {
|
|
171
168
|
id = useMemo(() => id || `${Math.random()}`, [id])
|
|
172
169
|
|
|
@@ -187,12 +184,7 @@ export const SmartTable = withRef(
|
|
|
187
184
|
<Tr
|
|
188
185
|
key={key}
|
|
189
186
|
accordionTrigger={accordionContent ? accordionTrigger : undefined}
|
|
190
|
-
onClick={
|
|
191
|
-
tabIndex={rowClick ? 0 : undefined}
|
|
192
|
-
aria-label={rowClick
|
|
193
|
-
? (typeof rowClick.description === 'function' ? rowClick.description(item): rowClick.description)
|
|
194
|
-
: undefined
|
|
195
|
-
}
|
|
187
|
+
onClick={rowClickElement ? createRowClickListener(rowClickElement) : undefined}
|
|
196
188
|
>
|
|
197
189
|
{columns.map(c => <td {...c.td} key={c.key}>{c.render ? c.render(item) : (item[c.key] || '')}</td>)}
|
|
198
190
|
{renderAccordion && (
|