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 / shared / utils / typography.ts

typography.ts in Tableberg – Simple Gutenberg Table Block 1.2.0, at shared/utils/typography.ts

65 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { StyleAttr } from "./styling-helpers";
2
3 /**
4 * The typography options a block can offer, the same set the core blocks do.
5 * Plain CSS values, so they can be dropped straight into a style attribute.
6 */
7 export interface TypographyValue {
8 fontFamily: string;
9 fontSize: string;
10 fontStyle: string;
11 fontWeight: string;
12 lineHeight: string;
13 letterSpacing: string;
14 textDecoration: string;
15 textTransform: string;
16 }
17
18 export const defaultTypography: TypographyValue = {
19 fontFamily: "",
20 fontSize: "",
21 fontStyle: "",
22 fontWeight: "",
23 lineHeight: "",
24 letterSpacing: "",
25 textDecoration: "",
26 textTransform: "",
27 };
28
29 /** Fills in the missing properties of a stored (partial) typography value. */
30 export function getTypography(
31 typography?: Partial<TypographyValue>
32 ): TypographyValue {
33 return { ...defaultTypography, ...(typography || {}) };
34 }
35
36 /**
37 * Typography as inline styles. Empty values are left out so the theme keeps
38 * deciding until the user picks something.
39 */
40 export function getTypographyCss(
41 typography?: Partial<TypographyValue>
42 ): StyleAttr {
43 const {
44 fontFamily,
45 fontSize,
46 fontStyle,
47 fontWeight,
48 lineHeight,
49 letterSpacing,
50 textDecoration,
51 textTransform,
52 } = getTypography(typography);
53
54 return {
55 fontFamily: fontFamily || undefined,
56 fontSize: fontSize || undefined,
57 fontStyle: fontStyle || undefined,
58 fontWeight: fontWeight || undefined,
59 lineHeight: lineHeight || undefined,
60 letterSpacing: letterSpacing || undefined,
61 textDecoration: textDecoration || undefined,
62 textTransform: (textTransform as StyleAttr["textTransform"]) || undefined,
63 };
64 }
65