Skip to content

Commit 97342a1

Browse files
author
Hector Arce De Las Heras
committed
Fixed double line separator on mobile
Fixed double line separator on mobile and added the posibility to set single variant to Header cell
1 parent fe7e2ff commit 97342a1

File tree

9 files changed

+70
-5
lines changed

9 files changed

+70
-5
lines changed

src/components/table/__tests__/table.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const mockBaseCustomizable = {
159159
id: 'routingNumber',
160160
label: 'Routing number',
161161
config: { alignHeader: 'left', alignValue: 'left' },
162+
headerVariant: 'SECONDARY',
162163
},
163164
{
164165
id: 'accountNumber',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
import { renderProvider } from '@/tests/renderProvider/renderProvider.utility';
4+
5+
import { ListDivider } from '../listDivider';
6+
7+
describe('ListDivider', () => {
8+
it('should render null when divider prop is null', () => {
9+
const { container } = renderProvider(<ListDivider divider={null} />);
10+
expect(container.firstChild).toBeNull();
11+
});
12+
13+
it('should render LineSeparator when divider prop is a string', () => {
14+
const dividerValue = 'test';
15+
const { getByText } = renderProvider(<ListDivider divider={dividerValue} />);
16+
expect(getByText(dividerValue)).toBeInTheDocument();
17+
});
18+
19+
it('should render Divider when divider prop is a Divider object', () => {
20+
const dividerObject = {
21+
variant: 'DEFAULT',
22+
};
23+
const { container } = renderProvider(<ListDivider divider={dividerObject} />);
24+
25+
expect(container.firstChild).not.toBeNull();
26+
});
27+
28+
it('should render null when divider object has no variant and either dividerStyles', () => {
29+
const dividerObject = {
30+
leftLabel: 'Left label',
31+
};
32+
const { container } = renderProvider(<ListDivider divider={dividerObject} />);
33+
34+
expect(container.firstChild).toBeNull();
35+
});
36+
});

src/components/table/component/listColumnHeaderPriority.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const ListColumnHeaderPriority = (props: IListComponent): JSX.Element =>
3939
customWidth={header?.config?.width}
4040
flexWidth={header?.config?.flexWidth}
4141
hidden={props.hiddenHeaderOn?.[props.device]}
42+
index={indexHeader}
4243
lineSeparatorBottomOnHeader={props.lineSeparatorBottomOnHeader}
4344
lineSeparatorLineStyles={props.lineSeparatorLineStyles}
4445
lineSeparatorTopOnHeader={props.lineSeparatorTopOnHeader}

src/components/table/component/listRowHeaderPriority.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const ListRowHeaderPriority = (props: IListRowHeaderPriority): JSX.Elemen
4444
customBackgroundColor={rowHeader?.config?.backgroundColor}
4545
customWidth={rowHeader?.config?.width}
4646
flexWidth={rowHeader?.config?.flexWidth}
47+
index={props.index}
4748
lineSeparatorBottomOnHeader={props.lineSeparatorBottomOnHeader}
4849
lineSeparatorLineStyles={props.lineSeparatorLineStyles}
4950
lineSeparatorTopOnHeader={props.lineSeparatorTopOnHeader}

src/components/table/component/table.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const TableComponent = (
9191
</TableColumnHeaderStyled>
9292
)}
9393
{headersElementWithoutDivider.map((headerValue, index) => {
94+
const headerVariant = headerValue.variant ? headerValue.variant : props.headerVariant;
9495
return (
9596
<TableColumnHeaderStyled
9697
key={headerValue.id}
@@ -103,15 +104,15 @@ export const TableComponent = (
103104
flexWidth={headerValue?.config?.flexWidth}
104105
hasDivider={headerValue?.config?.hasDivider}
105106
scope="col"
106-
styles={props.styles.header?.[props.headerVariant]}
107+
styles={props.styles.header?.[headerVariant]}
107108
>
108109
<Text
109110
align={
110111
headerValue?.config?.alignHeader?.[props.device] ||
111112
headerValue?.config?.alignHeader
112113
}
113114
component={TextComponentType.SPAN}
114-
customTypography={props.styles.header?.[props.headerVariant]?.typography}
115+
customTypography={props.styles.header?.[headerVariant]?.typography}
115116
dataTestId={`${props.dataTestId}Header${index}`}
116117
>
117118
{headerValue.label}

src/components/table/stories/mockTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export const mockCustomizableTable = {
499499
id: 'routingNumber',
500500
label: 'Routing number',
501501
config: { alignHeader: 'center', alignValue: 'center' },
502+
variant: 'PRIMARY',
502503
},
503504
{
504505
id: 'accountNumber',

src/components/table/table.styled.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const TableColumnHeaderStyled = styled.th<{
145145
customBackgroundColor?: string;
146146
}>`
147147
${props => getStyles(props.styles?.column)}
148+
${({ styles }) => getTypographyStyles(styles?.typography)}
148149
// Apply custom styles
149150
${({ customWidth, customAlign, flexWidth, customBackgroundColor }) =>
150151
applyCustomCellStyles({ customWidth, customAlign, flexWidth, customBackgroundColor })}
@@ -325,6 +326,7 @@ export const ListRowHeaderPriorityStyled = styled.ul<{
325326
`;
326327

327328
export const ListHeaderItemStylesStyled = styled.span<{
329+
index?: number;
328330
hasSomeExpandedContent?: boolean;
329331
lineSeparatorLineStyles?: LineSeparatorLinePropsStylesType;
330332
lineSeparatorTopOnHeader?: boolean;
@@ -335,9 +337,10 @@ export const ListHeaderItemStylesStyled = styled.span<{
335337
flexWidth?: string | number | FlexWidthType;
336338
customBackgroundColor?: string;
337339
}>`
338-
${({ lineSeparatorLineStyles, lineSeparatorTopOnHeader, lineSeparatorBottomOnHeader }) => {
340+
${({ index, lineSeparatorLineStyles, lineSeparatorTopOnHeader, lineSeparatorBottomOnHeader }) => {
339341
const lineSeparator: (CSSProp | undefined)[] = [];
340-
if (lineSeparatorTopOnHeader) {
342+
// Only add lineSeparator on top when it is the first row
343+
if (lineSeparatorTopOnHeader && index === 0) {
341344
lineSeparator.push(lineSeparatorLineStyles?.buildLineStyles?.(LineSeparatorPositionType.TOP));
342345
}
343346
if (lineSeparatorBottomOnHeader) {

src/components/table/types/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export interface ITableHeader {
134134
id: string;
135135
config?: ConfigType;
136136
value?: ValueFunctionType & DividerContent;
137+
variant?: string;
137138
}
138139

139140
export interface ITableRowHeader extends Omit<ITableHeader, 'id'> {

src/designSystem/kubit/components/table/styles.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export const TABLE_STYLES: TableStylesType<
9292
...commonPropsHeader.container,
9393
background_color: COLORS.SECONDARY.color_secondary_bg_150,
9494
},
95+
column: {
96+
...commonPropsHeader.column,
97+
//It is used to add color to one single header cell, intead of the whole row
98+
background_color: COLORS.SECONDARY.color_secondary_bg_150,
99+
},
95100
},
96101
[TableHeaderVariantType.SECONDARY]: {
97102
...commonPropsHeader,
@@ -102,6 +107,11 @@ export const TABLE_STYLES: TableStylesType<
102107
border_bottom_color: COLORS.SECONDARY.color_secondary_border_50,
103108
border_bottom_style: 'solid',
104109
},
110+
column: {
111+
...commonPropsHeader.column,
112+
//It is used to add color to one single header cell, intead of the whole row
113+
background_color: COLORS.NEUTRAL.color_neutral_bg_250,
114+
},
105115
},
106116
[TableHeaderVariantType.CUSTOMIZABLE_HEADER]: {
107117
...commonPropsHeader,
@@ -171,31 +181,41 @@ export const TABLE_STYLES: TableStylesType<
171181
flex_direction: 'column',
172182
justify_content: 'left',
173183
background_color: COLORS.NEUTRAL.color_neutral_bg_250,
184+
gap: SPACINGS.spacing_250,
185+
},
186+
listContainerHeaderPriority: {
187+
display: 'flex',
188+
flex_direction: 'column',
189+
justify_content: 'left',
190+
gap: SPACINGS.spacing_250,
174191
},
175192
listContainerSydeBySyde: {
176193
display: 'flex',
177194
flex_direction: 'row',
178195
justify_content: 'space-between',
179196
flex_wrap: 'wrap',
197+
gap: SPACINGS.spacing_250,
180198
},
181199
listRowContainer: {
182200
display: 'flex',
183201
flex_direction: 'column',
184202
justify_content: 'left',
203+
gap: SPACINGS.spacing_250,
185204
},
186205
listRowContainerBorder: true,
187206
listRow: {
188207
display: 'flex',
189208
flex_direction: 'column',
190209
justify_content: 'left',
191210
padding: `${SPACINGS.spacing_250} ${SPACINGS.spacing_300}`,
192-
gap: SPACINGS.spacing_150,
211+
gap: SPACINGS.spacing_250,
193212
},
194213
listRowSideBySide: {
195214
display: 'flex',
196215
flex_direction: 'row',
197216
justify_content: 'space-between',
198217
flex_wrap: 'wrap',
218+
gap: SPACINGS.spacing_250,
199219
},
200220
divider: {
201221
lineSeparatorLabelVariant: LineSeparatorLabelVariantType.LABEL_DEFAULT,

0 commit comments

Comments
 (0)