@dvrd/dvr-controls 1.0.4 → 1.0.7

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 (177) hide show
  1. package/package.json +1 -1
  2. package/src/js/button/button.tsx +0 -102
  3. package/src/js/button/buttonController.tsx +0 -179
  4. package/src/js/button/closeButton.tsx +0 -29
  5. package/src/js/button/dvrdButton.tsx +0 -128
  6. package/src/js/button/outlinedButton.tsx +0 -105
  7. package/src/js/button/simpleButton.tsx +0 -163
  8. package/src/js/button/style/button.scss +0 -95
  9. package/src/js/button/style/closeButton.scss +0 -15
  10. package/src/js/button/style/dvrdButton.scss +0 -30
  11. package/src/js/button/style/outlinedButton.scss +0 -84
  12. package/src/js/button/style/simpleButton.scss +0 -80
  13. package/src/js/carousel/DVRCarousel.tsx +0 -163
  14. package/src/js/carousel/DVRCarouselController.tsx +0 -95
  15. package/src/js/carousel/style/DVRCarousel.scss +0 -38
  16. package/src/js/checkbox/checkbox.tsx +0 -147
  17. package/src/js/checkbox/checkboxController.tsx +0 -131
  18. package/src/js/checkbox/style/checkbox.scss +0 -109
  19. package/src/js/colorPicker/colorPicker.tsx +0 -118
  20. package/src/js/colorPicker/style/colorPicker.scss +0 -20
  21. package/src/js/date/dvrdDatePicker.tsx +0 -357
  22. package/src/js/date/style/dvrdDatePicker.scss +0 -307
  23. package/src/js/dialog/dialog.tsx +0 -207
  24. package/src/js/dialog/dialogController.tsx +0 -70
  25. package/src/js/dialog/inlineDialog.tsx +0 -127
  26. package/src/js/dialog/style/dialog.scss +0 -61
  27. package/src/js/events/withEvents.tsx +0 -40
  28. package/src/js/head/DVRHead.tsx +0 -49
  29. package/src/js/header/DVRHeader.tsx +0 -413
  30. package/src/js/header/style/header.scss +0 -206
  31. package/src/js/icon/awesomeIcon.tsx +0 -46
  32. package/src/js/image/imageUpload.tsx +0 -69
  33. package/src/js/image/style/imageUpload.scss +0 -11
  34. package/src/js/info/info.tsx +0 -136
  35. package/src/js/info/style/info.scss +0 -39
  36. package/src/js/input/animated/animatedTextField.tsx +0 -159
  37. package/src/js/input/date/dateField.tsx +0 -360
  38. package/src/js/input/date/dateFieldController.tsx +0 -245
  39. package/src/js/input/date/datePicker/datePicker.tsx +0 -186
  40. package/src/js/input/date/datePicker/style/datePicker.scss +0 -102
  41. package/src/js/input/date/input/dateInput.tsx +0 -213
  42. package/src/js/input/date/style/dateField.scss +0 -40
  43. package/src/js/input/date/timePicker/style/timePicker.scss +0 -95
  44. package/src/js/input/date/timePicker/timePicker.tsx +0 -143
  45. package/src/js/input/editor/DVREditor.tsx +0 -21
  46. package/src/js/input/number/numberInput.tsx +0 -157
  47. package/src/js/input/password/passwordInput.tsx +0 -140
  48. package/src/js/input/password/passwordRules.tsx +0 -48
  49. package/src/js/input/password/style/passwordInput.scss +0 -39
  50. package/src/js/input/password/style/passwordRules.scss +0 -41
  51. package/src/js/input/simple/style/simpleInput.scss +0 -98
  52. package/src/js/input/simple/v2/simpleInputV2.tsx +0 -178
  53. package/src/js/input/style/input.scss +0 -138
  54. package/src/js/input/v2/inputController_v2.tsx +0 -250
  55. package/src/js/input/v2/input_v2.tsx +0 -7
  56. package/src/js/label/label.tsx +0 -196
  57. package/src/js/label/style/label.scss +0 -4
  58. package/src/js/link/link.tsx +0 -37
  59. package/src/js/link/style/link.scss +0 -30
  60. package/src/js/loader/loader.tsx +0 -79
  61. package/src/js/loader/loaderController.tsx +0 -61
  62. package/src/js/loader/style/loader.scss +0 -53
  63. package/src/js/media/media.tsx +0 -72
  64. package/src/js/navigator/navigator.tsx +0 -51
  65. package/src/js/optionsList/dvrdOptionsList.tsx +0 -112
  66. package/src/js/optionsList/style/dvrdOptionsList.scss +0 -84
  67. package/src/js/optionsMenu/optionsMenu.tsx +0 -187
  68. package/src/js/optionsMenu/style/optionsMenu.scss +0 -70
  69. package/src/js/pdf/element/pdfElement.tsx +0 -315
  70. package/src/js/pdf/element/style/pdfElement.scss +0 -111
  71. package/src/js/pdf/history/pdfHistory.ts +0 -57
  72. package/src/js/pdf/image/pdfImage.tsx +0 -175
  73. package/src/js/pdf/image/style/pdfImage.scss +0 -34
  74. package/src/js/pdf/invoiceTable/pdfInvoiceTable.tsx +0 -176
  75. package/src/js/pdf/invoiceTable/style/pdfInvoiceTable.scss +0 -32
  76. package/src/js/pdf/pdfTemplateCreator.tsx +0 -278
  77. package/src/js/pdf/settings/buttons/iconButton.tsx +0 -49
  78. package/src/js/pdf/settings/buttons/style/iconButton.scss +0 -50
  79. package/src/js/pdf/settings/image/pdfImageSettings.tsx +0 -82
  80. package/src/js/pdf/settings/image/style/pdfImageSettings.scss +0 -9
  81. package/src/js/pdf/settings/invoiceTable/pdfInvoiceTableSettings.tsx +0 -141
  82. package/src/js/pdf/settings/invoiceTable/style/pdfInvoiceTableSettings.scss +0 -38
  83. package/src/js/pdf/settings/pdfElementSettings.tsx +0 -86
  84. package/src/js/pdf/settings/style/pdfElementSettings.scss +0 -56
  85. package/src/js/pdf/settings/text/pdfTextSettings.tsx +0 -202
  86. package/src/js/pdf/settings/text/style/pdfTextSettings.scss +0 -94
  87. package/src/js/pdf/style/pdfTemplateCreator.scss +0 -118
  88. package/src/js/pdf/text/pdfText.tsx +0 -267
  89. package/src/js/pdf/text/style/pdfText.scss +0 -22
  90. package/src/js/popup/style/withBackground.scss +0 -29
  91. package/src/js/popup/withBackground.tsx +0 -102
  92. package/src/js/select/async/asyncSelect.tsx +0 -46
  93. package/src/js/select/async/style/asyncSelect.scss +0 -23
  94. package/src/js/select/dvrdSelect.tsx +0 -185
  95. package/src/js/select/dvrdSelectController.tsx +0 -81
  96. package/src/js/select/select.tsx +0 -310
  97. package/src/js/select/selectController.tsx +0 -341
  98. package/src/js/select/style/dvrdSelect.scss +0 -140
  99. package/src/js/select/style/select.scss +0 -199
  100. package/src/js/sidebarMenu/sidebarMenu.tsx +0 -165
  101. package/src/js/sidebarMenu/style/sidebarMenu.scss +0 -161
  102. package/src/js/slider/DVRSlider.tsx +0 -107
  103. package/src/js/slider/style/DVRSlider.scss +0 -88
  104. package/src/js/snackbar/snackbar.tsx +0 -72
  105. package/src/js/snackbar/snackbarController.tsx +0 -104
  106. package/src/js/snackbar/style/snackbar.scss +0 -46
  107. package/src/js/switch/dvrdSwitch.tsx +0 -53
  108. package/src/js/switch/style/dvrdSwitch.scss +0 -47
  109. package/src/js/switch/style/switch.scss +0 -84
  110. package/src/js/switch/switch.tsx +0 -115
  111. package/src/js/switch/switchController.tsx +0 -97
  112. package/src/js/textField/dvrdInput.tsx +0 -217
  113. package/src/js/textField/dvrdInputController.tsx +0 -97
  114. package/src/js/textField/dvrdNumberInput.tsx +0 -141
  115. package/src/js/textField/dvrdPasswordInput.tsx +0 -40
  116. package/src/js/textField/style/dvrdInput.scss +0 -114
  117. package/src/js/textField/style/dvrdPassword.scss +0 -15
  118. package/src/js/topButton/style/topButton.scss +0 -54
  119. package/src/js/topButton/topButton.tsx +0 -135
  120. package/src/js/util/analyticsUtil.ts +0 -41
  121. package/src/js/util/colorUtil.ts +0 -230
  122. package/src/js/util/componentUtil.tsx +0 -59
  123. package/src/js/util/constants.ts +0 -12
  124. package/src/js/util/controlContext.tsx +0 -46
  125. package/src/js/util/controlUtil.ts +0 -107
  126. package/src/js/util/cookieUtil.ts +0 -17
  127. package/src/js/util/eventUtil.ts +0 -65
  128. package/src/js/util/googleUtil.ts +0 -88
  129. package/src/js/util/interfaces.ts +0 -179
  130. package/src/js/util/jwtUtil.ts +0 -72
  131. package/src/js/util/miscUtil.ts +0 -170
  132. package/src/js/util/momentUtil.ts +0 -45
  133. package/src/js/util/pdfUtil.ts +0 -124
  134. package/src/js/util/requestUtil.ts +0 -146
  135. package/src/js/util/responsiveUtil.ts +0 -37
  136. package/src/js/util/validationUtil.ts +0 -13
  137. package/src/res/img/lock-handle.png +0 -0
  138. package/src/res/img/lock-handle.webp +0 -0
  139. package/src/res/img/lock.png +0 -0
  140. package/src/res/img/lock.webp +0 -0
  141. package/src/style/common-icons-variables.scss +0 -140
  142. package/src/style/common-icons.scss +0 -714
  143. package/src/style/common-variables.scss +0 -243
  144. package/src/style/display-breakpoints.scss +0 -141
  145. package/src/style/fonts/common-icons.eot +0 -0
  146. package/src/style/fonts/common-icons.svg +0 -150
  147. package/src/style/fonts/common-icons.ttf +0 -0
  148. package/src/style/fonts/common-icons.woff +0 -0
  149. package/src/style/fonts/common-icons.woff2 +0 -0
  150. package/src/style/fonts/fontAwesome/css/all.css +0 -7003
  151. package/src/style/fonts/fontAwesome/css/all.min.css +0 -6
  152. package/src/style/fonts/fontAwesome/css/brands.css +0 -1423
  153. package/src/style/fonts/fontAwesome/css/brands.min.css +0 -6
  154. package/src/style/fonts/fontAwesome/css/fontawesome.css +0 -5519
  155. package/src/style/fonts/fontAwesome/css/fontawesome.min.css +0 -6
  156. package/src/style/fonts/fontAwesome/css/regular.css +0 -19
  157. package/src/style/fonts/fontAwesome/css/regular.min.css +0 -6
  158. package/src/style/fonts/fontAwesome/css/solid.css +0 -19
  159. package/src/style/fonts/fontAwesome/css/solid.min.css +0 -6
  160. package/src/style/fonts/fontAwesome/css/svg-with-js.css +0 -634
  161. package/src/style/fonts/fontAwesome/css/svg-with-js.min.css +0 -6
  162. package/src/style/fonts/fontAwesome/css/v4-font-face.css +0 -26
  163. package/src/style/fonts/fontAwesome/css/v4-font-face.min.css +0 -6
  164. package/src/style/fonts/fontAwesome/css/v4-shims.css +0 -2146
  165. package/src/style/fonts/fontAwesome/css/v4-shims.min.css +0 -6
  166. package/src/style/fonts/fontAwesome/css/v5-font-face.css +0 -22
  167. package/src/style/fonts/fontAwesome/css/v5-font-face.min.css +0 -6
  168. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.ttf +0 -0
  169. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.woff2 +0 -0
  170. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.ttf +0 -0
  171. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.woff2 +0 -0
  172. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.ttf +0 -0
  173. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.woff2 +0 -0
  174. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.ttf +0 -0
  175. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.woff2 +0 -0
  176. package/src/style/variables.scss +0 -11
  177. package/tsconfig.json +0 -15
@@ -1,186 +0,0 @@
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
- }
@@ -1,102 +0,0 @@
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
- }
@@ -1,213 +0,0 @@
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
-
12
- type DateIndex = {
13
- index: number;
14
- value: string;
15
- placeholder: string;
16
- mutable: boolean;
17
- }
18
-
19
- interface Props {
20
- onClickOrnament?: MouseEventHandler;
21
- onChange: (value: Moment) => void;
22
- onEnter?: KeyboardEventHandler;
23
- dateType: DateType;
24
- value: Moment | null;
25
- error?: ErrorType;
26
- label?: string | number;
27
- fullWidth?: boolean;
28
- disabled?: boolean;
29
- }
30
-
31
- interface State {
32
- indexes: DateIndex[];
33
- }
34
-
35
- const BACKSPACE = 'Backspace', ENTER = 'Enter', RIGHT = 'ArrowRight', LEFT = 'ArrowLeft', TAB = 'Tab';
36
-
37
- const allowedKeys = new RegExp(`^\\d|${BACKSPACE}|${ENTER}|${RIGHT}|${LEFT}|${TAB}$`);
38
-
39
- export default class DateInput extends PureComponent<Props, State> {
40
- static defaultProps = DefaultInputProps;
41
- private id = generateComponentId(null);
42
-
43
- constructor(props: Props) {
44
- super(props);
45
- this.state = {
46
- indexes: this.parseValue(props.value)
47
- };
48
- }
49
-
50
- onKeyDown = (evt: React.KeyboardEvent) => {
51
- const key = evt.key;
52
- if (allowedKeys.test(key)) {
53
- if (key !== TAB && key !== ENTER) {
54
- evt.persist();
55
- evt.preventDefault();
56
- if (key === BACKSPACE) this.onBackspace(evt);
57
- else if (key === RIGHT) this.setCaretPos(evt, 1);
58
- else if (key === LEFT) this.setCaretPos(evt, -1);
59
- else this.onEnterDigit(evt);
60
- }
61
- }
62
- };
63
-
64
- onBackspace = (evt: React.KeyboardEvent) => {
65
- const {start, end} = this.getCaretStartEnd(evt), indexes = this.getIndexesCopy();
66
- if (start > -1) {
67
- if (start < end) {
68
- // Remove selection
69
- this.onBackspaceSelection(start, end, evt);
70
- } else if (start > 0) {
71
- let prevPos = start - 1, nextCaret = prevPos;
72
- while (prevPos > 0 && !indexes[prevPos].mutable) prevPos--;
73
- while (nextCaret > 0 && !indexes[nextCaret - 1].mutable) nextCaret--;
74
- if (prevPos > -1) {
75
- indexes[prevPos].value = indexes[prevPos].placeholder;
76
- this.setState({indexes}, () => {
77
- this.setCaretPos(evt, Math.max(0, nextCaret), false);
78
- });
79
- }
80
- }
81
- }
82
- };
83
-
84
- onBackspaceSelection = (start: number, end: number, evt: React.KeyboardEvent) => {
85
- const indexes = this.getIndexesCopy();
86
- for (let i = start; i < end; i++)
87
- if (indexes[i].mutable) indexes[i].value = indexes[i].placeholder;
88
- this.setState({indexes}, () => {
89
- this.setCaretPos(evt, start, false);
90
- })
91
- }
92
-
93
- onEnterDigit = (evt: React.KeyboardEvent) => {
94
- const pos = this.getCaretPos(evt), indexes = this.getIndexesCopy();
95
- if (pos > -1 && pos < indexes.length) {
96
- indexes[pos].value = evt.key;
97
- let nextPos = pos + 1;
98
- while (nextPos < indexes.length && !indexes[nextPos].mutable) nextPos++;
99
- this.setState({indexes}, () => {
100
- this.setCaretPos(evt, nextPos, false);
101
- });
102
- }
103
- };
104
-
105
- getIndexesCopy = (): DateIndex[] => this.state.indexes.map((index: DateIndex) => ({
106
- value: index.value,
107
- mutable: index.mutable,
108
- placeholder: index.placeholder,
109
- index: index.index
110
- }));
111
-
112
- getCaretPos = (evt: React.KeyboardEvent): number => {
113
- const target: HTMLInputElement = evt.target as HTMLInputElement,
114
- pos = target.selectionStart;
115
- if (pos !== null) return pos;
116
- return -1;
117
- };
118
-
119
- getCaretStartEnd = (evt: React.KeyboardEvent): { start: number, end: number } => {
120
- const target = evt.target as HTMLInputElement;
121
- let start = target.selectionStart, end = target.selectionEnd;
122
- if (start === null) start = -1;
123
- if (end === null) end = -1;
124
- return {start, end};
125
- }
126
-
127
- setCaretPos = (evt: React.KeyboardEvent, position: number, relative: boolean = true) => {
128
- const target: HTMLInputElement = evt.target as HTMLInputElement;
129
- if (relative) {
130
- const newPosition = (target.selectionStart || 0) + position;
131
- target.selectionStart = newPosition;
132
- target.selectionEnd = newPosition;
133
- } else {
134
- target.selectionStart = position;
135
- target.selectionEnd = position;
136
- }
137
- };
138
-
139
- parseValue = (value: Moment | null): DateIndex[] => {
140
- const indexes: DateIndex[] = [], {dateType} = this.props;
141
- let chars: string, defaultChars: string;
142
- if (dateType === DateType.DATE) {
143
- defaultChars = 'dd-mm-jjjj';
144
- chars = value ? value.format('DD-MM-YYYY') : defaultChars;
145
- } else if (dateType === DateType.DATETIME) {
146
- defaultChars = 'dd-mm-jjjj uu:mm';
147
- chars = value ? value.format('DD-MM-YYYY HH:mm') : defaultChars;
148
- } else {
149
- defaultChars = 'uu:mm';
150
- chars = value ? value.format('HH:mm') : defaultChars;
151
- }
152
- const breakPoint: number = Math.min(chars.length, defaultChars.length);
153
- for (let i = 0; i < breakPoint; i++) {
154
- const char = chars.charAt(i);
155
- indexes.push({index: i, value: char, placeholder: defaultChars.charAt(i), mutable: !/[-: ]/.test(char)});
156
- }
157
- return indexes;
158
- };
159
-
160
- getStringValue = (length: number = -1): string => {
161
- const {indexes} = this.state;
162
- return (length > -1 ? indexes.slice(0, length) : indexes).reduce(
163
- (prev: string, current: DateIndex) => prev + current.value, '');
164
- };
165
-
166
- getIconName = (): string => this.props.dateType === DateType.TIME ? 'clock' : 'calendar-alt';
167
-
168
- tryOnChange = (indexes: DateIndex[]) => {
169
- const {dateType, onChange} = this.props;
170
- let momentValue: Moment,
171
- format: string = dateType === DateType.DATE ? 'DD-MM-YYYY' : dateType === DateType.DATETIME ?
172
- 'DD-MM-YYYY HH:mm' : 'HH:mm';
173
- if (indexes.length >= format.length) {
174
- const stringValue = this.getStringValue(format.length);
175
- momentValue = moment(stringValue, format);
176
- if (!/[a-zA-Z]/.test(stringValue) && momentValue.isValid()) onChange(momentValue);
177
- }
178
- };
179
-
180
- indexesAreDifferent = (indexes: DateIndex[], prevIndexes: DateIndex[]) => {
181
- if (indexes.length !== prevIndexes.length) return true;
182
- for (let i = 0; i < indexes.length; i++)
183
- if (indexes[i].value !== prevIndexes[i].value) return true;
184
- return false;
185
- };
186
-
187
- renderOrnament = (): OrnamentShape | [] => {
188
- const {onClickOrnament} = this.props;
189
- if (onClickOrnament) return {
190
- placement: ElementPosition.RIGHT,
191
- element: <AwesomeIcon name={this.getIconName()} onClick={onClickOrnament}/>,
192
- allowPropagation: false,
193
- };
194
- return [];
195
- };
196
-
197
- componentDidUpdate = (prevProps: Props, prevState: State) => {
198
- const {indexes} = this.state, prevIndexes = prevState.indexes, {value} = this.props,
199
- prevValue = prevProps.value;
200
- if (this.indexesAreDifferent(indexes, prevIndexes)) this.tryOnChange(indexes);
201
- if ((!prevValue && value) || (!value && prevValue) || (value && prevValue && !value.isSame(prevValue)))
202
- this.setState({indexes: this.parseValue(value)});
203
- };
204
-
205
- render = () => {
206
- const {label, error, fullWidth, onEnter, disabled} = this.props;
207
- return (
208
- <TextField onChange={voidFunction} value={this.getStringValue()} inputProps={{onKeyDown: this.onKeyDown}}
209
- ornaments={this.renderOrnament()} id={this.id} label={label} error={error}
210
- fullWidth={fullWidth} onEnter={onEnter} disabled={disabled}/>
211
- );
212
- };
213
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,95 +0,0 @@
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
- }