Skip to content

Commit

Permalink
feat(Table): upgrade stripped props to support painting columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Fracala authored and Artur Fracala committed Dec 3, 2024
1 parent 64a6396 commit 56710f8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
13 changes: 6 additions & 7 deletions packages/react-components/src/components/Table/Table.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use './styles/pin';
@use './styles/size';
@use './styles/strips';

$base-class: 'table';
$action-bar-class: 'action-bar';
Expand Down Expand Up @@ -54,14 +55,12 @@ $action-bar-class: 'action-bar';
}
}

&--stripped {
tbody tr:nth-child(odd) {
background-color: var(--surface-secondary-default);
&--stripped_rows {
@include strips.generateStrips('rows');
}

&:hover {
background-color: var(--surface-primary-disabled);
}
}
&--stripped_columns {
@include strips.generateStrips('columns');
}

tbody {
Expand Down
28 changes: 28 additions & 0 deletions packages/react-components/src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ export const Resizing: StoryFn = () => {
);
};

export const Stripped: StoryFn = () => {
const getRowId = (row: Data) => row.id;
const data = generateData(4);

return (
<>
<StoryDescriptor title="Rows">
<Table
size="medium"
data={data}
columns={columns}
getRowId={getRowId}
stripped="rows"
/>
</StoryDescriptor>
<StoryDescriptor title="Columns">
<Table
size="medium"
data={data}
columns={columns}
getRowId={getRowId}
stripped="columns"
/>
</StoryDescriptor>
</>
);
};

export const Sizes: StoryFn = (): React.ReactElement => {
const getRowId = (row: Data) => row.id;
const data = generateData(4);
Expand Down
4 changes: 1 addition & 3 deletions packages/react-components/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ export const Table = <T,>({
styles[`${baseClass}`],
styles[`${baseClass}--${size}`],
styles[`${baseClass}--pinned_${pin}`],
{
[styles[`${baseClass}--stripped`]]: stripped,
}
styles[`${baseClass}--stripped_${stripped}`]
)}
>
<TableHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
}

@else {
@warn "Invalid pinned value: #{$type}. Supported value are 'header' and 'leftColumn'.";
@warn "Invalid pinned value: #{$type}. Supported values are 'header' and 'leftColumn'.";
}
}
25 changes: 25 additions & 0 deletions packages/react-components/src/components/Table/styles/strips.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@mixin generateStrips($type) {
@if $type == 'rows' {
tbody tr:nth-child(odd) {
background-color: var(--surface-secondary-default);

&:hover {
background-color: var(--surface-primary-disabled) !important;
}
}
}

@else if $type == 'columns' {
tbody tr td:nth-child(even) {
background-color: var(--surface-secondary-default);
}

tbody tr:hover td:nth-child(even) {
background-color: var(--surface-primary-hover);
}
}

@else {
@warn "Invalid stripped value: #{$type}. Supported values are 'rows' and 'columns'.";
}
}
8 changes: 6 additions & 2 deletions packages/react-components/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type TableSize = 'small' | 'medium' | 'large';

export type PinOptions = 'header' | 'leftColumn';

export type StrippedOptions = 'rows' | 'columns';

export enum SortOrder {
Ascending = 'asc',
Descending = 'desc',
Expand All @@ -27,9 +29,11 @@ export interface ITableProps<T> {
*/
columns: Column<T>[];
/**
* Whether to display alternating row background colors for better readability.
* The parameter allows you to customize alternating background colors for rows
* or columns in the table, enhancing readability and visual separation. Allowed values
* are 'rows' or 'columns'
*/
stripped?: boolean;
stripped?: StrippedOptions;
/**
* Specifies the size of the table, which affects row height and spacing.
* Options: 'small', 'medium', 'large'.
Expand Down

0 comments on commit 56710f8

Please sign in to comment.