Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[terra-table] Export Row Selection Column Width (#1924)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm9361 authored Dec 4, 2023
1 parent e383086 commit 1b5e5b9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ import Table from "terra-table";

<TablePropsTable />

### 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.

Expand Down
3 changes: 3 additions & 0 deletions packages/terra-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
15 changes: 10 additions & 5 deletions packages/terra-table/src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -601,3 +605,4 @@ Table.propTypes = propTypes;
Table.defaultProps = defaultProps;

export default React.memo(injectIntl(Table));
export { TableConstants, RowSelectionModes };
4 changes: 2 additions & 2 deletions packages/terra-table/src/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
};

0 comments on commit 1b5e5b9

Please sign in to comment.