@sebgroup/green-react 1.0.0-beta.7 → 1.0.0-beta.8

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/index.esm.js CHANGED
@@ -1840,27 +1840,14 @@ const validateInputValue = (target, rules, setError) => {
1840
1840
 
1841
1841
  const validateInputValueErrors = (rules, target) => {
1842
1842
  const {
1843
- value,
1844
- type,
1845
- checked
1843
+ value
1846
1844
  } = target;
1847
1845
 
1848
1846
  if ((rules === null || rules === void 0 ? void 0 : rules.custom) instanceof Function) {
1849
1847
  return rules === null || rules === void 0 ? void 0 : rules.custom();
1850
1848
  }
1851
1849
 
1852
- switch (type) {
1853
- case 'text':
1854
- case 'email':
1855
- case 'number':
1856
- return validateTextInputValues(value, rules);
1857
-
1858
- case 'checkbox':
1859
- return validateCheckBoxInput(checked);
1860
-
1861
- default:
1862
- return validateTextInputValues(value, rules);
1863
- }
1850
+ return validateTextInputValues(value, rules);
1864
1851
  };
1865
1852
 
1866
1853
  const setErrorInsert = (setError, name) => {
@@ -1893,14 +1880,6 @@ const validateTextInputValues = (value, rules) => {
1893
1880
  }
1894
1881
  };
1895
1882
 
1896
- const validateCheckBoxInput = checked => {
1897
- if (!checked) {
1898
- return 'error';
1899
- }
1900
-
1901
- return null;
1902
- };
1903
-
1904
1883
  const FormContext = /*#__PURE__*/React.createContext({});
1905
1884
  const useFormContext = () => {
1906
1885
  return React.useContext(FormContext);
@@ -2000,34 +1979,24 @@ const FormItems = ({
2000
1979
  type,
2001
1980
  checked
2002
1981
  } = event.target;
1982
+ let inputValue;
2003
1983
 
2004
1984
  if (type === 'checkbox') {
2005
- if (checked) {
2006
- setValues(values => {
2007
- return Object.assign(Object.assign({}, values), {
2008
- [name]: {
2009
- value,
2010
- checked
2011
- }
2012
- });
2013
- });
2014
- } else {
2015
- setValues(values => {
2016
- return Object.assign(Object.assign({}, values), {
2017
- [name]: null
2018
- });
2019
- });
2020
- }
1985
+ inputValue = checked ? value : null;
1986
+ checked ? setValues(values => Object.assign(Object.assign({}, values), {
1987
+ [name]: value
1988
+ })) : setValues(values => Object.assign(Object.assign({}, values), {
1989
+ [name]: null
1990
+ }));
2021
1991
  } else {
2022
- setValues(values => {
2023
- return Object.assign(Object.assign({}, values), {
2024
- [name]: value
2025
- });
2026
- });
1992
+ inputValue = value;
1993
+ setValues(values => Object.assign(Object.assign({}, values), {
1994
+ [name]: value
1995
+ }));
2027
1996
  }
2028
1997
 
2029
1998
  validateInputValue({
2030
- value,
1999
+ value: inputValue,
2031
2000
  name,
2032
2001
  type,
2033
2002
  checked
@@ -2200,7 +2169,7 @@ const Checkbox = _a => {
2200
2169
  }), void 0)]
2201
2170
  }, void 0);
2202
2171
  };
2203
- const RadioButton = _a => {
2172
+ const RadioButton = /*#__PURE__*/React.forwardRef((_a, ref) => {
2204
2173
  var {
2205
2174
  label,
2206
2175
  validator
@@ -2218,12 +2187,13 @@ const RadioButton = _a => {
2218
2187
  id: id,
2219
2188
  type: "radio"
2220
2189
  }, props, {
2221
- className: validator
2190
+ className: validator,
2191
+ ref: ref
2222
2192
  }), void 0), jsx("span", {
2223
2193
  children: label
2224
2194
  }, void 0), jsx("i", {}, void 0)]
2225
2195
  }), void 0);
2226
- };
2196
+ });
2227
2197
 
2228
2198
  const Text = ({
2229
2199
  children
@@ -2345,16 +2315,37 @@ const RadioGroup = ({
2345
2315
  title,
2346
2316
  validator,
2347
2317
  onChangeRadio,
2318
+ onChange,
2319
+ name,
2348
2320
  children
2349
2321
  }) => {
2350
2322
  const [checked, setChecked] = React.useState();
2351
2323
  const validatorClassName = validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator);
2352
2324
 
2353
- const onChange = event => {
2325
+ const onChanges = event => {
2354
2326
  setChecked(event.target.value);
2355
2327
  onChangeRadio && onChangeRadio(event.target.value);
2328
+ onChange && onChange(event);
2356
2329
  };
2357
2330
 
2331
+ const radioBtnRef = React.useRef(null);
2332
+ React.useEffect(() => {
2333
+ var _a;
2334
+
2335
+ if (radioBtnRef && radioBtnRef.current) {
2336
+ const form = (_a = radioBtnRef === null || radioBtnRef === void 0 ? void 0 : radioBtnRef.current) === null || _a === void 0 ? void 0 : _a.form;
2337
+
2338
+ const resetListner = () => {
2339
+ setChecked(undefined);
2340
+ };
2341
+
2342
+ form === null || form === void 0 ? void 0 : form.addEventListener('reset', resetListner);
2343
+ return () => form === null || form === void 0 ? void 0 : form.removeEventListener('reset', resetListner);
2344
+ } else {
2345
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2346
+ return () => {};
2347
+ }
2348
+ }, []);
2358
2349
  return jsxs("div", Object.assign({
2359
2350
  className: "form-group"
2360
2351
  }, {
@@ -2370,8 +2361,10 @@ const RadioGroup = ({
2370
2361
  }), void 0), React.Children.map(children, Child => {
2371
2362
  return /*#__PURE__*/React.isValidElement(Child) ? /*#__PURE__*/React.cloneElement(Child, {
2372
2363
  validator: validatorClassName,
2373
- onChange,
2374
- checked: checked === Child.props.value
2364
+ onChange: onChanges,
2365
+ checked: checked === Child.props.value,
2366
+ name,
2367
+ ref: radioBtnRef
2375
2368
  }) : Child;
2376
2369
  })]
2377
2370
  }), void 0), (validator === null || validator === void 0 ? void 0 : validator.message) && jsx("span", Object.assign({
package/index.umd.js CHANGED
@@ -330,26 +330,13 @@
330
330
  };
331
331
 
332
332
  var validateInputValueErrors = function validateInputValueErrors(rules, target) {
333
- var value = target.value,
334
- type = target.type,
335
- checked = target.checked;
333
+ var value = target.value;
336
334
 
337
335
  if ((rules === null || rules === void 0 ? void 0 : rules.custom) instanceof Function) {
338
336
  return rules === null || rules === void 0 ? void 0 : rules.custom();
339
337
  }
340
338
 
341
- switch (type) {
342
- case 'text':
343
- case 'email':
344
- case 'number':
345
- return validateTextInputValues(value, rules);
346
-
347
- case 'checkbox':
348
- return validateCheckBoxInput(checked);
349
-
350
- default:
351
- return validateTextInputValues(value, rules);
352
- }
339
+ return validateTextInputValues(value, rules);
353
340
  };
354
341
 
355
342
  var setErrorInsert = function setErrorInsert(setError, name) {
@@ -383,14 +370,6 @@
383
370
  }
384
371
  };
385
372
 
386
- var validateCheckBoxInput = function validateCheckBoxInput(checked) {
387
- if (!checked) {
388
- return 'error';
389
- }
390
-
391
- return null;
392
- };
393
-
394
373
  var FormContext = /*#__PURE__*/React__default["default"].createContext({});
395
374
  var useFormContext = function useFormContext() {
396
375
  return React__default["default"].useContext(FormContext);
@@ -506,25 +485,21 @@
506
485
  name = _a.name,
507
486
  type = _a.type,
508
487
  checked = _a.checked;
488
+ var inputValue;
509
489
 
510
490
  if (type === 'checkbox') {
511
- if (checked) {
512
- setValues(function (values) {
513
- var _a;
514
-
515
- return __assign(__assign({}, values), (_a = {}, _a[name] = {
516
- value: value,
517
- checked: checked
518
- }, _a));
519
- });
520
- } else {
521
- setValues(function (values) {
522
- var _a;
523
-
524
- return __assign(__assign({}, values), (_a = {}, _a[name] = null, _a));
525
- });
526
- }
491
+ inputValue = checked ? value : null;
492
+ checked ? setValues(function (values) {
493
+ var _a;
494
+
495
+ return __assign(__assign({}, values), (_a = {}, _a[name] = value, _a));
496
+ }) : setValues(function (values) {
497
+ var _a;
498
+
499
+ return __assign(__assign({}, values), (_a = {}, _a[name] = null, _a));
500
+ });
527
501
  } else {
502
+ inputValue = value;
528
503
  setValues(function (values) {
529
504
  var _a;
530
505
 
@@ -533,7 +508,7 @@
533
508
  }
534
509
 
535
510
  validateInputValue({
536
- value: value,
511
+ value: inputValue,
537
512
  name: name,
538
513
  type: type,
539
514
  checked: checked
@@ -707,7 +682,7 @@
707
682
  }), void 0)]
708
683
  }, void 0);
709
684
  };
710
- var RadioButton = function RadioButton(_a) {
685
+ var RadioButton = /*#__PURE__*/React__default["default"].forwardRef(function (_a, ref) {
711
686
  var label = _a.label,
712
687
  validator = _a.validator,
713
688
  props = __rest(_a, ["label", "validator"]);
@@ -721,12 +696,13 @@
721
696
  id: id,
722
697
  type: "radio"
723
698
  }, props, {
724
- className: validator
699
+ className: validator,
700
+ ref: ref
725
701
  }), void 0), jsxRuntime.jsx("span", {
726
702
  children: label
727
703
  }, void 0), jsxRuntime.jsx("i", {}, void 0)]
728
704
  }), void 0);
729
- };
705
+ });
730
706
 
731
707
  var Text = function Text(_a) {
732
708
  var children = _a.children;
@@ -1798,6 +1774,8 @@
1798
1774
  title = _a.title,
1799
1775
  validator = _a.validator,
1800
1776
  onChangeRadio = _a.onChangeRadio,
1777
+ onChange = _a.onChange,
1778
+ name = _a.name,
1801
1779
  children = _a.children;
1802
1780
 
1803
1781
  var _b = React__default["default"].useState(),
@@ -1806,11 +1784,32 @@
1806
1784
 
1807
1785
  var validatorClassName = extract.validateClassName(validator === null || validator === void 0 ? void 0 : validator.indicator);
1808
1786
 
1809
- var onChange = function onChange(event) {
1787
+ var onChanges = function onChanges(event) {
1810
1788
  setChecked(event.target.value);
1811
1789
  onChangeRadio && onChangeRadio(event.target.value);
1790
+ onChange && onChange(event);
1812
1791
  };
1813
1792
 
1793
+ var radioBtnRef = React__default["default"].useRef(null);
1794
+ React__default["default"].useEffect(function () {
1795
+ var _a;
1796
+
1797
+ if (radioBtnRef && radioBtnRef.current) {
1798
+ var form_1 = (_a = radioBtnRef === null || radioBtnRef === void 0 ? void 0 : radioBtnRef.current) === null || _a === void 0 ? void 0 : _a.form;
1799
+
1800
+ var resetListner_1 = function resetListner_1() {
1801
+ setChecked(undefined);
1802
+ };
1803
+
1804
+ form_1 === null || form_1 === void 0 ? void 0 : form_1.addEventListener('reset', resetListner_1);
1805
+ return function () {
1806
+ return form_1 === null || form_1 === void 0 ? void 0 : form_1.removeEventListener('reset', resetListner_1);
1807
+ };
1808
+ } else {
1809
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1810
+ return function () {};
1811
+ }
1812
+ }, []);
1814
1813
  return jsxRuntime.jsxs("div", __assign({
1815
1814
  className: "form-group"
1816
1815
  }, {
@@ -1826,8 +1825,10 @@
1826
1825
  }), void 0), React__default["default"].Children.map(children, function (Child) {
1827
1826
  return /*#__PURE__*/React__default["default"].isValidElement(Child) ? /*#__PURE__*/React__default["default"].cloneElement(Child, {
1828
1827
  validator: validatorClassName,
1829
- onChange: onChange,
1830
- checked: checked === Child.props.value
1828
+ onChange: onChanges,
1829
+ checked: checked === Child.props.value,
1830
+ name: name,
1831
+ ref: radioBtnRef
1831
1832
  }) : Child;
1832
1833
  })]
1833
1834
  }), void 0), (validator === null || validator === void 0 ? void 0 : validator.message) && jsxRuntime.jsx("span", __assign({
@@ -7,4 +7,4 @@ export declare const TextInput: ({ label, info, onChange, onChangeInput, validat
7
7
  export declare const EmailInput: ({ label, info, onChange, onChangeInput, validator, ...props }: TextInputProps) => JSX.Element;
8
8
  export declare const NumberInput: ({ label, info, onChange, onChangeInput, validator, ...props }: NumberInputProps) => JSX.Element;
9
9
  export declare const Checkbox: ({ label, onChange, validator, ...props }: CheckboxProps) => JSX.Element;
10
- export declare const RadioButton: ({ label, validator, ...props }: RadioButtonProps) => JSX.Element;
10
+ export declare const RadioButton: React.ForwardRefExoticComponent<Pick<RadioButtonProps, "label" | "onChange" | "validator" | "type" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "as" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "cite" | "classID" | "cols" | "colSpan" | "content" | "controls" | "coords" | "crossOrigin" | "data" | "dateTime" | "default" | "defer" | "disabled" | "download" | "encType" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "height" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "list" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "name" | "nonce" | "noValidate" | "open" | "optimum" | "pattern" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "selected" | "shape" | "size" | "sizes" | "span" | "src" | "srcDoc" | "srcLang" | "srcSet" | "start" | "step" | "summary" | "target" | "useMap" | "value" | "width" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & React.RefAttributes<HTMLInputElement>>;
@@ -5,6 +5,8 @@ export interface RadioGroupProps {
5
5
  description?: string;
6
6
  validator?: IValidator;
7
7
  onChangeRadio?: (value: string) => string;
8
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
9
+ name?: string;
8
10
  }
9
- export declare const RadioGroup: ({ description, title, validator, onChangeRadio, children }: React.PropsWithChildren<RadioGroupProps>) => JSX.Element;
11
+ export declare const RadioGroup: ({ description, title, validator, onChangeRadio, onChange, name, children }: React.PropsWithChildren<RadioGroupProps>) => JSX.Element;
10
12
  export default RadioGroup;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.8",
4
4
  "peerDependencies": {
5
5
  "react": "^17.0.0",
6
6
  "react-dom": "^17.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@sebgroup/chlorophyll": "^1.0.0-beta.7",
10
- "@sebgroup/extract": "^1.0.0-beta.7"
9
+ "@sebgroup/chlorophyll": "^1.0.0-beta.8",
10
+ "@sebgroup/extract": "^1.0.0-beta.8"
11
11
  },
12
12
  "description": "React components built on top of @sebgroup/chlorophyll.",
13
13
  "repository": {