@geotab/zenith 1.24.1 → 1.24.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +9 -0
  2. package/dist/chart/barChart.d.ts +1 -1
  3. package/dist/chart/barChart.js +2 -2
  4. package/dist/chart/lineChart/useSummary.d.ts +9 -5
  5. package/dist/chart/lineChart/useSummary.js +21 -6
  6. package/dist/chart/lineChart.d.ts +1 -1
  7. package/dist/chart/lineChart.js +2 -2
  8. package/dist/chart/pieChart.d.ts +1 -1
  9. package/dist/chart/pieChart.js +2 -2
  10. package/dist/dataFeed/dataFeedHeader/dataFeedHeader.js +2 -2
  11. package/dist/dataGrid/listColumn.d.ts +2 -0
  12. package/dist/dataGrid/withSortableColumns/columns/sortableColumnWrapper.d.ts +2 -0
  13. package/dist/dataGrid/withSortableColumns/columns/sortableColumnWrapper.js +31 -20
  14. package/dist/dataGrid/withSortableColumns/withSortableColumns.js +6 -2
  15. package/dist/header/header.js +6 -0
  16. package/dist/index.css +130 -127
  17. package/dist/stepperRaw/utils/calculateWithPrecision.d.ts +1 -0
  18. package/dist/stepperRaw/utils/calculateWithPrecision.js +21 -0
  19. package/dist/stepperRaw/utils/countDecimals.d.ts +1 -0
  20. package/dist/stepperRaw/utils/countDecimals.js +14 -0
  21. package/dist/stepperRaw/utils/getDecreasedValue.js +2 -1
  22. package/dist/stepperRaw/utils/getIncreasedValue.js +2 -1
  23. package/dist/summaries/summaries.d.ts +1 -1
  24. package/dist/summaries/summaries.js +1 -1
  25. package/dist/summary/summary.d.ts +1 -1
  26. package/dist/summary/summary.js +1 -1
  27. package/dist/table/loading/useLoading.d.ts +1 -0
  28. package/dist/table/sortable/sortableHeader.d.ts +2 -1
  29. package/dist/table/sortable/sortableHeader.js +31 -20
  30. package/dist/table/sortable/useSortableColumns.js +6 -2
  31. package/dist/table/table.d.ts +1 -0
  32. package/package.json +6 -5
package/README.md CHANGED
@@ -40,6 +40,15 @@ Zenith library provides components defined in Zenith Design System. It includes
40
40
 
41
41
  ## Change log
42
42
 
43
+ ### 1.24.2
44
+
45
+ * Add Summary component in Charts
46
+ * Fix Dropdown search in mobile view
47
+ * Add initial sorting order for table
48
+ * Fix Stepper issue with decimals
49
+ * Fix max banner width for XL size
50
+ * Fix sideEffect setting in package.json
51
+
43
52
  ### 1.24.1
44
53
 
45
54
  * Create `Summary` component
@@ -3,12 +3,12 @@ import "./chart.less";
3
3
  import { IZenComponentProps } from "../commonHelpers/zenComponent";
4
4
  import { Plugin } from "chart.js/auto";
5
5
  import "../react-chartjs/dateAdapter";
6
- import { IChartSummary } from "./chartSummary/chartSummary";
7
6
  import { IChartAxis } from "./chartAxis/chartAxis";
8
7
  import { IBarChartData, IBarChartOptions } from "./barChart/interfaces";
9
8
  import { ILegendOptions } from "./plugins/legend/interfaces";
10
9
  import { ITooltipOptions } from "./plugins/tooltip/interfaces";
11
10
  import { IChartInsight } from "./chartInsight/chartInsight";
11
+ import { IChartSummary } from "./chartSummary/chartSummary";
12
12
  export interface IBarChart extends IZenComponentProps {
13
13
  data: IBarChartData;
14
14
  options?: IBarChartOptions;
@@ -24,7 +24,6 @@ const themeContext_1 = require("../utils/theme/themeContext");
24
24
  const generateId_1 = require("../commonHelpers/generateId");
25
25
  const classNames_1 = require("../commonHelpers/classNames/classNames");
26
26
  const legendPlugin_1 = require("./plugins/legend/legendPlugin");
27
- const chartSummary_1 = require("./chartSummary/chartSummary");
28
27
  const chartAxis_1 = require("./chartAxis/chartAxis");
29
28
  const useLanguage_1 = require("../utils/localization/useLanguage");
30
29
  const isDateRange_1 = require("./utils/isDateRange");
@@ -38,6 +37,7 @@ const useHidden_1 = require("./utils/useHidden");
38
37
  const tooltipPlugin_1 = require("./plugins/tooltip/tooltipPlugin");
39
38
  const chartInsight_1 = require("./chartInsight/chartInsight");
40
39
  const userFormatContext_1 = require("../utils/userFormat/userFormatContext");
40
+ const summary_1 = require("../summary/summary");
41
41
  auto_1.Chart.register(auto_1.BarController, auto_1.BarElement, auto_1.CategoryScale, auto_1.LinearScale);
42
42
  const BarChart = (_a) => {
43
43
  var { data, options = {}, axis, insight, summary, legend, tooltip, plugins, className } = _a, rest = __rest(_a, ["data", "options", "axis", "insight", "summary", "legend", "tooltip", "plugins", "className"]);
@@ -78,7 +78,7 @@ const BarChart = (_a) => {
78
78
  return (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-chart", className || ""]), children: [insight
79
79
  ? (0, jsx_runtime_1.jsx)(chartInsight_1.ChartInsight, Object.assign({}, insight))
80
80
  : null, summary
81
- ? (0, jsx_runtime_1.jsx)(chartSummary_1.ChartSummary, Object.assign({ onClick: toggleMainData, isHidden: isMainHidden }, intSummary))
81
+ ? (0, jsx_runtime_1.jsx)(summary_1.Summary, Object.assign({ onToggle: toggleMainData, isEnabled: isMainHidden }, intSummary))
82
82
  : null, xLabels || yLabels.length > 0
83
83
  ? (0, jsx_runtime_1.jsx)(chartAxis_1.ChartAxis, { xLabel: xLabels, yLabels: yLabels })
84
84
  : null, (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__chart", children: (0, jsx_runtime_1.jsx)(typedCharts_1.Bar, Object.assign({ options: chartOptions, data: chartData, plugins: chartPlugins }, rest)) }), (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__legend", id: legendId })] });
@@ -1,15 +1,19 @@
1
1
  /// <reference types="react" />
2
- import { IChartSummary } from "../chartSummary/chartSummary";
3
2
  import { ILineChartData } from "./interfaces";
4
3
  import { IBarChartData } from "../barChart/interfaces";
5
4
  import { IPieChartData } from "../pieChart/interfaces";
6
- export declare const useSummary: (summary: IChartSummary | false | undefined, data: ILineChartData | IBarChartData | IPieChartData) => {
7
- label: string | undefined;
5
+ import { IChartSummary } from "../chartSummary/chartSummary";
6
+ export declare const useSummary: (chartSummary: IChartSummary | false | undefined, data: ILineChartData | IBarChartData | IPieChartData) => {
7
+ title: string | undefined;
8
8
  value: string | number;
9
- color: string;
9
+ color: string | undefined;
10
10
  unit?: string | undefined;
11
+ tooltip?: import("react").ReactNode;
11
12
  more?: import("react").ReactNode;
12
- description?: string | undefined;
13
+ isEnabled?: boolean | undefined;
14
+ onToggle?: (() => void) | undefined;
15
+ description?: string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined;
16
+ label?: string | undefined;
13
17
  onClick?: (() => void) | undefined;
14
18
  isHidden?: boolean | undefined;
15
19
  };
@@ -2,7 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSummary = void 0;
4
4
  const react_1 = require("react");
5
- const useSummary = (summary, data) => {
5
+ const mapChartSummaryToSummary = (chartSummary) => {
6
+ var _a;
7
+ const mappedSummary = {
8
+ value: (_a = chartSummary.value) !== null && _a !== void 0 ? _a : 0,
9
+ color: chartSummary.color,
10
+ title: chartSummary.label,
11
+ unit: chartSummary.unit,
12
+ description: chartSummary.description,
13
+ more: chartSummary.more,
14
+ onToggle: chartSummary.onClick,
15
+ isEnabled: chartSummary.isHidden
16
+ };
17
+ return mappedSummary;
18
+ };
19
+ const useSummary = (chartSummary, data) => {
20
+ const summary = (0, react_1.useMemo)(() => chartSummary ? Object.assign(Object.assign({}, chartSummary), mapChartSummaryToSummary(chartSummary)) : false, [chartSummary]);
6
21
  const value = (0, react_1.useMemo)(() => {
7
22
  if (summary && summary.value) {
8
23
  return summary.value;
@@ -36,15 +51,15 @@ const useSummary = (summary, data) => {
36
51
  }
37
52
  return data.datasets[0] && typeof data.datasets[0].borderColor === "string"
38
53
  ? data.datasets[0].borderColor
39
- : "#2853BD";
54
+ : (summary && summary.title) ? "#2853BD" : undefined;
40
55
  }, [data.datasets, summary]);
41
- const label = (0, react_1.useMemo)(() => {
42
- if (summary && summary.label) {
43
- return summary.label;
56
+ const title = (0, react_1.useMemo)(() => {
57
+ if (summary && summary.title) {
58
+ return summary.title;
44
59
  }
45
60
  return data.datasets[0] ? data.datasets[0].label : undefined;
46
61
  }, [summary, data.datasets]);
47
- return Object.assign(Object.assign({}, summary), { label,
62
+ return Object.assign(Object.assign({}, summary), { title,
48
63
  value,
49
64
  color });
50
65
  };
@@ -4,11 +4,11 @@ import { IZenComponentProps } from "../commonHelpers/zenComponent";
4
4
  import { Plugin } from "chart.js/auto";
5
5
  import "../react-chartjs/dateAdapter";
6
6
  import { IChartAxis } from "./chartAxis/chartAxis";
7
- import { IChartSummary } from "./chartSummary/chartSummary";
8
7
  import { ILineChartOptions, ILineChartData } from "./lineChart/interfaces";
9
8
  import { ILegendOptions } from "./plugins/legend/interfaces";
10
9
  import { ILineOptions } from "./plugins/linePlugin/interfaces";
11
10
  import { IChartInsight } from "./chartInsight/chartInsight";
11
+ import { IChartSummary } from "./chartSummary/chartSummary";
12
12
  export interface ILineChart extends IZenComponentProps {
13
13
  data: ILineChartData;
14
14
  options?: ILineChartOptions;
@@ -26,7 +26,6 @@ const generateId_1 = require("../commonHelpers/generateId");
26
26
  const classNames_1 = require("../commonHelpers/classNames/classNames");
27
27
  const legendPlugin_1 = require("./plugins/legend/legendPlugin");
28
28
  const chartAxis_1 = require("./chartAxis/chartAxis");
29
- const chartSummary_1 = require("./chartSummary/chartSummary");
30
29
  const isDateRange_1 = require("./utils/isDateRange");
31
30
  const convertDates_1 = require("./utils/convertDates");
32
31
  const useSummary_1 = require("./lineChart/useSummary");
@@ -40,6 +39,7 @@ const useChartTicks_1 = require("./lineChart/useChartTicks");
40
39
  const chartInsight_1 = require("./chartInsight/chartInsight");
41
40
  const getXAxisMeta_1 = require("./utils/getXAxisMeta");
42
41
  const userFormatContext_1 = require("../utils/userFormat/userFormatContext");
42
+ const summary_1 = require("../summary/summary");
43
43
  auto_1.Chart.register(auto_1.CategoryScale, auto_1.LinearScale, auto_1.PointElement, auto_1.LineElement, auto_1.Title, auto_1.Tooltip, auto_1.Legend, auto_1.Filler, auto_1.TimeScale);
44
44
  const LineChart = (_a) => {
45
45
  var { data, options = {}, axis, insight, summary, legend, tooltip, plugins, className } = _a, rest = __rest(_a, ["data", "options", "axis", "insight", "summary", "legend", "tooltip", "plugins", "className"]);
@@ -88,7 +88,7 @@ const LineChart = (_a) => {
88
88
  return (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-chart", className || ""]), ref: chartRef, children: [insight
89
89
  ? (0, jsx_runtime_1.jsx)(chartInsight_1.ChartInsight, Object.assign({}, insight))
90
90
  : null, summary !== false
91
- ? (0, jsx_runtime_1.jsx)(chartSummary_1.ChartSummary, Object.assign({}, intSummary, { onClick: toggleMainDataset, isHidden: isMainHidden }))
91
+ ? (0, jsx_runtime_1.jsx)(summary_1.Summary, Object.assign({}, intSummary, { onToggle: toggleMainDataset, isEnabled: isMainHidden }))
92
92
  : null, xLabels || yLabels.length > 0
93
93
  ? (0, jsx_runtime_1.jsx)(chartAxis_1.ChartAxis, { xLabel: xLabels, yLabels: yLabels })
94
94
  : null, (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__chart", children: (0, jsx_runtime_1.jsx)(typedCharts_1.Line, Object.assign({ width: 100, height: 100, options: chartOptions, data: chartData, plugins: chartPlugins }, rest)) }), (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__legend", id: legendId })] });
@@ -4,10 +4,10 @@ import { IZenComponentProps } from "../commonHelpers/zenComponent";
4
4
  import { Plugin } from "chart.js/auto";
5
5
  import "../react-chartjs/dateAdapter";
6
6
  import { IPieChartData, IPieChartOptions } from "./pieChart/interfaces";
7
- import { IChartSummary } from "./chartSummary/chartSummary";
8
7
  import { ILegendOptions } from "./plugins/legend/interfaces";
9
8
  import { ITooltipOptions } from "./plugins/tooltip/interfaces";
10
9
  import { IChartInsight } from "./chartInsight/chartInsight";
10
+ import { IChartSummary } from "./chartSummary/chartSummary";
11
11
  export interface IPieChart extends IZenComponentProps {
12
12
  data: IPieChartData;
13
13
  options?: IPieChartOptions;
@@ -24,13 +24,13 @@ const themeContext_1 = require("../utils/theme/themeContext");
24
24
  const generateId_1 = require("../commonHelpers/generateId");
25
25
  const classNames_1 = require("../commonHelpers/classNames/classNames");
26
26
  const legendPlugin_1 = require("./plugins/legend/legendPlugin");
27
- const chartSummary_1 = require("./chartSummary/chartSummary");
28
27
  const useSummary_1 = require("./lineChart/useSummary");
29
28
  const getDefaultOptions_1 = require("./pieChart/getDefaultOptions");
30
29
  const getDefaultDatasetStyle_1 = require("./pieChart/getDefaultDatasetStyle");
31
30
  const useHidden_1 = require("./utils/useHidden");
32
31
  const tooltipPlugin_1 = require("./plugins/tooltip/tooltipPlugin");
33
32
  const chartInsight_1 = require("./chartInsight/chartInsight");
33
+ const summary_1 = require("../summary/summary");
34
34
  auto_1.Chart.register(auto_1.PieController, auto_1.ArcElement);
35
35
  const PieChart = (_a) => {
36
36
  var { data, options = {}, insight, summary, legend, tooltip, plugins, className } = _a, rest = __rest(_a, ["data", "options", "insight", "summary", "legend", "tooltip", "plugins", "className"]);
@@ -63,7 +63,7 @@ const PieChart = (_a) => {
63
63
  return (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-chart", className || ""]), children: [insight
64
64
  ? (0, jsx_runtime_1.jsx)(chartInsight_1.ChartInsight, Object.assign({}, insight))
65
65
  : null, summary
66
- ? (0, jsx_runtime_1.jsx)(chartSummary_1.ChartSummary, Object.assign({}, intSummary))
66
+ ? (0, jsx_runtime_1.jsx)(summary_1.Summary, Object.assign({}, intSummary))
67
67
  : null, (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__chart", children: (0, jsx_runtime_1.jsx)(typedCharts_1.Pie, Object.assign({ options: chartOptions, data: chartData, plugins: chartPlugins }, rest)) }), (0, jsx_runtime_1.jsx)("div", { className: "zen-chart__legend", id: legendId })] });
68
68
  };
69
69
  exports.PieChart = PieChart;
@@ -5,8 +5,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const sortableColumnWrapper_1 = require("../../dataGrid/withSortableColumns/columns/sortableColumnWrapper");
6
6
  const columnSortDirection_1 = require("../../dataGrid/withSortableColumns/columns/columnSortDirection");
7
7
  const DataFeedHeader = ({ column, sortState, className, onSortChange }) => {
8
- var _a;
8
+ var _a, _b;
9
9
  const isSortedBy = (sortState === null || sortState === void 0 ? void 0 : sortState.sortColumn) === column.id;
10
- return (0, jsx_runtime_1.jsx)("div", { className: className, children: (0, jsx_runtime_1.jsx)(sortableColumnWrapper_1.SortableHeaderCell, { columnName: ((_a = column.name) === null || _a === void 0 ? void 0 : _a.toString()) || column.id.toString(), isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortState.sortDirection : columnSortDirection_1.ColumnSortDirection.None, title: column.title, tooltip: column.title, onSortChange: onSortChange, isMobile: true }) });
10
+ return (0, jsx_runtime_1.jsx)("div", { className: className, children: (0, jsx_runtime_1.jsx)(sortableColumnWrapper_1.SortableHeaderCell, { columnName: ((_a = column.name) === null || _a === void 0 ? void 0 : _a.toString()) || column.id.toString(), isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortState.sortDirection : columnSortDirection_1.ColumnSortDirection.None, title: column.title, tooltip: column.title, onSortChange: onSortChange, isMobile: true, initialSortDirection: (_b = column.meta) === null || _b === void 0 ? void 0 : _b.initialSortDirection }) });
11
11
  };
12
12
  exports.DataFeedHeader = DataFeedHeader;
@@ -1,9 +1,11 @@
1
1
  import { ReactNode } from "react";
2
+ import { ColumnSortDirection } from "./withSortableColumns/columns/columnSortDirection";
2
3
  export interface IListColumnMeta<T> {
3
4
  readonly defaultWidth?: number;
4
5
  readonly defaultValue?: string;
5
6
  readonly lazyLoad?: boolean;
6
7
  readonly visibleOnHover?: boolean;
8
+ readonly initialSortDirection?: ColumnSortDirection.Ascending | ColumnSortDirection.Descending;
7
9
  readonly renderPlaceholder?: (entity: T) => ReactNode;
8
10
  readonly renderFeedPlaceholder?: (title: ReactNode, entity: T) => [ReactNode, ReactNode];
9
11
  }
@@ -6,6 +6,7 @@ import { ColumnSortDirection } from "./columnSortDirection";
6
6
  interface ISortableColumnOptions {
7
7
  isSortedBy: boolean;
8
8
  sortDirection: ColumnSortDirection;
9
+ initialSortDirection?: ColumnSortDirection.Ascending | ColumnSortDirection.Descending;
9
10
  /**
10
11
  * @deprecated
11
12
  * @param translate - will be removed in the next major release
@@ -20,6 +21,7 @@ interface ISortableHeaderCellProps {
20
21
  tooltip: string;
21
22
  onSortChange: (state: ISortableColumnSettings) => void;
22
23
  isMobile?: boolean;
24
+ initialSortDirection?: ColumnSortDirection.Ascending | ColumnSortDirection.Descending;
23
25
  }
24
26
  export declare const SortableHeaderCell: FC<ISortableHeaderCellProps>;
25
27
  export declare class SortableColumnWrapper<T> implements IListColumnWrapper<T> {
@@ -14,28 +14,38 @@ const getSortButtonTitle = (sortDirection, title, translate) => {
14
14
  const titleTemplate = sortDirection === columnSortDirection_1.ColumnSortDirection.Descending ? "Sort by {COLUMN_NAME} descending" : "Sort by {COLUMN_NAME} ascending";
15
15
  return translate(titleTemplate).replace("{COLUMN_NAME}", title);
16
16
  };
17
- const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile = false }) => {
17
+ const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile = false, initialSortDirection = columnSortDirection_1.ColumnSortDirection.Ascending }) => {
18
18
  const { translate } = (0, useLanguage_1.useLanguage)();
19
19
  const [isHovered, setIsHovered] = (0, react_1.useState)(false);
20
20
  const [isFocused, setIsFocused] = (0, react_1.useState)(false);
21
21
  const isActive = isHovered || isFocused;
22
- const iconTitle = getSortButtonTitle(isActive
23
- ? sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
24
- ? columnSortDirection_1.ColumnSortDirection.Descending
25
- : columnSortDirection_1.ColumnSortDirection.Ascending
26
- : sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
27
- ? columnSortDirection_1.ColumnSortDirection.Descending
28
- : columnSortDirection_1.ColumnSortDirection.Ascending, tooltip, translate);
22
+ const iconTitleText = (0, react_1.useMemo)(() => {
23
+ switch (sortDirection) {
24
+ case columnSortDirection_1.ColumnSortDirection.Ascending: {
25
+ return columnSortDirection_1.ColumnSortDirection.Descending;
26
+ }
27
+ case columnSortDirection_1.ColumnSortDirection.Descending: {
28
+ return columnSortDirection_1.ColumnSortDirection.Ascending;
29
+ }
30
+ case undefined:
31
+ default:
32
+ return initialSortDirection;
33
+ }
34
+ }, [sortDirection, initialSortDirection]);
35
+ const iconTitle = getSortButtonTitle(iconTitleText, tooltip, translate);
29
36
  const icon = (0, react_1.useMemo)(() => {
30
- if (isActive) {
31
- return sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
32
- ? iconFilter3Desc_1.IconFilter3Desc
33
- : iconFilter3Asc_1.IconFilter3Asc;
37
+ switch (sortDirection) {
38
+ case columnSortDirection_1.ColumnSortDirection.Ascending: {
39
+ return isActive ? iconFilter3Desc_1.IconFilter3Desc : iconFilter3Asc_1.IconFilter3Asc;
40
+ }
41
+ case columnSortDirection_1.ColumnSortDirection.Descending:
42
+ return isActive ? iconFilter3Asc_1.IconFilter3Asc : iconFilter3Desc_1.IconFilter3Desc;
43
+ case undefined:
44
+ default: {
45
+ return initialSortDirection === columnSortDirection_1.ColumnSortDirection.Ascending ? iconFilter3Asc_1.IconFilter3Asc : iconFilter3Desc_1.IconFilter3Desc;
46
+ }
34
47
  }
35
- return sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
36
- ? iconFilter3Asc_1.IconFilter3Asc
37
- : iconFilter3Desc_1.IconFilter3Desc;
38
- }, [sortDirection, isActive]);
48
+ }, [sortDirection, isActive, initialSortDirection]);
39
49
  const iconButton = ((0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-sortable-column-button__dir-icon zen-caption__post-icon", icon: icon, iconPosition: isMobile ? textIconButton_1.ButtonIconPosition.Start : textIconButton_1.ButtonIconPosition.End, type: buttonType_1.ButtonType.TertiaryBlack, title: iconTitle }));
40
50
  return ((0, jsx_runtime_1.jsx)("div", { className: (0, classNames_1.classNames)([
41
51
  "zen-sortable-column",
@@ -52,9 +62,10 @@ const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tool
52
62
  ]), title: iconTitle, "aria-label": iconTitle, onClick: () => {
53
63
  onSortChange({
54
64
  sortColumn: columnName,
55
- sortDirection: sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
56
- ? columnSortDirection_1.ColumnSortDirection.Descending
57
- : columnSortDirection_1.ColumnSortDirection.Ascending
65
+ sortDirection: sortDirection === columnSortDirection_1.ColumnSortDirection.None ? initialSortDirection :
66
+ sortDirection === columnSortDirection_1.ColumnSortDirection.Ascending
67
+ ? columnSortDirection_1.ColumnSortDirection.Descending
68
+ : columnSortDirection_1.ColumnSortDirection.Ascending
58
69
  });
59
70
  }, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isMobile ? iconButton : null, (0, jsx_runtime_1.jsx)("div", { className: "zen-sortable-column-button__content zen-caption__content", children: title }), isMobile ? null : iconButton] }) }) }));
60
71
  };
@@ -87,7 +98,7 @@ class SortableColumnWrapper {
87
98
  });
88
99
  }
89
100
  renderHeader(title) {
90
- return (0, jsx_runtime_1.jsx)(exports.SortableHeaderCell, { columnName: this.columnName, isSortedBy: this.options.isSortedBy === undefined ? false : this.options.isSortedBy, sortDirection: this.options.sortDirection || columnSortDirection_1.ColumnSortDirection.None, title: title, tooltip: this.columnTitle, onSortChange: this.onSort });
101
+ return (0, jsx_runtime_1.jsx)(exports.SortableHeaderCell, { columnName: this.columnName, isSortedBy: this.options.isSortedBy === undefined ? false : this.options.isSortedBy, sortDirection: this.options.sortDirection || columnSortDirection_1.ColumnSortDirection.None, title: title, tooltip: this.columnTitle, onSortChange: this.onSort, initialSortDirection: this.options.initialSortDirection });
91
102
  }
92
103
  render(value, _) {
93
104
  return value;
@@ -17,7 +17,10 @@ function InnerColumnsList(props, ref) {
17
17
  var _a, _b;
18
18
  const { columns, options, onSortChange } = props;
19
19
  const settingsStore = (0, react_1.useMemo)(() => { var _a, _b; return new sortableColumnsStorage_1.SortableColumnsStorage(((_a = options.columnsSettingsStorage) === null || _a === void 0 ? void 0 : _a.pageName) || "", (_b = options.columnsSettingsStorage) === null || _b === void 0 ? void 0 : _b.storage); }, [(_a = options.columnsSettingsStorage) === null || _a === void 0 ? void 0 : _a.pageName, (_b = options.columnsSettingsStorage) === null || _b === void 0 ? void 0 : _b.storage]);
20
- const allColumns = (0, react_1.useMemo)(() => columns.map(column => (Object.assign(Object.assign({}, (0, toBasicColumn_1.toBasicColumn)(Object.assign({}, column))), { isSortable: column.isSortable }))), [columns]);
20
+ const allColumns = (0, react_1.useMemo)(() => columns.map(column => {
21
+ var _a;
22
+ return (Object.assign(Object.assign({}, (0, toBasicColumn_1.toBasicColumn)(Object.assign({}, column))), { isSortable: column.isSortable, initialSortDirection: (_a = column.meta) === null || _a === void 0 ? void 0 : _a.initialSortDirection }));
23
+ }), [columns]);
21
24
  const sortSettings = (0, react_1.useMemo)(() => options.sortOptions || settingsStore.getItem(), [options.sortOptions, settingsStore]);
22
25
  const saveSettingsToTheStore = (0, react_1.useCallback)((newSettings) =>
23
26
  // not to block main thread this operation can be postponed
@@ -44,7 +47,8 @@ function InnerColumnsList(props, ref) {
44
47
  ...wrappers,
45
48
  new sortableColumnWrapper_1.SortableColumnWrapper(column.name, {
46
49
  isSortedBy,
47
- sortDirection: isSortedBy ? sortSettings.sortDirection : columnSortDirection_1.ColumnSortDirection.None
50
+ sortDirection: isSortedBy ? sortSettings.sortDirection : columnSortDirection_1.ColumnSortDirection.None,
51
+ initialSortDirection: column.initialSortDirection
48
52
  }, column.title, onSort)
49
53
  ] }));
50
54
  }), [allColumns, sortSettings, onSort]);
@@ -103,6 +103,12 @@ const Header = ({ children, className, onFiltersBarOpen }) => {
103
103
  setIsFilterHidden(isDownDirection);
104
104
  }, [getPreviousScrollPosition, previousScrollPosition, headerRef]);
105
105
  const handleScroll = (0, useThrottle_1.useThrottle)((e) => {
106
+ var _a;
107
+ const isKeyboardLikelyOpen = ((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.matches("input, textarea, [contenteditable]")) || false;
108
+ const isMobileFilterOpen = (mobileFilterTrigger === null || mobileFilterTrigger === void 0 ? void 0 : mobileFilterTrigger.current) && mobileFilterTrigger.current.getAttribute("aria-expanded") === "true" || false;
109
+ if (isMobileFilterOpen || isKeyboardLikelyOpen) {
110
+ return;
111
+ }
106
112
  scrollCallback(e);
107
113
  }, 200);
108
114
  (0, react_1.useEffect)(() => {
package/dist/index.css CHANGED
@@ -4794,6 +4794,7 @@
4794
4794
  align-items: center;
4795
4795
  text-align: center;
4796
4796
  overflow: hidden;
4797
+ justify-content: center;
4797
4798
  }
4798
4799
  .zen-banner__content--XXL {
4799
4800
  max-width: unset;
@@ -4846,9 +4847,12 @@
4846
4847
  .zen-banner__block--multiline {
4847
4848
  height: unset;
4848
4849
  }
4849
- .zen-banner__block--XXL,
4850
+ .zen-banner__block--XXL {
4851
+ max-width: 100%;
4852
+ }
4850
4853
  .zen-banner__block--XL {
4851
4854
  max-width: 100%;
4855
+ justify-content: center;
4852
4856
  }
4853
4857
  .zen-banner__block--L {
4854
4858
  max-width: 1136px;
@@ -6622,6 +6626,131 @@
6622
6626
  line-height: 32px;
6623
6627
  color: var(--text-primary);
6624
6628
  }
6629
+ .zen-summary {
6630
+ font-family: var(--main-font);
6631
+ font-size: 14px;
6632
+ font-style: normal;
6633
+ font-weight: 400;
6634
+ letter-spacing: 0;
6635
+ line-height: 16px;
6636
+ box-sizing: border-box;
6637
+ background-color: var(--backgrounds-content-1);
6638
+ background: var(--backgrounds-main);
6639
+ border-radius: 8px;
6640
+ color: var(--text-primary);
6641
+ display: flex;
6642
+ flex-direction: column;
6643
+ text-transform: none;
6644
+ width: fit-content;
6645
+ max-width: 240px;
6646
+ }
6647
+ .zen-summary * {
6648
+ box-sizing: border-box;
6649
+ }
6650
+ .zen-summary__header,
6651
+ .zen-summary__data,
6652
+ .zen-summary__content {
6653
+ width: 100%;
6654
+ min-width: 0;
6655
+ }
6656
+ .zen-summary__header {
6657
+ font-family: var(--main-font);
6658
+ font-size: 12px;
6659
+ font-style: normal;
6660
+ font-weight: 400;
6661
+ letter-spacing: 0.32px;
6662
+ line-height: 16px;
6663
+ text-transform: none;
6664
+ align-items: center;
6665
+ color: var(--text-secondary);
6666
+ display: inline-flex;
6667
+ gap: 4px;
6668
+ margin-bottom: 8px;
6669
+ }
6670
+ .zen-summary__crossed-out {
6671
+ text-decoration: line-through;
6672
+ }
6673
+ .zen-summary__color {
6674
+ border: none;
6675
+ border-radius: 50%;
6676
+ display: inline-block;
6677
+ height: 8px;
6678
+ margin: 2px 2px;
6679
+ min-height: 8px;
6680
+ min-width: 8px;
6681
+ padding-inline: 0;
6682
+ text-align: center;
6683
+ text-decoration: none;
6684
+ width: 8px;
6685
+ }
6686
+ button.zen-summary__clickable {
6687
+ background: none;
6688
+ color: inherit;
6689
+ border: none;
6690
+ padding: 0;
6691
+ outline: inherit;
6692
+ }
6693
+ .zen-summary__clickable {
6694
+ cursor: pointer;
6695
+ }
6696
+ .zen-summary__trigger {
6697
+ align-items: center;
6698
+ cursor: pointer;
6699
+ display: flex;
6700
+ fill: var(--text-secondary);
6701
+ justify-content: center;
6702
+ }
6703
+ .zen-summary__data {
6704
+ align-items: center;
6705
+ display: flex;
6706
+ flex-direction: row;
6707
+ gap: 4px;
6708
+ justify-content: left;
6709
+ }
6710
+ .zen-summary__value,
6711
+ .zen-summary__unit {
6712
+ font-family: var(--main-font);
6713
+ font-size: 12px;
6714
+ font-style: normal;
6715
+ font-weight: 400;
6716
+ letter-spacing: 0.32px;
6717
+ line-height: 16px;
6718
+ text-transform: none;
6719
+ font-feature-settings: 'liga' off, 'clig' off;
6720
+ }
6721
+ .zen-summary__value {
6722
+ font-family: var(--main-font-data);
6723
+ font-size: 24px;
6724
+ font-style: normal;
6725
+ font-weight: 400;
6726
+ letter-spacing: 0;
6727
+ line-height: 32px;
6728
+ text-transform: none;
6729
+ color: var(--text-primary);
6730
+ }
6731
+ .zen-summary__unit,
6732
+ .zen-summary__content {
6733
+ font-family: var(--main-font);
6734
+ font-size: 12px;
6735
+ font-style: normal;
6736
+ font-weight: 400;
6737
+ letter-spacing: 0.32px;
6738
+ line-height: 16px;
6739
+ text-transform: none;
6740
+ color: var(--text-secondary);
6741
+ }
6742
+ .zen-summary__content {
6743
+ margin-top: 8px;
6744
+ display: -webkit-box;
6745
+ line-clamp: 2;
6746
+ -webkit-box-orient: vertical;
6747
+ -webkit-line-clamp: 2;
6748
+ overflow: hidden;
6749
+ text-overflow: ellipsis;
6750
+ }
6751
+ .zen-summary__more {
6752
+ flex: 1;
6753
+ }
6625
6754
  .zen-chart-tooltip {
6626
6755
  box-sizing: border-box;
6627
6756
  padding: 12px 16px;
@@ -13336,132 +13465,6 @@
13336
13465
  .zen-stepper-field.zen-stepper-field--drive-tablet.zen-stepper-field--drive-tablet .zen-text-input {
13337
13466
  padding-right: 25px;
13338
13467
  }
13339
- .zen-summary {
13340
- font-family: var(--main-font);
13341
- font-size: 14px;
13342
- font-style: normal;
13343
- font-weight: 400;
13344
- letter-spacing: 0;
13345
- line-height: 16px;
13346
- box-sizing: border-box;
13347
- background-color: var(--backgrounds-content-1);
13348
- background: var(--backgrounds-main);
13349
- border-radius: 8px;
13350
- color: var(--text-primary);
13351
- display: flex;
13352
- flex-direction: column;
13353
- padding: 12px;
13354
- text-transform: none;
13355
- width: fit-content;
13356
- max-width: 240px;
13357
- }
13358
- .zen-summary * {
13359
- box-sizing: border-box;
13360
- }
13361
- .zen-summary__header,
13362
- .zen-summary__data,
13363
- .zen-summary__content {
13364
- width: 100%;
13365
- min-width: 0;
13366
- }
13367
- .zen-summary__header {
13368
- font-family: var(--main-font);
13369
- font-size: 12px;
13370
- font-style: normal;
13371
- font-weight: 400;
13372
- letter-spacing: 0.32px;
13373
- line-height: 16px;
13374
- text-transform: none;
13375
- align-items: center;
13376
- color: var(--text-secondary);
13377
- display: inline-flex;
13378
- gap: 4px;
13379
- margin-bottom: 8px;
13380
- }
13381
- .zen-summary__crossed-out {
13382
- text-decoration: line-through;
13383
- }
13384
- .zen-summary__color {
13385
- border: none;
13386
- border-radius: 50%;
13387
- display: inline-block;
13388
- height: 8px;
13389
- margin: 2px 2px;
13390
- min-height: 8px;
13391
- min-width: 8px;
13392
- padding-inline: 0;
13393
- text-align: center;
13394
- text-decoration: none;
13395
- width: 8px;
13396
- }
13397
- button.zen-summary__clickable {
13398
- background: none;
13399
- color: inherit;
13400
- border: none;
13401
- padding: 0;
13402
- outline: inherit;
13403
- }
13404
- .zen-summary__clickable {
13405
- cursor: pointer;
13406
- }
13407
- .zen-summary__trigger {
13408
- align-items: center;
13409
- cursor: pointer;
13410
- display: flex;
13411
- fill: var(--text-secondary);
13412
- justify-content: center;
13413
- }
13414
- .zen-summary__data {
13415
- align-items: center;
13416
- display: flex;
13417
- flex-direction: row;
13418
- gap: 4px;
13419
- justify-content: left;
13420
- }
13421
- .zen-summary__value,
13422
- .zen-summary__unit {
13423
- font-family: var(--main-font);
13424
- font-size: 12px;
13425
- font-style: normal;
13426
- font-weight: 400;
13427
- letter-spacing: 0.32px;
13428
- line-height: 16px;
13429
- text-transform: none;
13430
- font-feature-settings: 'liga' off, 'clig' off;
13431
- }
13432
- .zen-summary__value {
13433
- font-family: var(--main-font-data);
13434
- font-size: 24px;
13435
- font-style: normal;
13436
- font-weight: 400;
13437
- letter-spacing: 0;
13438
- line-height: 32px;
13439
- text-transform: none;
13440
- color: var(--text-primary);
13441
- }
13442
- .zen-summary__unit,
13443
- .zen-summary__content {
13444
- font-family: var(--main-font);
13445
- font-size: 12px;
13446
- font-style: normal;
13447
- font-weight: 400;
13448
- letter-spacing: 0.32px;
13449
- line-height: 16px;
13450
- text-transform: none;
13451
- color: var(--text-secondary);
13452
- }
13453
- .zen-summary__content {
13454
- margin-top: 8px;
13455
- display: -webkit-box;
13456
- line-clamp: 2;
13457
- -webkit-box-orient: vertical;
13458
- -webkit-line-clamp: 2;
13459
- overflow: hidden;
13460
- text-overflow: ellipsis;
13461
- }
13462
- .zen-summary__more {
13463
- flex: 1;
13464
- }
13465
13468
  .zen-summaries__row {
13466
13469
  display: flex;
13467
13470
  align-items: top;
@@ -0,0 +1 @@
1
+ export declare const calculateWithPrecision: (value: number, step: number, isAddition?: boolean) => number;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateWithPrecision = void 0;
4
+ const countDecimals_1 = require("./countDecimals");
5
+ const calculateWithPrecision = (value, step, isAddition = true) => {
6
+ // Get the number of decimal places for both numbers
7
+ const decimals1 = (0, countDecimals_1.countDecimals)(value);
8
+ const decimals2 = (0, countDecimals_1.countDecimals)(step);
9
+ // Find the maximum number of decimal places
10
+ const maxDecimals = Math.max(decimals1, decimals2);
11
+ // Calculate the scale factor (e.g., 100 for 2 decimals, 1000 for 3)
12
+ const scaleFactor = Math.pow(10, maxDecimals);
13
+ // Convert to integers, perform the addition, and scale back
14
+ const integerValue = Math.round(value * scaleFactor);
15
+ const integerStep = Math.round(step * scaleFactor);
16
+ const result = isAddition
17
+ ? (integerValue + integerStep) / scaleFactor
18
+ : (integerValue - integerStep) / scaleFactor;
19
+ return result;
20
+ };
21
+ exports.calculateWithPrecision = calculateWithPrecision;
@@ -0,0 +1 @@
1
+ export declare const countDecimals: (num: unknown) => number;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countDecimals = void 0;
4
+ const countDecimals = (num) => {
5
+ var _a;
6
+ if (typeof num !== "number") {
7
+ return 0;
8
+ }
9
+ if (Math.floor(num) === num) {
10
+ return 0;
11
+ }
12
+ return ((_a = num.toString().split(".")[1]) === null || _a === void 0 ? void 0 : _a.length) || 0;
13
+ };
14
+ exports.countDecimals = countDecimals;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDecreasedValue = void 0;
4
+ const calculateWithPrecision_1 = require("./calculateWithPrecision");
4
5
  const getDecreasedValue = (value, step, min) => {
5
- const decreasedValue = (Number(value) || 0) - step;
6
+ const decreasedValue = (0, calculateWithPrecision_1.calculateWithPrecision)(Number(value) || 0, step, false);
6
7
  return decreasedValue < min ? min : decreasedValue;
7
8
  };
8
9
  exports.getDecreasedValue = getDecreasedValue;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIncreasedValue = void 0;
4
+ const calculateWithPrecision_1 = require("./calculateWithPrecision");
4
5
  const getIncreasedValue = (value, step, max) => {
5
- const increasedValue = (Number(value) || 0) + step;
6
+ const increasedValue = (0, calculateWithPrecision_1.calculateWithPrecision)(Number(value) || 0, step);
6
7
  return increasedValue > max ? max : increasedValue;
7
8
  };
8
9
  exports.getIncreasedValue = getIncreasedValue;
@@ -4,7 +4,7 @@ import "./summaries.less";
4
4
  type SummariesType = "row" | "column" | "two-columns";
5
5
  interface ISummaries {
6
6
  children: ReactElement<ISummary>[];
7
- type: SummariesType;
7
+ type?: SummariesType;
8
8
  }
9
9
  export declare const Summaries: React.FC<ISummaries>;
10
10
  export {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Summaries = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const splitIntoPairs_1 = require("./utils/splitIntoPairs");
6
- const Summaries = ({ type, children }) => {
6
+ const Summaries = ({ type = "row", children }) => {
7
7
  if (type === "two-columns") {
8
8
  return (0, jsx_runtime_1.jsx)("div", { className: `zen-summaries__${type}`, children: (0, splitIntoPairs_1.splitIntoPairs)(children).map((pair, index) => ((0, jsx_runtime_1.jsxs)("div", { className: "zen-summaries__two-columns-container", children: [pair[0], pair[1]] }, `summaries-item-${index}`))) });
9
9
  }
@@ -5,7 +5,7 @@ export interface ISummary {
5
5
  title?: string;
6
6
  value: string | number;
7
7
  unit?: string;
8
- tooltip?: React.ReactNode;
8
+ tooltip?: ReactNode;
9
9
  more?: ReactNode;
10
10
  isEnabled?: boolean;
11
11
  onToggle?: () => void;
@@ -12,6 +12,6 @@ const Summary = ({ color, title, value, unit, tooltip, more, isEnabled, onToggle
12
12
  const { translate } = (0, useLanguage_1.useLanguage)();
13
13
  return (0, jsx_runtime_1.jsxs)("div", { className: "zen-summary", children: [(color || title || tooltip) && (0, jsx_runtime_1.jsxs)("div", { className: "zen-summary__header", children: [color && (0, jsx_runtime_1.jsx)("button", { "aria-label": translate("Summary color"), className: (0, classNames_1.classNames)(["zen-summary__color", isClickable ? "zen-summary__clickable" : ""]), style: { backgroundColor: color }, onClick: onToggle }), isClickable ?
14
14
  (0, jsx_runtime_1.jsx)("button", { className: (0, classNames_1.classNames)(["zen-summary__title-text zen-ellipsis heading-05 zen-summary__clickable", isEnabled ? "zen-summary__crossed-out" : ""]), onClick: onToggle, children: title }) :
15
- (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__title-text zen-ellipsis heading-05", children: title }), tooltip && (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { alignment: "top", size: "auto", trigger: (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__trigger", children: (0, jsx_runtime_1.jsx)(iconInfoCircle_1.IconInfoCircle, { size: "large", className: "zen-summary__title-icon" }) }), children: tooltip })] }), (0, jsx_runtime_1.jsxs)("div", { className: "zen-summary__data", children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-summary__value zen-ellipsis", children: value }), unit && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__unit", children: unit }), more && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__more zen-ellipsis", children: more })] }), description && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__content", children: description })] });
15
+ (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__title-text zen-ellipsis heading-05", children: title }), tooltip && (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { alignment: "top", size: "auto", trigger: (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__trigger", children: (0, jsx_runtime_1.jsx)(iconInfoCircle_1.IconInfoCircle, { size: "large", className: "zen-summary__title-icon" }) }), children: tooltip })] }), (0, jsx_runtime_1.jsxs)("div", { className: "zen-summary__data", children: [(0, jsx_runtime_1.jsx)("div", { className: "zen-summary__value zen-ellipsis", children: typeof value === "string" ? value : value.toFixed(2) }), unit && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__unit", children: unit }), more && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__more zen-ellipsis", children: more })] }), description && (0, jsx_runtime_1.jsx)("div", { className: "zen-summary__content", children: description })] });
16
16
  };
17
17
  exports.Summary = Summary;
@@ -16,6 +16,7 @@ export declare const useLoading: <T extends IEntityWithId>(columns: IListColumn<
16
16
  renderPlaceholder: () => import("react/jsx-runtime").JSX.Element;
17
17
  renderFeedPlaceholder: (_: ReactNode) => [ReactNode, ReactNode];
18
18
  defaultWidth?: number | undefined;
19
+ initialSortDirection?: import("../table").ColumnSortDirection | undefined;
19
20
  };
20
21
  columnComponent: {
21
22
  render: (entity: T & ILoadingEntity) => string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | PromiseLike<ReactNode> | null | undefined;
@@ -4,10 +4,11 @@ interface ISortableHeaderCellProps {
4
4
  columnName: string;
5
5
  isSortedBy: boolean;
6
6
  sortDirection: ColumnSortDirection | undefined;
7
+ initialSortDirection?: ColumnSortDirection;
7
8
  title: ReactNode;
8
9
  tooltip: string;
9
10
  onSortChange: (state: ISortableValue) => void;
10
11
  isMobile?: boolean;
11
12
  }
12
- export declare const SortableHeaderCell: ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile }: ISortableHeaderCellProps) => import("react/jsx-runtime").JSX.Element;
13
+ export declare const SortableHeaderCell: ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile, initialSortDirection }: ISortableHeaderCellProps) => import("react/jsx-runtime").JSX.Element;
13
14
  export {};
@@ -31,28 +31,38 @@ const isClickOnSortableParent = (element) => {
31
31
  const parent = findParent(element, "zen-sortable-column-button");
32
32
  return parent.classList.contains("zen-sortable-column-button") || parent.classList.contains("zen-sortable-column-button__dir-icon");
33
33
  };
34
- const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile = false }) => {
34
+ const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tooltip, onSortChange, isMobile = false, initialSortDirection = interfaces_1.ColumnSortDirection.Ascending }) => {
35
35
  const { translate } = (0, useLanguage_1.useLanguage)();
36
36
  const [isHovered, setIsHovered] = (0, react_1.useState)(false);
37
37
  const [isFocused, setIsFocused] = (0, react_1.useState)(false);
38
38
  const isActive = isHovered || isFocused;
39
- const iconTitle = getSortButtonTitle(isActive
40
- ? sortDirection === interfaces_1.ColumnSortDirection.Ascending
41
- ? interfaces_1.ColumnSortDirection.Descending
42
- : interfaces_1.ColumnSortDirection.Ascending
43
- : sortDirection === interfaces_1.ColumnSortDirection.Ascending
44
- ? interfaces_1.ColumnSortDirection.Descending
45
- : interfaces_1.ColumnSortDirection.Ascending, tooltip, translate);
39
+ const iconTitleText = (0, react_1.useMemo)(() => {
40
+ switch (sortDirection) {
41
+ case interfaces_1.ColumnSortDirection.Ascending: {
42
+ return interfaces_1.ColumnSortDirection.Descending;
43
+ }
44
+ case interfaces_1.ColumnSortDirection.Descending: {
45
+ return interfaces_1.ColumnSortDirection.Ascending;
46
+ }
47
+ case undefined:
48
+ default:
49
+ return initialSortDirection;
50
+ }
51
+ }, [sortDirection, initialSortDirection]);
52
+ const iconTitle = getSortButtonTitle(iconTitleText, tooltip, translate);
46
53
  const icon = (0, react_1.useMemo)(() => {
47
- if (isActive) {
48
- return sortDirection === interfaces_1.ColumnSortDirection.Ascending
49
- ? iconFilter3Desc_1.IconFilter3Desc
50
- : iconFilter3Asc_1.IconFilter3Asc;
54
+ switch (sortDirection) {
55
+ case interfaces_1.ColumnSortDirection.Ascending: {
56
+ return isActive ? iconFilter3Desc_1.IconFilter3Desc : iconFilter3Asc_1.IconFilter3Asc;
57
+ }
58
+ case interfaces_1.ColumnSortDirection.Descending:
59
+ return isActive ? iconFilter3Asc_1.IconFilter3Asc : iconFilter3Desc_1.IconFilter3Desc;
60
+ case undefined:
61
+ default: {
62
+ return initialSortDirection === interfaces_1.ColumnSortDirection.Ascending ? iconFilter3Asc_1.IconFilter3Asc : iconFilter3Desc_1.IconFilter3Desc;
63
+ }
51
64
  }
52
- return sortDirection === interfaces_1.ColumnSortDirection.Ascending
53
- ? iconFilter3Asc_1.IconFilter3Asc
54
- : iconFilter3Desc_1.IconFilter3Desc;
55
- }, [sortDirection, isActive]);
65
+ }, [sortDirection, isActive, initialSortDirection]);
56
66
  const iconButton = ((0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { className: "zen-sortable-column-button__dir-icon zen-caption__post-icon", icon: icon, iconPosition: isMobile ? textIconButton_1.ButtonIconPosition.Start : textIconButton_1.ButtonIconPosition.End, type: "tertiary-black", title: iconTitle }));
57
67
  const onHeaderClick = (0, react_1.useCallback)((e) => {
58
68
  const target = e && e.target;
@@ -62,12 +72,13 @@ const SortableHeaderCell = ({ columnName, isSortedBy, sortDirection, title, tool
62
72
  if (isClickOnSortableParent(target)) {
63
73
  onSortChange({
64
74
  sortColumn: columnName,
65
- sortDirection: sortDirection === interfaces_1.ColumnSortDirection.Ascending
66
- ? interfaces_1.ColumnSortDirection.Descending
67
- : interfaces_1.ColumnSortDirection.Ascending
75
+ sortDirection: sortDirection === undefined ? initialSortDirection :
76
+ sortDirection === interfaces_1.ColumnSortDirection.Ascending
77
+ ? interfaces_1.ColumnSortDirection.Descending
78
+ : interfaces_1.ColumnSortDirection.Ascending
68
79
  });
69
80
  }
70
- }, [columnName, sortDirection, onSortChange]);
81
+ }, [onSortChange, columnName, sortDirection, initialSortDirection]);
71
82
  return ((0, jsx_runtime_1.jsx)("div", { onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), onFocus: () => setIsFocused(true), onBlur: () => setIsFocused(false), className: (0, classNames_1.classNames)([
72
83
  "zen-sortable-column",
73
84
  isSortedBy ? `zen-sortable-column--active` : "",
@@ -44,7 +44,10 @@ const useSortableColumns = (columns, sortable, isMobile) => {
44
44
  const isSortedBy = (sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortColumn) === column.id;
45
45
  const wrapper = {
46
46
  name: SortableWrapperName,
47
- renderHeader: (title) => (0, jsx_runtime_1.jsx)(sortableHeader_1.SortableHeaderCell, { columnName: column.id, isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortSettings.sortDirection : undefined, title: title, tooltip: column.title, onSortChange: onSort }),
47
+ renderHeader: (title) => {
48
+ var _a;
49
+ return (0, jsx_runtime_1.jsx)(sortableHeader_1.SortableHeaderCell, { columnName: column.id, isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortSettings.sortDirection : undefined, title: title, tooltip: column.title, onSortChange: onSort, initialSortDirection: (_a = column.meta) === null || _a === void 0 ? void 0 : _a.initialSortDirection });
50
+ },
48
51
  render: (value, _) => value
49
52
  };
50
53
  const columnWrappers = (column.wrappers || []).filter(w => w.name !== SortableWrapperName);
@@ -52,6 +55,7 @@ const useSortableColumns = (columns, sortable, isMobile) => {
52
55
  });
53
56
  }, [columns, onSort, sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortColumn, sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortDirection, sortable]);
54
57
  const feedSortControl = (0, react_1.useMemo)(() => {
58
+ var _a;
55
59
  if (!sortable) {
56
60
  return null;
57
61
  }
@@ -60,7 +64,7 @@ const useSortableColumns = (columns, sortable, isMobile) => {
60
64
  }
61
65
  const column = columns[0];
62
66
  const isSortedBy = (sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortColumn) === column.id;
63
- return (0, jsx_runtime_1.jsx)(sortableHeader_1.SortableHeaderCell, { columnName: column.id.toString(), isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortSettings.sortDirection : undefined, title: column.title, tooltip: column.title, onSortChange: onSort, isMobile: true });
67
+ return (0, jsx_runtime_1.jsx)(sortableHeader_1.SortableHeaderCell, { columnName: column.id.toString(), isSortedBy: isSortedBy, sortDirection: isSortedBy ? sortSettings.sortDirection : undefined, title: column.title, tooltip: column.title, onSortChange: onSort, isMobile: true, initialSortDirection: (_a = column.meta) === null || _a === void 0 ? void 0 : _a.initialSortDirection });
64
68
  }, [columns, isMobile, onSort, sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortColumn, sortSettings === null || sortSettings === void 0 ? void 0 : sortSettings.sortDirection, sortable]);
65
69
  return { sortableColumns, feedSortControl };
66
70
  };
@@ -31,6 +31,7 @@ export interface IListColumn<T> {
31
31
  defaultWidth?: number;
32
32
  readonly renderPlaceholder?: (entity: T) => ReactNode;
33
33
  readonly renderFeedPlaceholder?: (title: ReactNode, entity: T) => [ReactNode, ReactNode];
34
+ readonly initialSortDirection?: ColumnSortDirection;
34
35
  };
35
36
  columnComponent?: IListColumnBasic<T>;
36
37
  wrappers?: IListColumnWrapper<T>[];
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@geotab/zenith",
3
- "version": "1.24.1",
3
+ "version": "1.24.2-beta.0",
4
4
  "description": "Zenith components library on React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "sideEffects": [
8
- "**/*.css"
8
+ "**/*.css",
9
+ "**/*.less"
9
10
  ],
10
11
  "module": "dist/index.js",
11
12
  "scripts": {
@@ -46,6 +47,7 @@
46
47
  "@storybook/react": "^8.5.8",
47
48
  "@storybook/react-webpack5": "^8.5.8",
48
49
  "@storybook/theming": "^8.5.8",
50
+ "@storybook/test": "^8.5.8",
49
51
  "@testing-library/react": "^16.0.1",
50
52
  "@types/jest": "^29.5.12",
51
53
  "@types/react": "^18.2.73",
@@ -71,7 +73,6 @@
71
73
  "xml2js": "^0.6.0"
72
74
  },
73
75
  "dependencies": {
74
- "@storybook/test": "^8.5.8",
75
76
  "chart.js": "^4.4.6",
76
77
  "react": "^18.2.0",
77
78
  "react-dom": "^18.2.0"
@@ -97,6 +98,6 @@
97
98
  ]
98
99
  },
99
100
  "publishConfig": {
100
- "access": "public"
101
- }
101
+ "access": "public"
102
+ }
102
103
  }