@dvrd/dvr-controls 1.1.18 → 1.1.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  ]
26
26
  },
27
27
  "dependencies": {
28
- "@dvrd/idate": "^1.8.8",
28
+ "@dvrd/idate": "*",
29
29
  "@fortawesome/fontawesome-svg-core": "*",
30
30
  "@fortawesome/free-brands-svg-icons": "*",
31
31
  "@fortawesome/free-regular-svg-icons": "*",
@@ -18,10 +18,10 @@ import React, {
18
18
  import {ChangeFunction, DatePickerTimeMode, ErrorType} from '../util/interfaces';
19
19
  import AwesomeIcon from '../icon/awesomeIcon';
20
20
  import WithBackground from '../popup/withBackground';
21
- import DvrdButton from "../button/dvrdButton";
22
- import {generateComponentId} from "../util/componentUtil";
21
+ import DvrdButton from '../button/dvrdButton';
22
+ import {generateComponentId} from '../util/componentUtil';
23
23
  import IDate from '@dvrd/idate';
24
- import {pad} from "../util/controlUtil";
24
+ import {pad} from '../util/controlUtil';
25
25
  import {Swiper, SwiperClass, SwiperSlide} from 'swiper/react';
26
26
  import {FreeMode, Mousewheel} from 'swiper/modules';
27
27
  import 'swiper/css';
@@ -102,7 +102,7 @@ function DvrdDatePicker(props: Props, ref: ForwardedRef<DVRDDatePickerRef>) {
102
102
  placeholder={placeholder} className='native-date-field' id={`${id}-native`}/>
103
103
  <AwesomeIcon name='calendar-alt' className='calendar-icon' htmlFor={`${id}-native`}/>
104
104
  </div>
105
- )
105
+ );
106
106
  }
107
107
 
108
108
  useImperativeHandle(ref, () => ({onOpen: onClickContainer, onClose: onClosePicker}));
@@ -125,7 +125,7 @@ function DvrdDatePicker(props: Props, ref: ForwardedRef<DVRDDatePickerRef>) {
125
125
  open={timePickerOpen} timeMode={timeMode} closeOnChange={closeOnChange}/>}
126
126
  {!pickersOnly && <label className='error-label'>{error}</label>}
127
127
  </div>
128
- )
128
+ );
129
129
  }
130
130
 
131
131
  interface DatePickerProps {
@@ -148,14 +148,14 @@ function DatePicker(props: DatePickerProps) {
148
148
  const padBeforeDays: number[] = [];
149
149
  const padAfterDays: number[] = [];
150
150
  for (let i = 1; i <= daysInMonth; i++) days.push(i);
151
- let firstMonthDay = pickerValue.clone().day(1).weekday();
151
+ let firstMonthDay = pickerValue.day(1).weekday();
152
152
  if (!firstMonthDay) firstMonthDay = 7;
153
153
  const padDaysBefore = firstMonthDay - 1;
154
- let dayBefore = pickerValue.clone().add(-1, 'month').daysInMonth()
154
+ let dayBefore = pickerValue.add(-1, 'month').daysInMonth();
155
155
  for (let i = 0; i < padDaysBefore; i++)
156
156
  padBeforeDays.splice(0, 0, dayBefore--);
157
157
 
158
- const lastWeekDay = pickerValue.clone().day(daysInMonth).weekday();
158
+ const lastWeekDay = pickerValue.day(daysInMonth).weekday();
159
159
  const padDaysAfter = 7 - lastWeekDay;
160
160
  for (let i = 0; i < padDaysAfter; i++)
161
161
  padAfterDays.push(i + 1);
@@ -170,30 +170,30 @@ function DatePicker(props: DatePickerProps) {
170
170
 
171
171
  function onReduce(key: 'year' | 'month') {
172
172
  return function () {
173
- const value = pickerValue.clone();
174
- value.add(-1, key);
175
- value.day(Math.min(value.daysInMonth(), value.day()))
173
+ let value = pickerValue.clone();
174
+ value = value.add(-1, key);
175
+ value = value.day(Math.min(value.daysInMonth(), value.day()));
176
176
  onChange(false)(value);
177
- }
177
+ };
178
178
  }
179
179
 
180
180
  function onAdd(key: 'year' | 'month') {
181
181
  return function () {
182
- const value = pickerValue.clone();
183
- value.add(1, key);
184
- value.day(Math.min(value.daysInMonth(), value.day()))
182
+ let value = pickerValue.clone();
183
+ value = value.add(1, key);
184
+ value = value.day(Math.min(value.daysInMonth(), value.day()));
185
185
  onChange(false)(value);
186
- }
186
+ };
187
187
  }
188
188
 
189
189
  function onResetSwitcher(key: 'year' | 'month') {
190
190
  return function () {
191
- const value = pickerValue.clone();
192
- if (key === 'year') value.year(IDate.now().year());
193
- else value.month(IDate.now().month());
194
- value.day(Math.min(value.daysInMonth(), value.day()))
191
+ let value = pickerValue.clone();
192
+ if (key === 'year') value = value.year(IDate.now().year());
193
+ else value = value.month(IDate.now().month());
194
+ value = value.day(Math.min(value.daysInMonth(), value.day()));
195
195
  onChange(false)(value);
196
- }
196
+ };
197
197
  }
198
198
 
199
199
  function onClickToday() {
@@ -202,24 +202,24 @@ function DatePicker(props: DatePickerProps) {
202
202
 
203
203
  function onSelectDay(day: number, month?: number, year?: number) {
204
204
  return function () {
205
- const pickValue = pickerValue.clone();
205
+ let pickValue = pickerValue.clone();
206
206
  if (day || value === null) {
207
- pickValue.day(day);
208
- if (month !== undefined) pickValue.month(month);
209
- if (year !== undefined) pickValue.year(year);
207
+ pickValue = pickValue.day(day);
208
+ if (month !== undefined) pickValue = pickValue.month(month);
209
+ if (year !== undefined) pickValue = pickValue.year(year);
210
210
  onChange(true)(pickValue);
211
211
  }
212
- }
212
+ };
213
213
  }
214
214
 
215
215
  function onSelectPadDay(day: number, kind: 'prev' | 'next') {
216
216
  return function () {
217
- const value = pickerValue.clone();
218
- if (kind === 'prev') value.add(-1, 'month');
219
- else value.add(1, 'month');
220
- value.day(day);
217
+ let value = pickerValue.clone();
218
+ if (kind === 'prev') value = value.add(-1, 'month');
219
+ else value = value.add(1, 'month');
220
+ value = value.day(day);
221
221
  onChange(true)(value);
222
- }
222
+ };
223
223
  }
224
224
 
225
225
  function keyListener(evt: KeyboardEvent) {
@@ -235,29 +235,25 @@ function DatePicker(props: DatePickerProps) {
235
235
  }
236
236
 
237
237
  function onLeftKey(shiftKey: boolean, ctrlKey: boolean) {
238
- const value = pickerValue.clone();
239
238
  if (shiftKey) {
240
239
  if (ctrlKey) onReduce('year')();
241
240
  else onReduce('month')();
242
- } else onChange(false)(value.add(-1, 'days'));
241
+ } else onChange(false)(pickerValue.add(-1, 'days'));
243
242
  }
244
243
 
245
244
  function onRightKey(shiftKey: boolean, ctrlKey: boolean) {
246
- const value = pickerValue.clone();
247
245
  if (shiftKey) {
248
246
  if (ctrlKey) onAdd('year')();
249
247
  else onAdd('month')();
250
- } else onChange(false)(value.add(1, 'days'));
248
+ } else onChange(false)(pickerValue.add(1, 'days'));
251
249
  }
252
250
 
253
251
  function onUpKey() {
254
- const value = pickerValue.clone();
255
- onChange(false)(value.add(-7, 'days'));
252
+ onChange(false)(pickerValue.add(-7, 'days'));
256
253
  }
257
254
 
258
255
  function onDownKey() {
259
- const value = pickerValue.clone();
260
- onChange(false)(value.add(7, 'days'));
256
+ onChange(false)(pickerValue.add(7, 'days'));
261
257
  }
262
258
 
263
259
  function addMountClass() {
@@ -273,10 +269,10 @@ function DatePicker(props: DatePickerProps) {
273
269
 
274
270
  function dateIsDisabled(day: number, month?: number, year?: number) {
275
271
  if (!min && !max) return false;
276
- const pickValue = pickerValue.clone();
277
- pickValue.day(day);
278
- if (month !== undefined) pickValue.month(month);
279
- if (year !== undefined) pickValue.year(year);
272
+ let pickValue = pickerValue.clone();
273
+ pickValue = pickValue.day(day);
274
+ if (month !== undefined) pickValue = pickValue.month(month);
275
+ if (year !== undefined) pickValue = pickValue.year(year);
280
276
  if (min && new IDate(min).isAfter(pickValue, 'day')) return true;
281
277
  else if (max && new IDate(max).isBefore(pickValue, 'day')) return true;
282
278
  return false;
@@ -286,7 +282,7 @@ function DatePicker(props: DatePickerProps) {
286
282
  const icon = kind === 'add' ? 'chevron-right' : 'chevron-left';
287
283
  const title = kind === 'add' ? 'Volgende' : 'Vorige';
288
284
  const onClick = kind === 'add' ? onAdd(key) : onReduce(key);
289
- return <AwesomeIcon name={icon} title={title} className={classNames('switcher-icon', kind)} onClick={onClick}/>
285
+ return <AwesomeIcon name={icon} title={title} className={classNames('switcher-icon', kind)} onClick={onClick}/>;
290
286
  }
291
287
 
292
288
  function renderTooltipContainer() {
@@ -349,7 +345,7 @@ function DatePicker(props: DatePickerProps) {
349
345
  </div>
350
346
  </div>
351
347
  </div>
352
- )
348
+ );
353
349
  }
354
350
 
355
351
  useEffect(() => {
@@ -362,7 +358,7 @@ function DatePicker(props: DatePickerProps) {
362
358
  }
363
359
  return function () {
364
360
  document.removeEventListener('keydown', keyListener);
365
- }
361
+ };
366
362
  }, [open]);
367
363
 
368
364
  function renderDay(day: number, index: number, onClick: MouseEventHandler, className?: string,
@@ -380,7 +376,7 @@ function DatePicker(props: DatePickerProps) {
380
376
  onClick={disabled ? undefined : onClick} key={index}>
381
377
  <span className='day-label'>{day}</span>
382
378
  </div>
383
- )
379
+ );
384
380
  }
385
381
 
386
382
  return (
@@ -442,7 +438,7 @@ function DatePicker(props: DatePickerProps) {
442
438
  </div>
443
439
  </div>
444
440
  </WithBackground>
445
- )
441
+ );
446
442
  }
447
443
 
448
444
  interface TimePickerProps {
@@ -456,7 +452,7 @@ interface TimePickerProps {
456
452
 
457
453
  function TimePicker(props: TimePickerProps) {
458
454
  const {onChange, value, open, onClose, timeMode, closeOnChange} = props;
459
- const internalValue = useRef<IDate>(value ?? new IDate('00:00:00', 'HH:mm:ss'));
455
+ const internalValue = useRef<IDate>(value ?? new IDate('00:00:00', {dateFormat: 'HH:mm:ss', generative: true}));
460
456
 
461
457
  function onClickNow() {
462
458
  internalValue.current = IDate.now();
@@ -469,7 +465,7 @@ function TimePicker(props: TimePickerProps) {
469
465
  if (key === 'hour') internalValue.current = internalValue.current.hours(swiper.realIndex);
470
466
  if (key === 'minute') internalValue.current = internalValue.current.minutes(swiper.realIndex);
471
467
  if (key === 'second') internalValue.current = internalValue.current.seconds(swiper.realIndex);
472
- }
468
+ };
473
469
  }
474
470
 
475
471
  function onSubmit() {
@@ -478,8 +474,10 @@ function TimePicker(props: TimePickerProps) {
478
474
  }
479
475
 
480
476
  function renderTimeContainer() {
481
- const renderHours = [DatePickerTimeMode.FULL, DatePickerTimeMode.HOURS_MINUTES, DatePickerTimeMode.HOURS_ONLY].includes(timeMode);
482
- const renderMinutes = [DatePickerTimeMode.FULL, DatePickerTimeMode.HOURS_MINUTES, DatePickerTimeMode.MINUTES_ONLY].includes(timeMode);
477
+ const renderHours = [DatePickerTimeMode.FULL, DatePickerTimeMode.HOURS_MINUTES,
478
+ DatePickerTimeMode.HOURS_ONLY].includes(timeMode);
479
+ const renderMinutes = [DatePickerTimeMode.FULL, DatePickerTimeMode.HOURS_MINUTES,
480
+ DatePickerTimeMode.MINUTES_ONLY].includes(timeMode);
483
481
  const renderSeconds = [DatePickerTimeMode.FULL, DatePickerTimeMode.SECONDS_ONLY].includes(timeMode);
484
482
  const timeControls: Array<React.ReactElement> = [];
485
483
  if (renderHours) timeControls.push(renderTimeSwiper('hour'));
@@ -494,15 +492,15 @@ function TimePicker(props: TimePickerProps) {
494
492
  {control}
495
493
  {index < timeControls.length - 1 && <span className='sep'>:</span>}
496
494
  </Fragment>
497
- )
495
+ );
498
496
  })}
499
497
  <div className='vizor bottom'/>
500
498
  </div>
501
- )
499
+ );
502
500
  }
503
501
 
504
502
  function renderTimeSwiper(key: 'hour' | 'minute' | 'second') {
505
- const _value = value ?? new IDate('00:00:00', 'HH:mm:ss');
503
+ const _value = value ?? new IDate('00:00:00', {dateFormat: 'HH:mm:ss'});
506
504
  let timeValue: number, numSlides: number;
507
505
  if (key === 'hour') {
508
506
  timeValue = _value.hours();
@@ -527,7 +525,7 @@ function TimePicker(props: TimePickerProps) {
527
525
  }} loop slideToClickedSlide centeredSlides>
528
526
  {slideValues.map((value: string, index: number) => <SwiperSlide key={index}>{value}</SwiperSlide>)}
529
527
  </Swiper>
530
- )
528
+ );
531
529
  }
532
530
 
533
531
  useEffect(() => {
@@ -301,10 +301,10 @@ export default class DateField extends PureComponent<Props, State> {
301
301
  const {value, dateType} = this.props;
302
302
  if (value.length) {
303
303
  if (dateType === DateType.DATE)
304
- return new IDate(value, 'DD-MM-YYYY');
304
+ return new IDate(value, {dateFormat: 'DD-MM-YYYY'});
305
305
  if (dateType === DateType.DATETIME)
306
- return new IDate(value, 'DD-MM-YYYY HH:mm');
307
- return new IDate(value, 'HH:mm');
306
+ return new IDate(value, {dateFormat: 'DD-MM-YYYY HH:mm'});
307
+ return new IDate(value, {dateFormat: 'HH:mm'});
308
308
  }
309
309
  return null;
310
310
  };
@@ -152,9 +152,9 @@ export default class DateFieldController<T extends IDateValue> extends PureCompo
152
152
  // Only call onChange when the date is validly (only containing numbers)
153
153
  if (!/[a-zA-Z]/.test(value)) {
154
154
  let momentValue: IDate;
155
- if (dateType === DateType.DATE) momentValue = new IDate(value, 'DD-MM-YYYY');
156
- else if (dateType === DateType.TIME) momentValue = new IDate(value, 'HH:mm');
157
- else momentValue = new IDate(value, 'DD-MM-YYYY HH:mm');
155
+ if (dateType === DateType.DATE) momentValue = new IDate(value, {dateFormat: 'DD-MM-YYYY'});
156
+ else if (dateType === DateType.TIME) momentValue = new IDate(value, {dateFormat: 'HH:mm'});
157
+ else momentValue = new IDate(value, {dateFormat: 'DD-MM-YYYY HH:mm'});
158
158
  switch (returnType) {
159
159
  case DateReturnType.STRING:
160
160
  switch (dateType) {
@@ -5,12 +5,12 @@ import './style/datePicker.scss';
5
5
 
6
6
  import React from 'react';
7
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 {DateTimeParts} from "../dateFieldController";
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 {DateTimeParts} from '../dateFieldController';
14
14
  import AwesomeIcon from '../../../icon/awesomeIcon';
15
15
  import IDate, {IDateValue, MutateKey} from '@dvrd/idate';
16
16
 
@@ -77,9 +77,11 @@ export default class DatePicker extends PureComponent<Props> {
77
77
  IDate.now().month(index).format('MMMM');
78
78
 
79
79
  getDaysToRender = (): { day: number, isCurrentMonth: boolean }[] => {
80
- const daysToRender: { day: number, isCurrentMonth: boolean }[] = [],
81
- currentMoment = this.props.getCurrentMoment(), dayPadding = currentMoment.day(1).weekday() - 1,
82
- days = currentMoment.daysInMonth(), maxPrevMonth = currentMoment.subtract(1, 'month').daysInMonth();
80
+ const daysToRender: { day: number, isCurrentMonth: boolean }[] = [];
81
+ const currentMoment = this.props.getCurrentMoment();
82
+ const dayPadding = currentMoment.day(1).weekday() - 1;
83
+ const days = currentMoment.daysInMonth();
84
+ const maxPrevMonth = currentMoment.subtract(1, 'month').daysInMonth();
83
85
 
84
86
  // Add days to pad begin weekdays
85
87
  for (let i = dayPadding; i > 0; i--)
@@ -121,7 +123,7 @@ export default class DatePicker extends PureComponent<Props> {
121
123
  <AwesomeIcon name='chevron-right' className='dvr-year-toggle' style={{color: contrast}}
122
124
  onClick={onChange(PickerKey.YEAR, 1)}/>
123
125
  </div>
124
- )
126
+ );
125
127
  };
126
128
 
127
129
  renderMonthContainer = () => {
@@ -134,7 +136,7 @@ export default class DatePicker extends PureComponent<Props> {
134
136
  <AwesomeIcon name='chevron-right' className='dvr-month-toggle' onClick={onChange(PickerKey.MONTH, 1)}/>
135
137
 
136
138
  </div>
137
- )
139
+ );
138
140
  };
139
141
 
140
142
  renderDaysContainer = () => {
@@ -150,7 +152,7 @@ export default class DatePicker extends PureComponent<Props> {
150
152
  ))}
151
153
  {daysToRender.map(this.renderDay)}
152
154
  </div>
153
- )
155
+ );
154
156
  };
155
157
 
156
158
  renderDay = (dayData: { day: number, isCurrentMonth: boolean }, index: number) => {
@@ -172,7 +174,7 @@ export default class DatePicker extends PureComponent<Props> {
172
174
  {}} onClick={isDisabled ? voidFunction :
173
175
  onChange(PickerKey.DAY, day, false)}>{day}</label>
174
176
  </div>
175
- )
177
+ );
176
178
  };
177
179
 
178
180
  render = () => {
@@ -182,6 +184,6 @@ export default class DatePicker extends PureComponent<Props> {
182
184
  {this.renderMonthContainer()}
183
185
  {this.renderDaysContainer()}
184
186
  </div>
185
- )
187
+ );
186
188
  };
187
189
  }
@@ -173,7 +173,7 @@ export default class DateInput extends PureComponent<Props, State> {
173
173
  'DD-MM-YYYY HH:mm' : 'HH:mm';
174
174
  if (indexes.length >= format.length) {
175
175
  const stringValue = this.getStringValue(format.length);
176
- momentValue = new IDate(stringValue, format);
176
+ momentValue = new IDate(stringValue, {dateFormat: format});
177
177
  if (!/[a-zA-Z]/.test(stringValue) && momentValue.isValid()) onChange(momentValue);
178
178
  }
179
179
  };