-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathSettingsDropdown.js
More file actions
103 lines (91 loc) · 2.45 KB
/
SettingsDropdown.js
File metadata and controls
103 lines (91 loc) · 2.45 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { translate } from 'react-polyglot';
import { Icon, Dropdown, DropdownItem, DropdownButton, colors } from 'decap-cms-ui-default';
import { stripProtocol } from '../../lib/urlHelper';
const styles = {
avatarImage: css`
width: 32px;
border-radius: 32px;
`,
};
const AvatarDropdownButton = styled(DropdownButton)`
display: inline-block;
padding: 8px;
cursor: pointer;
color: #1e2532;
background-color: transparent;
`;
const AvatarImage = styled.img`
${styles.avatarImage};
`;
const AvatarPlaceholderIcon = styled(Icon)`
${styles.avatarImage};
height: 32px;
color: #1e2532;
background-color: ${colors.textFieldBorder};
`;
const AppHeaderSiteLink = styled.a`
font-size: 14px;
font-weight: 400;
color: #7b8290;
padding: 10px 16px;
`;
const AppHeaderTestRepoIndicator = styled.a`
font-size: 14px;
font-weight: 400;
color: #7b8290;
padding: 10px 16px;
`;
function Avatar({ imageUrl }) {
return imageUrl ? (
<AvatarImage src={imageUrl} />
) : (
<AvatarPlaceholderIcon type="user" size="large" />
);
}
Avatar.propTypes = {
imageUrl: PropTypes.string,
};
function SettingsDropdown({ displayUrl, isTestRepo, imageUrl, onLogoutClick, t }) {
return (
<React.Fragment>
{isTestRepo && (
<AppHeaderTestRepoIndicator
href="https://www.decapcms.org/docs/test-backend"
target="_blank"
rel="noopener noreferrer"
>
Test Backend ↗
</AppHeaderTestRepoIndicator>
)}
{displayUrl ? (
<AppHeaderSiteLink href={displayUrl} target="_blank">
{stripProtocol(displayUrl)}
</AppHeaderSiteLink>
) : null}
<Dropdown
dropdownTopOverlap="50px"
dropdownWidth="100px"
dropdownPosition="right"
renderButton={() => (
<AvatarDropdownButton aria-label="account options dropdown">
<Avatar imageUrl={imageUrl} />
</AvatarDropdownButton>
)}
>
<DropdownItem label={t('ui.settingsDropdown.logOut')} onClick={onLogoutClick} />
</Dropdown>
</React.Fragment>
);
}
SettingsDropdown.propTypes = {
displayUrl: PropTypes.string,
isTestRepo: PropTypes.bool,
imageUrl: PropTypes.string,
onLogoutClick: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
};
export default translate()(SettingsDropdown);