forked from digidem/mapeo-desktop
-
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.
add SettingsMenu tabs component (WIP)
- Loading branch information
Showing
5 changed files
with
153 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
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,6 @@ | ||
import React from 'react' | ||
import Paper from '@material-ui/core/Paper' | ||
|
||
export const AboutMapeoMenu = () => { | ||
return <Paper></Paper> | ||
} |
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,101 @@ | ||
import * as React from 'react' | ||
import Tabs from '@material-ui/core/Tabs' | ||
import Tab from '@material-ui/core/Tab' | ||
import { useIntl } from 'react-intl' | ||
import styled from 'styled-components' | ||
import { Paper, Typography } from '@material-ui/core' | ||
|
||
export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { | ||
const { formatMessage: t } = useIntl() | ||
|
||
return ( | ||
<Tabs | ||
orientation='vertical' | ||
value={currentTab} | ||
onChange={(e, newValue) => onTabChange(newValue)} | ||
style={{ | ||
maxWidth: '300px' | ||
}} | ||
> | ||
{tabs.map((tab, index) => ( | ||
<Tab | ||
orientation='vertical' | ||
key={tab.tabId} | ||
value={tab.tabId} | ||
component={RenderTab} | ||
tab={tab} | ||
active={tab.tabId === currentTab} | ||
/> | ||
))} | ||
</Tabs> | ||
) | ||
} | ||
|
||
const RenderTab = ({ | ||
tab: { icon: Icon, label, subtitle }, | ||
active, | ||
...rest | ||
}) => { | ||
const { formatMessage: t } = useIntl() | ||
|
||
console.log({ active, rest }) | ||
|
||
return ( | ||
<Paper {...rest}> | ||
<WrapperRow> | ||
<IconContainer>{Icon ? <Icon /> : null}</IconContainer> | ||
<TitleContainer> | ||
<Typography | ||
variant='body1' | ||
component='label' | ||
style={{ | ||
textTransform: 'none', | ||
textAlign: 'left', | ||
cursor: 'pointer' | ||
}} | ||
> | ||
{t(label)} | ||
</Typography> | ||
<Typography | ||
variant='caption' | ||
component='label' | ||
style={{ | ||
textTransform: 'none', | ||
textAlign: 'left', | ||
cursor: 'pointer' | ||
}} | ||
> | ||
{subtitle} | ||
</Typography> | ||
</TitleContainer> | ||
</WrapperRow> | ||
</Paper> | ||
) | ||
} | ||
|
||
const Row = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
` | ||
|
||
const Column = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
const WrapperRow = styled(Row)` | ||
padding: 10px; | ||
align-items: center; | ||
` | ||
|
||
const IconContainer = styled.div` | ||
flex: 1; | ||
padding: 10px; | ||
display: flex; | ||
align-items: center; | ||
` | ||
|
||
const TitleContainer = styled(Column)` | ||
justify-content: flex-start; | ||
flex: 8; | ||
` |
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, { useState } from 'react' | ||
import Paper from '@material-ui/core/Paper' | ||
import InfoIcon from '@material-ui/icons/Info' | ||
import { SettingsMenu } from './SettingsMenu' | ||
import { defineMessages } from 'react-intl' | ||
import { AboutMapeoMenu } from './AboutMapeo' | ||
|
||
const m = defineMessages({ | ||
aboutMapeo: 'About Mapeo' | ||
}) | ||
|
||
const tabs = /** @typedef {const} */ [ | ||
{ | ||
tabId: 'AboutMapeo', | ||
icon: InfoIcon, | ||
label: m.aboutMapeo, | ||
subtitle: 'Version and build number' | ||
} | ||
] | ||
|
||
export const SettingsView = () => { | ||
const [menuItem, setMenuItem] = useState(null) | ||
|
||
console.log({ menuItem }) | ||
|
||
return ( | ||
<div> | ||
<SettingsMenu | ||
tabs={tabs} | ||
currentTab={menuItem} | ||
onTabChange={setMenuItem} | ||
/> | ||
|
||
{menuItem === 'AboutMapeo' && ( | ||
<Paper> | ||
<AboutMapeoMenu /> | ||
</Paper> | ||
)} | ||
</div> | ||
) | ||
} |