@wordpress/components
Version:
UI components for WordPress.
1 lines • 2.68 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/text-control/index.tsx"],"sourcesContent":["import type { ChangeEvent, ForwardedRef } from 'react';\nimport { useInstanceId } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\nimport BaseControl from '../base-control';\nimport type { WordPressComponentProps } from '../context';\nimport type { TextControlProps } from './types';\n\nfunction UnforwardedTextControl(\n\tprops: WordPressComponentProps< TextControlProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\t// Prevent passing legacy props to `input`.\n\t\t__nextHasNoMarginBottom: _,\n\t\t__next40pxDefaultSize: __,\n\t\tlabel,\n\t\thideLabelFromVision,\n\t\tvalue,\n\t\thelp,\n\t\tid: idProp,\n\t\tclassName,\n\t\tonChange,\n\t\ttype = 'text',\n\t\t...additionalProps\n\t} = props;\n\tconst id = useInstanceId( TextControl, 'inspector-text-control', idProp );\n\tconst onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>\n\t\tonChange( event.target.value );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tlabel={ label }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tid={ id }\n\t\t\thelp={ help }\n\t\t\tclassName={ className }\n\t\t>\n\t\t\t<input\n\t\t\t\tclassName=\"components-text-control__input\"\n\t\t\t\ttype={ type }\n\t\t\t\tid={ id }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChangeValue }\n\t\t\t\taria-describedby={ !! help ? id + '__help' : undefined }\n\t\t\t\tref={ ref }\n\t\t\t\t{ ...additionalProps }\n\t\t\t/>\n\t\t</BaseControl>\n\t);\n}\n\n/**\n * TextControl components let users enter and edit text.\n *\n * ```jsx\n * import { TextControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTextControl = () => {\n * const [ className, setClassName ] = useState( '' );\n *\n * return (\n * <TextControl\n * label=\"Additional CSS Class\"\n * value={ className }\n * onChange={ ( value ) => setClassName( value ) }\n * />\n * );\n * };\n * ```\n */\nexport const TextControl = forwardRef( UnforwardedTextControl );\nTextControl.displayName = 'TextControl';\n\nexport default TextControl;\n"],"mappings":";;;;;AAOA,SAAS,uBACR,OACA,KACC;CACD,MAAM,EAEL,yBAAyB,GACzB,uBAAuB,IACvB,OACA,qBACA,OACA,MACA,IAAI,QACJ,WACA,UACA,OAAO,QACP,GAAG,oBACA;CACJ,MAAM,KAAK,cAAe,aAAa,0BAA0B,MAAO;CACxE,MAAM,iBAAkB,UACvB,SAAU,MAAM,OAAO,KAAM;CAE9B,OACC,oBAAC,aAAD;EACS;EACc;EACjB;EACE;EACK;EAEZ,UAAA,oBAAC,SAAD;GACC,WAAU;GACH;GACF;GACG;GACR,UAAW;GACX,oBAAmB,CAAC,CAAE,OAAO,KAAK,WAAW,KAAA;GACvC;GACN,GAAK;EACL,CAAA;CACW,CAAA;AAEf;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,cAAc,WAAY,sBAAuB;AAC9D,YAAY,cAAc"}