@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
40 lines (39 loc) • 1.64 kB
JavaScript
import { _n, isRTL, sprintf } from "@wordpress/i18n";
import { useEffect, useRef } from "@wordpress/element";
import { Button, Flex, FlexItem, __experimentalText, useNavigator } from "@wordpress/components";
import { Icon, chevronLeft, chevronRight } from "@wordpress/icons";
import FontDemo from "./font-demo.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/global-styles-ui/src/font-library/font-card.tsx
function FontCard({ font, onClick, variantsText, navigatorPath, shouldFocus }) {
const variantsCount = font.fontFace?.length || 1;
const style = { cursor: !!onClick ? "pointer" : "default" };
const navigator = useNavigator();
const ref = useRef(null);
useEffect(() => {
if (shouldFocus) ref.current?.focus();
}, [shouldFocus]);
return /* @__PURE__ */ jsx(Button, {
ref,
__next40pxDefaultSize: true,
onClick: () => {
onClick();
if (navigatorPath) navigator.goTo(navigatorPath);
},
style,
className: "font-library__font-card",
children: /* @__PURE__ */ jsxs(Flex, {
justify: "space-between",
wrap: false,
children: [/* @__PURE__ */ jsx(FontDemo, { font }), /* @__PURE__ */ jsxs(Flex, {
justify: "flex-end",
children: [/* @__PURE__ */ jsx(FlexItem, { children: /* @__PURE__ */ jsx(__experimentalText, {
className: "font-library__font-card__count",
children: variantsText || sprintf(_n("%d variant", "%d variants", variantsCount), variantsCount)
}) }), /* @__PURE__ */ jsx(FlexItem, { children: /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? chevronLeft : chevronRight }) })]
})]
})
});
}
export { FontCard as default };
//# sourceMappingURL=font-card.mjs.map