@zohodesk/dot 1.0.0-temp-187.4 → 1.0.0-temp-187.5
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/README.md +6 -0
- package/es/form/fields/Fields.module.css +1 -1
- package/es/form/fields/RadioField/RadioField.js +69 -6
- package/es/form/fields/RadioField/__tests__/RadioField.spec.js +33 -0
- package/es/form/fields/RadioField/__tests__/__snapshots__/RadioField.spec.js.snap +537 -1
- package/es/form/fields/RadioField/props/defaultProps.js +1 -0
- package/es/form/fields/RadioField/props/propTypes.js +3 -0
- package/es/v1/form/fields/RadioField/RadioField.js +3 -2
- package/lib/form/fields/Fields.module.css +1 -1
- package/lib/form/fields/RadioField/RadioField.js +100 -31
- package/lib/form/fields/RadioField/__tests__/RadioField.spec.js +33 -0
- package/lib/form/fields/RadioField/__tests__/__snapshots__/RadioField.spec.js.snap +537 -1
- package/lib/form/fields/RadioField/props/defaultProps.js +1 -0
- package/lib/form/fields/RadioField/props/propTypes.js +3 -0
- package/lib/v1/form/fields/RadioField/RadioField.js +3 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
In this Library, we Provide Some Basic Components to Build Your Application
|
|
4
4
|
|
|
5
|
+
# 1.7.3 (Yet To Publish)
|
|
6
|
+
|
|
7
|
+
- **RadioField**
|
|
8
|
+
- `getRef`, `isBoxStyle` props supported
|
|
9
|
+
- Fixed the Radio box hover style applying when disabled
|
|
10
|
+
|
|
5
11
|
# 1.7.2
|
|
6
12
|
|
|
7
13
|
- **Lookup - Search** - renderChildren, isActive, hasSeparator & customStyle props supported & Some customization also opened for this compoenent.
|
|
@@ -14,7 +14,40 @@ import style from "../Fields.module.css";
|
|
|
14
14
|
export default class RadioField extends PureComponent {
|
|
15
15
|
constructor(props) {
|
|
16
16
|
super(props);
|
|
17
|
+
this.data = {
|
|
18
|
+
radios: {},
|
|
19
|
+
focus: this.handleFocus
|
|
20
|
+
};
|
|
17
21
|
this.handleChange = this.handleChange.bind(this);
|
|
22
|
+
this.updateData = this.updateData.bind(this);
|
|
23
|
+
this.handleFocus = this.handleFocus.bind(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
componentDidMount() {
|
|
27
|
+
const {
|
|
28
|
+
getRef,
|
|
29
|
+
id
|
|
30
|
+
} = this.props;
|
|
31
|
+
getRef && getRef(this.data, id);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
componentDidUpdate(prevProps) {
|
|
35
|
+
const {
|
|
36
|
+
getRef,
|
|
37
|
+
id
|
|
38
|
+
} = this.props;
|
|
39
|
+
|
|
40
|
+
if (getRef !== prevProps.getRef) {
|
|
41
|
+
getRef && getRef(this.data, id);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
componentWillUnmount() {
|
|
46
|
+
const {
|
|
47
|
+
getRef,
|
|
48
|
+
id
|
|
49
|
+
} = this.props;
|
|
50
|
+
getRef && getRef(null, id);
|
|
18
51
|
}
|
|
19
52
|
|
|
20
53
|
handleChange(value) {
|
|
@@ -25,6 +58,24 @@ export default class RadioField extends PureComponent {
|
|
|
25
58
|
onChange && onChange(id, value);
|
|
26
59
|
}
|
|
27
60
|
|
|
61
|
+
updateData(ele, val) {
|
|
62
|
+
this.data.radios[val] = ele;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handleFocus() {
|
|
66
|
+
const {
|
|
67
|
+
selectedValue,
|
|
68
|
+
options
|
|
69
|
+
} = this.props;
|
|
70
|
+
const firstRadioValue = options[0].value;
|
|
71
|
+
|
|
72
|
+
if (selectedValue) {
|
|
73
|
+
this.data.radios[selectedValue].focus();
|
|
74
|
+
} else {
|
|
75
|
+
this.data.radios[firstRadioValue].focus();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
28
79
|
render() {
|
|
29
80
|
let {
|
|
30
81
|
labelName,
|
|
@@ -46,6 +97,7 @@ export default class RadioField extends PureComponent {
|
|
|
46
97
|
validationRuleMessage,
|
|
47
98
|
validationRulePalette,
|
|
48
99
|
isReadOnly,
|
|
100
|
+
isBoxStyle,
|
|
49
101
|
variant,
|
|
50
102
|
customProps
|
|
51
103
|
} = this.props;
|
|
@@ -69,7 +121,7 @@ export default class RadioField extends PureComponent {
|
|
|
69
121
|
dataId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
|
|
70
122
|
...LabelProps
|
|
71
123
|
}), /*#__PURE__*/React.createElement("div", {
|
|
72
|
-
className: `${style.fieldContainer} ${labelName ? style.fieldMargin_medium : ''} ${style.radioContainer}`
|
|
124
|
+
className: `${style.fieldContainer} ${isBoxStyle ? style.radiosWrapper : ''} ${labelName ? style.fieldMargin_medium : ''} ${style.radioContainer}`
|
|
73
125
|
}, options.map((option, index) => {
|
|
74
126
|
let {
|
|
75
127
|
text,
|
|
@@ -78,9 +130,11 @@ export default class RadioField extends PureComponent {
|
|
|
78
130
|
tooltip,
|
|
79
131
|
infoTooltip
|
|
80
132
|
} = option;
|
|
133
|
+
let isDisabledState = disabled || isDisabled;
|
|
134
|
+
let isChecked = selectedValue == value;
|
|
81
135
|
return /*#__PURE__*/React.createElement("span", {
|
|
82
136
|
key: index,
|
|
83
|
-
className: `${style.radio}`
|
|
137
|
+
className: `${!isBoxStyle ? style.radio : ''} ${style.radioWrap}`
|
|
84
138
|
}, /*#__PURE__*/React.createElement(Radio, {
|
|
85
139
|
id: index,
|
|
86
140
|
value: value,
|
|
@@ -88,17 +142,26 @@ export default class RadioField extends PureComponent {
|
|
|
88
142
|
text: text,
|
|
89
143
|
labelPalette: labelPalette,
|
|
90
144
|
labelSize: labelSize,
|
|
91
|
-
active: isActive,
|
|
92
|
-
disabled:
|
|
145
|
+
active: isActive || isBoxStyle && isChecked,
|
|
146
|
+
disabled: isDisabledState,
|
|
93
147
|
disabledTitle: tooltip,
|
|
94
148
|
title: tooltip,
|
|
95
149
|
onChange: this.handleChange,
|
|
150
|
+
getRef: this.updateData,
|
|
96
151
|
size: size,
|
|
97
|
-
checked:
|
|
152
|
+
checked: isChecked,
|
|
98
153
|
dataId: dataId,
|
|
99
154
|
isReadOnly: isReadOnly,
|
|
100
155
|
variant: variant,
|
|
101
|
-
...RadioProps
|
|
156
|
+
...RadioProps,
|
|
157
|
+
a11y: {
|
|
158
|
+
tabIndex: !!selectedValue ? isChecked ? '0' : '-1' : index === 0 ? '0' : '-1',
|
|
159
|
+
...RadioProps.a11y
|
|
160
|
+
},
|
|
161
|
+
customClass: {
|
|
162
|
+
customRadioWrap: isBoxStyle ? `${style.radioBox} ${!isDisabledState ? style.hoverableRadioBox : ''} ${isChecked ? style.radioBoxActive : ''}` : '',
|
|
163
|
+
...RadioProps.customClass
|
|
164
|
+
}
|
|
102
165
|
}, !!infoTooltip ? /*#__PURE__*/React.createElement(Icon, {
|
|
103
166
|
name: "ZD-GN-info",
|
|
104
167
|
size: "16",
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import RadioField from "../RadioField";
|
|
4
|
+
const options = [{
|
|
5
|
+
text: 'Chennai',
|
|
6
|
+
value: '1'
|
|
7
|
+
}, {
|
|
8
|
+
text: 'Mumbai',
|
|
9
|
+
value: '2',
|
|
10
|
+
tooltip: 'Disabled Option',
|
|
11
|
+
disabled: true
|
|
12
|
+
}, {
|
|
13
|
+
text: 'Delhi',
|
|
14
|
+
value: '3',
|
|
15
|
+
infoTooltip: 'Capital of India'
|
|
16
|
+
}, {
|
|
17
|
+
text: 'Kolkata',
|
|
18
|
+
value: '4'
|
|
19
|
+
}];
|
|
4
20
|
describe('RadioField', () => {
|
|
5
21
|
test('rendering the defult props', () => {
|
|
6
22
|
const {
|
|
@@ -10,4 +26,21 @@ describe('RadioField', () => {
|
|
|
10
26
|
}));
|
|
11
27
|
expect(asFragment()).toMatchSnapshot();
|
|
12
28
|
});
|
|
29
|
+
test('rendering with options', () => {
|
|
30
|
+
const {
|
|
31
|
+
asFragment
|
|
32
|
+
} = render( /*#__PURE__*/React.createElement(RadioField, {
|
|
33
|
+
options: options
|
|
34
|
+
}));
|
|
35
|
+
expect(asFragment()).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
test('rendering options with isBoxStyle', () => {
|
|
38
|
+
const {
|
|
39
|
+
asFragment
|
|
40
|
+
} = render( /*#__PURE__*/React.createElement(RadioField, {
|
|
41
|
+
options: options,
|
|
42
|
+
isBoxStyle: true
|
|
43
|
+
}));
|
|
44
|
+
expect(asFragment()).toMatchSnapshot();
|
|
45
|
+
});
|
|
13
46
|
});
|