Skip to content

Commit

Permalink
feat: add more styles
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasdano committed May 16, 2024
1 parent 01a5314 commit 1b7ca11
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
47 changes: 32 additions & 15 deletions src/__storyshots__/Updated Components/Table/Table-RowSelection.snap
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@
opacity: 1;
}

.emotion-49 {
cursor: pointer;
}

.emotion-49:hover {
background: rgba(200,206,255,0.20);
}

.emotion-50 {
width: 52px;
height: 2.75rem;
Expand Down Expand Up @@ -451,6 +459,15 @@
align-content: center;
}

.emotion-64 {
cursor: pointer;
background: rgba(200,206,255,0.30);
}

.emotion-64:hover {
background: rgba(200,206,255,0.20);
}

<div>
<div
class="emotion-0"
Expand Down Expand Up @@ -715,7 +732,7 @@
class="emotion-48"
>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -802,7 +819,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-64"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -891,7 +908,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -978,7 +995,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1065,7 +1082,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1152,7 +1169,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-64"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1241,7 +1258,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1328,7 +1345,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-64"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1417,7 +1434,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1504,7 +1521,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1591,7 +1608,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1678,7 +1695,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1765,7 +1782,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1852,7 +1869,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down Expand Up @@ -1939,7 +1956,7 @@
</td>
</tr>
<tr
class="emotion-28"
class="emotion-49"
>
<td
class="emotion-50"
Expand Down
14 changes: 13 additions & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const Table = <TData,>({
/** If true, the scrollbar of tbody is visible */
const [hasScrollbar, setHasScrollbar] = React.useState(false);

const isSelectable = Boolean(type === 'interactive' && rowsConfig.rowSelection);

const tBodyRef = useRef<HTMLTableSectionElement>();
const containerRef = useRef(null);

Expand Down Expand Up @@ -82,7 +84,17 @@ const Table = <TData,>({
<TBody hasStickyHeader={hasStickyHeader} ref={tBodyRef} sx={sx?.tbody}>
{table.getRowModel().rows.map((row) => {
return (
<TR key={row.id} sx={sx?.tr}>
<TR
key={row.id}
sx={sx?.tr}
{...(isSelectable && {
isSelectable,
isSelected: row.getIsSelected(),
onClick: (e) => {
row.toggleSelected();
},
})}
>
{row.getVisibleCells().map((cell) => {
return (
<TD
Expand Down
19 changes: 17 additions & 2 deletions src/components/Table/components/TR/TR.style.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { css, type SerializedStyles } from '@emotion/react';
import type { Theme } from 'theme';

import type { TRProps } from './TR';

export const trContainer =
({ sx }: Pick<TRProps, 'sx'>) =>
(): SerializedStyles => {
({ isSelected, isSelectable, sx }: Pick<TRProps, 'sx' | 'isSelectable' | 'isSelected'>) =>
(theme: Theme): SerializedStyles => {
return css`
${isSelectable &&
`
cursor: pointer;
&:hover {
background: ${theme.tokens.colors.get('palette.tertiary.muted')};
}
`}
${isSelected &&
`
background: ${theme.tokens.colors.get('palette.tertiary.contrast')};
`}
${sx};
`;
};
19 changes: 17 additions & 2 deletions src/components/Table/components/TR/TR.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import type { CSSObject } from '@emotion/react';
import React from 'react';
import isEqual from 'react-fast-compare';
import type { DivProps } from 'utils/common';

import { trContainer } from './TR.style';

export type TRProps = {
/** Whether the row is selected */
isSelected?: boolean;
/** Whether the row is selectable */
isSelectable?: boolean;
/** Style overrides */
sx?: CSSObject;
};

const TR: React.FCC<TRProps> = ({ sx, children }) => {
return <tr css={trContainer({ sx })}>{children}</tr>;
const TR: React.FCC<TRProps & Pick<DivProps, 'onClick'>> = ({
onClick,
isSelected,
isSelectable,
sx,
children,
}) => {
return (
<tr onClick={onClick} css={trContainer({ isSelected, isSelectable, sx })}>
{children}
</tr>
);
};

export default React.memo(TR, isEqual);

0 comments on commit 1b7ca11

Please sign in to comment.