@canonical/maas-react-components 2.1.0 → 2.3.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.
- package/dist/@canonical/maas-react-components.es.js +1323 -1212
- package/dist/@canonical/maas-react-components.umd.js +16 -16
- package/dist/maas-react-components.css +1 -1
- package/dist/src/lib/components/GenericTable/GenericTable.d.ts +11 -4
- package/dist/src/lib/components/GenericTable/components/TableCheckbox/TableCheckbox.d.ts +3 -3
- package/dist/src/lib/components/GenericTable/types.d.ts +5 -1
- package/dist/src/lib/components/GenericTable/utils/processColumnDefs.d.ts +1 -2
- package/dist/src/lib/components/GenericTable/utils/renderLoadingRows.d.ts +4 -2
- package/dist/src/lib/elements/Placeholder/Placeholder.d.ts +39 -9
- package/dist/src/lib/elements/Placeholder/Placeholder.stories.d.ts +7 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DetailedHTMLProps, Dispatch, HTMLAttributes, ReactElement, ReactNode, RefObject, SetStateAction } from 'react';
|
|
2
2
|
import { Column, ColumnDef, ColumnSort, Header, Row, SortingState } from '@tanstack/react-table';
|
|
3
3
|
import { PaginationBarProps } from './components/PaginationBar';
|
|
4
|
-
import { SelectionProps, GenericTableData } from './types';
|
|
4
|
+
import { SelectionProps, GenericTableData, ColumnVisibilityProps } from './types';
|
|
5
5
|
type GenericTableProps<T extends GenericTableData> = {
|
|
6
6
|
"aria-label"?: string;
|
|
7
7
|
className?: string;
|
|
@@ -15,17 +15,20 @@ type GenericTableProps<T extends GenericTableData> = {
|
|
|
15
15
|
isLoading: boolean;
|
|
16
16
|
loadingVariant?: "spinner" | "skeleton";
|
|
17
17
|
skeletonRowCount?: number;
|
|
18
|
+
skeletonGroupCount?: number;
|
|
18
19
|
noData?: ReactNode;
|
|
19
20
|
pagination?: PaginationBarProps;
|
|
20
21
|
pinGroup?: {
|
|
21
22
|
value: string;
|
|
22
23
|
isTop: boolean;
|
|
23
24
|
}[];
|
|
25
|
+
columnVisibility?: ColumnVisibilityProps;
|
|
24
26
|
sorting?: ColumnSort[];
|
|
25
27
|
selection?: SelectionProps<T>;
|
|
26
28
|
setSorting?: Dispatch<SetStateAction<SortingState>>;
|
|
27
29
|
showChevron?: boolean;
|
|
28
30
|
variant?: "full-height" | "regular";
|
|
31
|
+
debug?: boolean;
|
|
29
32
|
} & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
30
33
|
/**
|
|
31
34
|
* GenericTable - A flexible and feature-rich table component for React applications
|
|
@@ -39,6 +42,8 @@ type GenericTableProps<T extends GenericTableData> = {
|
|
|
39
42
|
* @param {Object} props - Component props
|
|
40
43
|
* @param {string} [props.className] - Additional CSS class for the table wrapper
|
|
41
44
|
* @param {ColumnDef<T, Partial<T>>[]} props.columns - Column definitions
|
|
45
|
+
* @param {ColumnVisibilityProps} [props.columnVisibility] - Controlled column visibility state and setter; when omitted, visibility is managed internally. See {@link ColumnVisibilityProps} for all sub-options
|
|
46
|
+
* (columnVisibility, setColumnVisibility).
|
|
42
47
|
* @param {RefObject<HTMLElement | null>} [props.containerRef] - Reference to container for size calculations
|
|
43
48
|
* @param {T[]} props.data - Table data array
|
|
44
49
|
* @param {(row: Row<T>, column: Column<T>) => boolean} [props.filterCells] - Function to filter which cells should be displayed
|
|
@@ -46,8 +51,9 @@ type GenericTableProps<T extends GenericTableData> = {
|
|
|
46
51
|
* @param {(originalRow: T, index: number) => T[] | undefined} [props.getSubRows] - Function that returns the T.prop that contains nested T data
|
|
47
52
|
* @param {string[]} [props.groupBy] - Column IDs to group rows by
|
|
48
53
|
* @param {boolean} props.isLoading - Loading state to display placeholder content
|
|
49
|
-
* @param {"spinner" | "skeleton"} [props.loadingVariant="spinner"] - Loading display style; "spinner" shows a single spinner row, "skeleton" renders skeletonRowCount
|
|
50
|
-
* @param {number} [props.skeletonRowCount=10] - Number of skeleton rows to render when loadingVariant="skeleton"
|
|
54
|
+
* @param {"spinner" | "skeleton"} [props.loadingVariant="spinner"] - Loading display style; "spinner" shows a single spinner row, "skeleton" renders skeletonRowCount pulsing skeleton rows using meta.skeleton per column when defined, falling back to a default Placeholder block
|
|
55
|
+
* @param {number} [props.skeletonRowCount=10] - Number of skeleton rows to render per group (or total when ungrouped) when loadingVariant="skeleton"
|
|
56
|
+
* @param {number} [props.skeletonGroupCount=2] - Number of skeleton group rows to render when loadingVariant="skeleton" and groupBy is set
|
|
51
57
|
* @param {ReactNode} [props.noData] - Content to display when no data is available
|
|
52
58
|
* @param {PaginationBarProps} [props.pagination] - Pagination configuration
|
|
53
59
|
* @param {{ value: string; isTop: boolean }[]} [props.pinGroup] - Group pinning configuration
|
|
@@ -57,6 +63,7 @@ type GenericTableProps<T extends GenericTableData> = {
|
|
|
57
63
|
* (filterSelectable, disabledSelectionTooltip, rowSelection, rowSelectionLabelKey, setRowSelection).
|
|
58
64
|
* @param {boolean} [props.showChevron=false] - Show group row expansion state chevrons
|
|
59
65
|
* @param {"full-height" | "regular"} [props.variant="full-height"] - Table layout variant
|
|
66
|
+
* @param {boolean} [props.debug] - React Table debug output
|
|
60
67
|
*
|
|
61
68
|
* @returns {ReactElement} - The rendered table component
|
|
62
69
|
*
|
|
@@ -80,5 +87,5 @@ type GenericTableProps<T extends GenericTableData> = {
|
|
|
80
87
|
* }}
|
|
81
88
|
* />
|
|
82
89
|
*/
|
|
83
|
-
export declare const GenericTable: <T extends GenericTableData>({ "aria-label": tableAriaLabel, className, columns: initialColumns, containerRef, data: initialData, filterCells, filterHeaders, getSubRows, groupBy, isLoading, loadingVariant, skeletonRowCount, noData, pagination, pinGroup, sorting: externalSorting, selection, setSorting: setExternalSorting, showChevron, variant, ...divProps }: GenericTableProps<T>) => ReactElement;
|
|
90
|
+
export declare const GenericTable: <T extends GenericTableData>({ "aria-label": tableAriaLabel, className, columns: initialColumns, columnVisibility: externalColumnVisibility, containerRef, data: initialData, filterCells, filterHeaders, getSubRows, groupBy, isLoading, loadingVariant, skeletonRowCount, skeletonGroupCount, noData, pagination, pinGroup, sorting: externalSorting, selection, setSorting: setExternalSorting, showChevron, variant, debug, ...divProps }: GenericTableProps<T>) => ReactElement;
|
|
84
91
|
export {};
|
|
@@ -6,10 +6,10 @@ type TableCheckboxProps<T> = Partial<DetailedHTMLProps<InputHTMLAttributes<HTMLI
|
|
|
6
6
|
};
|
|
7
7
|
declare const TableCheckbox: {
|
|
8
8
|
<T>({ row, disabledTooltip, isNested, ...props }: TableCheckboxProps<T> & {
|
|
9
|
-
disabledTooltip
|
|
10
|
-
isNested
|
|
9
|
+
disabledTooltip?: string | ((row: Row<T>) => string);
|
|
10
|
+
isNested?: boolean;
|
|
11
11
|
}): ReactElement | null;
|
|
12
12
|
All: <T>({ table, ...props }: TableCheckboxProps<T>) => import("react/jsx-runtime").JSX.Element | null;
|
|
13
|
-
Group: <T>({ row, ...props }: TableCheckboxProps<T>) => import("react/jsx-runtime").JSX.Element
|
|
13
|
+
Group: <T>({ row, ...props }: TableCheckboxProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
14
14
|
};
|
|
15
15
|
export default TableCheckbox;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, ReactNode, SetStateAction } from 'react';
|
|
2
|
-
import { Row, RowData, RowSelectionState } from '@tanstack/react-table';
|
|
2
|
+
import { Row, RowData, RowSelectionState, VisibilityState } from '@tanstack/react-table';
|
|
3
3
|
declare module "@tanstack/react-table" {
|
|
4
4
|
interface ColumnMeta<TData extends RowData, TValue = unknown> {
|
|
5
5
|
/** Custom loading skeleton renderer. Overrides the default shimmer for this column. */
|
|
@@ -25,3 +25,7 @@ export type SelectionProps<T extends GenericTableData> = {
|
|
|
25
25
|
rowSelection?: RowSelectionState;
|
|
26
26
|
setRowSelection?: Dispatch<SetStateAction<RowSelectionState>>;
|
|
27
27
|
};
|
|
28
|
+
export type ColumnVisibilityProps = {
|
|
29
|
+
columnVisibility: VisibilityState;
|
|
30
|
+
setColumnVisibility: Dispatch<SetStateAction<VisibilityState>>;
|
|
31
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ColumnDef } from '@tanstack/react-table';
|
|
2
2
|
import { SelectionProps, GenericTableData } from '../types';
|
|
3
|
-
export declare const processColumnDefs: <T extends GenericTableData>({ canSelect, initialColumns,
|
|
3
|
+
export declare const processColumnDefs: <T extends GenericTableData>({ canSelect, initialColumns, groupBy, getSubRows, selection, showChevron, }: {
|
|
4
4
|
canSelect: boolean;
|
|
5
5
|
initialColumns: ColumnDef<T, Partial<T>>[];
|
|
6
|
-
isLoading: boolean;
|
|
7
6
|
groupBy: string[] | undefined;
|
|
8
7
|
getSubRows?: (originalRow: T, index: number) => T[] | undefined;
|
|
9
8
|
selection?: SelectionProps<T>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ColumnDef, Header, Table } from '@tanstack/react-table';
|
|
1
|
+
import { Column, ColumnDef, Header, Row, Table } from '@tanstack/react-table';
|
|
2
2
|
import { GenericTableData } from '../types';
|
|
3
|
-
export declare const renderLoadingRows: <T extends GenericTableData>({ table, columns, filterHeaders, loadingVariant, skeletonRowCount, }: {
|
|
3
|
+
export declare const renderLoadingRows: <T extends GenericTableData>({ table, columns, filterHeaders, filterCells, loadingVariant, skeletonRowCount, skeletonGroupCount, }: {
|
|
4
4
|
table: Table<T>;
|
|
5
5
|
columns: ColumnDef<T, Partial<T>>[];
|
|
6
6
|
filterHeaders: (header: Header<T, unknown>) => boolean;
|
|
7
|
+
filterCells: (row: Row<T>, column: Column<T>) => boolean;
|
|
7
8
|
loadingVariant?: "skeleton" | "spinner";
|
|
8
9
|
skeletonRowCount: number;
|
|
10
|
+
skeletonGroupCount: number;
|
|
9
11
|
}) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[];
|
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
1
|
+
import { CSSProperties, HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
type PlaceholderProps = {
|
|
3
3
|
className?: string;
|
|
4
|
+
width?: CSSProperties["width"];
|
|
5
|
+
height?: CSSProperties["height"];
|
|
6
|
+
/** @deprecated */
|
|
4
7
|
isPending?: boolean;
|
|
5
|
-
|
|
6
|
-
text?: never;
|
|
7
|
-
children?: ReactNode;
|
|
8
|
-
} | {
|
|
8
|
+
/** @deprecated */
|
|
9
9
|
text?: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
variant?: "block" | "text";
|
|
13
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, "children">;
|
|
14
|
+
/**
|
|
15
|
+
* Placeholder - A pulsing skeleton block used to represent loading content
|
|
16
|
+
*
|
|
17
|
+
* Renders a rectangular block with a pulse animation that matches the dimensions
|
|
18
|
+
* of the content it is replacing. Use `width` and `height` to control the size
|
|
19
|
+
* explicitly, or rely on the default block layout for full-width skeletons.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} props - Component props
|
|
22
|
+
* @param {string} [props.className] - Additional CSS class names applied to the root element
|
|
23
|
+
* @param {CSSProperties["width"]} [props.width] - Width of the skeleton block; accepts any valid CSS value (e.g. "200px", "100%", "12rem"). When omitted the block stretches to fill its container
|
|
24
|
+
* @param {CSSProperties["height"]} [props.height] - Height of the skeleton block; accepts any valid CSS value (e.g. "1rem", "48px", "3em"). When omitted the block collapses unless content or a sizer provides height
|
|
25
|
+
* @param {"block" | "text"} [props.variant="text"] - Rendering variant. `"block"` renders a standalone skeleton div; `"text"` is the legacy variant that requires `isPending` to be set
|
|
26
|
+
* @param {HTMLAttributes<HTMLDivElement>} [props.style] - Any HTML div attributes (e.g. `style`, `data-*`, `aria-*`) are forwarded to the root element. `style` is merged with the component's internal width/height styles, with consumer values taking precedence
|
|
27
|
+
* @param {boolean} [props.isPending] - @deprecated Use conditional rendering at the call-site instead. When `true` the skeleton is shown; when `false` the `children` are rendered. Will be removed in a future major version
|
|
28
|
+
* @param {string} [props.text] - @deprecated Width is now controlled via the `width` prop. When provided the text is rendered in a visually-hidden sizer span that gives the block its natural content width. Will be removed in a future major version
|
|
29
|
+
* @param {ReactNode} [props.children] - @deprecated Pass children outside the Placeholder and control visibility at the call-site. Will be removed in a future major version
|
|
30
|
+
*
|
|
31
|
+
* @returns {ReactElement} The rendered skeleton block, or the children when `isPending` is `false`
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Standalone skeleton block
|
|
35
|
+
* <Placeholder width="200px" height="1rem" />
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Composed loading state
|
|
39
|
+
* {isLoading ? <Placeholder width="100%" height="1.5rem" /> : <p>{content}</p>}
|
|
40
|
+
*/
|
|
41
|
+
export declare const Placeholder: ({ className, width, height, isPending, text, children, variant, style, ...divProps }: PlaceholderProps) => ReactElement;
|
|
42
|
+
export {};
|
|
@@ -2,5 +2,10 @@ import { Meta, StoryObj } from '@storybook/react';
|
|
|
2
2
|
import { Placeholder } from './Placeholder';
|
|
3
3
|
declare const meta: Meta<typeof Placeholder>;
|
|
4
4
|
export default meta;
|
|
5
|
-
|
|
6
|
-
export declare const
|
|
5
|
+
type Story = StoryObj<typeof Placeholder>;
|
|
6
|
+
export declare const TextLine: Story;
|
|
7
|
+
export declare const Paragraph: Story;
|
|
8
|
+
export declare const Block: Story;
|
|
9
|
+
export declare const Complex: Story;
|
|
10
|
+
export declare const LegacyTextProp: Story;
|
|
11
|
+
export declare const LegacyChildrenProp: Story;
|
package/package.json
CHANGED