Skip to content

Commit

Permalink
feat: added generic tab component
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienne-deriv committed Sep 14, 2023
1 parent 6f946bd commit ab0ab57
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/components/src/components/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ import './common/ic-boleto-d24-voucher-light.svg';
import './common/ic-bot-builder-arrow.svg';
import './common/ic-bot-builder-tab-icon.svg';
import './common/ic-bot-builder.svg';
import './common/ic-bot-stop.svg';
import './common/ic-box.svg';
import './common/ic-button-back.svg';
import './common/ic-calendar-datefrom.svg';
Expand Down
1 change: 1 addition & 0 deletions packages/components/stories/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const icons =
'IcBotBuilderArrow',
'IcBotBuilderTabIcon',
'IcBotBuilder',
'IcBotStop',
'IcBox',
'IcButtonBack',
'IcCalendarDatefrom',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
border-radius: 0 0 16px 16px;
}

@include mobile {
margin: auto 1.8rem;
width: auto;
height: auto;
}

&__content {
margin-top: 24px;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/wallets/src/components/AccountsList/AccountsList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import React from 'react';
import useDevice from '../../hooks/useDevice';
import { TabList, TabPanel, TabPanels, Tabs } from '../Tabs';
import { OptionsAndMultipliersListing } from '..';
import './AccountsList.scss';

const AccountsList = () => {
const { is_mobile } = useDevice();

if (is_mobile) {
return (
<Tabs className='wallets-accounts-list'>
<TabList list={['CFDs', 'Options & multipliers']} />
<TabPanels>
<TabPanel>
<h1>CFDs</h1>
</TabPanel>
<TabPanel>
<OptionsAndMultipliersListing />
</TabPanel>
</TabPanels>
</Tabs>
);
}

return (
<div className='wallets-accounts-list'>
<div className='wallets-accounts-list__content'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
height: 100%;
padding-top: 24px;

@include mobile {
padding-top: unset;
height: calc(100vh - 400px);
overflow-y: auto;
}

@include desktop {
border-top: 2px solid var(--system-light-7-secondary-background, #f2f3f4);
}

&__header {
padding-bottom: 24px;

@include mobile {
display: flex;
flex-direction: column;
justify-content: center;
margin: auto 1.8rem;
}

&-title {
font-weight: bold;
font-size: 24px;
Expand All @@ -32,5 +45,11 @@
display: grid;
gap: 1.6rem 4.8rem;
grid-template-columns: repeat(3, 1fr);

@include mobile {
margin: auto 2rem;
grid-template-rows: repeat(5, 1fr);
grid-template-columns: auto;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { Localize } from '@deriv/translations';
import useDevice from '../../hooks/useDevice';
import IcAppstoreBinaryBot from '../../public/images/ic-appstore-binary-bot.svg';
import IcAppstoreDerivBot from '../../public/images/ic-appstore-deriv-bot.svg';
import IcAppstoreDerivGo from '../../public/images/ic-appstore-deriv-go.svg';
import IcAppstoreDerivTrader from '../../public/images/ic-appstore-deriv-trader.svg';
import IcAppstoreSmartTrader from '../../public/images/ic-appstore-smart-trader.svg';
import { TabList, TabPanel, TabPanels, Tabs } from '../Tabs';
import { TradingAccountCard } from '..';
import './OptionsAndMultipliersListing.scss';

Expand Down Expand Up @@ -37,12 +39,16 @@ const options_and_multipliers = [
];

const OptionsAndMultipliersListing = () => {
const { is_mobile } = useDevice();

return (
<div className='wallets-options-and-multipliers-listing'>
<section className='wallets-options-and-multipliers-listing__header'>
<div className='wallets-options-and-multipliers-listing__header-title'>
<Localize i18n_default_text='Options & Multipliers' />
</div>
{!is_mobile && (
<div className='wallets-options-and-multipliers-listing__header-title'>
<Localize i18n_default_text='Options & Multipliers' />
</div>
)}
<div className='wallets-options-and-multipliers-listing__header-subtitle'>
<Localize
i18n_default_text='Earn a range of payouts by correctly predicting market price movements with <0>options</0>, or get the
Expand Down
30 changes: 30 additions & 0 deletions packages/wallets/src/components/Tabs/TabList.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.wallets-tabs {
&-list {
display: grid;
grid-auto-columns: 1fr;
position: relative;
background-color: #f2f3f4;
height: 5rem;
margin: 2rem;
border-radius: 7px;

&-item {
grid-row: 1;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;

&--active {
font-weight: var(--text-weight-bold);
background-color: var(--general-main-1);
margin: 0.6rem;
border-radius: 5px;
}

&--disabled {
color: var(--text-disabled);
}
}
}
}
31 changes: 31 additions & 0 deletions packages/wallets/src/components/Tabs/TabList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { useTabs } from './Tabs';
import './TabList.scss';

type TTabListProps = {
list: string[];
text_size: string;
};

export const TabList = ({ list, text_size = 's' }: TTabListProps) => {
const { active_tab_index, setActiveTabIndex } = useTabs();

return (
<div className='wallets-tabs-list' data-list-count={list.length}>
{list.map((tab, i) => (
<div
className={`wallets-tabs-list-item wallets-tabs-list-item--${
i === active_tab_index ? 'active' : 'disabled'
}`}
key={i}
onClick={() => setActiveTabIndex(i)}
style={{
fontSize: `var(--text-size-${text_size})`,
}}
>
{tab}
</div>
))}
</div>
);
};
7 changes: 7 additions & 0 deletions packages/wallets/src/components/Tabs/TabPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const TabPanel = ({ children }: React.PropsWithChildren<unknown>) => {
return <div>{children}</div>;
};

export default TabPanel;
18 changes: 18 additions & 0 deletions packages/wallets/src/components/Tabs/TabPanels.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { useTabs } from './Tabs';

const TabPanels = ({ children }: React.PropsWithChildren<unknown>) => {
const { active_tab_index } = useTabs();

return (
<div>
{React.Children.map(children, (child, index) => {
if (index !== active_tab_index) return undefined;

return child;
})}
</div>
);
};

export default TabPanels;
35 changes: 35 additions & 0 deletions packages/wallets/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
// import classNames from 'classnames';

type TTabContext = {
active_tab_index: number;
setActiveTabIndex: React.Dispatch<React.SetStateAction<number>>;
};

const TabsContext = React.createContext<TTabContext | null>(null);

export const useTabs = () => {
const context = React.useContext(TabsContext);

if (!context) {
throw new Error('Seems you forgot to wrap the components in "<Tabs />"');
}

return context;
};

type TTabsProps = {
className?: string;
};

export const Tabs = ({ children, className }: React.PropsWithChildren<TTabsProps>) => {
const [active_tab_index, setActiveTabIndex] = React.useState(0);

return (
<TabsContext.Provider value={{ active_tab_index, setActiveTabIndex }}>
<div className={className}>{children}</div>
</TabsContext.Provider>
);
};

export default Tabs;
6 changes: 6 additions & 0 deletions packages/wallets/src/components/Tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TabList } from './TabList';
import TabPanel from './TabPanel';
import TabPanels from './TabPanels';
import Tabs from './Tabs';

export { TabList, TabPanel, TabPanels, Tabs };
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
$columns: 3;
$grid-last-row-children: '&:nth-child(#{$columns}n+1):nth-last-child(-n+#{$columns})';

.wallets-trading-account-card {
display: flex;
align-items: center;
gap: 16px;
height: 88px;

#{$grid-last-row-children} > &__content,
#{$grid-last-row-children} ~ & > &__content {
border-bottom: none;
@include desktop {
$columns: 3;
$grid-last-row-children: '&:nth-child(#{$columns}n+1):nth-last-child(-n+#{$columns})';
#{$grid-last-row-children} > &__content,
#{$grid-last-row-children} ~ & > &__content {
border-bottom: none;
}
}

@include mobile {
$columns: 1;
$grid-last-row-children: '&:nth-child(#{$columns}n+1):nth-last-child(-n+#{$columns})';
#{$grid-last-row-children} > &__content,
#{$grid-last-row-children} ~ & > &__content {
border-bottom: none;
}
}

&__content {
Expand Down Expand Up @@ -38,6 +48,11 @@ $grid-last-row-children: '&:nth-child(#{$columns}n+1):nth-last-child(-n+#{$colum
&-description {
font-size: 1.2rem;
line-height: 14px;

@include mobile {
font-size: 1.4rem;
line-height: 20px;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactElement } from 'react';
import { Localize } from '@deriv/translations';
import useDevice from '../../hooks/useDevice';
import './TradingAccountCard.scss';

type TProps = {
Expand All @@ -9,6 +10,8 @@ type TProps = {
};

const TradingAccountCard: React.FC<TProps> = ({ description, icon, title }) => {
const { is_mobile } = useDevice();

return (
<div className='wallets-trading-account-card'>
{icon}
Expand All @@ -21,11 +24,13 @@ const TradingAccountCard: React.FC<TProps> = ({ description, icon, title }) => {
<Localize i18n_default_text={description} />
</p>
</div>
<div className='wallets-trading-account-card__actions'>
<button className='wallets-trading-account-card__action'>
<Localize i18n_default_text='Open' />
</button>
</div>
{!is_mobile && (
<div className='wallets-trading-account-card__actions'>
<button className='wallets-trading-account-card__action'>
<Localize i18n_default_text='Open' />
</button>
</div>
)}
</div>
</div>
);
Expand Down

0 comments on commit ab0ab57

Please sign in to comment.