Newer
Older
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
127
128
129
130
131
import useOutsideClick from '@polkadot/extension-ui/hooks/useOutsideClick'
import MenuSettings from '@polkadot/extension-ui/partials/MenuSettings'
import React, { useRef, useState } from 'react'
import styled from 'styled-components'
import { EXT_NAME } from '../../utils/constants'
import type { ExtThemeProps } from '../types'
import { goTo } from '../utils/goTo'
interface Props extends ExtThemeProps {
showAdd?: boolean
showBackArrow?: boolean
showSettings?: boolean
smallMargin?: boolean
text?: React.ReactNode
}
const Header: React.FC<Props> = ({
className,
showAdd,
showBackArrow,
showSettings,
smallMargin,
text,
}) => {
const [isSettingsOpen, setShowSettings] = useState(false)
const setRef = useRef(null)
useOutsideClick(setRef, (): void => {
isSettingsOpen && setShowSettings(!isSettingsOpen)
})
const toggleAdd = () => goTo('/account/import-qr')
const toggleSettings = () =>
setShowSettings((isSettingsOpen) => !isSettingsOpen)
const toggleBack = () => goTo('/')
return (
<div className={`${className} ${smallMargin ? 'smallMargin' : ''}`}>
<div className='container'>
<div className='branding'>
{showBackArrow && (
<button className='backlink' onClick={toggleBack}>
Back
</button>
)}
<span className='logoText'>{text || EXT_NAME}</span>
</div>
<div className='popupMenus'>
{showAdd && (
<button className='popupToggle' onClick={toggleAdd}>
Add
</button>
)}
{showSettings && (
<button className='popupToggle' onClick={toggleSettings}>
Settings
</button>
)}
</div>
{isSettingsOpen && <MenuSettings reference={setRef} />}
</div>
</div>
)
}
export default styled(Header)`
max-width: 100%;
box-sizing: border-box;
font-weight: normal;
margin: 0;
position: relative;
margin-bottom: 25px;
&& {
padding: 0 0 0;
}
> .container {
display: flex;
justify-content: space-between;
width: 100%;
border-bottom: 1px solid
${({ theme }: ExtThemeProps) => theme.inputBorderColor};
min-height: 70px;
.branding {
display: flex;
justify-content: center;
align-items: center;
color: ${({ theme }: ExtThemeProps) => theme.labelColor};
font-family: ${({ theme }: ExtThemeProps) => theme.fontFamily};
text-align: center;
margin-left: 24px;
.logoText {
color: ${({ theme }: ExtThemeProps) => theme.textColor};
font-family: ${({ theme }: ExtThemeProps) => theme.fontFamily};
font-size: 20px;
line-height: 27px;
}
}
.backLink {
display: inline-block;
vertical-align: middle;
}
.popupMenus {
align-self: center;
.popupToggle {
display: inline-block;
vertical-align: middle;
&:last-child {
margin-right: 24px;
}
}
.popupToggle + .popupToggle {
margin-left: 8px;
}
}
}
&.smallMargin {
margin-bottom: 15px;
}
`