@dvrd/dvr-controls 1.0.44 → 1.0.46
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 +7 -7
- package/src/js/checkbox/checkbox.tsx +95 -107
- package/src/js/checkbox/checkboxController.tsx +186 -108
- package/src/js/checkbox/style/checkbox.scss +9 -1
- package/src/js/date/dvrdDatePicker.tsx +210 -186
- package/src/js/date/style/dvrdDatePicker.scss +6 -0
- package/src/js/select/dvrdMultiSelect.tsx +389 -0
- package/src/js/select/dvrdSelectController.tsx +119 -58
- package/src/js/sidebarMenu/sidebarMenu.tsx +20 -8
- package/src/js/sidebarMenu/style/sidebarMenu.scss +19 -7
- package/src/js/util/interfaces.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvrd/dvr-controls",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"description": "Custom web controls",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"react-router-dom": "6.15.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@fortawesome/fontawesome-svg-core": "6.3.0",
|
|
34
|
+
"@fortawesome/free-brands-svg-icons": "6.3.0",
|
|
35
|
+
"@fortawesome/free-regular-svg-icons": "6.3.0",
|
|
36
|
+
"@fortawesome/free-solid-svg-icons": "6.3.0",
|
|
37
|
+
"@fortawesome/react-fontawesome": "0.2.0",
|
|
33
38
|
"@types/dompurify": "2.4.0",
|
|
34
39
|
"@types/js-cookie": "3.0.3",
|
|
35
40
|
"@types/lodash.defer": "^4.1.7",
|
|
@@ -42,12 +47,6 @@
|
|
|
42
47
|
"@types/react-color": "2.13.5",
|
|
43
48
|
"@types/react-dom": "^18.0.11",
|
|
44
49
|
"@types/uuid": "9.0.0",
|
|
45
|
-
"typescript": "4.9.5",
|
|
46
|
-
"@fortawesome/fontawesome-svg-core": "6.3.0",
|
|
47
|
-
"@fortawesome/free-brands-svg-icons": "6.3.0",
|
|
48
|
-
"@fortawesome/free-regular-svg-icons": "6.3.0",
|
|
49
|
-
"@fortawesome/free-solid-svg-icons": "6.3.0",
|
|
50
|
-
"@fortawesome/react-fontawesome": "0.2.0",
|
|
51
50
|
"classnames": "2.3.2",
|
|
52
51
|
"dompurify": "3.0.0",
|
|
53
52
|
"js-cookie": "3.0.1",
|
|
@@ -59,6 +58,7 @@
|
|
|
59
58
|
"moment": "2.29.4",
|
|
60
59
|
"react-color": "2.19.3",
|
|
61
60
|
"react-rnd": "10.4.1",
|
|
61
|
+
"typescript": "4.9.5",
|
|
62
62
|
"uuid": "9.0.0"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -4,145 +4,133 @@
|
|
|
4
4
|
|
|
5
5
|
import './style/checkbox.scss';
|
|
6
6
|
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import {MouseEventHandler} from 'react';
|
|
7
|
+
import React, {CSSProperties, MouseEventHandler, useContext, useMemo} from 'react';
|
|
9
8
|
import classNames from 'classnames';
|
|
10
9
|
import AwesomeIcon from '../icon/awesomeIcon';
|
|
11
|
-
import {
|
|
12
|
-
import {isNotNull, isNull} from "../util/controlUtil";
|
|
10
|
+
import {convertColor, editColor, findDarkestColor} from "../util/colorUtil";
|
|
13
11
|
import {ControlContext} from "../util/controlContext";
|
|
14
|
-
import {
|
|
12
|
+
import {IconName} from '@fortawesome/fontawesome-svg-core';
|
|
13
|
+
import {ErrorType} from "../../../index";
|
|
15
14
|
|
|
16
|
-
interface
|
|
15
|
+
interface Props {
|
|
17
16
|
onCheck: MouseEventHandler;
|
|
18
|
-
onMouseEnter:
|
|
19
|
-
onMouseLeave:
|
|
20
|
-
checked: boolean
|
|
21
|
-
disabled: boolean
|
|
22
|
-
isHovered: boolean
|
|
23
|
-
label
|
|
24
|
-
labelPosition: 'left' | 'right'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
id: string
|
|
31
|
-
error:
|
|
32
|
-
checkIcon: IconName | React.ReactNode
|
|
17
|
+
onMouseEnter: MouseEventHandler;
|
|
18
|
+
onMouseLeave: MouseEventHandler;
|
|
19
|
+
checked: boolean;
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
isHovered: boolean;
|
|
22
|
+
label?: string;
|
|
23
|
+
labelPosition: 'left' | 'right';
|
|
24
|
+
className?: string;
|
|
25
|
+
labelClassName?: string;
|
|
26
|
+
checkboxClassName?: string;
|
|
27
|
+
checkClassName?: string;
|
|
28
|
+
errorClassName?: string;
|
|
29
|
+
id: string;
|
|
30
|
+
error: ErrorType;
|
|
31
|
+
checkIcon: IconName | React.ReactNode;
|
|
33
32
|
baseColor?: string;
|
|
34
33
|
contrastColor?: string;
|
|
35
34
|
title?: string;
|
|
36
35
|
useDarkestColor: boolean;
|
|
36
|
+
asRadio?: boolean;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
export default function DvrdCheckbox(props: Props) {
|
|
40
|
+
const context = useContext(ControlContext);
|
|
41
|
+
const {
|
|
42
|
+
disabled, error, label, useDarkestColor, isHovered, id, onCheck, onMouseEnter, onMouseLeave, title,
|
|
43
|
+
labelPosition, checkIcon, checked, asRadio
|
|
44
|
+
} = props;
|
|
45
|
+
const className = useMemo(() => {
|
|
46
|
+
const classes: Array<string> = ['checkboxContainer'];
|
|
46
47
|
if (disabled) classes.push('disabled');
|
|
47
|
-
if (
|
|
48
|
-
if (!label
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
getLabelClass = (position: 'left' | 'right'): string => {
|
|
55
|
-
const {disabled, labelClass, error} = this.props, classes = ['checkboxLabel', position];
|
|
48
|
+
if (!!error) classes.push('error');
|
|
49
|
+
if (!label?.length) classes.push('no-label');
|
|
50
|
+
return classNames(classes, props.className);
|
|
51
|
+
}, [disabled, error, label, props.className]);
|
|
52
|
+
const labelClassName = useMemo(() => {
|
|
53
|
+
const classes: Array<string> = ['checkboxLabel'];
|
|
56
54
|
if (disabled) classes.push('disabled');
|
|
57
|
-
if (
|
|
58
|
-
classes.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
getCheckboxClass = (): string => {
|
|
63
|
-
const {disabled, checkboxClass} = this.props, classes = ['checkbox'];
|
|
55
|
+
if (!!error) classes.push('error');
|
|
56
|
+
return classNames(classes, props.labelClassName);
|
|
57
|
+
}, [disabled, error, props.labelClassName]);
|
|
58
|
+
const checkboxClassName = useMemo(() => {
|
|
59
|
+
const classes: Array<string> = ['checkbox'];
|
|
64
60
|
if (disabled) classes.push('disabled');
|
|
65
|
-
classes.push(
|
|
66
|
-
return classNames(classes);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const {disabled, checkClass, checked} = this.props, classes = ['checkbox-check'];
|
|
61
|
+
if (asRadio) classes.push('as-radio');
|
|
62
|
+
return classNames(classes, props.checkboxClassName);
|
|
63
|
+
}, [disabled, props.checkClassName]);
|
|
64
|
+
const checkClassName = useMemo(() => {
|
|
65
|
+
const classes = ['checkbox-check'];
|
|
71
66
|
if (disabled) classes.push('disabled');
|
|
72
67
|
if (checked) classes.push('checked');
|
|
73
|
-
classes.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
return classNames(classes, props.checkClassName);
|
|
69
|
+
}, [disabled, checked, props.checkClassName]);
|
|
70
|
+
const [baseColor, contrastColor] = useMemo(() => {
|
|
71
|
+
const base = convertColor(props.baseColor || context.baseColor)
|
|
72
|
+
const contrast = convertColor(props.baseColor || context.baseColor);
|
|
73
|
+
return [base, contrast];
|
|
74
|
+
}, [props.baseColor, context.baseColor, props.contrastColor, context.contrastColor]);
|
|
75
|
+
const checkboxStyle: CSSProperties = useMemo(() => {
|
|
79
76
|
let color: string;
|
|
80
|
-
if (
|
|
77
|
+
if (!!error) color = 'red';
|
|
81
78
|
else if (disabled) color = 'color-gray-4';
|
|
82
79
|
else {
|
|
83
80
|
if (useDarkestColor)
|
|
84
|
-
color = findDarkestColor(
|
|
85
|
-
else color =
|
|
81
|
+
color = findDarkestColor(baseColor, contrastColor);
|
|
82
|
+
else color = baseColor;
|
|
86
83
|
if (isHovered) color = editColor(-.2, color);
|
|
87
84
|
}
|
|
88
85
|
return {borderColor: convertColor(color)};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let color: string;
|
|
94
|
-
if (isNotNull(error)) color = 'red';
|
|
86
|
+
}, [error, useDarkestColor, isHovered, disabled, baseColor, contrastColor]);
|
|
87
|
+
const checkStyle: CSSProperties = useMemo(() => {
|
|
88
|
+
let color: string = baseColor;
|
|
89
|
+
if (!!error) color = 'red';
|
|
95
90
|
else if (disabled) color = 'color-gray-4';
|
|
96
|
-
else if (useDarkestColor) color = findDarkestColor(
|
|
97
|
-
else color = this.getBaseColor();
|
|
91
|
+
else if (useDarkestColor) color = findDarkestColor(baseColor, contrastColor);
|
|
98
92
|
return {color: convertColor(color)};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (isNull(label) || labelPosition !== position) return null;
|
|
109
|
-
return <label className={this.getLabelClass(position)}>{label}</label>
|
|
110
|
-
};
|
|
93
|
+
}, [error, disabled, useDarkestColor, baseColor, contrastColor]);
|
|
94
|
+
const mainColor = useMemo(() => {
|
|
95
|
+
return useDarkestColor ? findDarkestColor(baseColor, contrastColor) : baseColor;
|
|
96
|
+
}, [useDarkestColor, props.baseColor, context.baseColor, props.contrastColor, context.contrastColor]);
|
|
97
|
+
|
|
98
|
+
function renderLabel(position: 'left' | 'right'): React.ReactNode {
|
|
99
|
+
if (!label || labelPosition !== position) return null;
|
|
100
|
+
return <label className={classNames(labelClassName, position)}>{label}</label>
|
|
101
|
+
}
|
|
111
102
|
|
|
112
|
-
renderCheckbox
|
|
103
|
+
function renderCheckbox() {
|
|
113
104
|
return (
|
|
114
|
-
<div className={
|
|
115
|
-
<div className='ripple' style={{backgroundColor:
|
|
116
|
-
{
|
|
105
|
+
<div className={checkboxClassName} style={checkboxStyle}>
|
|
106
|
+
<div className='ripple' style={{backgroundColor: mainColor}}/>
|
|
107
|
+
{renderCheck()}
|
|
117
108
|
</div>
|
|
118
109
|
)
|
|
119
|
-
}
|
|
110
|
+
}
|
|
120
111
|
|
|
121
|
-
renderCheck
|
|
122
|
-
const {checkIcon} = this.props;
|
|
112
|
+
function renderCheck() {
|
|
123
113
|
if (React.isValidElement(checkIcon)) return React.cloneElement((checkIcon as React.ReactElement), {
|
|
124
|
-
className: classNames(checkIcon.props.className,
|
|
125
|
-
style: {...checkIcon.props.style, ...
|
|
114
|
+
className: classNames(checkIcon.props.className, checkClassName),
|
|
115
|
+
style: {...checkIcon.props.style, ...checkStyle}
|
|
126
116
|
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const {error, errorClass} = this.props;
|
|
133
|
-
return <label className={classNames('error', errorClass)}>{error}</label>;
|
|
134
|
-
};
|
|
117
|
+
let checkName: IconName = 'check';
|
|
118
|
+
if(typeof checkIcon === 'string') checkName = checkIcon as IconName;
|
|
119
|
+
else if (asRadio) checkName = 'circle';
|
|
120
|
+
return <AwesomeIcon name={checkName} className={checkClassName} style={checkStyle}/>;
|
|
121
|
+
}
|
|
135
122
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<div className={this.getContainerClass()} id={id} onClick={onCheck} onMouseEnter={onMouseEnter}
|
|
140
|
-
title={title} onMouseLeave={onMouseLeave}>
|
|
141
|
-
{this.renderLabel('left')}
|
|
142
|
-
{this.renderCheckbox()}
|
|
143
|
-
{this.renderLabel('right')}
|
|
144
|
-
{this.renderError()}
|
|
145
|
-
</div>
|
|
146
|
-
)
|
|
123
|
+
function renderError() {
|
|
124
|
+
return <label className={classNames('error', props.errorClassName)}>{error}</label>;
|
|
147
125
|
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div className={className} id={id} onClick={onCheck} onMouseEnter={onMouseEnter}
|
|
129
|
+
title={title} onMouseLeave={onMouseLeave}>
|
|
130
|
+
{renderLabel('left')}
|
|
131
|
+
{renderCheckbox()}
|
|
132
|
+
{renderLabel('right')}
|
|
133
|
+
{renderError()}
|
|
134
|
+
</div>
|
|
135
|
+
)
|
|
148
136
|
}
|
|
@@ -2,136 +2,214 @@
|
|
|
2
2
|
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import
|
|
7
|
-
import {ControlContext} from "../util/controlContext";
|
|
5
|
+
import React, {MouseEventHandler, useEffect, useRef, useState} from 'react';
|
|
6
|
+
import DvrdCheckbox from "./checkbox";
|
|
8
7
|
import {generateComponentId} from '../../..';
|
|
9
8
|
|
|
10
9
|
interface Props {
|
|
11
10
|
onCheck: Function;
|
|
12
|
-
onMouseEnter?:
|
|
13
|
-
onMouseLeave?:
|
|
11
|
+
onMouseEnter?: MouseEventHandler;
|
|
12
|
+
onMouseLeave?: MouseEventHandler;
|
|
14
13
|
checked: boolean;
|
|
15
|
-
disabled
|
|
16
|
-
label
|
|
17
|
-
labelPosition
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
label?: string;
|
|
16
|
+
labelPosition?: 'left' | 'right';
|
|
17
|
+
className?: string;
|
|
18
|
+
labelClassName?: string;
|
|
19
|
+
checkboxClassName?: string;
|
|
20
|
+
checkClassName?: string;
|
|
21
|
+
errorClassName?: string;
|
|
23
22
|
baseColor?: string;
|
|
24
23
|
contrastColor?: string;
|
|
25
|
-
error
|
|
24
|
+
error?: string | null;
|
|
26
25
|
id?: string;
|
|
27
|
-
checkIcon
|
|
28
|
-
unControlled
|
|
26
|
+
checkIcon?: React.ReactNode;
|
|
27
|
+
unControlled?: boolean;
|
|
29
28
|
title?: string;
|
|
30
|
-
useDarkestColor
|
|
29
|
+
useDarkestColor?: boolean;
|
|
31
30
|
ref?: any;
|
|
31
|
+
asRadio?: boolean;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
static defaultProps = {
|
|
43
|
-
disabled: false,
|
|
44
|
-
label: '',
|
|
45
|
-
labelPosition: 'right',
|
|
46
|
-
containerClass: '',
|
|
47
|
-
labelClass: '',
|
|
48
|
-
checkboxClass: '',
|
|
49
|
-
checkClass: '',
|
|
50
|
-
errorClass: '',
|
|
51
|
-
checkIcon: null,
|
|
52
|
-
error: null,
|
|
53
|
-
unControlled: false,
|
|
54
|
-
useDarkestColor: true,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
private getContainer = (): HTMLElement | null => {
|
|
58
|
-
return document.getElementById(this.id);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
private getRipple = (): HTMLElement | null => {
|
|
62
|
-
const container = this.getContainer();
|
|
63
|
-
if (container === null) return null;
|
|
64
|
-
return container.querySelector('div.ripple');
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
private id: string = generateComponentId(this.props.id);
|
|
34
|
+
export default function CheckboxController(props: Props) {
|
|
35
|
+
const {
|
|
36
|
+
disabled, unControlled, checked, onCheck, label, labelPosition, className, labelClassName, checkboxClassName,
|
|
37
|
+
checkClassName, error, checkIcon, errorClassName, title, useDarkestColor, baseColor, contrastColor, asRadio
|
|
38
|
+
} = props;
|
|
39
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
40
|
+
const [internalValue, setInternalValue] = useState(props.checked);
|
|
41
|
+
const id = useRef(generateComponentId(props.id));
|
|
68
42
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
onCheck = (evt: React.MouseEvent<Element, Event>) => {
|
|
72
|
-
const {checked, onCheck, disabled, unControlled} = this.props;
|
|
43
|
+
function _onCheck(evt: React.MouseEvent<Element, Event>) {
|
|
73
44
|
if (disabled) return;
|
|
74
45
|
if (unControlled) {
|
|
75
46
|
evt.stopPropagation();
|
|
76
47
|
evt.persist();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
48
|
+
const nextInternal = !internalValue;
|
|
49
|
+
setInternalValue(nextInternal);
|
|
50
|
+
onCheck(nextInternal, evt);
|
|
80
51
|
} else onCheck(!checked, evt);
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
onMouseEnter = () => {
|
|
85
|
-
if (this.props.disabled) return;
|
|
86
|
-
this.setState({isHovered: true});
|
|
87
|
-
};
|
|
52
|
+
}
|
|
88
53
|
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
54
|
+
function onMouseEnter(evt: React.MouseEvent) {
|
|
55
|
+
if (disabled) return;
|
|
56
|
+
setIsHovered(true);
|
|
57
|
+
props.onMouseEnter?.(evt);
|
|
58
|
+
}
|
|
93
59
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (ripple !== null) {
|
|
99
|
-
if (container.classList.contains('rippling'))
|
|
100
|
-
container.classList.remove('rippling');
|
|
101
|
-
ripple.addEventListener('transitionend', this.removeRipple);
|
|
102
|
-
container.classList.add('rippling');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
60
|
+
function onMouseLeave(evt: React.MouseEvent) {
|
|
61
|
+
setIsHovered(false);
|
|
62
|
+
props.onMouseLeave?.(evt);
|
|
63
|
+
}
|
|
106
64
|
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
65
|
+
function addRipple() {
|
|
66
|
+
const container = getContainer();
|
|
67
|
+
if (!container) return;
|
|
68
|
+
const ripple = getRipple();
|
|
69
|
+
if (!ripple) return;
|
|
70
|
+
container.classList.remove('rippling');
|
|
71
|
+
ripple.addEventListener('transitionend', removeRipple);
|
|
72
|
+
container.classList.add('rippling');
|
|
73
|
+
}
|
|
115
74
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
75
|
+
function removeRipple() {
|
|
76
|
+
const container = getContainer();
|
|
77
|
+
if (!container) return;
|
|
78
|
+
const ripple = getRipple();
|
|
79
|
+
if (!ripple) return;
|
|
80
|
+
ripple.removeEventListener('transitionend', removeRipple);
|
|
81
|
+
container.classList.remove('rippling');
|
|
82
|
+
}
|
|
120
83
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
84
|
+
function getContainer() {
|
|
85
|
+
return document.getElementById(id.current);
|
|
86
|
+
}
|
|
124
87
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
checked, disabled, label, labelPosition, containerClass, labelClass, checkboxClass, checkClass, checkIcon,
|
|
128
|
-
error, errorClass, unControlled, title, baseColor, contrastColor, useDarkestColor,
|
|
129
|
-
} = this.props, {isHovered, internalValue} = this.state, isChecked = unControlled ? internalValue : checked;
|
|
130
|
-
return <Checkbox onCheck={this.onCheck} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}
|
|
131
|
-
checked={isChecked} disabled={disabled} isHovered={isHovered} label={label}
|
|
132
|
-
labelPosition={labelPosition} containerClass={containerClass} labelClass={labelClass}
|
|
133
|
-
checkboxClass={checkboxClass} checkClass={checkClass} id={this.id} checkIcon={checkIcon}
|
|
134
|
-
error={error} errorClass={errorClass} title={title} baseColor={baseColor}
|
|
135
|
-
contrastColor={contrastColor} useDarkestColor={useDarkestColor}/>
|
|
88
|
+
function getRipple() {
|
|
89
|
+
return getContainer()?.querySelector('div.ripple') ?? null;
|
|
136
90
|
}
|
|
137
|
-
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (unControlled && internalValue) addRipple();
|
|
94
|
+
else if (!unControlled && checked) addRipple();
|
|
95
|
+
return function () {
|
|
96
|
+
removeRipple();
|
|
97
|
+
}
|
|
98
|
+
}, [internalValue, checked]);
|
|
99
|
+
|
|
100
|
+
const isChecked = unControlled ? internalValue : checked
|
|
101
|
+
return (
|
|
102
|
+
<DvrdCheckbox onCheck={_onCheck} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} checked={isChecked}
|
|
103
|
+
disabled={disabled ?? false} isHovered={isHovered} label={label}
|
|
104
|
+
labelPosition={labelPosition ?? 'right'} className={className} labelClassName={labelClassName}
|
|
105
|
+
checkboxClassName={checkboxClassName} checkClassName={checkClassName} id={id.current}
|
|
106
|
+
checkIcon={checkIcon} error={error ?? null} errorClassName={errorClassName} title={title}
|
|
107
|
+
baseColor={baseColor} contrastColor={contrastColor} useDarkestColor={useDarkestColor ?? true}
|
|
108
|
+
asRadio={asRadio}/>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// interface CheckboxState {
|
|
113
|
+
// isHovered: boolean;
|
|
114
|
+
// internalValue: boolean;
|
|
115
|
+
// }
|
|
116
|
+
//
|
|
117
|
+
// class _CheckboxController extends React.Component<Props, CheckboxState> {
|
|
118
|
+
// static contextType = ControlContext;
|
|
119
|
+
//
|
|
120
|
+
// static defaultProps = {
|
|
121
|
+
// disabled: false,
|
|
122
|
+
// label: '',
|
|
123
|
+
// labelPosition: 'right',
|
|
124
|
+
// containerClass: '',
|
|
125
|
+
// labelClass: '',
|
|
126
|
+
// checkboxClass: '',
|
|
127
|
+
// checkClass: '',
|
|
128
|
+
// errorClass: '',
|
|
129
|
+
// checkIcon: null,
|
|
130
|
+
// error: null,
|
|
131
|
+
// unControlled: false,
|
|
132
|
+
// useDarkestColor: true,
|
|
133
|
+
// };
|
|
134
|
+
//
|
|
135
|
+
// private getContainer = (): HTMLElement | null => {
|
|
136
|
+
// return document.getElementById(this.id);
|
|
137
|
+
// };
|
|
138
|
+
//
|
|
139
|
+
// private getRipple = (): HTMLElement | null => {
|
|
140
|
+
// const container = this.getContainer();
|
|
141
|
+
// if (container === null) return null;
|
|
142
|
+
// return container.querySelector('div.ripple');
|
|
143
|
+
// };
|
|
144
|
+
//
|
|
145
|
+
// private id: string = generateComponentId(this.props.id);
|
|
146
|
+
//
|
|
147
|
+
// state = {isHovered: false, internalValue: this.props.checked};
|
|
148
|
+
//
|
|
149
|
+
// onCheck = (evt: React.MouseEvent<Element, Event>) => {
|
|
150
|
+
// const {checked, onCheck, disabled, unControlled} = this.props;
|
|
151
|
+
// if (disabled) return;
|
|
152
|
+
// if (unControlled) {
|
|
153
|
+
// evt.stopPropagation();
|
|
154
|
+
// evt.persist();
|
|
155
|
+
// this.setState({internalValue: !this.state.internalValue}, () => {
|
|
156
|
+
// onCheck(this.state.internalValue, evt);
|
|
157
|
+
// });
|
|
158
|
+
// } else onCheck(!checked, evt);
|
|
159
|
+
// this.addRipple();
|
|
160
|
+
// };
|
|
161
|
+
//
|
|
162
|
+
// onMouseEnter = () => {
|
|
163
|
+
// if (this.props.disabled) return;
|
|
164
|
+
// this.setState({isHovered: true});
|
|
165
|
+
// };
|
|
166
|
+
//
|
|
167
|
+
// onMouseLeave = () => {
|
|
168
|
+
// if (this.props.disabled) return;
|
|
169
|
+
// this.setState({isHovered: false});
|
|
170
|
+
// };
|
|
171
|
+
//
|
|
172
|
+
// addRipple = () => {
|
|
173
|
+
// const container = this.getContainer();
|
|
174
|
+
// if (container !== null) {
|
|
175
|
+
// const ripple = this.getRipple();
|
|
176
|
+
// if (ripple !== null) {
|
|
177
|
+
// if (container.classList.contains('rippling'))
|
|
178
|
+
// container.classList.remove('rippling');
|
|
179
|
+
// ripple.addEventListener('transitionend', this.removeRipple);
|
|
180
|
+
// container.classList.add('rippling');
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
// };
|
|
184
|
+
//
|
|
185
|
+
// removeRipple = () => {
|
|
186
|
+
// const ripple = this.getRipple();
|
|
187
|
+
// const container = this.getContainer();
|
|
188
|
+
// if (ripple !== null && container !== null) {
|
|
189
|
+
// ripple.removeEventListener('transitionend', this.removeRipple);
|
|
190
|
+
// container.classList.remove('rippling');
|
|
191
|
+
// }
|
|
192
|
+
// };
|
|
193
|
+
//
|
|
194
|
+
// componentDidUpdate = (prevProps: Props, prevState: CheckboxState) => {
|
|
195
|
+
// if (prevState.internalValue !== this.state.internalValue && this.state.internalValue) this.addRipple();
|
|
196
|
+
// else if (prevProps.checked !== this.props.checked && this.props.checked) this.addRipple();
|
|
197
|
+
// };
|
|
198
|
+
//
|
|
199
|
+
// componentWillUnmount = () => {
|
|
200
|
+
// this.removeRipple();
|
|
201
|
+
// };
|
|
202
|
+
//
|
|
203
|
+
// render = () => {
|
|
204
|
+
// const {
|
|
205
|
+
// checked, disabled, label, labelPosition, containerClass, labelClass, checkboxClass, checkClass, checkIcon,
|
|
206
|
+
// error, errorClass, unControlled, title, baseColor, contrastColor, useDarkestColor,
|
|
207
|
+
// } = this.props, {isHovered, internalValue} = this.state, isChecked = unControlled ? internalValue : checked;
|
|
208
|
+
// return <Checkbox onCheck={this.onCheck} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}
|
|
209
|
+
// checked={isChecked} disabled={disabled} isHovered={isHovered} label={label}
|
|
210
|
+
// labelPosition={labelPosition} containerClass={containerClass} labelClass={labelClass}
|
|
211
|
+
// checkboxClass={checkboxClass} checkClass={checkClass} id={this.id} checkIcon={checkIcon}
|
|
212
|
+
// error={error} errorClass={errorClass} title={title} baseColor={baseColor}
|
|
213
|
+
// contrastColor={contrastColor} useDarkestColor={useDarkestColor}/>
|
|
214
|
+
// }
|
|
215
|
+
// }
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
grid-template-columns: 22px auto;
|
|
10
10
|
grid-column-gap: .5rem;
|
|
11
11
|
align-items: center;
|
|
12
|
-
//padding: .2rem;
|
|
13
12
|
cursor: pointer;
|
|
14
13
|
position: relative;
|
|
15
14
|
margin-bottom: 0;
|
|
@@ -63,6 +62,15 @@
|
|
|
63
62
|
visibility: hidden;
|
|
64
63
|
pointer-events: none;
|
|
65
64
|
}
|
|
65
|
+
|
|
66
|
+
&.as-radio {
|
|
67
|
+
border-radius: 50%;
|
|
68
|
+
|
|
69
|
+
.checkbox-check {
|
|
70
|
+
@include centerXY;
|
|
71
|
+
font-size: 10px;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
.error {
|