boxwood 2.1.0 → 2.2.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/index.js CHANGED
@@ -509,6 +509,27 @@ function decamelize(string) {
509
509
 
510
510
  function stylesheet(input) {
511
511
  const object = { ...input }
512
+ function render(object, selector = "") {
513
+ let result = []
514
+ for (const key in object) {
515
+ const value = object[key]
516
+ if (value && typeof value === "object") {
517
+ if (key.startsWith("@")) {
518
+ result.push(`${key}{${render(value, selector)}}`)
519
+ } else {
520
+ const nextSelector = selector ? `${selector} ${key}` : key
521
+ result.push(render(value, nextSelector))
522
+ }
523
+ } else {
524
+ if (selector) {
525
+ result.push(`${selector}{${decamelize(key)}:${value};}`)
526
+ } else {
527
+ result.push(`${decamelize(key)}:${value};`)
528
+ }
529
+ }
530
+ }
531
+ return result.join("")
532
+ }
512
533
  return {
513
534
  add(item) {
514
535
  for (const key in item) {
@@ -519,14 +540,7 @@ function stylesheet(input) {
519
540
  object[key] = value
520
541
  },
521
542
  toString() {
522
- let result = []
523
- for (const key in object) {
524
- const value = object[key]
525
- if (value) {
526
- result.push(`${decamelize(key)}:${value}`)
527
- }
528
- }
529
- return result.join(";")
543
+ return render(object)
530
544
  },
531
545
  }
532
546
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {
8
8
  ".": "./index.js",
9
- "./adapters/express": "./adapters/express/index.js"
9
+ "./adapters/express": "./adapters/express/index.js",
10
+ "./ui": "./ui/index.js"
10
11
  },
11
12
  "scripts": {
12
13
  "test": "node --test --test-reporter=dot \"test/**/*.test.js\" \"test/**/*.spec.js\"",
@@ -0,0 +1,39 @@
1
+ const { css, component, Div } = require("../..")
2
+ const {
3
+ normalizeGap,
4
+ normalizeFlex,
5
+ normalizeBreakpoint,
6
+ normalizeWidth,
7
+ } = require("../normalize")
8
+
9
+ function Group({ align, breakpoint, justify, gap, width, style }, children) {
10
+ gap = normalizeGap(gap)
11
+ align = normalizeFlex(align)
12
+ justify = normalizeFlex(justify)
13
+ breakpoint = normalizeBreakpoint(breakpoint)
14
+ width = normalizeWidth(width)
15
+
16
+ const styleObject = {
17
+ display: "flex",
18
+ "flex-direction": "row",
19
+ ...(gap && { gap }),
20
+ ...(align && { "align-items": align }),
21
+ ...(justify && { "justify-content": justify }),
22
+ ...(width && { width }),
23
+ ...(breakpoint && {
24
+ [`@media (max-width: ${breakpoint})`]: {
25
+ "flex-direction": "column",
26
+ },
27
+ }),
28
+ }
29
+
30
+ const styles = css`
31
+ .group {
32
+ ${css.create(styleObject).toString()}
33
+ }
34
+ `
35
+
36
+ return [Div({ className: styles.group, style }, children), styles.css]
37
+ }
38
+
39
+ module.exports = component(Group)
@@ -0,0 +1,28 @@
1
+ const { css, component, Div } = require("../..")
2
+ const { normalizeGap, normalizeFlex, normalizeWidth } = require("../normalize")
3
+
4
+ function Stack({ align, justify, gap, width, style }, children) {
5
+ gap = normalizeGap(gap)
6
+ align = normalizeFlex(align)
7
+ justify = normalizeFlex(justify)
8
+ width = normalizeWidth(width)
9
+
10
+ const styleObject = {
11
+ display: "flex",
12
+ "flex-direction": "column",
13
+ ...(gap && { gap }),
14
+ ...(align && { "align-items": align }),
15
+ ...(justify && { "justify-content": justify }),
16
+ ...(width && { width }),
17
+ }
18
+
19
+ const styles = css`
20
+ .stack {
21
+ ${css.create(styleObject).toString()}
22
+ }
23
+ `
24
+
25
+ return [Div({ className: styles.stack, style }, children), styles.css]
26
+ }
27
+
28
+ module.exports = component(Stack)
package/ui/index.js ADDED
@@ -0,0 +1,7 @@
1
+ const Group = require("./Group")
2
+ const Stack = require("./Stack")
3
+
4
+ module.exports = {
5
+ Group,
6
+ Stack,
7
+ }
@@ -0,0 +1,66 @@
1
+ function normalizeFlex(align) {
2
+ switch (align) {
3
+ case "start":
4
+ return "flex-start"
5
+ case "end":
6
+ return "flex-end"
7
+ default:
8
+ return align
9
+ }
10
+ }
11
+
12
+ const GAP_MAP = {
13
+ xs: "0.25rem",
14
+ sm: "0.5rem",
15
+ md: "1rem",
16
+ lg: "2rem",
17
+ xl: "4rem",
18
+ none: null,
19
+ }
20
+
21
+ function normalizeGap(gap) {
22
+ if (!gap) {
23
+ return "1rem"
24
+ }
25
+ if (typeof gap === "number") {
26
+ return `${gap}px`
27
+ }
28
+
29
+ if (GAP_MAP.hasOwnProperty(gap)) {
30
+ return GAP_MAP[gap]
31
+ }
32
+
33
+ return gap
34
+ }
35
+
36
+ const BREAKPOINT_MAP = {
37
+ xs: "575px",
38
+ sm: "767px",
39
+ md: "991px",
40
+ lg: "1199px",
41
+ xl: "1399px",
42
+ }
43
+
44
+ function normalizeBreakpoint(breakpoint) {
45
+ if (typeof breakpoint === "number") {
46
+ return `${breakpoint}px`
47
+ }
48
+ if (BREAKPOINT_MAP.hasOwnProperty(breakpoint)) {
49
+ return BREAKPOINT_MAP[breakpoint]
50
+ }
51
+ return breakpoint
52
+ }
53
+
54
+ function normalizeWidth(width) {
55
+ if (typeof width === "number") {
56
+ return `${width}px`
57
+ }
58
+ return width
59
+ }
60
+
61
+ module.exports = {
62
+ normalizeFlex,
63
+ normalizeGap,
64
+ normalizeBreakpoint,
65
+ normalizeWidth,
66
+ }
@@ -1,11 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(node test:*)",
5
- "Bash(mkdir:*)",
6
- "Bash(npm test:*)",
7
- "Bash(mv:*)"
8
- ],
9
- "deny": []
10
- }
11
- }