@bytebrand/fe-ui-core-autobahn 1.0.124 → 1.0.125
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/compat/Checkbox/Checkbox.tsx +168 -161
- package/compat/Checkbox/FormCheckbox.tsx +88 -86
- package/package.json +1 -1
|
@@ -1,161 +1,168 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import styles from './Checkbox.styl';
|
|
3
|
-
import classnames from 'classnames';
|
|
4
|
-
import IconSVG from '../../iconsvg/IconSVG';
|
|
5
|
-
import Tooltip from '../Tooltip/Tooltip';
|
|
6
|
-
import FormattedNumber from '../FormattedNumber/FormattedNumber';
|
|
7
|
-
|
|
8
|
-
export interface ICheckboxProps {
|
|
9
|
-
// Native checkbox props
|
|
10
|
-
name?: string;
|
|
11
|
-
value?: any;
|
|
12
|
-
checked?: boolean;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
reversed?: boolean;
|
|
15
|
-
isAboAccordionExpanded0?: boolean;
|
|
16
|
-
onChange?: (event: React.ChangeEvent<HTMLInputElement>, checked?: boolean, value?: any) => void;
|
|
17
|
-
onBlur?: (event: React.FocusEvent<HTMLDivElement>) => void;
|
|
18
|
-
onFocus?: (event: React.FocusEvent<HTMLDivElement>) => void;
|
|
19
|
-
|
|
20
|
-
// Custom checkbox props
|
|
21
|
-
containerClassName?: string;
|
|
22
|
-
checkboxClassName?: string;
|
|
23
|
-
labelClassName?: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{ [styles.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
</span>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import styles from './Checkbox.styl';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import IconSVG from '../../iconsvg/IconSVG';
|
|
5
|
+
import Tooltip from '../Tooltip/Tooltip';
|
|
6
|
+
import FormattedNumber from '../FormattedNumber/FormattedNumber';
|
|
7
|
+
|
|
8
|
+
export interface ICheckboxProps {
|
|
9
|
+
// Native checkbox props
|
|
10
|
+
name?: string;
|
|
11
|
+
value?: any;
|
|
12
|
+
checked?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
reversed?: boolean;
|
|
15
|
+
isAboAccordionExpanded0?: boolean;
|
|
16
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, checked?: boolean, value?: any) => void;
|
|
17
|
+
onBlur?: (event: React.FocusEvent<HTMLDivElement>) => void;
|
|
18
|
+
onFocus?: (event: React.FocusEvent<HTMLDivElement>) => void;
|
|
19
|
+
|
|
20
|
+
// Custom checkbox props
|
|
21
|
+
containerClassName?: string;
|
|
22
|
+
checkboxClassName?: string;
|
|
23
|
+
labelClassName?: string;
|
|
24
|
+
labelContentClassName?: string;
|
|
25
|
+
tooltipDescription?: string;
|
|
26
|
+
checkboxPriceValue: any;
|
|
27
|
+
tooltipPosX?: string;
|
|
28
|
+
error?: boolean;
|
|
29
|
+
label?: JSX.Element | string | null | ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class Checkbox extends React.Component<ICheckboxProps, {}> {
|
|
33
|
+
static defaultProps = {
|
|
34
|
+
name: '',
|
|
35
|
+
value: '',
|
|
36
|
+
checked: false,
|
|
37
|
+
disabled: false,
|
|
38
|
+
reversed: false,
|
|
39
|
+
|
|
40
|
+
onChange: () => { },
|
|
41
|
+
onBlur: () => { },
|
|
42
|
+
onFocus: () => { },
|
|
43
|
+
|
|
44
|
+
containerClassName: '',
|
|
45
|
+
checkboxClassName: '',
|
|
46
|
+
labelClassName: '',
|
|
47
|
+
labelContentClassName: '',
|
|
48
|
+
tooltipDescription: '',
|
|
49
|
+
checkboxPriceValue: '',
|
|
50
|
+
tooltipPosX: '',
|
|
51
|
+
|
|
52
|
+
error: false,
|
|
53
|
+
label: false
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
input: HTMLInputElement = null;
|
|
57
|
+
|
|
58
|
+
setInputRef = (ref: HTMLInputElement) => {
|
|
59
|
+
this.input = ref;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
63
|
+
const { disabled, value } = this.props;
|
|
64
|
+
const { checked } = event.target;
|
|
65
|
+
|
|
66
|
+
if (disabled) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (!!event) {
|
|
70
|
+
event.stopPropagation();
|
|
71
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.props.onChange(event, checked, value);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
onKeyPress = (event: any) => {
|
|
78
|
+
const { disabled } = this.props;
|
|
79
|
+
const checked = !this.input.checked;
|
|
80
|
+
const value = this.input.value;
|
|
81
|
+
|
|
82
|
+
if (disabled) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.props.onChange(event, checked, value);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
render() {
|
|
90
|
+
const {
|
|
91
|
+
containerClassName, checkboxClassName, labelClassName, labelContentClassName, reversed,
|
|
92
|
+
checked, disabled, value, error, label, tooltipDescription, checkboxPriceValue, tooltipPosX, isAboAccordionExpanded0 = true
|
|
93
|
+
} = this.props;
|
|
94
|
+
|
|
95
|
+
const containerClasses = classnames(
|
|
96
|
+
styles.container,
|
|
97
|
+
containerClassName,
|
|
98
|
+
{ [styles.checked]: checked },
|
|
99
|
+
{ [styles.error]: error },
|
|
100
|
+
{ [styles.disabled]: disabled }
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const labelClasses = classnames(
|
|
104
|
+
styles.label,
|
|
105
|
+
labelClassName
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const labelContentClasses = classnames(
|
|
109
|
+
styles.labelContent,
|
|
110
|
+
labelContentClassName
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const checkboxClasses = classnames(
|
|
114
|
+
styles.checkbox,
|
|
115
|
+
checkboxClassName,
|
|
116
|
+
{ [styles.withLabel]: !!label }
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const wrapInputClasses = classnames(
|
|
120
|
+
styles.wrapInput,
|
|
121
|
+
{ [styles.reversed]: reversed }
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
// tabIndex: was 1 (a positive value) — a well-known anti-pattern (WCAG 2.4.3):
|
|
126
|
+
// positive tabindex elements are visited in their own ascending-order pass BEFORE
|
|
127
|
+
// every tabindex="0"/naturally-focusable element on the page, regardless of where
|
|
128
|
+
// they sit in the DOM. In BaseModal's new focus trap (which walks the panel's
|
|
129
|
+
// focusable elements in DOM order to decide where Tab should wrap) that mismatch
|
|
130
|
+
// made this checkbox unreachable by Tab entirely inside a trapped modal — verified
|
|
131
|
+
// live: 0 hits in 20 Tab presses cycling the RegistrationForm consent checkbox.
|
|
132
|
+
// 0 makes it a normal stop in DOM-order tab flow, matching the trap's own model and
|
|
133
|
+
// putting it where a sighted user would visually expect it (after the fields above,
|
|
134
|
+
// before the CTA below) instead of unpredictably early.
|
|
135
|
+
<div className={containerClasses} tabIndex={0} onFocus={this.props.onFocus} onBlur={this.props.onBlur} onKeyPress={this.onKeyPress}>
|
|
136
|
+
<label className={labelClasses}>
|
|
137
|
+
<div className={wrapInputClasses}>
|
|
138
|
+
{/* Visual representation of the checkbox */}
|
|
139
|
+
{/* HidePlus class for OrderOverview component */}
|
|
140
|
+
{checkboxPriceValue && <span className={styles.checkboxPrice}><span className={styles.hidePlus}>+</span><FormattedNumber numbersAfterDot={0} value={checkboxPriceValue} /> €</span>}
|
|
141
|
+
{/* Hidden input for SEO and HTML semantics */}
|
|
142
|
+
<input
|
|
143
|
+
className={styles.hiddenInput}
|
|
144
|
+
type='checkbox'
|
|
145
|
+
checked={checked}
|
|
146
|
+
value={value}
|
|
147
|
+
disabled={disabled}
|
|
148
|
+
tabIndex={-1}
|
|
149
|
+
onChange={this.onChange}
|
|
150
|
+
ref={this.setInputRef}
|
|
151
|
+
/>
|
|
152
|
+
|
|
153
|
+
{isAboAccordionExpanded0 && <span className={checkboxClasses}>{checked ? <IconSVG name='common_CheckBlue' className={styles.checkBlueIcon} /> : false}</span>}
|
|
154
|
+
|
|
155
|
+
</div>
|
|
156
|
+
{!!label ? (
|
|
157
|
+
<span className={labelContentClasses}>
|
|
158
|
+
{label}
|
|
159
|
+
{tooltipDescription && <Tooltip description={tooltipDescription} positionY={'top'} positionX={tooltipPosX} tooltipClassName={styles.tooltipCheckbox} iconName='InfoTransparent' />}
|
|
160
|
+
</span>
|
|
161
|
+
) : false}
|
|
162
|
+
</label>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export default Checkbox;
|
|
@@ -1,86 +1,88 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import classnames from 'classnames';
|
|
3
|
-
import Checkbox from './Checkbox';
|
|
4
|
-
import styles from './FormCheckbox.styl';
|
|
5
|
-
|
|
6
|
-
interface IFormCheckboxProps {
|
|
7
|
-
className?: string;
|
|
8
|
-
errorClassName?: string;
|
|
9
|
-
label?: JSX.Element | string | null;
|
|
10
|
-
field: any;
|
|
11
|
-
checkboxClassName?: string;
|
|
12
|
-
labelClassName?: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import Checkbox from './Checkbox';
|
|
4
|
+
import styles from './FormCheckbox.styl';
|
|
5
|
+
|
|
6
|
+
interface IFormCheckboxProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
errorClassName?: string;
|
|
9
|
+
label?: JSX.Element | string | null;
|
|
10
|
+
field: any;
|
|
11
|
+
checkboxClassName?: string;
|
|
12
|
+
labelClassName?: string;
|
|
13
|
+
labelContentClassName?: string;
|
|
14
|
+
customError?: boolean;
|
|
15
|
+
helperText?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface IFormCheckboxState {
|
|
19
|
+
field: {
|
|
20
|
+
name?: string;
|
|
21
|
+
value?: boolean;
|
|
22
|
+
checked?: boolean;
|
|
23
|
+
error?: boolean;
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class FormCheckbox extends React.Component<IFormCheckboxProps, IFormCheckboxState> {
|
|
29
|
+
constructor(props: IFormCheckboxProps) {
|
|
30
|
+
super(props);
|
|
31
|
+
|
|
32
|
+
this.state = {
|
|
33
|
+
field: {
|
|
34
|
+
value: this.props.field.value,
|
|
35
|
+
error: this.props.field.error,
|
|
36
|
+
checked: this.props.field.checked,
|
|
37
|
+
disabled: this.props.field.disabled,
|
|
38
|
+
name: this.props.field.name
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static defaultProps = {
|
|
43
|
+
className: '',
|
|
44
|
+
label: false
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
handleChange = (event: React.ChangeEvent<HTMLInputElement>, checked?: boolean, value?: any) => {
|
|
48
|
+
const { name, disabled, onChange, rules } = this.props.field;
|
|
49
|
+
const customError = (rules.includes('accepted') && !checked);
|
|
50
|
+
this.setState(() => ({
|
|
51
|
+
field: {
|
|
52
|
+
value,
|
|
53
|
+
name,
|
|
54
|
+
disabled,
|
|
55
|
+
checked,
|
|
56
|
+
error: customError
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
onChange(event, checked, value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
const { label, className, checkboxClassName, labelClassName, labelContentClassName } = this.props;
|
|
64
|
+
const { name, value, checked, disabled, error } = this.state.field;
|
|
65
|
+
const customError = error || (this.props.field.error && !checked);
|
|
66
|
+
|
|
67
|
+
const _props = {
|
|
68
|
+
value,
|
|
69
|
+
checked,
|
|
70
|
+
name,
|
|
71
|
+
disabled,
|
|
72
|
+
label,
|
|
73
|
+
checkboxClassName,
|
|
74
|
+
labelClassName,
|
|
75
|
+
labelContentClassName,
|
|
76
|
+
onChange: this.handleChange,
|
|
77
|
+
error: customError
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className={classnames(styles.field, className)}>
|
|
82
|
+
<Checkbox {..._props} />
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default FormCheckbox;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebrand/fe-ui-core-autobahn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.125",
|
|
4
4
|
"description": "auto.de md3 (Autobahn) design system — UI primitives, cards, chrome, VDP modules, theme CSS and locales. Ships raw TypeScript source (like fe-ui-core before it); each consumer's bundler compiles it.",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"license": "UNLICENSED",
|