diff --git a/packages/terra-framework-docs/CHANGELOG.md b/packages/terra-framework-docs/CHANGELOG.md index 5440fe0a3e6..d216acc7f6c 100644 --- a/packages/terra-framework-docs/CHANGELOG.md +++ b/packages/terra-framework-docs/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added + * Added documentation for exported constants of `terra-table` in the About page. + ## 1.49.0 - (December 1, 2023) * Added diff --git a/packages/terra-framework-docs/src/terra-dev-site/doc/table/About.1.doc.mdx b/packages/terra-framework-docs/src/terra-dev-site/doc/table/About.1.doc.mdx index 745573f793f..fb1cf67faf9 100644 --- a/packages/terra-framework-docs/src/terra-dev-site/doc/table/About.1.doc.mdx +++ b/packages/terra-framework-docs/src/terra-dev-site/doc/table/About.1.doc.mdx @@ -77,6 +77,20 @@ import Table from "terra-table"; +### Table Constants +Enumeration: TableConstants + +|Constant|Type|Description| +|---|---|---| +|**ROW_SELECTION_COLUMN_WIDTH**|number|The width of the row selection column.| + +Enumeration: RowSelectionModes + +|Constant|Type|Description| +|---|---|---| +|**SINGLE**|string|Single row selection mode| +|**MULTIPLE**|string|Multiple row selection mode| + ### Column A column specifies the data to render a cell in the header row of the Worklist Data Grid. diff --git a/packages/terra-table/CHANGELOG.md b/packages/terra-table/CHANGELOG.md index 5eaf04a6e44..686396a01cd 100644 --- a/packages/terra-table/CHANGELOG.md +++ b/packages/terra-table/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Added + * Exported the row selection column width via the `TableConstants.ROW_SELECTION_COLUMN_WIDTH`` constant. + * Changed * Removed console warning message when no pinned columns exist. diff --git a/packages/terra-table/src/Table.jsx b/packages/terra-table/src/Table.jsx index 7b26cd50ffa..0af1e0eefb3 100644 --- a/packages/terra-table/src/Table.jsx +++ b/packages/terra-table/src/Table.jsx @@ -23,11 +23,15 @@ import getFocusableElements from './utils/focusManagement'; const cx = classNames.bind(styles); -export const rowSelectionModes = { +const RowSelectionModes = { SINGLE: 'single', MULTIPLE: 'multiple', }; +const TableConstants = { + ROW_SELECTION_COLUMN_WIDTH: 40, +}; + const propTypes = { /** * Unique id used to identify the table. @@ -145,7 +149,7 @@ const propTypes = { * Enables row selection capabilities for the table. * Use 'single' for single row selection and 'multiple' for multi-row selection. */ - rowSelectionMode: PropTypes.oneOf(Object.values(rowSelectionModes)), + rowSelectionMode: PropTypes.oneOf(Object.values(RowSelectionModes)), /** * Boolean indicating whether or not the table columns should be displayed. Setting the value to false will hide the columns, @@ -246,14 +250,14 @@ function Table(props) { // Create row selection column object const tableRowSelectionColumn = { id: 'table-rowSelectionColumn', - width: 40, + width: TableConstants.ROW_SELECTION_COLUMN_WIDTH, displayName: intl.formatMessage({ id: 'Terra.table.row-selection-header-display' }), isDisplayVisible: false, isSelectable: !!onRowSelectionHeaderSelect, isResizable: false, }; - const hasSelectableRows = rowSelectionMode === rowSelectionModes.MULTIPLE; + const hasSelectableRows = rowSelectionMode === RowSelectionModes.MULTIPLE; const displayedColumns = (hasSelectableRows ? [tableRowSelectionColumn] : []).concat(pinnedColumns).concat(overflowColumns); const [tableColumns, setTableColumns] = useState(displayedColumns.map((column) => initializeColumn(column))); @@ -306,7 +310,7 @@ function Table(props) { } // Since the row selection mode has changed, the row selection mode needs to be updated. - setRowSelectionModeAriaLiveMessage(intl.formatMessage({ id: rowSelectionMode === rowSelectionModes.MULTIPLE ? 'Terra.table.row-selection-mode-enabled' : 'Terra.table.row-selection-mode-disabled' })); + setRowSelectionModeAriaLiveMessage(intl.formatMessage({ id: rowSelectionMode === RowSelectionModes.MULTIPLE ? 'Terra.table.row-selection-mode-enabled' : 'Terra.table.row-selection-mode-disabled' })); setTableColumns(displayedColumns.map((column) => initializeColumn(column))); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -601,3 +605,4 @@ Table.propTypes = propTypes; Table.defaultProps = defaultProps; export default React.memo(injectIntl(Table)); +export { TableConstants, RowSelectionModes }; diff --git a/packages/terra-table/src/index.js b/packages/terra-table/src/index.js index 4d412f92676..2dc80df38bf 100644 --- a/packages/terra-table/src/index.js +++ b/packages/terra-table/src/index.js @@ -1,4 +1,4 @@ -import Table from './Table'; +import Table, { TableConstants, RowSelectionModes } from './Table'; import GridContext, { GridConstants } from './utils/GridContext'; import cellShape from './proptypes/cellShape'; import columnShape from './proptypes/columnShape'; @@ -8,5 +8,5 @@ import validateRowHeaderIndex from './proptypes/validators'; export default Table; export { - GridContext, GridConstants, cellShape, columnShape, rowShape, sectionShape, validateRowHeaderIndex, + GridContext, GridConstants, TableConstants, RowSelectionModes, cellShape, columnShape, rowShape, sectionShape, validateRowHeaderIndex, };