{"version":3,"file":"index.cjs","names":["useInstanceId","BaseControl","HStack","FormToggle","FlexBlock","forwardRef"],"sources":["../../src/toggle-control/index.tsx"],"sourcesContent":["import type { ChangeEvent, ForwardedRef } from 'react';\nimport clsx from 'clsx';\nimport { forwardRef } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { FlexBlock } from '../flex';\nimport FormToggle from '../form-toggle';\nimport BaseControl from '../base-control';\nimport type { WordPressComponentProps } from '../context/wordpress-component';\nimport type { ToggleControlProps } from './types';\nimport { HStack } from '../h-stack';\n\nfunction UnforwardedToggleControl(\n\t{\n\t\tlabel,\n\t\tchecked,\n\t\thelp,\n\t\tclassName,\n\t\tonChange,\n\t\tdisabled,\n\t\t// Prevent passing to internal component.\n\t\t__nextHasNoMarginBottom: _,\n\t\t...additionalProps\n\t}: WordPressComponentProps< ToggleControlProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tfunction onChangeToggle( event: ChangeEvent< HTMLInputElement > ) {\n\t\tonChange( event.target.checked );\n\t}\n\tconst instanceId = useInstanceId( ToggleControl );\n\tconst id = `inspector-toggle-control-${ instanceId }`;\n\n\tlet describedBy, helpLabel;\n\tif ( help ) {\n\t\tif ( typeof help === 'function' ) {\n\t\t\t// `help` as a function works only for controlled components where\n\t\t\t// `checked` is passed down from parent component. Uncontrolled\n\t\t\t// component can show only a static help label.\n\t\t\tif ( checked !== undefined ) {\n\t\t\t\thelpLabel = help( checked );\n\t\t\t}\n\t\t} else {\n\t\t\thelpLabel = help;\n\t\t}\n\t\tif ( helpLabel ) {\n\t\t\tdescribedBy = id + '__help';\n\t\t}\n\t}\n\n\treturn (\n\t\t<BaseControl\n\t\t\tid={ id }\n\t\t\thelp={\n\t\t\t\thelpLabel && (\n\t\t\t\t\t<span className=\"components-toggle-control__help\">\n\t\t\t\t\t\t{ helpLabel }\n\t\t\t\t\t</span>\n\t\t\t\t)\n\t\t\t}\n\t\t\tclassName={ clsx( 'components-toggle-control', className ) }\n\t\t>\n\t\t\t<HStack justify=\"flex-start\" spacing={ 2 }>\n\t\t\t\t<FormToggle\n\t\t\t\t\tid={ id }\n\t\t\t\t\tchecked={ checked }\n\t\t\t\t\tonChange={ onChangeToggle }\n\t\t\t\t\taria-describedby={ describedBy }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\tref={ ref }\n\t\t\t\t\t{ ...additionalProps }\n\t\t\t\t/>\n\t\t\t\t<FlexBlock\n\t\t\t\t\tas=\"label\"\n\t\t\t\t\thtmlFor={ id }\n\t\t\t\t\tclassName={ clsx( 'components-toggle-control__label', {\n\t\t\t\t\t\t'is-disabled': disabled,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t</FlexBlock>\n\t\t\t</HStack>\n\t\t</BaseControl>\n\t);\n}\n\n/**\n * ToggleControl is used to generate a toggle user interface.\n *\n * ```jsx\n * import { ToggleControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyToggleControl = () => {\n *   const [ value, setValue ] = useState( false );\n *\n *   return (\n *     <ToggleControl\n *       label=\"Fixed Background\"\n *       checked={ value }\n *       onChange={ () => setValue( ( state ) => ! state ) }\n *     />\n *   );\n * };\n * ```\n */\nexport const ToggleControl = forwardRef( UnforwardedToggleControl );\nToggleControl.displayName = 'ToggleControl';\n\nexport default ToggleControl;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,SAAS,yBACR,EACC,OACA,SACA,MACA,WACA,UACA,UAEA,yBAAyB,GACzB,GAAG,mBAEJ,KACC;CACD,SAAS,eAAgB,OAAyC;EACjE,SAAU,MAAM,OAAO,OAAQ;CAChC;CAEA,MAAM,KAAK,6BAAA,GADQA,mBAAAA,cAAAA,CAAe,aACe;CAEjD,IAAI,aAAa;CACjB,IAAK,MAAO;EACX,IAAK,OAAO,SAAS,YAIf;OAAA,YAAY,KAAA,GAChB,YAAY,KAAM,OAAQ;EAAA,OAG3B,YAAY;EAEb,IAAK,WACJ,cAAc,KAAK;CAErB;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,0BAAAA,SAAD;EACM;EACL,MACC,aACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,WAAU;GACb,UAAA;EACG,CAAA;EAGR,YAAA,GAAY,KAAA,QAAA,CAAM,6BAA6B,SAAU;EAEzD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,oBAAAA,QAAD;GAAQ,SAAQ;GAAa,SAAU;GAAvC,UAAA,CACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,yBAAAA,SAAD;IACM;IACK;IACV,UAAW;IACX,oBAAmB;IACR;IACL;IACN,GAAK;GACL,CAAA,GACD,iBAAA,GAAA,kBAAA,IAAA,CAACC,iBAAAA,WAAD;IACC,IAAG;IACH,SAAU;IACV,YAAA,GAAY,KAAA,QAAA,CAAM,oCAAoC,EACrD,eAAe,SAChB,CAAE;IAEA,UAAA;GACQ,CAAA,CACJ;;CACI,CAAA;AAEf;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,iBAAA,GAAgBC,mBAAAA,WAAAA,CAAY,wBAAyB;AAClE,cAAc,cAAc"}