@wordpress/components
Version:
UI components for WordPress.
87 lines (83 loc) • 2.22 kB
JavaScript
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import BaseControl from '../base-control';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';
import { jsx as _jsx } from "react/jsx-runtime";
function UnforwardedTextControl(props, ref) {
const {
__nextHasNoMarginBottom,
__next40pxDefaultSize = false,
label,
hideLabelFromVision,
value,
help,
id: idProp,
className,
onChange,
type = 'text',
...additionalProps
} = props;
const id = useInstanceId(TextControl, 'inspector-text-control', idProp);
const onChangeValue = event => onChange(event.target.value);
maybeWarnDeprecated36pxSize({
componentName: 'TextControl',
size: undefined,
__next40pxDefaultSize
});
return /*#__PURE__*/_jsx(BaseControl, {
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
__associatedWPComponentName: "TextControl",
label: label,
hideLabelFromVision: hideLabelFromVision,
id: id,
help: help,
className: className,
children: /*#__PURE__*/_jsx("input", {
className: clsx('components-text-control__input', {
'is-next-40px-default-size': __next40pxDefaultSize
}),
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
* __nextHasNoMarginBottom
* __next40pxDefaultSize
* label="Additional CSS Class"
* value={ className }
* onChange={ ( value ) => setClassName( value ) }
* />
* );
* };
* ```
*/
export const TextControl = forwardRef(UnforwardedTextControl);
export default TextControl;
//# sourceMappingURL=index.js.map