@wordpress/components
Version:
UI components for WordPress.
27 lines (26 loc) • 757 B
JavaScript
import { useInstanceId } from "@wordpress/compose";
// packages/components/src/base-control/hooks.ts
/**
* Generate props for the `BaseControl` and the inner control itself.
*
* Namely, it takes care of generating a unique `id`, properly associating it with the `label` and `help` elements.
*
* @param props
*/
function useBaseControlProps(props) {
const { help, id: preferredId, ...restProps } = props;
const uniqueId = useInstanceId(useBaseControlProps, "wp-components-base-control", preferredId);
return {
baseControlProps: {
id: uniqueId,
help,
...restProps
},
controlProps: {
id: uniqueId,
...!!help ? { "aria-describedby": `${uniqueId}__help` } : {}
}
};
}
export { useBaseControlProps };
//# sourceMappingURL=hooks.mjs.map