-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ej/zustand-store
- Loading branch information
Showing
5 changed files
with
268 additions
and
9 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,57 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { Box, Typography, useTheme } from '@material-ui/core' | ||
import { defineMessages, useIntl } from 'react-intl' | ||
import buildConfig from '../../../build-config' | ||
|
||
const m = defineMessages({ | ||
mapeoVersion: 'Mapeo Version', | ||
mapeoVariant: 'Mapeo Variant', | ||
}) | ||
|
||
export const AboutMapeoMenu = () => { | ||
const { formatMessage: t } = useIntl() | ||
return ( | ||
<Container> | ||
<KeyValuePair label={t(m.mapeoVersion)} value={buildConfig.version}></KeyValuePair> | ||
<KeyValuePair label={t(m.mapeoVariant)} value={buildConfig.variant}></KeyValuePair> | ||
</Container> | ||
) | ||
} | ||
|
||
/** | ||
* @typedef KeyValuePairProps | ||
* @prop {string} label | ||
* @prop {string} value | ||
*/ | ||
|
||
/** @param {KeyValuePairProps} props */ | ||
const KeyValuePair = ({ label, value }) => { | ||
const theme = useTheme() | ||
return ( | ||
<Column> | ||
<Typography variant='body1' component='label' style={{ fontWeight: 500 }}> | ||
{label} | ||
</Typography> | ||
<Typography variant='caption' component='label' style={{ color: theme.palette.grey['700'] }}> | ||
{value} | ||
</Typography> | ||
</Column> | ||
) | ||
} | ||
const Container = styled(Box)` | ||
width: 100%; | ||
background-color: #fff; | ||
padding: 1.2em 1em 1em 2em; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
&.MuiPaper-rounded { | ||
border-radius: 0; | ||
} | ||
` | ||
const Column = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.1em; | ||
` |
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,138 @@ | ||
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 ChevronRightIcon from '@material-ui/icons/ChevronRight' | ||
import styled from 'styled-components' | ||
import { Paper, Typography, useTheme } from '@material-ui/core' | ||
|
||
/** @typedef {'AboutMapeo'} tabId */ | ||
|
||
/** | ||
* @typedef {object} tab | ||
* @prop {tabId} tab.tabId | ||
* @prop {string | import('react-intl').MessageDescriptor} tab.label | ||
* @prop {string | import('react-intl').MessageDescriptor} tab.subtitle | ||
* @prop {import('@material-ui/core/OverridableComponent').OverridableComponent<import('@material-ui/core').SvgIconTypeMap<{}, "svg">>} tab.icon | ||
* @typedef SettingsMenuProps | ||
* @prop {tab[]} tabs | ||
* @prop {number} currentTab | ||
* @prop {(e: React.Dispatch<number>) => number} onTabChange | ||
*/ | ||
|
||
/** @param {SettingsMenuProps} props */ | ||
export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { | ||
return ( | ||
<Paper | ||
style={{ | ||
width: 300, | ||
height: '100vh', | ||
borderRadius: 0, | ||
zIndex: 1, | ||
position: 'relative' | ||
}} | ||
> | ||
<StyledTabs | ||
orientation='vertical' | ||
value={currentTab} | ||
onChange={(e, newValue) => onTabChange(newValue)} | ||
> | ||
{tabs.map(tab => ( | ||
<Tab | ||
disableRipple | ||
orientation='vertical' | ||
key={tab.tabId} | ||
value={tab.tabId} | ||
component={RenderTab} | ||
tab={tab} | ||
active={tab.tabId === currentTab} | ||
/> | ||
))} | ||
</StyledTabs> | ||
</Paper> | ||
) | ||
} | ||
|
||
const RenderTab = React.forwardRef( | ||
( | ||
{ tab: { icon: Icon, label, subtitle }, active, children, ...rest }, | ||
ref | ||
) => { | ||
const { formatMessage: t } = useIntl() | ||
const theme = useTheme() | ||
|
||
return ( | ||
<WrapperRow ref={ref} {...rest}> | ||
<IconContainer> | ||
{Icon ? <Icon style={{ color: theme.palette.grey['600'] }} /> : null} | ||
</IconContainer> | ||
<TitleContainer> | ||
<Typography | ||
variant='body1' | ||
component='label' | ||
style={{ | ||
textTransform: 'none', | ||
textAlign: 'left', | ||
cursor: 'pointer' | ||
}} | ||
> | ||
{typeof label === 'string' ? label : t(label)} | ||
</Typography> | ||
<Typography | ||
variant='caption' | ||
component='label' | ||
style={{ | ||
textTransform: 'none', | ||
textAlign: 'left', | ||
cursor: 'pointer', | ||
color: theme.palette.grey['700'] | ||
}} | ||
> | ||
{typeof subtitle === 'string' ? subtitle : t(subtitle)} | ||
</Typography> | ||
</TitleContainer> | ||
<ChevronRightIcon style={{ opacity: active ? 1 : 0 }} /> | ||
</WrapperRow> | ||
) | ||
} | ||
) | ||
|
||
const StyledTabs = styled(Tabs)` | ||
height: 100vh; | ||
padding-top: 1em; | ||
& .MuiTabs-indicator { | ||
display: none; | ||
} | ||
& .MuiTab-root { | ||
max-width: 100%; | ||
} | ||
` | ||
|
||
const Row = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
` | ||
|
||
const Column = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
const WrapperRow = styled(Row)` | ||
padding: 20px; | ||
align-items: center; | ||
justify-content: space-between; | ||
` | ||
|
||
const IconContainer = styled.div` | ||
flex: 1; | ||
padding: 10px 30px 10px 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,39 @@ | ||
import React, { useState } from 'react' | ||
import InfoIcon from '@material-ui/icons/InfoOutlined' | ||
import { SettingsMenu } from './SettingsMenu' | ||
import { defineMessages } from 'react-intl' | ||
import { AboutMapeoMenu } from './AboutMapeo' | ||
import styled from 'styled-components' | ||
|
||
const m = defineMessages({ | ||
aboutMapeo: 'About Mapeo', | ||
aboutMapeoSubtitle: 'Version and build number', | ||
}) | ||
|
||
const tabs = [ | ||
{ | ||
/** @type {import('./SettingsMenu').tabId} */ | ||
tabId: 'AboutMapeo', | ||
icon: InfoIcon, | ||
label: m.aboutMapeo, | ||
subtitle: m.aboutMapeoSubtitle, | ||
}, | ||
] | ||
|
||
export const SettingsView = () => { | ||
/** @type {import('./SettingsMenu').tabId | null} */ | ||
const initialMenuState = /** {const} */ null | ||
const [menuItem, setMenuItem] = useState(initialMenuState) | ||
|
||
return ( | ||
<Container> | ||
<SettingsMenu tabs={tabs} currentTab={menuItem} onTabChange={setMenuItem} /> | ||
{menuItem === 'AboutMapeo' && <AboutMapeoMenu />} | ||
</Container> | ||
) | ||
} | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
` |