Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Table] enhancements #2322

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
role="heading"
>
<button
aria-controls="collapsible-body-34"
aria-controls="collapsible-body-31"
aria-expanded="false"
class="c3"
data-blade-component="accordion-button"
Expand Down Expand Up @@ -1241,7 +1241,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
aria-hidden="true"
class=""
data-blade-component="collapsible-body"
id="collapsible-body-34"
id="collapsible-body-31"
role="region"
>
<div
Expand Down Expand Up @@ -1298,7 +1298,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
role="heading"
>
<button
aria-controls="collapsible-body-35"
aria-controls="collapsible-body-32"
aria-expanded="false"
class="c3"
data-blade-component="accordion-button"
Expand Down Expand Up @@ -1389,7 +1389,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
aria-hidden="true"
class=""
data-blade-component="collapsible-body"
id="collapsible-body-35"
id="collapsible-body-32"
role="region"
>
<div
Expand Down Expand Up @@ -1446,7 +1446,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
role="heading"
>
<button
aria-controls="collapsible-body-36"
aria-controls="collapsible-body-33"
aria-expanded="false"
class="c3"
data-blade-component="accordion-button"
Expand Down Expand Up @@ -1537,7 +1537,7 @@ exports[`Deprecated <Accordion /> should render 1`] = `
aria-hidden="true"
class=""
data-blade-component="collapsible-body"
id="collapsible-body-36"
id="collapsible-body-33"
role="region"
>
<div
Expand Down
14 changes: 12 additions & 2 deletions packages/blade/src/components/Table/TableBody.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export const CellWrapper = styled(BaseBox)<{
rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
showStripedRows?: boolean;
hasPadding?: boolean;
}>(({ theme, rowDensity, showStripedRows, hasPadding = true }) => {
textAlign?: TableCellProps['textAlign'];
allowMultiline?: TableCellProps['allowMultiline'];
}>(({ theme, rowDensity, showStripedRows, hasPadding = true, textAlign, allowMultiline }) => {
const rowBackgroundTransition = `background-color ${makeMotionTime(
getIn(theme.motion, tableRow.backgroundColorMotionDuration),
)} ${getIn(theme.motion, tableRow.backgroundColorMotionEasing)}`;
Expand All @@ -178,6 +180,8 @@ export const CellWrapper = styled(BaseBox)<{
minHeight: makeSize(getIn(size, tableRow.minHeight[rowDensity])),
height: '100%',
width: '100%',
justifyContent: textAlign,
whiteSpace: allowMultiline ? 'normal' : 'nowrap',
...(!showStripedRows && {
borderBottomWidth: makeSpace(getIn(theme.border.width, tableRow.borderBottomWidth)),
borderBottomColor: getIn(theme.colors, tableRow.borderColor),
Expand All @@ -187,7 +191,11 @@ export const CellWrapper = styled(BaseBox)<{
};
});

const _TableCell = ({ children }: TableCellProps): React.ReactElement => {
const _TableCell = ({
children,
allowMultiline,
textAlign,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need textAlign on TableHeaderCell

}: TableCellProps): React.ReactElement => {
const isChildrenString = typeof children === 'string';
const { selectionType, rowDensity, showStripedRows, backgroundColor } = useTableContext();
const isSelectable = selectionType !== 'none';
Expand All @@ -207,6 +215,8 @@ const _TableCell = ({ children }: TableCellProps): React.ReactElement => {
display="flex"
alignItems="center"
flex={1}
textAlign={textAlign}
allowMultiline={allowMultiline}
// when a direct string child is passed we want to disable pointer events
// for custom cells components, consumers can handle pointer events themselves
pointerEvents={isChildrenString && isSelectable ? 'none' : 'auto'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ exports[`<Table /> should render table 1`] = `
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down Expand Up @@ -1655,6 +1656,7 @@ exports[`<Table /> should render table with TableEditableCell and Bordered cells
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand All @@ -1669,6 +1671,7 @@ exports[`<Table /> should render table with TableEditableCell and Bordered cells
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down Expand Up @@ -2872,6 +2875,7 @@ exports[`<Table /> should render table with comfortable rowDensity 1`] = `
min-height: 60px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down Expand Up @@ -3739,6 +3743,7 @@ exports[`<Table /> should render table with compact rowDensity 1`] = `
min-height: 36px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down Expand Up @@ -4757,6 +4762,7 @@ exports[`<Table /> should render table with isRefreshing 1`] = `
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down Expand Up @@ -5680,6 +5686,7 @@ exports[`<Table /> should render table with showStripedRows 1`] = `
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
}

.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6.c6 {
Expand Down Expand Up @@ -6548,6 +6555,7 @@ exports[`<Table /> should render table with sticky header, footer & first column
min-height: 48px;
height: 100%;
width: 100%;
white-space: nowrap;
border-bottom-width: 1px;
border-bottom-color: hsla(211,20%,52%,0.18);
border-bottom-style: solid;
Expand Down
11 changes: 11 additions & 0 deletions packages/blade/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ type TableCellProps = {
* </TableCell>
**/
children: React.ReactNode;
/**
* The textAlign prop determines the content alignment of the table.
* The textAlign prop can be 'left', 'center', or 'right'.
* The default value is `left`.
**/
textAlign?: 'left' | 'center' | 'right';
/**
* The allowMultiline prop determines whether the table should allow multiline cells or not.
* The default value is `false`.
**/
allowMultiline?: boolean;
};

type TableEditableCellProps = Pick<
Expand Down
Loading