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: ability to align individual table column items [FC-1234] #2458

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/sweet-apes-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@razorpay/blade': patch
---

feat: ability to align individual table column items
12 changes: 10 additions & 2 deletions packages/blade/src/components/Table/TableBody.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export const CellWrapper = styled(BaseBox)<{
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
showStripedRows?: boolean;
hasPadding?: boolean;
}>(({ theme, $rowDensity, showStripedRows, hasPadding = true }) => {
textAlign?: TableCellProps['textAlign'];
}>(({ theme, $rowDensity, showStripedRows, hasPadding = true, textAlign }) => {
const rowBackgroundTransition = `background-color ${makeMotionTime(
getIn(theme.motion, tableRow.backgroundColorMotionDuration),
)} ${getIn(theme.motion, tableRow.backgroundColorMotionEasing)}`;
Expand All @@ -272,6 +273,7 @@ export const CellWrapper = styled(BaseBox)<{
minHeight: makeSize(getIn(size, tableRow.minHeight[$rowDensity])),
height: '100%',
width: '100%',
justifyContent: textAlign,
...(!showStripedRows && {
borderBottomWidth: makeSpace(getIn(theme.border.width, tableRow.borderBottomWidth)),
borderBottomColor: getIn(theme.colors, tableRow.borderColor),
Expand All @@ -281,7 +283,12 @@ export const CellWrapper = styled(BaseBox)<{
};
});

const _TableCell = ({ children, _hasPadding, ...rest }: TableCellProps): React.ReactElement => {
const _TableCell = ({
children,
textAlign,
_hasPadding,
...rest
}: TableCellProps): React.ReactElement => {
const isChildrenString = typeof children === 'string';
const { selectionType, rowDensity, showStripedRows, backgroundColor } = useTableContext();
const isSelectable = selectionType !== 'none';
Expand All @@ -303,6 +310,7 @@ const _TableCell = ({ children, _hasPadding, ...rest }: TableCellProps): React.R
alignItems="center"
hasPadding={_hasPadding}
flex={1}
textAlign={textAlign}
// 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
11 changes: 9 additions & 2 deletions packages/blade/src/components/Table/TableFooter.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const TableFooterRow = assignWithoutSideEffects(_TableFooterRow, {
const StyledFooterCell = styled(FooterCell)<{
$backgroundColor: TableBackgroundColors;
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
}>(({ theme, $backgroundColor, $rowDensity }) => ({
$textAlign?: string;
}>(({ theme, $backgroundColor, $rowDensity, $textAlign }) => ({
'&&&': {
height: '100%',
backgroundColor: getIn(theme.colors, $backgroundColor),
Expand All @@ -98,18 +99,24 @@ const StyledFooterCell = styled(FooterCell)<{
paddingRight: makeSpace(getIn(theme, tableRow.paddingRight[$rowDensity])),
minHeight: makeSize(getIn(size, tableRow.minHeight[$rowDensity])),
alignItems: 'center',
justifyContent: $textAlign ? $textAlign : 'left',
},
},
}));

const _TableFooterCell = ({ children, ...rest }: TableFooterCellProps): React.ReactElement => {
const _TableFooterCell = ({
children,
textAlign,
...rest
}: TableFooterCellProps): React.ReactElement => {
const isChildrenString = typeof children === 'string';
const { backgroundColor, rowDensity } = useTableContext();

return (
<StyledFooterCell
$backgroundColor={backgroundColor}
$rowDensity={rowDensity}
$textAlign={textAlign}
{...metaAttribute({ name: MetaConstants.TableFooterCell })}
{...makeAnalyticsAttribute(rest)}
>
Expand Down
27 changes: 17 additions & 10 deletions packages/blade/src/components/Table/TableHeader.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ const StyledHeaderCell = styled(HeaderCell)<{
$backgroundColor: TableBackgroundColors;
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
$hasPadding: boolean;
}>(({ theme, $isSortable, $backgroundColor, $rowDensity, $hasPadding }) => ({
$textAlign: 'left' | 'center' | 'right';
}>(({ theme, $isSortable, $backgroundColor, $rowDensity, $hasPadding, $textAlign }) => ({
'&&&': {
display: $textAlign ? 'flex' : 'block',
justifyContent: $textAlign ? 'space-between' : 'initial',
height: '100%',
backgroundColor: getIn(theme.colors, $backgroundColor),
borderBottomWidth: makeSpace(getIn(theme.border.width, tableHeader.borderBottomAndTopWidth)),
Expand All @@ -111,7 +114,7 @@ const StyledHeaderCell = styled(HeaderCell)<{
backgroundColor: getIn(theme.colors, tableHeader.backgroundColor),
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
justifyContent: $textAlign ? $textAlign : 'space-between',
alignItems: 'center',
height: '100%',
paddingLeft: $hasPadding
Expand All @@ -130,6 +133,7 @@ const _TableHeaderCell = ({
children,
headerKey,
_hasPadding = true,
textAlign,
...rest
}: TableHeaderCellProps): React.ReactElement => {
const {
Expand All @@ -149,6 +153,7 @@ const _TableHeaderCell = ({
$backgroundColor={backgroundColor}
$rowDensity={headerRowDensity ?? rowDensity}
$hasPadding={_hasPadding}
$textAlign={textAlign}
onClick={() => {
if (isSortable) {
toggleSort(headerKey);
Expand All @@ -157,15 +162,17 @@ const _TableHeaderCell = ({
{...metaAttribute({ name: MetaConstants.TableHeaderCell })}
{...makeAnalyticsAttribute(rest)}
>
{isChildrenString ? (
<Text size="medium" weight="medium" color="surface.text.gray.normal">
{children}
</Text>
) : (
children
)}
<BaseBox display="flex" flexGrow={1} justifyContent={textAlign}>
{isChildrenString ? (
<Text size="medium" weight="medium" color="surface.text.gray.normal">
{children}
</Text>
) : (
children
)}
</BaseBox>
{isSortable && (
<BaseBox paddingLeft="spacing.2" backgroundColor="transparent">
<BaseBox paddingLeft="spacing.2" backgroundColor="transparent" flexShrink={0}>
<SortIcon
isSorted={currentSortedState.sortKey === headerKey}
isSortReversed={currentSortedState.isSortReversed}
Expand Down
Loading
Loading