boxwood 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/ui/grid/index.js +9 -4
- package/ui/normalize.js +32 -17
package/package.json
CHANGED
package/ui/grid/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { component, css, Div } = require("../..")
|
|
2
2
|
const { normalizeGap, normalizeBreakpoint } = require("../normalize")
|
|
3
|
+
const { toNumber } = require("../normalize")
|
|
3
4
|
|
|
4
5
|
const BREAKPOINTS = {
|
|
5
6
|
xl: "1199px",
|
|
@@ -15,6 +16,9 @@ function Grid(
|
|
|
15
16
|
gap = normalizeGap(gap)
|
|
16
17
|
breakpoint = normalizeBreakpoint(breakpoint)
|
|
17
18
|
|
|
19
|
+
// Normalize columns: convert string numbers to numbers
|
|
20
|
+
columns = toNumber(columns)
|
|
21
|
+
|
|
18
22
|
const styleObject = {
|
|
19
23
|
"box-sizing": "border-box",
|
|
20
24
|
display: "grid",
|
|
@@ -27,10 +31,11 @@ function Grid(
|
|
|
27
31
|
}),
|
|
28
32
|
...(typeof columns === "object" &&
|
|
29
33
|
Object.keys(columns).reduce((object, key) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
let value = toNumber(columns[key])
|
|
35
|
+
value =
|
|
36
|
+
typeof value === "number"
|
|
37
|
+
? `repeat(${value}, 1fr)`
|
|
38
|
+
: value
|
|
34
39
|
if (key === "default") {
|
|
35
40
|
object["grid-template-columns"] = value
|
|
36
41
|
} else if (typeof key === "string") {
|
package/ui/normalize.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts string numbers to integers
|
|
3
|
+
* @param {string|number} value - The value to convert
|
|
4
|
+
* @returns {number|string} - Integer if string is numeric, otherwise original value
|
|
5
|
+
*/
|
|
6
|
+
function toNumber(value) {
|
|
7
|
+
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
8
|
+
return parseInt(value, 10)
|
|
9
|
+
}
|
|
10
|
+
return value
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts number or string number to pixel value
|
|
15
|
+
* @param {string|number} value - The value to convert
|
|
16
|
+
* @returns {string|number} - Value with px suffix if numeric, otherwise original value
|
|
17
|
+
*/
|
|
18
|
+
function toPixels(value) {
|
|
19
|
+
value = toNumber(value)
|
|
20
|
+
if (typeof value === "number") {
|
|
21
|
+
return `${value}px`
|
|
22
|
+
}
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
|
|
1
26
|
function normalizeFlex(align) {
|
|
2
27
|
switch (align) {
|
|
3
28
|
case "start":
|
|
@@ -22,15 +47,12 @@ function normalizeGap(gap) {
|
|
|
22
47
|
if (!gap) {
|
|
23
48
|
return "1rem"
|
|
24
49
|
}
|
|
25
|
-
|
|
26
|
-
return `${gap}px`
|
|
27
|
-
}
|
|
28
|
-
|
|
50
|
+
|
|
29
51
|
if (GAP_MAP.hasOwnProperty(gap)) {
|
|
30
52
|
return GAP_MAP[gap]
|
|
31
53
|
}
|
|
32
54
|
|
|
33
|
-
return gap
|
|
55
|
+
return toPixels(gap)
|
|
34
56
|
}
|
|
35
57
|
|
|
36
58
|
const BREAKPOINT_MAP = {
|
|
@@ -42,20 +64,14 @@ const BREAKPOINT_MAP = {
|
|
|
42
64
|
}
|
|
43
65
|
|
|
44
66
|
function normalizeBreakpoint(breakpoint) {
|
|
45
|
-
if (typeof breakpoint === "number") {
|
|
46
|
-
return `${breakpoint}px`
|
|
47
|
-
}
|
|
48
67
|
if (BREAKPOINT_MAP.hasOwnProperty(breakpoint)) {
|
|
49
68
|
return BREAKPOINT_MAP[breakpoint]
|
|
50
69
|
}
|
|
51
|
-
return breakpoint
|
|
70
|
+
return toPixels(breakpoint)
|
|
52
71
|
}
|
|
53
72
|
|
|
54
73
|
function normalizeWidth(width) {
|
|
55
|
-
|
|
56
|
-
return `${width}px`
|
|
57
|
-
}
|
|
58
|
-
return width
|
|
74
|
+
return toPixels(width)
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
const SPACING_MAP = {
|
|
@@ -68,16 +84,15 @@ const SPACING_MAP = {
|
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
function normalizeSpacing(spacing) {
|
|
71
|
-
if (typeof spacing === "number") {
|
|
72
|
-
return `${spacing}px`
|
|
73
|
-
}
|
|
74
87
|
if (SPACING_MAP.hasOwnProperty(spacing)) {
|
|
75
88
|
return SPACING_MAP[spacing]
|
|
76
89
|
}
|
|
77
|
-
return spacing
|
|
90
|
+
return toPixels(spacing)
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
module.exports = {
|
|
94
|
+
toNumber,
|
|
95
|
+
toPixels,
|
|
81
96
|
normalizeFlex,
|
|
82
97
|
normalizeGap,
|
|
83
98
|
normalizeBreakpoint,
|