@mezzanine-ui/react 1.0.0-beta.1 → 1.0.0-beta.2

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 (90) hide show
  1. package/Badge/Badge.js +2 -2
  2. package/Breadcrumb/BreadcrumbItem.d.ts +1 -1
  3. package/Description/Description.d.ts +40 -0
  4. package/Description/Description.js +33 -0
  5. package/Description/DescriptionContent.d.ts +41 -0
  6. package/Description/DescriptionContent.js +14 -0
  7. package/Description/DescriptionGroup.d.ts +13 -0
  8. package/Description/DescriptionGroup.js +12 -0
  9. package/Description/DescriptionTitle.d.ts +45 -0
  10. package/Description/DescriptionTitle.js +17 -0
  11. package/Description/index.d.ts +8 -0
  12. package/Description/index.js +4 -0
  13. package/Dropdown/Dropdown.d.ts +15 -3
  14. package/Dropdown/Dropdown.js +63 -25
  15. package/Dropdown/DropdownItem.d.ts +4 -4
  16. package/Dropdown/DropdownItemCard.d.ts +5 -5
  17. package/Dropdown/DropdownStatus.d.ts +2 -2
  18. package/Form/FormControlContext.d.ts +2 -2
  19. package/Form/FormField.d.ts +56 -4
  20. package/Form/FormField.js +8 -6
  21. package/Form/FormHintText.d.ts +24 -1
  22. package/Form/FormHintText.js +4 -4
  23. package/Form/FormLabel.d.ts +6 -3
  24. package/Form/FormLabel.js +5 -3
  25. package/Input/PasswordStrengthIndicator/PasswordStrengthIndicator.js +1 -1
  26. package/Navigation/Navigation.d.ts +10 -1
  27. package/Navigation/Navigation.js +22 -7
  28. package/Navigation/NavigationFooter.js +4 -2
  29. package/Navigation/NavigationHeader.d.ts +7 -1
  30. package/Navigation/NavigationHeader.js +5 -3
  31. package/Navigation/NavigationOption.d.ts +1 -1
  32. package/Navigation/NavigationOption.js +19 -25
  33. package/Navigation/NavigationOptionCategory.js +19 -2
  34. package/Navigation/context.d.ts +2 -0
  35. package/Table/Table.d.ts +53 -15
  36. package/Table/Table.js +178 -82
  37. package/Table/TableContext.d.ts +18 -42
  38. package/Table/components/TableActionsCell.d.ts +26 -0
  39. package/Table/components/TableActionsCell.js +78 -0
  40. package/Table/components/TableBody.d.ts +2 -5
  41. package/Table/components/TableBody.js +16 -19
  42. package/Table/components/TableBulkActions.d.ts +15 -0
  43. package/Table/components/TableBulkActions.js +44 -0
  44. package/Table/components/TableCell.d.ts +2 -0
  45. package/Table/components/TableCell.js +42 -10
  46. package/Table/components/TableColGroup.js +10 -112
  47. package/Table/components/TableColumnTitleMenu.d.ts +6 -0
  48. package/Table/components/TableColumnTitleMenu.js +20 -0
  49. package/Table/components/TableDragHandleCell.d.ts +2 -0
  50. package/Table/components/TableDragHandleCell.js +8 -1
  51. package/Table/components/TableExpandCell.d.ts +2 -0
  52. package/Table/components/TableExpandCell.js +8 -1
  53. package/Table/components/TableExpandedRow.js +3 -2
  54. package/Table/components/TableHeader.d.ts +2 -4
  55. package/Table/components/TableHeader.js +11 -14
  56. package/Table/components/TableResizeHandle.js +3 -7
  57. package/Table/components/TableRow.js +54 -20
  58. package/Table/components/TableSelectionCell.d.ts +5 -0
  59. package/Table/components/TableSelectionCell.js +12 -1
  60. package/Table/components/index.d.ts +1 -0
  61. package/Table/components/index.js +1 -0
  62. package/Table/hooks/index.d.ts +1 -1
  63. package/Table/hooks/index.js +1 -1
  64. package/Table/hooks/useTableDataSource.d.ts +2 -2
  65. package/Table/hooks/useTableExpansion.js +0 -6
  66. package/Table/hooks/useTableFixedOffsets.d.ts +1 -1
  67. package/Table/hooks/useTableFixedOffsets.js +19 -21
  68. package/Table/hooks/useTableResizedColumns.d.ts +2 -0
  69. package/Table/hooks/useTableResizedColumns.js +22 -0
  70. package/Table/hooks/useTableScroll.d.ts +3 -1
  71. package/Table/hooks/useTableScroll.js +25 -19
  72. package/Table/hooks/useTableSelection.js +32 -8
  73. package/Table/hooks/useTableVirtualization.d.ts +1 -1
  74. package/Table/index.d.ts +4 -4
  75. package/Table/index.js +5 -3
  76. package/Table/utils/calculateColumnWidths.d.ts +28 -0
  77. package/Table/utils/calculateColumnWidths.js +80 -0
  78. package/Table/utils/index.d.ts +2 -0
  79. package/Table/utils/index.js +1 -0
  80. package/Table/utils/useTableRowSelection.d.ts +5 -5
  81. package/Table/utils/useTableRowSelection.js +1 -1
  82. package/index.d.ts +6 -4
  83. package/index.js +9 -1
  84. package/package.json +4 -4
  85. package/utils/format-number-with-commas.d.ts +4 -0
  86. package/utils/format-number-with-commas.js +27 -0
  87. package/utils/parse-number-with-commas.d.ts +4 -0
  88. package/utils/parse-number-with-commas.js +22 -0
  89. package/Table/hooks/useTableColumns.d.ts +0 -8
  90. package/Table/hooks/useTableColumns.js +0 -91
package/Table/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { tableClasses as classes, getCellAlignClass, getColumnStyle, getRowKey, type FixedType, type SortOrder, type TableColumn, type TableDataSource, type TableDraggable, type TableExpandable, type TableRowSelection, type TableScroll, type TableSize, } from '@mezzanine-ui/core/table';
2
- export { default, type TableBaseProps, type TableNonVirtualizedProps, type TableProps, type TableVirtualizedProps, } from './Table';
3
- export { TableContext, TableDataContext, useTableContext, useTableDataContext, type TableColumnState, type TableContextValue, type TableDataContextValue, type TableDraggableState, type TableExpansionState, type TableSelectionState, type TableSortingState, type TableTransitionState, } from './TableContext';
4
- export { type UpdateDataSourceOptions } from './hooks';
1
+ export { TABLE_ACTIONS_KEY, tableClasses as classes, getCellAlignClass, getRowKey, type ColumnAlign, type FixedType, type HighlightMode, type SortOrder, type TableActionItem, type TableActions, type TableActionsBase, type TableActionsWithMinWidth, type TableBulkActions, type TableBulkGeneralAction, type TableBulkOverflowAction, type TableColumnBase, type TableColumnBaseWithMinWidthRequired, type TableColumn, type TableColumnTitleMenu, type TableColumnWithDataIndex, type TableColumnWithDataIndexAndMinWidth, type TableColumnWithMinWidth, type TableColumnWithRender, type TableColumnWithRenderAndMinWidth, type TableDataSource, type TableDataSourceWithId, type TableDataSourceWithKey, type TableDraggable, type TableExpandable, type TableRecord, type TableRowSelection, type TableRowSelectionBase, type TableRowSelectionCheckbox, type TableRowSelectionRadio, type TableScroll, type TableSelectionMode, type TableSize, } from '@mezzanine-ui/core/table';
2
+ export { default, type TableBaseProps, type TableResizableProps, type TableNonResizableProps, type TableVirtualizedProps, type TableNonVirtualizedProps, type TableProps, } from './Table';
3
+ export { TableContext, TableDataContext, TableSuperContext, useTableContext, useTableDataContext, useTableSuperContext, type TableResizedColumnState, type TableContextValue, type TableDataContextValue, type TableDraggableState, type TableHighlightState, type TableExpansionState, type TableSelectionState, type TableSortingState, } from './TableContext';
4
+ export { type UpdateDataSourceOptions, type UseTableDataSourceOptions, type TableTransitionState, } from './hooks';
5
5
  export * from './hooks';
6
6
  export * from './components';
7
7
  export * from './utils';
package/Table/index.js CHANGED
@@ -1,14 +1,15 @@
1
- export { tableClasses as classes, getCellAlignClass, getColumnStyle, getRowKey } from '@mezzanine-ui/core/table';
1
+ export { TABLE_ACTIONS_KEY, tableClasses as classes, getCellAlignClass, getRowKey } from '@mezzanine-ui/core/table';
2
2
  export { Table as default } from './Table.js';
3
- export { TableContext, TableDataContext, useTableContext, useTableDataContext } from './TableContext.js';
3
+ export { TableContext, TableDataContext, TableSuperContext, useTableContext, useTableDataContext, useTableSuperContext } from './TableContext.js';
4
4
  export { useTableSorting } from './hooks/useTableSorting.js';
5
5
  export { useTableSelection } from './hooks/useTableSelection.js';
6
- export { useTableColumns } from './hooks/useTableColumns.js';
6
+ export { useTableResizedColumns } from './hooks/useTableResizedColumns.js';
7
7
  export { useTableExpansion } from './hooks/useTableExpansion.js';
8
8
  export { useTableFixedOffsets } from './hooks/useTableFixedOffsets.js';
9
9
  export { useTableScroll } from './hooks/useTableScroll.js';
10
10
  export { useTableVirtualization } from './hooks/useTableVirtualization.js';
11
11
  export { useTableDataSource } from './hooks/useTableDataSource.js';
12
+ export { TableActionsCell } from './components/TableActionsCell.js';
12
13
  export { TableBody } from './components/TableBody.js';
13
14
  export { TableCell } from './components/TableCell.js';
14
15
  export { TableColGroup } from './components/TableColGroup.js';
@@ -19,4 +20,5 @@ export { TablePagination } from './components/TablePagination.js';
19
20
  export { TableResizeHandle } from './components/TableResizeHandle.js';
20
21
  export { TableRow } from './components/TableRow.js';
21
22
  export { TableSelectionCell } from './components/TableSelectionCell.js';
23
+ export { calculateColumnWidths, clampWidth } from './utils/calculateColumnWidths.js';
22
24
  export { useTableRowSelection } from './utils/useTableRowSelection.js';
@@ -0,0 +1,28 @@
1
+ import type { TableColumn } from '@mezzanine-ui/core/table';
2
+ /**
3
+ * Check if width calculation should be applied.
4
+ * Only calculate explicit widths for root tables (not nested).
5
+ * Nested tables should let columns use natural CSS behavior.
6
+ */
7
+ export declare function shouldCalculateWidths(isNestedTable: boolean, containerWidth: number | undefined): boolean;
8
+ /**
9
+ * Clamp a width value between min and max bounds
10
+ */
11
+ export declare function clampWidth(width: number, minWidth?: number, maxWidth?: number): number;
12
+ export interface CalculateColumnWidthsOptions {
13
+ /** Action columns (drag handle, selection, expansion) total width */
14
+ actionColumnsWidth: number;
15
+ /** All data columns */
16
+ columns: TableColumn[];
17
+ /** Container width */
18
+ containerWidth: number;
19
+ /** Get resized column width by key */
20
+ getResizedColumnWidth?: (key: string) => number | undefined;
21
+ }
22
+ /**
23
+ * Calculate the resolved width for each column.
24
+ * - Columns with explicit width use that value
25
+ * - Columns without width share the remaining space equally (simulating flex: 1)
26
+ * - All widths are clamped to minWidth/maxWidth if specified
27
+ */
28
+ export declare function calculateColumnWidths({ actionColumnsWidth, columns, containerWidth, getResizedColumnWidth, }: CalculateColumnWidthsOptions): Map<string, number>;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Check if width calculation should be applied.
3
+ * Only calculate explicit widths for root tables (not nested).
4
+ * Nested tables should let columns use natural CSS behavior.
5
+ */
6
+ function shouldCalculateWidths(isNestedTable, containerWidth) {
7
+ // Don't calculate widths for nested tables - they inherit parent's context
8
+ // and should use natural CSS column sizing
9
+ if (isNestedTable) {
10
+ return false;
11
+ }
12
+ // Don't calculate if container width is not available
13
+ if (!containerWidth || containerWidth <= 0) {
14
+ return false;
15
+ }
16
+ return true;
17
+ }
18
+ /**
19
+ * Clamp a width value between min and max bounds
20
+ */
21
+ function clampWidth(width, minWidth, maxWidth) {
22
+ let result = width;
23
+ if (minWidth !== undefined && result < minWidth) {
24
+ result = minWidth;
25
+ }
26
+ if (maxWidth !== undefined && result > maxWidth) {
27
+ result = maxWidth;
28
+ }
29
+ return result;
30
+ }
31
+ /**
32
+ * Calculate the resolved width for each column.
33
+ * - Columns with explicit width use that value
34
+ * - Columns without width share the remaining space equally (simulating flex: 1)
35
+ * - All widths are clamped to minWidth/maxWidth if specified
36
+ */
37
+ function calculateColumnWidths({ actionColumnsWidth, columns, containerWidth, getResizedColumnWidth, }) {
38
+ const widthMap = new Map();
39
+ // If container width is not available yet, return empty map
40
+ if (containerWidth <= 0) {
41
+ return widthMap;
42
+ }
43
+ // Available width for data columns
44
+ const availableWidth = containerWidth - actionColumnsWidth;
45
+ if (availableWidth <= 0) {
46
+ return widthMap;
47
+ }
48
+ // First pass: identify columns with explicit width and calculate total fixed width
49
+ let totalFixedWidth = 0;
50
+ const flexColumns = [];
51
+ columns.forEach((column) => {
52
+ const resizedWidth = getResizedColumnWidth === null || getResizedColumnWidth === void 0 ? void 0 : getResizedColumnWidth(column.key);
53
+ if (resizedWidth !== undefined) {
54
+ // Column has been resized, use that width
55
+ widthMap.set(column.key, resizedWidth);
56
+ totalFixedWidth += resizedWidth;
57
+ }
58
+ else if (column.width !== undefined) {
59
+ // Column has explicit width
60
+ const width = clampWidth(column.width, column.minWidth, column.maxWidth);
61
+ widthMap.set(column.key, width);
62
+ totalFixedWidth += width;
63
+ }
64
+ else {
65
+ // Column needs flex width calculation
66
+ flexColumns.push(column);
67
+ }
68
+ });
69
+ // Second pass: distribute remaining width to flex columns
70
+ if (flexColumns.length > 0) {
71
+ const averageWidth = (availableWidth - totalFixedWidth) / flexColumns.length;
72
+ flexColumns.forEach((column) => {
73
+ const clampedWidth = clampWidth(averageWidth, column.minWidth, column.maxWidth);
74
+ widthMap.set(column.key, clampedWidth);
75
+ });
76
+ }
77
+ return widthMap;
78
+ }
79
+
80
+ export { calculateColumnWidths, clampWidth, shouldCalculateWidths };
@@ -1,2 +1,4 @@
1
+ export type { CalculateColumnWidthsOptions } from './calculateColumnWidths';
2
+ export { calculateColumnWidths, clampWidth } from './calculateColumnWidths';
1
3
  export type { UseTableRowSelectionProps } from './useTableRowSelection';
2
4
  export { useTableRowSelection } from './useTableRowSelection';
@@ -1 +1,2 @@
1
+ export { calculateColumnWidths, clampWidth } from './calculateColumnWidths.js';
1
2
  export { useTableRowSelection } from './useTableRowSelection.js';
@@ -1,4 +1,4 @@
1
- import { TableDataSource, TableRowSelection } from '@mezzanine-ui/core/table';
1
+ import { TableDataSource, TableRowSelectionCheckbox } from '@mezzanine-ui/core/table';
2
2
  export interface UseTableRowSelectionProps<T extends TableDataSource> {
3
3
  getSubData: (record: T) => T[] | undefined;
4
4
  }
@@ -6,13 +6,13 @@ export interface UseTableRowSelectionProps<T extends TableDataSource> {
6
6
  * Custom hook for users to manage row selection state in a table with expandable rows.
7
7
  */
8
8
  export declare function useTableRowSelection<T extends TableDataSource = TableDataSource>(props: UseTableRowSelectionProps<T>): {
9
- parentSelectedKeys: (string | number)[];
10
- parentOnChange: (selectedRowKeys: (string | number)[], selectedRow: T | null, selectedRows: T[]) => void;
9
+ parentSelectedKeys: string[];
10
+ parentOnChange: (selectedRowKeys: string[], selectedRow: T | null, selectedRows: T[]) => void;
11
11
  parentGetCheckboxProps: (record: T) => {
12
12
  indeterminate?: boolean;
13
13
  selected?: boolean;
14
14
  };
15
- getChildOnChange: (record: T) => TableRowSelection<T>["onChange"];
16
- getChildSelectedRowKeys: (record: T) => (string | number)[];
15
+ getChildOnChange: (record: T) => TableRowSelectionCheckbox<T>["onChange"];
16
+ getChildSelectedRowKeys: (record: T) => string[];
17
17
  totalSelectionCount: number;
18
18
  };
@@ -49,7 +49,7 @@ function useTableRowSelection(props) {
49
49
  const selectedItem = selectedKeys.find((item) => item.key === getRowKey(record));
50
50
  return (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.subKeys) || [];
51
51
  }, [selectedKeys]);
52
- const totalSelectionCount = useMemo(() => selectedKeys.reduce((acc, item) => { var _a; return acc + (((_a = item.subKeys) === null || _a === void 0 ? void 0 : _a.length) || 1); }, 0), [selectedKeys]);
52
+ const totalSelectionCount = useMemo(() => selectedKeys.reduce((acc, item) => { var _a, _b; return acc + ((_b = (_a = item.subKeys) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + 1; }, 0), [selectedKeys]);
53
53
  return {
54
54
  parentSelectedKeys,
55
55
  parentOnChange,
package/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export * from './utils/array-move';
2
2
  export * from './utils/composeRefs';
3
3
  export * from './utils/cx';
4
+ export * from './utils/format-number-with-commas';
4
5
  export * from './utils/general';
5
6
  export * from './utils/get-css-variable-value';
6
7
  export * from './utils/get-scrollbar-width';
7
8
  export * from './utils/getElement';
8
9
  export * from './utils/jsx-types';
10
+ export * from './utils/parse-number-with-commas';
9
11
  export * from './hooks/useClickAway';
10
12
  export * from './hooks/useComposeRefs';
11
13
  export * from './hooks/useDocumentEscapeKeyDown';
@@ -71,16 +73,16 @@ export { default as Badge, BadgeContainer } from './Badge';
71
73
  export type { BadgeProps } from './Badge';
72
74
  export { default as Card, CardActions } from './Card';
73
75
  export type { CardActionsProps, CardProps } from './Card';
76
+ export { Description, DescriptionTitle, DescriptionContent, DescriptionGroup, } from './Description';
77
+ export type { DescriptionProps, DescriptionTitleProps, DescriptionContentProps, DescriptionGroupProps, } from './Description';
74
78
  export { default as Empty } from './Empty';
75
79
  export type { EmptyProps } from './Empty';
76
80
  export { OverflowCounterTag } from './OverflowTooltip';
77
81
  export type { OverflowCounterTagProps } from './OverflowTooltip';
78
82
  export { default as Pagination, PaginationItem, PaginationJumper, PaginationPageSize, usePagination, } from './Pagination';
79
83
  export type { PaginationItemProps, PaginationItemType, PaginationJumperProps, PaginationPageSizeProps, PaginationProps, } from './Pagination';
80
- export { default as Table, TableContext, TableDataContext, useTableContext, useTableDataContext,
81
- /** @NOTE Table hooks only for internal usage */
82
- useTableRowSelection, } from './Table';
83
- export type { TableProps, TableContextValue, TableDataContextValue, TableSortingState, TableSelectionState, TableExpansionState, TableColumnState, TableDraggableState, TableSize, UseTableRowSelectionProps, } from './Table';
84
+ export { default as Table, getCellAlignClass, getRowKey, TableContext, TableDataContext, TableSuperContext, useTableContext, useTableDataContext, useTableSuperContext, useTableRowSelection, useTableDataSource, } from './Table';
85
+ export { type TableRecord, type TableDataSourceWithKey, type TableDataSourceWithId, type TableDataSource, type SortOrder, type ColumnAlign, type HighlightMode, type FixedType, type TableSize, type TableColumnTitleMenu, type TableColumnBase, type TableColumnBaseWithMinWidthRequired, type TableColumn, type TableColumnWithMinWidth, type TableColumnWithDataIndex, type TableColumnWithDataIndexAndMinWidth, type TableColumnWithRender, type TableColumnWithRenderAndMinWidth, type TableSelectionMode, type TableBulkGeneralAction, type TableBulkOverflowAction, type TableBulkActions, type TableRowSelectionBase, type TableRowSelectionCheckbox, type TableRowSelectionRadio, type TableRowSelection, type TableScroll, type TableDraggable, type TableExpandable, type TableBaseProps, type TableVirtualizedProps, type TableNonVirtualizedProps, type TableProps, type TableResizedColumnState, type TableContextValue, type TableDataContextValue, type TableDraggableState, type TableExpansionState, type TableSelectionState, type TableSortingState, type UpdateDataSourceOptions, type UseTableDataSourceOptions, type TableTransitionState, type TableActionItem, type TableActions, type TableActionsBase, type TableActionsWithMinWidth, } from './Table';
84
86
  export { default as Tag } from './Tag';
85
87
  export type { TagProps, TagSize } from './Tag';
86
88
  export { default as Tooltip } from './Tooltip';
package/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export { arrayMove } from './utils/array-move.js';
2
2
  export { composeRefs } from './utils/composeRefs.js';
3
+ export { formatNumberWithCommas } from './utils/format-number-with-commas.js';
3
4
  export { getCSSVariableValue, getNumericCSSVariablePixelValue } from './utils/get-css-variable-value.js';
4
5
  export { getScrollbarWidth } from './utils/get-scrollbar-width.js';
5
6
  export { getElement } from './utils/getElement.js';
7
+ export { parseNumberWithCommas } from './utils/parse-number-with-commas.js';
6
8
  export { useClickAway } from './hooks/useClickAway.js';
7
9
  export { useComposeRefs } from './hooks/useComposeRefs.js';
8
10
  export { useDocumentEscapeKeyDown } from './hooks/useDocumentEscapeKeyDown.js';
@@ -57,6 +59,10 @@ export { default as Badge } from './Badge/Badge.js';
57
59
  export { default as BadgeContainer } from './Badge/BadgeContainer.js';
58
60
  export { default as Card } from './Card/Card.js';
59
61
  export { default as CardActions } from './Card/CardActions.js';
62
+ export { default as Description } from './Description/Description.js';
63
+ export { default as DescriptionTitle } from './Description/DescriptionTitle.js';
64
+ export { default as DescriptionContent } from './Description/DescriptionContent.js';
65
+ export { default as DescriptionGroup } from './Description/DescriptionGroup.js';
60
66
  export { default as Empty } from './Empty/Empty.js';
61
67
  export { default as OverflowCounterTag } from './OverflowTooltip/OverflowCounterTag.js';
62
68
  export { default as Pagination } from './Pagination/Pagination.js';
@@ -147,8 +153,10 @@ export { default as Translate } from './Transition/Translate.js';
147
153
  export { default as ConfigProvider } from './Provider/ConfigProvider.js';
148
154
  export { useStepper } from './Stepper/useStepper.js';
149
155
  export { usePagination } from './Pagination/usePagination.js';
150
- export { TableContext, TableDataContext, useTableContext, useTableDataContext } from './Table/TableContext.js';
156
+ export { getCellAlignClass, getRowKey } from '@mezzanine-ui/core/table';
157
+ export { TableContext, TableDataContext, TableSuperContext, useTableContext, useTableDataContext, useTableSuperContext } from './Table/TableContext.js';
151
158
  export { useTableRowSelection } from './Table/utils/useTableRowSelection.js';
159
+ export { useTableDataSource } from './Table/hooks/useTableDataSource.js';
152
160
  export { getTreeNodeEntities } from './Tree/getTreeNodeEntities.js';
153
161
  export { toggleValue, toggleValueWithStatusControl, uniqueArray } from './Tree/toggleValue.js';
154
162
  export { traverseTree } from './Tree/traverseTree.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezzanine-ui/react",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "React components for mezzanine-ui",
5
5
  "author": "Mezzanine",
6
6
  "repository": {
@@ -31,9 +31,9 @@
31
31
  "@floating-ui/dom": "^1.7.4",
32
32
  "@floating-ui/react-dom": "^2.1.6",
33
33
  "@hello-pangea/dnd": "^18.0.1",
34
- "@mezzanine-ui/core": "^1.0.0-beta.1",
35
- "@mezzanine-ui/icons": "^1.0.0-beta.1",
36
- "@mezzanine-ui/system": "^1.0.0-beta.1",
34
+ "@mezzanine-ui/core": "^1.0.0-beta.2",
35
+ "@mezzanine-ui/icons": "^1.0.0-beta.2",
36
+ "@mezzanine-ui/system": "^1.0.0-beta.2",
37
37
  "@tanstack/react-virtual": "^3.13.13",
38
38
  "@types/react-transition-group": "^4.4.12",
39
39
  "clsx": "^2.1.1",
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Formats a number or numeric string with commas according to the specified locale.
3
+ */
4
+ export declare function formatNumberWithCommas(input: number | string, locale?: string, options?: Intl.NumberFormatOptions): string;
@@ -0,0 +1,27 @@
1
+ 'use client';
2
+ /**
3
+ * Formats a number or numeric string with commas according to the specified locale.
4
+ */
5
+ function formatNumberWithCommas(input, locale = 'en-US', options) {
6
+ let value;
7
+ if (typeof input === 'number') {
8
+ if (!Number.isFinite(input))
9
+ return '';
10
+ value = input;
11
+ }
12
+ else {
13
+ const trimmed = input.trim();
14
+ if (trimmed === '')
15
+ return '';
16
+ const parsed = Number(trimmed);
17
+ if (!Number.isFinite(parsed))
18
+ return '';
19
+ value = parsed;
20
+ }
21
+ return new Intl.NumberFormat(locale, {
22
+ maximumFractionDigits: 20,
23
+ ...options,
24
+ }).format(value);
25
+ }
26
+
27
+ export { formatNumberWithCommas };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Parses a string representing a number with commas into a number.
3
+ */
4
+ export declare function parseNumberWithCommas(input: string, strict?: boolean): number | null;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Parses a string representing a number with commas into a number.
3
+ */
4
+ function parseNumberWithCommas(input, strict = false) {
5
+ if (typeof input !== 'string')
6
+ return null;
7
+ const trimmed = input.trim();
8
+ if (trimmed === '')
9
+ return null;
10
+ if (strict) {
11
+ /** Strictly formatted number with commas */
12
+ const STRICT_FORMAT = /^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?$/;
13
+ if (!STRICT_FORMAT.test(trimmed)) {
14
+ return null;
15
+ }
16
+ }
17
+ const normalized = trimmed.split(',').join('');
18
+ const value = Number(normalized);
19
+ return Number.isFinite(value) ? value : null;
20
+ }
21
+
22
+ export { parseNumberWithCommas };
@@ -1,8 +0,0 @@
1
- import { type TableColumn, type TableDataSource } from '@mezzanine-ui/core/table';
2
- import type { TableColumnState } from '../TableContext';
3
- import { ActionColumnConfig } from './typings';
4
- export interface UseTableColumnsOptions<T extends TableDataSource> {
5
- actionConfig: ActionColumnConfig;
6
- columns: TableColumn<T>[];
7
- }
8
- export declare function useTableColumns<T extends TableDataSource>({ actionConfig, columns, }: UseTableColumnsOptions<T>): TableColumnState;
@@ -1,91 +0,0 @@
1
- 'use client';
2
- import { useState, useMemo, useCallback } from 'react';
3
- import { DRAG_HANDLE_COLUMN_WIDTH, EXPANSION_COLUMN_WIDTH, SELECTION_COLUMN_WIDTH } from '@mezzanine-ui/core/table';
4
-
5
- function useTableColumns({ actionConfig, columns, }) {
6
- const { dragHandleFixed, expansionFixed, selectionFixed } = actionConfig;
7
- const [resizedColumnWidths, setResizedColumnWidths] = useState(new Map());
8
- const parseFixed = (fixed) => {
9
- if (fixed === true || fixed === 'start')
10
- return 'start';
11
- if (fixed === 'end')
12
- return 'end';
13
- return null;
14
- };
15
- const { fixedEndColumns, fixedStartColumns, scrollableColumns } = useMemo(() => {
16
- const start = [];
17
- const end = [];
18
- const scrollable = [];
19
- columns.forEach((col) => {
20
- const fixedPos = parseFixed(col.fixed);
21
- if (fixedPos === 'start') {
22
- start.push(col);
23
- }
24
- else if (fixedPos === 'end') {
25
- end.push(col);
26
- }
27
- else {
28
- scrollable.push(col);
29
- }
30
- });
31
- return {
32
- fixedEndColumns: end,
33
- fixedStartColumns: start,
34
- scrollableColumns: scrollable,
35
- };
36
- }, [columns]);
37
- const totalFixedStartWidth = useMemo(() => {
38
- let width = 0;
39
- if (dragHandleFixed) {
40
- width += DRAG_HANDLE_COLUMN_WIDTH;
41
- }
42
- if (expansionFixed) {
43
- width += EXPANSION_COLUMN_WIDTH;
44
- }
45
- if (selectionFixed) {
46
- width += SELECTION_COLUMN_WIDTH;
47
- }
48
- fixedStartColumns.forEach((col) => {
49
- var _a, _b;
50
- width += (_b = (_a = resizedColumnWidths.get(col.key)) !== null && _a !== void 0 ? _a : col.width) !== null && _b !== void 0 ? _b : 0;
51
- });
52
- return width;
53
- }, [
54
- selectionFixed,
55
- expansionFixed,
56
- dragHandleFixed,
57
- fixedStartColumns,
58
- resizedColumnWidths,
59
- ]);
60
- const totalFixedEndWidth = useMemo(() => {
61
- let width = 0;
62
- fixedEndColumns.forEach((col) => {
63
- var _a, _b;
64
- width += (_b = (_a = resizedColumnWidths.get(col.key)) !== null && _a !== void 0 ? _a : col.width) !== null && _b !== void 0 ? _b : 0;
65
- });
66
- return width;
67
- }, [fixedEndColumns, resizedColumnWidths]);
68
- const getResizedColumnWidth = useCallback((key) => {
69
- return resizedColumnWidths.get(key);
70
- }, [resizedColumnWidths]);
71
- const setResizedColumnWidth = useCallback((key, width) => {
72
- setResizedColumnWidths((prev) => {
73
- const next = new Map(prev);
74
- next.set(key, width);
75
- return next;
76
- });
77
- }, []);
78
- return {
79
- resizedColumnWidths,
80
- columns: columns,
81
- fixedEndColumns,
82
- fixedStartColumns,
83
- getResizedColumnWidth,
84
- scrollableColumns,
85
- setResizedColumnWidth,
86
- totalFixedEndWidth,
87
- totalFixedStartWidth,
88
- };
89
- }
90
-
91
- export { useTableColumns };