PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / gutenberg / util / helpers / responsiveRangeHelpers.js

responsiveRangeHelpers.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/gutenberg/util/helpers/responsiveRangeHelpers.js

107 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // function to generate responsive range controller attributes for multiple range control based on the array of prefix
2 export const generateResponsiveRangeAttributes = (
3 controlName,
4 defaults = {}
5 ) => {
6 const { defaultRange, noUnits, defaultUnit = "px" } = defaults;
7 const desktop = defaultRange
8 ? {
9 [`${controlName}Range`]: {
10 type: "number",
11 default: defaultRange,
12 },
13 }
14 : {
15 [`${controlName}Range`]: {
16 type: "number",
17 },
18 };
19
20 const units =
21 noUnits === true
22 ? {}
23 : {
24 [`${controlName}Unit`]: {
25 type: "string",
26 default: defaultUnit,
27 },
28 [`TAB${controlName}Unit`]: {
29 type: "string",
30 default: "px",
31 },
32 [`MOB${controlName}Unit`]: {
33 type: "string",
34 default: "px",
35 },
36 };
37
38 return {
39 ...desktop,
40 [`TAB${controlName}Range`]: {
41 type: "number",
42 },
43
44 [`MOB${controlName}Range`]: {
45 type: "number",
46 },
47 ...units,
48 };
49 };
50
51 // function to generate responsive range control styles for an element based on it's prefix
52 export const generateResponsiveRangeStyles = ({
53 controlName,
54 property,
55 attributes,
56 customUnit,
57 }) => {
58 let desktopSizeUnit;
59 let TABsizeUnit;
60 let MOBsizeUnit;
61
62 if (!customUnit) {
63 desktopSizeUnit = attributes[`${controlName}Unit`];
64 TABsizeUnit = attributes[`TAB${controlName}Unit`];
65 MOBsizeUnit = attributes[`MOB${controlName}Unit`];
66 } else {
67 desktopSizeUnit = TABsizeUnit = MOBsizeUnit = customUnit;
68 }
69
70 const {
71 [`${controlName}Range`]: desktopRange,
72 [`TAB${controlName}Range`]: TABrange,
73 [`MOB${controlName}Range`]: MOBrange,
74 } = attributes;
75
76 const rangeStylesDesktop =
77 desktopRange || desktopRange === 0
78 ? property +
79 ":" +
80 (desktopSizeUnit !== "px" && desktopRange > 100 ? 100 : desktopRange) +
81 (customUnit || desktopSizeUnit) +
82 ";"
83 : "";
84 const rangeStylesTab =
85 TABrange || TABrange === 0
86 ? property +
87 ":" +
88 (TABsizeUnit !== "px" && TABrange > 100 ? 100 : TABrange) +
89 (customUnit || TABsizeUnit) +
90 ";"
91 : "";
92 const rangeStylesMobile =
93 MOBrange || MOBrange === 0
94 ? property +
95 ":" +
96 (MOBsizeUnit !== "px" && MOBrange > 100 ? 100 : MOBrange) +
97 (customUnit || MOBsizeUnit) +
98 ";"
99 : "";
100
101 return {
102 rangeStylesDesktop,
103 rangeStylesTab,
104 rangeStylesMobile,
105 };
106 };
107