boxwood 2.2.0 → 2.2.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "./ui": "./ui/index.js"
11
11
  },
12
12
  "scripts": {
13
- "test": "node --test --test-reporter=dot \"test/**/*.test.js\" \"test/**/*.spec.js\"",
14
- "test:debug": "node --test --test-reporter=spec \"test/**/*.test.js\" \"test/**/*.spec.js\"",
13
+ "test": "node --test --test-reporter=dot \"**/*.test.js\" \"**/*.spec.js\"",
14
+ "test:debug": "node --test --test-reporter=spec \"**/*.test.js\" \"**/*.spec.js\"",
15
15
  "coverage": "c8 npm test",
16
16
  "benchmark": "node --test benchmark/index.js",
17
17
  "watch": "npm test -- --watch",
@@ -0,0 +1,47 @@
1
+ const { css, component, Div } = require("../..")
2
+
3
+ const normalizeValue = (value) => {
4
+ if (typeof value === "string") {
5
+ if (value.endsWith("px")) {
6
+ return parseInt(value, 10)
7
+ }
8
+ if (value.endsWith("rem")) {
9
+ return parseInt(value, 10) * 16
10
+ }
11
+ throw new Error(
12
+ "Width must be a number or a string ending with 'px' or 'rem'"
13
+ )
14
+ }
15
+ return value
16
+ }
17
+
18
+ function Container(
19
+ { className, style, width = 1200, padding = 16 } = {},
20
+ children
21
+ ) {
22
+ width = normalizeValue(width)
23
+ padding = normalizeValue(padding)
24
+ const styles = css`
25
+ .container {
26
+ box-sizing: border-box;
27
+ margin-left: auto;
28
+ margin-right: auto;
29
+ max-width: ${width}px;
30
+ padding-left: ${padding}px;
31
+ padding-right: ${padding}px;
32
+ width: 100%;
33
+ }
34
+
35
+ @media (max-width: ${width + padding * 2 - 1}px) {
36
+ .container {
37
+ max-width: 100%;
38
+ }
39
+ }
40
+ `
41
+ return [
42
+ Div({ className: [styles.container, className], style }, children),
43
+ styles.css,
44
+ ]
45
+ }
46
+
47
+ module.exports = component(Container)
@@ -4,22 +4,31 @@ const {
4
4
  normalizeFlex,
5
5
  normalizeBreakpoint,
6
6
  normalizeWidth,
7
+ normalizeSpacing,
7
8
  } = require("../normalize")
8
9
 
9
- function Group({ align, breakpoint, justify, gap, width, style }, children) {
10
+ function Group(
11
+ { align, className, breakpoint, justify, gap, width, margin, padding, style },
12
+ children
13
+ ) {
10
14
  gap = normalizeGap(gap)
11
15
  align = normalizeFlex(align)
12
16
  justify = normalizeFlex(justify)
13
17
  breakpoint = normalizeBreakpoint(breakpoint)
14
18
  width = normalizeWidth(width)
19
+ margin = normalizeSpacing(margin)
20
+ padding = normalizeSpacing(padding)
15
21
 
16
22
  const styleObject = {
23
+ "box-sizing": "border-box",
17
24
  display: "flex",
18
25
  "flex-direction": "row",
19
26
  ...(gap && { gap }),
20
27
  ...(align && { "align-items": align }),
21
28
  ...(justify && { "justify-content": justify }),
22
29
  ...(width && { width }),
30
+ ...(margin && { margin }),
31
+ ...(padding && { padding }),
23
32
  ...(breakpoint && {
24
33
  [`@media (max-width: ${breakpoint})`]: {
25
34
  "flex-direction": "column",
@@ -33,7 +42,10 @@ function Group({ align, breakpoint, justify, gap, width, style }, children) {
33
42
  }
34
43
  `
35
44
 
36
- return [Div({ className: styles.group, style }, children), styles.css]
45
+ return [
46
+ Div({ className: [styles.group, className], style }, children),
47
+ styles.css,
48
+ ]
37
49
  }
38
50
 
39
51
  module.exports = component(Group)
package/ui/index.js CHANGED
@@ -1,7 +1,9 @@
1
- const Group = require("./Group")
2
- const Stack = require("./Stack")
1
+ const Container = require("./container")
2
+ const Group = require("./group")
3
+ const Stack = require("./stack")
3
4
 
4
5
  module.exports = {
6
+ Container,
5
7
  Group,
6
8
  Stack,
7
9
  }
package/ui/normalize.js CHANGED
@@ -58,9 +58,29 @@ function normalizeWidth(width) {
58
58
  return width
59
59
  }
60
60
 
61
+ const SPACING_MAP = {
62
+ xs: "0.25rem",
63
+ sm: "0.5rem",
64
+ md: "1rem",
65
+ lg: "2rem",
66
+ xl: "4rem",
67
+ none: null,
68
+ }
69
+
70
+ function normalizeSpacing(spacing) {
71
+ if (typeof spacing === "number") {
72
+ return `${spacing}px`
73
+ }
74
+ if (SPACING_MAP.hasOwnProperty(spacing)) {
75
+ return SPACING_MAP[spacing]
76
+ }
77
+ return spacing
78
+ }
79
+
61
80
  module.exports = {
62
81
  normalizeFlex,
63
82
  normalizeGap,
64
83
  normalizeBreakpoint,
65
84
  normalizeWidth,
85
+ normalizeSpacing,
66
86
  }
@@ -1,19 +1,32 @@
1
1
  const { css, component, Div } = require("../..")
2
- const { normalizeGap, normalizeFlex, normalizeWidth } = require("../normalize")
2
+ const {
3
+ normalizeGap,
4
+ normalizeFlex,
5
+ normalizeWidth,
6
+ normalizeSpacing,
7
+ } = require("../normalize")
3
8
 
4
- function Stack({ align, justify, gap, width, style }, children) {
9
+ function Stack(
10
+ { align, className, justify, gap, width, margin, padding, style },
11
+ children
12
+ ) {
5
13
  gap = normalizeGap(gap)
6
14
  align = normalizeFlex(align)
7
15
  justify = normalizeFlex(justify)
8
16
  width = normalizeWidth(width)
17
+ margin = normalizeSpacing(margin)
18
+ padding = normalizeSpacing(padding)
9
19
 
10
20
  const styleObject = {
21
+ "box-sizing": "border-box",
11
22
  display: "flex",
12
23
  "flex-direction": "column",
13
24
  ...(gap && { gap }),
14
25
  ...(align && { "align-items": align }),
15
26
  ...(justify && { "justify-content": justify }),
16
27
  ...(width && { width }),
28
+ ...(margin && { margin }),
29
+ ...(padding && { padding }),
17
30
  }
18
31
 
19
32
  const styles = css`
@@ -22,7 +35,10 @@ function Stack({ align, justify, gap, width, style }, children) {
22
35
  }
23
36
  `
24
37
 
25
- return [Div({ className: styles.stack, style }, children), styles.css]
38
+ return [
39
+ Div({ className: [styles.stack, className], style }, children),
40
+ styles.css,
41
+ ]
26
42
  }
27
43
 
28
44
  module.exports = component(Stack)