@navikt/ds-react 8.4.1 → 8.5.1
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/cjs/accordion/Accordion.d.ts +10 -0
- package/cjs/accordion/Accordion.js +2 -2
- package/cjs/accordion/Accordion.js.map +1 -1
- package/cjs/data/table/helpers/table-cell.d.ts +2 -2
- package/cjs/data/table/helpers/table-cell.js +2 -5
- package/cjs/data/table/helpers/table-cell.js.map +1 -1
- package/cjs/data/table/helpers/table-focus.d.ts +26 -2
- package/cjs/data/table/helpers/table-focus.js +60 -9
- package/cjs/data/table/helpers/table-focus.js.map +1 -1
- package/cjs/data/table/helpers/table-grid-nav.d.ts +40 -10
- package/cjs/data/table/helpers/table-grid-nav.js +102 -25
- package/cjs/data/table/helpers/table-grid-nav.js.map +1 -1
- package/cjs/data/table/helpers/table-keyboard.d.ts +24 -3
- package/cjs/data/table/helpers/table-keyboard.js +25 -5
- package/cjs/data/table/helpers/table-keyboard.js.map +1 -1
- package/cjs/data/table/hooks/useGridCache.d.ts +17 -0
- package/cjs/data/table/hooks/useGridCache.js +65 -0
- package/cjs/data/table/hooks/useGridCache.js.map +1 -0
- package/cjs/data/table/root/DataTableRoot.d.ts +14 -4
- package/cjs/data/table/root/DataTableRoot.js +4 -6
- package/cjs/data/table/root/DataTableRoot.js.map +1 -1
- package/cjs/data/table/root/useTableKeyboardNav.d.ts +10 -4
- package/cjs/data/table/root/useTableKeyboardNav.js +70 -99
- package/cjs/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/cjs/data/token-filter/AutoSuggest.d.ts +21 -0
- package/cjs/data/token-filter/AutoSuggest.js +129 -0
- package/cjs/data/token-filter/AutoSuggest.js.map +1 -0
- package/cjs/data/token-filter/TokenFilter.d.ts +11 -0
- package/cjs/data/token-filter/TokenFilter.js +91 -0
- package/cjs/data/token-filter/TokenFilter.js.map +1 -0
- package/cjs/data/token-filter/TokenFilter.types.d.ts +46 -0
- package/cjs/data/token-filter/TokenFilter.types.js +3 -0
- package/cjs/data/token-filter/TokenFilter.types.js.map +1 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.d.ts +70 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js +171 -0
- package/cjs/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -0
- package/cjs/data/token-filter/helpers/parse-query-text.d.ts +31 -0
- package/cjs/data/token-filter/helpers/parse-query-text.js +91 -0
- package/cjs/data/token-filter/helpers/parse-query-text.js.map +1 -0
- package/cjs/link-card/LinkCard.d.ts +13 -0
- package/cjs/link-card/LinkCard.js +2 -2
- package/cjs/link-card/LinkCard.js.map +1 -1
- package/cjs/process/Process.d.ts +1 -1
- package/cjs/tooltip/Tooltip.js +1 -1
- package/cjs/tooltip/Tooltip.js.map +1 -1
- package/esm/accordion/Accordion.d.ts +10 -0
- package/esm/accordion/Accordion.js +2 -2
- package/esm/accordion/Accordion.js.map +1 -1
- package/esm/data/table/helpers/table-cell.d.ts +2 -2
- package/esm/data/table/helpers/table-cell.js +2 -5
- package/esm/data/table/helpers/table-cell.js.map +1 -1
- package/esm/data/table/helpers/table-focus.d.ts +26 -2
- package/esm/data/table/helpers/table-focus.js +55 -9
- package/esm/data/table/helpers/table-focus.js.map +1 -1
- package/esm/data/table/helpers/table-grid-nav.d.ts +40 -10
- package/esm/data/table/helpers/table-grid-nav.js +96 -24
- package/esm/data/table/helpers/table-grid-nav.js.map +1 -1
- package/esm/data/table/helpers/table-keyboard.d.ts +24 -3
- package/esm/data/table/helpers/table-keyboard.js +24 -4
- package/esm/data/table/helpers/table-keyboard.js.map +1 -1
- package/esm/data/table/hooks/useGridCache.d.ts +17 -0
- package/esm/data/table/hooks/useGridCache.js +63 -0
- package/esm/data/table/hooks/useGridCache.js.map +1 -0
- package/esm/data/table/root/DataTableRoot.d.ts +14 -4
- package/esm/data/table/root/DataTableRoot.js +4 -6
- package/esm/data/table/root/DataTableRoot.js.map +1 -1
- package/esm/data/table/root/useTableKeyboardNav.d.ts +10 -4
- package/esm/data/table/root/useTableKeyboardNav.js +75 -104
- package/esm/data/table/root/useTableKeyboardNav.js.map +1 -1
- package/esm/data/token-filter/AutoSuggest.d.ts +21 -0
- package/esm/data/token-filter/AutoSuggest.js +93 -0
- package/esm/data/token-filter/AutoSuggest.js.map +1 -0
- package/esm/data/token-filter/TokenFilter.d.ts +11 -0
- package/esm/data/token-filter/TokenFilter.js +55 -0
- package/esm/data/token-filter/TokenFilter.js.map +1 -0
- package/esm/data/token-filter/TokenFilter.types.d.ts +46 -0
- package/esm/data/token-filter/TokenFilter.types.js +2 -0
- package/esm/data/token-filter/TokenFilter.types.js.map +1 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.d.ts +70 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js +169 -0
- package/esm/data/token-filter/helpers/generate-autocomplete-options.js.map +1 -0
- package/esm/data/token-filter/helpers/parse-query-text.d.ts +31 -0
- package/esm/data/token-filter/helpers/parse-query-text.js +87 -0
- package/esm/data/token-filter/helpers/parse-query-text.js.map +1 -0
- package/esm/link-card/LinkCard.d.ts +13 -0
- package/esm/link-card/LinkCard.js +2 -2
- package/esm/link-card/LinkCard.js.map +1 -1
- package/esm/process/Process.d.ts +1 -1
- package/esm/tooltip/Tooltip.js +2 -2
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/package.json +3 -3
- package/src/accordion/Accordion.tsx +19 -2
- package/src/data/table/helpers/table-cell.ts +2 -7
- package/src/data/table/helpers/table-focus.ts +70 -9
- package/src/data/table/helpers/table-grid-nav.test.ts +659 -0
- package/src/data/table/helpers/table-grid-nav.ts +128 -32
- package/src/data/table/helpers/table-keyboard.test.ts +27 -27
- package/src/data/table/helpers/table-keyboard.ts +34 -4
- package/src/data/table/hooks/useGridCache.ts +73 -0
- package/src/data/table/root/DataTableRoot.tsx +21 -11
- package/src/data/table/root/useTableKeyboardNav.ts +110 -128
- package/src/data/token-filter/AutoSuggest.tsx +179 -0
- package/src/data/token-filter/TokenFilter.tsx +124 -0
- package/src/data/token-filter/TokenFilter.types.ts +79 -0
- package/src/data/token-filter/helpers/generate-autocomplete-options.ts +244 -0
- package/src/data/token-filter/helpers/parse-query-text.test.ts +410 -0
- package/src/data/token-filter/helpers/parse-query-text.ts +148 -0
- package/src/link-card/LinkCard.tsx +15 -1
- package/src/process/Process.tsx +1 -1
- package/src/tooltip/Tooltip.tsx +3 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useGridCache = useGridCache;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const hooks_1 = require("../../../utils/hooks");
|
|
6
|
+
const table_grid_nav_1 = require("../helpers/table-grid-nav");
|
|
7
|
+
/**
|
|
8
|
+
* Manages the table grid cache and observes DOM changes that require grid rebuilding.
|
|
9
|
+
* Watches for structural changes (rows/cells added/removed) and attribute changes
|
|
10
|
+
* (colspan, rowspan, hidden, style) that affect grid layout and focusability.
|
|
11
|
+
*/
|
|
12
|
+
function useGridCache(tableRef, enabled) {
|
|
13
|
+
const gridCacheRef = (0, react_1.useRef)({
|
|
14
|
+
grid: null,
|
|
15
|
+
dirty: true,
|
|
16
|
+
});
|
|
17
|
+
const [activeCell, setActiveCell] = (0, react_1.useState)(null);
|
|
18
|
+
const activeCellRef = (0, hooks_1.useValueAsRef)(activeCell).current;
|
|
19
|
+
const observerRef = (0, react_1.useRef)(null);
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
if (!tableRef || !enabled) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
observerRef.current = new MutationObserver(() => {
|
|
25
|
+
gridCacheRef.current.dirty = true;
|
|
26
|
+
if (activeCellRef && !activeCellRef.isConnected) {
|
|
27
|
+
setActiveCell(null);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
observerRef.current.observe(tableRef, {
|
|
31
|
+
subtree: true,
|
|
32
|
+
childList: true,
|
|
33
|
+
attributes: true,
|
|
34
|
+
attributeFilter: ["colspan", "rowspan", "hidden", "style"],
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
if (observerRef.current) {
|
|
38
|
+
observerRef.current.disconnect();
|
|
39
|
+
observerRef.current = null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, [tableRef, enabled, activeCellRef]);
|
|
43
|
+
/**
|
|
44
|
+
* If keyboard-nav is re-enabled, mark grid as dirty since
|
|
45
|
+
* the table might have changed while it was disabled.
|
|
46
|
+
*/
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
if (enabled) {
|
|
49
|
+
gridCacheRef.current.dirty = true;
|
|
50
|
+
}
|
|
51
|
+
}, [enabled]);
|
|
52
|
+
const getTableGrid = (0, react_1.useCallback)((_tableRef) => {
|
|
53
|
+
if (gridCacheRef.current.dirty || !gridCacheRef.current.grid) {
|
|
54
|
+
gridCacheRef.current.grid = (0, table_grid_nav_1.buildTableGridMap)(_tableRef);
|
|
55
|
+
gridCacheRef.current.dirty = false;
|
|
56
|
+
}
|
|
57
|
+
return gridCacheRef.current.grid;
|
|
58
|
+
}, []);
|
|
59
|
+
return {
|
|
60
|
+
getTableGrid,
|
|
61
|
+
activeCell,
|
|
62
|
+
setActiveCell,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=useGridCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGridCache.js","sourceRoot":"","sources":["../../../../src/data/table/hooks/useGridCache.ts"],"names":[],"mappings":";;AAwES,oCAAY;AAxErB,iCAAiE;AACjE,gDAAqD;AACrD,8DAA8E;AAE9E;;;;GAIG;AACH,SAAS,YAAY,CAAC,QAAiC,EAAE,OAAgB;IACvE,MAAM,YAAY,GAAG,IAAA,cAAM,EAAY;QACrC,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;I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AC,OAAO,CAAC,CAAC,CAAC;IAEd,MAAM,YAAY,GAAG,IAAA,mBAAW,EAAC,CAAC,SAA2B,EAAE,EAAE;QAC/D,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAC7D,YAAY,CAAC,OAAO,CAAC,IAAI,GAAG,IAAA,kCAAiB,EAAC,SAAS,CAAC,CAAC;YACzD,YAAY,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACrC,CAAC;QAED,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC;IACnC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,YAAY;QACZ,UAAU;QACV,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -9,17 +9,27 @@ import { DataTableTr, type DataTableTrProps } from "../tr/DataTableTr";
|
|
|
9
9
|
interface DataTableProps extends React.HTMLAttributes<HTMLTableElement> {
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
rowDensity?: "condensed" | "normal" | "spacious";
|
|
12
|
+
/**
|
|
13
|
+
* Zebra striped table
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
zebraStripes?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Truncate content in cells and show ellipsis for overflowed text.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
truncateContent?: boolean;
|
|
12
22
|
/**
|
|
13
23
|
* Enables keyboard navigation for table rows and cells.
|
|
14
24
|
* @default false
|
|
15
25
|
*/
|
|
16
26
|
withKeyboardNav?: boolean;
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* Custom callback to determine if navigation should be blocked.
|
|
29
|
+
* Called before default blocking logic.
|
|
30
|
+
* Requires `withKeyboardNav` to be `true`.
|
|
20
31
|
*/
|
|
21
|
-
|
|
22
|
-
truncateContent?: boolean;
|
|
32
|
+
shouldBlockNavigation?: (event: KeyboardEvent) => boolean;
|
|
23
33
|
}
|
|
24
34
|
interface DataTableRootComponent extends React.ForwardRefExoticComponent<DataTableProps & React.RefAttributes<HTMLTableElement>> {
|
|
25
35
|
/**
|
|
@@ -64,18 +64,16 @@ const DataTableTr_1 = require("../tr/DataTableTr");
|
|
|
64
64
|
Object.defineProperty(exports, "DataTableTr", { enumerable: true, get: function () { return DataTableTr_1.DataTableTr; } });
|
|
65
65
|
const useTableKeyboardNav_1 = require("./useTableKeyboardNav");
|
|
66
66
|
const DataTable = (0, react_1.forwardRef)((_a, forwardedRef) => {
|
|
67
|
-
var { className, rowDensity = "normal", withKeyboardNav = false, zebraStripes = false, truncateContent = true } = _a, rest = __rest(_a, ["className", "rowDensity", "withKeyboardNav", "zebraStripes", "truncateContent"]);
|
|
67
|
+
var { className, rowDensity = "normal", withKeyboardNav = false, zebraStripes = false, truncateContent = true, shouldBlockNavigation } = _a, rest = __rest(_a, ["className", "rowDensity", "withKeyboardNav", "zebraStripes", "truncateContent", "shouldBlockNavigation"]);
|
|
68
68
|
const [tableRef, setTableRef] = (0, react_1.useState)(null);
|
|
69
69
|
const mergedRef = (0, hooks_1.useMergeRefs)(forwardedRef, setTableRef);
|
|
70
|
-
const {
|
|
70
|
+
const { tabIndex } = (0, useTableKeyboardNav_1.useTableKeyboardNav)(tableRef, {
|
|
71
71
|
enabled: withKeyboardNav,
|
|
72
|
+
shouldBlockNavigation,
|
|
72
73
|
});
|
|
73
74
|
return (react_1.default.createElement("div", { className: "aksel-data-table__border-wrapper" },
|
|
74
75
|
react_1.default.createElement("div", { className: "aksel-data-table__scroll-wrapper" },
|
|
75
|
-
react_1.default.createElement("table", Object.assign({}, rest, { ref: mergedRef, className: (0, helpers_1.cl)("aksel-data-table", className,
|
|
76
|
-
"aksel-data-table--zebra-stripes": zebraStripes,
|
|
77
|
-
"aksel-data-table--truncate-content": truncateContent,
|
|
78
|
-
}), "data-density": rowDensity, tabIndex: tableTabIndex, onFocus: onFocus })))));
|
|
76
|
+
react_1.default.createElement("table", Object.assign({}, rest, { ref: mergedRef, className: (0, helpers_1.cl)("aksel-data-table", className), "data-zebra-stripes": zebraStripes, "data-truncate-content": truncateContent, "data-density": rowDensity, tabIndex: tabIndex })))));
|
|
79
77
|
});
|
|
80
78
|
exports.DataTable = DataTable;
|
|
81
79
|
DataTable.Caption = DataTableCaption_1.DataTableCaption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableRoot.js","sourceRoot":"","sources":["../../../../src/data/table/root/DataTableRoot.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,oDAA4C;AAC5C,gDAAoD;AACpD,kEAGqC;
|
|
1
|
+
{"version":3,"file":"DataTableRoot.js","sourceRoot":"","sources":["../../../../src/data/table/root/DataTableRoot.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,oDAA4C;AAC5C,gDAAoD;AACpD,kEAGqC;AA4LnC,iGA9LA,mCAAgB,OA8LA;AA3LlB,4DAGiC;AAyL/B,+FA3LA,+BAAc,OA2LA;AAxLhB,mDAAuE;AAyLrE,4FAzLO,yBAAW,OAyLP;AAxLb,4DAGiC;AAsL/B,+FAxLA,+BAAc,OAwLA;AArLhB,mDAAuE;AAsLrE,4FAtLO,yBAAW,OAsLP;AArLb,4DAGiC;AAmL/B,+FArLA,+BAAc,OAqLA;AAlLhB,mDAAuE;AAmLrE,4FAnLO,yBAAW,OAmLP;AAlLb,+DAA4D;AA2H5D,MAAM,SAAS,GAAG,IAAA,kBAAU,EAC1B,CACE,EAQC,EACD,YAAY,EACZ,EAAE;QAVF,EACE,SAAS,EACT,UAAU,GAAG,QAAQ,EACrB,eAAe,GAAG,KAAK,EACvB,YAAY,GAAG,KAAK,EACpB,eAAe,GAAG,IAAI,EACtB,qBAAqB,OAEtB,EADI,IAAI,cAPT,0GAQC,CADQ;IAIT,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAA0B,IAAI,CAAC,CAAC;IACxE,MAAM,SAAS,GAAG,IAAA,oBAAY,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAE1D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,yCAAmB,EAAC,QAAQ,EAAE;QACjD,OAAO,EAAE,eAAe;QACxB,qBAAqB;KACtB,CAAC,CAAC;IAEH,OAAO,CACL,uCAAK,SAAS,EAAC,kCAAkC;QAC/C,uCAAK,SAAS,EAAC,kCAAkC;YAC/C,yDACM,IAAI,IACR,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,IAAA,YAAE,EAAC,kBAAkB,EAAE,SAAS,CAAC,wBACxB,YAAY,2BACT,eAAe,kBACxB,UAAU,EACxB,QAAQ,EAAE,QAAQ,IAClB,CACE,CACF,CACP,CAAC;AACJ,CAAC,CACwB,CAAC;AAW1B,8BAAS;AATX,SAAS,CAAC,OAAO,GAAG,mCAAgB,CAAC;AACrC,SAAS,CAAC,KAAK,GAAG,+BAAc,CAAC;AACjC,SAAS,CAAC,KAAK,GAAG,+BAAc,CAAC;AACjC,SAAS,CAAC,EAAE,GAAG,yBAAW,CAAC;AAC3B,SAAS,CAAC,EAAE,GAAG,yBAAW,CAAC;AAC3B,SAAS,CAAC,EAAE,GAAG,yBAAW,CAAC;AAC3B,SAAS,CAAC,KAAK,GAAG,+BAAc,CAAC;AAYjC,kBAAe,SAAS,CAAC"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
type UseTableKeyboardNavOptions = {
|
|
2
2
|
enabled: boolean;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Custom callback to determine if navigation should be blocked.
|
|
5
|
+
* Called before default blocking logic.
|
|
6
|
+
*/
|
|
7
|
+
shouldBlockNavigation?: (event: KeyboardEvent) => boolean;
|
|
8
|
+
};
|
|
9
|
+
declare function useTableKeyboardNav(tableRef: HTMLTableElement | null, { enabled, shouldBlockNavigation: customBlockFn }: UseTableKeyboardNavOptions): {
|
|
10
|
+
tabIndex: number | undefined;
|
|
6
11
|
};
|
|
7
12
|
export { useTableKeyboardNav };
|
|
13
|
+
export type { UseTableKeyboardNavOptions };
|
|
@@ -7,64 +7,90 @@ const table_cell_1 = require("../helpers/table-cell");
|
|
|
7
7
|
const table_focus_1 = require("../helpers/table-focus");
|
|
8
8
|
const table_grid_nav_1 = require("../helpers/table-grid-nav");
|
|
9
9
|
const table_keyboard_1 = require("../helpers/table-keyboard");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
activeCellRef.current = activeCell;
|
|
14
|
-
const observerRef = (0, react_1.useRef)(null);
|
|
15
|
-
const gridCacheRef = (0, react_1.useRef)({
|
|
16
|
-
grid: null,
|
|
17
|
-
dirty: true,
|
|
18
|
-
});
|
|
10
|
+
const useGridCache_1 = require("../hooks/useGridCache");
|
|
11
|
+
function useTableKeyboardNav(tableRef, { enabled, shouldBlockNavigation: customBlockFn }) {
|
|
12
|
+
const { getTableGrid, activeCell, setActiveCell } = (0, useGridCache_1.useGridCache)(tableRef, enabled);
|
|
19
13
|
/**
|
|
20
|
-
*
|
|
21
|
-
* - Save original tabIndex of cells and restore when navigating away?
|
|
14
|
+
* Executes a navigation action and returns the target cell.
|
|
22
15
|
*/
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const executeNavigationAction = (0, hooks_1.useEventCallback)((action) => {
|
|
17
|
+
if (!tableRef) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
let currentCell = activeCell;
|
|
21
|
+
currentCell !== null && currentCell !== void 0 ? currentCell : (currentCell = (0, table_cell_1.focusInitialTableTarget)(tableRef));
|
|
22
|
+
if (!currentCell) {
|
|
26
23
|
return null;
|
|
27
24
|
}
|
|
28
|
-
const { grid, positions
|
|
25
|
+
const { grid, positions } = getTableGrid(tableRef);
|
|
29
26
|
const currentPos = positions.get(currentCell);
|
|
30
|
-
|
|
27
|
+
let nextCell = null;
|
|
28
|
+
switch (action.type) {
|
|
29
|
+
case "delta": {
|
|
30
|
+
if (!currentPos) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
nextCell = (0, table_grid_nav_1.findNextFocusableCell)(grid, currentPos, action.delta, currentCell);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "home": {
|
|
37
|
+
if (!currentPos) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
nextCell = (0, table_grid_nav_1.findFirstCellInRow)(grid, currentPos.y);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "end": {
|
|
44
|
+
if (!currentPos) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
nextCell = (0, table_grid_nav_1.findLastCellInRow)(grid, currentPos.y);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "tableStart": {
|
|
51
|
+
nextCell = (0, table_grid_nav_1.findFirstCell)(grid);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "tableEnd": {
|
|
55
|
+
nextCell = (0, table_grid_nav_1.findLastCell)(grid);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!nextCell || nextCell === currentCell) {
|
|
31
60
|
return null;
|
|
32
61
|
}
|
|
33
|
-
|
|
34
|
-
return nextCell
|
|
35
|
-
? (0, table_focus_1.focusCellAndUpdateTabIndex)(nextCell, currentCell)
|
|
36
|
-
: null;
|
|
62
|
+
return (0, table_focus_1.focusCellAndUpdateTabIndex)(nextCell, currentCell);
|
|
37
63
|
});
|
|
38
64
|
/**
|
|
39
|
-
* Handles keyboard navigation with arrow keys.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* TODO:
|
|
43
|
-
* - Check for other "blocking" scenarios, like actionmenus, dropdown etc
|
|
44
|
-
* - Consider having acallback user can hook into to determine if navigation should be blocked
|
|
45
|
-
* - Consider adding Home, End, PageUp, PageDown navigation
|
|
46
|
-
*
|
|
65
|
+
* Handles keyboard navigation with arrow keys, Home/End, and PageUp/PageDown.
|
|
66
|
+
* Checks if navigation should be blocked based on current focus context.
|
|
47
67
|
*/
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
const handleTableKeyDown = (0, hooks_1.useEventCallback)((event) => {
|
|
69
|
+
if (customBlockFn === null || customBlockFn === void 0 ? void 0 : customBlockFn(event)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if ((0, table_keyboard_1.shouldBlockNavigation)(event)) {
|
|
51
73
|
return;
|
|
52
74
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
event.preventDefault();
|
|
57
|
-
newCell = navigateByArrowKey(delta);
|
|
75
|
+
const action = (0, table_keyboard_1.getNavigationAction)(event);
|
|
76
|
+
if (!action) {
|
|
77
|
+
return;
|
|
58
78
|
}
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
const newCell = executeNavigationAction(action);
|
|
59
81
|
newCell && setActiveCell(newCell);
|
|
60
82
|
});
|
|
61
83
|
/**
|
|
62
84
|
* When focus is moved to elements inside a cell like inputs, checkbox etc
|
|
63
85
|
* we want to update the active cell to the parent td/th, so that keyboard navigation continues to work as expected from there.
|
|
64
86
|
*/
|
|
65
|
-
const
|
|
87
|
+
const handleTableFocusIn = (0, hooks_1.useEventCallback)((event) => {
|
|
66
88
|
var _a;
|
|
67
89
|
const target = event.target;
|
|
90
|
+
if (tableRef && target === tableRef) {
|
|
91
|
+
(0, table_cell_1.focusInitialTableTarget)(tableRef);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
68
94
|
const newCell = (_a = target === null || target === void 0 ? void 0 : target.closest("td, th")) !== null && _a !== void 0 ? _a : null;
|
|
69
95
|
if (!newCell || newCell === activeCell) {
|
|
70
96
|
return;
|
|
@@ -77,77 +103,22 @@ function useTableKeyboardNav(tableRef, { enabled }) {
|
|
|
77
103
|
}
|
|
78
104
|
});
|
|
79
105
|
/**
|
|
80
|
-
*
|
|
81
|
-
* - We want to check if elements are removed/added, like when filtering table, pagination etc
|
|
82
|
-
* - Changes in colspan/rowspan that can affect the grid structure
|
|
83
|
-
* - Hidden attribute or styles that can affect focusability of cells
|
|
84
|
-
*
|
|
85
|
-
* We also check if the active cell is removed from the DOM, and clear it if so.
|
|
106
|
+
* Attach event listeners for keyboard navigation and focus management.
|
|
86
107
|
*/
|
|
87
108
|
(0, react_1.useEffect)(() => {
|
|
88
109
|
if (!tableRef || !enabled) {
|
|
89
110
|
return;
|
|
90
111
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (activeCellRef.current && !activeCellRef.current.isConnected) {
|
|
94
|
-
setActiveCell(null);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
observerRef.current.observe(tableRef, {
|
|
98
|
-
subtree: true,
|
|
99
|
-
childList: true,
|
|
100
|
-
attributes: true,
|
|
101
|
-
attributeFilter: ["colspan", "rowspan", "hidden", "style"],
|
|
102
|
-
});
|
|
103
|
-
return () => {
|
|
104
|
-
if (observerRef.current) {
|
|
105
|
-
observerRef.current.disconnect();
|
|
106
|
-
observerRef.current = null;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}, [tableRef, enabled]);
|
|
110
|
-
(0, react_1.useEffect)(() => {
|
|
111
|
-
if (!tableRef || !enabled) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
tableRef.addEventListener("keydown", onKeyDown);
|
|
115
|
-
tableRef.addEventListener("focusin", onFocusIn);
|
|
112
|
+
tableRef.addEventListener("keydown", handleTableKeyDown);
|
|
113
|
+
tableRef.addEventListener("focusin", handleTableFocusIn);
|
|
116
114
|
return () => {
|
|
117
|
-
tableRef.removeEventListener("keydown",
|
|
118
|
-
tableRef.removeEventListener("focusin",
|
|
115
|
+
tableRef.removeEventListener("keydown", handleTableKeyDown);
|
|
116
|
+
tableRef.removeEventListener("focusin", handleTableFocusIn);
|
|
119
117
|
};
|
|
120
|
-
}, [tableRef,
|
|
121
|
-
/*
|
|
122
|
-
* If keyboard-nav is re-enabled, we need to make sure to update the grid cache,
|
|
123
|
-
* since the table might have changed while it was disabled.
|
|
124
|
-
*/
|
|
125
|
-
(0, react_1.useEffect)(() => {
|
|
126
|
-
if (!enabled) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
gridCacheRef.current.dirty = true;
|
|
130
|
-
}, [enabled]);
|
|
118
|
+
}, [tableRef, handleTableKeyDown, handleTableFocusIn, enabled]);
|
|
131
119
|
return {
|
|
132
120
|
/* Table should only have tabIndex until the focus is moved inside and is enabled */
|
|
133
|
-
|
|
134
|
-
/*
|
|
135
|
-
* Allows us to capture focus on the table when navigating with Tab from outside, and move it to the first cell.
|
|
136
|
-
* We only want to do this if no cell is already focused.
|
|
137
|
-
*/
|
|
138
|
-
onFocus: () => {
|
|
139
|
-
if (!tableRef) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const focusedElement = document.activeElement;
|
|
143
|
-
const cellInTable = focusedElement === null || focusedElement === void 0 ? void 0 : focusedElement.closest("td, th");
|
|
144
|
-
/* Assume onFocusIn handler has updates cell */
|
|
145
|
-
if (cellInTable && tableRef.contains(cellInTable)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const firstCell = (0, table_cell_1.getFirstCell)(tableRef);
|
|
149
|
-
return firstCell ? (0, table_focus_1.focusCell)(firstCell) : null;
|
|
150
|
-
},
|
|
121
|
+
tabIndex: enabled ? (activeCell ? undefined : 0) : undefined,
|
|
151
122
|
};
|
|
152
123
|
}
|
|
153
124
|
//# sourceMappingURL=useTableKeyboardNav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTableKeyboardNav.js","sourceRoot":"","sources":["../../../../src/data/table/root/useTableKeyboardNav.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useTableKeyboardNav.js","sourceRoot":"","sources":["../../../../src/data/table/root/useTableKeyboardNav.ts"],"names":[],"mappings":";;AAiLS,kDAAmB;AAjL5B,iCAAkC;AAClC,gDAAwD;AACxD,sDAAgE;AAChE,wDAAoE;AACpE,8DAMmC;AACnC,8DAImC;AACnC,wDAAqD;AAWrD,SAAS,mBAAmB,CAC1B,QAAiC,EACjC,EAAE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAA8B;IAE7E,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,IAAA,2BAAY,EAC9D,QAAQ,EACR,OAAO,CACR,CAAC;IAEF;;OAEG;IACH,MAAM,uBAAuB,GAAG,IAAA,wBAAgB,EAC9C,CAAC,MAAwB,EAAE,EAAE;QAC3B,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,WAAW,GAAG,UAAU,CAAC;QAC7B,WAAW,aAAX,WAAW,cAAX,WAAW,IAAX,WAAW,GAAK,IAAA,oCAAuB,EAAC,QAAQ,CAAC,EAAC;QAElD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QACnD,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAE9C,IAAI,QAAQ,GAAmB,IAAI,CAAC;QAEpC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,QAAQ,GAAG,IAAA,sCAAqB,EAC9B,IAAI,EACJ,UAAU,EACV,MAAM,CAAC,KAAK,E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CAAC;YAC5D,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;QAC9D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC,CAAC;IAEhE,OAAO;QACL,oFAAoF;QACpF,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface AutoSuggestOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
filteringTags?: string[];
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
interface AutoSuggestGroup {
|
|
10
|
+
label: string;
|
|
11
|
+
options: AutoSuggestOption[];
|
|
12
|
+
}
|
|
13
|
+
interface AutoSuggestProps {
|
|
14
|
+
options: AutoSuggestGroup[];
|
|
15
|
+
value: string;
|
|
16
|
+
filterText: string;
|
|
17
|
+
onSelect: (value: string) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const AutoSuggest: React.ForwardRefExoticComponent<AutoSuggestProps & React.RefAttributes<HTMLDivElement>>;
|
|
21
|
+
export { AutoSuggest };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.AutoSuggest = void 0;
|
|
48
|
+
const react_1 = __importStar(require("react"));
|
|
49
|
+
const helpers_1 = require("../../utils/helpers");
|
|
50
|
+
const AutoSuggest = (0, react_1.forwardRef)(({ options, value, filterText, onSelect, className }, ref) => {
|
|
51
|
+
console.info({ options, value, filterText });
|
|
52
|
+
/* const highlightedText = filterText === undefined ? value : filterText; */
|
|
53
|
+
/* const filterValue = (value || "").toLowerCase();
|
|
54
|
+
|
|
55
|
+
const filteredGroups = options
|
|
56
|
+
.map((group) => ({
|
|
57
|
+
...group,
|
|
58
|
+
options: group.options.filter((option) => {
|
|
59
|
+
const searchableText = [
|
|
60
|
+
option.label,
|
|
61
|
+
option.description,
|
|
62
|
+
...(option.filteringTags ?? []),
|
|
63
|
+
...(option.tags ?? []),
|
|
64
|
+
]
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join(" ")
|
|
67
|
+
.toLowerCase();
|
|
68
|
+
return searchableText.includes(filterValue);
|
|
69
|
+
}),
|
|
70
|
+
}))
|
|
71
|
+
.filter((group) => group.options.length > 0); */
|
|
72
|
+
const { items } = useAutosuggestItems({ options, filterValue: filterText });
|
|
73
|
+
console.info({ items });
|
|
74
|
+
return (react_1.default.createElement("div", { ref: ref, className: (0, helpers_1.cl)("aksel-auto-suggest", className) }, options.map((group) => (react_1.default.createElement("div", { key: group.label, className: "aksel-auto-suggest__group" },
|
|
75
|
+
react_1.default.createElement("div", { className: "aksel-auto-suggest__group-label" }, group.label),
|
|
76
|
+
react_1.default.createElement("ul", { className: "aksel-auto-suggest__list" }, group.options.map((option) => (react_1.default.createElement("li", { key: option.value, className: "aksel-auto-suggest__item" },
|
|
77
|
+
react_1.default.createElement("button", { type: "button", className: "aksel-auto-suggest__button", onClick: () => onSelect(option.value) },
|
|
78
|
+
react_1.default.createElement("span", { className: "aksel-auto-suggest__label" }, option.label),
|
|
79
|
+
option.description && (react_1.default.createElement("span", { className: "aksel-auto-suggest__description" }, option.description)),
|
|
80
|
+
option.tags && option.tags.length > 0 && (react_1.default.createElement("div", { className: "aksel-auto-suggest__tags" }, option.tags.map((tag) => (react_1.default.createElement("span", { key: tag, className: "aksel-auto-suggest__tag" }, tag)))))))))))))));
|
|
81
|
+
});
|
|
82
|
+
exports.AutoSuggest = AutoSuggest;
|
|
83
|
+
function useAutosuggestItems({ options, filterValue }) {
|
|
84
|
+
const { items } = (0, react_1.useMemo)(() => createItems(options), [options]);
|
|
85
|
+
const filteredItems = (0, react_1.useMemo)(() => {
|
|
86
|
+
const localFilteredItems = items;
|
|
87
|
+
if (filterValue) {
|
|
88
|
+
localFilteredItems.unshift({
|
|
89
|
+
value: filterValue,
|
|
90
|
+
type: "use-entered",
|
|
91
|
+
label: `Use "${filterValue}"`,
|
|
92
|
+
option: { value: filterValue },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return localFilteredItems;
|
|
96
|
+
}, [items, filterValue]);
|
|
97
|
+
return { items: filteredItems };
|
|
98
|
+
}
|
|
99
|
+
function createItems(options) {
|
|
100
|
+
const items = [];
|
|
101
|
+
const itemToGroup = new WeakMap();
|
|
102
|
+
for (const option of options) {
|
|
103
|
+
if (isGroup(option)) {
|
|
104
|
+
for (const item of flattenGroup(option, itemToGroup)) {
|
|
105
|
+
items.push(item);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
items.push(Object.assign(Object.assign({}, option), { option }));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { items };
|
|
113
|
+
}
|
|
114
|
+
function flattenGroup(group, map) {
|
|
115
|
+
var _a;
|
|
116
|
+
const { options } = group, rest = __rest(group, ["options"]);
|
|
117
|
+
const groupItem = Object.assign(Object.assign({}, rest), { type: "parent", option: group });
|
|
118
|
+
const items = [groupItem];
|
|
119
|
+
for (const option of options) {
|
|
120
|
+
const childOption = Object.assign(Object.assign({}, option), { type: "child", disabled: (_a = option.disabled) !== null && _a !== void 0 ? _a : false, option, parent: group });
|
|
121
|
+
items.push(childOption);
|
|
122
|
+
map.set(childOption, groupItem);
|
|
123
|
+
}
|
|
124
|
+
return items;
|
|
125
|
+
}
|
|
126
|
+
function isGroup(optionOrGroup) {
|
|
127
|
+
return "options" in optionOrGroup;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=AutoSuggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoSuggest.js","sourceRoot":"","sources":["../../../src/data/token-filter/AutoSuggest.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAmD;AACnD,iDAAyC;AA2BzC,MAAM,WAAW,GAAG,IAAA,kBAAU,EAC5B,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IAC3D,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7C,4EAA4E;IAC5E;;;;;;;;;;;;;;;;;;sDAkBkD;IAElD,MAAM,EAAE,KAAK,EAAE,GAAG,mBAAmB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;IAE5E,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAExB,OAAO,CACL,uCAAK,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,IAAA,YAAE,EAAC,oBAAoB,EAAE,SAAS,CAAC,IAC1D,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACtB,uCAAK,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAC,2BAA2B;QAC1D,uCAAK,SAAS,EAAC,iCAAiC,IAAE,KAAK,CAAC,KAAK,CAAO;QACpE,sCAAI,SAAS,EAAC,0BAA0B,IACrC,KAAK,CAAC,OAAO,CAAC,GAAG,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WAAW,CAAC,CAAC;QAExB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CACd,aAA+D;IAE/D,OAAO,SAAS,IAAI,aAAa,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { QueryFilterQuery, QueryFilteringOptions, QueryFilteringProperties } from "./TokenFilter.types";
|
|
3
|
+
type TokenFilterProps = {
|
|
4
|
+
query: QueryFilterQuery;
|
|
5
|
+
onChange: (newQuery: QueryFilterQuery) => void;
|
|
6
|
+
className?: string;
|
|
7
|
+
filteringOptions: QueryFilteringOptions;
|
|
8
|
+
filteringProperties: QueryFilteringProperties;
|
|
9
|
+
};
|
|
10
|
+
export declare const TokenFilter: React.ForwardRefExoticComponent<TokenFilterProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export {};
|