@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,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
import './style/dvrdOptionsList.scss';
|
|
5
|
+
|
|
6
|
+
import {AwesomeIcon, convertColor, directTimeout, editColor, hasHover} from '@dvrd/dvr-controls';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import React, {CSSProperties, MouseEventHandler, useContext, useEffect, useRef, useState} from 'react';
|
|
9
|
+
import {ControlContext} from "../util/controlContext";
|
|
10
|
+
|
|
11
|
+
type Option = {
|
|
12
|
+
label: React.ReactNode;
|
|
13
|
+
onClick: MouseEventHandler;
|
|
14
|
+
hoverColor?: 'default' | 'red';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
options: Option[];
|
|
19
|
+
label: React.ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
hoverOpen?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function DvrdOptionsList(props: Props) {
|
|
26
|
+
const context = useContext(ControlContext),
|
|
27
|
+
{className, label, options, disabled, hoverOpen} = props,
|
|
28
|
+
[open, setOpen] = useState(false),
|
|
29
|
+
button = useRef<HTMLDivElement>(null),
|
|
30
|
+
[hover, setHover] = useState(false);
|
|
31
|
+
|
|
32
|
+
function onClickButton() {
|
|
33
|
+
if (!hoverOpen) setOpen(true);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function onMouseEnter() {
|
|
37
|
+
setHover(true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function onMouseLeave() {
|
|
41
|
+
setHover(false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getButtonStyle(): CSSProperties {
|
|
45
|
+
return {
|
|
46
|
+
backgroundColor: getBackgroundColor(),
|
|
47
|
+
color: getColor(),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getBackgroundColor(): string {
|
|
52
|
+
let color: string;
|
|
53
|
+
if (disabled) color = 'color-gray-4';
|
|
54
|
+
else color = context.baseColor;
|
|
55
|
+
color = convertColor(color);
|
|
56
|
+
if (hover) color = editColor(-.2, color);
|
|
57
|
+
return color;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getColor(): string {
|
|
61
|
+
let color: string;
|
|
62
|
+
if (disabled) color = 'color-gray-3';
|
|
63
|
+
else color = context.contrastColor;
|
|
64
|
+
return convertColor(color);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function clickListener() {
|
|
68
|
+
directTimeout(() => {
|
|
69
|
+
if (!hasHover(button.current)) setOpen(false);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (open)
|
|
75
|
+
document.addEventListener('click', clickListener);
|
|
76
|
+
else
|
|
77
|
+
document.removeEventListener('click', clickListener);
|
|
78
|
+
return function () {
|
|
79
|
+
document.removeEventListener('click', clickListener);
|
|
80
|
+
}
|
|
81
|
+
}, [open]);
|
|
82
|
+
|
|
83
|
+
function renderLabel(label: React.ReactNode, className: string) {
|
|
84
|
+
if (typeof label === 'string') return <label className={className}>{label}</label>;
|
|
85
|
+
return label;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function renderOptions() {
|
|
89
|
+
return (
|
|
90
|
+
<div className='options-container'>
|
|
91
|
+
{options.map((option: Option, index: number) => (
|
|
92
|
+
<div key={index} className={classNames('option', option.hoverColor ?? 'default')}
|
|
93
|
+
onClick={disabled ? undefined : option.onClick}>
|
|
94
|
+
{renderLabel(option.label, 'option-label')}
|
|
95
|
+
</div>
|
|
96
|
+
))}
|
|
97
|
+
</div>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div
|
|
103
|
+
className={classNames('dvrd-options-list', open && 'open', disabled && 'disabled', className, hoverOpen && 'hover')}>
|
|
104
|
+
<div className={classNames('btn-container')} ref={button} onClick={onClickButton} style={getButtonStyle()}
|
|
105
|
+
onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
|
106
|
+
<AwesomeIcon name='bars' className='caret'/>
|
|
107
|
+
{renderLabel(label, 'button-label')}
|
|
108
|
+
</div>
|
|
109
|
+
{renderOptions()}
|
|
110
|
+
</div>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@import '../../../style/variables';
|
|
6
|
+
|
|
7
|
+
.dvrd-options-list {
|
|
8
|
+
position: relative;
|
|
9
|
+
|
|
10
|
+
.btn-container {
|
|
11
|
+
@include backgroundShadow2;
|
|
12
|
+
border-radius: .5rem;
|
|
13
|
+
padding: .7rem 1rem;
|
|
14
|
+
display: grid;
|
|
15
|
+
grid-template-columns: repeat(2, fit-content(100%));
|
|
16
|
+
grid-column-gap: .5rem;
|
|
17
|
+
align-items: center;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
transition: background-color .2s ease-in-out;
|
|
20
|
+
|
|
21
|
+
.button-label {
|
|
22
|
+
cursor: inherit;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.caret {
|
|
26
|
+
cursor: inherit;
|
|
27
|
+
font-size: .8rem;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.options-container {
|
|
32
|
+
position: absolute;
|
|
33
|
+
left: 0;
|
|
34
|
+
top: 100%;
|
|
35
|
+
min-width: 100%;
|
|
36
|
+
visibility: hidden;
|
|
37
|
+
opacity: 0;
|
|
38
|
+
transition: visibility .2s ease-in-out, opacity .2s ease-in-out, box-shadow .2s ease-in-out;
|
|
39
|
+
background-color: white;
|
|
40
|
+
border-radius: .5rem;
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
|
|
43
|
+
.option {
|
|
44
|
+
padding: .5rem;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
border-bottom: 1px solid $color-gray-4;
|
|
47
|
+
transition: background-color .2s ease-in-out;
|
|
48
|
+
|
|
49
|
+
.option-label {
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
user-select: none;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:last-child {
|
|
55
|
+
border-bottom: none;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:hover {
|
|
59
|
+
&.default {
|
|
60
|
+
background-color: rgba($color-blue-1, .2);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&.red {
|
|
64
|
+
background-color: rgba(red, .2);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&.open, &.hover:hover {
|
|
71
|
+
.options-container {
|
|
72
|
+
@include backgroundShadow();
|
|
73
|
+
visibility: visible;
|
|
74
|
+
opacity: 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&.disabled {
|
|
79
|
+
.btn-container {
|
|
80
|
+
cursor: default;
|
|
81
|
+
box-shadow: none;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import './style/optionsMenu.scss';
|
|
6
|
+
|
|
7
|
+
import React, {ReactElement, ReactNode} from 'react';
|
|
8
|
+
import classNames from "classnames";
|
|
9
|
+
import {hasHover} from "../util/controlUtil";
|
|
10
|
+
import {ElementPosition, MenuPlacement, OptionsMenuItem} from '../util/interfaces';
|
|
11
|
+
import AwesomeIcon from '../icon/awesomeIcon';
|
|
12
|
+
import {directTimeout} from "../util/componentUtil";
|
|
13
|
+
import {getScreenHeight, getScreenWidth} from '../util/responsiveUtil';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
onClickOption?: (option: React.ReactNode | OptionsMenuItem, evt: React.MouseEvent) => void;
|
|
17
|
+
onClickOptionIcon?: Function;
|
|
18
|
+
optionsComponent?: React.ReactElement;
|
|
19
|
+
options: OptionsMenuItem[];
|
|
20
|
+
placement: MenuPlacement;
|
|
21
|
+
containerClass?: string;
|
|
22
|
+
labelClassName?: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
labelPosition: ElementPosition;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface State {
|
|
28
|
+
open: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default class OptionsMenu extends React.Component<Props, State> {
|
|
32
|
+
static defaultProps = {
|
|
33
|
+
placement: MenuPlacement.BOTTOM_RIGHT,
|
|
34
|
+
labelPosition: ElementPosition.RIGHT,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
menuList: HTMLDivElement;
|
|
38
|
+
container: HTMLDivElement;
|
|
39
|
+
|
|
40
|
+
state: State = {
|
|
41
|
+
open: false,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
onClickOption = (option: OptionsMenuItem) => (evt: React.MouseEvent) => {
|
|
45
|
+
if (option.disabled !== true) {
|
|
46
|
+
evt.stopPropagation();
|
|
47
|
+
const {onClickOption} = this.props;
|
|
48
|
+
this.onHideMenu();
|
|
49
|
+
if (option.onClick) option.onClick(evt);
|
|
50
|
+
else if (onClickOption) onClickOption(option, evt);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// noinspection JSUnusedGlobalSymbols
|
|
55
|
+
onOpenExternal = () => {
|
|
56
|
+
if (this.menuList && this.container) {
|
|
57
|
+
const {right, bottom} = this.container.getBoundingClientRect(),
|
|
58
|
+
coords = this.calculateMenuCoords(right, bottom);
|
|
59
|
+
this.menuList.style.left = coords.x + 'px';
|
|
60
|
+
this.menuList.style.top = coords.y + 'px';
|
|
61
|
+
this.onOpenMenu();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
onClickOptionsIcon = (evt: React.MouseEvent) => {
|
|
66
|
+
if (this.menuList) {
|
|
67
|
+
const {onClickOptionIcon} = this.props,
|
|
68
|
+
{clientX, clientY} = evt, {x, y} = this.calculateMenuCoords(clientX, clientY);
|
|
69
|
+
this.menuList.style.left = x + 'px';
|
|
70
|
+
this.menuList.style.top = y + 'px';
|
|
71
|
+
this.onOpenMenu(true);
|
|
72
|
+
if (onClickOptionIcon) onClickOptionIcon(evt);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
onHideMenu = () => {
|
|
77
|
+
this.setState({open: false});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
onOpenMenu = (toggle: boolean = false) => {
|
|
81
|
+
if (toggle) this.setState({open: !this.state.open});
|
|
82
|
+
else this.setState({open: true});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
calculateMenuCoords = (clickX: number, clickY: number) => {
|
|
86
|
+
let x = -999, y = -999;
|
|
87
|
+
if (this.menuList) {
|
|
88
|
+
const {placement} = this.props, screenWidth = getScreenWidth(), screenHeight = getScreenHeight(),
|
|
89
|
+
menuRect = this.menuList.getBoundingClientRect();
|
|
90
|
+
if (menuRect) {
|
|
91
|
+
const {width, height} = menuRect;
|
|
92
|
+
switch (placement) {
|
|
93
|
+
case MenuPlacement.BOTTOM_LEFT:
|
|
94
|
+
x = Math.max(clickX - width, 0);
|
|
95
|
+
y = clickY + height > screenHeight ? screenHeight - height : clickY;
|
|
96
|
+
break;
|
|
97
|
+
case MenuPlacement.BOTTOM_RIGHT:
|
|
98
|
+
x = clickX + width > screenWidth ? screenWidth - width : clickX;
|
|
99
|
+
y = clickY + height > screenHeight ? screenHeight - height : clickY;
|
|
100
|
+
break;
|
|
101
|
+
case MenuPlacement.TOP_LEFT:
|
|
102
|
+
x = Math.max(clickX - width, 0);
|
|
103
|
+
y = Math.max(clickY - height, 0);
|
|
104
|
+
break;
|
|
105
|
+
case MenuPlacement.TOP_RIGHT:
|
|
106
|
+
x = clickX + width > screenWidth ? screenWidth - width : clickX;
|
|
107
|
+
y = Math.max(clickY - height, 0);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {x, y};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
attachListRef = (ref: HTMLDivElement) => {
|
|
116
|
+
this.menuList = ref;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
attachContainerRef = (ref: HTMLDivElement) => {
|
|
120
|
+
this.container = ref;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
clickListener = () => {
|
|
124
|
+
if (!hasHover(this.container))
|
|
125
|
+
this.onHideMenu();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
addClickListener = () => {
|
|
129
|
+
document.addEventListener('click', this.clickListener);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
removeClickListener = () => {
|
|
133
|
+
document.removeEventListener('click', this.clickListener);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
renderOptionsElement = (): ReactElement => {
|
|
137
|
+
const {optionsComponent} = this.props;
|
|
138
|
+
if (optionsComponent) return React.cloneElement(optionsComponent, {onClick: this.onClickOptionsIcon});
|
|
139
|
+
return <AwesomeIcon name='ellipsis-v' className='options-icon' onClick={this.onClickOptionsIcon}/>
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
renderLabel = (position: ElementPosition): ReactNode => {
|
|
143
|
+
const {label, labelPosition, labelClassName} = this.props;
|
|
144
|
+
if (position !== labelPosition || !label?.length) return null;
|
|
145
|
+
return <label className={classNames('options-menu-label', labelPosition, labelClassName)}
|
|
146
|
+
onClick={this.onClickOptionsIcon}>{label}</label>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
renderOptionsList = (): React.ReactElement => {
|
|
150
|
+
const {options} = this.props, {open} = this.state;
|
|
151
|
+
return (
|
|
152
|
+
<div ref={this.attachListRef} className={classNames('menu-options-list', open && 'visible')}>
|
|
153
|
+
{options.map((option, key) => (
|
|
154
|
+
<div className={classNames('menu-option', option.disabled === true && 'disabled')} key={key}
|
|
155
|
+
onClick={this.onClickOption(option)}>
|
|
156
|
+
{(option.icon && (!option.iconPlacement || option.iconPlacement === ElementPosition.LEFT)) &&
|
|
157
|
+
option.icon}
|
|
158
|
+
<label className='menu-option-label'>{option.label}</label>
|
|
159
|
+
{(option.icon && option.iconPlacement === ElementPosition.RIGHT) && option.icon}
|
|
160
|
+
</div>
|
|
161
|
+
))}
|
|
162
|
+
</div>
|
|
163
|
+
)
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
componentDidUpdate = (props: Props, prevState: State) => {
|
|
167
|
+
const {open} = this.state;
|
|
168
|
+
if (open && !prevState.open) directTimeout(this.addClickListener);
|
|
169
|
+
else if (!open && prevState.open) directTimeout(this.removeClickListener);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
componentWillUnmount = () => {
|
|
173
|
+
this.removeClickListener();
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
render = () => {
|
|
177
|
+
const {containerClass} = this.props;
|
|
178
|
+
return (
|
|
179
|
+
<div className={classNames('option-menu-container', containerClass)} ref={this.attachContainerRef}>
|
|
180
|
+
{this.renderLabel(ElementPosition.LEFT)}
|
|
181
|
+
{this.renderOptionsElement()}
|
|
182
|
+
{this.renderLabel(ElementPosition.RIGHT)}
|
|
183
|
+
{this.renderOptionsList()}
|
|
184
|
+
</div>
|
|
185
|
+
)
|
|
186
|
+
};
|
|
187
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@import '../../../style/variables';
|
|
6
|
+
|
|
7
|
+
.option-menu-container {
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
|
|
11
|
+
.options-icon {
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
font-size: 1.5rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.options-menu-label {
|
|
17
|
+
&.left {
|
|
18
|
+
margin-right: .5rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&.right {
|
|
22
|
+
margin-left: .5rem;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.menu-options-list {
|
|
27
|
+
@include backgroundShadow;
|
|
28
|
+
position: fixed;
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
visibility: hidden;
|
|
32
|
+
opacity: 0;
|
|
33
|
+
transition: visibility .2s ease-in-out, opacity .2s ease-in-out;
|
|
34
|
+
z-index: $z-index-dialog;
|
|
35
|
+
|
|
36
|
+
.menu-option {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: space-between;
|
|
40
|
+
padding: .5rem 1rem;
|
|
41
|
+
background-color: white;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
transition: background-color .2s ease-in-out;
|
|
44
|
+
|
|
45
|
+
.menu-option-label {
|
|
46
|
+
margin: 0 .3rem;
|
|
47
|
+
flex: 1;
|
|
48
|
+
text-align: center;
|
|
49
|
+
white-space: nowrap;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:hover {
|
|
53
|
+
background-color: $color-gray-7;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&.disabled {
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
|
|
59
|
+
.menu-option-label {
|
|
60
|
+
color: $color-gray-3;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&.visible {
|
|
66
|
+
visibility: visible;
|
|
67
|
+
opacity: 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|