@sonic-equipment/ui 181.0.0 → 182.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 (53) hide show
  1. package/dist/cards/data-card/data-card.d.ts +30 -18
  2. package/dist/cards/data-card/data-card.js +38 -6
  3. package/dist/cards/data-card/data-card.module.css.js +1 -1
  4. package/dist/config.d.ts +1 -0
  5. package/dist/config.js +7 -0
  6. package/dist/exports.d.ts +18 -0
  7. package/dist/header/connected-header.js +1 -1
  8. package/dist/header/header.d.ts +3 -1
  9. package/dist/header/header.js +3 -2
  10. package/dist/icons/glyph/glyphs-chevrons-bold-up-icon.js +7 -0
  11. package/dist/index.js +17 -0
  12. package/dist/intl/translation-id.d.ts +1 -1
  13. package/dist/pages/my-sonic/widgets/components/address-data-card.d.ts +4 -4
  14. package/dist/styles.css +416 -41
  15. package/dist/table/data-table.d.ts +19 -0
  16. package/dist/table/data-table.js +47 -0
  17. package/dist/table/data-table.module.css.js +3 -0
  18. package/dist/table/elements/col.d.ts +7 -0
  19. package/dist/table/elements/col.js +9 -0
  20. package/dist/table/elements/table-column-properties.d.ts +10 -0
  21. package/dist/table/elements/table-context.d.ts +18 -0
  22. package/dist/table/elements/table-context.js +20 -0
  23. package/dist/table/elements/table-provider.d.ts +22 -0
  24. package/dist/table/elements/table-provider.js +59 -0
  25. package/dist/table/elements/table-row-context.d.ts +14 -0
  26. package/dist/table/elements/table-row-context.js +16 -0
  27. package/dist/table/elements/table-row-provider.d.ts +4 -0
  28. package/dist/table/elements/table-row-provider.js +25 -0
  29. package/dist/table/elements/table-sort-button.d.ts +11 -0
  30. package/dist/table/elements/table-sort-button.js +17 -0
  31. package/dist/table/elements/table.d.ts +14 -0
  32. package/dist/table/elements/table.js +23 -0
  33. package/dist/table/elements/table.module.css.js +3 -0
  34. package/dist/table/elements/td.d.ts +6 -0
  35. package/dist/table/elements/td.js +12 -0
  36. package/dist/table/elements/th.d.ts +8 -0
  37. package/dist/table/elements/th.js +12 -0
  38. package/dist/table/elements/tr.d.ts +8 -0
  39. package/dist/table/elements/tr.js +12 -0
  40. package/dist/table/elements/use-table-row.d.ts +1 -0
  41. package/dist/table/elements/use-table-row.js +8 -0
  42. package/dist/table/elements/use-table.d.ts +2 -0
  43. package/dist/table/elements/use-table.js +13 -0
  44. package/dist/table/elements/use-td.d.ts +2 -0
  45. package/dist/table/elements/use-td.js +26 -0
  46. package/dist/table/elements/use-th.d.ts +2 -0
  47. package/dist/table/elements/use-th.js +22 -0
  48. package/dist/table/elements/use-tr.d.ts +2 -0
  49. package/dist/table/elements/use-tr.js +16 -0
  50. package/dist/text/truncated/truncated.d.ts +6 -0
  51. package/dist/text/truncated/truncated.js +9 -0
  52. package/dist/text/truncated/truncated.module.css.js +3 -0
  53. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useRef, useMemo } from 'react';
3
+ import { TableContext } from './table-context.js';
4
+
5
+ function TableProvider({ children, onColumnsChanged, }) {
6
+ const columnsRef = useRef([]);
7
+ const rowsRef = useRef([]);
8
+ const value = useMemo(() => ({
9
+ register: {
10
+ cell: (rowIndex, onColumnChanged) => {
11
+ const row = rowsRef.current[rowIndex];
12
+ if (!row)
13
+ throw new Error(`Row with index ${rowIndex} does not exist.`);
14
+ const cell = { index: -1, onColumnChanged };
15
+ cell.index = row.cells.push(cell) - 1;
16
+ return {
17
+ deregister: () => {
18
+ row.cells = row.cells.filter(c => c.index !== cell.index);
19
+ },
20
+ };
21
+ },
22
+ column: (rowIndex, props) => {
23
+ const column = { index: -1, props, rowIndex };
24
+ column.index = columnsRef.current.push(column) - 1;
25
+ onColumnsChanged?.(columnsRef.current);
26
+ return {
27
+ deregister: () => {
28
+ columnsRef.current = columnsRef.current.filter(c => c.index !== column.index);
29
+ onColumnsChanged?.(columnsRef.current);
30
+ },
31
+ update: (props) => {
32
+ const updatedColumn = columnsRef.current.find(c => c.index === column.index);
33
+ if (!updatedColumn)
34
+ throw new Error(`Column with index ${column.index} does not exist.`);
35
+ updatedColumn.props = props;
36
+ rowsRef.current.forEach(row => row.cells
37
+ .find(cell => cell.index === column.index)
38
+ ?.onColumnChanged(props));
39
+ },
40
+ };
41
+ },
42
+ row: () => {
43
+ const row = { cells: [], index: -1 };
44
+ row.index = rowsRef.current.push(row) - 1;
45
+ return {
46
+ deregister: () => {
47
+ rowsRef.current = rowsRef.current.filter(r => r.index !== row.index);
48
+ },
49
+ index: row.index,
50
+ };
51
+ },
52
+ },
53
+ }), [onColumnsChanged]);
54
+ return (jsx(TableContext.Provider, { value: value, children: children instanceof Function
55
+ ? children({ columnInfos: columnsRef.current })
56
+ : children }));
57
+ }
58
+
59
+ export { TableProvider };
@@ -0,0 +1,14 @@
1
+ import { TableColumnProperties } from './table-column-properties';
2
+ import { OnColumnChangedHandler } from './table-context';
3
+ export interface TableRowContextValue {
4
+ register: {
5
+ cell: (onColumnChanged: OnColumnChangedHandler) => {
6
+ deregister: VoidFunction;
7
+ };
8
+ column: (props: TableColumnProperties) => {
9
+ deregister: VoidFunction;
10
+ update: OnColumnChangedHandler;
11
+ };
12
+ };
13
+ }
14
+ export declare const TableRowContext: React.Context<TableRowContextValue>;
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+ import { voidFunction } from '../../shared/model/defaults.js';
3
+
4
+ const TableRowContext = createContext({
5
+ register: {
6
+ cell: () => ({
7
+ deregister: voidFunction,
8
+ }),
9
+ column: () => ({
10
+ deregister: voidFunction,
11
+ update: voidFunction,
12
+ }),
13
+ },
14
+ });
15
+
16
+ export { TableRowContext };
@@ -0,0 +1,4 @@
1
+ import { ReactNode } from 'react';
2
+ export declare function TableRowProvider({ children }: {
3
+ children: ReactNode;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useState, useEffect, useMemo } from 'react';
3
+ import { TableRowContext } from './table-row-context.js';
4
+ import { useTable } from './use-table.js';
5
+
6
+ function TableRowProvider({ children }) {
7
+ const { register } = useTable();
8
+ const [{ deregister, index }] = useState(() => register.row());
9
+ useEffect(() => {
10
+ return deregister;
11
+ }, [deregister]);
12
+ const value = useMemo(() => ({
13
+ register: {
14
+ cell: onColumnChanged => {
15
+ return register.cell(index, onColumnChanged);
16
+ },
17
+ column: props => {
18
+ return register.column(index, props);
19
+ },
20
+ },
21
+ }), [index, register]);
22
+ return (jsx(TableRowContext.Provider, { value: value, children: children }));
23
+ }
24
+
25
+ export { TableRowProvider };
@@ -0,0 +1,11 @@
1
+ import { TableColumnAlignment } from './table-column-properties';
2
+ type SortDirection = 'ascending' | 'descending';
3
+ export interface TableSortButtonProps {
4
+ active?: boolean;
5
+ align?: TableColumnAlignment;
6
+ children: string;
7
+ direction?: SortDirection;
8
+ onClick: (direction: SortDirection) => void;
9
+ }
10
+ export declare function TableSortButton({ active, align, children, direction, onClick, }: TableSortButtonProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,17 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import { GlyphsChevronsBoldUpIcon } from '../../icons/glyph/glyphs-chevrons-bold-up-icon.js';
4
+ import { useFormattedMessage } from '../../intl/use-formatted-message.js';
5
+ import styles from './table.module.css.js';
6
+
7
+ function TableSortButton({ active, align = 'start', children, direction = 'descending', onClick, }) {
8
+ const t = useFormattedMessage();
9
+ const ariaLabel = `
10
+ ${t('Sort by')}
11
+ ${children}
12
+ ${active && `(${t('active')}, ${t(direction)})`}
13
+ `;
14
+ 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'] })] }));
15
+ }
16
+
17
+ export { TableSortButton };
@@ -0,0 +1,14 @@
1
+ export interface TableProps {
2
+ 'aria-describedby'?: string;
3
+ 'aria-label'?: string;
4
+ 'aria-rowcount'?: number;
5
+ children: React.ReactNode;
6
+ className?: string;
7
+ cssColumns?: string;
8
+ 'data-test-selector'?: string;
9
+ highlight?: 'row' | 'col' | 'both';
10
+ nowrap?: boolean;
11
+ stretch?: boolean;
12
+ thead?: React.ReactNode;
13
+ }
14
+ export declare function Table({ 'aria-describedby': ariaDescribedBy, 'aria-label': ariaLabel, 'aria-rowcount': ariaRowCount, children, className, cssColumns, 'data-test-selector': dataTestSelector, highlight, nowrap, stretch, thead, }: TableProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useRef, useState, useCallback } from 'react';
3
+ import clsx from 'clsx';
4
+ import { Col } from './col.js';
5
+ import { TableProvider } from './table-provider.js';
6
+ import styles from './table.module.css.js';
7
+
8
+ function Table({ 'aria-describedby': ariaDescribedBy, 'aria-label': ariaLabel, 'aria-rowcount': ariaRowCount, children, className, cssColumns, 'data-test-selector': dataTestSelector, highlight, nowrap, stretch, thead, }) {
9
+ const tableRef = useRef(null);
10
+ const [colgroup, setColgroup] = useState([]);
11
+ const onColumnsChanged = useCallback((columnInfos) => {
12
+ tableRef.current?.style.setProperty('--columns', columnInfos.length.toString());
13
+ setColgroup(columnInfos.map(col => {
14
+ return (jsx(Col, { selected: col.props.selected, span: col.props.colSpan, sticky: col.props.sticky }, col.index));
15
+ }));
16
+ }, []);
17
+ 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
+ '--columns': 0,
19
+ '--grid-columns': cssColumns,
20
+ }, children: [colgroup && (jsx("colgroup", { className: styles['colgroup'], children: colgroup })), thead && jsx("thead", { className: styles['thead'], children: thead }), jsx("tbody", { className: styles['tbody'], children: children })] }) }) }));
21
+ }
22
+
23
+ export { Table };
@@ -0,0 +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"};
2
+
3
+ export { styles as default };
@@ -0,0 +1,6 @@
1
+ import { TableColumnProperties } from './table-column-properties';
2
+ export interface TDProps extends TableColumnProperties {
3
+ children: React.ReactNode;
4
+ className?: string;
5
+ }
6
+ export declare function TD(props: TDProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import { Truncated } from '../../text/truncated/truncated.js';
4
+ import { useTD } from './use-td.js';
5
+ import styles from './table.module.css.js';
6
+
7
+ function TD(props) {
8
+ const { align = 'start', children, className, colSpan, nowrap, rowSpan, sticky, truncated, } = useTD(props);
9
+ return (jsx("td", { className: clsx(styles['td'], styles[align], nowrap && styles['nowrap'], sticky && styles['sticky'], className), colSpan: colSpan, rowSpan: rowSpan, children: truncated ? (jsx(Truncated, { lines: typeof truncated === 'number' ? truncated : undefined, children: children })) : (children) }));
10
+ }
11
+
12
+ export { TD };
@@ -0,0 +1,8 @@
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
+ }
8
+ export declare function TH(props: THProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import { Truncated } from '../../text/truncated/truncated.js';
4
+ import { useTH } from './use-th.js';
5
+ import styles from './table.module.css.js';
6
+
7
+ function TH(props) {
8
+ const { align = 'start', 'aria-sort': ariaSort, children, className, colSpan, nowrap, rowSpan, scope, sticky, truncated, } = useTH(props);
9
+ 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) }));
10
+ }
11
+
12
+ export { TH };
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,12 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import { TableRowProvider } from './table-row-provider.js';
4
+ import { useTR } from './use-tr.js';
5
+ import styles from './table.module.css.js';
6
+
7
+ function TR(props) {
8
+ const { children, className, onClick, selected } = useTR(props);
9
+ 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 }) }));
10
+ }
11
+
12
+ export { TR };
@@ -0,0 +1 @@
1
+ export declare function useTableRow(): import("./table-row-context").TableRowContextValue;
@@ -0,0 +1,8 @@
1
+ import { useContext } from 'react';
2
+ import { TableRowContext } from './table-row-context.js';
3
+
4
+ function useTableRow() {
5
+ return useContext(TableRowContext);
6
+ }
7
+
8
+ export { useTableRow };
@@ -0,0 +1,2 @@
1
+ import { TableContextValue } from './table-context';
2
+ export declare function useTable(): TableContextValue;
@@ -0,0 +1,13 @@
1
+ import { useContext } from 'react';
2
+ import { TableContext } from './table-context.js';
3
+
4
+ function useTable() {
5
+ const context = useContext(TableContext);
6
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
7
+ if (!context) {
8
+ throw new Error('useTable must be used within a TableProvider');
9
+ }
10
+ return context;
11
+ }
12
+
13
+ export { useTable };
@@ -0,0 +1,2 @@
1
+ import { TableColumnProperties } from './table-column-properties';
2
+ export declare function useTD<TProps extends TableColumnProperties>(props: TProps): TProps;
@@ -0,0 +1,26 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+ import { useTableRow } from './use-table-row.js';
3
+
4
+ function useTD(props) {
5
+ const [columnProps, setColumnProps] = useState(null);
6
+ const { register } = useTableRow();
7
+ const onColumnChanged = useCallback((columnProps) => {
8
+ setColumnProps(columnProps);
9
+ }, []);
10
+ const [{ deregister }] = useState(register.cell(onColumnChanged));
11
+ useEffect(() => {
12
+ return deregister;
13
+ }, [deregister]);
14
+ return {
15
+ ...props,
16
+ align: columnProps?.align ?? props.align ?? 'start',
17
+ colSpan: columnProps?.colSpan ?? props.colSpan ?? 1,
18
+ nowrap: columnProps?.nowrap ?? props.nowrap ?? false,
19
+ rowSpan: columnProps?.rowSpan ?? props.rowSpan ?? 1,
20
+ selected: columnProps?.selected ?? props.selected ?? false,
21
+ sticky: columnProps?.sticky ?? props.sticky ?? false,
22
+ truncated: columnProps?.truncated ?? props.truncated ?? false,
23
+ };
24
+ }
25
+
26
+ export { useTD };
@@ -0,0 +1,2 @@
1
+ import { TableColumnProperties } from './table-column-properties';
2
+ export declare function useTH<TProps extends TableColumnProperties>(props: TProps): TProps;
@@ -0,0 +1,22 @@
1
+ import { useRef, useEffect } from 'react';
2
+ import { useTableRow } from './use-table-row.js';
3
+
4
+ function useTH(props) {
5
+ const { register } = useTableRow();
6
+ const updateRef = useRef();
7
+ useEffect(() => {
8
+ const { deregister, update } = register.column(props);
9
+ updateRef.current = update;
10
+ return () => {
11
+ deregister();
12
+ updateRef.current = undefined;
13
+ };
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ }, [register]);
16
+ useEffect(() => {
17
+ updateRef.current?.(props);
18
+ }, [props]);
19
+ return props;
20
+ }
21
+
22
+ export { useTH };
@@ -0,0 +1,2 @@
1
+ import { TableColumnProperties } from './table-column-properties';
2
+ export declare function useTR<TProps extends TableColumnProperties>(props: TProps): TProps;
@@ -0,0 +1,16 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { useTableRow } from './use-table-row.js';
3
+
4
+ function useTR(props) {
5
+ const { register } = useTableRow();
6
+ const [{ deregister, update }] = useState(register.column(props));
7
+ useEffect(() => {
8
+ return deregister;
9
+ }, [deregister]);
10
+ useEffect(() => {
11
+ update(props);
12
+ }, [props, update]);
13
+ return props;
14
+ }
15
+
16
+ export { useTR };
@@ -0,0 +1,6 @@
1
+ export interface TruncatedProps {
2
+ active?: boolean;
3
+ children: React.ReactNode;
4
+ lines?: number;
5
+ }
6
+ export declare function Truncated({ active, children, lines, }: TruncatedProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import clsx from 'clsx';
3
+ import styles from './truncated.module.css.js';
4
+
5
+ function Truncated({ active = true, children, lines = 1, }) {
6
+ return (jsx("div", { className: clsx(styles['truncated'], active && styles['active']), style: { '--lines': lines }, title: children?.toString(), children: children }));
7
+ }
8
+
9
+ export { Truncated };
@@ -0,0 +1,3 @@
1
+ var styles = {"truncated":"truncated-module-bwo1A","active":"truncated-module-JHMUL"};
2
+
3
+ export { styles as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "181.0.0",
3
+ "version": "182.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {