@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,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import './style/withBackground.scss';
|
|
6
|
+
|
|
7
|
+
import React, {CSSProperties, PropsWithChildren, useEffect, useMemo, useRef} from 'react';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import {escapePressed, hasHover} from "../util/controlUtil";
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
onClickBackground?: Function,
|
|
13
|
+
onClose: Function;
|
|
14
|
+
active: boolean;
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
transparent?: boolean;
|
|
17
|
+
backgroundClass?: string;
|
|
18
|
+
containerClass?: string;
|
|
19
|
+
escapeDisabled?: boolean;
|
|
20
|
+
preventBackgroundClick?: boolean;
|
|
21
|
+
zIndex?: number;
|
|
22
|
+
allowBodyScroll?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function WithBackground(props: PropsWithChildren<Props>) {
|
|
26
|
+
const {
|
|
27
|
+
active, escapeDisabled, backgroundClass, containerClass, children, backgroundColor, preventBackgroundClick,
|
|
28
|
+
onClickBackground, onClose, transparent, zIndex, allowBodyScroll
|
|
29
|
+
} = props;
|
|
30
|
+
const escapeListenerActive = useRef(false);
|
|
31
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
32
|
+
const backgroundStyle = useMemo(() => {
|
|
33
|
+
const color = transparent ? 'transparent' : backgroundColor ?? 'rgba(0,0,0,.2)';
|
|
34
|
+
const style: CSSProperties = {backgroundColor: color};
|
|
35
|
+
if (zIndex !== undefined) style.zIndex = zIndex;
|
|
36
|
+
return style;
|
|
37
|
+
}, [transparent, backgroundColor, zIndex]);
|
|
38
|
+
|
|
39
|
+
function _onClickBackground(evt: React.MouseEvent) {
|
|
40
|
+
if (preventBackgroundClick) return;
|
|
41
|
+
if (onClickBackground) onClickBackground(evt);
|
|
42
|
+
else if (!hasHover(contentRef.current)) onClose(evt);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onKeyDown(evt: KeyboardEvent) {
|
|
46
|
+
if (escapeDisabled) return;
|
|
47
|
+
if (escapePressed(evt)) onClose();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function addEscapeListener() {
|
|
51
|
+
if (escapeListenerActive.current) return;
|
|
52
|
+
document.addEventListener('keydown', onKeyDown);
|
|
53
|
+
escapeListenerActive.current = true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function removeEscapeListener() {
|
|
57
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
58
|
+
escapeListenerActive.current = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function setBodyScroll(active: boolean) {
|
|
62
|
+
if (allowBodyScroll) return;
|
|
63
|
+
if (active)
|
|
64
|
+
document.body.style.overflowY = 'hidden';
|
|
65
|
+
else document.body.style.removeProperty('overflow-y');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (escapeDisabled) removeEscapeListener();
|
|
70
|
+
else if (active) addEscapeListener();
|
|
71
|
+
return function () {
|
|
72
|
+
removeEscapeListener();
|
|
73
|
+
}
|
|
74
|
+
}, [active, escapeDisabled]);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
setBodyScroll(active);
|
|
78
|
+
return function () {
|
|
79
|
+
removeEscapeListener();
|
|
80
|
+
}
|
|
81
|
+
}, [active]);
|
|
82
|
+
|
|
83
|
+
if (!active) return null;
|
|
84
|
+
return (
|
|
85
|
+
<div className={classNames('with-background', backgroundClass)} onMouseDown={_onClickBackground}
|
|
86
|
+
style={backgroundStyle}>
|
|
87
|
+
<div className={classNames('content-container', containerClass)} ref={contentRef}>
|
|
88
|
+
{children}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
import './style/asyncSelect.scss';
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import {PureComponent} from 'react';
|
|
8
|
+
import {SelectDefaultProps, SelectProps} from "../selectController";
|
|
9
|
+
import {Loader, Select, generateComponentId} from "../../../..";
|
|
10
|
+
import classNames from "classnames";
|
|
11
|
+
|
|
12
|
+
interface Props extends SelectProps {
|
|
13
|
+
onSearch: (value: string, callback: VoidFunction) => void;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class AsyncSelect extends PureComponent<Props> {
|
|
18
|
+
static defaultProps = SelectDefaultProps;
|
|
19
|
+
|
|
20
|
+
private searchValue: string = '';
|
|
21
|
+
private id: string = generateComponentId(this.props.id);
|
|
22
|
+
|
|
23
|
+
onChangeSearch = (value: string) => {
|
|
24
|
+
this.searchValue = value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
onEnter = () => {
|
|
28
|
+
this.props.onSearch(this.searchValue, this.focusInput);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
focusInput = () => {
|
|
32
|
+
const input = document.getElementById(`${this.id}-input`);
|
|
33
|
+
if (input) input.focus();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
render = () => {
|
|
37
|
+
const {loading, fullWidth} = this.props;
|
|
38
|
+
return (
|
|
39
|
+
<div className={classNames('dvr-async-select', fullWidth && 'fw')}>
|
|
40
|
+
<Loader active={loading} containerClass='dvr-async-select-loader' size='2rem' disableBackground/>
|
|
41
|
+
<Select {...this.props} onChangeSearch={this.onChangeSearch} onEnter={this.onEnter} disabled={loading}
|
|
42
|
+
id={this.id} forceDisplayItems/>
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@import '../../../../style/variables';
|
|
6
|
+
|
|
7
|
+
.dvr-async-select {
|
|
8
|
+
display: inline-block;
|
|
9
|
+
position: relative;
|
|
10
|
+
|
|
11
|
+
.dvr-async-select-loader {
|
|
12
|
+
position: absolute;
|
|
13
|
+
right: 2.5rem;
|
|
14
|
+
top: 1.2rem;
|
|
15
|
+
width: min-content;
|
|
16
|
+
height: auto;
|
|
17
|
+
left: unset;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&.fw {
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
import './style/dvrdSelect.scss';
|
|
5
|
+
|
|
6
|
+
import React, {CSSProperties, MouseEventHandler, PureComponent, ReactElement} from 'react';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import {ChangeFunction, ErrorType, SelectItemShape} from '../util/interfaces';
|
|
9
|
+
import {hasHover, stopPropagation} from '../util/controlUtil';
|
|
10
|
+
import AwesomeIcon from '../icon/awesomeIcon';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
onChange: (value: string | number) => MouseEventHandler;
|
|
14
|
+
onChangeSearch: ChangeFunction;
|
|
15
|
+
value: string | number;
|
|
16
|
+
items: SelectItemShape[];
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
error?: ErrorType;
|
|
19
|
+
label?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
labelClassName?: string;
|
|
22
|
+
valueClassName?: string;
|
|
23
|
+
arrowClassName?: string;
|
|
24
|
+
errorClassName?: string;
|
|
25
|
+
itemContainerClassName?: string;
|
|
26
|
+
itemClassName?: string;
|
|
27
|
+
itemsPosition: 'top' | 'bottom';
|
|
28
|
+
selectOnly: boolean;
|
|
29
|
+
searchValue: string;
|
|
30
|
+
optionsContainerHeight: number | string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface State {
|
|
34
|
+
open: boolean;
|
|
35
|
+
searchFocused: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default class DvrdSelect extends PureComponent<Props, State> {
|
|
39
|
+
private container: HTMLDivElement;
|
|
40
|
+
state: State = {
|
|
41
|
+
open: false,
|
|
42
|
+
searchFocused: false,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
hasError = (): boolean => this.props.error !== undefined && this.props.error !== null;
|
|
46
|
+
|
|
47
|
+
onClickElement = (evt: React.MouseEvent) => {
|
|
48
|
+
evt.stopPropagation();
|
|
49
|
+
if (!this.props.disabled)
|
|
50
|
+
this.setState({open: !this.state.open});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
onClickItem = (value: string | number) => (evt: React.MouseEvent) => {
|
|
54
|
+
evt.stopPropagation();
|
|
55
|
+
this.props.onChange(value)(evt);
|
|
56
|
+
this.setState({open: false});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
onFocusInput = () => {
|
|
60
|
+
this.setState({searchFocused: true, open: true});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
onBlurInput = () => {
|
|
64
|
+
window.setTimeout(() => {
|
|
65
|
+
this.setState({searchFocused: false});
|
|
66
|
+
this.props.onChangeSearch({target: {value: ''}});
|
|
67
|
+
}, 200);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
getLongestValue = (): string => {
|
|
71
|
+
const {items} = this.props;
|
|
72
|
+
let longest: string = '';
|
|
73
|
+
for (const item of items) {
|
|
74
|
+
if (item.label.toString().length > longest.length) {
|
|
75
|
+
longest = item.label.toString();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return longest;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
getValueLabel = (): string | number => {
|
|
82
|
+
const {value, items} = this.props;
|
|
83
|
+
for (const item of items) {
|
|
84
|
+
if (item.value === value) return this.getItemLabel(item);
|
|
85
|
+
}
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getItemLabel = (item: SelectItemShape): string | number => {
|
|
90
|
+
const {label} = item;
|
|
91
|
+
if (['string', 'number'].includes(typeof label)) return label as string | number;
|
|
92
|
+
else if (!!item.valueLabel) return item.valueLabel;
|
|
93
|
+
return item.value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getItemsContainerStyle = (): CSSProperties => {
|
|
97
|
+
let {optionsContainerHeight} = this.props;
|
|
98
|
+
if (typeof optionsContainerHeight === 'number') optionsContainerHeight = `${optionsContainerHeight}px`;
|
|
99
|
+
return {maxHeight: optionsContainerHeight};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
renderLabel = () => {
|
|
103
|
+
const {labelClassName, label} = this.props;
|
|
104
|
+
if (!label) return null;
|
|
105
|
+
return <label className={classNames('dvrd-select-label', labelClassName)}
|
|
106
|
+
onClick={this.onClickElement}>{label}</label>
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
renderValue = () => {
|
|
110
|
+
const {valueClassName, selectOnly, searchValue, onChangeSearch, disabled} = this.props,
|
|
111
|
+
{searchFocused} = this.state, valueLabel = this.getValueLabel();
|
|
112
|
+
if (selectOnly)
|
|
113
|
+
return (
|
|
114
|
+
<div style={{display: 'flex', flexDirection: 'column'}}>
|
|
115
|
+
<label className={classNames('dvrd-select-value', valueClassName)}
|
|
116
|
+
onClick={this.onClickElement}>{valueLabel}</label>
|
|
117
|
+
<label style={{height: 0, visibility: 'hidden'}}>{this.getLongestValue()}</label>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
const value = searchFocused ? searchValue : valueLabel;
|
|
121
|
+
return <input className='dvrd-select-search' value={value} onChange={onChangeSearch} disabled={disabled}
|
|
122
|
+
onFocus={this.onFocusInput} onBlur={this.onBlurInput} onClick={stopPropagation}/>
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
renderArrow = () => {
|
|
126
|
+
const {arrowClassName} = this.props, {open} = this.state;
|
|
127
|
+
return <AwesomeIcon name='chevron-down' onClick={this.onClickElement}
|
|
128
|
+
className={classNames('dvrd-select-arrow', open && 'open', arrowClassName)}/>;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
renderItems = () => {
|
|
132
|
+
const {disabled, itemContainerClassName, itemsPosition} = this.props, {open} = this.state;
|
|
133
|
+
const items = this.props.items.filter((item: SelectItemShape) => {
|
|
134
|
+
if (item.selectable === false) return false;
|
|
135
|
+
if (typeof item.label === 'string') return item.label.length > 0;
|
|
136
|
+
return true;
|
|
137
|
+
})
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
className={classNames('dvrd-select-items', (open && !disabled) && 'open', itemsPosition,
|
|
141
|
+
itemContainerClassName)} style={this.getItemsContainerStyle()}>
|
|
142
|
+
{items.map(this.renderItem)}
|
|
143
|
+
</div>
|
|
144
|
+
)
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
renderItem = (item: SelectItemShape, index: number) => {
|
|
148
|
+
const {label, value} = item;
|
|
149
|
+
const {itemClassName} = this.props;
|
|
150
|
+
if (['number', 'string'].includes(typeof label)) return (
|
|
151
|
+
<label key={index} className={classNames('dvrd-select-item', itemClassName)}
|
|
152
|
+
onClick={this.onClickItem(value)}>{label}</label>
|
|
153
|
+
);
|
|
154
|
+
const labelElement: ReactElement = label as ReactElement;
|
|
155
|
+
const onClick = (evt: React.MouseEvent) => {
|
|
156
|
+
this.onClickItem(value)(evt);
|
|
157
|
+
labelElement.props.onClick?.(evt);
|
|
158
|
+
};
|
|
159
|
+
const className = classNames(labelElement.props.className, 'dvrd-select-item', itemClassName);
|
|
160
|
+
return React.cloneElement(labelElement, Object.assign({}, labelElement.props, {
|
|
161
|
+
onClick,
|
|
162
|
+
className,
|
|
163
|
+
key: index
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
renderError = () => {
|
|
168
|
+
if (!this.hasError()) return null;
|
|
169
|
+
const {error, errorClassName} = this.props;
|
|
170
|
+
return <label className={classNames('dvrd-select-error', errorClassName)}>{error}</label>
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
addClickListener = () => {
|
|
174
|
+
document.addEventListener('click', this.clickListener);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
removeClickListener = () => {
|
|
178
|
+
document.removeEventListener('click', this.clickListener);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
clickListener = () => {
|
|
182
|
+
if (!hasHover(this.container)) this.setState({open: false});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
componentDidUpdate = (props: Props, prevState: State) => {
|
|
186
|
+
const {open} = this.state, prevOpen = prevState.open;
|
|
187
|
+
if (open && !prevOpen) this.addClickListener();
|
|
188
|
+
else if (!open && prevOpen) this.removeClickListener();
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
componentWillUnmount = () => {
|
|
192
|
+
this.removeClickListener();
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
render = () => {
|
|
196
|
+
const {className, disabled, selectOnly} = this.props, {open} = this.state;
|
|
197
|
+
return (
|
|
198
|
+
<div
|
|
199
|
+
className={classNames('dvrd-select-container', disabled && 'disabled', open && 'open',
|
|
200
|
+
this.hasError() && 'error', className)}
|
|
201
|
+
ref={(ref: HTMLDivElement) => {
|
|
202
|
+
this.container = ref
|
|
203
|
+
}} onClick={this.onClickElement}>
|
|
204
|
+
{this.renderLabel()}
|
|
205
|
+
<div className={classNames('content-container', !selectOnly && 'search')}>
|
|
206
|
+
{this.renderValue()}
|
|
207
|
+
{this.renderArrow()}
|
|
208
|
+
</div>
|
|
209
|
+
{this.renderItems()}
|
|
210
|
+
{this.renderError()}
|
|
211
|
+
</div>
|
|
212
|
+
)
|
|
213
|
+
};
|
|
214
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import React, {PureComponent} from 'react';
|
|
6
|
+
import DvrdSelect from "./dvrdSelect";
|
|
7
|
+
import {ChangeFunction, ErrorType, SelectItemShape} from "../util/interfaces";
|
|
8
|
+
import {stringContains} from '../util/controlUtil';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
onChange: ChangeFunction;
|
|
12
|
+
value: string | number;
|
|
13
|
+
items: SelectItemShape[];
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
label?: string;
|
|
16
|
+
error?: ErrorType;
|
|
17
|
+
className?: string;
|
|
18
|
+
labelClassName?: string;
|
|
19
|
+
valueClassName?: string;
|
|
20
|
+
arrowClassName?: string;
|
|
21
|
+
errorClassName?: string;
|
|
22
|
+
itemContainerClassName?: string;
|
|
23
|
+
itemClassName?: string;
|
|
24
|
+
itemsPosition: 'top' | 'bottom';
|
|
25
|
+
selectOnly: boolean;
|
|
26
|
+
optionsContainerHeight: number | string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface State {
|
|
30
|
+
searchValue: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default class DvrdSelectController extends PureComponent<Props, State> {
|
|
34
|
+
private select: DvrdSelect;
|
|
35
|
+
|
|
36
|
+
static defaultProps = {
|
|
37
|
+
itemsPosition: 'bottom',
|
|
38
|
+
selectOnly: true,
|
|
39
|
+
optionsContainerHeight: '15rem',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
state: State = {
|
|
43
|
+
searchValue: '',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
onChange = (value: string) => () => {
|
|
47
|
+
this.props.onChange(value);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
onChangeSearch = (evt: React.ChangeEvent<HTMLInputElement>) => {
|
|
51
|
+
const {value} = evt.target;
|
|
52
|
+
this.setState({searchValue: value});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
onOpen = (evt: React.MouseEvent) => {
|
|
56
|
+
if (this.select) this.select.onClickElement(evt);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
getItems = () => {
|
|
60
|
+
const items = this.props.items.slice(), {searchValue} = this.state;
|
|
61
|
+
if (!searchValue) return items;
|
|
62
|
+
return items.filter((item) => stringContains(item.label.toString(), searchValue))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render = () => {
|
|
66
|
+
const {
|
|
67
|
+
arrowClassName, label, error, className, labelClassName, valueClassName, itemContainerClassName,
|
|
68
|
+
itemClassName, errorClassName, disabled, value, itemsPosition, selectOnly, optionsContainerHeight
|
|
69
|
+
} = this.props, {searchValue} = this.state;
|
|
70
|
+
return (
|
|
71
|
+
<DvrdSelect onChange={this.onChange} value={value} items={this.getItems()} disabled={disabled}
|
|
72
|
+
errorClassName={errorClassName} itemClassName={itemClassName}
|
|
73
|
+
itemContainerClassName={itemContainerClassName} valueClassName={valueClassName}
|
|
74
|
+
labelClassName={labelClassName} className={className} error={error} label={label}
|
|
75
|
+
arrowClassName={arrowClassName} itemsPosition={itemsPosition} ref={(ref: DvrdSelect) => {
|
|
76
|
+
this.select = ref
|
|
77
|
+
}} searchValue={searchValue} onChangeSearch={this.onChangeSearch} selectOnly={selectOnly}
|
|
78
|
+
optionsContainerHeight={optionsContainerHeight}/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
};
|