{"version":3,"file":"FormToggle.mjs","sources":["../../../src/lib/components/FormToggle/FormToggle.jsx"],"sourcesContent":["/*\nCopyright 2022 Iguazio Systems Ltd.\nLicensed under the Apache License, Version 2.0 (the \"License\") with\nan addition restriction as set forth herein. You may not use this\nfile except in compliance with the License. You may obtain a copy of\nthe License at http://www.apache.org/licenses/LICENSE-2.0.\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied. See the License for the specific language governing\npermissions and limitations under the License.\nIn addition, you may not use the software for any purposes that are\nillegal under applicable law, and the grant of the foregoing license\nunder the Apache 2.0 license is conditioned upon your compliance with\nsuch restriction.\n*/\nimport React from 'react'\nimport classnames from 'classnames'\nimport PropTypes from 'prop-types'\nimport { Field } from 'react-final-form'\n\nimport Tip from '../Tip/Tip'\nimport { DENSITY } from '../../types.js'\n\nimport './formToggle.scss'\n\nconst FormToggle = ({\n  className = '',\n  density = '',\n  label = '',\n  labelTip = '',\n  name,\n  readOnly = false,\n  onChange = () => {},\n  ...inputProps\n}) => {\n  const formFieldClassNames = classnames(\n    'form-field-toggle',\n    'form-field__wrapper',\n    density && `form-field__wrapper-${density}`,\n    (label || labelTip) && 'form-field-toggle_has-label',\n    className\n  )\n\n  return (\n    <Field name={name} value={inputProps.value} type=\"checkbox\">\n      {({ input }) => (\n        <div\n          className={formFieldClassNames}\n          data-testid={name ? `${name}-form-field-toggle` : 'form-field-toggle'}\n        >\n          {(label || labelTip) && (\n            <label htmlFor={name} className=\"form-field-toggle__label\">\n              {label}\n              {labelTip && <Tip text={labelTip} />}\n            </label>\n          )}\n          <label htmlFor={name} className=\"form-field-toggle__toggle-wrapper\">\n            <input\n              type=\"checkbox\"\n              data-testid={name ? `${name}-form-toggle` : 'form-toggle'}\n              id={name}\n              {...{ ...input, ...inputProps }}\n              value={String(input.checked)}\n              disabled={readOnly}\n              onChange={event => {\n                onChange?.(event)\n                input.onChange(event)\n              }}\n            />\n            <span className=\"form-field-toggle__switch\" />\n          </label>\n        </div>\n      )}\n    </Field>\n  )\n}\n\nFormToggle.propTypes = {\n  className: PropTypes.string,\n  density: DENSITY,\n  label: PropTypes.string,\n  labelTip: PropTypes.string,\n  name: PropTypes.string.isRequired,\n  readOnly: PropTypes.bool,\n  onChange: PropTypes.func\n}\n\nexport default FormToggle\n"],"names":["FormToggle","className","density","label","labelTip","name","readOnly","onChange","inputProps","formFieldClassNames","classnames","jsx","Field","input","jsxs","Tip","event","PropTypes","DENSITY"],"mappings":";;;;;;;;AA0BA,MAAMA,IAAa,CAAC;AAAA,EAClB,WAAAC,IAAY;AAAA,EACZ,SAAAC,IAAU;AAAA,EACV,OAAAC,IAAQ;AAAA,EACR,UAAAC,IAAW;AAAA,EACX,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW,MAAM;AAAA,EAAC;AAAA,EAClB,GAAGC;AACL,MAAM;AACJ,QAAMC,IAAsBC;AAAA,IAC1B;AAAA,IACA;AAAA,IACAR,KAAW,uBAAuBA,CAAO;AAAA,KACxCC,KAASC,MAAa;AAAA,IACvBH;AAAA,EAAA;AAGF,SACE,gBAAAU,EAACC,GAAA,EAAM,MAAAP,GAAY,OAAOG,EAAW,OAAO,MAAK,YAC9C,UAAA,CAAC,EAAE,OAAAK,EAAA,MACF,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWL;AAAA,MACX,eAAaJ,IAAO,GAAGA,CAAI,uBAAuB;AAAA,MAEhD,UAAA;AAAA,SAAAF,KAASC,MACT,gBAAAU,EAAC,SAAA,EAAM,SAAST,GAAM,WAAU,4BAC7B,UAAA;AAAA,UAAAF;AAAA,UACAC,KAAY,gBAAAO,EAACI,GAAA,EAAI,MAAMX,EAAA,CAAU;AAAA,QAAA,GACpC;AAAA,QAEF,gBAAAU,EAAC,SAAA,EAAM,SAAST,GAAM,WAAU,qCAC9B,UAAA;AAAA,UAAA,gBAA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