@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,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
import './style/imageUpload.scss';
|
|
5
|
+
|
|
6
|
+
import React, {PureComponent} from "react";
|
|
7
|
+
import classNames from "classnames";
|
|
8
|
+
import {voidFunction} from "../util/controlUtil";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
className?: string;
|
|
12
|
+
onChange: (files: FileList | null) => void;
|
|
13
|
+
files: string[] | string;
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
multiple?: boolean;
|
|
16
|
+
accept?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class ImageUpload extends PureComponent<Props> {
|
|
20
|
+
private input: HTMLInputElement;
|
|
21
|
+
|
|
22
|
+
static defaultProps = {
|
|
23
|
+
multiple: false,
|
|
24
|
+
accept: 'image/*',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
onClickUpload = () => {
|
|
28
|
+
if (this.input) this.input.click();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onDrag = (evt: React.DragEvent) => {
|
|
32
|
+
evt.preventDefault();
|
|
33
|
+
evt.stopPropagation();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
onDrop = (evt: React.DragEvent) => {
|
|
37
|
+
evt.preventDefault();
|
|
38
|
+
evt.stopPropagation();
|
|
39
|
+
const {onChange} = this.props, files = evt.dataTransfer.files;
|
|
40
|
+
if (files?.length) {
|
|
41
|
+
onChange(files);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
renderFile = () => {
|
|
46
|
+
const {files} = this.props;
|
|
47
|
+
if (typeof files === 'string') return <img src={files} alt='' className='upload-img'/>;
|
|
48
|
+
else if (files.length) return (
|
|
49
|
+
<div className='files-list'>
|
|
50
|
+
{files.map((file: string, index: number) => <label className='file' key={index}>{file}</label>)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
render = () => {
|
|
56
|
+
const {disabled, className, multiple, accept} = this.props;
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className={classNames('dvr-upload-container', disabled && 'disabled', className)}
|
|
60
|
+
onClick={disabled ? voidFunction : this.onClickUpload} onDrop={this.onDrop} onDragOver={this.onDrag}
|
|
61
|
+
onDrag={this.onDrag}>
|
|
62
|
+
<input alt='' ref={(ref: HTMLInputElement) => {
|
|
63
|
+
this.input = ref
|
|
64
|
+
}} style={{display: 'none'}} type='image' accept={accept} multiple={multiple}/>
|
|
65
|
+
{this.renderFile()}
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
import './style/info.scss';
|
|
5
|
+
|
|
6
|
+
import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
|
|
7
|
+
import {ControlContext} from "../util/controlContext";
|
|
8
|
+
import {colorIsWhite, convertColor, editColor} from "../util/colorUtil";
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import {getScreenHeight, getScreenWidth} from '../util/responsiveUtil';
|
|
11
|
+
import { directTimeout } from '../util/componentUtil';
|
|
12
|
+
import AwesomeIcon from '../icon/awesomeIcon';
|
|
13
|
+
|
|
14
|
+
type LimitBox = Partial<{ top: number, bottom: number, left: number, right: number }>;
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
onClick?: MouseEventHandler;
|
|
18
|
+
onMouseEnter?: MouseEventHandler;
|
|
19
|
+
onMouseLeave?: MouseEventHandler;
|
|
20
|
+
message: React.ReactNode;
|
|
21
|
+
title?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
messageClassName?: string;
|
|
24
|
+
iconClassName?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
limitBox?: LimitBox;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface State {
|
|
30
|
+
hovered: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default class Info extends PureComponent<Props, State> {
|
|
34
|
+
declare context: React.ContextType<typeof ControlContext>;
|
|
35
|
+
static contextType = ControlContext;
|
|
36
|
+
|
|
37
|
+
private messageContainer: HTMLDivElement;
|
|
38
|
+
|
|
39
|
+
state: State = {
|
|
40
|
+
hovered: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
getColor = (): string => {
|
|
44
|
+
const {baseColor, contrastColor} = this.context, {hovered} = this.state, {disabled} = this.props;
|
|
45
|
+
let color = convertColor(baseColor);
|
|
46
|
+
if (colorIsWhite(color)) color = convertColor(contrastColor);
|
|
47
|
+
if (hovered) color = editColor(-.2, color);
|
|
48
|
+
if (disabled) color = '#ccc';
|
|
49
|
+
return color;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
onMouseEnter = (evt: React.MouseEvent) => {
|
|
53
|
+
const {onMouseEnter} = this.props;
|
|
54
|
+
this.setState({hovered: true});
|
|
55
|
+
if (onMouseEnter) onMouseEnter(evt);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
onMouseLeave = (evt: React.MouseEvent) => {
|
|
59
|
+
const {onMouseLeave} = this.props;
|
|
60
|
+
this.setState({hovered: false});
|
|
61
|
+
if (onMouseLeave) onMouseLeave(evt);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
getIconStyle = (): CSSProperties => {
|
|
65
|
+
return {color: this.getColor()};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
setMessagePosition = () => {
|
|
69
|
+
if (this.messageContainer) {
|
|
70
|
+
let {width, height, bottom, left, right, top} = this.messageContainer.getBoundingClientRect(),
|
|
71
|
+
screenWidth = getScreenWidth(), screenHeight = getScreenHeight(), {limitBox} = this.props;
|
|
72
|
+
top = top - (limitBox?.top || 0);
|
|
73
|
+
left = left - (limitBox?.left || 0);
|
|
74
|
+
bottom = bottom + (limitBox?.bottom || 0);
|
|
75
|
+
right = right + (limitBox?.right || 0);
|
|
76
|
+
let translateX: number = 0, translateY: number = 0;
|
|
77
|
+
if (top < 0) translateY = top;
|
|
78
|
+
else if (bottom > screenHeight) translateY = screenHeight - bottom;
|
|
79
|
+
if (left < 0) translateX = left;
|
|
80
|
+
else if (right > screenWidth) translateX = screenWidth - right;
|
|
81
|
+
|
|
82
|
+
let transform: string = this.messageContainer.style.transform;
|
|
83
|
+
const {x, y} = this.getCurrentTranslates(transform);
|
|
84
|
+
if (translateX) {
|
|
85
|
+
translateX = this.getCalculatedTranslate(x, translateX, width);
|
|
86
|
+
transform = transform.replace(/translateX\(-?\d*(%|px|rem)?\)/, `translateX(${translateX}%)`);
|
|
87
|
+
}
|
|
88
|
+
if (translateY) {
|
|
89
|
+
translateY = this.getCalculatedTranslate(y, translateY, height);
|
|
90
|
+
transform = transform.replace(/translateY\(-?\d*(%|px|rem)?\)/, `translateY(${translateY}%)`);
|
|
91
|
+
}
|
|
92
|
+
this.messageContainer.style.transform = transform;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
getCalculatedTranslate = (initial: number, value: number, dimension: number) => {
|
|
97
|
+
return initial - Math.round((value / dimension) * 100);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
getCurrentTranslates = (transform: string): { x: number, y: number } => {
|
|
101
|
+
let x = 100, y = -100;
|
|
102
|
+
const translateX = transform.match(/translateX\(-?\d*(%|px|rem)?\)/),
|
|
103
|
+
translateY = transform.match(/translateY\(-?\d*(%|px|rem)?\)/);
|
|
104
|
+
if (translateX) x = Number(translateX[0].match(/\(-?\d*(%|px|rem)?\)/)![0].replace(/[()%]|rem|px/g, ''));
|
|
105
|
+
if (translateY) y = Number(translateY[0].match(/\(-?\d*(%|px|rem)?\)/)![0].replace(/[()%]|rem|px/g, ''));
|
|
106
|
+
return {x, y};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
renderMessage = (): React.ReactNode => {
|
|
110
|
+
const {message} = this.props;
|
|
111
|
+
if (typeof message === 'string') return <p className='dvr-info-message'>{message}</p>;
|
|
112
|
+
return message;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
componentDidUpdate = (prevProps: Props, prevState: State) => {
|
|
116
|
+
const {hovered} = this.state, prevHovered = prevState.hovered;
|
|
117
|
+
if (hovered && hovered !== prevHovered)
|
|
118
|
+
directTimeout(this.setMessagePosition);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
render = () => {
|
|
122
|
+
const {className, messageClassName, iconClassName} = this.props;
|
|
123
|
+
return (
|
|
124
|
+
<div className={classNames('dvr-info-container', className)} onMouseEnter={this.onMouseEnter}
|
|
125
|
+
onMouseLeave={this.onMouseLeave}>
|
|
126
|
+
<AwesomeIcon name='info-circle' style={this.getIconStyle()}
|
|
127
|
+
className={classNames('dvr-info-icon', iconClassName)}/>
|
|
128
|
+
<div className={classNames('dvr-message-container', messageClassName)}
|
|
129
|
+
ref={(ref: HTMLDivElement) => {this.messageContainer = ref}}
|
|
130
|
+
style={{transform: 'translateX(100%) translateY(-100%)'}}>
|
|
131
|
+
{this.renderMessage()}
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
)
|
|
135
|
+
};
|
|
136
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@import '../../../style/variables';
|
|
6
|
+
|
|
7
|
+
.dvr-info-container {
|
|
8
|
+
position: relative;
|
|
9
|
+
display: inline-block;
|
|
10
|
+
justify-self: start;
|
|
11
|
+
|
|
12
|
+
.dvr-info-icon {
|
|
13
|
+
cursor: help;
|
|
14
|
+
transition: color .2s ease-in-out;
|
|
15
|
+
font-size: 1.1rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.dvr-message-container {
|
|
19
|
+
@include backgroundShadow;
|
|
20
|
+
padding: .2rem;
|
|
21
|
+
border-radius: .2rem;
|
|
22
|
+
background-color: white;
|
|
23
|
+
position: absolute;
|
|
24
|
+
z-index: $z-index-high;
|
|
25
|
+
top: 0;
|
|
26
|
+
right: 0;
|
|
27
|
+
width: 15rem;
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
opacity: 0;
|
|
30
|
+
transition: visibility .2s ease-in-out, opacity .2s ease-in-out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:hover {
|
|
34
|
+
.dvr-message-container {
|
|
35
|
+
visibility: visible;
|
|
36
|
+
opacity: 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import {CSSProperties, PureComponent, ReactElement} from 'react';
|
|
7
|
+
import {DefaultInputProps} from "../v2/inputController_v2";
|
|
8
|
+
import {TextField} from "../../../../index";
|
|
9
|
+
import {DVRInputControllerProps} from "../v2/inputController_v2";
|
|
10
|
+
|
|
11
|
+
interface Props extends DVRInputControllerProps {
|
|
12
|
+
animatedTexts: string[];
|
|
13
|
+
typingTime: number;
|
|
14
|
+
randomise: boolean;
|
|
15
|
+
doBackspace: boolean;
|
|
16
|
+
Input?: ReactElement;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface State {
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default class AnimatedTextField extends PureComponent<Props, State> {
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
...DefaultInputProps,
|
|
27
|
+
typingTime: 150,
|
|
28
|
+
randomise: true,
|
|
29
|
+
doBackspace: true,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
state: State = {
|
|
33
|
+
value: '',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
private timer: null | number = null;
|
|
37
|
+
private currentWord: string = '';
|
|
38
|
+
private words: string[] = [];
|
|
39
|
+
private isFocused: boolean = false;
|
|
40
|
+
|
|
41
|
+
onFocus = (evt: React.FocusEvent) => {
|
|
42
|
+
const {onFocus} = this.props;
|
|
43
|
+
this.isFocused = true;
|
|
44
|
+
this.stopAnimate();
|
|
45
|
+
if (onFocus) onFocus(evt);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
onBlur = (evt: React.FocusEvent) => {
|
|
49
|
+
const {onBlur, value} = this.props;
|
|
50
|
+
this.isFocused = false;
|
|
51
|
+
if(!value?.toString().length) {
|
|
52
|
+
this.animate();
|
|
53
|
+
}
|
|
54
|
+
if (onBlur) onBlur(evt);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
onChangeNative = (evt: React.ChangeEvent<HTMLInputElement>) => {
|
|
58
|
+
const target = evt.target, value = target.value;
|
|
59
|
+
this.onChange(value, evt);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
onChange = (value: string, evt: React.ChangeEvent) => {
|
|
63
|
+
if (value.length) this.stopAnimate();
|
|
64
|
+
else if (!this.isFocused) this.animate();
|
|
65
|
+
this.props.onChange(value, evt);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
getRandomTexts = (): string[] => {
|
|
69
|
+
const texts = this.props.animatedTexts.slice(), randomised: string[] = [];
|
|
70
|
+
while (texts.length > 0)
|
|
71
|
+
randomised.push(texts.splice(Math.round(Math.random() * (texts.length - 1)), 1)[0]);
|
|
72
|
+
return randomised;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
private animate = () => {
|
|
76
|
+
const {randomise, animatedTexts} = this.props;
|
|
77
|
+
if (randomise) this.words = this.getRandomTexts();
|
|
78
|
+
else this.words = animatedTexts.slice();
|
|
79
|
+
this.currentWord = this.words.pop() || '';
|
|
80
|
+
this.doType();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
private stopAnimate = () => {
|
|
84
|
+
this.setState({value: ''});
|
|
85
|
+
if (this.timer) {
|
|
86
|
+
window.clearTimeout(this.timer);
|
|
87
|
+
this.timer = null;
|
|
88
|
+
}
|
|
89
|
+
this.words = [];
|
|
90
|
+
this.currentWord = '';
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
private randomiseTimeout = () => {
|
|
94
|
+
const {typingTime} = this.props, variations: number[] = [1, .8, .4];
|
|
95
|
+
return typingTime * variations[Math.round(Math.random() * 2)];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
private doType = () => {
|
|
99
|
+
const {value} = this.state, {doBackspace, randomise, animatedTexts} = this.props;
|
|
100
|
+
let newValue: string, timeout: number = this.randomiseTimeout();
|
|
101
|
+
if (this.currentWord.length === 0) {
|
|
102
|
+
if (value.length > 0) {
|
|
103
|
+
if (doBackspace) {
|
|
104
|
+
newValue = value.substr(0, value.length - 1);
|
|
105
|
+
timeout = Math.round(timeout / 2);
|
|
106
|
+
if (!newValue.length) timeout = 300;
|
|
107
|
+
} else newValue = '';
|
|
108
|
+
} else {
|
|
109
|
+
if (!this.words.length) {
|
|
110
|
+
if (randomise) this.words = this.getRandomTexts();
|
|
111
|
+
else this.words = animatedTexts.slice();
|
|
112
|
+
}
|
|
113
|
+
this.currentWord = this.words.pop() as string;
|
|
114
|
+
newValue = value + this.getNextLetter();
|
|
115
|
+
if (!this.currentWord.length) timeout = 300;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
newValue = value + this.getNextLetter();
|
|
119
|
+
if (!this.currentWord.length) timeout = 300;
|
|
120
|
+
}
|
|
121
|
+
this.setState({value: newValue});
|
|
122
|
+
this.timer = window.setTimeout(this.doType, timeout);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
private getNextLetter = () => {
|
|
126
|
+
const letter = this.currentWord.substr(0, 1);
|
|
127
|
+
this.currentWord = this.currentWord.substr(1, this.currentWord.length);
|
|
128
|
+
return letter;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
componentDidMount = () => {
|
|
132
|
+
if (!this.props.autoFocus)
|
|
133
|
+
this.animate();
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
componentWillUnmount = () => {
|
|
137
|
+
if (this.timer) {
|
|
138
|
+
window.clearTimeout(this.timer);
|
|
139
|
+
this.timer = null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
render = () => {
|
|
144
|
+
const value = this.props.value?.toString(), {Input} = this.props;
|
|
145
|
+
let textValue: string, style: CSSProperties;
|
|
146
|
+
if (value?.length) {
|
|
147
|
+
textValue = value;
|
|
148
|
+
style = {};
|
|
149
|
+
} else {
|
|
150
|
+
textValue = this.state.value + (this.state.value.length > 1 ? '|' : '');
|
|
151
|
+
style = {color: "gray"};
|
|
152
|
+
}
|
|
153
|
+
if (Input)
|
|
154
|
+
return React.cloneElement(Input,
|
|
155
|
+
{onChange: this.onChangeNative, value: textValue, onFocus: this.onFocus, onBlur: this.onBlur, style});
|
|
156
|
+
return <TextField {...this.props} onChange={this.onChange} onFocus={this.onFocus} onBlur={this.onBlur}
|
|
157
|
+
value={textValue} inputProps={{style}}/>;
|
|
158
|
+
};
|
|
159
|
+
}
|