-
Notifications
You must be signed in to change notification settings - Fork 4
/
nav-menu.tsx
61 lines (54 loc) · 1.46 KB
/
nav-menu.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
import {t} from '@lingui/macro'
import {Autocomplete, IconButton, TextField} from '@material-ui/core'
import styled from '@emotion/styled'
import {NavLink, useNavigate} from 'react-router-dom'
import {useRef} from 'react'
import {NavigateNext} from '@material-ui/icons'
type Props = {
locale: Locale
setLocale: (locale: Locale) => void
}
export const NavMenu = ({locale, setLocale}: Props) => {
const navigate = useNavigate()
const navRef = useRef('')
const navigateNext = () => navigate(navRef.current)
return (
<Nav>
<MyLink to="a">{t`go to page a`}</MyLink>
<MyLink to="b">{t`go to page b`}</MyLink>
<MyTextField
size="small"
onChange={(event) => (navRef.current = event.target.value)}
InputProps={{
endAdornment: (
<IconButton onClick={navigateNext}>
<NavigateNext />
</IconButton>
),
}}
onKeyPress={(event) => {
if (event.key === 'Enter') navigateNext()
}}
label={t`pathname to navigate`}
/>
<Autocomplete<Locale>
value={locale}
onChange={(_, value) => {
if (value) setLocale(value)
}}
renderInput={(props) => <MyTextField {...props} />}
options={['en', 'ky']}
/>
</Nav>
)
}
const MyLink = styled(NavLink)`
margin: 0 10px;
`
const MyTextField = styled(TextField)`
margin: 5px;
`
const Nav = styled.nav`
display: flex;
align-items: center;
`