-
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.
- Loading branch information
vien.nguyen2-tiki
committed
Feb 6, 2023
1 parent
cd13473
commit b1966f4
Showing
28 changed files
with
3,156 additions
and
2,230 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,116 @@ | ||
import { Card, Table } from '@astraprotocol/astra-ui' | ||
import clsx from 'clsx' | ||
import Tabs from 'components/Tabs/Tabs' | ||
import { isObject, isString } from 'lodash' | ||
import styles from '../style.module.scss' | ||
|
||
type CardTabsProps = { | ||
tabTitles: string[] | ||
tabContent: any[] | ||
} | ||
|
||
export default function CardTabs({ tabTitles, tabContent }: CardTabsProps) { | ||
const _title = tabTitles.map(title => ({ title: title, id: title, padding: ' ' })) | ||
const _content = {} | ||
// console.log({ tabContent, tabTitles }) | ||
|
||
const _renderTable = (titles: string[], rowData: string[][]) => { | ||
const titleEl = titles.map(t => ({ | ||
key: t, | ||
content: <span className="text-md contrast-color-70">{t}</span>, | ||
render: val => <span className="contrast-color-70 text-sm">{val}</span> | ||
})) | ||
const rows = [] | ||
for (let row of rowData) { | ||
const rowData = {} | ||
for (let i = 0; i < row.length; i++) { | ||
rowData[titles[i]] = { content: row[i] } | ||
} | ||
rows.push(rowData) | ||
} | ||
|
||
return <Table classes={{ table: styles.tableTD }} id="param" colums={titleEl} rows={rows} /> | ||
} | ||
|
||
tabContent.map((content, idx) => { | ||
if (isString(content)) { | ||
// only string | ||
_content[tabTitles[idx]] = ( | ||
<span | ||
className={clsx(styles.rawInput, 'text text-sm contrast-color-70 padding-sm word-break-all')} | ||
style={{ display: 'block' }} | ||
> | ||
{content} | ||
</span> | ||
) | ||
} else if (isObject(content) && content['tableTitles']) { | ||
// table | ||
_content[tabTitles[idx]] = _renderTable(content['tableTitles'], content['tableContents']) | ||
} else if (isObject(content) && content['tabTitles']) { | ||
// table | ||
_content[tabTitles[idx]] = <CardTabs tabTitles={content['tabTitles']} tabContent={content['tabContent']} /> | ||
} else { | ||
// row | ||
const keys = Object.keys(content) | ||
const rows: JSX.Element[] = [] | ||
for (let key of keys) { | ||
if (isString(content[key])) { | ||
rows.push( | ||
<Card.Row | ||
left={{ content: key, wapperClasses: styles.left }} | ||
right={{ content: content[key], align: 'left' }} | ||
/> | ||
) | ||
} else if (isObject(content[key]) && content[key]['tableTitles']) { | ||
// table | ||
rows.push( | ||
<Card.Row | ||
left={{ content: key, wapperClasses: styles.left }} | ||
right={{ | ||
content: _renderTable(content[key]['tableTitles'], content[key]['tableContents']), | ||
align: 'left' | ||
}} | ||
/> | ||
) | ||
} else if (isObject(content[key]) && content[key]['tabTitles']) { | ||
// table | ||
rows.push( | ||
<Card.Row | ||
left={{ content: key, wapperClasses: styles.left }} | ||
right={{ | ||
content: ( | ||
<CardTabs | ||
tabTitles={content[key]['tabTitles']} | ||
tabContent={content[key]['tabContent']} | ||
/> | ||
), | ||
align: 'left' | ||
}} | ||
/> | ||
) | ||
} | ||
} | ||
_content[tabTitles[idx]] = ( | ||
<span | ||
className={clsx(styles.rawInput, 'text text-sm contrast-color-70 padding-sm word-break-all')} | ||
style={{ display: 'block' }} | ||
> | ||
{rows} | ||
</span> | ||
) | ||
} | ||
}) | ||
return ( | ||
<div> | ||
<div style={{ maxWidth: '10000px' }}> | ||
<Tabs | ||
tabs={_title} | ||
contents={_content} | ||
classes="padding-top-xs aaa" | ||
headerBorder={false} | ||
headerPadding="padding-left-sm flex-wrap" | ||
/> | ||
</div> | ||
</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
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
Oops, something went wrong.