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'
|
2022-07-08 22:20:52 +00:00
|
|
|
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'
|
2022-03-31 17:44:35 +00:00
|
|
|
| '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}>
|
2022-07-08 22:20:52 +00:00
|
|
|
<VStack css={{ py: '12px', px: '24px' }}>
|
2022-04-22 11:07:26 +00:00
|
|
|
<StyledText style="menuTitle">Theme</StyledText>
|
2022-07-10 00:08:49 +00:00
|
|
|
<HStack css={{ py: '8px', width: '100%', gap: '25px' }}>
|
2022-04-22 11:07:26 +00:00
|
|
|
<Button
|
|
|
|
|
style="themeSwitch"
|
2022-07-08 22:20:52 +00:00
|
|
|
css={{ background: '#FFFFFF' }}
|
2023-01-27 04:17:27 +00:00
|
|
|
data-state={isDark ? 'unselected' : 'selected'}
|
2022-04-22 11:07:26 +00:00
|
|
|
onClick={() => {
|
2023-03-09 08:44:45 +00:00
|
|
|
props.actionHandler('apply-light-theme')
|
2022-04-22 11:07:26 +00:00
|
|
|
setCurrentTheme(currentThemeName())
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-01-27 04:17:27 +00:00
|
|
|
{!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"
|
2022-07-08 22:20:52 +00:00
|
|
|
css={{ background: '#3D3D3D' }}
|
2023-01-27 04:17:27 +00:00
|
|
|
data-state={isDark ? 'selected' : 'unselected'}
|
2022-04-22 11:07:26 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
props.actionHandler('apply-dark-theme')
|
|
|
|
|
setCurrentTheme(currentThemeName())
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-01-27 04:17:27 +00:00
|
|
|
{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"
|
|
|
|
|
/>
|
2022-03-31 17:44:35 +00:00
|
|
|
<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"
|
|
|
|
|
/>
|
2022-07-11 23:20:35 +00:00
|
|
|
<DropdownOption
|
|
|
|
|
onSelect={() => props.actionHandler('navigate-to-api')}
|
|
|
|
|
title="API Keys"
|
|
|
|
|
/>
|
2022-11-14 09:11:41 +00:00
|
|
|
<DropdownOption
|
2022-10-18 03:47:42 +00:00
|
|
|
onSelect={() => props.actionHandler('navigate-to-integrations')}
|
|
|
|
|
title="Integrations"
|
2022-11-14 09:11:41 +00:00
|
|
|
/>
|
2023-01-27 04:17:27 +00:00
|
|
|
<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>
|
|
|
|
|
)
|
|
|
|
|
}
|