@dt-dds/react-app-header 0.1.0-beta.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/CHANGELOG.md +17 -0
- package/LICENSE.md +21 -0
- package/README.md +150 -0
- package/dist/index.d.mts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +704 -0
- package/dist/index.mjs +666 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// index.ts
|
|
60
|
+
var index_exports = {};
|
|
61
|
+
__export(index_exports, {
|
|
62
|
+
Actions: () => Actions,
|
|
63
|
+
AppHeader: () => AppHeader2,
|
|
64
|
+
AppName: () => AppName,
|
|
65
|
+
Logo: () => Logo,
|
|
66
|
+
Navigation: () => Navigation
|
|
67
|
+
});
|
|
68
|
+
module.exports = __toCommonJS(index_exports);
|
|
69
|
+
|
|
70
|
+
// src/AppHeader.tsx
|
|
71
|
+
var import_react4 = require("react");
|
|
72
|
+
var import_react5 = require("@emotion/react");
|
|
73
|
+
var import_react_core = require("@dt-dds/react-core");
|
|
74
|
+
|
|
75
|
+
// src/AppHeader.styled.ts
|
|
76
|
+
var import_styled = __toESM(require("@emotion/styled"));
|
|
77
|
+
|
|
78
|
+
// src/constants/index.ts
|
|
79
|
+
var HEADER_HEIGHT = 64;
|
|
80
|
+
var HEADER_HEIGHT_MOBILE = 72;
|
|
81
|
+
var NAVIGATION_HEIGHT = 52;
|
|
82
|
+
var APP_HEADER_Z_INDEX = 1;
|
|
83
|
+
var THIRD_WIDTH = "calc(100% / 3)";
|
|
84
|
+
var LOGO_MAX_HEIGHT = 54;
|
|
85
|
+
var APP_NAME_MAX_WIDTH = 170;
|
|
86
|
+
var APP_NAME_MAX_WIDTH_DESKTOP = 250;
|
|
87
|
+
var APP_NAME_MAX_HEIGHT = 50;
|
|
88
|
+
var COMPOUND_COMPONENT_NAMES = {
|
|
89
|
+
NAVIGATION: "AppHeader.Navigation",
|
|
90
|
+
APP_NAME: "AppHeader.AppName",
|
|
91
|
+
LOGO: "AppHeader.Logo",
|
|
92
|
+
ACTIONS: "AppHeader.Actions"
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/AppHeader.styled.ts
|
|
96
|
+
var AppHeaderStyled = import_styled.default.header`
|
|
97
|
+
${({ theme: theme2, isMobile }) => {
|
|
98
|
+
const paddingHorizontal = theme2.spacing.spacing_60;
|
|
99
|
+
const gap = theme2.spacing.spacing_50;
|
|
100
|
+
return `
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: flex-start;
|
|
104
|
+
gap: ${gap};
|
|
105
|
+
width: 100%;
|
|
106
|
+
height: ${isMobile ? `${HEADER_HEIGHT_MOBILE}px` : `${HEADER_HEIGHT}px`};
|
|
107
|
+
overflow: hidden;
|
|
108
|
+
padding: 0 ${paddingHorizontal};
|
|
109
|
+
position: fixed;
|
|
110
|
+
top: 0;
|
|
111
|
+
z-index: ${APP_HEADER_Z_INDEX};
|
|
112
|
+
background: ${theme2.palette.surface.contrast};
|
|
113
|
+
`;
|
|
114
|
+
}}
|
|
115
|
+
`;
|
|
116
|
+
|
|
117
|
+
// src/context/AppHeaderContext.tsx
|
|
118
|
+
var import_react = require("react");
|
|
119
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
120
|
+
var AppHeaderContext = (0, import_react.createContext)(
|
|
121
|
+
null
|
|
122
|
+
);
|
|
123
|
+
var AppHeaderContextProvider = ({
|
|
124
|
+
value,
|
|
125
|
+
children
|
|
126
|
+
}) => {
|
|
127
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AppHeaderContext.Provider, { value, children });
|
|
128
|
+
};
|
|
129
|
+
var useAppHeaderContext = () => {
|
|
130
|
+
const context = (0, import_react.useContext)(AppHeaderContext);
|
|
131
|
+
if (!context) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"AppHeader compound components must be used within AppHeader"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return context;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/utils/headerState.ts
|
|
140
|
+
var computeHeaderState = (type, navPosition, appName, hasActionsPositionRight) => ({
|
|
141
|
+
isStandard: type === "standard",
|
|
142
|
+
isCompact: type === "compact",
|
|
143
|
+
isNavCenter: navPosition === "center",
|
|
144
|
+
isNavLeft: navPosition === "left",
|
|
145
|
+
isNavRight: navPosition === "right",
|
|
146
|
+
isNavCompact: type === "compact" || !appName,
|
|
147
|
+
hasAppName: !!appName,
|
|
148
|
+
isActionsPositionRight: hasActionsPositionRight
|
|
149
|
+
});
|
|
150
|
+
var shouldCenterLogo = (type, appName) => {
|
|
151
|
+
return type === "standard" && !!appName;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/utils/children.ts
|
|
155
|
+
var import_react2 = __toESM(require("react"));
|
|
156
|
+
var getDisplayName = (element) => {
|
|
157
|
+
var _a;
|
|
158
|
+
return (_a = element.type) == null ? void 0 : _a.displayName;
|
|
159
|
+
};
|
|
160
|
+
var findChildRecursive = (children, matcher) => {
|
|
161
|
+
const childrenArray = import_react2.Children.toArray(children);
|
|
162
|
+
for (const child of childrenArray) {
|
|
163
|
+
if (import_react2.default.isValidElement(child)) {
|
|
164
|
+
if (matcher(child)) {
|
|
165
|
+
return child;
|
|
166
|
+
}
|
|
167
|
+
const childProps = child.props;
|
|
168
|
+
if (childProps == null ? void 0 : childProps.children) {
|
|
169
|
+
const found = findChildRecursive(childProps.children, matcher);
|
|
170
|
+
if (found) {
|
|
171
|
+
return found;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
178
|
+
var findChildByType = (children, type) => {
|
|
179
|
+
return findChildRecursive(
|
|
180
|
+
children,
|
|
181
|
+
(child) => getDisplayName(child) === type
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
var findChildByTypeAndProp = (children, type, propName, propValue) => {
|
|
185
|
+
return findChildRecursive(children, (child) => {
|
|
186
|
+
if (getDisplayName(child) !== type) return false;
|
|
187
|
+
const props = child.props;
|
|
188
|
+
return propName in props && props[propName] === propValue;
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
var findChildIndexByTypeAndProp = (children, type, propName, propValue) => {
|
|
192
|
+
const childrenArray = import_react2.Children.toArray(children);
|
|
193
|
+
return childrenArray.findIndex((child) => {
|
|
194
|
+
if (!import_react2.default.isValidElement(child)) return false;
|
|
195
|
+
const displayName = getDisplayName(child);
|
|
196
|
+
if (displayName !== type) return false;
|
|
197
|
+
const props = child.props;
|
|
198
|
+
return propName in props && props[propName] === propValue;
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
var extractProp = (element, propName, defaultValue) => {
|
|
202
|
+
if (!import_react2.default.isValidElement(element)) {
|
|
203
|
+
return defaultValue;
|
|
204
|
+
}
|
|
205
|
+
const props = element.props;
|
|
206
|
+
return propName in props && props[propName] !== void 0 ? props[propName] : defaultValue;
|
|
207
|
+
};
|
|
208
|
+
var findChildIndices = (children, targetNames) => {
|
|
209
|
+
const indices = {};
|
|
210
|
+
const childrenArray = import_react2.Children.toArray(children);
|
|
211
|
+
childrenArray.forEach((child, index) => {
|
|
212
|
+
if (import_react2.default.isValidElement(child)) {
|
|
213
|
+
const displayName = getDisplayName(child);
|
|
214
|
+
if (displayName && targetNames.includes(displayName)) {
|
|
215
|
+
indices[displayName] = index;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return indices;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/utils/composition.tsx
|
|
223
|
+
var import_react3 = __toESM(require("react"));
|
|
224
|
+
var import_react_box = require("@dt-dds/react-box");
|
|
225
|
+
var import_themes = require("@dt-dds/themes");
|
|
226
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
227
|
+
var areSiblings = (index1, index2) => {
|
|
228
|
+
return Math.abs(index1 - index2) === 1;
|
|
229
|
+
};
|
|
230
|
+
var groupSiblingComponents = (children, componentNames, isMobile, additionalStyles) => {
|
|
231
|
+
const childrenArray = import_react3.default.Children.toArray(children);
|
|
232
|
+
const result = [];
|
|
233
|
+
let i = 0;
|
|
234
|
+
while (i < childrenArray.length) {
|
|
235
|
+
const child = childrenArray[i];
|
|
236
|
+
const nextChild = i + 1 < childrenArray.length ? childrenArray[i + 1] : null;
|
|
237
|
+
if (import_react3.default.isValidElement(child) && import_react3.default.isValidElement(nextChild)) {
|
|
238
|
+
const currentName = getDisplayName(child);
|
|
239
|
+
const nextName = getDisplayName(nextChild);
|
|
240
|
+
const shouldGroup = currentName && nextName && componentNames.includes(currentName) && componentNames.includes(nextName) && areSiblings(i, i + 1);
|
|
241
|
+
if (shouldGroup) {
|
|
242
|
+
result.push(
|
|
243
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
244
|
+
import_react_box.Box,
|
|
245
|
+
{
|
|
246
|
+
style: __spreadValues({
|
|
247
|
+
display: "flex",
|
|
248
|
+
flexWrap: "nowrap",
|
|
249
|
+
flexDirection: isMobile ? "column" : "row",
|
|
250
|
+
alignItems: isMobile ? "flex-start" : "center",
|
|
251
|
+
justifyContent: isMobile ? "center" : "flex-start",
|
|
252
|
+
height: isMobile ? "48px" : "auto",
|
|
253
|
+
gap: isMobile ? import_themes.theme.spacing.spacing_0 : import_themes.theme.spacing.spacing_30
|
|
254
|
+
}, additionalStyles),
|
|
255
|
+
children: [
|
|
256
|
+
child,
|
|
257
|
+
nextChild
|
|
258
|
+
]
|
|
259
|
+
},
|
|
260
|
+
`group-${i}`
|
|
261
|
+
)
|
|
262
|
+
);
|
|
263
|
+
i += 2;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
result.push(child);
|
|
268
|
+
i++;
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
};
|
|
272
|
+
var shouldGroupNavigationAndActions = (state) => {
|
|
273
|
+
if (!state.isNavRight || !state.isActionsPositionRight) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
return state.isCompact || state.isStandard && !state.hasAppName;
|
|
277
|
+
};
|
|
278
|
+
var groupNavigationAndActionsIfSiblings = (children, isMobile, themeInstance) => {
|
|
279
|
+
var _a;
|
|
280
|
+
const normalizedChildren = children;
|
|
281
|
+
const indices = findChildIndices(normalizedChildren, [
|
|
282
|
+
COMPOUND_COMPONENT_NAMES.NAVIGATION,
|
|
283
|
+
COMPOUND_COMPONENT_NAMES.ACTIONS
|
|
284
|
+
]);
|
|
285
|
+
const navIndex = (_a = indices[COMPOUND_COMPONENT_NAMES.NAVIGATION]) != null ? _a : -1;
|
|
286
|
+
const actionsRightIndex = findChildIndexByTypeAndProp(
|
|
287
|
+
normalizedChildren,
|
|
288
|
+
COMPOUND_COMPONENT_NAMES.ACTIONS,
|
|
289
|
+
"position",
|
|
290
|
+
"right"
|
|
291
|
+
);
|
|
292
|
+
const areSiblingsAfterGrouping = navIndex !== -1 && actionsRightIndex !== -1 && areSiblings(navIndex, actionsRightIndex);
|
|
293
|
+
if (!areSiblingsAfterGrouping) {
|
|
294
|
+
return Array.isArray(children) ? children : import_react3.default.Children.toArray(children);
|
|
295
|
+
}
|
|
296
|
+
return groupSiblingComponents(
|
|
297
|
+
normalizedChildren,
|
|
298
|
+
[COMPOUND_COMPONENT_NAMES.NAVIGATION, COMPOUND_COMPONENT_NAMES.ACTIONS],
|
|
299
|
+
isMobile,
|
|
300
|
+
{
|
|
301
|
+
position: "fixed",
|
|
302
|
+
right: themeInstance.spacing.spacing_60
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// src/AppHeader.tsx
|
|
308
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
309
|
+
var AppHeader = (_a) => {
|
|
310
|
+
var _b = _a, {
|
|
311
|
+
type = "standard",
|
|
312
|
+
style,
|
|
313
|
+
children
|
|
314
|
+
} = _b, rest = __objRest(_b, [
|
|
315
|
+
"type",
|
|
316
|
+
"style",
|
|
317
|
+
"children"
|
|
318
|
+
]);
|
|
319
|
+
var _a2, _b2;
|
|
320
|
+
const theme2 = (0, import_react5.useTheme)();
|
|
321
|
+
const isMobile = (0, import_react_core.useMedia)(`(max-width: ${theme2.breakpoints.mq3}px)`);
|
|
322
|
+
const navPosition = extractProp(
|
|
323
|
+
findChildByType(children, COMPOUND_COMPONENT_NAMES.NAVIGATION),
|
|
324
|
+
"position",
|
|
325
|
+
"center"
|
|
326
|
+
);
|
|
327
|
+
const appName = extractProp(
|
|
328
|
+
findChildByType(children, COMPOUND_COMPONENT_NAMES.APP_NAME),
|
|
329
|
+
"name",
|
|
330
|
+
void 0
|
|
331
|
+
);
|
|
332
|
+
const childIndices = findChildIndices(children, [
|
|
333
|
+
COMPOUND_COMPONENT_NAMES.APP_NAME,
|
|
334
|
+
COMPOUND_COMPONENT_NAMES.LOGO,
|
|
335
|
+
COMPOUND_COMPONENT_NAMES.NAVIGATION,
|
|
336
|
+
COMPOUND_COMPONENT_NAMES.ACTIONS
|
|
337
|
+
]);
|
|
338
|
+
const appNameIndex = (_a2 = childIndices[COMPOUND_COMPONENT_NAMES.APP_NAME]) != null ? _a2 : -1;
|
|
339
|
+
const logoIndex = (_b2 = childIndices[COMPOUND_COMPONENT_NAMES.LOGO]) != null ? _b2 : -1;
|
|
340
|
+
const shouldCenterLogoValue = shouldCenterLogo(type, appName);
|
|
341
|
+
const hasAppNameAsSibling = appNameIndex !== -1 && logoIndex !== -1 && areSiblings(appNameIndex, logoIndex);
|
|
342
|
+
const hasActionsPositionRight = findChildByTypeAndProp(
|
|
343
|
+
children,
|
|
344
|
+
COMPOUND_COMPONENT_NAMES.ACTIONS,
|
|
345
|
+
"position",
|
|
346
|
+
"right"
|
|
347
|
+
) !== null;
|
|
348
|
+
const state = computeHeaderState(
|
|
349
|
+
type,
|
|
350
|
+
navPosition,
|
|
351
|
+
appName,
|
|
352
|
+
hasActionsPositionRight
|
|
353
|
+
);
|
|
354
|
+
const contextValue = (0, import_react4.useMemo)(
|
|
355
|
+
() => ({
|
|
356
|
+
state,
|
|
357
|
+
shouldCenterLogo: shouldCenterLogoValue,
|
|
358
|
+
hasAppNameAsSibling,
|
|
359
|
+
isMobile
|
|
360
|
+
}),
|
|
361
|
+
[state, shouldCenterLogoValue, hasAppNameAsSibling, isMobile]
|
|
362
|
+
);
|
|
363
|
+
const processedChildren = (0, import_react4.useMemo)(() => {
|
|
364
|
+
let result = groupSiblingComponents(
|
|
365
|
+
children,
|
|
366
|
+
[COMPOUND_COMPONENT_NAMES.APP_NAME, COMPOUND_COMPONENT_NAMES.LOGO],
|
|
367
|
+
isMobile
|
|
368
|
+
);
|
|
369
|
+
if (shouldGroupNavigationAndActions(state)) {
|
|
370
|
+
result = groupNavigationAndActionsIfSiblings(
|
|
371
|
+
result,
|
|
372
|
+
isMobile,
|
|
373
|
+
theme2
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return result;
|
|
377
|
+
}, [children, state, isMobile, theme2]);
|
|
378
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AppHeaderContextProvider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AppHeaderStyled, __spreadProps(__spreadValues({ isMobile, style }, rest), { children: processedChildren })) });
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// src/components/Actions/Actions.tsx
|
|
382
|
+
var import_react6 = require("@emotion/react");
|
|
383
|
+
var import_react_core3 = require("@dt-dds/react-core");
|
|
384
|
+
|
|
385
|
+
// src/components/Actions/Actions.styled.tsx
|
|
386
|
+
var import_styled2 = __toESM(require("@emotion/styled"));
|
|
387
|
+
var getActionsPosition = (position, state) => {
|
|
388
|
+
if (position === "left") {
|
|
389
|
+
return "relative";
|
|
390
|
+
}
|
|
391
|
+
if (state.isNavRight) {
|
|
392
|
+
return state.isStandard && state.hasAppName ? "fixed" : "relative";
|
|
393
|
+
}
|
|
394
|
+
return "fixed";
|
|
395
|
+
};
|
|
396
|
+
var getActionsRight = (theme2, position, state) => {
|
|
397
|
+
if (position === "left") {
|
|
398
|
+
return "auto";
|
|
399
|
+
}
|
|
400
|
+
const defaultRight = theme2.spacing.spacing_60;
|
|
401
|
+
if (state.isNavRight) {
|
|
402
|
+
return state.isStandard && state.hasAppName ? defaultRight : 0;
|
|
403
|
+
}
|
|
404
|
+
return defaultRight;
|
|
405
|
+
};
|
|
406
|
+
var getActionsMinWidth = (state, position) => {
|
|
407
|
+
if (position === "left") {
|
|
408
|
+
return "auto";
|
|
409
|
+
}
|
|
410
|
+
const { isNavLeft, isStandard, hasAppName } = state;
|
|
411
|
+
return isNavLeft && isStandard && !hasAppName ? "auto" : THIRD_WIDTH;
|
|
412
|
+
};
|
|
413
|
+
var ActionsContainer = import_styled2.default.div`
|
|
414
|
+
${({ theme: theme2, state, position = "right" }) => {
|
|
415
|
+
const cssPosition = getActionsPosition(position, state);
|
|
416
|
+
const right = getActionsRight(theme2, position, state);
|
|
417
|
+
const minWidth = getActionsMinWidth(state, position);
|
|
418
|
+
return `
|
|
419
|
+
display: flex;
|
|
420
|
+
align-items: center;
|
|
421
|
+
position: ${cssPosition};
|
|
422
|
+
right: ${right};
|
|
423
|
+
min-width: ${minWidth};
|
|
424
|
+
flex-direction: row;
|
|
425
|
+
justify-content: ${position === "left" ? "flex-start" : "flex-end"};
|
|
426
|
+
gap: ${theme2.spacing.spacing_50};
|
|
427
|
+
`;
|
|
428
|
+
}}
|
|
429
|
+
`;
|
|
430
|
+
|
|
431
|
+
// src/utils/responsive.tsx
|
|
432
|
+
var import_react_core2 = require("@dt-dds/react-core");
|
|
433
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
434
|
+
var withResponsive = (Component) => {
|
|
435
|
+
const ResponsiveComponent = (props) => {
|
|
436
|
+
const hideMatches = (0, import_react_core2.useMedia)(props.hide || "(max-width: 0px)");
|
|
437
|
+
const showMatches = (0, import_react_core2.useMedia)(props.show || "(max-width: 0px)");
|
|
438
|
+
if (props.hide && hideMatches) return null;
|
|
439
|
+
if (props.show && !showMatches) return null;
|
|
440
|
+
const _a = props, { hide, show } = _a, componentProps = __objRest(_a, ["hide", "show"]);
|
|
441
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component, __spreadValues({}, componentProps));
|
|
442
|
+
};
|
|
443
|
+
ResponsiveComponent.displayName = Component.displayName || Component.name || "Component";
|
|
444
|
+
return ResponsiveComponent;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/components/Actions/Actions.tsx
|
|
448
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
449
|
+
var ActionsBase = (_a) => {
|
|
450
|
+
var _b = _a, {
|
|
451
|
+
children,
|
|
452
|
+
position = "right"
|
|
453
|
+
} = _b, rest = __objRest(_b, [
|
|
454
|
+
"children",
|
|
455
|
+
"position"
|
|
456
|
+
]);
|
|
457
|
+
const theme2 = (0, import_react6.useTheme)();
|
|
458
|
+
const isMobile = (0, import_react_core3.useMedia)(`(max-width: ${theme2.breakpoints.mq3}px)`);
|
|
459
|
+
const { state } = useAppHeaderContext();
|
|
460
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
461
|
+
ActionsContainer,
|
|
462
|
+
__spreadProps(__spreadValues({
|
|
463
|
+
isMobile,
|
|
464
|
+
position,
|
|
465
|
+
state
|
|
466
|
+
}, rest), {
|
|
467
|
+
children
|
|
468
|
+
})
|
|
469
|
+
);
|
|
470
|
+
};
|
|
471
|
+
ActionsBase.displayName = "AppHeader.Actions";
|
|
472
|
+
var Actions = withResponsive(ActionsBase);
|
|
473
|
+
|
|
474
|
+
// src/components/AppName/AppName.tsx
|
|
475
|
+
var import_react_typography = require("@dt-dds/react-typography");
|
|
476
|
+
|
|
477
|
+
// src/components/AppName/AppName.styled.tsx
|
|
478
|
+
var import_styled3 = __toESM(require("@emotion/styled"));
|
|
479
|
+
var AppNameContainer = import_styled3.default.div`
|
|
480
|
+
${({ theme: theme2, state, isMobile }) => {
|
|
481
|
+
const shouldAlignLeft = isMobile && state.isStandard;
|
|
482
|
+
return `
|
|
483
|
+
display: flex;
|
|
484
|
+
flex-flow: row nowrap;
|
|
485
|
+
align-items: center;
|
|
486
|
+
min-width: auto;
|
|
487
|
+
width: auto;
|
|
488
|
+
max-width: ${APP_NAME_MAX_WIDTH}px;
|
|
489
|
+
max-height: ${APP_NAME_MAX_HEIGHT}px;
|
|
490
|
+
|
|
491
|
+
${shouldAlignLeft ? "justify-content: flex-start;" : ""}
|
|
492
|
+
|
|
493
|
+
@media screen and (min-width: ${theme2.breakpoints.mq3}px) {
|
|
494
|
+
max-width: ${APP_NAME_MAX_WIDTH_DESKTOP}px;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
> * {
|
|
498
|
+
white-space: nowrap;
|
|
499
|
+
overflow: hidden;
|
|
500
|
+
text-overflow: ellipsis;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
`;
|
|
504
|
+
}}
|
|
505
|
+
`;
|
|
506
|
+
|
|
507
|
+
// src/components/AppName/AppName.tsx
|
|
508
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
509
|
+
var AppNameBase = (_a) => {
|
|
510
|
+
var _b = _a, {
|
|
511
|
+
name,
|
|
512
|
+
children
|
|
513
|
+
} = _b, rest = __objRest(_b, [
|
|
514
|
+
"name",
|
|
515
|
+
"children"
|
|
516
|
+
]);
|
|
517
|
+
const { state, isMobile } = useAppHeaderContext();
|
|
518
|
+
const isStandardFontStyles = state.isStandard ? "h5" : "h5Bold";
|
|
519
|
+
const fontStyles = !isMobile ? isStandardFontStyles : "h6Bold";
|
|
520
|
+
const content = children != null ? children : name;
|
|
521
|
+
if (!content) {
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
if (children) {
|
|
525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AppNameContainer, __spreadProps(__spreadValues({ isMobile, state }, rest), { children: content }));
|
|
526
|
+
}
|
|
527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AppNameContainer, __spreadProps(__spreadValues({ isMobile, state }, rest), { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
528
|
+
import_react_typography.Typography,
|
|
529
|
+
{
|
|
530
|
+
color: "primary.default",
|
|
531
|
+
element: "span",
|
|
532
|
+
fontStyles,
|
|
533
|
+
children: content
|
|
534
|
+
}
|
|
535
|
+
) }));
|
|
536
|
+
};
|
|
537
|
+
AppNameBase.displayName = "AppHeader.AppName";
|
|
538
|
+
var AppName = withResponsive(AppNameBase);
|
|
539
|
+
|
|
540
|
+
// src/components/Logo/Logo.styled.tsx
|
|
541
|
+
var import_styled4 = __toESM(require("@emotion/styled"));
|
|
542
|
+
var LogoContainer = import_styled4.default.div`
|
|
543
|
+
${({ shouldCenterLogo: shouldCenterLogo2 }) => {
|
|
544
|
+
const centerLogoStyles = `
|
|
545
|
+
width: auto;
|
|
546
|
+
min-width: auto;
|
|
547
|
+
margin: 0 auto;
|
|
548
|
+
position: absolute;
|
|
549
|
+
left: 50%;
|
|
550
|
+
transform: translateX(-50%);
|
|
551
|
+
`;
|
|
552
|
+
return `
|
|
553
|
+
display: flex;
|
|
554
|
+
flex-flow: row nowrap;
|
|
555
|
+
align-items: center;
|
|
556
|
+
min-width: auto;
|
|
557
|
+
height: auto;
|
|
558
|
+
|
|
559
|
+
img,
|
|
560
|
+
[data-nextjs-image],
|
|
561
|
+
svg,
|
|
562
|
+
> * {
|
|
563
|
+
display: flex;
|
|
564
|
+
max-height: ${LOGO_MAX_HEIGHT}px;
|
|
565
|
+
width: auto;
|
|
566
|
+
height: auto;
|
|
567
|
+
object-fit: contain;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
${shouldCenterLogo2 ? centerLogoStyles : ""}
|
|
571
|
+
`;
|
|
572
|
+
}}
|
|
573
|
+
`;
|
|
574
|
+
|
|
575
|
+
// src/components/Logo/Logo.tsx
|
|
576
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
577
|
+
var LogoBase = (_a) => {
|
|
578
|
+
var _b = _a, {
|
|
579
|
+
children
|
|
580
|
+
} = _b, rest = __objRest(_b, [
|
|
581
|
+
"children"
|
|
582
|
+
]);
|
|
583
|
+
const { shouldCenterLogo: shouldCenterLogo2, isMobile } = useAppHeaderContext();
|
|
584
|
+
const shouldCenter = shouldCenterLogo2 && !isMobile;
|
|
585
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LogoContainer, __spreadProps(__spreadValues({ shouldCenterLogo: shouldCenter }, rest), { children }));
|
|
586
|
+
};
|
|
587
|
+
LogoBase.displayName = "AppHeader.Logo";
|
|
588
|
+
var Logo = withResponsive(LogoBase);
|
|
589
|
+
|
|
590
|
+
// src/components/Navigation/Navigation.styled.ts
|
|
591
|
+
var import_styled5 = __toESM(require("@emotion/styled"));
|
|
592
|
+
var CENTERING_STYLES = {
|
|
593
|
+
absoluteCenter: `
|
|
594
|
+
position: absolute;
|
|
595
|
+
left: 50%;
|
|
596
|
+
top: 50%;
|
|
597
|
+
transform: translate(-50%, -50%);
|
|
598
|
+
width: auto;
|
|
599
|
+
max-width: calc(100% - 400px); // hardcoded value to avoid layout shift
|
|
600
|
+
min-width: 0;
|
|
601
|
+
overflow: hidden;
|
|
602
|
+
`,
|
|
603
|
+
autoMargins: `
|
|
604
|
+
margin-left: auto;
|
|
605
|
+
margin-right: auto;
|
|
606
|
+
`
|
|
607
|
+
};
|
|
608
|
+
var shouldUseAbsoluteCenter = (state) => {
|
|
609
|
+
if (!state.isNavCenter) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
return state.isNavCompact || !state.hasAppName;
|
|
613
|
+
};
|
|
614
|
+
var getNavigationCenteringStyles = (state) => {
|
|
615
|
+
if (!shouldUseAbsoluteCenter(state)) {
|
|
616
|
+
return state.isNavCenter ? CENTERING_STYLES.autoMargins : "";
|
|
617
|
+
}
|
|
618
|
+
return CENTERING_STYLES.absoluteCenter;
|
|
619
|
+
};
|
|
620
|
+
var getJustifyContent = (isAbsoluteCenter, isNavLeft, isNavRight) => {
|
|
621
|
+
if (isAbsoluteCenter) {
|
|
622
|
+
return "center";
|
|
623
|
+
}
|
|
624
|
+
if (isNavLeft) {
|
|
625
|
+
return "flex-start";
|
|
626
|
+
}
|
|
627
|
+
if (isNavRight) {
|
|
628
|
+
return "flex-end";
|
|
629
|
+
}
|
|
630
|
+
return "center";
|
|
631
|
+
};
|
|
632
|
+
var NavigationStyled = import_styled5.default.nav`
|
|
633
|
+
${({ theme: theme2, state }) => {
|
|
634
|
+
const { isStandard, hasAppName, isNavCompact, isNavLeft, isNavRight } = state;
|
|
635
|
+
const isStandardAndHasAppName = isStandard && hasAppName;
|
|
636
|
+
const isAbsoluteCenter = shouldUseAbsoluteCenter(state);
|
|
637
|
+
const basePosition = isStandardAndHasAppName ? "fixed" : "relative";
|
|
638
|
+
const baseTop = isNavCompact ? 0 : `${HEADER_HEIGHT}px`;
|
|
639
|
+
const baseWidth = isNavCompact ? "auto" : "100%";
|
|
640
|
+
const minHeight = isNavCompact ? "auto" : `${NAVIGATION_HEIGHT}px`;
|
|
641
|
+
const position = isAbsoluteCenter ? "absolute" : basePosition;
|
|
642
|
+
const top = isAbsoluteCenter ? "50%" : baseTop;
|
|
643
|
+
const left = isAbsoluteCenter ? "50%" : "0";
|
|
644
|
+
const right = isAbsoluteCenter ? "auto" : "0";
|
|
645
|
+
const width = isAbsoluteCenter ? "auto" : baseWidth;
|
|
646
|
+
const justifyContent = getJustifyContent(
|
|
647
|
+
isAbsoluteCenter,
|
|
648
|
+
isNavLeft,
|
|
649
|
+
isNavRight
|
|
650
|
+
);
|
|
651
|
+
const centeringStyles = getNavigationCenteringStyles(state);
|
|
652
|
+
return `
|
|
653
|
+
position: ${position};
|
|
654
|
+
top: ${top};
|
|
655
|
+
left: ${left};
|
|
656
|
+
right: ${right};
|
|
657
|
+
z-index: ${APP_HEADER_Z_INDEX};
|
|
658
|
+
width: ${width};
|
|
659
|
+
min-height: ${minHeight};
|
|
660
|
+
height: auto;
|
|
661
|
+
background-color: ${theme2.palette.surface.contrast};
|
|
662
|
+
display: flex;
|
|
663
|
+
flex-flow: row nowrap;
|
|
664
|
+
align-items: center;
|
|
665
|
+
justify-content: ${justifyContent};
|
|
666
|
+
padding: 0 ${theme2.spacing.spacing_60};
|
|
667
|
+
|
|
668
|
+
${centeringStyles}
|
|
669
|
+
`;
|
|
670
|
+
}}
|
|
671
|
+
`;
|
|
672
|
+
|
|
673
|
+
// src/components/Navigation/Navigation.tsx
|
|
674
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
675
|
+
var NavigationBase = (_a) => {
|
|
676
|
+
var _b = _a, {
|
|
677
|
+
children
|
|
678
|
+
} = _b, rest = __objRest(_b, [
|
|
679
|
+
"children"
|
|
680
|
+
]);
|
|
681
|
+
const { state } = useAppHeaderContext();
|
|
682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(NavigationStyled, __spreadProps(__spreadValues({ state }, rest), { children }));
|
|
683
|
+
};
|
|
684
|
+
NavigationBase.displayName = "AppHeader.Navigation";
|
|
685
|
+
var Navigation = withResponsive(NavigationBase);
|
|
686
|
+
|
|
687
|
+
// src/index.ts
|
|
688
|
+
var AppHeader2 = Object.assign(
|
|
689
|
+
AppHeader,
|
|
690
|
+
{
|
|
691
|
+
Logo,
|
|
692
|
+
AppName,
|
|
693
|
+
Navigation,
|
|
694
|
+
Actions
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
698
|
+
0 && (module.exports = {
|
|
699
|
+
Actions,
|
|
700
|
+
AppHeader,
|
|
701
|
+
AppName,
|
|
702
|
+
Logo,
|
|
703
|
+
Navigation
|
|
704
|
+
});
|