omnivore/packages/web/components/patterns/DropdownMenu.tsx

101 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-02-11 17:24:33 +00:00
import { ReactNode, useMemo, useState } from 'react'
2022-04-22 11:07:26 +00:00
import { HStack, VStack } from './../elements/LayoutPrimitives'
2022-02-11 17:24:33 +00:00
import {
Dropdown,
DropdownOption,
2022-04-22 11:07:26 +00:00
DropdownSeparator,
2022-02-11 17:24:33 +00:00
} from '../elements/DropdownElements'
import { StyledText } from '../elements/StyledText'
import { Button } from '../elements/Button'
import { currentThemeName } from '../../lib/themeUpdater'
import { Check } from 'phosphor-react'
2022-02-11 17:24:33 +00:00
export type HeaderDropdownAction =
| 'apply-darker-theme'
| 'apply-dark-theme'
| 'apply-light-theme'
| 'apply-lighter-theme'
| 'navigate-to-install'
| 'navigate-to-emails'
2022-04-13 17:34:46 +00:00
| 'navigate-to-labels'
2022-02-11 17:24:33 +00:00
| 'navigate-to-profile'
2022-04-22 11:07:26 +00:00
| 'navigate-to-subscriptions'
2022-07-02 00:29:08 +00:00
| 'navigate-to-api'
2022-02-11 17:24:33 +00:00
| 'increaseFontSize'
| 'decreaseFontSize'
| 'logout'
type DropdownMenuProps = {
username?: string
triggerElement: ReactNode
actionHandler: (action: HeaderDropdownAction) => void
}
export function DropdownMenu(props: DropdownMenuProps): JSX.Element {
const [currentTheme, setCurrentTheme] = useState(currentThemeName())
const isDark = useMemo(() => {
return currentTheme === 'Dark' || currentTheme === 'Darker'
}, [currentTheme])
return (
<Dropdown triggerElement={props.triggerElement}>
<VStack css={{ py: '12px', px: '24px' }}>
2022-04-22 11:07:26 +00:00
<StyledText style="menuTitle">Theme</StyledText>
<HStack css={{ py: '8px', width: '100%', gap: '25px' }}>
2022-04-22 11:07:26 +00:00
<Button
style="themeSwitch"
css={{ background: '#FFFFFF' }}
data-state={isDark ? 'unselected' : 'selected' }
2022-04-22 11:07:26 +00:00
onClick={() => {
props.actionHandler('apply-lighter-theme')
setCurrentTheme(currentThemeName())
}}
>
{!isDark && (
<Check color='#F9D354' size={32} />
)}
2022-02-11 17:24:33 +00:00
</Button>
2022-04-22 11:07:26 +00:00
<Button
style="themeSwitch"
css={{ background: '#3D3D3D' }}
data-state={isDark ? 'selected' : 'unselected' }
2022-04-22 11:07:26 +00:00
onClick={() => {
props.actionHandler('apply-dark-theme')
setCurrentTheme(currentThemeName())
}}
>
{isDark && (
<Check color='#F9D354' size={32} />
)}
2022-02-11 17:24:33 +00:00
</Button>
</HStack>
</VStack>
<DropdownOption
onSelect={() => props.actionHandler('navigate-to-install')}
title="Install"
/>
<DropdownOption
onSelect={() => props.actionHandler('navigate-to-emails')}
title="Emails"
/>
2022-04-13 17:34:46 +00:00
<DropdownOption
onSelect={() => props.actionHandler('navigate-to-labels')}
title="Labels"
/>
<DropdownOption
onSelect={() => props.actionHandler('navigate-to-api')}
title="API Keys"
/>
2022-02-11 17:24:33 +00:00
<DropdownOption
onSelect={() => window.Intercom('show')}
title="Feedback"
/>
<DropdownOption
onSelect={() => props.actionHandler('logout')}
title="Logout"
/>
</Dropdown>
)
}