@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,186 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+ import './style/datePicker.scss';
5
+
6
+ import React from 'react';
7
+ import {PureComponent} from 'react';
8
+ import {DateNumParts, PickerKey} from "../dateField";
9
+ import {ControlContext} from "../../../util/controlContext";
10
+ import {colorIsWhite, convertColor, editColor} from "../../../util/colorUtil";
11
+ import {voidFunction} from "../../../util/controlUtil";
12
+ import classNames from "classnames";
13
+ import {Moment, unitOfTime} from 'moment';
14
+ import {DateTimeParts} from "../dateFieldController";
15
+ import {toMoment} from '../../../util/momentUtil';
16
+ import AwesomeIcon from '../../../icon/awesomeIcon';
17
+
18
+ interface Props {
19
+ onChange: (key: PickerKey, value: number, add?: boolean) => VoidFunction;
20
+ getCurrentMoment: (value?: DateNumParts) => Moment;
21
+ pickerValue: DateNumParts;
22
+ dateParts: DateTimeParts;
23
+ disableAfter?: Date | Moment | string;
24
+ disableBefore?: Date | Moment | string;
25
+ disableFuture?: boolean;
26
+ disablePast?: boolean;
27
+ }
28
+
29
+ export default class DatePicker extends PureComponent<Props> {
30
+ declare context: React.ContextType<typeof ControlContext>;
31
+ static contextType = ControlContext;
32
+
33
+ onClickReset = (type: 'year' | 'month') => () => {
34
+ const {onChange} = this.props, today = toMoment();
35
+ let key: PickerKey, value: number;
36
+ if (type === 'year') {
37
+ key = PickerKey.YEAR;
38
+ value = today.year();
39
+ } else {
40
+ key = PickerKey.MONTH;
41
+ value = today.month();
42
+ }
43
+ onChange(key, value, false)();
44
+ };
45
+
46
+ onLeaveDay = (hoverAble: boolean) => (evt: React.MouseEvent<HTMLLabelElement>) => {
47
+ if (hoverAble) {
48
+ const target = evt.target as HTMLLabelElement;
49
+ target.style.backgroundColor = 'transparent';
50
+ target.style.color = convertColor('color-gray-header');
51
+ }
52
+ };
53
+
54
+ onEnterDay = (hoverAble: boolean) => (evt: React.MouseEvent<HTMLLabelElement>) => {
55
+ if (hoverAble) {
56
+ const target = evt.target as HTMLLabelElement;
57
+ target.style.backgroundColor = editColor(.1, this.getBaseColor(false));
58
+ target.style.color = this.getContrastColor(false);
59
+ }
60
+ };
61
+
62
+ getBaseColor = (allowWhite: boolean = true): string => {
63
+ let color = convertColor(this.context.baseColor);
64
+ if (!allowWhite && colorIsWhite(color)) color = convertColor(this.context.contrastColor);
65
+ return color;
66
+ };
67
+
68
+ getContrastColor = (allowWhiteBase: boolean = true): string => {
69
+ if (!allowWhiteBase) {
70
+ const base = this.getBaseColor(true);
71
+ if (colorIsWhite(base)) return base;
72
+ }
73
+ return convertColor(this.context.contrastColor);
74
+ };
75
+
76
+ getMonthLabel = (index: number): string =>
77
+ toMoment().month(index).format('MMMM');
78
+
79
+ getDaysToRender = (): { day: number, isCurrentMonth: boolean }[] => {
80
+ const daysToRender: { day: number, isCurrentMonth: boolean }[] = [],
81
+ currentMoment = this.props.getCurrentMoment(), dayPadding = currentMoment.date(1).day() - 1,
82
+ days = currentMoment.daysInMonth(), maxPrevMonth = currentMoment.subtract(1, 'month').daysInMonth();
83
+
84
+ // Add days to pad begin weekdays
85
+ for (let i = dayPadding; i > 0; i--)
86
+ daysToRender.push({day: maxPrevMonth - (i - 1), isCurrentMonth: false});
87
+
88
+ for (let day = 1; day <= days; day++) daysToRender.push({day, isCurrentMonth: true});
89
+
90
+ // Add days to pad end weekdays
91
+ for (let i = 1; daysToRender.length / 7 < 5; i++)
92
+ daysToRender.push({day: i, isCurrentMonth: false});
93
+
94
+ return daysToRender;
95
+ };
96
+
97
+ isDateDisabled = (date: Moment, granularity: unitOfTime.StartOf = 'd'): boolean => {
98
+ const {disableAfter, disableBefore, disableFuture, disablePast} = this.props, now = toMoment();
99
+ if (disablePast && date.isBefore(now, granularity)) return true;
100
+ if (disableFuture && date.isAfter(now, granularity)) return true;
101
+ if (disableAfter && date.isAfter(toMoment(disableAfter), granularity)) return true;
102
+ return !!(disableBefore && date.isBefore(toMoment(disableBefore), granularity));
103
+ };
104
+
105
+ isDayCurrent = (day: number) => {
106
+ const {pickerValue, dateParts, getCurrentMoment} = this.props, pickerCurrent = getCurrentMoment(),
107
+ currentMonth = dateParts.month.includes('m') ? toMoment().month() : Number(dateParts.month) - 1;
108
+ return pickerCurrent.month() === currentMonth && day === Number(pickerValue.day);
109
+ };
110
+
111
+ renderYearContainer = () => {
112
+ const {pickerValue, onChange} = this.props, year = pickerValue.year, baseColor = this.getBaseColor(),
113
+ contrast = this.getContrastColor();
114
+ return (
115
+ <div className='dvr-year-container' style={{backgroundColor: baseColor}}>
116
+ <AwesomeIcon name='chevron-left' className='dvr-year-toggle' style={{color: contrast}}
117
+ onClick={onChange(PickerKey.YEAR, -1)}/>
118
+ <label className='dvr-year-label' style={{color: contrast}}
119
+ onClick={this.onClickReset('year')}>{year}</label>
120
+ <AwesomeIcon name='chevron-right' className='dvr-year-toggle' style={{color: contrast}}
121
+ onClick={onChange(PickerKey.YEAR, 1)}/>
122
+ </div>
123
+ )
124
+ };
125
+
126
+ renderMonthContainer = () => {
127
+ const {pickerValue, onChange} = this.props, month = pickerValue.month;
128
+ return (
129
+ <div className='dvr-month-container'>
130
+ <AwesomeIcon name='chevron-left' className='dvr-month-toggle' onClick={onChange(PickerKey.MONTH, -1)}/>
131
+ <label className='dvr-month-label' onClick={this.onClickReset('month')}>{this.getMonthLabel(
132
+ month)}</label>
133
+ <AwesomeIcon name='chevron-right' className='dvr-month-toggle' onClick={onChange(PickerKey.MONTH, 1)}/>
134
+
135
+ </div>
136
+ )
137
+ };
138
+
139
+ renderDaysContainer = () => {
140
+ const daysToRender = this.getDaysToRender(), weekDays: string[] = [];
141
+ for (let i = 1; i <= 7; i++)
142
+ weekDays.push(toMoment().day(i).format('dd'));
143
+ return (
144
+ <div className='dvr-days-container'>
145
+ {weekDays.map((day: string, index: number) => (
146
+ <div key={index} className='dvr-day-container'>
147
+ <label className='weekday-label'>{day}</label>
148
+ </div>
149
+ ))}
150
+ {daysToRender.map(this.renderDay)}
151
+ </div>
152
+ )
153
+ };
154
+
155
+ renderDay = (dayData: { day: number, isCurrentMonth: boolean }, index: number) => {
156
+ const {day, isCurrentMonth} = dayData, {onChange} = this.props,
157
+ dayMoment = this.props.getCurrentMoment().date(day),
158
+ isDisabled = this.isDateDisabled(dayMoment) || !isCurrentMonth,
159
+ isCurrent = this.isDayCurrent(day) && isCurrentMonth, isHoverAble = !isCurrent && isCurrentMonth,
160
+ key: string = isCurrentMonth ? `day-${day}-${index}` : `other-day-${day}-${index}`;
161
+
162
+ return (
163
+ <div key={key}
164
+ className={classNames('dvr-day-container', isCurrent && 'current', isDisabled && 'disabled',
165
+ !isCurrentMonth && 'other-month')}>
166
+ <label className='day-label'
167
+ onMouseEnter={isDisabled ? voidFunction : this.onEnterDay(isHoverAble)}
168
+ onMouseLeave={isDisabled ? voidFunction : this.onLeaveDay(isHoverAble)}
169
+ style={isCurrent ?
170
+ {color: this.getContrastColor(false), backgroundColor: this.getBaseColor(false)} :
171
+ {}} onClick={isDisabled ? voidFunction :
172
+ onChange(PickerKey.DAY, day, false)}>{day}</label>
173
+ </div>
174
+ )
175
+ };
176
+
177
+ render = () => {
178
+ return (
179
+ <div className='datepicker-container'>
180
+ {this.renderYearContainer()}
181
+ {this.renderMonthContainer()}
182
+ {this.renderDaysContainer()}
183
+ </div>
184
+ )
185
+ };
186
+ }
@@ -0,0 +1,102 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../../../style/variables';
6
+
7
+ .datepicker-container {
8
+ height: 21.5rem;
9
+
10
+ .dvr-year-container {
11
+ padding: 1rem;
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+
16
+ .dvr-year-toggle {
17
+ font-size: .9rem;
18
+ cursor: pointer;
19
+ height: .9rem;
20
+ }
21
+
22
+ .dvr-year-label {
23
+ margin: 0 1rem;
24
+ font-size: 1.2rem;
25
+ font-weight: 500;
26
+ cursor: pointer;
27
+ }
28
+ }
29
+
30
+ .dvr-month-container {
31
+ color: $color-gray-header;
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ padding: 1rem;
36
+
37
+ .dvr-month-toggle {
38
+ font-size: .9rem;
39
+ height: .9rem;
40
+ cursor: pointer;
41
+ }
42
+
43
+ .dvr-month-label {
44
+ width: 6.6rem;
45
+ display: block;
46
+ text-align: center;
47
+ cursor: pointer;
48
+ }
49
+ }
50
+
51
+ .dvr-days-container {
52
+ padding: 0 1rem 1rem;
53
+ display: grid;
54
+ grid-template-columns: repeat(7, 2rem);
55
+
56
+ .day-padding {
57
+ padding: .5rem;
58
+ visibility: hidden;
59
+ }
60
+
61
+ .dvr-day-container {
62
+ width: 2rem;
63
+ height: 2rem;
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+
68
+ .weekday-label, .day-label {
69
+ font-size: .9rem;
70
+ user-select: none;
71
+ }
72
+
73
+ .weekday-label {
74
+ width: 100%;
75
+ text-align: center;
76
+ border-bottom: 1px solid $color-gray-7;
77
+ }
78
+
79
+ .day-label {
80
+ cursor: pointer;
81
+ transition: background-color .2s ease-in-out, color .2s ease-in-out;
82
+ border-radius: 50%;
83
+ padding: .25rem;
84
+ width: 1.5rem;
85
+ text-align: center;
86
+ }
87
+
88
+ &.disabled .day-label{
89
+ cursor: not-allowed;
90
+ color: $color-gray-4;
91
+ }
92
+
93
+ &.other-month {
94
+ .day-label {
95
+ color: $color-gray-4;
96
+ cursor: default;
97
+ transition: none;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,214 @@
1
+ /*
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+ import React, {KeyboardEventHandler, MouseEventHandler, PureComponent} from 'react';
5
+ import moment, {Moment} from 'moment';
6
+ import {DateType} from "../dateFieldController";
7
+ import {AwesomeIcon, ElementPosition, OrnamentShape, TextField, generateComponentId} from "../../../../../";
8
+ import {voidFunction} from "../../../util/controlUtil";
9
+ import {ErrorType} from "../../../util/interfaces";
10
+ import {DefaultInputProps} from "../../v2/inputController_v2";
11
+ import { IconName } from '@fortawesome/fontawesome-svg-core';
12
+
13
+ type DateIndex = {
14
+ index: number;
15
+ value: string;
16
+ placeholder: string;
17
+ mutable: boolean;
18
+ }
19
+
20
+ interface Props {
21
+ onClickOrnament?: MouseEventHandler;
22
+ onChange: (value: Moment) => void;
23
+ onEnter?: KeyboardEventHandler;
24
+ dateType: DateType;
25
+ value: Moment | null;
26
+ error?: ErrorType;
27
+ label?: string | number;
28
+ fullWidth?: boolean;
29
+ disabled?: boolean;
30
+ }
31
+
32
+ interface State {
33
+ indexes: DateIndex[];
34
+ }
35
+
36
+ const BACKSPACE = 'Backspace', ENTER = 'Enter', RIGHT = 'ArrowRight', LEFT = 'ArrowLeft', TAB = 'Tab';
37
+
38
+ const allowedKeys = new RegExp(`^\\d|${BACKSPACE}|${ENTER}|${RIGHT}|${LEFT}|${TAB}$`);
39
+
40
+ export default class DateInput extends PureComponent<Props, State> {
41
+ static defaultProps = DefaultInputProps;
42
+ private id = generateComponentId(null);
43
+
44
+ constructor(props: Props) {
45
+ super(props);
46
+ this.state = {
47
+ indexes: this.parseValue(props.value)
48
+ };
49
+ }
50
+
51
+ onKeyDown = (evt: React.KeyboardEvent) => {
52
+ const key = evt.key;
53
+ if (allowedKeys.test(key)) {
54
+ if (key !== TAB && key !== ENTER) {
55
+ evt.persist();
56
+ evt.preventDefault();
57
+ if (key === BACKSPACE) this.onBackspace(evt);
58
+ else if (key === RIGHT) this.setCaretPos(evt, 1);
59
+ else if (key === LEFT) this.setCaretPos(evt, -1);
60
+ else this.onEnterDigit(evt);
61
+ }
62
+ }
63
+ };
64
+
65
+ onBackspace = (evt: React.KeyboardEvent) => {
66
+ const {start, end} = this.getCaretStartEnd(evt), indexes = this.getIndexesCopy();
67
+ if (start > -1) {
68
+ if (start < end) {
69
+ // Remove selection
70
+ this.onBackspaceSelection(start, end, evt);
71
+ } else if (start > 0) {
72
+ let prevPos = start - 1, nextCaret = prevPos;
73
+ while (prevPos > 0 && !indexes[prevPos].mutable) prevPos--;
74
+ while (nextCaret > 0 && !indexes[nextCaret - 1].mutable) nextCaret--;
75
+ if (prevPos > -1) {
76
+ indexes[prevPos].value = indexes[prevPos].placeholder;
77
+ this.setState({indexes}, () => {
78
+ this.setCaretPos(evt, Math.max(0, nextCaret), false);
79
+ });
80
+ }
81
+ }
82
+ }
83
+ };
84
+
85
+ onBackspaceSelection = (start: number, end: number, evt: React.KeyboardEvent) => {
86
+ const indexes = this.getIndexesCopy();
87
+ for (let i = start; i < end; i++)
88
+ if (indexes[i].mutable) indexes[i].value = indexes[i].placeholder;
89
+ this.setState({indexes}, () => {
90
+ this.setCaretPos(evt, start, false);
91
+ })
92
+ }
93
+
94
+ onEnterDigit = (evt: React.KeyboardEvent) => {
95
+ const pos = this.getCaretPos(evt), indexes = this.getIndexesCopy();
96
+ if (pos > -1 && pos < indexes.length) {
97
+ indexes[pos].value = evt.key;
98
+ let nextPos = pos + 1;
99
+ while (nextPos < indexes.length && !indexes[nextPos].mutable) nextPos++;
100
+ this.setState({indexes}, () => {
101
+ this.setCaretPos(evt, nextPos, false);
102
+ });
103
+ }
104
+ };
105
+
106
+ getIndexesCopy = (): DateIndex[] => this.state.indexes.map((index: DateIndex) => ({
107
+ value: index.value,
108
+ mutable: index.mutable,
109
+ placeholder: index.placeholder,
110
+ index: index.index
111
+ }));
112
+
113
+ getCaretPos = (evt: React.KeyboardEvent): number => {
114
+ const target: HTMLInputElement = evt.target as HTMLInputElement,
115
+ pos = target.selectionStart;
116
+ if (pos !== null) return pos;
117
+ return -1;
118
+ };
119
+
120
+ getCaretStartEnd = (evt: React.KeyboardEvent): { start: number, end: number } => {
121
+ const target = evt.target as HTMLInputElement;
122
+ let start = target.selectionStart, end = target.selectionEnd;
123
+ if (start === null) start = -1;
124
+ if (end === null) end = -1;
125
+ return {start, end};
126
+ }
127
+
128
+ setCaretPos = (evt: React.KeyboardEvent, position: number, relative: boolean = true) => {
129
+ const target: HTMLInputElement = evt.target as HTMLInputElement;
130
+ if (relative) {
131
+ const newPosition = (target.selectionStart || 0) + position;
132
+ target.selectionStart = newPosition;
133
+ target.selectionEnd = newPosition;
134
+ } else {
135
+ target.selectionStart = position;
136
+ target.selectionEnd = position;
137
+ }
138
+ };
139
+
140
+ parseValue = (value: Moment | null): DateIndex[] => {
141
+ const indexes: DateIndex[] = [], {dateType} = this.props;
142
+ let chars: string, defaultChars: string;
143
+ if (dateType === DateType.DATE) {
144
+ defaultChars = 'dd-mm-jjjj';
145
+ chars = value ? value.format('DD-MM-YYYY') : defaultChars;
146
+ } else if (dateType === DateType.DATETIME) {
147
+ defaultChars = 'dd-mm-jjjj uu:mm';
148
+ chars = value ? value.format('DD-MM-YYYY HH:mm') : defaultChars;
149
+ } else {
150
+ defaultChars = 'uu:mm';
151
+ chars = value ? value.format('HH:mm') : defaultChars;
152
+ }
153
+ const breakPoint: number = Math.min(chars.length, defaultChars.length);
154
+ for (let i = 0; i < breakPoint; i++) {
155
+ const char = chars.charAt(i);
156
+ indexes.push({index: i, value: char, placeholder: defaultChars.charAt(i), mutable: !/[-: ]/.test(char)});
157
+ }
158
+ return indexes;
159
+ };
160
+
161
+ getStringValue = (length: number = -1): string => {
162
+ const {indexes} = this.state;
163
+ return (length > -1 ? indexes.slice(0, length) : indexes).reduce(
164
+ (prev: string, current: DateIndex) => prev + current.value, '');
165
+ };
166
+
167
+ getIconName = (): IconName => this.props.dateType === DateType.TIME ? 'clock' : 'calendar-alt';
168
+
169
+ tryOnChange = (indexes: DateIndex[]) => {
170
+ const {dateType, onChange} = this.props;
171
+ let momentValue: Moment,
172
+ format: string = dateType === DateType.DATE ? 'DD-MM-YYYY' : dateType === DateType.DATETIME ?
173
+ 'DD-MM-YYYY HH:mm' : 'HH:mm';
174
+ if (indexes.length >= format.length) {
175
+ const stringValue = this.getStringValue(format.length);
176
+ momentValue = moment(stringValue, format);
177
+ if (!/[a-zA-Z]/.test(stringValue) && momentValue.isValid()) onChange(momentValue);
178
+ }
179
+ };
180
+
181
+ indexesAreDifferent = (indexes: DateIndex[], prevIndexes: DateIndex[]) => {
182
+ if (indexes.length !== prevIndexes.length) return true;
183
+ for (let i = 0; i < indexes.length; i++)
184
+ if (indexes[i].value !== prevIndexes[i].value) return true;
185
+ return false;
186
+ };
187
+
188
+ renderOrnament = (): OrnamentShape | [] => {
189
+ const {onClickOrnament} = this.props;
190
+ if (onClickOrnament) return {
191
+ placement: ElementPosition.RIGHT,
192
+ element: <AwesomeIcon name={this.getIconName()} onClick={onClickOrnament}/>,
193
+ allowPropagation: false,
194
+ };
195
+ return [];
196
+ };
197
+
198
+ componentDidUpdate = (prevProps: Props, prevState: State) => {
199
+ const {indexes} = this.state, prevIndexes = prevState.indexes, {value} = this.props,
200
+ prevValue = prevProps.value;
201
+ if (this.indexesAreDifferent(indexes, prevIndexes)) this.tryOnChange(indexes);
202
+ if ((!prevValue && value) || (!value && prevValue) || (value && prevValue && !value.isSame(prevValue)))
203
+ this.setState({indexes: this.parseValue(value)});
204
+ };
205
+
206
+ render = () => {
207
+ const {label, error, fullWidth, onEnter, disabled} = this.props;
208
+ return (
209
+ <TextField onChange={voidFunction} value={this.getStringValue()} inputProps={{onKeyDown: this.onKeyDown}}
210
+ ornaments={this.renderOrnament()} id={this.id} label={label} error={error}
211
+ fullWidth={fullWidth} onEnter={onEnter} disabled={disabled}/>
212
+ );
213
+ };
214
+ }
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../../style/variables';
6
+
7
+ .dvr-datepicker-container {
8
+ @include backgroundShadow;
9
+ background-color: white;
10
+ min-width: 16rem;
11
+ max-width: 100vw;
12
+
13
+ &, * {
14
+ user-select: none;
15
+ }
16
+
17
+ .dvr-pickerstate-container {
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ padding: .5rem 0;
22
+ border-top: 1px solid $color-gray-7;
23
+
24
+ .selector {
25
+ color: $color-gray-4;
26
+ cursor: pointer;
27
+ transition: color .2s ease-in-out;
28
+
29
+ &:first-child {
30
+ margin-right: 1rem;
31
+ }
32
+ }
33
+ }
34
+
35
+ .dvr-datepicker-footer {
36
+ padding: .5rem;
37
+ display: flex;
38
+ justify-content: space-between;
39
+ }
40
+ }
@@ -0,0 +1,95 @@
1
+ /*!
2
+ * Copyright (c) 2021. Dave van Rijn Development
3
+ */
4
+
5
+ @import '../../../../../style/variables';
6
+
7
+ .timepicker-container {
8
+ height: 21.5rem;
9
+
10
+ .header-container {
11
+ padding: 1rem;
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+
16
+ .header-title {
17
+ font-size: 1.2rem;
18
+ font-weight: 500;
19
+ }
20
+ }
21
+
22
+ .date-label {
23
+ display: flex;
24
+ justify-content: center;
25
+ padding-top: 1rem;
26
+
27
+ &.invis {
28
+ visibility: hidden;
29
+ }
30
+ }
31
+
32
+ .time-body-container {
33
+ display: grid;
34
+ grid-template-columns: 50% 50%;
35
+ justify-items: center;
36
+ padding: 1rem;
37
+
38
+ .time-column {
39
+ display: flex;
40
+ flex-direction: column;
41
+ align-items: center;
42
+ justify-content: center;
43
+ //height: 14rem;
44
+
45
+ .time-col-title {
46
+ font-weight: 500;
47
+ margin-bottom: 1rem;
48
+ }
49
+
50
+ .time-select-background-container {
51
+ position: relative;
52
+
53
+ .selected-background {
54
+ @include centerY;
55
+ position: absolute;
56
+ width: 100%;
57
+ height: calc(100% / 3);
58
+ z-index: 0;
59
+ background-color: $color-gray-4;
60
+ }
61
+
62
+ .time-select-container {
63
+ position: relative;
64
+ border: 1px solid $color-gray-7;
65
+ border-radius: .25rem;
66
+ height: 6rem;
67
+ overflow-y: auto;
68
+ scroll-snap-type: y mandatory;
69
+ -ms-overflow-style: none;
70
+ z-index: 1;
71
+
72
+ .time-unit-container {
73
+ height: 2rem;
74
+ padding: 0 1rem;
75
+ scroll-snap-align: start;
76
+ display: flex;
77
+ align-items: center;
78
+
79
+ .time-unit-label {
80
+ height: 1rem;
81
+ }
82
+
83
+ &.invis {
84
+ visibility: hidden;
85
+ }
86
+ }
87
+
88
+ &::-webkit-scrollbar {
89
+ display: none;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }