@equinor/cpl-top-bar-react 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCE +21 -0
- package/README.md +9 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +234 -0
- package/dist/index.mjs +196 -0
- package/package.json +45 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Equinor ASA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface TopBarProps {
|
|
4
|
+
appName: string;
|
|
5
|
+
logoLink: string;
|
|
6
|
+
documentationLink: string;
|
|
7
|
+
documentationName?: string;
|
|
8
|
+
userMenu?: React.ReactNode;
|
|
9
|
+
darkMode?: boolean;
|
|
10
|
+
logoPath?: string;
|
|
11
|
+
logoAlt?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function TopBar({ appName, logoLink, documentationLink, documentationName, userMenu, darkMode, logoPath, logoAlt, }: TopBarProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
interface UserMenuProps {
|
|
16
|
+
logoutUrl: string;
|
|
17
|
+
darkMode?: boolean;
|
|
18
|
+
user: {
|
|
19
|
+
name: string;
|
|
20
|
+
email: string;
|
|
21
|
+
};
|
|
22
|
+
settingsLink?: string;
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
declare function UserMenu({ user, logoutUrl, darkMode, settingsLink, children, }: UserMenuProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { TopBar, UserMenu };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface TopBarProps {
|
|
4
|
+
appName: string;
|
|
5
|
+
logoLink: string;
|
|
6
|
+
documentationLink: string;
|
|
7
|
+
documentationName?: string;
|
|
8
|
+
userMenu?: React.ReactNode;
|
|
9
|
+
darkMode?: boolean;
|
|
10
|
+
logoPath?: string;
|
|
11
|
+
logoAlt?: string;
|
|
12
|
+
}
|
|
13
|
+
declare function TopBar({ appName, logoLink, documentationLink, documentationName, userMenu, darkMode, logoPath, logoAlt, }: TopBarProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
|
|
15
|
+
interface UserMenuProps {
|
|
16
|
+
logoutUrl: string;
|
|
17
|
+
darkMode?: boolean;
|
|
18
|
+
user: {
|
|
19
|
+
name: string;
|
|
20
|
+
email: string;
|
|
21
|
+
};
|
|
22
|
+
settingsLink?: string;
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
declare function UserMenu({ user, logoutUrl, darkMode, settingsLink, children, }: UserMenuProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { TopBar, UserMenu };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
TopBar: () => TopBar,
|
|
34
|
+
UserMenu: () => UserMenu
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/TopBar/TopBar.tsx
|
|
39
|
+
var import_eds_core_react = require("@equinor/eds-core-react");
|
|
40
|
+
var import_eds_icons = require("@equinor/eds-icons");
|
|
41
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
42
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
function TopBar({
|
|
44
|
+
appName,
|
|
45
|
+
logoLink,
|
|
46
|
+
documentationLink,
|
|
47
|
+
documentationName = "Documentation",
|
|
48
|
+
userMenu,
|
|
49
|
+
darkMode = false,
|
|
50
|
+
logoPath = ".",
|
|
51
|
+
logoAlt = "logo"
|
|
52
|
+
}) {
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(StyledEDSTopBar, { $darkMode: darkMode, children: [
|
|
54
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.TopBar.Header, { style: { padding: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AppNameContainer, { children: [
|
|
55
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: logoPath, alt: logoAlt, height: 24, width: 22 }) }),
|
|
56
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: logoLink, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledTypography, { $darkMode: darkMode, children: appName }) })
|
|
57
|
+
] }) }),
|
|
58
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_eds_core_react.TopBar.Actions, { children: [
|
|
59
|
+
documentationLink && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DocumentationDiv, { $darkMode: darkMode, children: [
|
|
60
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: documentationLink, children: documentationName }),
|
|
61
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_eds_core_react.Icon, { data: import_eds_icons.external_link, size: 16 })
|
|
62
|
+
] }),
|
|
63
|
+
userMenu
|
|
64
|
+
] })
|
|
65
|
+
] });
|
|
66
|
+
}
|
|
67
|
+
var StyledEDSTopBar = (0, import_styled_components.default)(import_eds_core_react.TopBar)`
|
|
68
|
+
background-color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
69
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
70
|
+
border-color: rgba(255, 255, 255, 0.16);
|
|
71
|
+
gap: 0;
|
|
72
|
+
`;
|
|
73
|
+
var AppNameContainer = import_styled_components.default.div`
|
|
74
|
+
display: flex;
|
|
75
|
+
gap: 1rem;
|
|
76
|
+
align-items: center;
|
|
77
|
+
`;
|
|
78
|
+
var StyledTypography = (0, import_styled_components.default)(import_eds_core_react.Typography)`
|
|
79
|
+
font-weight: 300;
|
|
80
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
81
|
+
`;
|
|
82
|
+
var DocumentationDiv = import_styled_components.default.div`
|
|
83
|
+
text-decoration: none;
|
|
84
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: 0.3rem;
|
|
87
|
+
font-weight: 300;
|
|
88
|
+
a {
|
|
89
|
+
text-decoration: none;
|
|
90
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
// src/UserMenu/UserMenu.tsx
|
|
95
|
+
var import_eds_core_react2 = require("@equinor/eds-core-react");
|
|
96
|
+
var import_eds_icons2 = require("@equinor/eds-icons");
|
|
97
|
+
var import_eds_tokens = require("@equinor/eds-tokens");
|
|
98
|
+
var import_react = require("react");
|
|
99
|
+
var import_styled_components2 = __toESM(require("styled-components"));
|
|
100
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
101
|
+
function UserMenu({
|
|
102
|
+
user,
|
|
103
|
+
logoutUrl,
|
|
104
|
+
darkMode = false,
|
|
105
|
+
settingsLink,
|
|
106
|
+
children
|
|
107
|
+
}) {
|
|
108
|
+
var _a, _b, _c, _d, _e;
|
|
109
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
110
|
+
const [anchorEl, setAnchorEl] = (0, import_react.useState)(null);
|
|
111
|
+
const openMenu = () => {
|
|
112
|
+
setIsOpen(true);
|
|
113
|
+
};
|
|
114
|
+
const closeMenu = () => {
|
|
115
|
+
setIsOpen(false);
|
|
116
|
+
};
|
|
117
|
+
const firstLetter = (_c = (_b = (_a = user == null ? void 0 : user.email) == null ? void 0 : _a[0]) == null ? void 0 : _b.toUpperCase()) != null ? _c : "-";
|
|
118
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
119
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
120
|
+
StyledUserButton,
|
|
121
|
+
{
|
|
122
|
+
id: "user-button",
|
|
123
|
+
variant: "contained_icon",
|
|
124
|
+
ref: setAnchorEl,
|
|
125
|
+
"aria-haspopup": "true",
|
|
126
|
+
"aria-expanded": isOpen,
|
|
127
|
+
"aria-controls": "user-menu",
|
|
128
|
+
onClick: () => isOpen ? closeMenu() : openMenu(),
|
|
129
|
+
$darkMode: darkMode,
|
|
130
|
+
children: firstLetter
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
134
|
+
MenuWrapper,
|
|
135
|
+
{
|
|
136
|
+
$darkMode: darkMode,
|
|
137
|
+
id: "user-menu",
|
|
138
|
+
"aria-labelledby": "user-button",
|
|
139
|
+
open: isOpen,
|
|
140
|
+
onClose: closeMenu,
|
|
141
|
+
anchorEl,
|
|
142
|
+
style: { padding: 0, paddingBottom: 2 },
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconAndTextWrapper, { children: [
|
|
145
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LetterCircle, { $darkMode: darkMode, children: firstLetter }),
|
|
146
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { fontWeight: "bold", lineHeight: 0.9, marginBottom: 2 }, children: (_d = user == null ? void 0 : user.name) != null ? _d : "-" }),
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: (_e = user == null ? void 0 : user.email) != null ? _e : "-" })
|
|
149
|
+
] })
|
|
150
|
+
] }),
|
|
151
|
+
settingsLink && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_eds_core_react2.Menu.Item, { as: "a", href: settingsLink, className: "menu-item", children: [
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_eds_core_react2.Icon, { data: import_eds_icons2.settings }),
|
|
153
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Settings" })
|
|
154
|
+
] }),
|
|
155
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_eds_core_react2.Menu.Item, { as: "a", href: logoutUrl, className: "menu-item", children: [
|
|
156
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_eds_core_react2.Icon, { data: import_eds_icons2.log_out }),
|
|
157
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Log out" })
|
|
158
|
+
] }),
|
|
159
|
+
children
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
var MenuWrapper = (0, import_styled_components2.default)(import_eds_core_react2.Menu)`
|
|
166
|
+
background: ${(p) => p.$darkMode ? " #3E4F5C" : " #3a7e82"};
|
|
167
|
+
border-radius: ${import_eds_tokens.tokens.shape.corners.borderRadius};
|
|
168
|
+
margin-top: ${import_eds_tokens.tokens.spacings.comfortable.small};
|
|
169
|
+
margin-bottom: -${import_eds_tokens.tokens.spacings.comfortable.small};
|
|
170
|
+
padding-bottom: ${import_eds_tokens.tokens.spacings.comfortable.small};
|
|
171
|
+
padding-left: 0;
|
|
172
|
+
padding-right: 0;
|
|
173
|
+
padding-top: ${import_eds_tokens.tokens.spacings.comfortable.small};
|
|
174
|
+
width: 315px;
|
|
175
|
+
color: white;
|
|
176
|
+
|
|
177
|
+
.menu-item {
|
|
178
|
+
align-items: center;
|
|
179
|
+
background: transparent;
|
|
180
|
+
color: white;
|
|
181
|
+
display: flex;
|
|
182
|
+
gap: ${import_eds_tokens.tokens.spacings.comfortable.medium};
|
|
183
|
+
opacity: 0.85;
|
|
184
|
+
padding: ${import_eds_tokens.tokens.spacings.comfortable.small} ${import_eds_tokens.tokens.spacings.comfortable.large};
|
|
185
|
+
svg {
|
|
186
|
+
opacity: 0.7;
|
|
187
|
+
}
|
|
188
|
+
&:hover {
|
|
189
|
+
background: #305c75;
|
|
190
|
+
opacity: 1;
|
|
191
|
+
svg {
|
|
192
|
+
opacity: 1;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
`;
|
|
197
|
+
var LetterCircle = import_styled_components2.default.span`
|
|
198
|
+
align-items: center;
|
|
199
|
+
background: ${(p) => p.$darkMode ? "#97CACE" : " #007079"};
|
|
200
|
+
border-radius: 1000px;
|
|
201
|
+
color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
202
|
+
display: flex;
|
|
203
|
+
flex-shrink: 0;
|
|
204
|
+
font-weight: bold;
|
|
205
|
+
height: 32px;
|
|
206
|
+
justify-content: center;
|
|
207
|
+
width: 32px;
|
|
208
|
+
`;
|
|
209
|
+
var StyledUserButton = (0, import_styled_components2.default)(import_eds_core_react2.Button)`
|
|
210
|
+
background: ${(p) => p.$darkMode ? "#97CACE" : " #007079"};
|
|
211
|
+
color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
212
|
+
margin: 10px 12px;
|
|
213
|
+
font-weight: bold;
|
|
214
|
+
width: 32px;
|
|
215
|
+
height: 32px;
|
|
216
|
+
&:hover {
|
|
217
|
+
background: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
218
|
+
}
|
|
219
|
+
`;
|
|
220
|
+
var IconAndTextWrapper = (0, import_styled_components2.default)(import_eds_core_react2.Menu.Item)`
|
|
221
|
+
display: flex;
|
|
222
|
+
gap: 12px;
|
|
223
|
+
padding: 12px 20px;
|
|
224
|
+
width: 315px;
|
|
225
|
+
color: inherit;
|
|
226
|
+
&:hover {
|
|
227
|
+
background: #305c75;
|
|
228
|
+
}
|
|
229
|
+
`;
|
|
230
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
231
|
+
0 && (module.exports = {
|
|
232
|
+
TopBar,
|
|
233
|
+
UserMenu
|
|
234
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// src/TopBar/TopBar.tsx
|
|
2
|
+
import { TopBar as EDSTopBar, Icon, Typography } from "@equinor/eds-core-react";
|
|
3
|
+
import { external_link } from "@equinor/eds-icons";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function TopBar({
|
|
7
|
+
appName,
|
|
8
|
+
logoLink,
|
|
9
|
+
documentationLink,
|
|
10
|
+
documentationName = "Documentation",
|
|
11
|
+
userMenu,
|
|
12
|
+
darkMode = false,
|
|
13
|
+
logoPath = ".",
|
|
14
|
+
logoAlt = "logo"
|
|
15
|
+
}) {
|
|
16
|
+
return /* @__PURE__ */ jsxs(StyledEDSTopBar, { $darkMode: darkMode, children: [
|
|
17
|
+
/* @__PURE__ */ jsx(EDSTopBar.Header, { style: { padding: 0 }, children: /* @__PURE__ */ jsxs(AppNameContainer, { children: [
|
|
18
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("img", { src: logoPath, alt: logoAlt, height: 24, width: 22 }) }),
|
|
19
|
+
/* @__PURE__ */ jsx("a", { href: logoLink, children: /* @__PURE__ */ jsx(StyledTypography, { $darkMode: darkMode, children: appName }) })
|
|
20
|
+
] }) }),
|
|
21
|
+
/* @__PURE__ */ jsxs(EDSTopBar.Actions, { children: [
|
|
22
|
+
documentationLink && /* @__PURE__ */ jsxs(DocumentationDiv, { $darkMode: darkMode, children: [
|
|
23
|
+
/* @__PURE__ */ jsx("a", { href: documentationLink, children: documentationName }),
|
|
24
|
+
/* @__PURE__ */ jsx(Icon, { data: external_link, size: 16 })
|
|
25
|
+
] }),
|
|
26
|
+
userMenu
|
|
27
|
+
] })
|
|
28
|
+
] });
|
|
29
|
+
}
|
|
30
|
+
var StyledEDSTopBar = styled(EDSTopBar)`
|
|
31
|
+
background-color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
32
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
33
|
+
border-color: rgba(255, 255, 255, 0.16);
|
|
34
|
+
gap: 0;
|
|
35
|
+
`;
|
|
36
|
+
var AppNameContainer = styled.div`
|
|
37
|
+
display: flex;
|
|
38
|
+
gap: 1rem;
|
|
39
|
+
align-items: center;
|
|
40
|
+
`;
|
|
41
|
+
var StyledTypography = styled(Typography)`
|
|
42
|
+
font-weight: 300;
|
|
43
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
44
|
+
`;
|
|
45
|
+
var DocumentationDiv = styled.div`
|
|
46
|
+
text-decoration: none;
|
|
47
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
48
|
+
display: flex;
|
|
49
|
+
gap: 0.3rem;
|
|
50
|
+
font-weight: 300;
|
|
51
|
+
a {
|
|
52
|
+
text-decoration: none;
|
|
53
|
+
color: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
// src/UserMenu/UserMenu.tsx
|
|
58
|
+
import { Button, Icon as Icon2, Menu } from "@equinor/eds-core-react";
|
|
59
|
+
import { log_out, settings } from "@equinor/eds-icons";
|
|
60
|
+
import { tokens } from "@equinor/eds-tokens";
|
|
61
|
+
import { useState } from "react";
|
|
62
|
+
import styled2 from "styled-components";
|
|
63
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
64
|
+
function UserMenu({
|
|
65
|
+
user,
|
|
66
|
+
logoutUrl,
|
|
67
|
+
darkMode = false,
|
|
68
|
+
settingsLink,
|
|
69
|
+
children
|
|
70
|
+
}) {
|
|
71
|
+
var _a, _b, _c, _d, _e;
|
|
72
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
73
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
74
|
+
const openMenu = () => {
|
|
75
|
+
setIsOpen(true);
|
|
76
|
+
};
|
|
77
|
+
const closeMenu = () => {
|
|
78
|
+
setIsOpen(false);
|
|
79
|
+
};
|
|
80
|
+
const firstLetter = (_c = (_b = (_a = user == null ? void 0 : user.email) == null ? void 0 : _a[0]) == null ? void 0 : _b.toUpperCase()) != null ? _c : "-";
|
|
81
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
82
|
+
/* @__PURE__ */ jsx2(
|
|
83
|
+
StyledUserButton,
|
|
84
|
+
{
|
|
85
|
+
id: "user-button",
|
|
86
|
+
variant: "contained_icon",
|
|
87
|
+
ref: setAnchorEl,
|
|
88
|
+
"aria-haspopup": "true",
|
|
89
|
+
"aria-expanded": isOpen,
|
|
90
|
+
"aria-controls": "user-menu",
|
|
91
|
+
onClick: () => isOpen ? closeMenu() : openMenu(),
|
|
92
|
+
$darkMode: darkMode,
|
|
93
|
+
children: firstLetter
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
/* @__PURE__ */ jsxs2(
|
|
97
|
+
MenuWrapper,
|
|
98
|
+
{
|
|
99
|
+
$darkMode: darkMode,
|
|
100
|
+
id: "user-menu",
|
|
101
|
+
"aria-labelledby": "user-button",
|
|
102
|
+
open: isOpen,
|
|
103
|
+
onClose: closeMenu,
|
|
104
|
+
anchorEl,
|
|
105
|
+
style: { padding: 0, paddingBottom: 2 },
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ jsxs2(IconAndTextWrapper, { children: [
|
|
108
|
+
/* @__PURE__ */ jsx2(LetterCircle, { $darkMode: darkMode, children: firstLetter }),
|
|
109
|
+
isOpen && /* @__PURE__ */ jsxs2("div", { children: [
|
|
110
|
+
/* @__PURE__ */ jsx2("div", { style: { fontWeight: "bold", lineHeight: 0.9, marginBottom: 2 }, children: (_d = user == null ? void 0 : user.name) != null ? _d : "-" }),
|
|
111
|
+
/* @__PURE__ */ jsx2("div", { children: (_e = user == null ? void 0 : user.email) != null ? _e : "-" })
|
|
112
|
+
] })
|
|
113
|
+
] }),
|
|
114
|
+
settingsLink && /* @__PURE__ */ jsxs2(Menu.Item, { as: "a", href: settingsLink, className: "menu-item", children: [
|
|
115
|
+
/* @__PURE__ */ jsx2(Icon2, { data: settings }),
|
|
116
|
+
/* @__PURE__ */ jsx2("span", { children: "Settings" })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsxs2(Menu.Item, { as: "a", href: logoutUrl, className: "menu-item", children: [
|
|
119
|
+
/* @__PURE__ */ jsx2(Icon2, { data: log_out }),
|
|
120
|
+
/* @__PURE__ */ jsx2("span", { children: "Log out" })
|
|
121
|
+
] }),
|
|
122
|
+
children
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
] });
|
|
127
|
+
}
|
|
128
|
+
var MenuWrapper = styled2(Menu)`
|
|
129
|
+
background: ${(p) => p.$darkMode ? " #3E4F5C" : " #3a7e82"};
|
|
130
|
+
border-radius: ${tokens.shape.corners.borderRadius};
|
|
131
|
+
margin-top: ${tokens.spacings.comfortable.small};
|
|
132
|
+
margin-bottom: -${tokens.spacings.comfortable.small};
|
|
133
|
+
padding-bottom: ${tokens.spacings.comfortable.small};
|
|
134
|
+
padding-left: 0;
|
|
135
|
+
padding-right: 0;
|
|
136
|
+
padding-top: ${tokens.spacings.comfortable.small};
|
|
137
|
+
width: 315px;
|
|
138
|
+
color: white;
|
|
139
|
+
|
|
140
|
+
.menu-item {
|
|
141
|
+
align-items: center;
|
|
142
|
+
background: transparent;
|
|
143
|
+
color: white;
|
|
144
|
+
display: flex;
|
|
145
|
+
gap: ${tokens.spacings.comfortable.medium};
|
|
146
|
+
opacity: 0.85;
|
|
147
|
+
padding: ${tokens.spacings.comfortable.small} ${tokens.spacings.comfortable.large};
|
|
148
|
+
svg {
|
|
149
|
+
opacity: 0.7;
|
|
150
|
+
}
|
|
151
|
+
&:hover {
|
|
152
|
+
background: #305c75;
|
|
153
|
+
opacity: 1;
|
|
154
|
+
svg {
|
|
155
|
+
opacity: 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
160
|
+
var LetterCircle = styled2.span`
|
|
161
|
+
align-items: center;
|
|
162
|
+
background: ${(p) => p.$darkMode ? "#97CACE" : " #007079"};
|
|
163
|
+
border-radius: 1000px;
|
|
164
|
+
color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
165
|
+
display: flex;
|
|
166
|
+
flex-shrink: 0;
|
|
167
|
+
font-weight: bold;
|
|
168
|
+
height: 32px;
|
|
169
|
+
justify-content: center;
|
|
170
|
+
width: 32px;
|
|
171
|
+
`;
|
|
172
|
+
var StyledUserButton = styled2(Button)`
|
|
173
|
+
background: ${(p) => p.$darkMode ? "#97CACE" : " #007079"};
|
|
174
|
+
color: ${(p) => p.$darkMode ? "#132634" : "#fff"};
|
|
175
|
+
margin: 10px 12px;
|
|
176
|
+
font-weight: bold;
|
|
177
|
+
width: 32px;
|
|
178
|
+
height: 32px;
|
|
179
|
+
&:hover {
|
|
180
|
+
background: ${(p) => p.$darkMode ? "#fff" : "#132634"};
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
var IconAndTextWrapper = styled2(Menu.Item)`
|
|
184
|
+
display: flex;
|
|
185
|
+
gap: 12px;
|
|
186
|
+
padding: 12px 20px;
|
|
187
|
+
width: 315px;
|
|
188
|
+
color: inherit;
|
|
189
|
+
&:hover {
|
|
190
|
+
background: #305c75;
|
|
191
|
+
}
|
|
192
|
+
`;
|
|
193
|
+
export {
|
|
194
|
+
TopBar,
|
|
195
|
+
UserMenu
|
|
196
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/cpl-top-bar-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@equinor/eds-icons": "^0.21.0",
|
|
13
|
+
"@equinor/eds-tokens": "^0.9.2"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@equinor/eds-core-react": "^0.42.1",
|
|
17
|
+
"@storybook/react": "^8.1.11",
|
|
18
|
+
"@storybook/test": "^8.1.11",
|
|
19
|
+
"@types/react": "^18.3.3",
|
|
20
|
+
"@types/react-dom": "^18.3.0",
|
|
21
|
+
"@types/styled-components": "^5.1.34",
|
|
22
|
+
"eslint": "^8.56.0",
|
|
23
|
+
"react": "^18.2.0",
|
|
24
|
+
"react-dom": "^18.2.0",
|
|
25
|
+
"styled-components": "^6.1.11",
|
|
26
|
+
"tsup": "^8.1.0",
|
|
27
|
+
"eslint-config-custom": "0.0.5",
|
|
28
|
+
"tsconfig": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@equinor/eds-core-react": ">=0.42.1",
|
|
32
|
+
"react": ">=18.2.0",
|
|
33
|
+
"react-dom": ">=18.2.0",
|
|
34
|
+
"styled-components": ">=5.3.11"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
41
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
42
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react",
|
|
43
|
+
"lint": "TIMING=1 eslint . --fix"
|
|
44
|
+
}
|
|
45
|
+
}
|