Skip to content

Commit

Permalink
EPMRPP-90306 || code review fix - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
maria-hambardzumian committed Jun 13, 2024
1 parent 3a7499d commit 6c4ec55
Show file tree
Hide file tree
Showing 13 changed files with 563 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/components/checkbox/checkbox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
background-position: center;
background-image: url("data:image/svg+xml,%3Csvg width='12' height='9' viewBox='0 0 12 9' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1.5 4.25L4.5 7.25L10.5 0.75' stroke='white' stroke-width='2'/%3E%3C/svg%3E");
}
@mixin not-all-checked-state($border-color, $rect-fill) {
@mixin partially-checked-state($border-color, $rect-fill) {
border-color: $border-color;
background-repeat: no-repeat;
background-position: center;
Expand Down Expand Up @@ -87,20 +87,20 @@
border: 2px solid var(--rp-ui-color-primary-focused);
}

&.not-all-checked:not(:checked){
&.partially-checked:not(:checked){
& + .control {
@include not-all-checked-state(var(--rp-ui-color-field-border), var(--rp-ui-color-field-border-2));
@include partially-checked-state(var(--rp-ui-color-field-border), var(--rp-ui-color-field-border-2));
}

&:hover + .control {
@include not-all-checked-state(var(--rp-ui-color-field-border-2-hover), var(--rp-ui-color-primary-hover));
@include partially-checked-state(var(--rp-ui-color-field-border-2-hover), var(--rp-ui-color-primary-hover));
}

&:active:not(:disabled) + .control {
@include not-all-checked-state(var(--rp-ui-color-primary-focused), var(--rp-ui-color-field-border-2));
@include partially-checked-state(var(--rp-ui-color-primary-focused), var(--rp-ui-color-field-border-2));
}
&:disabled + .control {
@include not-all-checked-state(var(--rp-ui-color-field-borderd), var(--rp-ui-color-field-border));
@include partially-checked-state(var(--rp-ui-color-field-borderd), var(--rp-ui-color-field-border));
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface CheckboxProps extends HTMLAttributes<HTMLInputElement> {
disabled?: boolean;
className?: string;
onChange?: ChangeEventHandler<HTMLInputElement>;
notAllChecked?: boolean;
partiallyChecked?: boolean;
}

// DS link - https://www.figma.com/file/gjYQPbeyf4YsH3wZiVKoaj/%F0%9F%9B%A0-RP-DS-6?type=design&node-id=2350-8764&mode=design&t=GAXsAg9jOEgkVVlq-0
Expand All @@ -29,7 +29,7 @@ export const Checkbox: FC<CheckboxProps> = ({
onChange,
className,
value,
notAllChecked,
partiallyChecked,
...rest
}): ReactElement => {
const inputRef = useRef<HTMLInputElement | null>(null);
Expand Down Expand Up @@ -61,7 +61,7 @@ export const Checkbox: FC<CheckboxProps> = ({
tabIndex={0}
type="checkbox"
onKeyDown={handleKeyDown}
className={cx('input', { 'not-all-checked': notAllChecked })}
className={cx('input', { 'partially-checked': partiallyChecked })}
disabled={disabled}
onChange={onChange}
checked={value}
Expand Down
3 changes: 3 additions & 0 deletions src/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export { default as DeleteIcon } from './svg/delete.svg';
export { default as DropdownIcon } from './svg/dropdown.svg';
export { default as PrevPageIcon } from './svg/prevPage.svg';
export { default as PrevChapterIcon } from './svg/prevChapter.svg';
export { default as ArrowDownIcon } from './svg/arrowDown.svg';
export { default as ArrowUpIcon } from './svg/arrowUp.svg';
export { default as MeatballMenuIcon } from './svg/meatballMenu.svg';
3 changes: 3 additions & 0 deletions src/components/icons/svg/arrowDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/components/icons/svg/arrowUp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/components/icons/svg/meatballMenu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions src/components/table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Table Component

### Table props:

#### `data` (RowData[])

An array of objects representing the data to be displayed in the table. Each object should have properties corresponding to the columns of the table.

The `RowData` interface allows for flexibility in defining each row of data. It consists of the following properties:

- `[key: string]`: The key-value pairs representing the data for each column in the table. The keys should match the keys of the columns specified in the `primaryColumn` and `fixedColumns` props.
- `detailedCellData` _(optional)_: An object containing detailed data for the cell, including content for sorting and a React component for rendering.
- `content` _(string | number)_: The content of the cell for sorting purposes.
- `component` _(ReactNode)_: A React component to render in the cell.
- `rowConfigs` _(optional)_: An object containing configuration options for the row, such as its size.
- `size` _(optional)_: The size of the row, which can be 'small', 'default', or 'large'.

#### `primaryColumn` (PrimaryColumn)

Specifies the primary column of the table. It should be an object with the following properties:

- `key` _(string)_: The unique key of the primary column.
- `header` _(string)_: The header text of the primary column.

#### `fixedColumns` (FixedColumn[])

An array of objects representing the fixed columns of the table. Each object should have the following properties:

- `key` _(string)_: The unique key of the column.
- `header` _(string)_: The header text of the column.
- `width` _(number)_: The width of the column in pixels.
- `order` _(number)_: The order of the column.
- `align` _(optional, string)_: The alignment of the column content ('left', 'center', 'right').

#### `rowActionMenu` (ReactNode, optional)

A custom action menu to be displayed for each row in the table. It can be any valid ReactNode.

#### `selectable` (boolean, optional)

Indicates whether row selection using checkboxes is enabled. Set to true to enable checkbox selection.

#### `className` (string, optional)

Additional CSS classes to be applied to the table.

#### `selectedRowIds` ((string | number)[], optional)
An array containing the IDs of the currently selected rows.

#### `sortingDirection` (SortDirection, optional)
Specifies the current sorting direction ('asc' or 'desc').

#### `sortingColumn` (Column, optional)
Specifies the column by which the table is currently sorted.

#### `onChangeSorting` ((sortConfig?: SortConfig) => void, optional)
Callback function triggered when the sorting configuration changes.

#### `onToggleRowSelection` ((id: string | number) => void, optional)
Callback function triggered when a row's selection state changes.
5 changes: 5 additions & 0 deletions src/components/table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Table } from './table';

export { Table };

export default Table;
115 changes: 115 additions & 0 deletions src/components/table/table.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@import 'src/assets/styles/variables/typography';

$HEIGHT-SMALL: 44px;
$HEIGHT-DEFAULT: 64px;
$HEIGHT-LARGE: 80px;


* {
box-sizing: border-box;
}

.table {
width: 100%;
max-width: 1200px;

}

.table-header {
display: flex;
width: 100%;
height: 32px;
align-items: center;
}

.table-row {
display: flex;
width: 100%;
height: $HEIGHT-DEFAULT;

.table-row-content {
display: flex;
align-items: center;
height: 100%;
flex: 1;
box-shadow: var(--rp-ui-base-shadow-hover);
background-color: var(--rp-ui-base-bg-000);
border-radius: 4px;
}

&.size-small {
height: $HEIGHT-SMALL;
}

&.size-large {
height: $HEIGHT-LARGE;
}

&:hover {
color: var(--rp-ui-base-topaz-hover);
}
}

.table-body {
display: flex;
flex-direction: column;
gap: 4px;
width: 100%;
}

.table-header-cell, .table-cell {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-family: var(--rp-ui-base-font-family);
font-weight: $fw-regular;
padding: 0 16px;

&.action-menu-cell {
width: 48px;
padding: 0 16px;
}

&.checkbox-cell{
width: 48px;
display: flex;
justify-content: center;
height: 100%;
cursor: pointer;
}

&.primary-cell {
flex: 1 0 320px;
font-weight: $fw-medium;
text-align: left;
}
}

.table-header-cell {
font-size: 11px;
line-height: 16px;
color: var(--rp-ui-base-e-400);
display: flex;
align-items: center;
text-align: left;
background: none;
border: none;
cursor: pointer;

&.align-right {
justify-content: flex-end;

svg {
margin-right: -16px;
}
}

&.align-center {
justify-content: center;
}
}

.table-cell {
font-size: 13px;
line-height: 20px;
}
108 changes: 108 additions & 0 deletions src/components/table/table.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Table } from './table';
import { Popover } from '@components/popover';
import { MeatballMenuIcon } from '@components/icons';
import { TableComponentProps, RowData, FixedColumn, Column, SortDirection } from './types';
import { useState } from 'react';
import { sortTableData } from '@components/table/utils';

const meta: Meta<typeof Table> = {
title: 'Table',
component: Table,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
selectable: true,
},
};

export default meta;

type Story = StoryObj<TableComponentProps>;

const rowActionMenu = (
<Popover
placement={'bottom-end'}
content={
<div>
<p>Edit</p>
<p>Rename</p>
</div>
}
>
<MeatballMenuIcon />
</Popover>
);

const data: RowData[] = [
{
id: 1,
name: {
content: 'Sam',
component: (
<a
href={'https://example.com/profile/sam'}
style={{ color: 'inherit', textDecoration: 'none' }}
>
Sam
</a>
),
},
age: 25,
city: 'New York',
},
{ name: 'Anna', age: 3, city: 'New York1', id: 2 },
{ name: 'Mike', age: 30, city: 'Los Angeles', config: { size: 'small' }, id: 3 },
];

const primaryColumn: Column = {
key: 'name',
header: 'Name',
};

const fixedColumns: FixedColumn[] = [
{
key: 'age',
header: 'Age',
order: 3,
align: 'right',
width: 100,
},
{
key: 'city',
header: 'City',
order: 2,
width: 150,
},
];

export const Default: Story = {
render: (args: TableComponentProps) => {
const defaultSortedData = sortTableData(data, {
key: primaryColumn.key,
direction: SortDirection.ASC,
});
// eslint-disable-next-line react-hooks/rules-of-hooks
const [tableData, setTableData] = useState(defaultSortedData);
return (
<div style={{ minWidth: '700px' }}>
<Table
{...args}
data={tableData}
onChangeSorting={(sortConfig) => {
const sortedData = sortTableData(tableData, sortConfig);
setTableData(sortedData);
}}
/>
</div>
);
},
args: {
primaryColumn,
fixedColumns,
rowActionMenu,
selectable: true,
},
};
Loading

0 comments on commit 6c4ec55

Please sign in to comment.