|
1 | | -import * as React from 'react'; |
2 | | - |
3 | | -import { |
4 | | - Button, |
5 | | - ColorMode, |
6 | | - Divider, |
7 | | - Flex, |
8 | | - Link, |
9 | | - ToggleButton, |
10 | | - ToggleButtonGroup, |
11 | | - View, |
12 | | - VisuallyHidden, |
13 | | -} from '@aws-amplify/ui-react'; |
14 | | -import { |
15 | | - MdBedtime, |
16 | | - MdClose, |
17 | | - MdMenu, |
18 | | - MdOpenInNew, |
19 | | - MdTonality, |
20 | | - MdWbSunny, |
21 | | -} from 'react-icons/md'; |
22 | | - |
23 | | -import { FrameworkChooser } from './FrameworkChooser'; |
24 | | -import LinkButton from './LinkButton'; |
25 | | -import { Logo } from '@/components/Logo'; |
26 | | -import NextLink from 'next/link'; |
27 | | -import { SecondaryNav } from './SecondaryNav'; |
28 | | -import { useCustomRouter } from '@/components/useCustomRouter'; |
29 | | - |
30 | | -const NavLink = ({ |
31 | | - href, |
32 | | - children, |
33 | | - isExternal = false, |
34 | | - onClick, |
35 | | -}: { |
36 | | - href: string; |
37 | | - children: React.ReactElement; |
38 | | - isExternal?: boolean; |
39 | | - onClick?: React.MouseEventHandler<HTMLAnchorElement>; |
| 1 | +import { Flex, Image } from '@aws-amplify/ui-react'; |
| 2 | + |
| 3 | +import { ColorModeSwitcher } from './ColorModeSwitcher'; |
| 4 | +import { Sidebar } from './Sidebar'; |
| 5 | +import { LogoLink } from './LogoLink'; |
| 6 | +import { MenuButton } from './MenuButton'; |
| 7 | + |
| 8 | +export const Header = ({ |
| 9 | + expanded, |
| 10 | + setExpanded, |
| 11 | + colorMode, |
| 12 | + setColorMode, |
| 13 | + platform, |
40 | 14 | }) => { |
41 | | - const { pathname } = useCustomRouter(); |
42 | | - const pathnameHeader = pathname.split('/')[2]; |
43 | | - const hrefHeader = href.split('/')[2]; |
44 | | - const isCurrent = pathnameHeader === hrefHeader && href !== `/`; |
45 | | - const className = `docs-nav-link ${isCurrent ? 'current' : ''}`; |
46 | | - |
47 | | - if (isExternal) { |
48 | | - return ( |
49 | | - <Link isExternal href={href} className={className}> |
50 | | - {children} |
51 | | - </Link> |
52 | | - ); |
53 | | - } |
54 | | - return ( |
55 | | - <NextLink href={href} passHref> |
56 | | - <LinkButton href={href} classNames={className} onClick={onClick}> |
57 | | - {children} |
58 | | - </LinkButton> |
59 | | - </NextLink> |
60 | | - ); |
61 | | -}; |
62 | | - |
63 | | -const Nav = (props) => ( |
64 | | - <Flex |
65 | | - as="nav" |
66 | | - aria-label="Main navigation" |
67 | | - className="docs-nav" |
68 | | - alignItems="center" |
69 | | - gap="0" |
70 | | - grow="1" |
71 | | - > |
72 | | - <NavLink |
73 | | - {...props} |
74 | | - href={`/${props.platform}/getting-started/installation`} |
75 | | - > |
76 | | - Getting started |
77 | | - </NavLink> |
78 | | - <NavLink {...props} href={`/${props.platform}/components`}> |
79 | | - Components |
80 | | - </NavLink> |
81 | | - <NavLink {...props} href={`/${props.platform}/theming`}> |
82 | | - Theming |
83 | | - </NavLink> |
84 | | - <NavLink {...props} href={`/${props.platform}/guides`}> |
85 | | - Guides |
86 | | - </NavLink> |
87 | | - <Divider orientation="vertical" /> |
88 | | - <NavLink {...props} isExternal href="https://docs.amplify.aws"> |
89 | | - Amplify docs <MdOpenInNew /> |
90 | | - </NavLink> |
91 | | - </Flex> |
92 | | -); |
93 | | - |
94 | | -const Settings = ({ platform, setColorMode, colorMode }) => ( |
95 | | - <Flex className="docs-settings" justifyContent="center" alignItems="center"> |
96 | | - <FrameworkChooser platform={platform} /> |
97 | | - <ColorModeSwitcher setColorMode={setColorMode} colorMode={colorMode} /> |
98 | | - </Flex> |
99 | | -); |
100 | | - |
101 | | -const ColorModeSwitcher = ({ colorMode, setColorMode }) => { |
102 | | - return ( |
103 | | - <ToggleButtonGroup |
104 | | - value={colorMode} |
105 | | - size="small" |
106 | | - onChange={(value: ColorMode) => setColorMode(value)} |
107 | | - isExclusive |
108 | | - isSelectionRequired |
109 | | - className="color-switcher" |
110 | | - > |
111 | | - <ToggleButton value="light" title="Light mode"> |
112 | | - <VisuallyHidden>Light mode</VisuallyHidden> |
113 | | - <MdWbSunny /> |
114 | | - </ToggleButton> |
115 | | - <ToggleButton value="dark" title="Dark mode"> |
116 | | - <VisuallyHidden>Dark mode</VisuallyHidden> |
117 | | - <MdBedtime /> |
118 | | - </ToggleButton> |
119 | | - <ToggleButton value="system" title="System preferences"> |
120 | | - <VisuallyHidden>System preference</VisuallyHidden> |
121 | | - <MdTonality /> |
122 | | - </ToggleButton> |
123 | | - </ToggleButtonGroup> |
124 | | - ); |
125 | | -}; |
126 | | - |
127 | | -export const Header = ({ platform, colorMode, setColorMode }) => { |
128 | | - const [expanded, setExpanded] = React.useState(false); |
129 | 15 | return ( |
130 | | - <> |
131 | | - <header className={`docs-header ${expanded ? 'expanded' : ''}`}> |
132 | | - <Button |
133 | | - className="docs-header-menu-button" |
134 | | - onClick={() => setExpanded(!expanded)} |
135 | | - ariaLabel="Docs header menu button" |
136 | | - > |
137 | | - {expanded ? ( |
138 | | - <MdClose style={{ width: '1.5rem', height: '1.5rem' }} /> |
139 | | - ) : ( |
140 | | - <MdMenu style={{ width: '1.5rem', height: '1.5rem' }} /> |
141 | | - )} |
142 | | - </Button> |
143 | | - |
144 | | - <NavLink href={`/`}> |
145 | | - <span className="docs-logo-link"> |
146 | | - <VisuallyHidden>Amplify UI Home</VisuallyHidden> |
147 | | - <Logo /> |
148 | | - </span> |
149 | | - </NavLink> |
150 | | - |
151 | | - <Nav platform={platform} /> |
152 | | - |
153 | | - <Settings |
154 | | - colorMode={colorMode} |
155 | | - setColorMode={setColorMode} |
156 | | - platform={platform} |
157 | | - /> |
158 | | - </header> |
159 | | - {expanded ? ( |
160 | | - <View className="docs-header-mobile-nav"> |
161 | | - <Flex |
162 | | - className="color-switcher__wrapper" |
163 | | - justifyContent="center" |
164 | | - alignItems="center" |
165 | | - > |
166 | | - <ColorModeSwitcher |
167 | | - setColorMode={setColorMode} |
168 | | - colorMode={colorMode} |
169 | | - /> |
170 | | - </Flex> |
171 | | - |
172 | | - <Nav onClick={() => setExpanded(false)} platform={platform} /> |
173 | | - <nav aria-label="Section navigation" className="docs-sidebar-nav"> |
174 | | - <SecondaryNav onClick={() => setExpanded(false)} /> |
175 | | - </nav> |
176 | | - </View> |
177 | | - ) : null} |
178 | | - </> |
| 16 | + <Flex as="header" className="docs-header"> |
| 17 | + <div className="docs-header-bg" /> |
| 18 | + <MenuButton expanded={expanded} setExpanded={setExpanded} /> |
| 19 | + |
| 20 | + <Sidebar |
| 21 | + expanded={expanded} |
| 22 | + setExpanded={setExpanded} |
| 23 | + platform={platform} |
| 24 | + /> |
| 25 | + |
| 26 | + <LogoLink platform={platform} /> |
| 27 | + |
| 28 | + <Image |
| 29 | + alt={platform} |
| 30 | + height="1.5rem" |
| 31 | + width="1.5rem" |
| 32 | + display="block" |
| 33 | + src={`/svg/integrations/${platform}.svg`} |
| 34 | + /> |
| 35 | + |
| 36 | + <Flex flex="1" justifyContent="flex-end"> |
| 37 | + <ColorModeSwitcher colorMode={colorMode} setColorMode={setColorMode} /> |
| 38 | + </Flex> |
| 39 | + </Flex> |
179 | 40 | ); |
180 | 41 | }; |
0 commit comments