@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.
@@ -29,6 +29,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
29
29
 
30
30
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
31
 
32
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
+
34
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
35
+
36
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
37
+
32
38
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
33
39
 
34
40
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -62,45 +68,98 @@ var RadioField = /*#__PURE__*/function (_PureComponent) {
62
68
  _classCallCheck(this, RadioField);
63
69
 
64
70
  _this = _super.call(this, props);
71
+ _this.data = {
72
+ radios: {},
73
+ focus: _this.handleFocus
74
+ };
65
75
  _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
76
+ _this.updateData = _this.updateData.bind(_assertThisInitialized(_this));
77
+ _this.handleFocus = _this.handleFocus.bind(_assertThisInitialized(_this));
66
78
  return _this;
67
79
  }
68
80
 
69
81
  _createClass(RadioField, [{
82
+ key: "componentDidMount",
83
+ value: function componentDidMount() {
84
+ var _this$props = this.props,
85
+ getRef = _this$props.getRef,
86
+ id = _this$props.id;
87
+ getRef && getRef(this.data, id);
88
+ }
89
+ }, {
90
+ key: "componentDidUpdate",
91
+ value: function componentDidUpdate(prevProps) {
92
+ var _this$props2 = this.props,
93
+ getRef = _this$props2.getRef,
94
+ id = _this$props2.id;
95
+
96
+ if (getRef !== prevProps.getRef) {
97
+ getRef && getRef(this.data, id);
98
+ }
99
+ }
100
+ }, {
101
+ key: "componentWillUnmount",
102
+ value: function componentWillUnmount() {
103
+ var _this$props3 = this.props,
104
+ getRef = _this$props3.getRef,
105
+ id = _this$props3.id;
106
+ getRef && getRef(null, id);
107
+ }
108
+ }, {
70
109
  key: "handleChange",
71
110
  value: function handleChange(value) {
72
- var _this$props = this.props,
73
- id = _this$props.id,
74
- onChange = _this$props.onChange;
111
+ var _this$props4 = this.props,
112
+ id = _this$props4.id,
113
+ onChange = _this$props4.onChange;
75
114
  onChange && onChange(id, value);
76
115
  }
116
+ }, {
117
+ key: "updateData",
118
+ value: function updateData(ele, val) {
119
+ this.data.radios[val] = ele;
120
+ }
121
+ }, {
122
+ key: "handleFocus",
123
+ value: function handleFocus() {
124
+ var _this$props5 = this.props,
125
+ selectedValue = _this$props5.selectedValue,
126
+ options = _this$props5.options;
127
+ var firstRadioValue = options[0].value;
128
+
129
+ if (selectedValue) {
130
+ this.data.radios[selectedValue].focus();
131
+ } else {
132
+ this.data.radios[firstRadioValue].focus();
133
+ }
134
+ }
77
135
  }, {
78
136
  key: "render",
79
137
  value: function render() {
80
138
  var _this2 = this;
81
139
 
82
- var _this$props2 = this.props,
83
- labelName = _this$props2.labelName,
84
- id = _this$props2.id,
85
- isMandatory = _this$props2.isMandatory,
86
- options = _this$props2.options,
87
- validationMessage = _this$props2.validationMessage,
88
- validationPalette = _this$props2.validationPalette,
89
- errorType = _this$props2.errorType,
90
- isDisabled = _this$props2.isDisabled,
91
- title = _this$props2.title,
92
- labelPalette = _this$props2.labelPalette,
93
- labelSize = _this$props2.labelSize,
94
- size = _this$props2.size,
95
- selectedValue = _this$props2.selectedValue,
96
- isActive = _this$props2.isActive,
97
- dataId = _this$props2.dataId,
98
- dataSelectorId = _this$props2.dataSelectorId,
99
- validationRuleMessage = _this$props2.validationRuleMessage,
100
- validationRulePalette = _this$props2.validationRulePalette,
101
- isReadOnly = _this$props2.isReadOnly,
102
- variant = _this$props2.variant,
103
- customProps = _this$props2.customProps;
140
+ var _this$props6 = this.props,
141
+ labelName = _this$props6.labelName,
142
+ id = _this$props6.id,
143
+ isMandatory = _this$props6.isMandatory,
144
+ options = _this$props6.options,
145
+ validationMessage = _this$props6.validationMessage,
146
+ validationPalette = _this$props6.validationPalette,
147
+ errorType = _this$props6.errorType,
148
+ isDisabled = _this$props6.isDisabled,
149
+ title = _this$props6.title,
150
+ labelPalette = _this$props6.labelPalette,
151
+ labelSize = _this$props6.labelSize,
152
+ size = _this$props6.size,
153
+ selectedValue = _this$props6.selectedValue,
154
+ isActive = _this$props6.isActive,
155
+ dataId = _this$props6.dataId,
156
+ dataSelectorId = _this$props6.dataSelectorId,
157
+ validationRuleMessage = _this$props6.validationRuleMessage,
158
+ validationRulePalette = _this$props6.validationRulePalette,
159
+ isReadOnly = _this$props6.isReadOnly,
160
+ isBoxStyle = _this$props6.isBoxStyle,
161
+ variant = _this$props6.variant,
162
+ customProps = _this$props6.customProps;
104
163
  var _customProps$LabelPro = customProps.LabelProps,
105
164
  LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro,
106
165
  _customProps$RadioPro = customProps.RadioProps,
@@ -123,7 +182,7 @@ var RadioField = /*#__PURE__*/function (_PureComponent) {
123
182
  customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''),
124
183
  dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label")
125
184
  }, LabelProps)), /*#__PURE__*/_react["default"].createElement("div", {
126
- className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(labelName ? _FieldsModule["default"].fieldMargin_medium : '', " ").concat(_FieldsModule["default"].radioContainer)
185
+ className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(isBoxStyle ? _FieldsModule["default"].radiosWrapper : '', " ").concat(labelName ? _FieldsModule["default"].fieldMargin_medium : '', " ").concat(_FieldsModule["default"].radioContainer)
127
186
  }, options.map(function (option, index) {
128
187
  var text = option.text,
129
188
  value = option.value,
@@ -131,9 +190,11 @@ var RadioField = /*#__PURE__*/function (_PureComponent) {
131
190
  disabled = _option$disabled === void 0 ? false : _option$disabled,
132
191
  tooltip = option.tooltip,
133
192
  infoTooltip = option.infoTooltip;
193
+ var isDisabledState = disabled || isDisabled;
194
+ var isChecked = selectedValue == value;
134
195
  return /*#__PURE__*/_react["default"].createElement("span", {
135
196
  key: index,
136
- className: "".concat(_FieldsModule["default"].radio)
197
+ className: "".concat(!isBoxStyle ? _FieldsModule["default"].radio : '', " ").concat(_FieldsModule["default"].radioWrap)
137
198
  }, /*#__PURE__*/_react["default"].createElement(_Radio["default"], _extends({
138
199
  id: index,
139
200
  value: value,
@@ -141,17 +202,25 @@ var RadioField = /*#__PURE__*/function (_PureComponent) {
141
202
  text: text,
142
203
  labelPalette: labelPalette,
143
204
  labelSize: labelSize,
144
- active: isActive,
145
- disabled: disabled || isDisabled,
205
+ active: isActive || isBoxStyle && isChecked,
206
+ disabled: isDisabledState,
146
207
  disabledTitle: tooltip,
147
208
  title: tooltip,
148
209
  onChange: _this2.handleChange,
210
+ getRef: _this2.updateData,
149
211
  size: size,
150
- checked: selectedValue == value,
212
+ checked: isChecked,
151
213
  dataId: dataId,
152
214
  isReadOnly: isReadOnly,
153
215
  variant: variant
154
- }, RadioProps), !!infoTooltip ? /*#__PURE__*/_react["default"].createElement(_Icon["default"], _extends({
216
+ }, RadioProps, {
217
+ a11y: _objectSpread({
218
+ tabIndex: !!selectedValue ? isChecked ? '0' : '-1' : index === 0 ? '0' : '-1'
219
+ }, RadioProps.a11y),
220
+ customClass: _objectSpread({
221
+ customRadioWrap: isBoxStyle ? "".concat(_FieldsModule["default"].radioBox, " ").concat(!isDisabledState ? _FieldsModule["default"].hoverableRadioBox : '', " ").concat(isChecked ? _FieldsModule["default"].radioBoxActive : '') : ''
222
+ }, RadioProps.customClass)
223
+ }), !!infoTooltip ? /*#__PURE__*/_react["default"].createElement(_Icon["default"], _extends({
155
224
  name: "ZD-GN-info",
156
225
  size: "16",
157
226
  title: infoTooltip,
@@ -8,6 +8,22 @@ var _RadioField = _interopRequireDefault(require("../RadioField"));
8
8
 
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
10
 
11
+ var options = [{
12
+ text: 'Chennai',
13
+ value: '1'
14
+ }, {
15
+ text: 'Mumbai',
16
+ value: '2',
17
+ tooltip: 'Disabled Option',
18
+ disabled: true
19
+ }, {
20
+ text: 'Delhi',
21
+ value: '3',
22
+ infoTooltip: 'Capital of India'
23
+ }, {
24
+ text: 'Kolkata',
25
+ value: '4'
26
+ }];
11
27
  describe('RadioField', function () {
12
28
  test('rendering the defult props', function () {
13
29
  var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioField["default"], {
@@ -17,4 +33,21 @@ describe('RadioField', function () {
17
33
 
18
34
  expect(asFragment()).toMatchSnapshot();
19
35
  });
36
+ test('rendering with options', function () {
37
+ var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioField["default"], {
38
+ options: options
39
+ })),
40
+ asFragment = _render2.asFragment;
41
+
42
+ expect(asFragment()).toMatchSnapshot();
43
+ });
44
+ test('rendering options with isBoxStyle', function () {
45
+ var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioField["default"], {
46
+ options: options,
47
+ isBoxStyle: true
48
+ })),
49
+ asFragment = _render3.asFragment;
50
+
51
+ expect(asFragment()).toMatchSnapshot();
52
+ });
20
53
  });