tp-react-elements-dev 1.4.10 → 1.4.11

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/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { forwardRef, useContext, Children, isValidElement, cloneElement, useState, useRef, useEffect, createContext, useMemo, useCallback } from 'react';
2
+ import React__default, { forwardRef, useContext, Children, isValidElement, cloneElement, useState, useRef, useEffect, useCallback, createContext, useMemo } from 'react';
3
3
  import * as ReactDOM from 'react-dom';
4
4
  import ReactDOM__default from 'react-dom';
5
5
 
@@ -52248,14 +52248,25 @@ const SingleSelectNonAutoComplete = ({ props }) => {
52248
52248
  };
52249
52249
 
52250
52250
  const FormActiveSwitch = ({ props }) => {
52251
- const [active, setActive] = useState(props.getValues(props.item.name)); // Assuming "Active" is the default
52252
- const handleSwitchChange = () => {
52253
- setActive(!active);
52254
- };
52251
+ const { getValues, setValue, item } = props;
52252
+ const [active, setActive] = useState(true);
52253
+ const data = getValues(item.name);
52255
52254
  useEffect(() => {
52256
- props.setValue(props.item.name, active);
52257
- }, [active]);
52258
- return (jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsxs("div", Object.assign({ className: "m-form__input" }, { children: [props.item.label && jsxRuntimeExports.jsx("span", Object.assign({ style: { fontSize: "12px", fontWeight: 400, paddingRight: 10 } }, { children: props.item.label })), jsxRuntimeExports.jsxs("span", Object.assign({ className: "switch prestashop-switch fixed-width-lg" }, { children: [jsxRuntimeExports.jsx("input", { checked: active, id: props.item.name + '_on', name: props.item.name, type: "radio", value: "Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: props.item.name + '_on', style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: props.item.label1 ? props.item.label1 : 'Active' })), jsxRuntimeExports.jsx("input", { id: props.item.name + '_off', checked: !active, name: props.item.name, type: "radio", value: "In Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: props.item.name + '_off', style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: props.item.label2 ? props.item.label2 : 'In Active' })), jsxRuntimeExports.jsx("a", { className: "slide-button btn" })] }))] })) }));
52255
+ if (data === undefined || data === null) {
52256
+ setActive(false);
52257
+ }
52258
+ else {
52259
+ setActive(data);
52260
+ }
52261
+ }, [data]);
52262
+ const handleSwitchChange = useCallback(() => {
52263
+ setActive(prevActive => {
52264
+ // const newValue = !prevActive ? "A" : "I";
52265
+ setValue(item.name, !prevActive);
52266
+ return !prevActive;
52267
+ });
52268
+ }, [setValue, item.name]);
52269
+ return (jsxRuntimeExports.jsx("div", { children: jsxRuntimeExports.jsxs("div", Object.assign({ className: "m-form__input" }, { children: [item.label && (jsxRuntimeExports.jsx("span", Object.assign({ style: { fontSize: "12px", fontWeight: 400, paddingRight: 10 } }, { children: item.label }))), jsxRuntimeExports.jsxs("span", Object.assign({ className: "switch prestashop-switch fixed-width-lg" }, { children: [jsxRuntimeExports.jsx("input", { checked: active, id: `${item.name}_on`, name: item.name, type: "radio", value: "Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: `${item.name}_on`, style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: item.label1 ? item.label1 : "Active" })), jsxRuntimeExports.jsx("input", { checked: !active, id: `${item.name}_off`, name: item.name, type: "radio", value: "In Active", onChange: handleSwitchChange }), jsxRuntimeExports.jsx("label", Object.assign({ htmlFor: `${item.name}_off`, style: { fontFamily: "Roboto-Reg", textTransform: "none" } }, { children: item.label2 ? item.label2 : "In Active" })), jsxRuntimeExports.jsx("a", { className: "slide-button btn" })] }))] })) }));
52259
52270
  };
52260
52271
 
52261
52272
  const renderLabel = (label, isRequired, alignRight) => {