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

100 lines
3.1 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'
2023-06-20 05:36:36 +00:00
import { Dropdown, DropdownOption } from '../elements/DropdownElements'
2022-02-11 17:24:33 +00:00
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-dark-theme'
| 'apply-light-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-10-18 03:47:42 +00:00
| 'navigate-to-integrations'
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-light-theme')
2022-04-22 11:07:26 +00:00
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"
/>
<DropdownOption
2022-10-18 03:47:42 +00:00
onSelect={() => props.actionHandler('navigate-to-integrations')}
title="Integrations"
/>
<DropdownOption
onSelect={() => window.open('https://docs.omnivore.app', '_blank')}
title="Documentation"
/>
2022-02-11 17:24:33 +00:00
<DropdownOption
onSelect={() => window.Intercom('show')}
title="Feedback"
/>
<DropdownOption
onSelect={() => props.actionHandler('logout')}
title="Logout"
/>
</Dropdown>
)
}