@wordpress/components
Version:
UI components for WordPress.
116 lines (115 loc) • 4.29 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_compose = require("@wordpress/compose");
let _wordpress_element = require("@wordpress/element");
let __input_base_tsx = require("./input-base.cjs");
__input_base_tsx = __toESM(__input_base_tsx);
let __input_field_tsx = require("./input-field.cjs");
__input_field_tsx = __toESM(__input_field_tsx);
let __utils_ts = require("./utils.cjs");
let ___base_control_index_tsx = require("../base-control/index.cjs");
___base_control_index_tsx = __toESM(___base_control_index_tsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/input-control/index.tsx
const noop = () => {};
function useUniqueId(idProp) {
const id = `inspector-input-control-${(0, _wordpress_compose.useInstanceId)(InputControl)}`;
return idProp || id;
}
function UnforwardedInputControl(props, ref) {
const { __next40pxDefaultSize: _next40pxDefaultSize, __next36pxDefaultSize: _next36pxDefaultSize, __unstableStateReducer: stateReducer = (state) => state, __unstableInputWidth, className, disabled = false, help, hideLabelFromVision = false, id: idProp, isPressEnterToChange = false, label, labelPosition = "top", onChange = noop, onValidate = noop, onKeyDown = noop, prefix, size = "default", style, suffix, value, ...restProps } = props;
const id = useUniqueId(idProp);
const classes = (0, clsx.default)("components-input-control", className);
const draftHookProps = (0, __utils_ts.useDraft)({
value,
onBlur: restProps.onBlur,
onChange
});
const helpProp = !!help ? { "aria-describedby": `${id}__help` } : {};
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___base_control_index_tsx.default, {
className: classes,
help,
id,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__input_base_tsx.default, {
__unstableInputWidth,
disabled,
gap: 3,
hideLabelFromVision,
id,
justify: "left",
label,
labelPosition,
prefix,
size,
style,
suffix,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__input_field_tsx.default, {
...restProps,
...helpProp,
className: "components-input-control__input",
disabled,
id,
isPressEnterToChange,
onKeyDown,
onValidate,
paddingInlineStart: prefix ? "var(--wpds-dimension-padding-xs, 4px)" : void 0,
paddingInlineEnd: suffix ? "var(--wpds-dimension-padding-xs, 4px)" : void 0,
ref,
size,
stateReducer,
...draftHookProps
})
})
});
}
/**
* InputControl components let users enter and edit text. This is an experimental component
* intended to (in time) merge with or replace `TextControl`.
*
* ```jsx
* import { __experimentalInputControl as InputControl } from '@wordpress/components';
* import { useState } from 'react';
*
* const Example = () => {
* const [ value, setValue ] = useState( '' );
*
* return (
* <InputControl
* value={ value }
* onChange={ ( nextValue ) => setValue( nextValue ?? '' ) }
* />
* );
* };
* ```
*/
const InputControl = (0, _wordpress_element.forwardRef)(UnforwardedInputControl);
exports.InputControl = InputControl;
exports.default = InputControl;
exports.UnforwardedInputControl = UnforwardedInputControl;
//# sourceMappingURL=index.cjs.map