Skip to content

Commit 964ee14

Browse files
feat: ability to align individual table column items [FC-1234] (#2458)
* feat: [Table] enhancements * fix: minior change * feat: snapshot update * fix req change * feat: snapshot update * chore: remove allowmultiline * chore: update table header * chore: add text align * chore: table header * chore: update snaps * chore: update table header icon * feat: add changeset * chore: update changeset * chore: review changes & add align in table footer * chore: update snap * chore: review changes & updated snap --------- Co-authored-by: Sumitmaithani <[email protected]>
1 parent a87a200 commit 964ee14

File tree

6 files changed

+1852
-1411
lines changed

6 files changed

+1852
-1411
lines changed

.changeset/sweet-apes-roll.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@razorpay/blade': minor
3+
---
4+
5+
feat: ability to align individual table column items

packages/blade/src/components/Table/TableBody.web.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ export const CellWrapper = styled(BaseBox)<{
256256
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
257257
showStripedRows?: boolean;
258258
hasPadding?: boolean;
259-
}>(({ theme, $rowDensity, showStripedRows, hasPadding = true }) => {
259+
textAlign?: TableCellProps['textAlign'];
260+
}>(({ theme, $rowDensity, showStripedRows, hasPadding = true, textAlign }) => {
260261
const rowBackgroundTransition = `background-color ${makeMotionTime(
261262
getIn(theme.motion, tableRow.backgroundColorMotionDuration),
262263
)} ${getIn(theme.motion, tableRow.backgroundColorMotionEasing)}`;
@@ -272,6 +273,7 @@ export const CellWrapper = styled(BaseBox)<{
272273
minHeight: makeSize(getIn(size, tableRow.minHeight[$rowDensity])),
273274
height: '100%',
274275
width: '100%',
276+
justifyContent: textAlign,
275277
...(!showStripedRows && {
276278
borderBottomWidth: makeSpace(getIn(theme.border.width, tableRow.borderBottomWidth)),
277279
borderBottomColor: getIn(theme.colors, tableRow.borderColor),
@@ -281,7 +283,12 @@ export const CellWrapper = styled(BaseBox)<{
281283
};
282284
});
283285

284-
const _TableCell = ({ children, _hasPadding, ...rest }: TableCellProps): React.ReactElement => {
286+
const _TableCell = ({
287+
children,
288+
textAlign,
289+
_hasPadding,
290+
...rest
291+
}: TableCellProps): React.ReactElement => {
285292
const isChildrenString = typeof children === 'string';
286293
const { selectionType, rowDensity, showStripedRows, backgroundColor } = useTableContext();
287294
const isSelectable = selectionType !== 'none';
@@ -303,6 +310,7 @@ const _TableCell = ({ children, _hasPadding, ...rest }: TableCellProps): React.R
303310
alignItems="center"
304311
hasPadding={_hasPadding}
305312
flex={1}
313+
textAlign={textAlign}
306314
// when a direct string child is passed we want to disable pointer events
307315
// for custom cells components, consumers can handle pointer events themselves
308316
pointerEvents={isChildrenString && isSelectable ? 'none' : 'auto'}

packages/blade/src/components/Table/TableFooter.web.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ const TableFooterRow = assignWithoutSideEffects(_TableFooterRow, {
7979
const StyledFooterCell = styled(FooterCell)<{
8080
$backgroundColor: TableBackgroundColors;
8181
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
82-
}>(({ theme, $backgroundColor, $rowDensity }) => ({
82+
$textAlign?: string;
83+
}>(({ theme, $backgroundColor, $rowDensity, $textAlign }) => ({
8384
'&&&': {
8485
height: '100%',
8586
backgroundColor: getIn(theme.colors, $backgroundColor),
@@ -98,18 +99,24 @@ const StyledFooterCell = styled(FooterCell)<{
9899
paddingRight: makeSpace(getIn(theme, tableRow.paddingRight[$rowDensity])),
99100
minHeight: makeSize(getIn(size, tableRow.minHeight[$rowDensity])),
100101
alignItems: 'center',
102+
justifyContent: $textAlign ? $textAlign : 'left',
101103
},
102104
},
103105
}));
104106

105-
const _TableFooterCell = ({ children, ...rest }: TableFooterCellProps): React.ReactElement => {
107+
const _TableFooterCell = ({
108+
children,
109+
textAlign,
110+
...rest
111+
}: TableFooterCellProps): React.ReactElement => {
106112
const isChildrenString = typeof children === 'string';
107113
const { backgroundColor, rowDensity } = useTableContext();
108114

109115
return (
110116
<StyledFooterCell
111117
$backgroundColor={backgroundColor}
112118
$rowDensity={rowDensity}
119+
$textAlign={textAlign}
113120
{...metaAttribute({ name: MetaConstants.TableFooterCell })}
114121
{...makeAnalyticsAttribute(rest)}
115122
>

packages/blade/src/components/Table/TableHeader.web.tsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ const StyledHeaderCell = styled(HeaderCell)<{
9999
$backgroundColor: TableBackgroundColors;
100100
$rowDensity: NonNullable<TableProps<unknown>['rowDensity']>;
101101
$hasPadding: boolean;
102-
}>(({ theme, $isSortable, $backgroundColor, $rowDensity, $hasPadding }) => ({
102+
$textAlign: 'left' | 'center' | 'right';
103+
}>(({ theme, $isSortable, $backgroundColor, $rowDensity, $hasPadding, $textAlign }) => ({
103104
'&&&': {
105+
display: $textAlign ? 'flex' : 'block',
106+
justifyContent: $textAlign ? 'space-between' : 'initial',
104107
height: '100%',
105108
backgroundColor: getIn(theme.colors, $backgroundColor),
106109
borderBottomWidth: makeSpace(getIn(theme.border.width, tableHeader.borderBottomAndTopWidth)),
@@ -114,7 +117,7 @@ const StyledHeaderCell = styled(HeaderCell)<{
114117
backgroundColor: getIn(theme.colors, tableHeader.backgroundColor),
115118
display: 'flex',
116119
flexDirection: 'row',
117-
justifyContent: 'space-between',
120+
justifyContent: $textAlign ? $textAlign : 'space-between',
118121
alignItems: 'center',
119122
height: '100%',
120123
paddingLeft: $hasPadding
@@ -133,6 +136,7 @@ const _TableHeaderCell = ({
133136
children,
134137
headerKey,
135138
_hasPadding = true,
139+
textAlign,
136140
...rest
137141
}: TableHeaderCellProps): React.ReactElement => {
138142
const {
@@ -152,6 +156,7 @@ const _TableHeaderCell = ({
152156
$backgroundColor={backgroundColor}
153157
$rowDensity={headerRowDensity ?? rowDensity}
154158
$hasPadding={_hasPadding}
159+
$textAlign={textAlign}
155160
onClick={() => {
156161
if (isSortable) {
157162
toggleSort(headerKey);
@@ -160,15 +165,17 @@ const _TableHeaderCell = ({
160165
{...metaAttribute({ name: MetaConstants.TableHeaderCell })}
161166
{...makeAnalyticsAttribute(rest)}
162167
>
163-
{isChildrenString ? (
164-
<Text size="medium" weight="medium" color="surface.text.gray.normal">
165-
{children}
166-
</Text>
167-
) : (
168-
children
169-
)}
168+
<BaseBox display="flex" flexGrow={1} justifyContent={textAlign}>
169+
{isChildrenString ? (
170+
<Text size="medium" weight="medium" color="surface.text.gray.normal">
171+
{children}
172+
</Text>
173+
) : (
174+
children
175+
)}
176+
</BaseBox>
170177
{isSortable && (
171-
<BaseBox paddingLeft="spacing.2" backgroundColor="transparent">
178+
<BaseBox paddingLeft="spacing.2" backgroundColor="transparent" flexShrink={0}>
172179
<SortIcon
173180
isSorted={currentSortedState.sortKey === headerKey}
174181
isSortReversed={currentSortedState.isSortReversed}

0 commit comments

Comments
 (0)