-
Notifications
You must be signed in to change notification settings - Fork 28
/
nav.tsx
126 lines (119 loc) · 4.9 KB
/
nav.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Cross2Icon, QuestionMarkCircledIcon, HamburgerMenuIcon } from '@radix-ui/react-icons';
import * as Popover from '@radix-ui/react-popover';
import * as ToggleGroup from '@radix-ui/react-toggle-group';
import classnames from 'classnames';
import { LayoutGroup } from 'framer-motion';
import * as React from 'react';
import { Views } from '../types';
import { NavButton } from './nav-button';
interface NavProps extends React.ComponentPropsWithoutRef<'header'> {
activeView?: Views;
markup?: string;
openNav: () => void;
setActiveView?: (view: Views) => void;
title: string;
}
export const Nav = React.forwardRef<React.ElementRef<'header'>, Readonly<NavProps>>(
({ className, title, markup, activeView, setActiveView, openNav, ...props }, forwardedRef) => (
<>
<header
ref={forwardedRef}
className={classnames(
'bg-dark-bg flex relative items-center px-6 justify-between h-[70px] border-b border-dark-bg-border',
className
)}
{...props}
>
<div className="flex items-center gap-4">
<button
onClick={openNav}
className="inlne-block lg:hidden w-5 h-5"
aria-label="Toggle nav menu"
>
<HamburgerMenuIcon className="h-5 w-5" />
</button>
{!!title && (
<div className={`items-center overflow-hidden hidden lg:flex`}>
<h2 className="text-base font-bold truncate text">{title}</h2>
</div>
)}
</div>
{!!title && (
<div className="flex flex-row items-center gap-4">
<Popover.Root>
<Popover.Trigger asChild>
<button className="h-5 w-5" aria-label="Preview Information">
<QuestionMarkCircledIcon className="h-5 w-5" />
</button>
</Popover.Trigger>
<Popover.Portal>
<Popover.Content className="note" sideOffset={5}>
<div className="pt-4 text-xs">
The Desktop and Mobile views are <em>an approximation</em> of what your email
template will looke like on various devices. It should not be considered a
source of truth, but rather a guide for styling and layout. Always send a test
email to your target email clients for Quality Control, before sending emails in
production.
</div>
<Popover.Close className="note-close" aria-label="Close">
<Cross2Icon />
</Popover.Close>
<Popover.Arrow className="note-arrow" />
</Popover.Content>
</Popover.Portal>
</Popover.Root>
<LayoutGroup id="topbar">
{setActiveView && (
<ToggleGroup.Root
className="hidden sm:inline-block items-center bg-darker-bg border border-dark-bg-border rounded overflow-hidden"
type="single"
value={activeView}
aria-label="View mode"
onValueChange={(value) => {
if (value) setActiveView(value as Views);
}}
>
<NavButton
activeView={activeView}
addClassNames="px-1 py-1 sm:px-3 sm:py-2"
label={Views.Desktop}
/>
<NavButton activeView={activeView} label={Views.Mobile} />
<NavButton activeView={activeView} label={Views.Jsx} />
<NavButton activeView={activeView} label={Views.Html} />
<NavButton activeView={activeView} label={Views.Plain} />
</ToggleGroup.Root>
)}
</LayoutGroup>
</div>
)}
</header>
<div className="bg-dark-bg h-[70px] flex sm:hidden items-center justify-center">
<LayoutGroup id="topbar">
{setActiveView && (
<ToggleGroup.Root
className="inline-block items-center bg-darker-bg border border-dark-bg-border rounded overflow-hidden"
type="single"
value={activeView}
aria-label="View mode"
onValueChange={(value) => {
if (value) setActiveView(value as Views);
}}
>
<NavButton
activeView={activeView}
addClassNames="px-1 py-1 sm:px-3 sm:py-2"
label={Views.Desktop}
/>
<NavButton activeView={activeView} label={Views.Mobile} />
<NavButton activeView={activeView} label={Views.Jsx} />
<NavButton activeView={activeView} label={Views.Html} />
<NavButton activeView={activeView} label={Views.Plain} />
</ToggleGroup.Root>
)}
</LayoutGroup>
</div>
</>
)
);
Nav.displayName = 'Nav';