forked from tari-project/tari
-
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.
Improve Tabs component and its usage in DashboardContainer
- Loading branch information
1 parent
21e3070
commit 2cc40a9
Showing
6 changed files
with
213 additions
and
50 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
applications/launchpad_v2/src/components/Tabs/Tabs.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { act, render, screen } from '@testing-library/react' | ||
import { ThemeProvider } from 'styled-components' | ||
|
||
import themes from '../../styles/themes' | ||
import Tabs from './' | ||
|
||
const tabs = [ | ||
{ | ||
id: 'first-tab', | ||
content: <span>First tab</span>, | ||
}, | ||
{ | ||
id: 'second-tab', | ||
content: <span>Second tab</span>, | ||
}, | ||
] | ||
|
||
describe('Tabs', () => { | ||
it('should render without crashing', async () => { | ||
const selected = 'second-tab' | ||
const onSelect = jest.fn() | ||
|
||
await act(async () => { | ||
render( | ||
<ThemeProvider theme={themes.light}> | ||
<Tabs tabs={tabs} selected={selected} onSelect={onSelect} /> | ||
</ThemeProvider>, | ||
) | ||
}) | ||
|
||
const firstTabText = screen.queryAllByText('First tab') | ||
expect(firstTabText.length).toBeGreaterThan(0) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,31 +1,53 @@ | ||
import { animated } from 'react-spring' | ||
import styled from 'styled-components' | ||
|
||
export const TabsContainer = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
flex-direction: column; | ||
position: relative; | ||
` | ||
|
||
export const Tab = styled.div<{ selected?: boolean }>` | ||
export const TabOptions = styled.div` | ||
display: flex; | ||
padding: 12px; | ||
border-bottom: ${({ selected }) => | ||
selected ? '4px solid #9330FF' : '4px solid #fff'}; | ||
align-items: center; | ||
` | ||
|
||
export const TabOptions = styled.div` | ||
export const Tab = styled.button` | ||
display: flex; | ||
align-items: center; | ||
padding: 8px 12px; | ||
box-shadow: none; | ||
border-width: 0px; | ||
border-bottom: 4px solid transparent; | ||
background: transparent; | ||
box-sizing: border-box; | ||
margin: 0px; | ||
position: relative; | ||
cursor: pointer; | ||
` | ||
|
||
export const TabsBorder = styled.div` | ||
export const TabSelectedBorder = styled(animated.div)` | ||
position: absolute; | ||
height: 4px; | ||
background: red; | ||
width: 100%; | ||
border-radius: 2px; | ||
background: ${({ theme }) => theme.accent}; | ||
bottom: 0; | ||
` | ||
|
||
export const TabBorderSelection = styled.div` | ||
height: 100%; | ||
background: blue; | ||
width: 50px; | ||
export const FontWeightCompensation = styled.div` | ||
visibility: hidden; | ||
& > p { | ||
margin: 0; | ||
} | ||
` | ||
|
||
export const TabContent = styled.div<{ selected?: boolean }>` | ||
position: absolute; | ||
top: 12px; | ||
left: 12px; | ||
& > p { | ||
margin: 0; | ||
} | ||
` |
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,10 +1,12 @@ | ||
import { ReactNode } from 'react' | ||
|
||
export interface TabProp { | ||
id: string | ||
content: ReactNode | ||
} | ||
|
||
export interface TabsProps { | ||
tabs: { | ||
id: string | ||
content: ReactNode | ||
}[] | ||
tabs: TabProp[] | ||
selected: string | ||
onSelect: (id: string) => void | ||
} |
47 changes: 47 additions & 0 deletions
47
...unchpad_v2/src/containers/Dashboard/DashboardContainer/components/DashboardTabs/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import Tabs from '../../../../../components/Tabs' | ||
|
||
import { setPage } from '../../../../../store/app' | ||
import { ViewType } from '../../../../../store/app/types' | ||
import { selectView } from '../../../../../store/app/selectors' | ||
import { useEffect, useState } from 'react' | ||
|
||
/** | ||
* Renders Dasboard tabs | ||
*/ | ||
const DashboardTabs = () => { | ||
const dispatch = useDispatch() | ||
|
||
const currentPage = useSelector(selectView) | ||
|
||
const [tabs, setTabs] = useState([ | ||
{ | ||
id: 'MINING', | ||
content: <span>Mining</span>, | ||
}, | ||
{ | ||
id: 'BASE_NODE', | ||
content: <span>Base Node</span>, | ||
}, | ||
{ | ||
id: 'WALLET', | ||
content: <span>Wallet</span>, | ||
}, | ||
]) | ||
|
||
// useEffect(() => {}, []) | ||
|
||
const setPageTab = (tabId: string) => { | ||
dispatch(setPage(tabId as ViewType)) | ||
} | ||
|
||
return ( | ||
<Tabs | ||
tabs={tabs} | ||
selected={currentPage || 'MINING'} | ||
onSelect={setPageTab} | ||
/> | ||
) | ||
} | ||
|
||
export default DashboardTabs |
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