var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.InputControl=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireWildcard(require("react"));var _index=require("../../../index");var _CodePreviewProvider=require("../CodePreviewProvider");var _jsxRuntime=require("react/jsx-runtime");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}var InputControl=function InputControl(_ref){var defaultValue=_ref.defaultValue,componentProp=_ref.componentProp;var _useContext=(0,_react.useContext)(_CodePreviewProvider.CodePreviewContext),propsString=_useContext.propsString,updatePropsString=_useContext.updatePropsString;var _useState=(0,_react.useState)(defaultValue!=null?defaultValue:''),_useState2=(0,_slicedToArray2.default)(_useState,2),value=_useState2[0],setValue=_useState2[1];var handleChange=function handleChange(e){var inputValue=e.target.value;setValue(inputValue);var componentPropValueRegex=new RegExp(componentProp+'="(.*?)"','g');if(propsString.match(componentPropValueRegex)){updatePropsString(propsString.replace(componentPropValueRegex,`${componentProp}="${inputValue}"`));}else{updatePropsString(`${propsString} ${componentProp}="${inputValue}"`);}if(inputValue===''){updatePropsString(propsString.replace(componentPropValueRegex,''));}};return(0,_jsxRuntime.jsxs)(_index.FormControl,{children:[(0,_jsxRuntime.jsx)(_index.FormControl.Label,{mb:"$3",children:(0,_jsxRuntime.jsx)(_index.FormControl.Label.Text,{fontSize:"$xs",lineHeight:"$xs",color:"$textDark400",fontWeight:"$normal",children:componentProp})}),(0,_jsxRuntime.jsx)(_index.Input,{variant:"underlined",children:(0,_jsxRuntime.jsx)(_index.Input.Input,{placeholder:"Enter label",value:value,onChange:handleChange,color:"$textLight900",sx:{_dark:{color:'$textDark50'}},fontSize:"$sm",pt:"$3",pb:"$2",px:"$0"})})]});};exports.InputControl=InputControl;
//# sourceMappingURL=InputControl.js.map