Skip to content
Closed
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
8 changes: 4 additions & 4 deletions lib/src/common/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,10 @@ export const componentTokens = {
dataFontWeight: CoreTokens.type_regular,
dataFontColor: CoreTokens.color_black,
dataFontTextTransform: "none",
dataPaddingTop: "14px",
dataPaddingBottom: "12px",
dataPaddingTop: "16px",
dataPaddingBottom: "16px",
dataPaddingRight: "20px",
dataPaddingLeft: "40px",
dataPaddingLeft: "20px",
dataTextAlign: "left",
dataTextLineHeight: "normal",
headerBackgroundColor: CoreTokens.color_purple_700,
Expand All @@ -861,7 +861,7 @@ export const componentTokens = {
headerPaddingTop: "16px",
headerPaddingBottom: "16px",
headerPaddingRight: "20px",
headerPaddingLeft: "40px",
headerPaddingLeft: "20px",
headerTextAlign: "left",
headerTextLineHeight: "normal",
scrollBarThumbColor: CoreTokens.color_grey_700,
Expand Down
19 changes: 19 additions & 0 deletions lib/src/resultset-table/ResultsetTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ export const Chromatic = () => (
<DxcResultsetTable columns={columnsSortable} rows={longValues} />
</SmallContainer>
</ExampleContainer>
<ExampleContainer>
<Title title="Reduced sortable table" theme="light" level={4} />
<DxcResultsetTable columns={columnsSortable} rows={rowsSortable} mode="reduced" />
</ExampleContainer>
{/* PENDING SMALL ICON VERSION */}
<ExampleContainer>
<Title title="Reduced with items per page option" theme="light" level={4} />
<DxcResultsetTable columns={columns} rows={rows} itemsPerPage={2} itemsPerPageOptions={[2, 3]} mode="reduced" />
</ExampleContainer>
<ExampleContainer>
<Title title="Reduced scroll resultset table" theme="light" level={4} />
<DxcResultsetTable columns={longColumns} rows={longRows} mode="reduced" />
</ExampleContainer>
<ExampleContainer>
<SmallContainer>
<Title title="Reduced small container and text overflow" theme="light" level={4} />
<DxcResultsetTable columns={columnsSortable} rows={longValues} mode="reduced" />
</SmallContainer>
</ExampleContainer>
<Title title="Margins" theme="light" level={2} />
<ExampleContainer>
<Title title="Xxsmall" theme="light" level={4} />
Expand Down
14 changes: 8 additions & 6 deletions lib/src/resultset-table/ResultsetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useTheme from "../useTheme";
import ResultsetTablePropsType, { Column } from "./types";
import icons from "./Icons";
import { getMargin } from "../common/utils";
import CoreTokens from "../common/coreTokens";

const normalizeSortValue = (sortValue) => (typeof sortValue === "string" ? sortValue.toUpperCase() : sortValue);

Expand Down Expand Up @@ -42,6 +43,7 @@ const DxcResultsetTable = ({
itemsPerPageFunction,
margin,
tabIndex = 0,
mode = "default",
}: ResultsetTablePropsType): JSX.Element => {
const colorsTheme = useTheme();
const [page, changePage] = useState(1);
Expand Down Expand Up @@ -85,7 +87,7 @@ const DxcResultsetTable = ({
return (
<ThemeProvider theme={colorsTheme.table}>
<DxcResultsetTableContainer margin={margin}>
<DxcTable>
<DxcTable mode={mode}>
<thead>
<tr>
{columns.map((column, index) => (
Expand All @@ -101,6 +103,7 @@ const DxcResultsetTable = ({
}}
tabIndex={column.isSortable ? tabIndex : -1}
isSortable={column.isSortable}
mode={mode}
>
<span>{column.displayValue}</span>
{column.isSortable && (
Expand Down Expand Up @@ -157,20 +160,19 @@ const DxcResultsetTableContainer = styled.div<{ margin: ResultsetTablePropsType[
props.margin && typeof props.margin === "object" && props.margin.left ? spaces[props.margin.left] : ""};
`;

const HeaderContainer = styled.span<{ isSortable: Column["isSortable"] }>`
const HeaderContainer = styled.span<{ isSortable: Column["isSortable"]; mode: ResultsetTablePropsType["mode"] }>`
display: flex;
align-items: center;
justify-content: ${(props) =>
props.theme.headerTextAlign === "center"
? "center"
: props.theme.headerTextAlign === "right"
? "flex-end"
: "flex-start"};
gap: 8px;
? "flex-end"
: "flex-start"};
gap: ${CoreTokens.spacing_8};
width: fit-content;
border: 1px solid transparent;
border-radius: 2px;
padding: 3px;
cursor: ${(props) => (props.isSortable ? "pointer" : "default")};

${(props) =>
Expand Down
6 changes: 6 additions & 0 deletions lib/src/resultset-table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ type Props = {
* Value of the tabindex attribute applied to the sortable icon.
*/
tabIndex?: number;
/**
* Determines the visual style and layout
* - "default": The default mode with big spacing
* - "reduced": A reduced mode with minimal spacing for dense tables
*/
mode?: "default" | "reduced";
};

export default Props;
98 changes: 98 additions & 0 deletions lib/src/table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,104 @@ export const Chromatic = () => (
</DxcTable>
</div>
</ExampleContainer>
<ExampleContainer>
<Title title="Default reduced" theme="light" level={4} />
<DxcTable mode="reduced">
<tr>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
</tr>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
<tr>
<td>cell 4</td>
<td>cell 5</td>
<td>cell 6</td>
</tr>
<tr>
<td>cell 7</td>
<td>cell 8</td>
<td>Cell 9</td>
</tr>
</DxcTable>
</ExampleContainer>
<ExampleContainer>
<Title title="Reduced with scrollbar" theme="light" level={4} />
<div
style={{ height: 200 + "px", display: "flex", flexDirection: "row", width: 100 + "%", marginBottom: 50 + "px" }}
>
<DxcTable mode="reduced">
<tr>
<th>
header<br></br>subheader
</th>
<th>
header<br></br>subheader
</th>
<th>
header<br></br>subheader
</th>
</tr>
<tr>
<td>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.
</td>
<td>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</td>
<td>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
<tr>
<td>cell data</td>
<td>cell data</td>
<td>cell data</td>
</tr>
</DxcTable>
</div>
</ExampleContainer>
<Title title="Margins" theme="light" level={2} />
<ExampleContainer>
<Title title="Xxsmall margin" theme="light" level={4} />
Expand Down
24 changes: 17 additions & 7 deletions lib/src/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { spaces } from "../common/variables";
import { getMargin } from "../common/utils";
import useTheme from "../useTheme";
import TablePropsType from "./types";
import CoreTokens from "../common/coreTokens";

const DxcTable = ({ children, margin }: TablePropsType): JSX.Element => {
const DxcTable = ({ children, margin, mode = "default" }: TablePropsType): JSX.Element => {
const colorsTheme = useTheme();

return (
<ThemeProvider theme={colorsTheme.table}>
<DxcTableContainer margin={margin}>
<DxcTableContent>{children}</DxcTableContent>
<DxcTableContent mode={mode}>{children}</DxcTableContent>
</DxcTableContainer>
</ThemeProvider>
);
Expand Down Expand Up @@ -48,14 +49,14 @@ const DxcTableContainer = styled.div<{ margin: TablePropsType["margin"] }>`
}
`;

const DxcTableContent = styled.table`
const DxcTableContent = styled.table<{ mode: TablePropsType["mode"] }>`
border-collapse: collapse;
width: 100%;

& tr {
border-bottom: ${(props) =>
`${props.theme.rowSeparatorThickness} ${props.theme.rowSeparatorStyle} ${props.theme.rowSeparatorColor}`};
height: 60px;
height: ${(props) => (props.mode === "default" ? "60px" : "36px")};
}
& td {
background-color: ${(props) => props.theme.dataBackgroundColor};
Expand All @@ -68,7 +69,9 @@ const DxcTableContent = styled.table`
text-align: ${(props) => props.theme.dataTextAlign};
line-height: ${(props) => props.theme.dataTextLineHeight};
padding: ${(props) =>
`${props.theme.dataPaddingTop} ${props.theme.dataPaddingRight} ${props.theme.dataPaddingBottom} ${props.theme.dataPaddingLeft}`};
props.mode === "default"
? `${props.theme.dataPaddingTop} ${props.theme.dataPaddingRight} ${props.theme.dataPaddingBottom} ${props.theme.dataPaddingLeft}`
: `${CoreTokens.spacing_8} ${CoreTokens.spacing_16}`};
}
& th {
background-color: ${(props) => props.theme.headerBackgroundColor};
Expand All @@ -81,16 +84,23 @@ const DxcTableContent = styled.table`
text-align: ${(props) => props.theme.headerTextAlign};
line-height: ${(props) => props.theme.headerTextLineHeight};
padding: ${(props) =>
`${props.theme.headerPaddingTop} ${props.theme.headerPaddingRight} ${props.theme.headerPaddingBottom} ${props.theme.headerPaddingLeft}`};
props.mode === "default"
? `${props.theme.headerPaddingTop} ${props.theme.headerPaddingRight} ${props.theme.headerPaddingBottom} ${props.theme.headerPaddingLeft}`
: `${CoreTokens.spacing_8} ${CoreTokens.spacing_16}`};
}
& th:first-child {
border-top-left-radius: ${(props) => props.theme.headerBorderRadius};
padding-left: ${(props) => (props.mode === "default" ? CoreTokens.spacing_24 : "20px")};
}
& th:last-child {
border-top-right-radius: ${(props) => props.theme.headerBorderRadius};
padding-right: ${(props) => (props.mode === "default" ? CoreTokens.spacing_24 : "20px")};
}
& td:first-child {
padding-left: ${(props) => (props.mode === "default" ? CoreTokens.spacing_24 : "20px")};
}
& td:last-child {
padding-right: 40px;
padding-right: ${(props) => (props.mode === "default" ? CoreTokens.spacing_24 : "20px")};
}
`;

Expand Down
6 changes: 6 additions & 0 deletions lib/src/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type Props = {
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
*/
margin?: Space | Margin;
/**
* Determines the visual style and layout
* - "default": Table with big spacing, applicable to most cases.
* - "reduced": Smaller table with minimal spacing for high density information.
*/
mode?: "default" | "reduced";
};

export default Props;
6 changes: 3 additions & 3 deletions website/screens/common/themes/advanced-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,10 @@
"dataFontWeight": "400",
"dataFontColor": "#000000",
"dataFontTextTransform": "none",
"dataPaddingTop": "14px",
"dataPaddingBottom": "12px",
"dataPaddingTop": "16px",
"dataPaddingBottom": "16px",
"dataPaddingRight": "20px",
"dataPaddingLeft": "40px",
"dataPaddingLeft": "20px",
"dataTextAlign": "left",
"dataTextLineHeight": "normal",
"headerBackgroundColor": "#5f249f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ const sections = [
</td>
<td>-</td>
</tr>
<tr>
<td>
<DxcFlex direction="column" gap="0.25rem" alignItems="baseline">
<StatusTag status="Information">New</StatusTag>mode
</DxcFlex>
</td>
<td>
<TableCode>'default' | 'reduced'</TableCode>
</td>
<td>
The available table modes:
<ul>
<li>
<b>default</b>: Table with big spacing, applicable to most cases.
</li>
<li>
<b>reduced</b>: Smaller table with minimal spacing for high density information.
</li>
</ul>
</td>
<td>
<TableCode>'default'</TableCode>
</td>
</tr>
<tr>
<td>showGoToPage</td>
<td>
Expand Down Expand Up @@ -160,6 +184,12 @@ const sections = [
title: "Basic usage",
content: <Example example={basicUsage} defaultIsVisible />,
},
{
title: "Reduced usage",
content: (
<p>This example is not available yet, it will be added soon.</p>
),
},
{
title: "Sortable",
content: <Example example={sortable} defaultIsVisible />,
Expand Down
Loading