@dvrd/dvr-controls 1.0.76 → 1.0.78

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.0.76",
3
+ "version": "1.0.78",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -41,6 +41,7 @@ interface Props {
41
41
  id?: string;
42
42
  max?: IDate | string;
43
43
  min?: IDate | string;
44
+ pickersOnly?: boolean;
44
45
  }
45
46
 
46
47
  export type DVRDDatePickerRef = { onOpen: VoidFunction; onClose: VoidFunction; }
@@ -48,7 +49,7 @@ export type DVRDDatePickerRef = { onOpen: VoidFunction; onClose: VoidFunction; }
48
49
  function DvrdDatePicker(props: Props, ref: ForwardedRef<DVRDDatePickerRef>) {
49
50
  const {
50
51
  onChange, className, closeOnChange, error, label, value, placeholder, disabled, alwaysShowArrows,
51
- useMobileNative, max, min, timeMode
52
+ useMobileNative, max, min, timeMode, pickersOnly
52
53
  } = props;
53
54
  const [pickerOpen, setPickerOpen] = useState(false);
54
55
  const [timePickerOpen, setTimePickerOpen] = useState(false);
@@ -107,19 +108,21 @@ function DvrdDatePicker(props: Props, ref: ForwardedRef<DVRDDatePickerRef>) {
107
108
 
108
109
  return (
109
110
  <div className={classNames('dvrd-date-picker', className, error && 'error', disabled && 'disabled')}>
110
- <label className='field-label'>{label}</label>
111
- {renderMobilePicker()}
112
- <div className={classNames('value-container', useMobileNative && 'no-mob')} onClick={onClickContainer}>
113
- <label className={classNames('value', !value && 'placeholder')}>{value?.format(dateFormat) ??
114
- placeholder ?? ''}</label>
115
- <AwesomeIcon name='calendar-alt' className='calendar-icon'/>
116
- </div>
111
+ {!pickersOnly && <>
112
+ <label className='field-label'>{label}</label>
113
+ {renderMobilePicker()}
114
+ <div className={classNames('value-container', useMobileNative && 'no-mob')} onClick={onClickContainer}>
115
+ <label className={classNames('value', !value && 'placeholder')}>{value?.format(dateFormat) ??
116
+ placeholder ?? ''}</label>
117
+ <AwesomeIcon name='calendar-alt' className='calendar-icon'/>
118
+ </div>
119
+ </>}
117
120
  <DatePicker onClose={onClosePicker} onChange={onChangePicker} open={pickerOpen} value={value}
118
121
  alwaysShowArrows={alwaysShowArrows} max={max} min={min}/>
119
122
  {!!timeMode &&
120
123
  <TimePicker onChange={onChangeTimePicker} onClose={onClosePicker} value={value}
121
124
  open={timePickerOpen} timeMode={timeMode} closeOnChange={closeOnChange}/>}
122
- <label className='error-label'>{error}</label>
125
+ {!pickersOnly && <label className='error-label'>{error}</label>}
123
126
  </div>
124
127
  )
125
128
  }
@@ -351,7 +354,7 @@ function DatePicker(props: DatePickerProps) {
351
354
  useEffect(() => {
352
355
  if (open) {
353
356
  document.addEventListener('keydown', keyListener);
354
- addMountClass();
357
+ defer(addMountClass);
355
358
  window.setTimeout(removeMountClass, 1000);
356
359
  } else {
357
360
  document.removeEventListener('keydown', keyListener);
@@ -361,7 +364,8 @@ function DatePicker(props: DatePickerProps) {
361
364
  }
362
365
  }, [open]);
363
366
 
364
- function renderDay(day: number, index: number, onClick: MouseEventHandler, className?: string, type?: 'prev' | 'next') {
367
+ function renderDay(day: number, index: number, onClick: MouseEventHandler, className?: string,
368
+ type?: 'prev' | 'next') {
365
369
  let pickValue = pickerValue.clone();
366
370
  if (type === 'prev')
367
371
  pickValue = pickValue.subtract(1, 'month');
@@ -380,7 +384,7 @@ function DatePicker(props: DatePickerProps) {
380
384
 
381
385
  return (
382
386
  <WithBackground active={open} onClose={onClose}>
383
- <div className='picker' ref={divRef}>
387
+ <div className={classNames('picker', alwaysShowArrows && 'switch-mount')} ref={divRef}>
384
388
  <div className='switcher year'>
385
389
  {renderSwitcher('year', 'reduce')}
386
390
  <label className='switcher-label'
@@ -66,8 +66,8 @@
66
66
  .switcher {
67
67
  display: grid;
68
68
  justify-content: center;
69
- background-color: $color-blue-1;
70
- color: white;
69
+ background-color: var(--base-color);
70
+ color: var(--contrast-color);
71
71
  align-items: center;
72
72
  grid-column-gap: .5rem;
73
73
 
@@ -247,12 +247,12 @@
247
247
  }
248
248
 
249
249
  &.selected {
250
- background-color: $color-blue-1 !important;
251
- color: white;
250
+ background-color: var(--base-color);
251
+ color: var(--contrast-color);
252
252
  }
253
253
 
254
254
  &:hover {
255
- background-color: rgba($color-blue-1, .2);
255
+ background-color: rgba(var(--base-color-rgb), .2);
256
256
  }
257
257
 
258
258
  &.disabled {
@@ -5,6 +5,7 @@
5
5
  import React, {Context, PropsWithChildren, useEffect} from 'react';
6
6
  import {ControlVariant} from "./interfaces";
7
7
  import defer from 'lodash.defer';
8
+ import {convertColor, hexToRgb} from "./colorUtil";
8
9
 
9
10
  // noinspection JSUnusedGlobalSymbols
10
11
  export interface ThemeContextShape {
@@ -34,8 +35,12 @@ export default function ThemeContextProvider(props: PropsWithChildren<ProviderPr
34
35
  useEffect(() => {
35
36
  defer(() => {
36
37
  const root = document.documentElement;
38
+ const baseRgb = hexToRgb(convertColor(theme.baseColor));
39
+ const contrastRgb = hexToRgb(convertColor(theme.contrastColor));
37
40
  root.style.setProperty('--base-color', theme.baseColor);
41
+ root.style.setProperty('--base-color-rgb', `${baseRgb.r}, ${baseRgb.g}, ${baseRgb.b}`);
38
42
  root.style.setProperty('--contrast-color', theme.contrastColor);
43
+ root.style.setProperty('--contrast-color-rgb', `${contrastRgb.r}, ${contrastRgb.g}, ${contrastRgb.b}`);
39
44
  });
40
45
  }, [theme]);
41
46