PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
content-blocks-builder / src / features / grid / deprecated.js

deprecated.js in Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts trunk, at src/features/grid/deprecated.js

107 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External depencencies
3 */
4 import { isEmpty, isObject, isString, isUndefined } from "lodash";
5
6 /**
7 * Internal dependencies
8 */
9 import { isUnsetValue } from "sdk/utils";
10
11 /**
12 * Get gap style
13 *
14 * @param {Object} gap : ;
15 * @returns {Object}
16 */
17 export function getGridGapStyleDeprecatedV1(gap) {
18 let gapStyle = {};
19 Object.keys(gap).forEach((breakpoint) => {
20 const { value: { row, column } = {}, inherit } = gap[breakpoint];
21 if (isUndefined(row) && isUndefined(column)) {
22 if (inherit && isString(inherit)) {
23 gapStyle = {
24 ...gapStyle,
25 [`--bb--grid--gap--row--${breakpoint}`]: `var(--bb--grid--gap--row--${inherit})`,
26 [`--bb--grid--gap--column--${breakpoint}`]: `var(--bb--grid--gap--column--${inherit})`,
27 };
28 }
29 } else {
30 if (!isUndefined(row)) {
31 gapStyle = {
32 ...gapStyle,
33 [`--bb--grid--gap--row--${breakpoint}`]: row,
34 };
35 }
36 if (!isUndefined(column)) {
37 gapStyle = {
38 ...gapStyle,
39 [`--bb--grid--gap--column--${breakpoint}`]: column,
40 };
41 }
42 }
43 });
44
45 return gapStyle;
46 }
47
48 /**
49 * Build style for grid column / grid row.
50 *
51 * @param {Object} gridItem
52 * @param {String} prefix
53 * @param {Boolean} hasOrder
54 */
55 export function getSpanStylesDeprecatedV1(gridItem, prefix, hasOrder = false) {
56 let gridItemStyle = {};
57 if (isObject(gridItem) && !isEmpty(gridItem)) {
58 Object.keys(gridItem).forEach((breakpoint) => {
59 let { value: { start, span, order } = {}, inherit } =
60 gridItem[breakpoint] ?? {};
61 if (isUnsetValue(start) && isUnsetValue(span) && isUnsetValue(order)) {
62 if (inherit && isString(inherit)) {
63 gridItemStyle = {
64 ...gridItemStyle,
65 [`${prefix}${breakpoint}`]: `var(${prefix}${inherit})`,
66 };
67
68 if (hasOrder) {
69 gridItemStyle = {
70 ...gridItemStyle,
71 [`--bb--grid-item--order--${breakpoint}`]: `var(--bb--grid-item--order--${inherit})`,
72 };
73 }
74 }
75 } else {
76 if (start || span) {
77 if (isUnsetValue(start)) {
78 start = "auto";
79 }
80
81 if (isUnsetValue(span)) {
82 span = "auto";
83 }
84 if (span !== "auto" && span > 0) {
85 // Ignore auto and -1 value
86 span = `span ${span}`;
87 }
88
89 gridItemStyle = {
90 ...gridItemStyle,
91 [`${prefix}${breakpoint}`]: `${start} / ${span}`,
92 };
93 }
94
95 if (hasOrder && order && order !== "auto") {
96 gridItemStyle = {
97 ...gridItemStyle,
98 [`--bb--grid-item--order--${breakpoint}`]: order + "",
99 };
100 }
101 }
102 });
103 }
104
105 return gridItemStyle;
106 }
107