@appdirect/design-system 0.0.17 → 0.0.19
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/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +15 -51
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +91 -139
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +1 -1
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DashboardWidget.json +92 -0
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +6 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +173 -7
- package/dist/css/tokens.css +3195 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DashboardWidget/DashboardWidget.stories.tsx +76 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +16 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/DateRangeSelectorFilter/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
3
|
+
export var Preset;
|
|
4
|
+
(function (Preset) {
|
|
5
|
+
Preset["WEEK"] = "week";
|
|
6
|
+
Preset["MONTH"] = "month";
|
|
7
|
+
Preset["QUARTER"] = "quarter";
|
|
8
|
+
Preset["CUSTOM"] = "custom";
|
|
9
|
+
})(Preset || (Preset = {}));
|
|
10
|
+
export const getPresets = () => [
|
|
11
|
+
{
|
|
12
|
+
label: translate("table.filters.date.range.week"),
|
|
13
|
+
value: Preset.WEEK,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: translate("table.filters.date.range.month"),
|
|
17
|
+
value: Preset.MONTH,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: translate("table.filters.date.range.quarter"),
|
|
21
|
+
value: Preset.QUARTER,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: translate("table.filters.date.range.custom"),
|
|
25
|
+
value: Preset.CUSTOM,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
export const getPresetLabel = (value) => {
|
|
29
|
+
return getPresets().find(item => item.value === value)?.label || "";
|
|
30
|
+
};
|
|
31
|
+
export const getDateRangeFromPreset = (preset) => {
|
|
32
|
+
const now = new Date();
|
|
33
|
+
const start = new Date();
|
|
34
|
+
switch (preset) {
|
|
35
|
+
case Preset.WEEK:
|
|
36
|
+
start.setDate(now.getDate() - 7);
|
|
37
|
+
break;
|
|
38
|
+
case Preset.MONTH:
|
|
39
|
+
start.setMonth(now.getMonth() - 1);
|
|
40
|
+
break;
|
|
41
|
+
case Preset.QUARTER:
|
|
42
|
+
start.setMonth(now.getMonth() - 3);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return [start, now];
|
|
48
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/DateRangeSelectorFilter/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
3
|
+
|
|
4
|
+
export enum Preset {
|
|
5
|
+
WEEK = "week",
|
|
6
|
+
MONTH = "month",
|
|
7
|
+
QUARTER = "quarter",
|
|
8
|
+
CUSTOM = "custom",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const getPresets = (): { label: string; value: Preset }[] => [
|
|
12
|
+
{
|
|
13
|
+
label: translate("table.filters.date.range.week"),
|
|
14
|
+
value: Preset.WEEK,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: translate("table.filters.date.range.month"),
|
|
18
|
+
value: Preset.MONTH,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: translate("table.filters.date.range.quarter"),
|
|
22
|
+
value: Preset.QUARTER,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: translate("table.filters.date.range.custom"),
|
|
26
|
+
value: Preset.CUSTOM,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export const getPresetLabel = (value: string): string => {
|
|
31
|
+
return getPresets().find(item => item.value === value)?.label || "";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const getDateRangeFromPreset = (preset: string): [Date | null, Date | null] | null => {
|
|
35
|
+
const now = new Date();
|
|
36
|
+
const start = new Date();
|
|
37
|
+
switch (preset) {
|
|
38
|
+
case Preset.WEEK:
|
|
39
|
+
start.setDate(now.getDate() - 7);
|
|
40
|
+
break;
|
|
41
|
+
case Preset.MONTH:
|
|
42
|
+
start.setMonth(now.getMonth() - 1);
|
|
43
|
+
break;
|
|
44
|
+
case Preset.QUARTER:
|
|
45
|
+
start.setMonth(now.getMonth() - 3);
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return [start, now];
|
|
51
|
+
};
|
|
@@ -1,30 +1,10 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/FilterChip.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
4
|
import React from "react";
|
|
3
|
-
import { Chip } from "@mantine/core";
|
|
4
|
-
import { RiCloseLine } from
|
|
5
|
-
/**
|
|
6
|
-
* FilterChip component for displaying active filters with remove functionality
|
|
7
|
-
* Shows as an outlined chip with a close icon for easy removal
|
|
8
|
-
*/
|
|
5
|
+
import { Chip, rem } from "@mantine/core";
|
|
6
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
9
7
|
const FilterChip = ({ label, onClick }) => {
|
|
10
|
-
return (_jsx(Chip, { color: "gray", size: "xs", variant: "outline", checked: true, onChange: onClick,
|
|
11
|
-
root: {
|
|
12
|
-
cursor: 'pointer',
|
|
13
|
-
'&[dataChecked="true"]': {
|
|
14
|
-
backgroundColor: 'transparent',
|
|
15
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
16
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
17
|
-
},
|
|
18
|
-
'&:hover': {
|
|
19
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
label: {
|
|
23
|
-
cursor: 'pointer',
|
|
24
|
-
},
|
|
25
|
-
iconWrapper: {
|
|
26
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
27
|
-
},
|
|
28
|
-
}, children: label }));
|
|
8
|
+
return (_jsx(Chip, { color: "gray.3", size: "xs", icon: _jsx(CloseIcon, { style: { width: rem(10), height: rem(10) } }), variant: "outline", checked: true, onChange: onClick, children: label }));
|
|
29
9
|
};
|
|
30
10
|
export default FilterChip;
|
|
@@ -1,44 +1,23 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/FilterChip.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
1
3
|
import React from "react";
|
|
2
|
-
import { Chip } from "@mantine/core";
|
|
3
|
-
import { RiCloseLine } from
|
|
4
|
+
import { Chip, rem } from "@mantine/core";
|
|
5
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
4
6
|
|
|
5
7
|
interface FilterChipProps {
|
|
6
8
|
label: string;
|
|
7
9
|
onClick: () => void;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
/**
|
|
11
|
-
* FilterChip component for displaying active filters with remove functionality
|
|
12
|
-
* Shows as an outlined chip with a close icon for easy removal
|
|
13
|
-
*/
|
|
14
12
|
const FilterChip = ({ label, onClick }: FilterChipProps): JSX.Element => {
|
|
15
13
|
return (
|
|
16
14
|
<Chip
|
|
17
|
-
color="gray"
|
|
15
|
+
color="gray.3"
|
|
18
16
|
size="xs"
|
|
17
|
+
icon={<CloseIcon style={{ width: rem(10), height: rem(10) }} />}
|
|
19
18
|
variant="outline"
|
|
20
|
-
checked
|
|
19
|
+
checked
|
|
21
20
|
onChange={onClick}
|
|
22
|
-
icon={<RiCloseLine size={12} />}
|
|
23
|
-
styles={{
|
|
24
|
-
root: {
|
|
25
|
-
cursor: 'pointer',
|
|
26
|
-
'&[dataChecked="true"]': {
|
|
27
|
-
backgroundColor: 'transparent',
|
|
28
|
-
border: '1px solid var(--ad-color-border-default)',
|
|
29
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
30
|
-
},
|
|
31
|
-
'&:hover': {
|
|
32
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
label: {
|
|
36
|
-
cursor: 'pointer',
|
|
37
|
-
},
|
|
38
|
-
iconWrapper: {
|
|
39
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
40
|
-
},
|
|
41
|
-
}}
|
|
42
21
|
>
|
|
43
22
|
{label}
|
|
44
23
|
</Chip>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/ResultCount.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Loader, Text } from "@mantine/core";
|
|
6
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
7
|
+
const ResultCount = ({ resultCount, isLoading = false }) => {
|
|
8
|
+
const getResultCountText = () => {
|
|
9
|
+
if (resultCount === 1) {
|
|
10
|
+
return translate("table.filters.result.count.one");
|
|
11
|
+
}
|
|
12
|
+
return translate("table.filters.result.count.many", { count: resultCount });
|
|
13
|
+
};
|
|
14
|
+
return isLoading ? (_jsx(Loader, { color: "gray", size: "xs" })) : (_jsx(Text, { size: "sm", children: getResultCountText() }));
|
|
15
|
+
};
|
|
16
|
+
export default ResultCount;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/ResultCount.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { ReactElement } from "react";
|
|
4
|
+
import { Loader, Text } from "@mantine/core";
|
|
5
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
6
|
+
|
|
7
|
+
interface ResultCountProps {
|
|
8
|
+
resultCount: number;
|
|
9
|
+
isLoading?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ResultCount = ({ resultCount, isLoading = false }: ResultCountProps): ReactElement => {
|
|
13
|
+
const getResultCountText = (): string => {
|
|
14
|
+
if (resultCount === 1) {
|
|
15
|
+
return translate("table.filters.result.count.one");
|
|
16
|
+
}
|
|
17
|
+
return translate("table.filters.result.count.many", { count: resultCount });
|
|
18
|
+
};
|
|
19
|
+
return isLoading ? (
|
|
20
|
+
<Loader color="gray" size="xs" />
|
|
21
|
+
) : (
|
|
22
|
+
<Text size="sm">{getResultCountText()}</Text>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default ResultCount;
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/SearchFilter.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
4
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { RiSearchLine as SearchIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
6
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
3
7
|
import { rem, TextInput } from "@mantine/core";
|
|
4
|
-
import {
|
|
5
|
-
// Local translation function
|
|
6
|
-
const translate = (key, params) => {
|
|
7
|
-
if (!params)
|
|
8
|
-
return key;
|
|
9
|
-
return Object.entries(params).reduce((str, [key, value]) => {
|
|
10
|
-
return str.replace(`{${key}}`, String(value));
|
|
11
|
-
}, key);
|
|
12
|
-
};
|
|
8
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
13
9
|
const debounce = (fn, timeout = 1000) => {
|
|
14
10
|
let timer;
|
|
15
11
|
return (value) => {
|
|
16
|
-
if (timer)
|
|
12
|
+
if (timer)
|
|
17
13
|
clearTimeout(timer);
|
|
18
|
-
|
|
19
|
-
timer = setTimeout(() => {
|
|
20
|
-
fn(value);
|
|
21
|
-
}, timeout);
|
|
14
|
+
timer = setTimeout(() => fn(value), timeout);
|
|
22
15
|
};
|
|
23
16
|
};
|
|
24
17
|
const SearchFilter = ({ searchTerm, onChange }) => {
|
|
25
|
-
const [
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
const [localSearchTerm, setLocalSearchTerm] = useState(searchTerm);
|
|
19
|
+
// DS-ADAPT: always call the latest onChange; the debounced fn is created once.
|
|
20
|
+
const onChangeRef = useRef(onChange);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onChangeRef.current = onChange;
|
|
23
|
+
});
|
|
24
|
+
const debouncedSearch = useRef(debounce(value => {
|
|
25
|
+
onChangeRef.current(value);
|
|
26
|
+
}, 300)).current;
|
|
27
|
+
const handleSearchChange = (value) => {
|
|
28
|
+
setLocalSearchTerm(value);
|
|
29
|
+
debouncedSearch(value);
|
|
31
30
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
31
|
+
const clearSearch = () => {
|
|
32
|
+
setLocalSearchTerm("");
|
|
34
33
|
onChange("");
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} }));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setLocalSearchTerm(searchTerm);
|
|
37
|
+
}, [searchTerm]);
|
|
38
|
+
return (_jsx(TextInput, { size: "xs", placeholder: translate("table.search.placeholder"), flex: "1 1 auto", onChange: (event) => handleSearchChange(event.target.value), rightSection: localSearchTerm === "" ? (_jsx(SearchIcon, { style: { width: rem(14), height: rem(14) } })) : (_jsx(CloseIcon, { "data-testid": "search-clear", onClick: clearSearch, style: { width: rem(14), height: rem(14), cursor: "pointer" } })), value: localSearchTerm }));
|
|
41
39
|
};
|
|
42
40
|
export default SearchFilter;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/SearchFilter.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { ReactElement, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { RiSearchLine as SearchIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
5
|
+
import { RiCloseLine as CloseIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
2
6
|
import { rem, TextInput } from "@mantine/core";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
// Local translation function
|
|
6
|
-
const translate = (key: string, params?: Record<string, any>) => {
|
|
7
|
-
if (!params) return key;
|
|
8
|
-
return Object.entries(params).reduce((str, [key, value]) => {
|
|
9
|
-
return str.replace(`{${key}}`, String(value));
|
|
10
|
-
}, key);
|
|
11
|
-
};
|
|
7
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
12
8
|
|
|
13
9
|
const debounce = (fn: (value: string) => void, timeout = 1000): ((value: string) => void) => {
|
|
14
10
|
let timer: NodeJS.Timeout | undefined;
|
|
15
|
-
return (value: string) => {
|
|
16
|
-
if (timer)
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
timer = setTimeout(() => {
|
|
20
|
-
fn(value);
|
|
21
|
-
}, timeout);
|
|
11
|
+
return (value: string): void => {
|
|
12
|
+
if (timer) clearTimeout(timer);
|
|
13
|
+
timer = setTimeout(() => fn(value), timeout);
|
|
22
14
|
};
|
|
23
15
|
};
|
|
24
16
|
|
|
@@ -28,44 +20,52 @@ interface SearchFilterProps {
|
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
const SearchFilter = ({ searchTerm, onChange }: SearchFilterProps): ReactElement => {
|
|
31
|
-
const [
|
|
23
|
+
const [localSearchTerm, setLocalSearchTerm] = useState<string>(searchTerm);
|
|
24
|
+
|
|
25
|
+
// DS-ADAPT: always call the latest onChange; the debounced fn is created once.
|
|
26
|
+
const onChangeRef = useRef(onChange);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
onChangeRef.current = onChange;
|
|
29
|
+
});
|
|
32
30
|
|
|
33
|
-
const
|
|
31
|
+
const debouncedSearch = useRef(
|
|
32
|
+
debounce(value => {
|
|
33
|
+
onChangeRef.current(value);
|
|
34
|
+
}, 300)
|
|
35
|
+
).current;
|
|
34
36
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
debouncedOnChange(newValue);
|
|
37
|
+
const handleSearchChange = (value: string): void => {
|
|
38
|
+
setLocalSearchTerm(value);
|
|
39
|
+
debouncedSearch(value);
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
-
|
|
42
|
+
const clearSearch = (): void => {
|
|
43
|
+
setLocalSearchTerm("");
|
|
43
44
|
onChange("");
|
|
44
45
|
};
|
|
45
46
|
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
setLocalSearchTerm(searchTerm);
|
|
49
|
+
}, [searchTerm]);
|
|
50
|
+
|
|
46
51
|
return (
|
|
47
52
|
<TextInput
|
|
48
53
|
size="xs"
|
|
49
54
|
placeholder={translate("table.search.placeholder")}
|
|
50
|
-
|
|
51
|
-
onChange={
|
|
55
|
+
flex="1 1 auto"
|
|
56
|
+
onChange={(event): void => handleSearchChange(event.target.value)}
|
|
52
57
|
rightSection={
|
|
53
|
-
|
|
54
|
-
<
|
|
58
|
+
localSearchTerm === "" ? (
|
|
59
|
+
<SearchIcon style={{ width: rem(14), height: rem(14) }} />
|
|
60
|
+
) : (
|
|
61
|
+
<CloseIcon
|
|
55
62
|
data-testid="search-clear"
|
|
56
|
-
onClick={
|
|
63
|
+
onClick={clearSearch}
|
|
57
64
|
style={{ width: rem(14), height: rem(14), cursor: "pointer" }}
|
|
58
65
|
/>
|
|
59
|
-
) : (
|
|
60
|
-
<IconSearch style={{ width: rem(14), height: rem(14) }} />
|
|
61
66
|
)
|
|
62
67
|
}
|
|
63
|
-
value={
|
|
64
|
-
styles={{
|
|
65
|
-
wrapper: {
|
|
66
|
-
fontSize: "var(--mantine-font-size-xs)",
|
|
67
|
-
},
|
|
68
|
-
}}
|
|
68
|
+
value={localSearchTerm}
|
|
69
69
|
/>
|
|
70
70
|
);
|
|
71
71
|
};
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/SelectFilter.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
4
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return str.replace(`{${key}}`, String(value));
|
|
10
|
-
}, key);
|
|
11
|
-
};
|
|
12
|
-
const SelectFilter = ({ label, data, selectedValue, onChange, placeholderEmpty = "All", placeholderWithSelection = "Select more" }) => {
|
|
13
|
-
const hasSelection = selectedValue && selectedValue.length > 0;
|
|
14
|
-
const placeholder = hasSelection ? placeholderWithSelection : placeholderEmpty;
|
|
15
|
-
return (_jsx(MultiSelect, { size: "xs", label: label, placeholder: placeholder, data: data, value: selectedValue || [], onChange: (value) => onChange(value.length > 0 ? value : null), clearable: true, styles: {
|
|
16
|
-
label: {
|
|
17
|
-
fontWeight: 600,
|
|
18
|
-
},
|
|
19
|
-
} }));
|
|
20
|
-
};
|
|
5
|
+
import { Select } from "@mantine/core";
|
|
6
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
7
|
+
import styles from "./SelectFilter.module.css";
|
|
8
|
+
const SelectFilter = ({ selectedValue, data, onChange, label, }) => (_jsx("div", { role: "menuitem", children: _jsx(Select, { className: styles.field, "data-testid": "select-filter", clearable: true, size: "xs", label: label, placeholder: translate("table.filters.show.all"), data: data, onChange: (value) => {
|
|
9
|
+
onChange(value);
|
|
10
|
+
}, value: selectedValue }) }));
|
|
21
11
|
export default SelectFilter;
|
|
@@ -1,50 +1,38 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomTopToolbar/SelectFilter.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
1
3
|
import React, { ReactElement } from "react";
|
|
2
|
-
import { ComboboxData,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const translate = (key: string, params?: Record<string, any>) => {
|
|
6
|
-
if (!params) return key;
|
|
7
|
-
return Object.entries(params).reduce((str, [key, value]) => {
|
|
8
|
-
return str.replace(`{${key}}`, String(value));
|
|
9
|
-
}, key);
|
|
10
|
-
};
|
|
4
|
+
import { ComboboxData, Select } from "@mantine/core";
|
|
5
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
6
|
+
import styles from "./SelectFilter.module.css";
|
|
11
7
|
|
|
12
8
|
export interface SelectFilterProps {
|
|
13
9
|
label: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
placeholderEmpty?: string;
|
|
18
|
-
placeholderWithSelection?: string;
|
|
10
|
+
selectedValue: string | null;
|
|
11
|
+
onChange: (value: string | null) => void;
|
|
12
|
+
data?: ComboboxData;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
const SelectFilter = ({
|
|
22
|
-
|
|
23
|
-
data,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<MultiSelect
|
|
15
|
+
const SelectFilter = ({
|
|
16
|
+
selectedValue,
|
|
17
|
+
data,
|
|
18
|
+
onChange,
|
|
19
|
+
label,
|
|
20
|
+
}: SelectFilterProps): ReactElement => (
|
|
21
|
+
<div role="menuitem">
|
|
22
|
+
<Select
|
|
23
|
+
className={styles.field}
|
|
24
|
+
data-testid="select-filter"
|
|
25
|
+
clearable
|
|
34
26
|
size="xs"
|
|
35
27
|
label={label}
|
|
36
|
-
placeholder={
|
|
28
|
+
placeholder={translate("table.filters.show.all")}
|
|
37
29
|
data={data}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
clearable
|
|
41
|
-
styles={{
|
|
42
|
-
label: {
|
|
43
|
-
fontWeight: 600,
|
|
44
|
-
},
|
|
30
|
+
onChange={(value): void => {
|
|
31
|
+
onChange(value);
|
|
45
32
|
}}
|
|
33
|
+
value={selectedValue}
|
|
46
34
|
/>
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
49
37
|
|
|
50
38
|
export default SelectFilter;
|