-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve async components (#53)
* feat: added SkeletonText component Included some refactoring of older components * fix(skeleton): import react * feat(async-table): improve handling of async data * lint: fix warnings * lint: fix warnings * lint: fix warning Again... * feat(async-table): increase grid chunk size * feat(async-table): use rem for grid gaps
- Loading branch information
Showing
32 changed files
with
667 additions
and
141 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
1 change: 1 addition & 0 deletions
1
src/components/.storybook/HotswapContainer/HotswapContainer.tsx
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,51 @@ | ||
import React, { createElement, ReactNode } from 'react'; | ||
|
||
import { startCase, toLower } from 'lodash'; | ||
|
||
import classNames from 'classnames/bind'; | ||
import styles from './alignments.module.scss'; | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
export interface Column { | ||
id: string; // ID is required because header is optional | ||
header?: string; | ||
alignment: 'left' | 'right' | 'center'; | ||
className?: string; | ||
} | ||
|
||
interface ColumnProps { | ||
alignment: Column['alignment']; | ||
className?: string; | ||
children: ReactNode; | ||
} | ||
|
||
interface ColumnElementProps { | ||
element: 'th' | 'td'; | ||
} | ||
|
||
export const TableHeader = ({ children, ...props }: ColumnProps) => { | ||
return ( | ||
<ColumnElement element="th" {...props}> | ||
{children} | ||
</ColumnElement> | ||
); | ||
}; | ||
|
||
export const TableData = ({ children, ...props }: ColumnProps) => { | ||
return ( | ||
<ColumnElement element="td" {...props}> | ||
{children} | ||
</ColumnElement> | ||
); | ||
}; | ||
|
||
const ColumnElement = ({ alignment, element, className, children }: ColumnProps & ColumnElementProps) => { | ||
return createElement( | ||
element, | ||
{ | ||
className: classNames(cx(className, styles[startCase(toLower(alignment))])) | ||
}, | ||
children | ||
); | ||
}; |
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,19 @@ | ||
import React, { memo, ReactNode } from 'react'; | ||
|
||
import { GridPlaceholders } from './Placeholder'; | ||
|
||
import styles from './AsyncTable.module.scss'; | ||
|
||
interface GridProps { | ||
cards: ReactNode; | ||
isSingleColumnGrid: boolean; | ||
} | ||
|
||
export const Grid = memo(({ cards, isSingleColumnGrid }: GridProps) => { | ||
return ( | ||
<div className={styles.Grid}> | ||
{cards} | ||
{!isSingleColumnGrid && <GridPlaceholders amount={3} />} | ||
</div> | ||
); | ||
}); |
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,45 @@ | ||
import { TableData, TableHeader } from './Column'; | ||
import Skeleton from 'react-loading-skeleton'; | ||
import React from 'react'; | ||
|
||
interface HeaderPlaceholdersProps { | ||
amount: number; | ||
} | ||
|
||
export const HeaderPlaceholders = ({ amount }: HeaderPlaceholdersProps) => { | ||
const columnPlaceholder = ( | ||
<TableHeader alignment={'center'}> | ||
<Skeleton width={'100%'} /> | ||
</TableHeader> | ||
); | ||
|
||
return <>{Array(amount).fill(columnPlaceholder)}</>; | ||
}; | ||
|
||
interface RowPlaceholdersProps { | ||
amount: number; | ||
height: number; | ||
numColumns: number; | ||
} | ||
|
||
export const RowPlaceholders = ({ amount, height, numColumns }: RowPlaceholdersProps) => { | ||
const columnPlaceholder = ( | ||
<TableData alignment={'center'}> | ||
<Skeleton width={'100%'} height={height} /> | ||
</TableData> | ||
); | ||
|
||
const columns = Array(numColumns).fill(columnPlaceholder); | ||
const rows = Array(amount).fill(<tr>{columns}</tr>); | ||
return <>{rows}</>; | ||
}; | ||
|
||
interface GridPlaceholdersProps { | ||
amount: number; | ||
} | ||
|
||
export const GridPlaceholders = ({ amount }: GridPlaceholdersProps) => { | ||
const placeholders = Array(amount).fill(<div />); | ||
|
||
return <>{placeholders}</>; | ||
}; |
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,31 @@ | ||
import React, { memo, ReactNode } from 'react'; | ||
|
||
import { Column, TableHeader } from './Column'; | ||
import { HeaderPlaceholders, RowPlaceholders } from './Placeholder'; | ||
|
||
import styles from './AsyncTable.module.scss'; | ||
|
||
interface TableProps { | ||
columns: Column[]; | ||
rows: ReactNode; | ||
isLoading: boolean; | ||
} | ||
|
||
export const Table = memo(({ columns, rows, isLoading }: TableProps) => ( | ||
<table className={styles.Table}> | ||
<thead> | ||
<tr> | ||
{isLoading ? ( | ||
<HeaderPlaceholders amount={columns.length} /> | ||
) : ( | ||
columns.map((c: Column) => ( | ||
<TableHeader alignment={c.alignment} key={c.id}> | ||
{c.header} | ||
</TableHeader> | ||
)) | ||
)} | ||
</tr> | ||
</thead> | ||
<tbody>{isLoading ? <RowPlaceholders amount={5} height={40} numColumns={columns.length} /> : rows}</tbody> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './AsyncTable'; | ||
export { TableData, TableHeader, Column } from './Column'; |
Oops, something went wrong.