@wordpress/components
Version:
UI components for WordPress.
77 lines (69 loc) • 1.82 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import BaseControl from '../base-control';
function UnforwardedTextControl(props, ref) {
const {
__nextHasNoMarginBottom,
label,
hideLabelFromVision,
value,
help,
className,
onChange,
type = 'text',
...additionalProps
} = props;
const instanceId = useInstanceId(TextControl);
const id = `inspector-text-control-${instanceId}`;
const onChangeValue = event => onChange(event.target.value);
return createElement(BaseControl, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
label: label,
hideLabelFromVision: hideLabelFromVision,
id: id,
help: help,
className: className
}, createElement("input", _extends({
className: "components-text-control__input",
type: type,
id: id,
value: value,
onChange: onChangeValue,
"aria-describedby": !!help ? id + '__help' : undefined,
ref: ref
}, additionalProps)));
}
/**
* TextControl components let users enter and edit text.
*
* ```jsx
* import { TextControl } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const MyTextControl = () => {
* const [ className, setClassName ] = useState( '' );
*
* return (
* <TextControl
* label="Additional CSS Class"
* value={ className }
* onChange={ ( value ) => setClassName( value ) }
* />
* );
* };
* ```
*/
export const TextControl = forwardRef(UnforwardedTextControl);
export default TextControl;
//# sourceMappingURL=index.js.map