@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.
Files changed (180) hide show
  1. package/index.ts +8 -1
  2. package/package.json +29 -23
  3. package/src/js/button/button.tsx +102 -0
  4. package/src/js/button/buttonController.tsx +179 -0
  5. package/src/js/button/closeButton.tsx +29 -0
  6. package/src/js/button/dvrdButton.tsx +128 -0
  7. package/src/js/button/outlinedButton.tsx +105 -0
  8. package/src/js/button/simpleButton.tsx +163 -0
  9. package/src/js/button/style/button.scss +95 -0
  10. package/src/js/button/style/closeButton.scss +15 -0
  11. package/src/js/button/style/dvrdButton.scss +30 -0
  12. package/src/js/button/style/outlinedButton.scss +84 -0
  13. package/src/js/button/style/simpleButton.scss +80 -0
  14. package/src/js/carousel/DVRCarousel.tsx +163 -0
  15. package/src/js/carousel/DVRCarouselController.tsx +95 -0
  16. package/src/js/carousel/style/DVRCarousel.scss +38 -0
  17. package/src/js/checkbox/checkbox.tsx +148 -0
  18. package/src/js/checkbox/checkboxController.tsx +131 -0
  19. package/src/js/checkbox/style/checkbox.scss +109 -0
  20. package/src/js/colorPicker/colorPicker.tsx +118 -0
  21. package/src/js/colorPicker/style/colorPicker.scss +20 -0
  22. package/src/js/date/dvrdDatePicker.tsx +357 -0
  23. package/src/js/date/style/dvrdDatePicker.scss +307 -0
  24. package/src/js/dialog/dialog.tsx +207 -0
  25. package/src/js/dialog/dialogController.tsx +70 -0
  26. package/src/js/dialog/inlineDialog.tsx +127 -0
  27. package/src/js/dialog/style/dialog.scss +61 -0
  28. package/src/js/events/withEvents.tsx +40 -0
  29. package/src/js/head/DVRHead.tsx +49 -0
  30. package/src/js/header/DVRHeader.tsx +417 -0
  31. package/src/js/header/style/header.scss +206 -0
  32. package/src/js/icon/awesomeIcon.tsx +20 -0
  33. package/src/js/image/imageUpload.tsx +69 -0
  34. package/src/js/image/style/imageUpload.scss +11 -0
  35. package/src/js/info/info.tsx +136 -0
  36. package/src/js/info/style/info.scss +39 -0
  37. package/src/js/input/animated/animatedTextField.tsx +159 -0
  38. package/src/js/input/date/dateField.tsx +360 -0
  39. package/src/js/input/date/dateFieldController.tsx +245 -0
  40. package/src/js/input/date/datePicker/datePicker.tsx +186 -0
  41. package/src/js/input/date/datePicker/style/datePicker.scss +102 -0
  42. package/src/js/input/date/input/dateInput.tsx +214 -0
  43. package/src/js/input/date/style/dateField.scss +40 -0
  44. package/src/js/input/date/timePicker/style/timePicker.scss +95 -0
  45. package/src/js/input/date/timePicker/timePicker.tsx +143 -0
  46. package/src/js/input/editor/DVREditor.tsx +21 -0
  47. package/src/js/input/number/numberInput.tsx +157 -0
  48. package/src/js/input/password/passwordInput.tsx +140 -0
  49. package/src/js/input/password/passwordRules.tsx +48 -0
  50. package/src/js/input/password/style/passwordInput.scss +39 -0
  51. package/src/js/input/password/style/passwordRules.scss +41 -0
  52. package/src/js/input/simple/style/simpleInput.scss +98 -0
  53. package/src/js/input/simple/v2/simpleInputV2.tsx +178 -0
  54. package/src/js/input/style/input.scss +138 -0
  55. package/src/js/input/v2/inputController_v2.tsx +250 -0
  56. package/src/js/input/v2/input_v2.tsx +7 -0
  57. package/src/js/label/label.tsx +196 -0
  58. package/src/js/label/style/label.scss +4 -0
  59. package/src/js/link/link.tsx +38 -0
  60. package/src/js/link/style/link.scss +30 -0
  61. package/src/js/loader/loader.tsx +79 -0
  62. package/src/js/loader/loaderController.tsx +61 -0
  63. package/src/js/loader/style/loader.scss +53 -0
  64. package/src/js/media/media.tsx +72 -0
  65. package/src/js/navigator/navigator.tsx +51 -0
  66. package/src/js/optionsList/dvrdOptionsList.tsx +112 -0
  67. package/src/js/optionsList/style/dvrdOptionsList.scss +84 -0
  68. package/src/js/optionsMenu/optionsMenu.tsx +187 -0
  69. package/src/js/optionsMenu/style/optionsMenu.scss +70 -0
  70. package/src/js/pdf/element/pdfElement.tsx +315 -0
  71. package/src/js/pdf/element/style/pdfElement.scss +111 -0
  72. package/src/js/pdf/history/pdfHistory.ts +57 -0
  73. package/src/js/pdf/image/pdfImage.tsx +175 -0
  74. package/src/js/pdf/image/style/pdfImage.scss +34 -0
  75. package/src/js/pdf/invoiceTable/pdfInvoiceTable.tsx +176 -0
  76. package/src/js/pdf/invoiceTable/style/pdfInvoiceTable.scss +32 -0
  77. package/src/js/pdf/pdfTemplateCreator.tsx +279 -0
  78. package/src/js/pdf/settings/buttons/iconButton.tsx +49 -0
  79. package/src/js/pdf/settings/buttons/style/iconButton.scss +50 -0
  80. package/src/js/pdf/settings/image/pdfImageSettings.tsx +82 -0
  81. package/src/js/pdf/settings/image/style/pdfImageSettings.scss +9 -0
  82. package/src/js/pdf/settings/invoiceTable/pdfInvoiceTableSettings.tsx +141 -0
  83. package/src/js/pdf/settings/invoiceTable/style/pdfInvoiceTableSettings.scss +38 -0
  84. package/src/js/pdf/settings/pdfElementSettings.tsx +86 -0
  85. package/src/js/pdf/settings/style/pdfElementSettings.scss +56 -0
  86. package/src/js/pdf/settings/text/pdfTextSettings.tsx +202 -0
  87. package/src/js/pdf/settings/text/style/pdfTextSettings.scss +94 -0
  88. package/src/js/pdf/style/pdfTemplateCreator.scss +118 -0
  89. package/src/js/pdf/text/pdfText.tsx +267 -0
  90. package/src/js/pdf/text/style/pdfText.scss +22 -0
  91. package/src/js/pdf/v2/pdfElement/pdfDraggableElement.tsx +193 -0
  92. package/src/js/pdf/v2/types/pdfTemplateTypes.ts +27 -0
  93. package/src/js/popup/style/withBackground.scss +29 -0
  94. package/src/js/popup/withBackground.tsx +92 -0
  95. package/src/js/select/async/asyncSelect.tsx +46 -0
  96. package/src/js/select/async/style/asyncSelect.scss +23 -0
  97. package/src/js/select/dvrdSelect.tsx +214 -0
  98. package/src/js/select/dvrdSelectController.tsx +81 -0
  99. package/src/js/select/select.tsx +310 -0
  100. package/src/js/select/selectController.tsx +341 -0
  101. package/src/js/select/style/dvrdSelect.scss +140 -0
  102. package/src/js/select/style/select.scss +199 -0
  103. package/src/js/sidebarMenu/sidebarMenu.tsx +167 -0
  104. package/src/js/sidebarMenu/style/sidebarMenu.scss +167 -0
  105. package/src/js/slider/DVRSlider.tsx +107 -0
  106. package/src/js/slider/style/DVRSlider.scss +88 -0
  107. package/src/js/snackbar/snackbar.tsx +72 -0
  108. package/src/js/snackbar/snackbarController.tsx +104 -0
  109. package/src/js/snackbar/style/snackbar.scss +46 -0
  110. package/src/js/switch/dvrdSwitch.tsx +53 -0
  111. package/src/js/switch/style/dvrdSwitch.scss +47 -0
  112. package/src/js/switch/style/switch.scss +84 -0
  113. package/src/js/switch/switch.tsx +115 -0
  114. package/src/js/switch/switchController.tsx +97 -0
  115. package/src/js/textField/dvrdInput.tsx +219 -0
  116. package/src/js/textField/dvrdInputController.tsx +97 -0
  117. package/src/js/textField/dvrdNumberInput.tsx +141 -0
  118. package/src/js/textField/dvrdPasswordInput.tsx +40 -0
  119. package/src/js/textField/style/dvrdInput.scss +114 -0
  120. package/src/js/textField/style/dvrdPassword.scss +15 -0
  121. package/src/js/topButton/style/topButton.scss +54 -0
  122. package/src/js/topButton/topButton.tsx +136 -0
  123. package/src/js/util/analyticsUtil.ts +41 -0
  124. package/src/js/util/colorUtil.ts +230 -0
  125. package/src/js/util/componentUtil.tsx +59 -0
  126. package/src/js/util/constants.ts +12 -0
  127. package/src/js/util/controlContext.tsx +46 -0
  128. package/src/js/util/controlUtil.ts +107 -0
  129. package/src/js/util/cookieUtil.ts +17 -0
  130. package/src/js/util/eventUtil.ts +65 -0
  131. package/src/js/util/googleUtil.ts +88 -0
  132. package/src/js/util/interfaces.ts +180 -0
  133. package/src/js/util/jwtUtil.ts +72 -0
  134. package/src/js/util/miscUtil.ts +170 -0
  135. package/src/js/util/momentUtil.ts +45 -0
  136. package/src/js/util/pdfUtil.ts +124 -0
  137. package/src/js/util/requestUtil.ts +145 -0
  138. package/src/js/util/responsiveUtil.ts +37 -0
  139. package/src/js/util/validationUtil.ts +13 -0
  140. package/src/res/img/lock-handle.png +0 -0
  141. package/src/res/img/lock-handle.webp +0 -0
  142. package/src/res/img/lock.png +0 -0
  143. package/src/res/img/lock.webp +0 -0
  144. package/src/style/common-icons-variables.scss +140 -0
  145. package/src/style/common-icons.scss +714 -0
  146. package/src/style/common-variables.scss +243 -0
  147. package/src/style/display-breakpoints.scss +141 -0
  148. package/src/style/fonts/common-icons.eot +0 -0
  149. package/src/style/fonts/common-icons.svg +150 -0
  150. package/src/style/fonts/common-icons.ttf +0 -0
  151. package/src/style/fonts/common-icons.woff +0 -0
  152. package/src/style/fonts/common-icons.woff2 +0 -0
  153. package/src/style/fonts/fontAwesome/css/all.css +7003 -0
  154. package/src/style/fonts/fontAwesome/css/all.min.css +6 -0
  155. package/src/style/fonts/fontAwesome/css/brands.css +1423 -0
  156. package/src/style/fonts/fontAwesome/css/brands.min.css +6 -0
  157. package/src/style/fonts/fontAwesome/css/fontawesome.css +5519 -0
  158. package/src/style/fonts/fontAwesome/css/fontawesome.min.css +6 -0
  159. package/src/style/fonts/fontAwesome/css/regular.css +19 -0
  160. package/src/style/fonts/fontAwesome/css/regular.min.css +6 -0
  161. package/src/style/fonts/fontAwesome/css/solid.css +19 -0
  162. package/src/style/fonts/fontAwesome/css/solid.min.css +6 -0
  163. package/src/style/fonts/fontAwesome/css/svg-with-js.css +634 -0
  164. package/src/style/fonts/fontAwesome/css/svg-with-js.min.css +6 -0
  165. package/src/style/fonts/fontAwesome/css/v4-font-face.css +26 -0
  166. package/src/style/fonts/fontAwesome/css/v4-font-face.min.css +6 -0
  167. package/src/style/fonts/fontAwesome/css/v4-shims.css +2146 -0
  168. package/src/style/fonts/fontAwesome/css/v4-shims.min.css +6 -0
  169. package/src/style/fonts/fontAwesome/css/v5-font-face.css +22 -0
  170. package/src/style/fonts/fontAwesome/css/v5-font-face.min.css +6 -0
  171. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.ttf +0 -0
  172. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.woff2 +0 -0
  173. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.ttf +0 -0
  174. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.woff2 +0 -0
  175. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.ttf +0 -0
  176. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.woff2 +0 -0
  177. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.ttf +0 -0
  178. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.woff2 +0 -0
  179. package/src/style/variables.scss +11 -0
  180. package/.gitignore +0 -31
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+ import './style/DVRSlider.scss';
5
+
6
+ import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
7
+ import {ChangeFunction, Colors, convertColor, generateComponentId} from "../../..";
8
+ import {ElementPosition} from '../util/interfaces';
9
+ import {ControlContext} from "../util/controlContext";
10
+ import classNames from "classnames";
11
+
12
+ interface Props {
13
+ onChange: ChangeFunction;
14
+ onMouseEnter?: MouseEventHandler;
15
+ onMouseLeave?: MouseEventHandler;
16
+ value?: number;
17
+ disabled: boolean;
18
+ id?: string;
19
+ className: string;
20
+ labelClassName: string;
21
+ style?: CSSProperties;
22
+ asNumber?: boolean;
23
+ label?: string;
24
+ labelPosition: ElementPosition;
25
+ inputProps?: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
26
+ }
27
+
28
+ export default class DVRSlider extends PureComponent<Props> {
29
+ id: string;
30
+ static defaultProps = {
31
+ min: 0,
32
+ max: 100,
33
+ step: 1,
34
+ disabled: false,
35
+ className: '',
36
+ labelClassName: '',
37
+ labelPosition: ElementPosition.RIGHT,
38
+ };
39
+ declare context: React.ContextType<typeof ControlContext>;
40
+ static contextType = ControlContext;
41
+
42
+ constructor(props: Props) {
43
+ super(props);
44
+ this.id = generateComponentId(props.id);
45
+ }
46
+
47
+ onChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
48
+ const {onChange, asNumber} = this.props, {value} = evt.target;
49
+ if (asNumber) onChange(Number(value), evt);
50
+ else onChange(value, evt);
51
+ };
52
+
53
+ onMouseEnter = (evt: React.MouseEvent) => {
54
+ const {onMouseEnter} = this.props;
55
+ this.setState({hovered: true});
56
+ if (onMouseEnter) onMouseEnter(evt);
57
+ }
58
+
59
+ onMouseLeave = (evt: React.MouseEvent) => {
60
+ const {onMouseLeave} = this.props;
61
+ this.setState({hovered: false});
62
+ if (onMouseLeave) onMouseLeave(evt);
63
+ };
64
+
65
+ getInputProps = (): React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> => {
66
+ const {inputProps} = this.props, defaultProps = {min: 0, max: 100, step: 1};
67
+ return Object.assign({}, defaultProps, inputProps);
68
+ }
69
+
70
+ getTrackColor = () => {
71
+ const {disabled} = this.props;
72
+ if (disabled) return Colors.GRAY4;
73
+ return convertColor(this.context.baseColor);
74
+ };
75
+
76
+ getControlColor = () => convertColor(this.context.baseColor);
77
+
78
+ componentDidMount = () => {
79
+ const input = document.getElementById(`${this.id}-input`);
80
+ if (input) {
81
+ window.setTimeout(() => {
82
+ input.style.setProperty('--control-color', this.getControlColor())
83
+ });
84
+ }
85
+ };
86
+
87
+ renderLabel = () => {
88
+ const {label} = this.props;
89
+ if (!label?.length) return null;
90
+ return <label className='dvr-slider-label'>{label}</label>;
91
+ };
92
+
93
+ render = () => {
94
+ const {value, disabled, className, style, labelPosition, label} = this.props;
95
+ return (
96
+ <div className={classNames('dvr-slider-container', className, label?.length && labelPosition,
97
+ disabled && 'disabled')}
98
+ id={this.id}>
99
+ {this.renderLabel()}
100
+ <input type='range' value={value} id={`${this.id}-input`} onChange={this.onChange}
101
+ disabled={disabled} className={classNames('dvr-slider', disabled && 'disabled')}
102
+ style={{backgroundColor: this.getTrackColor(), ...style}} onMouseEnter={this.onMouseEnter}
103
+ onMouseLeave={this.onMouseLeave} {...this.getInputProps()}/>
104
+ </div>
105
+ )
106
+ }
107
+ }
@@ -0,0 +1,88 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../style/variables';
6
+
7
+ .dvr-slider-container {
8
+ .dvr-slider-label {
9
+ white-space: nowrap;
10
+ }
11
+
12
+ .dvr-slider {
13
+ --control-color: black;
14
+ -webkit-appearance: none;
15
+ appearance: none;
16
+ height: 2px;
17
+ border-radius: .25rem;
18
+ outline: none;
19
+ transition: opacity .2s ease-in-out;
20
+ cursor: pointer;
21
+
22
+ &::-webkit-slider-thumb {
23
+ @include backgroundShadow;
24
+ -webkit-appearance: none;
25
+ appearance: none;
26
+ width: .75rem;
27
+ height: .75rem;
28
+ border-radius: 50%;
29
+ background: var(--control-color);
30
+ cursor: pointer;
31
+ transition: width .2s ease-in-out, height .2s ease-in-out;
32
+ }
33
+
34
+ &::-moz-range-thumb {
35
+ width: .75rem;
36
+ height: .75rem;
37
+ border-radius: 50%;
38
+ background: var(--control-color);
39
+ cursor: pointer;
40
+ transition: width .2s ease-in-out, height .2s ease-in-out;
41
+ }
42
+
43
+ &:hover {
44
+ opacity: 1;
45
+ }
46
+ }
47
+
48
+ &.top, &.bottom {
49
+ display: grid;
50
+ grid-template-columns: auto;
51
+ //justify-items: start;
52
+ grid-row-gap: .5rem;
53
+
54
+ .dvr-slider-label {
55
+ padding-left: .2rem;
56
+ }
57
+ }
58
+
59
+ &.right, &.left {
60
+ display: grid;
61
+ grid-column-gap: .5rem;
62
+ align-items: center;
63
+ //justify-items: start;
64
+ }
65
+
66
+ &.bottom, &.right {
67
+ .dvr-slider-label {
68
+ grid-area: label;
69
+ }
70
+
71
+ .dvr-input {
72
+ grid-area: input;
73
+ }
74
+ }
75
+
76
+ &.bottom {
77
+ grid-template-areas: 'input' 'label';
78
+ }
79
+
80
+ &.right {
81
+ grid-template-areas: 'input label';
82
+ grid-template-columns: 1fr min-content;
83
+ }
84
+
85
+ &.left {
86
+ grid-template-columns: min-content 1fr;
87
+ }
88
+ }
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ import './style/snackbar.scss';
6
+
7
+ import React from 'react';
8
+ import classNames from 'classnames';
9
+ import {convertColor} from "../util/colorUtil";
10
+ import {ControlContext} from "../util/controlContext";
11
+ import {Snack} from "../util/interfaces";
12
+
13
+ interface ViewProps {
14
+ onClick: any;
15
+ snack: Snack | null;
16
+ containerClass: string;
17
+ textClass: string;
18
+ backgroundColor?: string;
19
+ textColor?: string;
20
+ active: boolean;
21
+ }
22
+
23
+ export class Snackbar extends React.Component<ViewProps> {
24
+ // noinspection JSUnusedGlobalSymbols
25
+ declare context: React.ContextType<typeof ControlContext>;
26
+ static contextType = ControlContext;
27
+
28
+ getBackgroundColor = (): string => {
29
+ const {backgroundColor, snack} = this.props;
30
+ if (snack?.config?.backgroundColor) return convertColor(snack.config.backgroundColor);
31
+ if (backgroundColor) return convertColor(backgroundColor);
32
+ // noinspection JSDeprecatedSymbols
33
+ return convertColor(this.context.baseColor);
34
+ };
35
+
36
+ getTextColor = (): string => {
37
+ const {textColor, snack} = this.props;
38
+ if (snack?.config?.textColor) return convertColor(snack.config.textColor);
39
+ if (textColor !== undefined && textColor !== null) return convertColor(textColor);
40
+ // noinspection JSDeprecatedSymbols
41
+ return convertColor(this.context.contrastColor);
42
+ };
43
+
44
+ getBackgroundStyle = (): { backgroundColor: string } => ({backgroundColor: this.getBackgroundColor()});
45
+
46
+ getTextStyle = (): { color: string } => ({color: this.getTextColor()});
47
+
48
+ renderText = () => {
49
+ const {snack, textClass} = this.props;
50
+ if (!snack) return null;
51
+ const {text} = snack;
52
+ let element: React.ReactNode = null;
53
+ if (typeof text === 'string') element =
54
+ <label className={classNames('snackBarText', textClass)} style={this.getTextStyle()}>{text}</label>;
55
+ else if (text) {
56
+ const className = Object.assign({}, text.props?.className, classNames('snackBarText', textClass)),
57
+ style = Object.assign({}, text.props?.style, this.getTextStyle());
58
+ element = React.cloneElement(text, {className, style});
59
+ }
60
+ return element;
61
+ }
62
+
63
+ render = () => {
64
+ const {containerClass, active, onClick} = this.props;
65
+ return (
66
+ <div className={classNames('snackbar', active && 'active', containerClass)}
67
+ style={this.getBackgroundStyle()} onClick={onClick}>
68
+ {this.renderText()}
69
+ </div>
70
+ );
71
+ };
72
+ }
@@ -0,0 +1,104 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ import React from 'react';
6
+ import {Snackbar} from "./snackbar";
7
+ import {CustomAppEvent, DialogConfig, Snack} from "../util/interfaces";
8
+ import WithEvents from '../events/withEvents';
9
+ import {delay} from 'lodash';
10
+
11
+ interface Props {
12
+ containerClass: string;
13
+ textClass: string;
14
+ activeTime: number;
15
+ backgroundColor?: string;
16
+ textColor?: string;
17
+ maxSnacks?: number;
18
+ noDuplicates?: boolean;
19
+ }
20
+
21
+ interface State {
22
+ active: boolean;
23
+ snack: Snack | null;
24
+ config: DialogConfig;
25
+ }
26
+
27
+ export default class SnackbarController extends React.Component<Props, State> {
28
+ static defaultProps = {
29
+ activeTime: 3000,
30
+ containerClass: '',
31
+ textClass: '',
32
+ };
33
+
34
+ state: State = {
35
+ active: false,
36
+ snack: null,
37
+ config: {}
38
+ };
39
+
40
+ snackQueue: Snack[] = [];
41
+ timeout: number | null = null;
42
+
43
+ onAddSnack = (snack: Snack) => {
44
+ const {maxSnacks, noDuplicates} = this.props;
45
+ if (noDuplicates && this.isDuplicate(snack)) return;
46
+ this.snackQueue.push(snack);
47
+ if (maxSnacks !== undefined)
48
+ while (this.snackQueue.length > maxSnacks - 1)
49
+ this.snackQueue.shift();
50
+ if (!this.state.active)
51
+ this.activate();
52
+ };
53
+
54
+ onClick = () => {
55
+ if (this.timeout !== null)
56
+ window.clearTimeout(this.timeout);
57
+ this.deactivate();
58
+ };
59
+
60
+ isDuplicate = (snack: Snack): boolean => {
61
+ return this.state.snack?.text === snack.text || this.snackQueue.pop()?.text === snack.text;
62
+ }
63
+
64
+ deactivate = () => {
65
+ this.setState({active: false}, () => {
66
+ delay(() => {
67
+ // Clear snack after 200ms (css transition)
68
+ this.setState({snack: null}, () => {
69
+ if (this.snackQueue.length > 0)
70
+ this.timeout = window.setTimeout(this.activate, 500);
71
+ })
72
+ }, 200);
73
+ })
74
+ };
75
+
76
+ activate = () => {
77
+ const snack: Snack | undefined = this.snackQueue.pop();
78
+ if (snack) {
79
+ this.setState({snack}, () => {
80
+ this.setState({active: true});
81
+ this.timeout = window.setTimeout(this.deactivate, this.props.activeTime);
82
+ })
83
+ }
84
+ };
85
+
86
+ componentWillUnmount = () => {
87
+ if (this.timeout !== null)
88
+ window.clearTimeout(this.timeout);
89
+ };
90
+
91
+ getEvents = (): CustomAppEvent[] => [
92
+ {eventName: 'onShowSnackbar', handler: this.onAddSnack}
93
+ ];
94
+
95
+ render = () => {
96
+ const {snack, active} = this.state, {containerClass, textClass, textColor, backgroundColor} = this.props;
97
+ return (
98
+ <WithEvents events={this.getEvents()}>
99
+ <Snackbar snack={snack} containerClass={containerClass} textClass={textClass} active={active}
100
+ onClick={this.onClick} textColor={textColor} backgroundColor={backgroundColor}/>
101
+ </WithEvents>
102
+ )
103
+ };
104
+ }
@@ -0,0 +1,46 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../style/variables';
6
+
7
+ .snackbar {
8
+ @include backgroundShadow;
9
+ @include borderRadius(.2rem);
10
+ position: fixed;
11
+ left: 50%;
12
+ bottom: 1rem;
13
+ transition: transform .2s ease-in-out;
14
+ z-index: $z-index-dialog;
15
+ max-width: 30vw;
16
+ min-height: 2.5rem;
17
+ overflow-y: auto;
18
+ display: flex;
19
+ flex-direction: column;
20
+ justify-content: center;
21
+ transform: translateY(calc(100% + 1rem)) translateX(-50%);
22
+ padding: .3rem 1rem;
23
+
24
+ &, * {
25
+ cursor: pointer;
26
+ }
27
+
28
+ &.active {
29
+ transform: translateY(0) translateX(-50%);
30
+ }
31
+
32
+ .snackBarText {
33
+ text-align: center;
34
+ user-select: none;
35
+ }
36
+
37
+ @include break-xs {
38
+ max-width: 90vw;
39
+ width: 90vw;
40
+ white-space: normal;
41
+ }
42
+
43
+ @include break-sm {
44
+ width: unset;
45
+ }
46
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+ import './style/dvrdSwitch.scss';
5
+
6
+ import classNames from 'classnames';
7
+ import React, {useContext} from 'react';
8
+ import {ControlContext} from "../util/controlContext";
9
+ import {convertColor} from "../util/colorUtil";
10
+
11
+ interface Props {
12
+ onChange: (value: boolean, evt: React.MouseEvent) => void;
13
+ value: boolean;
14
+ className?: string;
15
+ disabled?: boolean;
16
+ activeColor?: string;
17
+ }
18
+
19
+ export default function DvrdSwitch(props: Props) {
20
+ const context = useContext(ControlContext),
21
+ {className, onChange, disabled, value, activeColor} = props;
22
+
23
+ function onToggle(evt: React.MouseEvent) {
24
+ if (!disabled)
25
+ onChange(!value, evt);
26
+ }
27
+
28
+ function getTrackColor(): string {
29
+ let color: string;
30
+ if (disabled) color = 'color-gray-4';
31
+ else if (value) {
32
+ if (activeColor) color = activeColor;
33
+ else color = context.baseColor;
34
+ } else color = 'color-gray-7';
35
+ return convertColor(color);
36
+ }
37
+
38
+ function getHandleColor(): string {
39
+ let color: string;
40
+ if (disabled) color = 'color-gray-3';
41
+ else color = context.contrastColor;
42
+ return convertColor(color);
43
+ }
44
+
45
+ return (
46
+ <div className={classNames('dvrd-switch', value && 'active', disabled && 'disabled', className)}
47
+ onClick={onToggle}>
48
+ <div className='track' style={{backgroundColor: getTrackColor()}}>
49
+ <div className='handle' style={{backgroundColor: getHandleColor()}}/>
50
+ </div>
51
+ </div>
52
+ )
53
+ }
@@ -0,0 +1,47 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../style/variables';
6
+
7
+ .dvrd-switch {
8
+ $track-height: 14px;
9
+ $handle-size: 18px;
10
+
11
+ .track {
12
+ width: $handle-size * 1.3;
13
+ border-radius: 1rem;
14
+ height: $track-height;
15
+ position: relative;
16
+
17
+ .handle {
18
+ @include backgroundShadow;
19
+ position: absolute;
20
+ left: 0;
21
+ top: 50%;
22
+ transform: translateX(-9px) translateY(-50%);
23
+ border-radius: 100%;
24
+ width: $handle-size;
25
+ height: $handle-size;
26
+ cursor: pointer;
27
+ transition: transform .2s ease-in-out, left .2s ease-in-out;
28
+ will-change: left;
29
+ }
30
+ }
31
+
32
+ &.active {
33
+ .track {
34
+ .handle {
35
+ left: 100%;
36
+ }
37
+ }
38
+ }
39
+
40
+ &.disabled {
41
+ .track {
42
+ .handle {
43
+ cursor: default;
44
+ }
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,84 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../style/variables';
6
+
7
+ .switchContainer {
8
+ display: flex;
9
+ padding: 1rem 0;
10
+ align-items: center;
11
+
12
+ .main-label {
13
+ font-size: .9rem;
14
+ color: $color-gray-5;
15
+ //margin-right: .5rem;
16
+ }
17
+
18
+ .label {
19
+ font-size: .9rem;
20
+ color: $color-gray-5;
21
+
22
+ &.left {
23
+ margin-right: .7rem;
24
+ }
25
+
26
+ &.right {
27
+ margin-left: .7rem;
28
+ }
29
+ }
30
+
31
+ .switch-track-container {
32
+ @include borderRadius(1rem);
33
+ display: flex;
34
+ position: relative;
35
+ width: 35px;
36
+ height: 1.2rem;
37
+ cursor: pointer;
38
+
39
+ .track {
40
+ border-radius: inherit;
41
+ cursor: inherit;
42
+ flex: 1;
43
+ height: inherit;
44
+ }
45
+
46
+ .switch {
47
+ @include centerY;
48
+ box-shadow: 0 1px 3px 0 rgba(0,0,0,0.2), 0 1px 1px 0 rgba(0,0,0,0.14), 0 2px 1px -1px rgba(0,0,0,0.12);
49
+ border-radius: 50%;
50
+ position: absolute;
51
+ left: -5%;
52
+ width: 20px;
53
+ height: 20px;
54
+ transition: transform .2s ease-in-out, background-color .2s ease, left .2s ease-in-out;
55
+
56
+ &.on {
57
+ left: 105%;
58
+ transform: translate(-100%, -50%);
59
+ }
60
+ }
61
+ }
62
+
63
+ &.lp {
64
+ padding: 2rem 0;
65
+ }
66
+
67
+ &.sp {
68
+ padding: .8rem 0;
69
+ }
70
+
71
+ &.disabled {
72
+ .switch-track-container {
73
+ cursor: not-allowed;
74
+
75
+ .track {
76
+ background-color: $color-gray-7 !important;
77
+ }
78
+
79
+ .switch {
80
+ background-color: $color-gray-4 !important;
81
+ }
82
+ }
83
+ }
84
+ }