@wordpress/components
Version:
UI components for WordPress.
52 lines (51 loc) • 1.59 kB
JavaScript
import { useInstanceId } from "@wordpress/compose";
import { forwardRef } from "@wordpress/element";
import BaseControl from "../base-control/index.mjs";
import { jsx } from "react/jsx-runtime";
// packages/components/src/text-control/index.tsx
function UnforwardedTextControl(props, ref) {
const { __nextHasNoMarginBottom: _, __next40pxDefaultSize: __, 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);
return /* @__PURE__ */ jsx(BaseControl, {
label,
hideLabelFromVision,
id,
help,
className,
children: /* @__PURE__ */ jsx("input", {
className: "components-text-control__input",
type,
id,
value,
onChange: onChangeValue,
"aria-describedby": !!help ? id + "__help" : void 0,
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 ) }
* />
* );
* };
* ```
*/
const TextControl = forwardRef(UnforwardedTextControl);
TextControl.displayName = "TextControl";
export { TextControl, TextControl as default };
//# sourceMappingURL=index.mjs.map