PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.0.2
Tableberg – Simple Gutenberg Table Block v0.0.2
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 0.5.7 0.5.8 All 41 releases
tableberg / src / get-styles.ts

get-styles.ts in Tableberg – Simple Gutenberg Table Block 0.0.2, at src/get-styles.ts

63 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 //@ts-ignore
2 import { omitBy, isUndefined, trim, isEmpty, isNumber } from "lodash";
3 import { getBorderVariablesCss, getSpacingCss } from "./utils/styling-helpers";
4 import { PaddingTypes, TablebergBlockAttrs } from "./types";
5
6 export function getStyles(attributes: TablebergBlockAttrs) {
7 const {
8 cellPadding,
9 enableInnerBorder,
10 evenRowBackgroundColor,
11 innerBorder,
12 headerBackgroundColor,
13 oddRowBackgroundColor,
14 tableBorder,
15 headerBackgroundGradient,
16 evenRowBackgroundGradient,
17 oddRowBackgroundGradient,
18 tableWidth,
19 footerBackgroundColor,
20 footerBackgroundGradient,
21 enableTableFooter,
22 tableAlignment,
23 enableTableHeader,
24 } = attributes;
25 const cellPaddingCSS: PaddingTypes = getSpacingCss(cellPadding);
26 const tableBorderVar = getBorderVariablesCss(tableBorder, "table");
27 const tableInnerBorder = enableInnerBorder
28 ? getBorderVariablesCss(innerBorder, "inner")
29 : {};
30
31 let styles = {
32 "--tableber-table-width": tableWidth,
33 "--tableberg-footer-bg-color": !isEmpty(footerBackgroundColor)
34 ? footerBackgroundColor
35 : footerBackgroundGradient,
36 "--tableberg-header-bg-color": !isEmpty(headerBackgroundColor)
37 ? headerBackgroundColor
38 : headerBackgroundGradient,
39 "--tableberg-even-row-bg-color": !isEmpty(evenRowBackgroundColor)
40 ? evenRowBackgroundColor
41 : evenRowBackgroundGradient,
42 "--tableberg-odd-row-bg-color": !isEmpty(oddRowBackgroundColor)
43 ? oddRowBackgroundColor
44 : oddRowBackgroundGradient,
45 "--tableberg-cell-padding-top": cellPaddingCSS?.top,
46 "--tableberg-cell-padding-right": cellPaddingCSS?.right,
47 "--tableberg-cell-padding-bottom": cellPaddingCSS?.bottom,
48 "--tableberg-cell-padding-left": cellPaddingCSS?.left,
49 ...tableBorderVar,
50 ...tableInnerBorder,
51 };
52
53 return omitBy(
54 styles,
55 (value: any) =>
56 value === false ||
57 isEmpty(value) ||
58 isUndefined(value) ||
59 trim(value) === "" ||
60 trim(value) === "undefined undefined undefined"
61 );
62 }
63