@dvrd/dvr-controls 1.0.63 → 1.0.65

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.63",
3
+ "version": "1.0.65",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -31,10 +31,10 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@dvrd/idate": "^1.8.4",
34
- "@fortawesome/fontawesome-svg-core": "6.3.0",
35
- "@fortawesome/free-brands-svg-icons": "6.3.0",
36
- "@fortawesome/free-regular-svg-icons": "6.3.0",
37
- "@fortawesome/free-solid-svg-icons": "6.3.0",
34
+ "@fortawesome/fontawesome-svg-core": "6.5.2",
35
+ "@fortawesome/free-brands-svg-icons": "6.5.2",
36
+ "@fortawesome/free-regular-svg-icons": "6.5.2",
37
+ "@fortawesome/free-solid-svg-icons": "6.5.2",
38
38
  "@fortawesome/react-fontawesome": "0.2.0",
39
39
  "@types/dompurify": "2.4.0",
40
40
  "@types/js-cookie": "3.0.3",
@@ -84,12 +84,12 @@ export default function DvrdCheckbox(props: Props) {
84
84
  }
85
85
  return {borderColor: convertColor(color)};
86
86
  }, [error, useDarkestColor, isHovered, disabled, baseColor, contrastColor]);
87
- const checkStyle: CSSProperties = useMemo(() => {
87
+ const [checkStyle, partialCheckStyle]: [CSSProperties, CSSProperties] = useMemo(() => {
88
88
  let color: string = baseColor;
89
89
  if (!!error) color = 'red';
90
90
  else if (disabled) color = 'color-gray-4';
91
91
  else if (useDarkestColor) color = findDarkestColor(baseColor, contrastColor);
92
- return {color: convertColor(color)};
92
+ return [{color: convertColor(color)}, {backgroundColor: convertColor(color)}];
93
93
  }, [error, disabled, useDarkestColor, baseColor, contrastColor]);
94
94
  const mainColor = useMemo(() => {
95
95
  return useDarkestColor ? findDarkestColor(baseColor, contrastColor) : baseColor;
@@ -114,11 +114,15 @@ export default function DvrdCheckbox(props: Props) {
114
114
  className: classNames(checkIcon.props.className, checkClassName),
115
115
  style: {...checkIcon.props.style, ...checkStyle}
116
116
  });
117
+ else if (checked === 'partial') return (
118
+ <div className={classNames(checkClassName, 'partial-icon')} style={partialCheckStyle}/>
119
+ );
117
120
  let checkName: IconName = 'check';
118
- if(typeof checkIcon === 'string') checkName = checkIcon as IconName;
121
+ let additionalClassName: string | null = null;
122
+ if (typeof checkIcon === 'string') checkName = checkIcon as IconName;
119
123
  else if (asRadio) checkName = 'circle';
120
- else if (checked === 'partial') checkName = 'minus';
121
- return <AwesomeIcon name={checkName} className={checkClassName} style={checkStyle}/>;
124
+ return <AwesomeIcon name={checkName} className={classNames(checkClassName, additionalClassName)}
125
+ style={checkStyle}/>;
122
126
  }
123
127
 
124
128
  function renderError() {
@@ -47,6 +47,13 @@
47
47
  transition: opacity .1s ease-in-out, visibility .1s ease-in-out;
48
48
  user-select: none;
49
49
 
50
+ &.partial-icon {
51
+ top: 50%;
52
+ width: 12px;
53
+ height: 3px;
54
+ border-radius: 4px;
55
+ }
56
+
50
57
  &.checked {
51
58
  visibility: visible;
52
59
  opacity: 1;
@@ -4,76 +4,62 @@
4
4
 
5
5
  import './style/loader.scss';
6
6
 
7
- import React, {CSSProperties} from 'react';
7
+ import React, {CSSProperties, useMemo} from 'react';
8
8
  import classNames from 'classnames';
9
9
  import {ThemeShape} from '../util/controlContext';
10
10
  import {isNull} from "../util/controlUtil";
11
11
  import {colorIsWhite, convertColor} from "../util/colorUtil";
12
12
 
13
- interface LoaderProps {
13
+ interface Props {
14
14
  label?: string,
15
15
  size?: string,
16
16
  thickness?: string,
17
17
  baseColor: string,
18
18
  trackColor: string,
19
- containerClass: string,
20
- loaderClass: string,
21
- labelClass: string,
19
+ className?: string,
20
+ loaderClassName?: string,
21
+ labelClassName?: string,
22
22
  contextStyle: ThemeShape,
23
- disableBackground: boolean,
24
- loaderStyle: CSSProperties;
23
+ disableBackground?: boolean,
24
+ loaderStyle?: CSSProperties;
25
25
  position: 'absolute' | 'fixed' | 'relative';
26
26
  }
27
27
 
28
- export class Loader extends React.Component<LoaderProps> {
29
- getContainerClass = (): string => {
30
- const {containerClass, disableBackground} = this.props, classes = ['loaderContainer'];
31
- if (disableBackground) classes.push('noBack');
32
- classes.push(containerClass);
28
+ export default function Loader(props: Props) {
29
+ const {
30
+ loaderClassName, labelClassName, loaderStyle, label, className, contextStyle, disableBackground, size,
31
+ thickness, trackColor, baseColor, position
32
+ } = props;
33
+ const _className = useMemo(() => {
34
+ const classes: Array<string> = ['loader-container'];
35
+ if (disableBackground) classes.push('no-back');
36
+ if (className) classes.push(className);
33
37
  return classNames(classes);
34
- };
35
-
36
- getLoaderClass = (): string => {
37
- const {loaderClass} = this.props, classes = ['loader'];
38
- classes.push(loaderClass);
39
- return classNames(classes);
40
- };
41
-
42
- getLoaderStyle = (): object => {
43
- const {baseColor, trackColor, contextStyle} = this.props;
38
+ }, [className, disableBackground]);
39
+ const _loaderStyle = useMemo(() => {
44
40
  let color = isNull(baseColor) ? 'color-orange-1' :
45
- colorIsWhite(baseColor) ? contextStyle.contrastColor : baseColor,
46
- track = isNull(trackColor) ? 'color-gray-7' : trackColor;
47
- const style: CSSProperties = {borderColor: convertColor(track), borderTopColor: convertColor(color)};
48
- return this.addPropStyles(style);
49
- };
41
+ colorIsWhite(baseColor) ? contextStyle.contrastColor : baseColor;
42
+ const track = isNull(trackColor) ? 'color-gray-7' : trackColor;
43
+ let style: CSSProperties = {borderColor: convertColor(track), borderTopColor: convertColor(color)};
44
+ if (!!size) {
45
+ style.width = size;
46
+ style.height = size;
47
+ style.paddingBottom = 'unset';
48
+ }
49
+ if (!!thickness)
50
+ style.borderWidth = thickness;
51
+ return {...style, ...loaderStyle};
52
+ }, [baseColor, contextStyle.contrastColor, trackColor, size, thickness, loaderStyle]);
50
53
 
51
- addPropStyles = (style: CSSProperties): CSSProperties => {
52
- const {size, thickness, loaderStyle} = this.props;
53
- if (size !== null && size !== undefined)
54
- style = Object.assign({}, style, {
55
- width: size,
56
- height: size,
57
- paddingBottom: 'unset',
58
- });
59
- if (thickness !== null && thickness !== undefined)
60
- style = Object.assign({}, style, {borderWidth: thickness});
61
- return Object.assign({}, style, loaderStyle);
62
- };
63
-
64
- renderLabel = (): React.ReactNode => {
65
- const {label, labelClass} = this.props;
66
- if (label === null || label === undefined) return null;
67
- return <label className={classNames('loaderLabel', labelClass)}>{label}</label>
68
- };
69
-
70
- render = () => {
71
- const {position} = this.props;
72
- return (
73
- <div className={this.getContainerClass()} style={{position}}>
74
- <div className={this.getLoaderClass()} style={this.getLoaderStyle()}/>
75
- {this.renderLabel()}
76
- </div>
77
- )
54
+ function renderLabel() {
55
+ if (!label) return null;
56
+ return <label className={classNames('loader-label', labelClassName)}>{label}</label>
78
57
  }
58
+
59
+ return (
60
+ <div className={_className} style={{position}}>
61
+ <div className={classNames('loader', loaderClassName)} style={_loaderStyle}/>
62
+ {renderLabel()}
63
+ </div>
64
+ )
79
65
  }
@@ -2,60 +2,44 @@
2
2
  * Copyright (c) 2024. Dave van Rijn Development
3
3
  */
4
4
 
5
- import React, {CSSProperties} from 'react';
6
- import {Loader} from "./loader";
5
+ import React, {CSSProperties, useContext, useMemo} from 'react';
6
+ import Loader from "./loader";
7
7
  import {ControlContext} from "../util/controlContext";
8
8
 
9
- interface LoaderProps {
9
+ interface Props {
10
10
  label?: string,
11
11
  baseColor?: string,
12
- thickness: string,
13
- size: string,
12
+ thickness?: string,
13
+ size?: string,
14
14
  trackColor: string,
15
- containerClass: string,
16
- loaderClass: string,
17
- labelClass: string,
15
+ className?: string,
16
+ loaderClassName?: string,
17
+ labelClassName?: string,
18
18
  active: boolean,
19
- disableBackground: boolean,
20
- loaderStyle: CSSProperties;
21
- position: 'absolute' | 'fixed' | 'relative';
19
+ disableBackground?: boolean,
20
+ loaderStyle?: CSSProperties;
21
+ position?: 'absolute' | 'fixed' | 'relative';
22
22
  }
23
23
 
24
- export default class LoaderController extends React.Component<LoaderProps> {
25
- // noinspection JSUnusedGlobalSymbols
26
- declare context: React.ContextType<typeof ControlContext>;
27
- static contextType = ControlContext;
28
-
29
- static defaultProps = {
30
- trackColor: 'transparent',
31
- size: '5rem',
32
- thickness: '.2rem',
33
- containerClass: '',
34
- trackClass: '',
35
- loaderClass: '',
36
- labelClass: '',
37
- disableBackground: false,
38
- loaderStyle: {},
39
- position: 'absolute',
40
- };
41
-
42
- getBaseColor = () => {
43
- const {baseColor} = this.props;
44
- if (baseColor !== null && baseColor !== undefined) return baseColor;
45
- // noinspection JSDeprecatedSymbols
46
- return this.context.baseColor;
47
- };
48
-
49
- render = () => {
50
- const {
51
- active, trackColor, containerClass, loaderClass, labelClass, label, size, thickness, disableBackground,
52
- loaderStyle, position
53
- } = this.props;
54
- if (active)
55
- return <Loader baseColor={this.getBaseColor()} trackColor={trackColor} contextStyle={this.context}
56
- containerClass={containerClass} loaderClass={loaderClass} labelClass={labelClass}
57
- label={label} size={size} thickness={thickness} disableBackground={disableBackground}
58
- loaderStyle={loaderStyle} position={position}/>;
59
- return null;
24
+ export default function LoaderController(props: Props) {
25
+ const context = useContext(ControlContext);
26
+ const baseColor = useMemo(() => {
27
+ if (!!props.baseColor) return props.baseColor;
28
+ return context.baseColor;
29
+ }, [props.baseColor, context.baseColor]);
30
+ const defaultProps: Props = {
31
+ ...props,
32
+ trackColor: props.trackColor ?? 'transparent',
33
+ size: props.size ?? '5rem',
34
+ thickness: props.thickness ?? '.2rem',
35
+ position: props.position ?? 'absolute',
60
36
  }
37
+
38
+ if (!props.active) return null;
39
+ return (
40
+ <Loader baseColor={baseColor} trackColor={defaultProps.trackColor} className={defaultProps.className}
41
+ loaderClassName={defaultProps.loaderClassName} labelClassName={defaultProps.labelClassName}
42
+ contextStyle={context} disableBackground={defaultProps.disableBackground}
43
+ loaderStyle={defaultProps.loaderStyle} position={defaultProps.position!}/>
44
+ )
61
45
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  @import '../../../style/variables';
6
6
 
7
- .loaderContainer {
7
+ .loader-container {
8
8
  display: flex;
9
9
  flex-direction: column;
10
10
  align-items: center;
@@ -16,11 +16,11 @@
16
16
  width: 100%;
17
17
  height: 100%;
18
18
 
19
- &.noBack {
19
+ &.no-back {
20
20
  background-color: transparent;
21
21
  }
22
22
 
23
- .loaderLabel {
23
+ .loader-label {
24
24
  @include borderRadius(.2rem);
25
25
  font-size: .9rem;
26
26
  color: $color-gray-6;
@@ -9,7 +9,7 @@ import {ControlContext} from "../util/controlContext";
9
9
  import {convertColor} from "../util/colorUtil";
10
10
 
11
11
  interface Props {
12
- onChange: (value: boolean, evt: React.MouseEvent) => void;
12
+ onChange: (value: boolean, evt?: React.MouseEvent | React.ChangeEvent) => void;
13
13
  value: boolean;
14
14
  className?: string;
15
15
  disabled?: boolean;