@wordpress/block-editor
Version:
64 lines (63 loc) • 1.94 kB
JavaScript
// packages/block-editor/src/components/font-family/index.js
import clsx from "clsx";
import { CustomSelectControl } from "@wordpress/components";
import deprecated from "@wordpress/deprecated";
import { __ } from "@wordpress/i18n";
import { useSettings } from "../use-settings";
import { jsx } from "react/jsx-runtime";
function FontFamilyControl({
/** Start opting into the larger default height that will become the default size in a future version. */
__next40pxDefaultSize = false,
value = "",
onChange,
fontFamilies,
className,
...props
}) {
const [blockLevelFontFamilies] = useSettings("typography.fontFamilies");
if (!fontFamilies) {
fontFamilies = blockLevelFontFamilies;
}
if (!fontFamilies || fontFamilies.length === 0) {
return null;
}
const options = [
{
key: "",
name: __("Default")
},
...fontFamilies.map(({ fontFamily, name }) => ({
key: fontFamily,
name: name || fontFamily,
style: { fontFamily }
}))
];
if (!__next40pxDefaultSize && (props.size === void 0 || props.size === "default")) {
deprecated(
`36px default size for wp.blockEditor.__experimentalFontFamilyControl`,
{
since: "6.8",
version: "7.1",
hint: "Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version."
}
);
}
const selectedValue = options.find((option) => option.key === value) ?? "";
return /* @__PURE__ */ jsx(
CustomSelectControl,
{
__next40pxDefaultSize,
__shouldNotWarnDeprecated36pxSize: true,
label: __("Font"),
value: selectedValue,
onChange: ({ selectedItem }) => onChange(selectedItem.key),
options,
className: clsx("block-editor-font-family-control", className),
...props
}
);
}
export {
FontFamilyControl as default
};
//# sourceMappingURL=index.js.map