PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.2.0
Tableberg – Simple Gutenberg Table Block v1.2.0
1.2.0 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 All 43 releases
tableberg / components / editor / FontAppearanceControl.tsx

FontAppearanceControl.tsx in Tableberg – Simple Gutenberg Table Block 1.2.0, at components/editor/FontAppearanceControl.tsx

70 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from "@wordpress/i18n";
2 import { __experimentalFontAppearanceControl as WPFontAppearanceControl } from "@wordpress/block-editor";
3
4 import TypographyPanelItem from "./TypographyPanelItem";
5 import { useFontFamilies } from "./FontFamilyControl";
6
7 export interface FontAppearance {
8 fontStyle: string;
9 fontWeight: string;
10 }
11
12 interface Props {
13 label?: string;
14 value: FontAppearance;
15 onChange: (newValue: FontAppearance) => void;
16 /** The font the appearance belongs to, so its own faces are offered. */
17 fontFamily?: string;
18 onDeselect?: () => void;
19 resetAllFilter?: () => void;
20 isShownByDefault?: boolean;
21 isSingleColumn?: boolean;
22 panelId?: string;
23 }
24
25 const noAppearance: FontAppearance = { fontStyle: "", fontWeight: "" };
26
27 export default function FontAppearanceControl({
28 label = __("Appearance", "tableberg"),
29 value,
30 onChange,
31 fontFamily,
32 onDeselect,
33 resetAllFilter,
34 isShownByDefault = false,
35 isSingleColumn = true,
36 panelId,
37 }: Props) {
38 const fontFamilies = useFontFamilies();
39 const fontFamilyFaces =
40 fontFamilies.find(family => family.fontFamily === fontFamily)
41 ?.fontFace ?? [];
42
43 return (
44 <TypographyPanelItem
45 label={label}
46 hasValue={() => !!value.fontStyle || !!value.fontWeight}
47 onDeselect={onDeselect ?? (() => onChange({ ...noAppearance }))}
48 resetAllFilter={resetAllFilter}
49 isShownByDefault={isShownByDefault}
50 isSingleColumn={isSingleColumn}
51 panelId={panelId}
52 >
53 <WPFontAppearanceControl
54 __next40pxDefaultSize
55 fontFamilyFaces={fontFamilyFaces}
56 value={{
57 fontStyle: value.fontStyle || undefined,
58 fontWeight: value.fontWeight || undefined,
59 }}
60 onChange={newValue =>
61 onChange({
62 fontStyle: newValue?.fontStyle || "",
63 fontWeight: newValue?.fontWeight || "",
64 })
65 }
66 />
67 </TypographyPanelItem>
68 );
69 }
70