@flodesk/grain 2.0.0 → 2.1.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/es/components/box/index.js +102 -0
- package/es/components/index.js +2 -1
- package/es/components/text/index.js +4 -5
- package/es/types/index.js +9 -0
- package/es/utilities/index.js +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import "core-js/modules/es.array.slice.js";
|
|
2
|
+
import "core-js/modules/es.object.freeze.js";
|
|
3
|
+
import "core-js/modules/es.object.define-properties.js";
|
|
4
|
+
|
|
5
|
+
var _templateObject;
|
|
6
|
+
|
|
7
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
8
|
+
|
|
9
|
+
import { getBorder, getColor, getSpace } from '../../utilities';
|
|
10
|
+
import PropTypes from "prop-types";
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { cssVars } from '../../variables';
|
|
13
|
+
import styled from "@emotion/styled";
|
|
14
|
+
import { types } from '../../types';
|
|
15
|
+
var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n \n ", ";\n ", ";\n ", ";\n ", ";\n \n ", ";\n ", ";\n ", ";\n ", ";\n \n color: ", ";\n background-color: ", ";\n width: ", ";\n height: ", ";\n"])), function (p) {
|
|
16
|
+
return getBorder(p.borderSide, p.borderWidth, p.borderColor);
|
|
17
|
+
}, function (p) {
|
|
18
|
+
return p.paddingTop && "padding-top: ".concat(getSpace(p.paddingTop));
|
|
19
|
+
}, function (p) {
|
|
20
|
+
return p.paddingBottom && "padding-bottom: ".concat(getSpace(p.paddingBottom));
|
|
21
|
+
}, function (p) {
|
|
22
|
+
return p.paddingLeft && "padding-left: ".concat(getSpace(p.paddingLeft));
|
|
23
|
+
}, function (p) {
|
|
24
|
+
return p.paddingRight && "padding-right: ".concat(getSpace(p.paddingRight));
|
|
25
|
+
}, function (p) {
|
|
26
|
+
return p.marginTop && "margin-top: ".concat(getSpace(p.marginTop));
|
|
27
|
+
}, function (p) {
|
|
28
|
+
return p.marginBottom && "margin-bottom: ".concat(getSpace(p.marginBottom));
|
|
29
|
+
}, function (p) {
|
|
30
|
+
return p.marginLeft && "margin-left: ".concat(getSpace(p.marginLeft));
|
|
31
|
+
}, function (p) {
|
|
32
|
+
return p.marginRight && "margin-right: ".concat(getSpace(p.marginRight));
|
|
33
|
+
}, function (p) {
|
|
34
|
+
return getColor(p.color);
|
|
35
|
+
}, function (p) {
|
|
36
|
+
return getColor(p.backgroundColor);
|
|
37
|
+
}, function (p) {
|
|
38
|
+
return getSpace(p.width);
|
|
39
|
+
}, function (p) {
|
|
40
|
+
return getSpace(p.height);
|
|
41
|
+
});
|
|
42
|
+
export var Box = function Box(_ref) {
|
|
43
|
+
var children = _ref.children,
|
|
44
|
+
color = _ref.color,
|
|
45
|
+
backgroundColor = _ref.backgroundColor,
|
|
46
|
+
borderSide = _ref.borderSide,
|
|
47
|
+
borderWidth = _ref.borderWidth,
|
|
48
|
+
borderColor = _ref.borderColor,
|
|
49
|
+
width = _ref.width,
|
|
50
|
+
height = _ref.height,
|
|
51
|
+
padding = _ref.padding,
|
|
52
|
+
paddingTop = _ref.paddingTop,
|
|
53
|
+
paddingBottom = _ref.paddingBottom,
|
|
54
|
+
paddingLeft = _ref.paddingLeft,
|
|
55
|
+
paddingRight = _ref.paddingRight,
|
|
56
|
+
paddingX = _ref.paddingX,
|
|
57
|
+
paddingY = _ref.paddingY,
|
|
58
|
+
margin = _ref.margin,
|
|
59
|
+
marginTop = _ref.marginTop,
|
|
60
|
+
marginBottom = _ref.marginBottom,
|
|
61
|
+
marginLeft = _ref.marginLeft,
|
|
62
|
+
marginRight = _ref.marginRight,
|
|
63
|
+
marginX = _ref.marginX,
|
|
64
|
+
marginY = _ref.marginY;
|
|
65
|
+
return /*#__PURE__*/React.createElement(Wrapper, {
|
|
66
|
+
backgroundColor: backgroundColor,
|
|
67
|
+
color: color,
|
|
68
|
+
borderSide: borderSide,
|
|
69
|
+
borderWidth: borderWidth,
|
|
70
|
+
borderColor: borderColor,
|
|
71
|
+
width: width,
|
|
72
|
+
height: height,
|
|
73
|
+
paddingTop: padding || paddingY || paddingTop,
|
|
74
|
+
paddingBottom: padding || paddingY || paddingBottom,
|
|
75
|
+
paddingLeft: padding || paddingX || paddingLeft,
|
|
76
|
+
paddingRight: padding || paddingX || paddingRight,
|
|
77
|
+
marginTop: margin || marginY || marginTop,
|
|
78
|
+
marginBottom: margin || marginY || marginBottom,
|
|
79
|
+
marginLeft: margin || marginX || marginLeft,
|
|
80
|
+
marginRight: margin || marginX || marginRight
|
|
81
|
+
}, children);
|
|
82
|
+
};
|
|
83
|
+
Box.propTypes = {
|
|
84
|
+
color: types.color,
|
|
85
|
+
borderSide: types.side,
|
|
86
|
+
width: types.space,
|
|
87
|
+
height: types.space,
|
|
88
|
+
padding: types.space,
|
|
89
|
+
paddingTop: types.space,
|
|
90
|
+
paddingBottom: types.space,
|
|
91
|
+
paddingLeft: types.space,
|
|
92
|
+
paddingRight: types.space,
|
|
93
|
+
paddingX: types.space,
|
|
94
|
+
paddingY: types.space,
|
|
95
|
+
margin: types.space,
|
|
96
|
+
marginTop: types.space,
|
|
97
|
+
marginBottom: types.space,
|
|
98
|
+
marginLeft: types.space,
|
|
99
|
+
marginRight: types.space,
|
|
100
|
+
marginX: types.space,
|
|
101
|
+
marginY: types.space
|
|
102
|
+
};
|
package/es/components/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { Text } from "./text";
|
|
1
|
+
export { Text } from "./text";
|
|
2
|
+
export { Box } from "./box";
|
|
@@ -7,10 +7,9 @@ var _templateObject;
|
|
|
7
7
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
8
8
|
|
|
9
9
|
import { getColor, getTextSize, getWeight } from '../../utilities';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
10
|
import React from "react";
|
|
12
|
-
import { cssVars } from '../../variables';
|
|
13
11
|
import styled from "@emotion/styled";
|
|
12
|
+
import { types } from '../../types';
|
|
14
13
|
var Wrapper = styled.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n font-size: ", ";\n font-weight: ", ";\n color: ", ";\n"])), function (p) {
|
|
15
14
|
return getTextSize(p.size);
|
|
16
15
|
}, function (p) {
|
|
@@ -32,7 +31,7 @@ export var Text = function Text(_ref) {
|
|
|
32
31
|
}, children);
|
|
33
32
|
};
|
|
34
33
|
Text.propTypes = {
|
|
35
|
-
size:
|
|
36
|
-
weight:
|
|
37
|
-
color:
|
|
34
|
+
size: types.textSize,
|
|
35
|
+
weight: types.weight,
|
|
36
|
+
color: types.color
|
|
38
37
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import { cssVars } from "../variables";
|
|
3
|
+
export var types = {
|
|
4
|
+
color: PropTypes.oneOfType([PropTypes.oneOf(cssVars.colors), PropTypes.string]),
|
|
5
|
+
space: PropTypes.oneOfType([PropTypes.oneOf(cssVars.spaces), PropTypes.number, PropTypes.string]),
|
|
6
|
+
side: PropTypes.oneOf(["all", "left", "right", "top", "bottom", "x", "y"]),
|
|
7
|
+
textSize: PropTypes.oneOfType([PropTypes.oneOf(cssVars.textSizes), PropTypes.number, PropTypes.string]),
|
|
8
|
+
weight: PropTypes.oneOf(cssVars.weights)
|
|
9
|
+
};
|
package/es/utilities/index.js
CHANGED
|
@@ -8,6 +8,11 @@ export var getCssVarCore = function getCssVarCore(type, value) {
|
|
|
8
8
|
export var getCssVar = function getCssVar(type, value) {
|
|
9
9
|
return "var(".concat(getCssVarCore(type, value), ")");
|
|
10
10
|
};
|
|
11
|
+
|
|
12
|
+
var u = function u(amount) {
|
|
13
|
+
return "calc(var(--grn-unit) * ".concat(amount, ")");
|
|
14
|
+
};
|
|
15
|
+
|
|
11
16
|
export var getColor = function getColor(color) {
|
|
12
17
|
if (cssVars.colors.includes(color)) {
|
|
13
18
|
return getCssVar("color", color);
|
|
@@ -26,4 +31,33 @@ export var getWeight = function getWeight(weight) {
|
|
|
26
31
|
if (cssVars.weights.includes(weight)) {
|
|
27
32
|
return getCssVar("weight", weight);
|
|
28
33
|
}
|
|
34
|
+
};
|
|
35
|
+
export var getSpace = function getSpace(space) {
|
|
36
|
+
if (isNaN(space)) {
|
|
37
|
+
if (cssVars.spaces.includes(space)) {
|
|
38
|
+
return getCssVar("space", space);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return space;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return u(space);
|
|
45
|
+
};
|
|
46
|
+
export var getBorder = function getBorder(borderSide) {
|
|
47
|
+
var borderWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "1px";
|
|
48
|
+
var borderColor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "border";
|
|
49
|
+
var w = getSpace(borderWidth);
|
|
50
|
+
var borderSideStyles = {
|
|
51
|
+
x: "0 ".concat(w),
|
|
52
|
+
y: "".concat(w, " 0"),
|
|
53
|
+
all: "".concat(w),
|
|
54
|
+
top: "".concat(w, " 0 0 0"),
|
|
55
|
+
right: "0 ".concat(w, " 0 0"),
|
|
56
|
+
bottom: "0 0 ".concat(w, " 0"),
|
|
57
|
+
left: "0 0 0 ".concat(w)
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (borderSide in borderSideStyles) {
|
|
61
|
+
return "\n border-style: solid;\n border-width: ".concat(borderSideStyles[borderSide], ";\n border-color: ").concat(getColor(borderColor), ";\n ");
|
|
62
|
+
}
|
|
29
63
|
};
|