@dvrd/dvr-controls 1.0.14 → 1.0.16
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/index.ts +8 -1
- package/package.json +29 -23
- package/src/js/button/button.tsx +102 -0
- package/src/js/button/buttonController.tsx +179 -0
- package/src/js/button/closeButton.tsx +29 -0
- package/src/js/button/dvrdButton.tsx +128 -0
- package/src/js/button/outlinedButton.tsx +105 -0
- package/src/js/button/simpleButton.tsx +163 -0
- package/src/js/button/style/button.scss +95 -0
- package/src/js/button/style/closeButton.scss +15 -0
- package/src/js/button/style/dvrdButton.scss +30 -0
- package/src/js/button/style/outlinedButton.scss +84 -0
- package/src/js/button/style/simpleButton.scss +80 -0
- package/src/js/carousel/DVRCarousel.tsx +163 -0
- package/src/js/carousel/DVRCarouselController.tsx +95 -0
- package/src/js/carousel/style/DVRCarousel.scss +38 -0
- package/src/js/checkbox/checkbox.tsx +148 -0
- package/src/js/checkbox/checkboxController.tsx +131 -0
- package/src/js/checkbox/style/checkbox.scss +109 -0
- package/src/js/colorPicker/colorPicker.tsx +118 -0
- package/src/js/colorPicker/style/colorPicker.scss +20 -0
- package/src/js/date/dvrdDatePicker.tsx +357 -0
- package/src/js/date/style/dvrdDatePicker.scss +307 -0
- package/src/js/dialog/dialog.tsx +207 -0
- package/src/js/dialog/dialogController.tsx +70 -0
- package/src/js/dialog/inlineDialog.tsx +127 -0
- package/src/js/dialog/style/dialog.scss +61 -0
- package/src/js/events/withEvents.tsx +40 -0
- package/src/js/head/DVRHead.tsx +49 -0
- package/src/js/header/DVRHeader.tsx +417 -0
- package/src/js/header/style/header.scss +206 -0
- package/src/js/icon/awesomeIcon.tsx +20 -0
- package/src/js/image/imageUpload.tsx +69 -0
- package/src/js/image/style/imageUpload.scss +11 -0
- package/src/js/info/info.tsx +136 -0
- package/src/js/info/style/info.scss +39 -0
- package/src/js/input/animated/animatedTextField.tsx +159 -0
- package/src/js/input/date/dateField.tsx +360 -0
- package/src/js/input/date/dateFieldController.tsx +245 -0
- package/src/js/input/date/datePicker/datePicker.tsx +186 -0
- package/src/js/input/date/datePicker/style/datePicker.scss +102 -0
- package/src/js/input/date/input/dateInput.tsx +214 -0
- package/src/js/input/date/style/dateField.scss +40 -0
- package/src/js/input/date/timePicker/style/timePicker.scss +95 -0
- package/src/js/input/date/timePicker/timePicker.tsx +143 -0
- package/src/js/input/editor/DVREditor.tsx +21 -0
- package/src/js/input/number/numberInput.tsx +157 -0
- package/src/js/input/password/passwordInput.tsx +140 -0
- package/src/js/input/password/passwordRules.tsx +48 -0
- package/src/js/input/password/style/passwordInput.scss +39 -0
- package/src/js/input/password/style/passwordRules.scss +41 -0
- package/src/js/input/simple/style/simpleInput.scss +98 -0
- package/src/js/input/simple/v2/simpleInputV2.tsx +178 -0
- package/src/js/input/style/input.scss +138 -0
- package/src/js/input/v2/inputController_v2.tsx +250 -0
- package/src/js/input/v2/input_v2.tsx +7 -0
- package/src/js/label/label.tsx +196 -0
- package/src/js/label/style/label.scss +4 -0
- package/src/js/link/link.tsx +38 -0
- package/src/js/link/style/link.scss +30 -0
- package/src/js/loader/loader.tsx +79 -0
- package/src/js/loader/loaderController.tsx +61 -0
- package/src/js/loader/style/loader.scss +53 -0
- package/src/js/media/media.tsx +72 -0
- package/src/js/navigator/navigator.tsx +51 -0
- package/src/js/optionsList/dvrdOptionsList.tsx +112 -0
- package/src/js/optionsList/style/dvrdOptionsList.scss +84 -0
- package/src/js/optionsMenu/optionsMenu.tsx +187 -0
- package/src/js/optionsMenu/style/optionsMenu.scss +70 -0
- package/src/js/pdf/element/pdfElement.tsx +315 -0
- package/src/js/pdf/element/style/pdfElement.scss +111 -0
- package/src/js/pdf/history/pdfHistory.ts +57 -0
- package/src/js/pdf/image/pdfImage.tsx +175 -0
- package/src/js/pdf/image/style/pdfImage.scss +34 -0
- package/src/js/pdf/invoiceTable/pdfInvoiceTable.tsx +176 -0
- package/src/js/pdf/invoiceTable/style/pdfInvoiceTable.scss +32 -0
- package/src/js/pdf/pdfTemplateCreator.tsx +279 -0
- package/src/js/pdf/settings/buttons/iconButton.tsx +49 -0
- package/src/js/pdf/settings/buttons/style/iconButton.scss +50 -0
- package/src/js/pdf/settings/image/pdfImageSettings.tsx +82 -0
- package/src/js/pdf/settings/image/style/pdfImageSettings.scss +9 -0
- package/src/js/pdf/settings/invoiceTable/pdfInvoiceTableSettings.tsx +141 -0
- package/src/js/pdf/settings/invoiceTable/style/pdfInvoiceTableSettings.scss +38 -0
- package/src/js/pdf/settings/pdfElementSettings.tsx +86 -0
- package/src/js/pdf/settings/style/pdfElementSettings.scss +56 -0
- package/src/js/pdf/settings/text/pdfTextSettings.tsx +202 -0
- package/src/js/pdf/settings/text/style/pdfTextSettings.scss +94 -0
- package/src/js/pdf/style/pdfTemplateCreator.scss +118 -0
- package/src/js/pdf/text/pdfText.tsx +267 -0
- package/src/js/pdf/text/style/pdfText.scss +22 -0
- package/src/js/pdf/v2/pdfElement/pdfDraggableElement.tsx +193 -0
- package/src/js/pdf/v2/types/pdfTemplateTypes.ts +27 -0
- package/src/js/popup/style/withBackground.scss +29 -0
- package/src/js/popup/withBackground.tsx +92 -0
- package/src/js/select/async/asyncSelect.tsx +46 -0
- package/src/js/select/async/style/asyncSelect.scss +23 -0
- package/src/js/select/dvrdSelect.tsx +214 -0
- package/src/js/select/dvrdSelectController.tsx +81 -0
- package/src/js/select/select.tsx +310 -0
- package/src/js/select/selectController.tsx +341 -0
- package/src/js/select/style/dvrdSelect.scss +140 -0
- package/src/js/select/style/select.scss +199 -0
- package/src/js/sidebarMenu/sidebarMenu.tsx +167 -0
- package/src/js/sidebarMenu/style/sidebarMenu.scss +167 -0
- package/src/js/slider/DVRSlider.tsx +107 -0
- package/src/js/slider/style/DVRSlider.scss +88 -0
- package/src/js/snackbar/snackbar.tsx +72 -0
- package/src/js/snackbar/snackbarController.tsx +104 -0
- package/src/js/snackbar/style/snackbar.scss +46 -0
- package/src/js/switch/dvrdSwitch.tsx +53 -0
- package/src/js/switch/style/dvrdSwitch.scss +47 -0
- package/src/js/switch/style/switch.scss +84 -0
- package/src/js/switch/switch.tsx +115 -0
- package/src/js/switch/switchController.tsx +97 -0
- package/src/js/textField/dvrdInput.tsx +219 -0
- package/src/js/textField/dvrdInputController.tsx +97 -0
- package/src/js/textField/dvrdNumberInput.tsx +141 -0
- package/src/js/textField/dvrdPasswordInput.tsx +40 -0
- package/src/js/textField/style/dvrdInput.scss +114 -0
- package/src/js/textField/style/dvrdPassword.scss +15 -0
- package/src/js/topButton/style/topButton.scss +54 -0
- package/src/js/topButton/topButton.tsx +136 -0
- package/src/js/util/analyticsUtil.ts +41 -0
- package/src/js/util/colorUtil.ts +230 -0
- package/src/js/util/componentUtil.tsx +59 -0
- package/src/js/util/constants.ts +12 -0
- package/src/js/util/controlContext.tsx +46 -0
- package/src/js/util/controlUtil.ts +107 -0
- package/src/js/util/cookieUtil.ts +17 -0
- package/src/js/util/eventUtil.ts +65 -0
- package/src/js/util/googleUtil.ts +88 -0
- package/src/js/util/interfaces.ts +180 -0
- package/src/js/util/jwtUtil.ts +72 -0
- package/src/js/util/miscUtil.ts +170 -0
- package/src/js/util/momentUtil.ts +45 -0
- package/src/js/util/pdfUtil.ts +124 -0
- package/src/js/util/requestUtil.ts +145 -0
- package/src/js/util/responsiveUtil.ts +37 -0
- package/src/js/util/validationUtil.ts +13 -0
- package/src/res/img/lock-handle.png +0 -0
- package/src/res/img/lock-handle.webp +0 -0
- package/src/res/img/lock.png +0 -0
- package/src/res/img/lock.webp +0 -0
- package/src/style/common-icons-variables.scss +140 -0
- package/src/style/common-icons.scss +714 -0
- package/src/style/common-variables.scss +243 -0
- package/src/style/display-breakpoints.scss +141 -0
- package/src/style/fonts/common-icons.eot +0 -0
- package/src/style/fonts/common-icons.svg +150 -0
- package/src/style/fonts/common-icons.ttf +0 -0
- package/src/style/fonts/common-icons.woff +0 -0
- package/src/style/fonts/common-icons.woff2 +0 -0
- package/src/style/fonts/fontAwesome/css/all.css +7003 -0
- package/src/style/fonts/fontAwesome/css/all.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/brands.css +1423 -0
- package/src/style/fonts/fontAwesome/css/brands.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/fontawesome.css +5519 -0
- package/src/style/fonts/fontAwesome/css/fontawesome.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/regular.css +19 -0
- package/src/style/fonts/fontAwesome/css/regular.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/solid.css +19 -0
- package/src/style/fonts/fontAwesome/css/solid.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/svg-with-js.css +634 -0
- package/src/style/fonts/fontAwesome/css/svg-with-js.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/v4-font-face.css +26 -0
- package/src/style/fonts/fontAwesome/css/v4-font-face.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/v4-shims.css +2146 -0
- package/src/style/fonts/fontAwesome/css/v4-shims.min.css +6 -0
- package/src/style/fonts/fontAwesome/css/v5-font-face.css +22 -0
- package/src/style/fonts/fontAwesome/css/v5-font-face.min.css +6 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.ttf +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.woff2 +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.ttf +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.woff2 +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.ttf +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.woff2 +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.ttf +0 -0
- package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.woff2 +0 -0
- package/src/style/variables.scss +11 -0
- package/.gitignore +0 -31
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import './style/header.scss';
|
|
6
|
+
|
|
7
|
+
import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
|
|
8
|
+
import classNames from "classnames";
|
|
9
|
+
import {hasHover, remToPx} from "../util/controlUtil";
|
|
10
|
+
import {AwesomeIcon, convertColor, directTimeout, generateComponentId, voidFunction} from "../../../";
|
|
11
|
+
import {ControlContext} from "../util/controlContext";
|
|
12
|
+
import TopButton, {TopButtonProps} from "../topButton/topButton";
|
|
13
|
+
import {getScreenWidth} from '../util/responsiveUtil';
|
|
14
|
+
import { IconName } from '@fortawesome/fontawesome-svg-core';
|
|
15
|
+
|
|
16
|
+
export interface HeaderItem {
|
|
17
|
+
label?: string;
|
|
18
|
+
component?: React.ReactElement;
|
|
19
|
+
icon?: IconName | React.ReactElement;
|
|
20
|
+
iconOnly?: boolean;
|
|
21
|
+
forceBar?: boolean;
|
|
22
|
+
onClick: MouseEventHandler | null;
|
|
23
|
+
route?: string;
|
|
24
|
+
customClass?: string;
|
|
25
|
+
children?: HeaderItem[];
|
|
26
|
+
id?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface RenderAble {
|
|
30
|
+
toRender: React.ReactNode;
|
|
31
|
+
clickHandler: MouseEventHandler | null;
|
|
32
|
+
children?: RenderAble[];
|
|
33
|
+
isComp: boolean;
|
|
34
|
+
id?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Props {
|
|
38
|
+
items: HeaderItem[];
|
|
39
|
+
forcedMenu: boolean;
|
|
40
|
+
forceHeader: boolean;
|
|
41
|
+
containerClass: string;
|
|
42
|
+
menuContainerClass: string;
|
|
43
|
+
id?: string;
|
|
44
|
+
transparent: boolean;
|
|
45
|
+
fix: boolean;
|
|
46
|
+
leftMenuComp?: React.ReactNode;
|
|
47
|
+
headerColor?: string;
|
|
48
|
+
headerLabelColor?: string;
|
|
49
|
+
menuColor?: string;
|
|
50
|
+
menuLabelColor?: string;
|
|
51
|
+
topControl: boolean;
|
|
52
|
+
topControlProps?: Partial<TopButtonProps>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface State {
|
|
56
|
+
phase: Phase;
|
|
57
|
+
menuOpen: boolean;
|
|
58
|
+
openSubMenus: string[];
|
|
59
|
+
headerHeight: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
enum Phase {HEADER = 'header', MENU = 'menu', CALCULATING = 'calculating'}
|
|
63
|
+
|
|
64
|
+
const RESIZE_TIMEOUT = Math.ceil(1000 / 120); // 30 fps
|
|
65
|
+
|
|
66
|
+
export default class DVRHeader extends PureComponent<Props, State> {
|
|
67
|
+
declare context: React.ContextType<typeof ControlContext>;
|
|
68
|
+
static contextType = ControlContext;
|
|
69
|
+
|
|
70
|
+
static defaultProps = {
|
|
71
|
+
forcedMenu: false,
|
|
72
|
+
forceHeader: false,
|
|
73
|
+
containerClass: '',
|
|
74
|
+
menuContainerClass: '',
|
|
75
|
+
transparent: false,
|
|
76
|
+
fix: false,
|
|
77
|
+
topControl: false,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
validateProps = (items: HeaderItem[]) => {
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
const canRender = item.label !== undefined || item.component !== undefined || item.icon !== undefined,
|
|
83
|
+
canClick = item.route !== undefined || item.onClick !== undefined,
|
|
84
|
+
usesValidIcon = !item.iconOnly || item.icon !== undefined;
|
|
85
|
+
if (!canRender) throw new TypeError(
|
|
86
|
+
`Cannot render header item without label, component or icon. Invalid item: ${item}`);
|
|
87
|
+
if (!canClick) throw new TypeError(
|
|
88
|
+
`Item can not process click events without route or onClick. invalid item: ${item}`);
|
|
89
|
+
if (!usesValidIcon) throw new TypeError(`Item is forced to use non-existing icon. Invalid item: ${item}`);
|
|
90
|
+
if (item.children && item.children.length)
|
|
91
|
+
this.validateProps(item.children);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
prepIds = (items: HeaderItem[]) => {
|
|
96
|
+
for (const item of items) item.id = generateComponentId(item.id);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
constructor(props: Props) {
|
|
100
|
+
super(props);
|
|
101
|
+
this.validateProps(props.items);
|
|
102
|
+
this.prepIds(props.items);
|
|
103
|
+
const phase = props.forceHeader ? Phase.HEADER : props.forcedMenu ? Phase.MENU : Phase.CALCULATING;
|
|
104
|
+
this.state = {
|
|
105
|
+
phase,
|
|
106
|
+
menuOpen: false,
|
|
107
|
+
openSubMenus: [],
|
|
108
|
+
headerHeight: remToPx(4),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
menu: HTMLDivElement | null = null;
|
|
113
|
+
id: string = generateComponentId(this.props.id);
|
|
114
|
+
handlingResize: boolean = false;
|
|
115
|
+
resizeTimeout: number | null = null;
|
|
116
|
+
lastKnownHeaderWidth: number = 0;
|
|
117
|
+
lastKnownScreenWidth: number = getScreenWidth(true);
|
|
118
|
+
|
|
119
|
+
onClickBars = () => {
|
|
120
|
+
const {menuOpen} = this.state;
|
|
121
|
+
if (menuOpen) this.closeMenu();
|
|
122
|
+
else this.openMenu();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
onClick = () => {
|
|
126
|
+
if (!this.menu || !hasHover(this.menu)) this.closeMenu();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
closeMenu = () => {
|
|
130
|
+
this.setState({menuOpen: false, openSubMenus: []}, this.removeClickListener)
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
onClickChild = (item: RenderAble) => (evt: React.MouseEvent) => {
|
|
134
|
+
evt.stopPropagation();
|
|
135
|
+
if (item.clickHandler)
|
|
136
|
+
item.clickHandler(evt);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
onClickMenuItem = (item: RenderAble) => (evt: React.MouseEvent) => {
|
|
140
|
+
if (item.children && item.id) {
|
|
141
|
+
const openSubMenus = this.state.openSubMenus.slice();
|
|
142
|
+
if (openSubMenus.includes(item.id)) openSubMenus.splice(openSubMenus.indexOf(item.id), 1);
|
|
143
|
+
else openSubMenus.push(item.id);
|
|
144
|
+
this.setState({openSubMenus});
|
|
145
|
+
} else {
|
|
146
|
+
if (item.clickHandler)
|
|
147
|
+
item.clickHandler(evt);
|
|
148
|
+
if (this.state.phase === Phase.MENU)
|
|
149
|
+
this.closeMenu();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
getBaseColor = (): string => convertColor(this.context.baseColor);
|
|
154
|
+
getContrastColor = (): string => convertColor(this.context.contrastColor);
|
|
155
|
+
|
|
156
|
+
getHeaderStyle = (): CSSProperties => {
|
|
157
|
+
const {transparent, headerColor} = this.props, baseColor = this.getBaseColor();
|
|
158
|
+
let backgroundColor: string;
|
|
159
|
+
if (headerColor && headerColor.length) backgroundColor = headerColor;
|
|
160
|
+
else if (transparent) backgroundColor = 'transparent';
|
|
161
|
+
else backgroundColor = baseColor;
|
|
162
|
+
return {backgroundColor};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
getHeaderLabelStyle = (): CSSProperties => {
|
|
166
|
+
const {transparent, headerLabelColor} = this.props, contrastColor = this.getContrastColor();
|
|
167
|
+
let color: string;
|
|
168
|
+
if (headerLabelColor) color = headerLabelColor;
|
|
169
|
+
else if (transparent) color = '#3a4044';
|
|
170
|
+
else color = contrastColor;
|
|
171
|
+
return {color};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
openMenu = () => {
|
|
175
|
+
this.setState({menuOpen: true}, this.addClickListener);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
removeClickListener = () => {
|
|
179
|
+
document.removeEventListener('click', this.onClick);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
addClickListener = () => {
|
|
183
|
+
document.addEventListener('click', this.onClick);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
resizeListener = () => {
|
|
187
|
+
if (!this.handlingResize) {
|
|
188
|
+
this.handlingResize = true;
|
|
189
|
+
this.determineType();
|
|
190
|
+
this.resizeTimeout = window.setTimeout(() => {
|
|
191
|
+
this.handlingResize = false;
|
|
192
|
+
this.resizeTimeout = null;
|
|
193
|
+
}, RESIZE_TIMEOUT)
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
determineType = (initial: boolean = false) => {
|
|
198
|
+
if (this.props.forceHeader || this.props.forcedMenu) return;
|
|
199
|
+
const container = document.getElementById(this.id), currentPhase = this.state.phase,
|
|
200
|
+
screenWidth = getScreenWidth(true);
|
|
201
|
+
if (screenWidth === this.lastKnownScreenWidth && !initial) return;
|
|
202
|
+
this.lastKnownScreenWidth = screenWidth;
|
|
203
|
+
let phase: Phase.HEADER | Phase.MENU = Phase.HEADER;
|
|
204
|
+
if (container) {
|
|
205
|
+
const box = container.getBoundingClientRect(), width = box.width;
|
|
206
|
+
if (currentPhase === Phase.CALCULATING) {
|
|
207
|
+
if (width > screenWidth) {
|
|
208
|
+
phase = Phase.MENU;
|
|
209
|
+
this.lastKnownHeaderWidth = width;
|
|
210
|
+
} else phase = Phase.HEADER;
|
|
211
|
+
} else if (currentPhase === Phase.MENU) {
|
|
212
|
+
if (screenWidth >= this.lastKnownHeaderWidth) phase = Phase.HEADER;
|
|
213
|
+
else phase = Phase.MENU;
|
|
214
|
+
} else if (currentPhase === Phase.HEADER) {
|
|
215
|
+
if (screenWidth < width) {
|
|
216
|
+
this.lastKnownHeaderWidth = width;
|
|
217
|
+
phase = Phase.MENU;
|
|
218
|
+
} else phase = Phase.HEADER;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (currentPhase !== phase) this.setState({phase});
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
getHeaderItems = (): RenderAble[] => {
|
|
225
|
+
const {phase} = this.state, {items} = this.props;
|
|
226
|
+
if (phase !== Phase.MENU) return items.map(this.createHeaderRenderAble);
|
|
227
|
+
return items.filter((item: HeaderItem) => item.forceBar).map(this.createHeaderRenderAble);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
getMenuItems = (): RenderAble[] => {
|
|
231
|
+
const {items} = this.props;
|
|
232
|
+
return items.filter(item => !item.forceBar).map(this.createMenuRenderAble);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
createHeaderRenderAble = (item: HeaderItem): RenderAble => {
|
|
236
|
+
const {onClick, component, customClass, icon, iconOnly, label} = item,
|
|
237
|
+
renderAble: RenderAble = {
|
|
238
|
+
toRender: null,
|
|
239
|
+
clickHandler: onClick,
|
|
240
|
+
isComp: false,
|
|
241
|
+
}, className = classNames('dvr-header-item', customClass);
|
|
242
|
+
if (iconOnly) {
|
|
243
|
+
if (typeof icon === 'string') renderAble.toRender = <AwesomeIcon name={icon} className={className}/>;
|
|
244
|
+
// Type cast since props are checked by constructor
|
|
245
|
+
else renderAble.toRender = React.cloneElement((icon as React.ReactElement), {className});
|
|
246
|
+
} else if (component !== undefined) {
|
|
247
|
+
renderAble.isComp = true;
|
|
248
|
+
renderAble.toRender = React.cloneElement(component, {className});
|
|
249
|
+
} else renderAble.toRender = <label className={className}>{label}</label>;
|
|
250
|
+
|
|
251
|
+
if (item.children) renderAble.children = item.children.map(this.createHeaderRenderAble);
|
|
252
|
+
return renderAble;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
createMenuRenderAble = (item: HeaderItem): RenderAble => {
|
|
256
|
+
const {onClick, component, customClass, icon, label} = item;
|
|
257
|
+
let className = classNames('dvr-menu-item', customClass);
|
|
258
|
+
const renderAble: RenderAble = {
|
|
259
|
+
toRender: null,
|
|
260
|
+
clickHandler: onClick,
|
|
261
|
+
isComp: false,
|
|
262
|
+
id: item.id,
|
|
263
|
+
};
|
|
264
|
+
if (component) {
|
|
265
|
+
className = classNames('dvr-menu-item', 'full', customClass);
|
|
266
|
+
renderAble.toRender = React.cloneElement(component, {className, containerClass: className});
|
|
267
|
+
renderAble.isComp = true;
|
|
268
|
+
} else if (icon && label) {
|
|
269
|
+
const iconComp = typeof icon === 'string' ?
|
|
270
|
+
<AwesomeIcon key='icon' name={icon} className={className}/> :
|
|
271
|
+
React.cloneElement(icon, {className, key: 'icon'});
|
|
272
|
+
const labelComp = <span key='label' className={className}>{label}</span>;
|
|
273
|
+
renderAble.toRender = [iconComp, labelComp];
|
|
274
|
+
} else if (icon) {
|
|
275
|
+
className = classNames('dvr-menu-item', 'full', customClass);
|
|
276
|
+
renderAble.toRender = typeof icon === 'string' ?
|
|
277
|
+
<AwesomeIcon name={icon} className={className}/> : React.cloneElement(icon, {className});
|
|
278
|
+
} else if (label) {
|
|
279
|
+
className = classNames('dvr-menu-item', 'single', customClass);
|
|
280
|
+
renderAble.toRender = <label className={className}>{label}</label>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (item.children) renderAble.children = item.children.map(this.createMenuRenderAble);
|
|
284
|
+
return renderAble;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
attachRef = (ref: HTMLDivElement) => {
|
|
288
|
+
this.menu = ref;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
getSubMenuHeight = (item: RenderAble): CSSProperties => {
|
|
292
|
+
const {openSubMenus} = this.state;
|
|
293
|
+
let height: number | string = 0;
|
|
294
|
+
if (item.id && openSubMenus.includes(item.id)) {
|
|
295
|
+
const childContainer = document.getElementById(item.id);
|
|
296
|
+
let totalHeight: number = 0;
|
|
297
|
+
if (childContainer) {
|
|
298
|
+
for (const elem of childContainer.querySelectorAll('div.child-item')) {
|
|
299
|
+
totalHeight += elem.getBoundingClientRect().height;
|
|
300
|
+
}
|
|
301
|
+
height = totalHeight + 'px';
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return {height};
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
setHeaderHeight = () => {
|
|
308
|
+
const header = document.getElementById(this.id);
|
|
309
|
+
let height = remToPx(4);
|
|
310
|
+
if (header)
|
|
311
|
+
height = header.getBoundingClientRect().height;
|
|
312
|
+
this.setState({headerHeight: height});
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
renderHeader = () => {
|
|
316
|
+
const {phase} = this.state, {transparent, leftMenuComp} = this.props;
|
|
317
|
+
return (
|
|
318
|
+
<div className={classNames('dvr-header-container', transparent && 'transparent')} id={this.id}
|
|
319
|
+
style={{...this.getHeaderStyle(), ...this.getHeaderLabelStyle()}}>
|
|
320
|
+
<div className='left-container'>
|
|
321
|
+
{phase === Phase.MENU && <AwesomeIcon name='bars' onClick={this.onClickBars}
|
|
322
|
+
className={classNames('menu-bars')}/>}
|
|
323
|
+
{leftMenuComp !== undefined && leftMenuComp}
|
|
324
|
+
</div>
|
|
325
|
+
<div className='items-container'>
|
|
326
|
+
{this.getHeaderItems().map((item: RenderAble, index: number) => (
|
|
327
|
+
<div key={index} className={classNames('header-item-container', item.isComp && 'comp',
|
|
328
|
+
item.clickHandler === null && 'no-click')}
|
|
329
|
+
onClick={item.clickHandler || voidFunction} style={this.getHeaderLabelStyle()}>
|
|
330
|
+
{item.toRender}
|
|
331
|
+
{item.children && this.renderHeaderChildren(item)}
|
|
332
|
+
</div>
|
|
333
|
+
))}
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
)
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
renderHeaderChildren = (item: RenderAble) => {
|
|
340
|
+
if (!item.children) return null;
|
|
341
|
+
return (
|
|
342
|
+
<div className='children-container'>
|
|
343
|
+
{item.children.map((item: RenderAble, index: number) => (
|
|
344
|
+
<div key={index} className='child-item' onClick={this.onClickChild(item)}>
|
|
345
|
+
{item.toRender}
|
|
346
|
+
</div>
|
|
347
|
+
))}
|
|
348
|
+
</div>
|
|
349
|
+
)
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
renderMenu = () => {
|
|
353
|
+
const {phase, menuOpen} = this.state, {
|
|
354
|
+
forcedMenu,
|
|
355
|
+
menuContainerClass
|
|
356
|
+
} = this.props, {headerHeight} = this.state;
|
|
357
|
+
if (phase !== Phase.MENU && !forcedMenu) return null;
|
|
358
|
+
return (
|
|
359
|
+
<div className={classNames('dvr-menu', menuContainerClass, menuOpen && 'open')} ref={this.attachRef}
|
|
360
|
+
style={{top: headerHeight + 'px'}}>
|
|
361
|
+
{this.getMenuItems().map((item: RenderAble, index: number) => (
|
|
362
|
+
<div key={index} className='menu-item-container' onClick={this.onClickMenuItem(item)}>
|
|
363
|
+
{item.toRender}
|
|
364
|
+
{item.children && this.renderMenuChildren(item)}
|
|
365
|
+
</div>
|
|
366
|
+
))}
|
|
367
|
+
</div>
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
renderMenuChildren = (item: RenderAble) => {
|
|
372
|
+
if (!item.children) return null;
|
|
373
|
+
return (
|
|
374
|
+
<div className='children-container' id={item.id} style={this.getSubMenuHeight(item)}>
|
|
375
|
+
{item.children.map((item: RenderAble, index: number) => (
|
|
376
|
+
<div key={index} className='child-item' onClick={this.onClickMenuItem(item)}>
|
|
377
|
+
{item.toRender}
|
|
378
|
+
</div>
|
|
379
|
+
))}
|
|
380
|
+
</div>
|
|
381
|
+
);
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
renderFixedSpace = () => {
|
|
385
|
+
const {fix} = this.props, {headerHeight} = this.state;
|
|
386
|
+
if (!fix) return null;
|
|
387
|
+
return (<div style={{height: headerHeight + 'px'}}/>);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
componentDidMount = () => {
|
|
391
|
+
this.determineType(true);
|
|
392
|
+
window.addEventListener('resize', this.resizeListener);
|
|
393
|
+
directTimeout(this.setHeaderHeight);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
componentWillUnmount = () => {
|
|
397
|
+
this.removeClickListener();
|
|
398
|
+
window.removeEventListener('resize', this.resizeListener);
|
|
399
|
+
if (this.resizeTimeout)
|
|
400
|
+
window.clearTimeout(this.resizeTimeout);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
render = () => {
|
|
404
|
+
const {containerClass, items, fix, topControl, topControlProps} = this.props, {phase} = this.state;
|
|
405
|
+
this.prepIds(items);
|
|
406
|
+
return (
|
|
407
|
+
<>
|
|
408
|
+
{this.renderFixedSpace()}
|
|
409
|
+
<div className={classNames('dvr-header', containerClass, phase, fix && 'fix')}>
|
|
410
|
+
{this.renderHeader()}
|
|
411
|
+
{this.renderMenu()}
|
|
412
|
+
</div>
|
|
413
|
+
{topControl && <TopButton {...topControlProps}/>}
|
|
414
|
+
</>
|
|
415
|
+
)
|
|
416
|
+
};
|
|
417
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@import '../../../style/variables';
|
|
6
|
+
|
|
7
|
+
.dvr-header {
|
|
8
|
+
width: fit-content;
|
|
9
|
+
|
|
10
|
+
&.calculating {
|
|
11
|
+
visibility: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&.menu {
|
|
15
|
+
.dvr-header-container {
|
|
16
|
+
box-shadow: 0 1px 5px 0 rgba(black, 0.2), 0 2px 2px 0 rgba(black, 0.14), 0 3px 1px -2px rgba(black, 0.12) !important;
|
|
17
|
+
padding: .5rem 1rem;
|
|
18
|
+
width: 100vw;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&.header {
|
|
23
|
+
.dvr-header-container {
|
|
24
|
+
min-width: 100vw;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$height: 4rem;
|
|
29
|
+
|
|
30
|
+
.dvr-header-container {
|
|
31
|
+
@include backgroundShadow;
|
|
32
|
+
padding: .5rem 2rem;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: space-between;
|
|
36
|
+
min-height: $height;
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
|
|
39
|
+
.left-container {
|
|
40
|
+
display: grid;
|
|
41
|
+
grid-template-columns: auto auto;
|
|
42
|
+
align-items: center;
|
|
43
|
+
|
|
44
|
+
.menu-bars {
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
padding: 1rem;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.items-container {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
|
|
54
|
+
.header-item-container {
|
|
55
|
+
margin: 0 .6rem;
|
|
56
|
+
padding: .2rem;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
border-bottom: 1px solid transparent;
|
|
59
|
+
transition: border-color .2s ease-in-out;
|
|
60
|
+
position: relative;
|
|
61
|
+
|
|
62
|
+
.children-container {
|
|
63
|
+
@include centerX;
|
|
64
|
+
visibility: hidden;
|
|
65
|
+
opacity: 0;
|
|
66
|
+
transition: visibility .1s ease-in-out, opacity .1s ease-in-out, box-shadow .1s ease-in-out;
|
|
67
|
+
position: absolute;
|
|
68
|
+
top: 100%;
|
|
69
|
+
background-color: white;
|
|
70
|
+
|
|
71
|
+
.child-item {
|
|
72
|
+
padding: .5rem;
|
|
73
|
+
color: $color-gray-header;
|
|
74
|
+
border-bottom: 1px solid $color-gray-4;
|
|
75
|
+
transition: background-color .2s ease-in-out;
|
|
76
|
+
display: flex;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
|
|
79
|
+
label {
|
|
80
|
+
font-size: .9rem;
|
|
81
|
+
color: $color-gray-header;
|
|
82
|
+
font-weight: normal;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:last-child {
|
|
86
|
+
border-bottom: none;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&:hover {
|
|
90
|
+
background-color: $color-gray-6;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&:hover {
|
|
96
|
+
border-color: currentColor;
|
|
97
|
+
|
|
98
|
+
.children-container {
|
|
99
|
+
@include backgroundShadow;
|
|
100
|
+
visibility: visible;
|
|
101
|
+
opacity: 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
label.dvr-header-item {
|
|
106
|
+
font-weight: 500;
|
|
107
|
+
white-space: nowrap;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&.comp {
|
|
111
|
+
border-color: transparent !important;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&.no-click {
|
|
115
|
+
cursor: default;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&.transparent {
|
|
121
|
+
box-shadow: none;
|
|
122
|
+
background-color: transparent;
|
|
123
|
+
|
|
124
|
+
.items-container .header-item-container {
|
|
125
|
+
color: $color-gray-header;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.dvr-menu {
|
|
131
|
+
@include backgroundShadow;
|
|
132
|
+
position: fixed;
|
|
133
|
+
height: 100%;
|
|
134
|
+
top: $height;
|
|
135
|
+
left: 0;
|
|
136
|
+
transform: translateX(-100%);
|
|
137
|
+
box-shadow: 0 1px 5px 0 rgba(black, 0.2), 0 2px 2px 0 rgba(black, 0.14), 0 3px 1px -2px rgba(black, 0.12);
|
|
138
|
+
transition: transform .2s ease-in-out;
|
|
139
|
+
padding: 1rem;
|
|
140
|
+
background-color: $color-gray-header;
|
|
141
|
+
max-width: 100vw;
|
|
142
|
+
box-sizing: border-box;
|
|
143
|
+
z-index: 9999;
|
|
144
|
+
|
|
145
|
+
&, * {
|
|
146
|
+
user-select: none;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.menu-item-container {
|
|
150
|
+
color: $color-gray-header-text;
|
|
151
|
+
padding: .75rem 1rem;
|
|
152
|
+
cursor: pointer;
|
|
153
|
+
transition: background-color .2s ease-in-out;
|
|
154
|
+
border-radius: .25rem;
|
|
155
|
+
display: grid;
|
|
156
|
+
grid-template-columns: 1rem auto;
|
|
157
|
+
grid-column-gap: 1rem;
|
|
158
|
+
|
|
159
|
+
.dvr-menu-item {
|
|
160
|
+
&.full {
|
|
161
|
+
grid-column-start: span 2;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&.single {
|
|
165
|
+
grid-column-start: 2;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.combined-label {
|
|
170
|
+
display: flex;
|
|
171
|
+
align-items: center;
|
|
172
|
+
|
|
173
|
+
span:first-child {
|
|
174
|
+
margin-right: 1rem;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.children-container {
|
|
179
|
+
overflow: hidden;
|
|
180
|
+
height: 0;
|
|
181
|
+
transition: height .2s ease-in-out;
|
|
182
|
+
grid-column-start: 2;
|
|
183
|
+
padding-top: .5rem;
|
|
184
|
+
|
|
185
|
+
.child-item {
|
|
186
|
+
padding: .75rem;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&:hover {
|
|
191
|
+
background-color: darken($color-gray-header, 10%);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
&.open {
|
|
196
|
+
transform: none;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
&.fix {
|
|
201
|
+
position: fixed;
|
|
202
|
+
top: 0;
|
|
203
|
+
left: 0;
|
|
204
|
+
z-index: $z-index-menu + 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
|
|
7
|
+
import {IconName, IconPrefix} from '@fortawesome/fontawesome-svg-core';
|
|
8
|
+
|
|
9
|
+
interface Props extends React.ComponentProps<any>{
|
|
10
|
+
name: IconName;
|
|
11
|
+
prefix?: IconPrefix;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function AwesomeIcon(props: Props) {
|
|
15
|
+
const {name, prefix} = props;
|
|
16
|
+
const iconName = !!prefix ? [prefix, name] as [IconPrefix, IconName] : name;
|
|
17
|
+
return (
|
|
18
|
+
<FontAwesomeIcon {...props} icon={iconName}/>
|
|
19
|
+
);
|
|
20
|
+
}
|