-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tables): add $isLoading prop to SimpleTable.Td
- add `$isLoading` prop to `SimpleTable.Td (& `TableWithSelectableRows.Td`) - add `$width` prop to `SimpleTable.Th` (& `TableWithSelectableRows.Th`) - add & expose `SimpleTable.CellLoader` (& `TableWithSelectableRows.CellLoader`) - fix ellipsis when `SimpleTable.Th` width is set while not set in `SimpleTable.Td` (// `TableWithSelectableRows`) - deprecate `$width` prop from `TableWithSelectableRows.Td`
- Loading branch information
1 parent
f655623
commit 6cc137e
Showing
11 changed files
with
177 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import styled, { keyframes } from 'styled-components' | ||
|
||
const cellLoaderAnimation = keyframes` | ||
from { | ||
left: -100%; | ||
} | ||
to { | ||
left: 100%; | ||
} | ||
` | ||
export const CellLoader = styled.div` | ||
background: ${p => p.theme.color.gainsboro}; | ||
height: 18px; | ||
overflow: hidden; | ||
position: relative; | ||
&:before { | ||
animation: ${cellLoaderAnimation} 1s cubic-bezier(0.4, 0, 0.2, 1) infinite; | ||
background: linear-gradient(to right, transparent 0%, ${p => p.theme.color.white} 50%, transparent 100%); | ||
content: ''; | ||
display: block; | ||
height: 100%; | ||
left: -100%; | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import styled from 'styled-components' | ||
|
||
import { CellLoader } from './CellLoader' | ||
|
||
import type { TdHTMLAttributes } from 'react' | ||
|
||
type TdProps = TdHTMLAttributes<HTMLTableCellElement> & { | ||
$isCenter?: boolean | undefined | ||
$isLoading?: boolean | undefined | ||
} | ||
export const Td = styled.td.attrs<TdProps, TdProps>(props => ({ | ||
children: props.$isLoading ? <CellLoader /> : props.children | ||
}))` | ||
border-bottom: 1px solid ${p => p.theme.color.lightGray}; | ||
border-right: 1px solid ${p => p.theme.color.lightGray}; | ||
color: ${p => p.theme.color.gunMetal}; | ||
font-size: 13px; | ||
font-weight: 500; | ||
max-width: 0; | ||
overflow: hidden; | ||
padding: 10px; | ||
text-align: ${p => (p.$isCenter ? 'center' : 'left')}; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ky from 'ky' | ||
import { useEffect, useState } from 'react' | ||
|
||
import { META_DEFAULTS } from '../../../.storybook/constants' | ||
import { generateStoryDecorator } from '../../../.storybook/utils/generateStoryDecorator' | ||
import { SimpleTable } from '../../../src' | ||
|
||
import type { Meta } from '@storybook/react' | ||
|
||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
const meta: Meta<{}> = { | ||
...META_DEFAULTS, | ||
|
||
title: 'Tables/SimpleTable (variations)', | ||
|
||
decorators: [ | ||
generateStoryDecorator({ | ||
withBackgroundButton: true | ||
}) | ||
] | ||
} | ||
/* eslint-enable sort-keys-fix/sort-keys-fix */ | ||
|
||
export default meta | ||
|
||
export function WithLoader() { | ||
const [data, setData] = useState<any[] | undefined>(undefined) | ||
|
||
const emptyRows = new Array(10).fill(undefined) | ||
const isLoading = !data | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(async () => { | ||
const nextData: any = await ky.get('https://api.openbrewerydb.org/v1/breweries?per_page=10').json() | ||
|
||
setData(nextData) | ||
}, 5000) | ||
|
||
return () => clearTimeout(timer) | ||
}, []) | ||
|
||
return ( | ||
<SimpleTable.Table> | ||
<SimpleTable.Head> | ||
<SimpleTable.Th $width={48}>ID</SimpleTable.Th> | ||
<SimpleTable.Th $width={240}>Name</SimpleTable.Th> | ||
<SimpleTable.Th $width={480}>Address</SimpleTable.Th> | ||
</SimpleTable.Head> | ||
<tbody> | ||
{isLoading && | ||
emptyRows.map((_, index) => ( | ||
// eslint-disable-next-line react/no-array-index-key | ||
<SimpleTable.BodyTr key={`row-${index}`}> | ||
<SimpleTable.Td $isLoading /> | ||
<SimpleTable.Td $isLoading /> | ||
<SimpleTable.Td $isLoading /> | ||
</SimpleTable.BodyTr> | ||
))} | ||
{!isLoading && | ||
data?.map(brewery => ( | ||
<SimpleTable.BodyTr key={brewery.id}> | ||
<SimpleTable.Td>{brewery.id}</SimpleTable.Td> | ||
<SimpleTable.Td>{brewery.name}</SimpleTable.Td> | ||
<SimpleTable.Td>{`${brewery.street}, ${brewery.city} ${brewery.postalCode}, ${brewery.state}`}</SimpleTable.Td> | ||
</SimpleTable.BodyTr> | ||
))} | ||
</tbody> | ||
</SimpleTable.Table> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters