@sonic-equipment/ui 188.0.0 → 189.0.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 (82) hide show
  1. package/dist/cards/data-card/data-card.js +1 -1
  2. package/dist/country-selector/connected-country-selector.js +0 -11
  3. package/dist/country-selector/use-countries-languages.js +0 -11
  4. package/dist/delivery-time/delivery-time.js +3 -4
  5. package/dist/exports.d.ts +12 -3
  6. package/dist/forms/fields/select-field/select-field.js +1 -1
  7. package/dist/forms/layout/form/form.js +1 -1
  8. package/dist/header/link-list/navigation-link-list.js +14 -4
  9. package/dist/index.js +13 -4
  10. package/dist/intl/formatted-date.d.ts +4 -0
  11. package/dist/intl/formatted-date.js +8 -0
  12. package/dist/intl/translation-id.d.ts +1 -1
  13. package/dist/intl/use-formatted-date.d.ts +6 -0
  14. package/dist/intl/use-formatted-date.js +19 -0
  15. package/dist/lists/menu-list/menu-list-item.js +3 -1
  16. package/dist/lists/menu-list/menu-list-provider.d.ts +11 -0
  17. package/dist/lists/menu-list/menu-list-provider.js +30 -0
  18. package/dist/lists/menu-list/menu-list.d.ts +2 -1
  19. package/dist/lists/menu-list/menu-list.js +4 -3
  20. package/dist/lists/menu-list/menu-list.module.css.js +1 -1
  21. package/dist/lists/menu-list/use-menu-list-item.d.ts +5 -0
  22. package/dist/lists/menu-list/use-menu-list-item.js +12 -0
  23. package/dist/lists/menu-list/use-menu-list.d.ts +1 -0
  24. package/dist/lists/menu-list/use-menu-list.js +11 -0
  25. package/dist/loading/dynamic-loading-overlay.d.ts +5 -0
  26. package/dist/loading/dynamic-loading-overlay.js +26 -0
  27. package/dist/loading/dynamic-loading-overlay.module.css.js +3 -0
  28. package/dist/pages/checkout/cart-page/cart-page.js +1 -1
  29. package/dist/pages/checkout/order-confirmation-page/order-confirmation-page-content.js +2 -4
  30. package/dist/pages/error-page/error-page.js +2 -7
  31. package/dist/pages/my-sonic/actions/change-password/connected-change-password-dialog.js +0 -2
  32. package/dist/pages/my-sonic/navigation/my-sonic-desktop-navigation.js +1 -1
  33. package/dist/pages/my-sonic/pages/order-history/order-history.d.ts +1 -0
  34. package/dist/pages/my-sonic/pages/order-history/order-history.js +166 -0
  35. package/dist/pages/my-sonic/pages/order-history/order-history.module.css.js +3 -0
  36. package/dist/pages/product/product-listing-page/product-listing.js +1 -1
  37. package/dist/pages/product/search-result-page/search-results-page.js +1 -1
  38. package/dist/shared/api/storefront/hooks/orders/use-fetch-orders.d.ts +10 -0
  39. package/dist/shared/api/storefront/hooks/orders/use-fetch-orders.js +13 -0
  40. package/dist/shared/api/storefront/model/storefront.model.d.ts +13 -1
  41. package/dist/shared/api/storefront/model/storefront.model.js +28 -1
  42. package/dist/shared/api/storefront/services/order-service.d.ts +12 -0
  43. package/dist/shared/api/storefront/services/order-service.js +29 -0
  44. package/dist/shared/hooks/use-intersection-observer.d.ts +3 -1
  45. package/dist/shared/hooks/use-intersection-observer.js +3 -2
  46. package/dist/shared/utils/date.d.ts +4 -1
  47. package/dist/shared/utils/date.js +6 -5
  48. package/dist/shared/utils/price.d.ts +1 -1
  49. package/dist/shared/{hooks/use-scroll-to.d.ts → utils/scrolling.d.ts} +1 -1
  50. package/dist/shared/utils/scrolling.js +16 -0
  51. package/dist/shared/utils/uuid.d.ts +2 -1
  52. package/dist/styles.css +894 -634
  53. package/dist/table/data-table.d.ts +37 -10
  54. package/dist/table/data-table.js +72 -17
  55. package/dist/table/data-table.module.css.js +1 -1
  56. package/dist/table/elements/switch-sort-direction.d.ts +2 -0
  57. package/dist/table/elements/switch-sort-direction.js +11 -0
  58. package/dist/table/elements/table-context.d.ts +6 -5
  59. package/dist/table/elements/table-context.js +1 -16
  60. package/dist/table/elements/table-provider.d.ts +6 -5
  61. package/dist/table/elements/table-provider.js +23 -17
  62. package/dist/table/elements/table-row-context.d.ts +2 -2
  63. package/dist/table/elements/table-row-provider.js +4 -4
  64. package/dist/table/elements/table-sort-button.d.ts +8 -7
  65. package/dist/table/elements/table-sort-button.js +5 -4
  66. package/dist/table/elements/table.d.ts +1 -1
  67. package/dist/table/elements/table.js +2 -2
  68. package/dist/table/elements/table.module.css.js +1 -1
  69. package/dist/table/elements/td.d.ts +1 -1
  70. package/dist/table/elements/th.d.ts +1 -7
  71. package/dist/table/elements/th.js +2 -3
  72. package/dist/table/elements/tr.d.ts +2 -8
  73. package/dist/table/elements/tr.js +1 -3
  74. package/dist/table/elements/types.d.ts +36 -0
  75. package/dist/table/elements/use-table.js +1 -3
  76. package/dist/table/elements/use-td.d.ts +1 -1
  77. package/dist/table/elements/use-th.d.ts +2 -2
  78. package/package.json +1 -1
  79. package/dist/shared/hooks/use-scroll-to.js +0 -19
  80. package/dist/table/elements/table-column-properties.d.ts +0 -10
  81. package/dist/table/elements/use-tr.d.ts +0 -2
  82. package/dist/table/elements/use-tr.js +0 -16
@@ -1,19 +1,46 @@
1
+ import { FunctionComponent, ReactNode } from 'react';
1
2
  import { TranslationId } from '../intl/translation-id';
2
- import { TableColumnProperties } from './elements/table-column-properties';
3
- export interface ColumnBase {
3
+ import { SortDirection, SortHanlder, SortOptions, TableColumnProperties } from './elements/types';
4
+ export interface Column<T extends object> {
5
+ header: {
6
+ isHidden?: boolean;
7
+ label: TranslationId;
8
+ render?: (column: Column<T>, data: T[]) => React.ReactNode;
9
+ } | {
10
+ Icon: FunctionComponent<{
11
+ className?: string;
12
+ }>;
13
+ label: TranslationId;
14
+ };
4
15
  key: string;
5
- label: TranslationId;
6
16
  props?: TableColumnProperties;
17
+ sort?: SortOptions;
18
+ value: {
19
+ action: string;
20
+ } | {
21
+ propertyName: keyof T;
22
+ } | {
23
+ render: (row: T, column: Column<T>, data: T[]) => React.ReactNode;
24
+ };
7
25
  }
8
- export interface ColumnRender<T extends object> extends ColumnBase {
9
- render: (row: T, column: Column<T>, data: T[]) => React.ReactNode;
10
- }
11
- export interface ColumnProperty<T extends object> extends ColumnBase {
12
- propertyName: keyof T;
26
+ export interface Action<T extends object> {
27
+ icon?: ReactNode;
28
+ isEnabled?: (item: T) => boolean;
29
+ isPrimary?: boolean;
30
+ key: string;
31
+ label: TranslationId;
32
+ onAction: (item: T) => void;
13
33
  }
14
- export type Column<T extends object> = ColumnProperty<T> | ColumnRender<T>;
15
34
  export interface DataTableProps<T extends object> {
35
+ actions?: Action<T>[];
16
36
  columns?: Column<T>[];
17
37
  data: T[];
38
+ onSort?: SortHanlder;
18
39
  }
19
- export declare function DataTable<T extends object>({ columns: _columns, data, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element | null;
40
+ export declare function SortWrapper<T extends object>({ children, column, direction, onSort, }: {
41
+ children: ReactNode;
42
+ column: Column<T>;
43
+ direction?: SortDirection;
44
+ onSort: SortHanlder;
45
+ }): import("react/jsx-runtime").JSX.Element;
46
+ export declare function DataTable<T extends object>({ actions, columns: _columns, data, onSort: _onSort, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element | null;
@@ -1,16 +1,39 @@
1
1
  "use client";
2
- import { jsx } from 'react/jsx-runtime';
3
- import { useMemo } from 'react';
2
+ import { jsx, Fragment } from 'react/jsx-runtime';
3
+ import { useState, useMemo, useCallback } from 'react';
4
+ import { Button } from '../buttons/button/button.js';
5
+ import { Link } from '../buttons/link/link.js';
4
6
  import { DataCard } from '../cards/data-card/data-card.js';
7
+ import { useFormattedMessage } from '../intl/use-formatted-message.js';
5
8
  import { useIsBreakpoint } from '../shared/hooks/use-is-breakpoint.js';
9
+ import { switchSortDirection } from './elements/switch-sort-direction.js';
6
10
  import { Table } from './elements/table.js';
11
+ import { TableSortButton } from './elements/table-sort-button.js';
7
12
  import { TD } from './elements/td.js';
8
13
  import { TH } from './elements/th.js';
9
14
  import { TR } from './elements/tr.js';
10
15
  import styles from './data-table.module.css.js';
11
16
 
12
- function DataTable({ columns: _columns, data, }) {
17
+ function SortWrapper({ children, column, direction, onSort, }) {
18
+ if (!column.sort?.isEnabled)
19
+ return jsx(Fragment, { children: children });
20
+ return (jsx(TableSortButton, { columnName: column.header.label, direction: direction, onSort: onSort, sortKey: column.sort.columnName || column.key, children: children }));
21
+ }
22
+ function DataTable({ actions, columns: _columns, data, onSort: _onSort, }) {
13
23
  const isXl = useIsBreakpoint('lg');
24
+ const t = useFormattedMessage();
25
+ const [sortInfo, setSortInfo] = useState(() => {
26
+ const sortColumn = _columns?.find(column => column.sort?.isEnabled);
27
+ if (!sortColumn ||
28
+ !sortColumn.sort?.isEnabled ||
29
+ !sortColumn.sort.direction ||
30
+ sortColumn.sort.direction === 'NONE')
31
+ return null;
32
+ return {
33
+ direction: sortColumn.sort.direction,
34
+ key: sortColumn.key,
35
+ };
36
+ });
14
37
  const columns = useMemo(() => {
15
38
  if (_columns)
16
39
  return _columns;
@@ -19,30 +42,62 @@ function DataTable({ columns: _columns, data, }) {
19
42
  return [];
20
43
  const propertyNames = Object.keys(firstItem);
21
44
  return propertyNames.map(key => ({
45
+ header: { label: key },
22
46
  key,
23
- label: key,
24
- propertyName: key,
47
+ value: { propertyName: key },
25
48
  }));
26
49
  }, [_columns, data]);
50
+ const onSort = useCallback((key, direction) => {
51
+ const newDirection = switchSortDirection(direction);
52
+ setSortInfo({ direction: newDirection, key });
53
+ _onSort?.(key, newDirection);
54
+ }, [_onSort]);
55
+ const cssColumns = useMemo(() => {
56
+ if (!_columns?.some(column => column.props?.cssColumn))
57
+ return;
58
+ return _columns
59
+ .map(column => {
60
+ return column.props?.cssColumn || 'minmax(min-content, auto)';
61
+ })
62
+ .join(' ');
63
+ }, [_columns]);
27
64
  if (data.length === 0 || columns.length === 0)
28
65
  return null;
29
66
  if (isXl)
30
- return (jsx(Table, { thead: jsx(TR, { children: columns.map(column => (jsx(TH, { ...column.props, children: column.label }, column.key))) }), children: data.map((item, index) => (
31
- // eslint-disable-next-line @eslint-react/no-array-index-key
32
- jsx(TR, { children: columns.map(column => 'render' in column ? (jsx(TD, { children: column.render(item, column, data) }, column.key)) : (jsx(TD, { children: String(item[column.propertyName]) }, column.key))) }, index))) }));
67
+ return (jsx("div", { className: styles['data-table'], children: jsx(Table, { className: styles['content'], cssColumns: cssColumns, highlight: "col", stretch: true, thead: jsx(TR, { children: columns.map(column => (jsx(TH, { ...column.props, sortable: !!column.sort?.isEnabled, children: 'Icon' in column.header ? (jsx(column.header.Icon, { className: styles['th-icon'] })) : (!column.header.isHidden && (jsx(SortWrapper, { column: column, direction: sortInfo?.key === column.key ||
68
+ (column.sort?.isEnabled &&
69
+ sortInfo?.key === column.sort.columnName)
70
+ ? sortInfo?.direction
71
+ : 'NONE', onSort: onSort, children: 'render' in column.header && column.header.render
72
+ ? column.header.render(column, data)
73
+ : t(column.header.label) }))) }, column.key))) }), children: data.map((item, index) => (
74
+ // eslint-disable-next-line @eslint-react/no-array-index-key
75
+ jsx(TR, { children: columns.map(column => {
76
+ const actionKey = 'action' in column.value ? column.value.action : undefined;
77
+ const action = actionKey
78
+ ? actions?.find(action => action.key === actionKey)
79
+ : undefined;
80
+ if (actionKey && !action)
81
+ throw new Error(`Action "${actionKey}" not found`);
82
+ return 'render' in column.value ? (jsx(TD, { children: column.value.render(item, column, data) }, column.key)) : 'propertyName' in column.value ? (jsx(TD, { children: String(item[column.value.propertyName]) }, column.key)) : 'action' in column.value ? (jsx(TD, { children: action && (jsx(Link, { hasUnderline: true, color: "secondary", isDisabled: action.isEnabled ? !action.isEnabled(item) : false, onClick: () => action.onAction(item), children: t(action.label) })) }, column.key)) : null;
83
+ }) }, index))) }) }));
33
84
  return (jsx("div", { className: styles['data-card-list'], children: data.map((item, index) => (jsx(DataCard
34
85
  // eslint-disable-next-line @eslint-react/no-array-index-key
35
- , { data: columns.map(column => 'render' in column
86
+ , { actions: actions?.map(action => (jsx(Button, { color: action.isPrimary ? 'primary' : 'secondary', isDisabled: action.isEnabled ? !action.isEnabled(item) : false, onClick: () => action.onAction(item), size: "sm", variant: action.isPrimary ? undefined : 'outline', children: t(action.label) }, action.key))), data: columns
87
+ .map(column => 'render' in column.value
36
88
  ? {
37
89
  key: column.key,
38
- label: column.label,
39
- value: column.render(item, column, data),
90
+ label: column.header.label,
91
+ value: column.value.render(item, column, data),
40
92
  }
41
- : {
42
- key: column.key,
43
- label: column.label,
44
- value: item[column.propertyName],
45
- }) }, index))) }));
93
+ : 'propertyName' in column.value
94
+ ? {
95
+ key: column.key,
96
+ label: column.header.label,
97
+ value: item[column.value.propertyName],
98
+ }
99
+ : null)
100
+ .filter(Boolean) }, index))) }));
46
101
  }
47
102
 
48
- export { DataTable };
103
+ export { DataTable, SortWrapper };
@@ -1,3 +1,3 @@
1
- var styles = {"data-card-list":"data-table-module-7CcZR"};
1
+ var styles = {"data-card-list":"data-table-module-7CcZR","data-table":"data-table-module-WFG32","th-icon":"data-table-module-9UZ8I"};
2
2
 
3
3
  export { styles as default };
@@ -0,0 +1,2 @@
1
+ import { SortDirection } from './types';
2
+ export declare function switchSortDirection(direction: SortDirection | undefined): SortDirection;
@@ -0,0 +1,11 @@
1
+ function switchSortDirection(direction) {
2
+ if (direction === 'ASC')
3
+ return 'DESC';
4
+ if (direction === 'DESC')
5
+ return 'ASC';
6
+ if (direction === 'NONE')
7
+ return 'ASC';
8
+ return 'NONE';
9
+ }
10
+
11
+ export { switchSortDirection };
@@ -1,18 +1,19 @@
1
- import { TableColumnProperties } from './table-column-properties';
1
+ import { UUID } from '../../shared/utils/uuid';
2
+ import { TableColumnProperties, THProps } from './types';
2
3
  export type OnColumnChangedHandler = (columnProps: TableColumnProperties) => void;
3
4
  export interface TableContextValue {
4
5
  register: {
5
- cell: (rowIndex: number, onColumnChanged: OnColumnChangedHandler) => {
6
+ cell: (rowId: UUID, onColumnChanged: OnColumnChangedHandler) => {
6
7
  deregister: VoidFunction;
7
8
  };
8
- column: (rowIndex: number, props: TableColumnProperties) => {
9
+ column: (rowId: UUID, props: THProps) => {
9
10
  deregister: VoidFunction;
10
11
  update: OnColumnChangedHandler;
11
12
  };
12
13
  row: () => {
13
14
  deregister: VoidFunction;
14
- index: number;
15
+ id: UUID;
15
16
  };
16
17
  };
17
18
  }
18
- export declare const TableContext: React.Context<TableContextValue>;
19
+ export declare const TableContext: React.Context<TableContextValue | undefined>;
@@ -1,21 +1,6 @@
1
1
  "use client";
2
2
  import { createContext } from 'react';
3
- import { voidFunction } from '../../shared/model/defaults.js';
4
3
 
5
- const TableContext = createContext({
6
- register: {
7
- cell: () => ({
8
- deregister: voidFunction,
9
- }),
10
- column: () => ({
11
- deregister: voidFunction,
12
- update: voidFunction,
13
- }),
14
- row: () => ({
15
- deregister: voidFunction,
16
- index: -1,
17
- }),
18
- },
19
- });
4
+ const TableContext = createContext(undefined);
20
5
 
21
6
  export { TableContext };
@@ -1,18 +1,19 @@
1
1
  import { ReactNode } from 'react';
2
- import { TableColumnProperties } from './table-column-properties';
2
+ import { UUID } from '../../shared/utils/uuid';
3
3
  import { OnColumnChangedHandler } from './table-context';
4
+ import { TableColumnProperties } from './types';
4
5
  export interface ColumnInfo {
5
- index: number;
6
+ id: UUID;
6
7
  props: TableColumnProperties;
7
- rowIndex: number;
8
+ rowId: UUID;
8
9
  }
9
10
  export interface CellInfo {
10
- index: number;
11
+ id: UUID;
11
12
  onColumnChanged: OnColumnChangedHandler;
12
13
  }
13
14
  export interface RowInfo {
14
15
  cells: CellInfo[];
15
- index: number;
16
+ id: UUID;
16
17
  }
17
18
  export declare function TableProvider({ children, onColumnsChanged, }: {
18
19
  children: ReactNode | ((args: {
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { useRef, useMemo } from 'react';
4
+ import { voidFunction } from '../../shared/model/defaults.js';
5
+ import { createUUID } from '../../shared/utils/uuid.js';
4
6
  import { TableContext } from './table-context.js';
5
7
 
6
8
  function TableProvider({ children, onColumnsChanged, }) {
@@ -8,46 +10,50 @@ function TableProvider({ children, onColumnsChanged, }) {
8
10
  const rowsRef = useRef([]);
9
11
  const value = useMemo(() => ({
10
12
  register: {
11
- cell: (rowIndex, onColumnChanged) => {
12
- const row = rowsRef.current[rowIndex];
13
+ cell: (rowId, onColumnChanged) => {
14
+ const row = rowsRef.current.find(row => row.id === rowId);
13
15
  if (!row)
14
- throw new Error(`Row with index ${rowIndex} does not exist.`);
15
- const cell = { index: -1, onColumnChanged };
16
- cell.index = row.cells.push(cell) - 1;
16
+ return { deregister: voidFunction }; // throw new Error(`Row with id ${id} does not exist.`)
17
+ const cell = { id: createUUID(), onColumnChanged };
18
+ row.cells.push(cell);
17
19
  return {
18
20
  deregister: () => {
19
- row.cells = row.cells.filter(c => c.index !== cell.index);
21
+ row.cells = row.cells.filter(c => c.id !== cell.id);
20
22
  },
21
23
  };
22
24
  },
23
- column: (rowIndex, props) => {
24
- const column = { index: -1, props, rowIndex };
25
- column.index = columnsRef.current.push(column) - 1;
25
+ column: (rowId, props) => {
26
+ const column = {
27
+ id: createUUID(),
28
+ props,
29
+ rowId,
30
+ };
31
+ columnsRef.current.push(column);
26
32
  onColumnsChanged?.(columnsRef.current);
27
33
  return {
28
34
  deregister: () => {
29
- columnsRef.current = columnsRef.current.filter(c => c.index !== column.index);
35
+ columnsRef.current = columnsRef.current.filter(c => c.id !== column.id);
30
36
  onColumnsChanged?.(columnsRef.current);
31
37
  },
32
38
  update: (props) => {
33
- const updatedColumn = columnsRef.current.find(c => c.index === column.index);
39
+ const updatedColumn = columnsRef.current.find(c => c.id === column.id);
34
40
  if (!updatedColumn)
35
- throw new Error(`Column with index ${column.index} does not exist.`);
41
+ throw new Error(`Column with id ${column.id} does not exist.`);
36
42
  updatedColumn.props = props;
37
43
  rowsRef.current.forEach(row => row.cells
38
- .find(cell => cell.index === column.index)
44
+ .find(cell => cell.id === column.id)
39
45
  ?.onColumnChanged(props));
40
46
  },
41
47
  };
42
48
  },
43
49
  row: () => {
44
- const row = { cells: [], index: -1 };
45
- row.index = rowsRef.current.push(row) - 1;
50
+ const row = { cells: [], id: createUUID() };
51
+ rowsRef.current.push(row);
46
52
  return {
47
53
  deregister: () => {
48
- rowsRef.current = rowsRef.current.filter(r => r.index !== row.index);
54
+ rowsRef.current = rowsRef.current.filter(r => r.id !== row.id);
49
55
  },
50
- index: row.index,
56
+ id: row.id,
51
57
  };
52
58
  },
53
59
  },
@@ -1,11 +1,11 @@
1
- import { TableColumnProperties } from './table-column-properties';
2
1
  import { OnColumnChangedHandler } from './table-context';
2
+ import { THProps } from './types';
3
3
  export interface TableRowContextValue {
4
4
  register: {
5
5
  cell: (onColumnChanged: OnColumnChangedHandler) => {
6
6
  deregister: VoidFunction;
7
7
  };
8
- column: (props: TableColumnProperties) => {
8
+ column: (props: THProps) => {
9
9
  deregister: VoidFunction;
10
10
  update: OnColumnChangedHandler;
11
11
  };
@@ -6,20 +6,20 @@ import { useTable } from './use-table.js';
6
6
 
7
7
  function TableRowProvider({ children }) {
8
8
  const { register } = useTable();
9
- const [{ deregister, index }] = useState(() => register.row());
9
+ const [{ deregister, id }] = useState(() => register.row());
10
10
  useEffect(() => {
11
11
  return deregister;
12
12
  }, [deregister]);
13
13
  const value = useMemo(() => ({
14
14
  register: {
15
15
  cell: onColumnChanged => {
16
- return register.cell(index, onColumnChanged);
16
+ return register.cell(id, onColumnChanged);
17
17
  },
18
18
  column: props => {
19
- return register.column(index, props);
19
+ return register.column(id, props);
20
20
  },
21
21
  },
22
- }), [index, register]);
22
+ }), [id, register]);
23
23
  return (jsx(TableRowContext.Provider, { value: value, children: children }));
24
24
  }
25
25
 
@@ -1,11 +1,12 @@
1
- import { TableColumnAlignment } from './table-column-properties';
2
- type SortDirection = 'ascending' | 'descending';
1
+ import { ReactNode } from 'react';
2
+ import { TranslationId } from '../../intl/translation-id';
3
+ import { SortDirection, SortHanlder, TableColumnAlignment } from './types';
3
4
  export interface TableSortButtonProps {
4
- active?: boolean;
5
5
  align?: TableColumnAlignment;
6
- children: string;
6
+ children: ReactNode;
7
+ columnName: TranslationId;
7
8
  direction?: SortDirection;
8
- onClick: (direction: SortDirection) => void;
9
+ onSort: SortHanlder;
10
+ sortKey: string;
9
11
  }
10
- export declare function TableSortButton({ active, align, children, direction, onClick, }: TableSortButtonProps): import("react/jsx-runtime").JSX.Element;
11
- export {};
12
+ export declare function TableSortButton({ align, children, columnName, direction, onSort, sortKey, }: TableSortButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -5,14 +5,15 @@ import { GlyphsChevronsBoldUpIcon } from '../../icons/glyph/glyphs-chevrons-bold
5
5
  import { useFormattedMessage } from '../../intl/use-formatted-message.js';
6
6
  import styles from './table.module.css.js';
7
7
 
8
- function TableSortButton({ active, align = 'start', children, direction = 'descending', onClick, }) {
8
+ function TableSortButton({ align = 'start', children, columnName, direction = 'NONE', onSort, sortKey, }) {
9
9
  const t = useFormattedMessage();
10
+ const isActive = direction !== 'NONE';
10
11
  const ariaLabel = `
11
12
  ${t('Sort by')}
12
- ${children}
13
- ${active && `(${t('active')}, ${t(direction)})`}
13
+ ${t(columnName)}
14
+ ${isActive && `(${t('active')}, ${t(direction)})`}
14
15
  `;
15
- return (jsxs("button", { "aria-label": ariaLabel, className: clsx(styles['table-sort-button'], active && styles['active'], styles[direction], styles[align]), onClick: () => onClick(direction), type: "button", children: [jsx("span", { className: styles['label'], children: children }), jsx(GlyphsChevronsBoldUpIcon, { "aria-label": t(direction), className: styles['icon'] })] }));
16
+ return (jsxs("button", { "aria-label": ariaLabel, className: clsx(styles['table-sort-button'], isActive && styles['active'], styles[direction.toLowerCase()], styles[align]), onClick: () => onSort(sortKey, direction), type: "button", children: [jsx("span", { className: styles['label'], children: children }), isActive && (jsx(GlyphsChevronsBoldUpIcon, { "aria-label": t(direction), className: styles['icon'] }))] }));
16
17
  }
17
18
 
18
19
  export { TableSortButton };
@@ -2,7 +2,7 @@ export interface TableProps {
2
2
  'aria-describedby'?: string;
3
3
  'aria-label'?: string;
4
4
  'aria-rowcount'?: number;
5
- children: React.ReactNode;
5
+ children?: React.ReactNode;
6
6
  className?: string;
7
7
  cssColumns?: string;
8
8
  'data-test-selector'?: string;
@@ -12,10 +12,10 @@ function Table({ 'aria-describedby': ariaDescribedBy, 'aria-label': ariaLabel, '
12
12
  const onColumnsChanged = useCallback((columnInfos) => {
13
13
  tableRef.current?.style.setProperty('--columns', columnInfos.length.toString());
14
14
  setColgroup(columnInfos.map(col => {
15
- return (jsx(Col, { selected: col.props.selected, span: col.props.colSpan, sticky: col.props.sticky }, col.index));
15
+ return (jsx(Col, { selected: col.props.selected, span: col.props.colSpan, sticky: col.props.sticky }, col.id));
16
16
  }));
17
17
  }, []);
18
- return (jsx("div", { className: styles['table-container'], children: jsx(TableProvider, { onColumnsChanged: onColumnsChanged, children: jsxs("table", { ref: tableRef, "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel, "aria-rowcount": ariaRowCount, className: clsx(styles['table'], stretch && styles.stretch, nowrap && styles['nowrap'], (highlight === 'row' || highlight === 'both') && styles['hl-row'], (highlight === 'col' || highlight === 'both') && styles['hl-col'], className), "data-test-selector": dataTestSelector, style: {
18
+ return (jsx("div", { className: clsx(styles['table-container'], className), children: jsx(TableProvider, { onColumnsChanged: onColumnsChanged, children: jsxs("table", { ref: tableRef, "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel, "aria-rowcount": ariaRowCount, className: clsx(styles['table'], stretch && styles.stretch, nowrap && styles['nowrap'], (highlight === 'row' || highlight === 'both') && styles['hl-row'], (highlight === 'col' || highlight === 'both') && styles['hl-col']), "data-test-selector": dataTestSelector, style: {
19
19
  '--columns': 0,
20
20
  '--grid-columns': cssColumns,
21
21
  }, children: [colgroup && (jsx("colgroup", { className: styles['colgroup'], children: colgroup })), thead && jsx("thead", { className: styles['thead'], children: thead }), jsx("tbody", { className: styles['tbody'], children: children })] }) }) }));
@@ -1,3 +1,3 @@
1
- var styles = {"table-container":"table-module-pevNG","table":"table-module-k47fT","colgroup":"table-module-1lgqE","col":"table-module-dISOo","selected":"table-module-WGz-I","sticky":"table-module-PQejy","th":"table-module-jRXnY","td":"table-module-wJwSq","start":"table-module-EWdty","end":"table-module-yJD74","center":"table-module-XAdfy","nowrap":"table-module-h7qdo","tr":"table-module-Nisf1","hl-row":"table-module-3zZB6","clickable":"table-module-qRfjM","thead":"table-module-DK-wn","tbody":"table-module-tygZb","stretch":"table-module-YnmWV","caption":"table-module-skhNZ","hl-col":"table-module-JEp5f","table-sort-button":"table-module-RtOV-","label":"table-module-ukG8s","icon":"table-module-QdiLJ","active":"table-module-gWy-a","ascending":"table-module-SjJ57","descending":"table-module--p8TF"};
1
+ var styles = {"table-container":"table-module-pevNG","table":"table-module-k47fT","colgroup":"table-module-1lgqE","col":"table-module-dISOo","selected":"table-module-WGz-I","sticky":"table-module-PQejy","th":"table-module-jRXnY","td":"table-module-wJwSq","nowrap":"table-module-h7qdo","start":"table-module-EWdty","end":"table-module-yJD74","center":"table-module-XAdfy","tr":"table-module-Nisf1","hl-row":"table-module-3zZB6","clickable":"table-module-qRfjM","thead":"table-module-DK-wn","tbody":"table-module-tygZb","stretch":"table-module-YnmWV","caption":"table-module-skhNZ","hl-col":"table-module-JEp5f","sortable":"table-module-hyPmy","table-sort-button":"table-module-RtOV-","label":"table-module-ukG8s","icon":"table-module-QdiLJ","active":"table-module-gWy-a","asc":"table-module-9AwNp","desc":"table-module-aYS8r"};
2
2
 
3
3
  export { styles as default };
@@ -1,4 +1,4 @@
1
- import { TableColumnProperties } from './table-column-properties';
1
+ import { TableColumnProperties } from './types';
2
2
  export interface TDProps extends TableColumnProperties {
3
3
  children: React.ReactNode;
4
4
  className?: string;
@@ -1,8 +1,2 @@
1
- import { TableColumnProperties } from './table-column-properties';
2
- export interface THProps extends TableColumnProperties {
3
- 'aria-sort'?: 'ascending' | 'descending' | 'none' | 'other';
4
- children: React.ReactNode;
5
- className?: string;
6
- scope?: 'col' | 'row' | 'colgroup' | 'rowgroup';
7
- }
1
+ import { THProps } from './types';
8
2
  export declare function TH(props: THProps): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,12 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import clsx from 'clsx';
4
- import { Truncated } from '../../text/truncated/truncated.js';
5
4
  import { useTH } from './use-th.js';
6
5
  import styles from './table.module.css.js';
7
6
 
8
7
  function TH(props) {
9
- const { align = 'start', 'aria-sort': ariaSort, children, className, colSpan, nowrap, rowSpan, scope, sticky, truncated, } = useTH(props);
10
- return (jsx("th", { "aria-sort": ariaSort, className: clsx(styles['th'], styles[align], nowrap && styles['nowrap'], sticky && styles['sticky'], className), colSpan: colSpan, rowSpan: rowSpan, scope: scope, children: truncated ? (jsx(Truncated, { lines: typeof truncated === 'number' ? truncated : undefined, children: children })) : (children) }));
8
+ const { align = 'start', 'aria-sort': ariaSort, children, className, colSpan, nowrap, rowSpan, scope, sortable, sticky, } = useTH(props);
9
+ return (jsx("th", { "aria-sort": ariaSort, className: clsx(styles['th'], styles[align], nowrap && styles['nowrap'], sticky && styles['sticky'], sortable && styles['sortable'], className), colSpan: colSpan, rowSpan: rowSpan, scope: scope, children: children }));
11
10
  }
12
11
 
13
12
  export { TH };
@@ -1,8 +1,2 @@
1
- import { ReactNode } from 'react';
2
- import { TableColumnProperties } from './table-column-properties';
3
- export interface TRProps extends TableColumnProperties {
4
- children: ReactNode;
5
- className?: string;
6
- onClick?: (event: React.MouseEvent<HTMLTableRowElement>) => void;
7
- }
8
- export declare function TR(props: TRProps): import("react/jsx-runtime").JSX.Element;
1
+ import { TRProps } from './types';
2
+ export declare function TR({ children, className, onClick, selected }: TRProps): import("react/jsx-runtime").JSX.Element;
@@ -2,11 +2,9 @@
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import clsx from 'clsx';
4
4
  import { TableRowProvider } from './table-row-provider.js';
5
- import { useTR } from './use-tr.js';
6
5
  import styles from './table.module.css.js';
7
6
 
8
- function TR(props) {
9
- const { children, className, onClick, selected } = useTR(props);
7
+ function TR({ children, className, onClick, selected }) {
10
8
  return (jsx(TableRowProvider, { children: jsx("tr", { "aria-selected": selected, className: clsx(styles['tr'], selected && styles['selected'], Boolean(onClick) && styles['clickable'], className), onClick: onClick, children: children }) }));
11
9
  }
12
10
 
@@ -0,0 +1,36 @@
1
+ import { ReactNode } from 'react';
2
+ export type SortDirection = 'ASC' | 'DESC' | 'NONE';
3
+ export type TableColumnAlignment = 'start' | 'center' | 'end';
4
+ export type SortHanlder = (key: string, direction: SortDirection) => void;
5
+ export interface SortOptionsEnabled {
6
+ columnName?: string;
7
+ direction?: SortDirection;
8
+ isEnabled: true;
9
+ }
10
+ export interface SortOptionsDisabled {
11
+ isEnabled: false;
12
+ }
13
+ export type SortOptions = SortOptionsEnabled | SortOptionsDisabled;
14
+ export interface TableColumnProperties {
15
+ align?: TableColumnAlignment;
16
+ colSpan?: number;
17
+ cssColumn?: string;
18
+ nowrap?: boolean;
19
+ rowSpan?: number;
20
+ selected?: boolean;
21
+ sticky?: boolean;
22
+ truncated?: boolean | number;
23
+ }
24
+ export interface THProps extends TableColumnProperties {
25
+ 'aria-sort'?: 'ascending' | 'descending' | 'none' | 'other';
26
+ children: ReactNode;
27
+ className?: string;
28
+ scope?: 'col' | 'row' | 'colgroup' | 'rowgroup';
29
+ sortable?: boolean;
30
+ }
31
+ export interface TRProps {
32
+ children: ReactNode;
33
+ className?: string;
34
+ onClick?: (event: React.MouseEvent<HTMLTableRowElement>) => void;
35
+ selected?: boolean;
36
+ }
@@ -3,10 +3,8 @@ import { TableContext } from './table-context.js';
3
3
 
4
4
  function useTable() {
5
5
  const context = useContext(TableContext);
6
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7
- if (!context) {
6
+ if (!context)
8
7
  throw new Error('useTable must be used within a TableProvider');
9
- }
10
8
  return context;
11
9
  }
12
10
 
@@ -1,2 +1,2 @@
1
- import { TableColumnProperties } from './table-column-properties';
1
+ import { TableColumnProperties } from './types';
2
2
  export declare function useTD<TProps extends TableColumnProperties>(props: TProps): TProps;
@@ -1,2 +1,2 @@
1
- import { TableColumnProperties } from './table-column-properties';
2
- export declare function useTH<TProps extends TableColumnProperties>(props: TProps): TProps;
1
+ import { THProps } from './types';
2
+ export declare function useTH<TProps extends THProps>(props: TProps): TProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "188.0.0",
3
+ "version": "189.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -1,19 +0,0 @@
1
- const scrollToTop = (scrollOptions) => {
2
- window?.scrollTo({
3
- behavior: scrollOptions?.behavior || 'smooth',
4
- top: 0,
5
- });
6
- };
7
- const scrollTo = (ref, scrollOptions) => () => {
8
- if (!ref.current)
9
- return;
10
- const rect = ref.current.getBoundingClientRect();
11
- const scrollPadding = scrollOptions?.scrollPadding || 12;
12
- const scrollY = (window?.scrollY || 0) + rect.top - scrollPadding;
13
- window?.scrollTo({
14
- behavior: scrollOptions?.behavior || 'smooth',
15
- top: scrollY,
16
- });
17
- };
18
-
19
- export { scrollTo, scrollToTop };