This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
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
1 parent
50cb3e8
commit af13732
Showing
6 changed files
with
186 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import Tabs from 'components/common/Tabs/Tabs' | ||
|
||
export interface TabItemType { | ||
readonly id: number | ||
title: string | ||
content: string | ||
readonly activeColor?: string | ||
} | ||
|
||
// pass string props to indicate what content/component to show | ||
|
||
const tabItems: TabItemType[] = [ | ||
{ | ||
id: 1, | ||
title: 'BUY', | ||
content: '- buy component -', | ||
activeColor: '--color-buy', | ||
}, | ||
{ | ||
id: 2, | ||
title: 'SELL', | ||
content: '- sell component -', | ||
activeColor: '--color-sell', | ||
}, | ||
] | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
width: 100%; | ||
padding: var(--padding-container-default); | ||
` | ||
|
||
export const OrderBuySell: React.FC = () => ( | ||
<Wrapper> | ||
<Tabs tabItems={tabItems} /> | ||
</Wrapper> | ||
) | ||
|
||
export default OrderBuySell |
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,20 @@ | ||
import React from 'react' | ||
import { TabItemType } from 'components/OrderBuySell' | ||
|
||
type Props = { | ||
tabItems: TabItemType[] | ||
activeTab: number | ||
} | ||
|
||
const TabContent: React.FC<Props> = (props) => { | ||
const { tabItems, activeTab } = props | ||
return ( | ||
<div> | ||
{tabItems.map((tab) => { | ||
return tab.id === activeTab ? tab.content : '' | ||
})} | ||
</div> | ||
) | ||
} | ||
|
||
export default TabContent |
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,56 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
interface TabProps { | ||
title: string | ||
readonly id: number | ||
readonly isActive: boolean | ||
readonly activeColor?: string | ||
onTabClick: (arg: number) => void | ||
} | ||
|
||
interface WrapperProps { | ||
readonly activeColor?: string | ||
} | ||
|
||
const Wrapper = styled.li<WrapperProps>` | ||
background: var(--color-primary); | ||
color: var(--color-text-secondary2); | ||
height: var(--height-button-default); | ||
display: flex; | ||
align-items: center; | ||
flex: 1 1 0; | ||
font-weight: var(--font-weight-bold); | ||
font-size: var(--font-size-large); | ||
letter-spacing: 0.1rem; | ||
text-align: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
&:first-of-type { | ||
border-top-left-radius: var(--border-radius-default); | ||
border-bottom-left-radius: var(--border-radius-default); | ||
} | ||
&:last-of-type { | ||
border-top-right-radius: var(--border-radius-default); | ||
border-bottom-right-radius: var(--border-radius-default); | ||
} | ||
&.isActive { | ||
background: ${(props): string => (props.activeColor ? `var(${props.activeColor})` : 'var(--color-primary)')}; | ||
color: var(--color-text-primary); | ||
} | ||
` | ||
|
||
const TabItem: React.FC<TabProps> = (props) => { | ||
const { onTabClick, id, title, isActive, activeColor } = props | ||
|
||
return ( | ||
<Wrapper activeColor={activeColor} className={isActive ? 'isActive' : ''} onClick={(): void => onTabClick(id)}> | ||
{title} | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export default TabItem |
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,54 @@ | ||
import React, { useState } from 'react' | ||
import styled from 'styled-components' | ||
|
||
// Components | ||
import { TabItemType } from 'components/OrderBuySell' | ||
import TabItem from 'components/common/Tabs/TabItem' | ||
import TabContent from 'components/common/Tabs/TabContent' | ||
|
||
interface Props { | ||
tabItems: TabItemType[] | ||
} | ||
|
||
const Tabs: React.FC<Props> = (props) => { | ||
const [activeTab, setActiveTab] = useState<number>(1) | ||
|
||
const onTabClick = (id: number): void => { | ||
return setActiveTab(id) | ||
} | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-flow: column; | ||
width: 100%; | ||
> ul { | ||
list-style: none; | ||
display: flex; | ||
flex-flow: row nowrap; | ||
padding: 0; | ||
justify-content: space-between; | ||
width: 100%; | ||
} | ||
` | ||
|
||
return ( | ||
<Wrapper> | ||
<ul> | ||
{props.tabItems.map(({ id, title, activeColor }) => ( | ||
<TabItem | ||
key={id} | ||
id={id} | ||
title={title} | ||
onTabClick={(): void => onTabClick(id)} | ||
isActive={activeTab === id} | ||
activeColor={activeColor} | ||
/> | ||
))} | ||
</ul> | ||
<TabContent tabItems={props.tabItems} activeTab={activeTab} /> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export default Tabs |
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