@appdirect/design-system 0.0.10 → 0.0.12
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/README.md +85 -5
- package/dist/Buttons/ActionIcon.js +14 -0
- package/dist/Buttons/Button.js +66 -0
- package/dist/Buttons/CloseButton.js +48 -0
- package/dist/Buttons/index.js +13 -0
- package/dist/Combobox/AutocompleteClearable.js +36 -0
- package/dist/Combobox/Combobox.js +28 -0
- package/dist/Combobox/Multiselect.js +31 -0
- package/dist/Combobox/SearchableSelect.js +43 -0
- package/dist/Combobox/Select.js +72 -0
- package/dist/Combobox/index.js +10 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +96 -0
- package/dist/ComplexComponents/DashboardWidget/index.js +1 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +82 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +23 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +23 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +230 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +30 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.js +12 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.js +32 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.js +90 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.js +43 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.js +30 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.js +39 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.js +9 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +31 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +42 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +21 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +410 -0
- package/dist/ComplexComponents/DataTable/DataTable.js +405 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +9 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +27 -0
- package/dist/ComplexComponents/DataTable/index.js +1 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +99 -0
- package/dist/ComplexComponents/DataTable/translations/index.js +17 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.js +176 -0
- package/dist/ComplexComponents/KeyInsight/index.js +1 -0
- package/dist/ComplexComponents/NameValue/NameValue.js +94 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.js +59 -0
- package/dist/ComplexComponents/NameValue/index.js +2 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.js +92 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +24 -34
- package/dist/ComplexComponents/PageContentHeader/index.js +1 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +0 -2
- package/dist/ComplexComponents/Placeholder/Placeholder.js +51 -0
- package/dist/ComplexComponents/Placeholder/index.js +1 -0
- package/dist/ComplexComponents/Slat/Slat.js +53 -0
- package/dist/ComplexComponents/Slat/index.js +1 -0
- package/dist/ComplexComponents/Utilities/CopyButton.js +45 -0
- package/dist/ComplexComponents/Utilities/index.js +1 -0
- package/dist/DataDisplay/Alert.js +77 -0
- package/dist/DataDisplay/Avatar.js +157 -0
- package/dist/DataDisplay/Badge.js +78 -0
- package/dist/DataDisplay/Card.js +100 -0
- package/dist/DataDisplay/Chip.js +36 -0
- package/dist/DataDisplay/Indicator.js +59 -0
- package/dist/DataDisplay/List.js +60 -0
- package/dist/DataDisplay/Pill.js +81 -0
- package/dist/DataDisplay/Progress.js +42 -0
- package/dist/DataDisplay/Table.js +38 -0
- package/dist/DataDisplay/ThemeIcon.js +31 -0
- package/dist/DataDisplay/index.js +18 -0
- package/dist/Inputs/Checkbox.js +62 -0
- package/dist/Inputs/ColorInput.js +48 -0
- package/dist/Inputs/DropZone.js +12 -0
- package/dist/Inputs/FileInput.js +77 -0
- package/dist/Inputs/NumberInput.js +49 -0
- package/dist/Inputs/Radio.js +55 -0
- package/dist/Inputs/RadioGroup.js +59 -0
- package/dist/Inputs/SegmentedControl.js +50 -0
- package/dist/Inputs/Slider.js +50 -0
- package/dist/Inputs/SliderWithLabel.js +32 -0
- package/dist/Inputs/Switch.js +47 -0
- package/dist/Inputs/TextArea.js +50 -0
- package/dist/Inputs/TextInput.js +87 -0
- package/dist/Inputs/index.js +27 -0
- package/dist/Layout/Box.js +39 -0
- package/dist/Layout/Center.js +11 -0
- package/dist/Layout/Container.js +11 -0
- package/dist/Layout/Flex.js +12 -0
- package/dist/Layout/Grid.js +13 -0
- package/dist/Layout/Group.js +14 -0
- package/dist/Layout/Inline.js +46 -0
- package/dist/Layout/SimpleGrid.js +14 -0
- package/dist/Layout/Stack.js +45 -0
- package/dist/Layout/index.js +10 -0
- package/dist/Misc/Divider.js +8 -0
- package/dist/Misc/Paper.js +24 -0
- package/dist/Misc/index.js +10 -0
- package/dist/Navigation/Breadcrumb.js +60 -0
- package/dist/Navigation/NavLink.js +28 -0
- package/dist/Navigation/Stepper.js +8 -0
- package/dist/Navigation/Tabs.js +22 -0
- package/dist/Navigation/index.js +9 -0
- package/dist/Overlays/Drawer.js +63 -0
- package/dist/Overlays/Menu.js +85 -0
- package/dist/Overlays/Modal.js +61 -0
- package/dist/Overlays/Popover.js +118 -0
- package/dist/Overlays/Tooltip.js +71 -0
- package/dist/Overlays/index.js +12 -0
- package/dist/Shell/AppShellLayout.js +13 -0
- package/dist/Shell/HeaderBar.js +8 -0
- package/dist/Shell/SidebarNav.js +9 -0
- package/dist/Shell/SidebarNavLink.js +17 -0
- package/dist/Shell/SingleColumnLayout.js +11 -0
- package/dist/Shell/TertiaryColumnLayout.js +12 -0
- package/dist/Shell/index.js +6 -0
- package/dist/Typography/Code.js +8 -0
- package/dist/Typography/Kbd.js +58 -0
- package/dist/Typography/Text.js +8 -0
- package/dist/Typography/Title.js +11 -0
- package/dist/Typography/index.js +12 -0
- package/dist/config.js +202 -0
- package/dist/contracts/PageContentHeader.json +10 -5
- package/dist/contracts/index.json +1 -1
- package/dist/hooks/useTableHandlers.js +136 -0
- package/dist/hooks/useTableRenderFunctions.js +164 -0
- package/dist/hooks/useTableState.js +70 -0
- package/dist/index.js +162 -0
- package/dist/index.ts +3 -4
- package/dist/stories/Buttons/ActionIcon.stories.tsx +159 -0
- package/dist/stories/Buttons/Button.stories.tsx +145 -0
- package/dist/stories/Buttons/CloseButton.stories.tsx +121 -0
- package/dist/stories/Combobox/AutocompleteClearable.stories.tsx +554 -0
- package/dist/stories/Combobox/Combobox.stories.tsx +106 -0
- package/dist/stories/Combobox/Multiselect.stories.tsx +664 -0
- package/dist/stories/Combobox/SearchableSelect.stories.tsx +640 -0
- package/dist/stories/Combobox/Select.stories.tsx +311 -0
- package/dist/stories/ComplexComponents/DashboardWidget/DashboardWidget.stories.tsx +822 -0
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +502 -0
- package/dist/stories/ComplexComponents/KeyInsight/KeyInsights.stories.tsx +386 -0
- package/dist/stories/ComplexComponents/NameValue/NameValue.stories.tsx +405 -0
- package/dist/stories/ComplexComponents/PageContentHeader/PageContentHeader.stories.tsx +527 -0
- package/dist/stories/ComplexComponents/Placeholder/Placeholder.stories.tsx +76 -0
- package/dist/stories/ComplexComponents/Slat/Slat.stories.tsx +79 -0
- package/dist/stories/ComplexComponents/Utilities/CopyButton.stories.tsx +479 -0
- package/dist/stories/DataDisplay/Alert.stories.tsx +296 -0
- package/dist/stories/DataDisplay/Avatar.stories.tsx +251 -0
- package/dist/stories/DataDisplay/Badge.stories.tsx +176 -0
- package/dist/stories/DataDisplay/Card.stories.tsx +406 -0
- package/dist/stories/DataDisplay/Chip.stories.tsx +495 -0
- package/dist/stories/DataDisplay/Indicator.stories.tsx +571 -0
- package/dist/stories/DataDisplay/List.stories.tsx +376 -0
- package/dist/stories/DataDisplay/Pill.stories.tsx +506 -0
- package/dist/stories/DataDisplay/Progress.stories.tsx +352 -0
- package/dist/stories/DataDisplay/Table.stories.tsx +346 -0
- package/dist/stories/DataDisplay/ThemeIcon.stories.tsx +125 -0
- package/dist/stories/Inputs/Checkbox.stories.tsx +263 -0
- package/dist/stories/Inputs/ColorInput.stories.tsx +434 -0
- package/dist/stories/Inputs/DropZone.stories.tsx +401 -0
- package/dist/stories/Inputs/FileInput.stories.tsx +383 -0
- package/dist/stories/Inputs/NumberInput.stories.tsx +342 -0
- package/dist/stories/Inputs/Radio.stories.tsx +437 -0
- package/dist/stories/Inputs/RadioGroup.stories.tsx +526 -0
- package/dist/stories/Inputs/SegmentedControl.stories.tsx +60 -0
- package/dist/stories/Inputs/Slider.stories.tsx +22 -0
- package/dist/stories/Inputs/SliderWithLabel.stories.tsx +37 -0
- package/dist/stories/Inputs/Switch.stories.tsx +361 -0
- package/dist/stories/Inputs/TextArea.stories.tsx +355 -0
- package/dist/stories/Inputs/TextInput.stories.tsx +266 -0
- package/dist/stories/Misc/Divider.stories.tsx +581 -0
- package/dist/stories/Misc/Paper.stories.tsx +557 -0
- package/dist/stories/Navigation/Breadcrumb.stories.tsx +489 -0
- package/dist/stories/Navigation/NavLink.stories.tsx +601 -0
- package/dist/stories/Navigation/Stepper.stories.tsx +413 -0
- package/dist/stories/Navigation/Tabs.stories.tsx +528 -0
- package/dist/stories/Overlays/Drawer.stories.tsx +802 -0
- package/dist/stories/Overlays/Menu.stories.tsx +941 -0
- package/dist/stories/Overlays/Modal.stories.tsx +249 -0
- package/dist/stories/Overlays/Popover.stories.tsx +780 -0
- package/dist/stories/Overlays/Tooltip.stories.tsx +52 -0
- package/dist/stories/Typography/Code.stories.tsx +368 -0
- package/dist/stories/Typography/Kbd.stories.tsx +514 -0
- package/dist/stories/Typography/Text.stories.tsx +117 -0
- package/dist/stories/Typography/Title.stories.tsx +112 -0
- package/dist/stories/index.json +1435 -0
- package/dist/types.js +127 -0
- package/package.json +12 -7
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +0 -65
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { Select, rem, ActionIcon, Text } from '@mantine/core';
|
|
4
|
+
import { Inline } from '../../../index.js';
|
|
5
|
+
import { translate } from '../translations/index.js';
|
|
6
|
+
import { RiArrowLeftSLine, RiArrowRightSLine } from '@remixicon/react';
|
|
7
|
+
// Constants
|
|
8
|
+
const PAGE_SIZE_OPTIONS = [
|
|
9
|
+
{ value: "5", label: "5" },
|
|
10
|
+
{ value: "10", label: "10" },
|
|
11
|
+
{ value: "25", label: "25" },
|
|
12
|
+
{ value: "50", label: "50" },
|
|
13
|
+
{ value: "100", label: "100" },
|
|
14
|
+
];
|
|
15
|
+
const TOOLBAR_STYLES = {
|
|
16
|
+
container: {
|
|
17
|
+
borderTop: "1px solid var(--ad-color-border-subtle)",
|
|
18
|
+
padding: `${rem(5)} ${rem(12)}`,
|
|
19
|
+
backgroundColor: "var(--ad-color-bg-subtle)",
|
|
20
|
+
},
|
|
21
|
+
select: {
|
|
22
|
+
width: "80px",
|
|
23
|
+
},
|
|
24
|
+
selectInput: {
|
|
25
|
+
backgroundColor: "transparent",
|
|
26
|
+
border: "none",
|
|
27
|
+
color: "var(--ad-color-text-default)",
|
|
28
|
+
fontSize: "var(--mantine-font-size-xs)",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generate the appropriate selected rows text based on count
|
|
33
|
+
*/
|
|
34
|
+
const useSelectedRowsText = (numberOfSelectedRows) => {
|
|
35
|
+
return useMemo(() => {
|
|
36
|
+
if (numberOfSelectedRows === 0)
|
|
37
|
+
return null;
|
|
38
|
+
return numberOfSelectedRows === 1
|
|
39
|
+
? translate("table.selected.row")
|
|
40
|
+
: translate("table.selected.rows", { count: numberOfSelectedRows });
|
|
41
|
+
}, [numberOfSelectedRows]);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Calculate pagination information
|
|
45
|
+
*/
|
|
46
|
+
const usePaginationInfo = (pageIndex, totalCount, pageSize) => {
|
|
47
|
+
return useMemo(() => ({
|
|
48
|
+
totalPages: Math.ceil(totalCount / pageSize),
|
|
49
|
+
currentPage: pageIndex + 1,
|
|
50
|
+
}), [pageIndex, totalCount, pageSize]);
|
|
51
|
+
};
|
|
52
|
+
const CustomBottomToolbar = ({ table, totalCount, pageInfo, numberOfSelectedRows = 0, }) => {
|
|
53
|
+
const { getState, setPageIndex, setPageSize } = table;
|
|
54
|
+
const { pagination } = getState();
|
|
55
|
+
const { pageIndex, pageSize } = pagination;
|
|
56
|
+
const selectedRowsText = useSelectedRowsText(numberOfSelectedRows);
|
|
57
|
+
const { totalPages, currentPage } = usePaginationInfo(pageIndex, totalCount, pageSize);
|
|
58
|
+
const handlePageSizeChange = (value) => {
|
|
59
|
+
if (value) {
|
|
60
|
+
setPageSize(Number(value));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handlePreviousPage = () => {
|
|
64
|
+
if (pageIndex > 0) {
|
|
65
|
+
setPageIndex(pageIndex - 1);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handleNextPage = () => {
|
|
69
|
+
if (pageIndex < totalPages - 1) {
|
|
70
|
+
setPageIndex(pageIndex + 1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const canGoPrevious = pageIndex > 0;
|
|
74
|
+
const canGoNext = pageIndex < totalPages - 1;
|
|
75
|
+
return (_jsxs(Inline, { justify: "space-between", style: TOOLBAR_STYLES.container, children: [_jsxs(Inline, { gap: "xs", children: [_jsx(Text, { size: "sm", children: translate("table.rows.per.page") }), _jsx(Select, { size: "xs", value: String(pageSize), onChange: handlePageSizeChange, data: PAGE_SIZE_OPTIONS, style: TOOLBAR_STYLES.select, styles: {
|
|
76
|
+
input: TOOLBAR_STYLES.selectInput,
|
|
77
|
+
}, "aria-label": translate("table.rows.per.page") })] }), _jsx(Inline, { gap: "xs", children: selectedRowsText && (_jsx(Text, { size: "sm", children: selectedRowsText })) }), _jsxs(Inline, { gap: "xs", children: [_jsx(ActionIcon, { variant: "subtle", color: "gray", size: "sm", onClick: handlePreviousPage, disabled: !canGoPrevious, "aria-label": "Previous page", children: _jsx(RiArrowLeftSLine, { size: 16 }) }), _jsx(Text, { size: "sm", children: translate("table.pagination.page", {
|
|
78
|
+
current: currentPage,
|
|
79
|
+
total: totalPages,
|
|
80
|
+
}) }), _jsx(ActionIcon, { variant: "subtle", color: "gray", size: "sm", onClick: handleNextPage, disabled: !canGoNext, "aria-label": "Next page", children: _jsx(RiArrowRightSLine, { size: 16 }) })] })] }));
|
|
81
|
+
};
|
|
82
|
+
export default CustomBottomToolbar;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { translate } from "../translations/index.js";
|
|
2
|
+
const DEFAULT_PAGE_SIZE = 5;
|
|
3
|
+
export const getFormattedPageSize = (newPageSize) => newPageSize ? parseInt(newPageSize, 10) : DEFAULT_PAGE_SIZE;
|
|
4
|
+
export const getFormattedPageCount = (pageIndex, pageSize, rowCount) => {
|
|
5
|
+
const firstRowIndex = rowCount ? pageIndex * pageSize + 1 : 0;
|
|
6
|
+
const clampedFirstRowIndex = Math.min(firstRowIndex, rowCount);
|
|
7
|
+
const lastRowIndex = Math.min(clampedFirstRowIndex + pageSize - 1, rowCount);
|
|
8
|
+
return translate("table.row.count", {
|
|
9
|
+
start: clampedFirstRowIndex,
|
|
10
|
+
end: lastRowIndex,
|
|
11
|
+
total: rowCount,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export const getNumOfRowsPerPageOptions = (totalNumOfRows, increment = DEFAULT_PAGE_SIZE) => {
|
|
15
|
+
if (!totalNumOfRows) {
|
|
16
|
+
return [increment.toString()];
|
|
17
|
+
}
|
|
18
|
+
const options = [];
|
|
19
|
+
for (let i = increment; i - increment < totalNumOfRows; i += increment) {
|
|
20
|
+
options.push(i.toString());
|
|
21
|
+
}
|
|
22
|
+
return options;
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Text, ActionIcon } from '@mantine/core';
|
|
4
|
+
import { Inline } from '../../../index.js';
|
|
5
|
+
import { Button } from '../../../index.js';
|
|
6
|
+
import { IconX } from '@tabler/icons-react';
|
|
7
|
+
import { RiFlashlightFill } from '@remixicon/react';
|
|
8
|
+
import { translate } from '../translations/index.js';
|
|
9
|
+
const CustomToolbarAlertBannerContent = ({ numberOfSelectedRows, onClearSelection, }) => {
|
|
10
|
+
if (numberOfSelectedRows === 0) {
|
|
11
|
+
return _jsx(_Fragment, {});
|
|
12
|
+
}
|
|
13
|
+
const selectedRowsText = numberOfSelectedRows === 1
|
|
14
|
+
? translate("table.selected.row")
|
|
15
|
+
: translate("table.selected.rows", { count: numberOfSelectedRows });
|
|
16
|
+
return (_jsxs(Inline, { gap: "sm", align: "center", style: {
|
|
17
|
+
background: 'var(--ad-color-brand-primary)',
|
|
18
|
+
color: 'var(--ad-white)',
|
|
19
|
+
borderRadius: 0,
|
|
20
|
+
minHeight: 'var(--mantine-spacing-xl)',
|
|
21
|
+
}, children: [_jsx(ActionIcon, { variant: "transparent", color: "white", onClick: onClearSelection, "aria-label": "Clear selection", size: "sm", children: _jsx(IconX, { size: 16 }) }), _jsx(Button, { variant: "outline", color: "gray", size: "xs", leftSection: _jsx(RiFlashlightFill, { size: 16 }), style: { borderColor: 'white', color: 'white' }, children: "Button one" }), _jsx(Button, { variant: "outline", color: "gray", size: "xs", leftSection: _jsx(RiFlashlightFill, { size: 16 }), style: { borderColor: 'white', color: 'white' }, children: "Button two" }), _jsx(Text, { size: "sm", c: "white", fw: 500, children: selectedRowsText })] }));
|
|
22
|
+
};
|
|
23
|
+
export default CustomToolbarAlertBannerContent;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo, useState } from "react";
|
|
3
|
+
import { CloseButton, Combobox, InputBase, InputPlaceholder, Popover, useCombobox, } from "@mantine/core";
|
|
4
|
+
import { DatePicker } from "@mantine/dates";
|
|
5
|
+
import { translate } from '../../translations/index.js';
|
|
6
|
+
/** Local-calendar YYYY-MM-DD for Mantine DatePicker string values */
|
|
7
|
+
function toDateStringValue(d) {
|
|
8
|
+
const y = d.getFullYear();
|
|
9
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
10
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
11
|
+
return `${y}-${m}-${day}`;
|
|
12
|
+
}
|
|
13
|
+
function formatDateValueLocale(v, locale) {
|
|
14
|
+
if (v == null)
|
|
15
|
+
return "";
|
|
16
|
+
const d = typeof v === "string" ? new Date(`${v}T12:00:00`) : v;
|
|
17
|
+
return d.toLocaleDateString(locale);
|
|
18
|
+
}
|
|
19
|
+
function toPickerDate(v) {
|
|
20
|
+
if (v == null)
|
|
21
|
+
return new Date();
|
|
22
|
+
return typeof v === "string" ? new Date(`${v}T12:00:00`) : v;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Enum defining available preset date range options
|
|
26
|
+
*/
|
|
27
|
+
var Preset;
|
|
28
|
+
(function (Preset) {
|
|
29
|
+
Preset["WEEK"] = "week";
|
|
30
|
+
Preset["MONTH"] = "month";
|
|
31
|
+
Preset["QUARTER"] = "quarter";
|
|
32
|
+
Preset["CUSTOM"] = "custom";
|
|
33
|
+
})(Preset || (Preset = {}));
|
|
34
|
+
/**
|
|
35
|
+
* Returns available preset options with translated labels
|
|
36
|
+
* @returns Array of preset options for the dropdown
|
|
37
|
+
*/
|
|
38
|
+
const getPresets = () => [
|
|
39
|
+
{
|
|
40
|
+
label: translate("table.filters.date.range.week"),
|
|
41
|
+
value: Preset.WEEK,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: translate("table.filters.date.range.month"),
|
|
45
|
+
value: Preset.MONTH,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: translate("table.filters.date.range.quarter"),
|
|
49
|
+
value: Preset.QUARTER,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: translate("table.filters.date.range.custom"),
|
|
53
|
+
value: Preset.CUSTOM,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* Finds and returns the display label for a given preset value
|
|
58
|
+
* @param value - The preset value to look up
|
|
59
|
+
* @returns The translated label or empty string if not found
|
|
60
|
+
*/
|
|
61
|
+
const getPresetLabel = (value) => {
|
|
62
|
+
return getPresets().find(item => item.value === value)?.label || "";
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Calculates date range for preset options (last N days/months/quarters)
|
|
66
|
+
* @param preset - The preset type to calculate range for
|
|
67
|
+
* @returns Tuple of [startDate, endDate] or null for invalid preset
|
|
68
|
+
*/
|
|
69
|
+
const getDateRangeFromPreset = (preset) => {
|
|
70
|
+
const now = new Date();
|
|
71
|
+
const start = new Date();
|
|
72
|
+
switch (preset) {
|
|
73
|
+
case Preset.WEEK:
|
|
74
|
+
start.setDate(now.getDate() - 7);
|
|
75
|
+
break;
|
|
76
|
+
case Preset.MONTH:
|
|
77
|
+
start.setMonth(now.getMonth() - 1);
|
|
78
|
+
break;
|
|
79
|
+
case Preset.QUARTER:
|
|
80
|
+
start.setMonth(now.getMonth() - 3);
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return [toDateStringValue(start), toDateStringValue(now)];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* DateRangeSelector - A sophisticated date range filter component with preset options
|
|
89
|
+
* and custom date selection via floating calendar dialog.
|
|
90
|
+
*
|
|
91
|
+
* Features:
|
|
92
|
+
* - Preset options: Last week, month, quarter
|
|
93
|
+
* - Custom date range selection with floating calendar
|
|
94
|
+
* - Proper state management with rollback capability
|
|
95
|
+
* - Localized date display and formatting
|
|
96
|
+
* - Clear functionality with visual feedback
|
|
97
|
+
*/
|
|
98
|
+
const DateRangeSelector = ({ label, locale, onChange }) => {
|
|
99
|
+
// Main state management for date filter selections
|
|
100
|
+
const [dateFilterState, setDateFilterState] = useState({
|
|
101
|
+
previousPreset: null,
|
|
102
|
+
preset: null,
|
|
103
|
+
customDateRange: [null, null],
|
|
104
|
+
});
|
|
105
|
+
// Destructure state for easier access
|
|
106
|
+
const { preset, customDateRange } = dateFilterState;
|
|
107
|
+
// Controls visibility of the floating date picker
|
|
108
|
+
const [isDatePickerOpened, setIsDatePickerOpened] = useState(false);
|
|
109
|
+
/**
|
|
110
|
+
* Checks if a complete custom date range has been selected
|
|
111
|
+
* @param value - The preset value to check
|
|
112
|
+
* @returns True if custom preset with both start and end dates selected
|
|
113
|
+
*/
|
|
114
|
+
const isDateRangeSelected = (value) => {
|
|
115
|
+
return value === Preset.CUSTOM && customDateRange[0] !== null && customDateRange[1] !== null;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Determines what value to display in the input field
|
|
119
|
+
* Handles different states: empty, preset selected, custom dates, partial custom selection
|
|
120
|
+
*/
|
|
121
|
+
const getValueDisplayed = useMemo(() => {
|
|
122
|
+
// Show formatted date range for completed custom selection
|
|
123
|
+
if (isDateRangeSelected(preset)) {
|
|
124
|
+
return `${formatDateValueLocale(customDateRange[0], locale)} - ${formatDateValueLocale(customDateRange[1], locale)}`;
|
|
125
|
+
}
|
|
126
|
+
// Show helper text for partial custom selection
|
|
127
|
+
if (preset === Preset.CUSTOM) {
|
|
128
|
+
return translate("table.filters.date.range.select");
|
|
129
|
+
}
|
|
130
|
+
// Show preset label for selected presets
|
|
131
|
+
if (preset) {
|
|
132
|
+
return getPresetLabel(preset);
|
|
133
|
+
}
|
|
134
|
+
// Show placeholder for empty state
|
|
135
|
+
return _jsx(InputPlaceholder, { children: translate("table.filters.show.all") });
|
|
136
|
+
}, [preset, customDateRange, locale]);
|
|
137
|
+
/**
|
|
138
|
+
* Combobox configuration for dropdown behavior
|
|
139
|
+
* Handles dropdown close events and option selection
|
|
140
|
+
*/
|
|
141
|
+
const combobox = useCombobox({
|
|
142
|
+
onDropdownClose: () => {
|
|
143
|
+
// Reset selected option when dropdown closes
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Renders preset options for the dropdown menu
|
|
148
|
+
*/
|
|
149
|
+
const options = getPresets().map(item => (_jsx(Combobox.Option, { value: item.value, children: item.label }, item.value)));
|
|
150
|
+
/**
|
|
151
|
+
* Handles clearing the current selection
|
|
152
|
+
* Resets all state and notifies parent component
|
|
153
|
+
*/
|
|
154
|
+
const handleClearClick = () => {
|
|
155
|
+
setDateFilterState(prev => ({
|
|
156
|
+
previousPreset: prev.preset,
|
|
157
|
+
preset: null,
|
|
158
|
+
customDateRange: [null, null],
|
|
159
|
+
}));
|
|
160
|
+
setIsDatePickerOpened(false);
|
|
161
|
+
onChange(null);
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Handles selection of preset options from dropdown
|
|
165
|
+
* @param value - The selected preset value
|
|
166
|
+
*/
|
|
167
|
+
const handlePresetChange = (value) => {
|
|
168
|
+
combobox.closeDropdown();
|
|
169
|
+
// Update state with new selection
|
|
170
|
+
setDateFilterState(prev => ({
|
|
171
|
+
...prev,
|
|
172
|
+
previousPreset: prev.preset,
|
|
173
|
+
preset: value,
|
|
174
|
+
}));
|
|
175
|
+
if (value === Preset.CUSTOM) {
|
|
176
|
+
// Open floating date picker for custom selection
|
|
177
|
+
setIsDatePickerOpened(true);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// Apply preset date range immediately and close any open picker
|
|
181
|
+
setIsDatePickerOpened(false);
|
|
182
|
+
onChange(getDateRangeFromPreset(value));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Handles clicks on the main input button
|
|
187
|
+
* Toggles dropdown or date picker based on current state
|
|
188
|
+
*/
|
|
189
|
+
const handleInputBaseClick = () => {
|
|
190
|
+
if (!isDatePickerOpened) {
|
|
191
|
+
// Open dropdown for preset selection
|
|
192
|
+
combobox.toggleDropdown();
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// Close date picker
|
|
196
|
+
setIsDatePickerOpened(false);
|
|
197
|
+
// Revert to previous preset if no complete date range was selected
|
|
198
|
+
if (customDateRange[0] === null && customDateRange[1] === null) {
|
|
199
|
+
setDateFilterState(prev => ({
|
|
200
|
+
...prev,
|
|
201
|
+
previousPreset: prev.preset,
|
|
202
|
+
preset: prev.previousPreset,
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Handles date range changes from the floating date picker
|
|
209
|
+
* @param value - The selected date range [startDate, endDate]
|
|
210
|
+
*/
|
|
211
|
+
const handleDatePickerChange = (value) => {
|
|
212
|
+
// Update state and notify parent immediately for real-time filtering
|
|
213
|
+
setDateFilterState(prev => ({ ...prev, customDateRange: value }));
|
|
214
|
+
onChange(value);
|
|
215
|
+
// Auto-close the picker when both dates are selected (complete range)
|
|
216
|
+
if (value[0] !== null && value[1] !== null) {
|
|
217
|
+
setIsDatePickerOpened(false);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
return (_jsxs(Popover, { opened: isDatePickerOpened, position: "bottom-start", children: [_jsx(Popover.Target, { children: _jsx("div", { role: "menuitem", children: _jsxs(Combobox, { size: "xs", store: combobox, withinPortal: false, onOptionSubmit: handlePresetChange, children: [_jsx(Combobox.Target, { children: _jsx(InputBase, { component: "button", type: "button", size: "xs", pointer: true, rightSection: preset ? (
|
|
221
|
+
/* Clear button - shown when something is selected */
|
|
222
|
+
_jsx(CloseButton, { size: "xs", variant: "transparent", onMouseDown: (event) => event.preventDefault(), onClick: handleClearClick, "aria-label": "Clear date range" })) : (
|
|
223
|
+
/* Dropdown chevron - shown when nothing is selected */
|
|
224
|
+
_jsx(Combobox.Chevron, { size: "xs" })), onClick: handleInputBaseClick, rightSectionPointerEvents: preset === null ? "none" : "all", label: label, styles: {
|
|
225
|
+
label: {
|
|
226
|
+
fontWeight: 600,
|
|
227
|
+
},
|
|
228
|
+
}, children: getValueDisplayed }) }), _jsx(Combobox.Dropdown, { children: _jsx(Combobox.Options, { children: options }) })] }) }) }), _jsx(Popover.Dropdown, { children: _jsx(DatePicker, { id: "date-picker", "data-testid": "date-picker", type: "range", value: customDateRange, onChange: handleDatePickerChange, defaultDate: toPickerDate(customDateRange[0] ?? customDateRange[1]) }) })] }));
|
|
229
|
+
};
|
|
230
|
+
export default DateRangeSelector;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Chip } from "@mantine/core";
|
|
4
|
+
import { RiCloseLine } from '@remixicon/react';
|
|
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
|
+
*/
|
|
9
|
+
const FilterChip = ({ label, onClick }) => {
|
|
10
|
+
return (_jsx(Chip, { color: "gray", size: "xs", variant: "outline", checked: true, onChange: onClick, icon: _jsx(RiCloseLine, { size: 12 }), styles: {
|
|
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 }));
|
|
29
|
+
};
|
|
30
|
+
export default FilterChip;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import DateRangeSelector from '../DateRangeSelectorFilter/index.js';
|
|
4
|
+
import { translate } from '../../translations/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* DateRangeFilter - Renders a date range picker within the flexible filter system
|
|
7
|
+
*/
|
|
8
|
+
const DateRangeFilter = ({ config, value, onChange, }) => {
|
|
9
|
+
const dateConfig = config;
|
|
10
|
+
return (_jsx(DateRangeSelector, { label: translate(config.labelKey), locale: dateConfig.locale || 'en-US', onChange: onChange }));
|
|
11
|
+
};
|
|
12
|
+
export default DateRangeFilter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Box } from '@mantine/core';
|
|
4
|
+
import DateRangeFilter from './DateRangeFilter.js';
|
|
5
|
+
import SingleSelectFilter from './SingleSelectFilter.js';
|
|
6
|
+
import MultiSelectFilter from './MultiSelectFilter.js';
|
|
7
|
+
import { FilterType } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* FilterRenderer - Factory component that renders the appropriate filter type
|
|
10
|
+
* based on the configuration provided
|
|
11
|
+
*/
|
|
12
|
+
const FilterRenderer = ({ config, value, onChange, }) => {
|
|
13
|
+
// Don't render if filter is explicitly disabled
|
|
14
|
+
if (config.enabled === false) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const renderFilter = () => {
|
|
18
|
+
switch (config.type) {
|
|
19
|
+
case FilterType.DATE_RANGE:
|
|
20
|
+
return (_jsx(DateRangeFilter, { config: config, value: value, onChange: onChange }));
|
|
21
|
+
case FilterType.SINGLE_SELECT:
|
|
22
|
+
return (_jsx(SingleSelectFilter, { config: config, value: value, onChange: onChange }));
|
|
23
|
+
case FilterType.MULTI_SELECT:
|
|
24
|
+
return (_jsx(MultiSelectFilter, { config: config, value: value, onChange: onChange }));
|
|
25
|
+
default:
|
|
26
|
+
console.warn(`Unknown filter type: ${config.type}`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return (_jsx(Box, { className: config.className, children: renderFilter() }));
|
|
31
|
+
};
|
|
32
|
+
export default FilterRenderer;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Box, Alert } from '@mantine/core';
|
|
4
|
+
import { SimpleGrid } from '../../../../index.js';
|
|
5
|
+
import { IconAlertCircle } from '@tabler/icons-react';
|
|
6
|
+
import FilterRenderer from './FilterRenderer.js';
|
|
7
|
+
import { translate } from '../../translations/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Validates filter system configuration
|
|
10
|
+
*/
|
|
11
|
+
const validateFilterConfig = (config) => {
|
|
12
|
+
const errors = [];
|
|
13
|
+
const warnings = [];
|
|
14
|
+
// Check maximum filters limit
|
|
15
|
+
const maxFilters = config.maxFilters || 6;
|
|
16
|
+
if (config.filters.length > maxFilters) {
|
|
17
|
+
errors.push(translate('table.filters.system.validation.max.exceeded', {
|
|
18
|
+
maxFilters: maxFilters.toString(),
|
|
19
|
+
filterCount: config.filters.length.toString(),
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
// Check for duplicate IDs
|
|
23
|
+
const filterIds = config.filters.map(f => f.id);
|
|
24
|
+
const duplicateIds = filterIds.filter((id, index) => filterIds.indexOf(id) !== index);
|
|
25
|
+
if (duplicateIds.length > 0) {
|
|
26
|
+
errors.push(translate('table.filters.system.validation.duplicate.ids', {
|
|
27
|
+
duplicateIds: duplicateIds.join(', '),
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
// Check for missing required fields
|
|
31
|
+
config.filters.forEach(filter => {
|
|
32
|
+
if (!filter.id) {
|
|
33
|
+
errors.push(translate('table.filters.system.validation.missing.id'));
|
|
34
|
+
}
|
|
35
|
+
if (!filter.labelKey) {
|
|
36
|
+
warnings.push(translate('table.filters.system.validation.missing.label', {
|
|
37
|
+
filterId: filter.id,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
isValid: errors.length === 0,
|
|
43
|
+
errors,
|
|
44
|
+
warnings,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* FilterSystem - Main component for managing multiple filters with layout and validation
|
|
49
|
+
*/
|
|
50
|
+
const FilterSystem = ({ filters, values, onChange, visible = true, columns = 3, maxFilters = 6, }) => {
|
|
51
|
+
// Validate configuration
|
|
52
|
+
const validation = validateFilterConfig({
|
|
53
|
+
filters,
|
|
54
|
+
values,
|
|
55
|
+
onChange,
|
|
56
|
+
visible,
|
|
57
|
+
columns,
|
|
58
|
+
maxFilters
|
|
59
|
+
});
|
|
60
|
+
// Don't render if not visible
|
|
61
|
+
if (!visible) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// Show validation errors
|
|
65
|
+
if (!validation.isValid) {
|
|
66
|
+
return (_jsx(Alert, { color: "red", icon: _jsx(IconAlertCircle, { size: 16 }), title: translate('table.filters.system.validation.title'), children: _jsx("ul", { children: validation.errors.map((error, index) => (_jsx("li", { children: error }, index))) }) }));
|
|
67
|
+
}
|
|
68
|
+
// Show warnings in development
|
|
69
|
+
if (validation.warnings.length > 0 && process.env.NODE_ENV === 'development') {
|
|
70
|
+
console.warn('Filter System Warnings:', validation.warnings);
|
|
71
|
+
}
|
|
72
|
+
// Limit filters to maximum allowed
|
|
73
|
+
const limitedFilters = filters.slice(0, maxFilters);
|
|
74
|
+
const handleFilterChange = (filterId, value, filterType) => {
|
|
75
|
+
const changeEvent = {
|
|
76
|
+
filterId,
|
|
77
|
+
value,
|
|
78
|
+
filterType,
|
|
79
|
+
};
|
|
80
|
+
onChange(changeEvent);
|
|
81
|
+
};
|
|
82
|
+
return (_jsxs(Box, { children: [_jsx(SimpleGrid, { cols: Math.min(columns, limitedFilters.length), spacing: "xs", role: "region", "aria-label": "Data filters", children: limitedFilters.map((filterConfig) => {
|
|
83
|
+
const currentValue = values[filterConfig.id];
|
|
84
|
+
return (_jsx(FilterRenderer, { config: filterConfig, value: currentValue, onChange: (value) => handleFilterChange(filterConfig.id, value, filterConfig.type) }, filterConfig.id));
|
|
85
|
+
}) }), filters.length > maxFilters && (_jsx(Alert, { color: "yellow", mt: "xs", icon: _jsx(IconAlertCircle, { size: 14 }), children: translate('table.filters.system.overflow.warning', {
|
|
86
|
+
maxFilters: maxFilters.toString(),
|
|
87
|
+
hiddenCount: (filters.length - maxFilters).toString(),
|
|
88
|
+
}) }))] }));
|
|
89
|
+
};
|
|
90
|
+
export default FilterSystem;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from 'react';
|
|
3
|
+
import { MultiSelect, CloseButton } from '@mantine/core';
|
|
4
|
+
import { translate } from '../../translations/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* MultiSelectFilter - Renders a multiple selection dropdown within the flexible filter system
|
|
7
|
+
*/
|
|
8
|
+
const MultiSelectFilter = ({ config, value, onChange, }) => {
|
|
9
|
+
const multiConfig = config;
|
|
10
|
+
const handleClear = () => {
|
|
11
|
+
onChange(null);
|
|
12
|
+
};
|
|
13
|
+
// Transform options to use translated labels
|
|
14
|
+
const translatedOptions = multiConfig.options.map(option => ({
|
|
15
|
+
value: option.value,
|
|
16
|
+
label: translate(option.labelKey),
|
|
17
|
+
disabled: option.disabled,
|
|
18
|
+
}));
|
|
19
|
+
// Dynamic placeholder based on selection state
|
|
20
|
+
const placeholder = useMemo(() => {
|
|
21
|
+
if (!value || value.length === 0) {
|
|
22
|
+
if (multiConfig.placeholderEmptyKey) {
|
|
23
|
+
return translate(multiConfig.placeholderEmptyKey);
|
|
24
|
+
}
|
|
25
|
+
if (config.placeholderKey) {
|
|
26
|
+
return translate(config.placeholderKey);
|
|
27
|
+
}
|
|
28
|
+
return translate('table.filters.placeholder.select.options');
|
|
29
|
+
}
|
|
30
|
+
if (multiConfig.placeholderWithSelectionKey) {
|
|
31
|
+
return translate(multiConfig.placeholderWithSelectionKey);
|
|
32
|
+
}
|
|
33
|
+
return translate('table.filters.placeholder.select.more');
|
|
34
|
+
}, [value, multiConfig.placeholderEmptyKey, multiConfig.placeholderWithSelectionKey, config.placeholderKey]);
|
|
35
|
+
return (_jsx(MultiSelect, { label: translate(config.labelKey), placeholder: placeholder, data: translatedOptions, value: value || [], onChange: onChange, searchable: multiConfig.searchable, clearable: true, size: "xs", rightSection: value && value.length > 0 ? (_jsx(CloseButton, { size: "xs", variant: "transparent", onMouseDown: (event) => event.preventDefault(), onClick: handleClear, "aria-label": translate('table.filters.system.clear.aria', {
|
|
36
|
+
filterLabel: translate(config.labelKey)
|
|
37
|
+
}) })) : undefined, styles: {
|
|
38
|
+
label: {
|
|
39
|
+
fontWeight: 600,
|
|
40
|
+
},
|
|
41
|
+
}, disabled: config.enabled === false, className: config.className }));
|
|
42
|
+
};
|
|
43
|
+
export default MultiSelectFilter;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Select, CloseButton } from '@mantine/core';
|
|
4
|
+
import { translate } from '../../translations/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* SingleSelectFilter - Renders a single selection dropdown within the flexible filter system
|
|
7
|
+
*/
|
|
8
|
+
const SingleSelectFilter = ({ config, value, onChange, }) => {
|
|
9
|
+
const selectConfig = config;
|
|
10
|
+
const handleClear = () => {
|
|
11
|
+
onChange(null);
|
|
12
|
+
};
|
|
13
|
+
// Transform options to use translated labels
|
|
14
|
+
const translatedOptions = selectConfig.options.map(option => ({
|
|
15
|
+
value: option.value,
|
|
16
|
+
label: translate(option.labelKey),
|
|
17
|
+
disabled: option.disabled,
|
|
18
|
+
}));
|
|
19
|
+
const placeholder = config.placeholderKey
|
|
20
|
+
? translate(config.placeholderKey)
|
|
21
|
+
: translate('table.filters.placeholder.select.option');
|
|
22
|
+
return (_jsx(Select, { label: translate(config.labelKey), placeholder: placeholder, data: translatedOptions, value: value, onChange: onChange, searchable: selectConfig.searchable, clearable: true, size: "xs", rightSection: value ? (_jsx(CloseButton, { size: "xs", variant: "transparent", onMouseDown: (event) => event.preventDefault(), onClick: handleClear, "aria-label": translate('table.filters.system.clear.aria', {
|
|
23
|
+
filterLabel: translate(config.labelKey)
|
|
24
|
+
}) })) : undefined, styles: {
|
|
25
|
+
label: {
|
|
26
|
+
fontWeight: 600,
|
|
27
|
+
},
|
|
28
|
+
}, disabled: config.enabled === false, className: config.className }));
|
|
29
|
+
};
|
|
30
|
+
export default SingleSelectFilter;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Main components
|
|
2
|
+
export { default as FilterSystem } from './FilterSystem.js';
|
|
3
|
+
export { default as FilterRenderer } from './FilterRenderer.js';
|
|
4
|
+
export { default as DateRangeFilter } from './DateRangeFilter.js';
|
|
5
|
+
export { default as SingleSelectFilter } from './SingleSelectFilter.js';
|
|
6
|
+
export { default as MultiSelectFilter } from './MultiSelectFilter.js';
|
|
7
|
+
// Types and interfaces
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
// Import types for helper functions
|
|
10
|
+
import { FilterType, } from './types.js';
|
|
11
|
+
// Helper function to create filter configurations
|
|
12
|
+
export const createFilterConfig = {
|
|
13
|
+
dateRange: (id, labelKey, options) => ({
|
|
14
|
+
id,
|
|
15
|
+
labelKey,
|
|
16
|
+
type: FilterType.DATE_RANGE,
|
|
17
|
+
...options,
|
|
18
|
+
}),
|
|
19
|
+
singleSelect: (id, labelKey, optionsArray, config) => ({
|
|
20
|
+
id,
|
|
21
|
+
labelKey,
|
|
22
|
+
type: FilterType.SINGLE_SELECT,
|
|
23
|
+
options: optionsArray,
|
|
24
|
+
...config,
|
|
25
|
+
}),
|
|
26
|
+
multiSelect: (id, labelKey, optionsArray, config) => ({
|
|
27
|
+
id,
|
|
28
|
+
labelKey,
|
|
29
|
+
type: FilterType.MULTI_SELECT,
|
|
30
|
+
options: optionsArray,
|
|
31
|
+
...config,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
// Helper function to create select options with translation keys
|
|
35
|
+
export const createSelectOption = (value, labelKey, disabled) => ({
|
|
36
|
+
value,
|
|
37
|
+
labelKey,
|
|
38
|
+
disabled,
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported filter types for the flexible filter system
|
|
3
|
+
*/
|
|
4
|
+
export var FilterType;
|
|
5
|
+
(function (FilterType) {
|
|
6
|
+
FilterType["DATE_RANGE"] = "date_range";
|
|
7
|
+
FilterType["SINGLE_SELECT"] = "single_select";
|
|
8
|
+
FilterType["MULTI_SELECT"] = "multi_select";
|
|
9
|
+
})(FilterType || (FilterType = {}));
|