@flodesk/grain 1.6.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/README.md CHANGED
@@ -8,10 +8,10 @@ npm install @flodesk/grain
8
8
 
9
9
  ### Add base styles
10
10
 
11
- `base-styles.css` contains all Grain global styles. Import it in the highest component possible so that it's accessible everywhere in the UI.
11
+ `base.css` contains all Grain global styles. Import it in the highest component possible so that it's accessible everywhere in the UI.
12
12
 
13
13
  ```js
14
- import "@flodesk/grain/es/base-styles.css";
14
+ import "@flodesk/grain/es/styles/base.css";
15
15
  ```
16
16
 
17
17
  ## Usage
@@ -0,0 +1,149 @@
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
+ import "core-js/modules/es.object.keys.js";
5
+ import "core-js/modules/es.array.index-of.js";
6
+ import "core-js/modules/es.symbol.js";
7
+ var _excluded = ["children", "color", "backgroundColor", "borderSide", "borderWidth", "borderColor", "width", "height", "radius", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY", "position", "top", "bottom", "left", "right"];
8
+
9
+ var _templateObject;
10
+
11
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
12
+
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
14
+
15
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
16
+
17
+ import "core-js/modules/es.array.concat.js";
18
+ import "core-js/modules/es.object.assign.js";
19
+ import { getBorder, getColor, getRadius, getSpace } from '../../utilities';
20
+ import React from "react";
21
+ import styled from "@emotion/styled";
22
+ import { types } from '../../types';
23
+
24
+ var getSpaceCss = function getSpaceCss(propertyName, propertyValue) {
25
+ if (propertyValue || propertyValue === 0) {
26
+ return "".concat(propertyName, ": ").concat(getSpace(propertyValue));
27
+ }
28
+ };
29
+
30
+ var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n \n ", ";\n ", ";\n ", ";\n ", ";\n \n ", ";\n ", ";\n ", ";\n ", ";\n \n ", ";\n ", ";\n ", ";\n ", ";\n \n ", ";\n \n color: ", ";\n background-color: ", ";\n width: ", ";\n height: ", ";\n border-radius: ", ";\n"])), function (p) {
31
+ return getBorder(p.borderSide, p.borderWidth, p.borderColor);
32
+ }, function (p) {
33
+ return getSpaceCss('padding-top', p.paddingTop);
34
+ }, function (p) {
35
+ return getSpaceCss('padding-bottom', p.paddingBottom);
36
+ }, function (p) {
37
+ return getSpaceCss('padding-left', p.paddingLeft);
38
+ }, function (p) {
39
+ return getSpaceCss('padding-right', p.paddingRight);
40
+ }, function (p) {
41
+ return getSpaceCss('margin-top', p.marginTop);
42
+ }, function (p) {
43
+ return getSpaceCss('margin-bottom', p.marginBottom);
44
+ }, function (p) {
45
+ return getSpaceCss('margin-left', p.marginLeft);
46
+ }, function (p) {
47
+ return getSpaceCss('margin-right', p.marginRight);
48
+ }, function (p) {
49
+ return getSpaceCss('top', p.top);
50
+ }, function (p) {
51
+ return getSpaceCss('bottom', p.bottom);
52
+ }, function (p) {
53
+ return getSpaceCss('left', p.left);
54
+ }, function (p) {
55
+ return getSpaceCss('right', p.right);
56
+ }, function (p) {
57
+ return p.position && "position: ".concat(p.position);
58
+ }, function (p) {
59
+ return getColor(p.color);
60
+ }, function (p) {
61
+ return getColor(p.backgroundColor);
62
+ }, function (p) {
63
+ return getSpace(p.width);
64
+ }, function (p) {
65
+ return getSpace(p.height);
66
+ }, function (p) {
67
+ return getRadius(p.radius);
68
+ });
69
+ export var Box = function Box(_ref) {
70
+ var children = _ref.children,
71
+ color = _ref.color,
72
+ backgroundColor = _ref.backgroundColor,
73
+ borderSide = _ref.borderSide,
74
+ borderWidth = _ref.borderWidth,
75
+ borderColor = _ref.borderColor,
76
+ width = _ref.width,
77
+ height = _ref.height,
78
+ radius = _ref.radius,
79
+ padding = _ref.padding,
80
+ paddingTop = _ref.paddingTop,
81
+ paddingBottom = _ref.paddingBottom,
82
+ paddingLeft = _ref.paddingLeft,
83
+ paddingRight = _ref.paddingRight,
84
+ paddingX = _ref.paddingX,
85
+ paddingY = _ref.paddingY,
86
+ margin = _ref.margin,
87
+ marginTop = _ref.marginTop,
88
+ marginBottom = _ref.marginBottom,
89
+ marginLeft = _ref.marginLeft,
90
+ marginRight = _ref.marginRight,
91
+ marginX = _ref.marginX,
92
+ marginY = _ref.marginY,
93
+ position = _ref.position,
94
+ top = _ref.top,
95
+ bottom = _ref.bottom,
96
+ left = _ref.left,
97
+ right = _ref.right,
98
+ props = _objectWithoutProperties(_ref, _excluded);
99
+
100
+ return /*#__PURE__*/React.createElement(Wrapper, Object.assign({
101
+ backgroundColor: backgroundColor,
102
+ color: color,
103
+ borderSide: borderSide,
104
+ borderWidth: borderWidth,
105
+ borderColor: borderColor,
106
+ width: width,
107
+ height: height,
108
+ radius: radius,
109
+ paddingTop: padding || paddingY || paddingTop,
110
+ paddingBottom: padding || paddingY || paddingBottom,
111
+ paddingLeft: padding || paddingX || paddingLeft,
112
+ paddingRight: padding || paddingX || paddingRight,
113
+ marginTop: margin || marginY || marginTop,
114
+ marginBottom: margin || marginY || marginBottom,
115
+ marginLeft: margin || marginX || marginLeft,
116
+ marginRight: margin || marginX || marginRight,
117
+ position: position,
118
+ top: top,
119
+ bottom: bottom,
120
+ left: left,
121
+ right: right
122
+ }, props), children);
123
+ };
124
+ Box.propTypes = {
125
+ color: types.color,
126
+ borderSide: types.side,
127
+ width: types.space,
128
+ height: types.space,
129
+ radius: types.radius,
130
+ padding: types.space,
131
+ paddingTop: types.space,
132
+ paddingBottom: types.space,
133
+ paddingLeft: types.space,
134
+ paddingRight: types.space,
135
+ paddingX: types.space,
136
+ paddingY: types.space,
137
+ margin: types.space,
138
+ marginTop: types.space,
139
+ marginBottom: types.space,
140
+ marginLeft: types.space,
141
+ marginRight: types.space,
142
+ marginX: types.space,
143
+ marginY: types.space,
144
+ position: types.position,
145
+ top: types.space,
146
+ bottom: types.space,
147
+ left: types.space,
148
+ right: types.space
149
+ };
@@ -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 { cssVarOptions } 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: PropTypes.oneOf(cssVarOptions.textSizes),
36
- weight: PropTypes.oneOf(cssVarOptions.weights),
37
- color: PropTypes.oneOfType([PropTypes.oneOf(cssVarOptions.weights), PropTypes.string])
34
+ size: types.textSize,
35
+ weight: types.weight,
36
+ color: types.color
38
37
  };
@@ -25,6 +25,12 @@
25
25
  --grn-space-xxl: calc(var(--grn-unit) * 7);
26
26
  }
27
27
 
28
+ :root {
29
+ --grn-radius-s: calc(var(--grn-unit) / 2);
30
+ --grn-radius-m: calc(var(--grn-unit) / 1.33);
31
+ --grn-radius-l: calc(var(--grn-unit) * 1.25);
32
+ }
33
+
28
34
  :root {
29
35
  --grey8-HSL: 0 0% 7%;
30
36
 
@@ -0,0 +1,12 @@
1
+ import "core-js/modules/es.object.keys.js";
2
+ import PropTypes from "prop-types";
3
+ import { vars } from "../variables";
4
+ export var types = {
5
+ color: PropTypes.oneOfType([PropTypes.oneOf(Object.keys(vars.colors)), PropTypes.string]),
6
+ space: PropTypes.oneOfType([PropTypes.oneOf(Object.keys(vars.spaces)), PropTypes.number, PropTypes.string]),
7
+ side: PropTypes.oneOf(["all", "left", "right", "top", "bottom", "x", "y"]),
8
+ radius: PropTypes.oneOf(["s", "m", "l"]),
9
+ position: PropTypes.oneOf(["static", "relative", "fixed", "absolute", "sticky"]),
10
+ textSize: PropTypes.oneOfType([PropTypes.oneOf(Object.keys(vars.textSizes)), PropTypes.number, PropTypes.string]),
11
+ weight: PropTypes.oneOf(Object.keys(vars.weights))
12
+ };
@@ -1,29 +1,68 @@
1
1
  import "core-js/modules/es.array.concat.js";
2
- import "core-js/modules/es.array.includes.js";
3
- import "core-js/modules/es.string.includes.js";
4
- import { cssVarOptions, grnPrefix } from "../variables";
2
+ import { grnPrefix, vars } from "../variables";
5
3
  export var getCssVarCore = function getCssVarCore(type, value) {
6
4
  return "".concat(grnPrefix).concat(type, "-").concat(value);
7
5
  };
8
6
  export var getCssVar = function getCssVar(type, value) {
9
7
  return "var(".concat(getCssVarCore(type, value), ")");
10
8
  };
9
+
10
+ var u = function u(amount) {
11
+ return "calc(var(--grn-unit) * ".concat(amount, ")");
12
+ };
13
+
11
14
  export var getColor = function getColor(color) {
12
- if (cssVarOptions.colors.includes(color)) {
15
+ if (color in vars.colors) {
13
16
  return getCssVar("color", color);
14
17
  }
15
18
 
16
19
  return color;
17
20
  };
18
21
  export var getTextSize = function getTextSize(size) {
19
- if (cssVarOptions.textSizes.includes(size)) {
22
+ if (size in vars.textSizes) {
20
23
  return getCssVar("text", size);
21
24
  }
22
25
 
23
26
  return size;
24
27
  };
25
28
  export var getWeight = function getWeight(weight) {
26
- if (cssVarOptions.weights.includes(weight)) {
29
+ if (weight in vars.weights) {
27
30
  return getCssVar("weight", weight);
28
31
  }
32
+ };
33
+ export var getRadius = function getRadius(radius) {
34
+ if (radius in vars.radiuses) {
35
+ return getCssVar("radius", radius);
36
+ }
37
+ };
38
+ export var getSpace = function getSpace(space) {
39
+ if (isNaN(space)) {
40
+ if (space in vars.spaces) {
41
+ return getCssVar("space", space);
42
+ }
43
+
44
+ return space;
45
+ }
46
+
47
+ if (space === 0) return space;
48
+ return u(space);
49
+ };
50
+ console.log("getSpace", getSpace(0));
51
+ export var getBorder = function getBorder(borderSide) {
52
+ var borderWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "1px";
53
+ var borderColor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "border";
54
+ var w = getSpace(borderWidth);
55
+ var borderSideStyles = {
56
+ x: "0 ".concat(w),
57
+ y: "".concat(w, " 0"),
58
+ all: "".concat(w),
59
+ top: "".concat(w, " 0 0 0"),
60
+ right: "0 ".concat(w, " 0 0"),
61
+ bottom: "0 0 ".concat(w, " 0"),
62
+ left: "0 0 0 ".concat(w)
63
+ };
64
+
65
+ if (borderSide in borderSideStyles) {
66
+ return "\n border-style: solid;\n border-width: ".concat(borderSideStyles[borderSide], ";\n border-color: ").concat(getColor(borderColor), ";\n ");
67
+ }
29
68
  };
@@ -1,41 +1,70 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- import "core-js/modules/es.array.reverse.js";
14
- import "core-js/modules/es.array.concat.js";
1
+ import "core-js/modules/es.object.define-property.js";
2
+ import "core-js/modules/es.object.keys.js";
15
3
  import "core-js/modules/es.symbol.js";
16
- import "core-js/modules/es.symbol.description.js";
4
+ import "core-js/modules/es.array.filter.js";
17
5
  import "core-js/modules/es.object.to-string.js";
18
- import "core-js/modules/es.symbol.iterator.js";
19
- import "core-js/modules/es.array.iterator.js";
20
- import "core-js/modules/es.string.iterator.js";
21
- import "core-js/modules/web.dom-collections.iterator.js";
22
- import "core-js/modules/es.array.from.js";
23
- import "core-js/modules/es.array.slice.js";
24
- import "core-js/modules/es.regexp.exec.js";
25
- var greysAmount = 8;
26
- var greysArray = [];
6
+ import "core-js/modules/es.object.get-own-property-descriptor.js";
7
+ import "core-js/modules/web.dom-collections.for-each.js";
8
+ import "core-js/modules/es.object.get-own-property-descriptors.js";
9
+ import "core-js/modules/es.object.define-properties.js";
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
14
 
28
- for (var step = 1; step < greysAmount + 1; step++) {
29
- greysArray.push("grey" + step);
30
- }
15
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
16
 
32
17
  export var grnPrefix = "--grn-";
33
- export var greys = greysArray.reverse();
34
- export var semanticColors = ["body", "bodyDimmed", "accent", "backgroundSecondary", "background", "overlay", "border", "selection", "danger"];
35
- export var baseColors = ["blue", "red"];
36
- export var cssVarOptions = {
37
- textSizes: ["s", "m", "l", "xl", "xxl"],
38
- spaces: ["xs", "s", "m", "l", "xl", "xxl"],
39
- weights: ["normal", "medium", "semiBold"],
40
- colors: [].concat(_toConsumableArray(greys), baseColors, semanticColors)
18
+ export var greys = {
19
+ grey8: "grey8",
20
+ grey7: "grey7",
21
+ grey6: "grey6",
22
+ grey5: "grey5",
23
+ grey4: "grey4",
24
+ grey3: "grey3",
25
+ grey2: "grey2",
26
+ grey1: "grey1"
27
+ };
28
+ export var semanticColors = {
29
+ body: "body",
30
+ bodyDimmed: "bodyDimmed",
31
+ accent: "accent",
32
+ backgroundSecondary: "backgroundSecondary",
33
+ background: "background",
34
+ overlay: "overlay",
35
+ border: "border",
36
+ selection: "selection",
37
+ danger: "danger"
38
+ };
39
+ export var baseColors = {
40
+ blue: "blue",
41
+ red: "red"
42
+ };
43
+ export var vars = {
44
+ textSizes: {
45
+ s: "s",
46
+ m: "m",
47
+ l: "l",
48
+ xl: "xl",
49
+ xxl: "xxl"
50
+ },
51
+ spaces: {
52
+ xs: "xs",
53
+ s: "s",
54
+ m: "m",
55
+ l: "l",
56
+ xl: "xl",
57
+ xxl: "xxl"
58
+ },
59
+ weights: {
60
+ normal: "normal",
61
+ medium: "medium",
62
+ semiBold: "semiBold"
63
+ },
64
+ radiuses: {
65
+ s: "s",
66
+ m: "m",
67
+ l: "l"
68
+ },
69
+ colors: _objectSpread(_objectSpread(_objectSpread({}, greys), baseColors), semanticColors)
41
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "1.6.0",
3
+ "version": "2.2.0",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",
@@ -1,67 +0,0 @@
1
- import "core-js/modules/es.symbol.js";
2
- import "core-js/modules/es.symbol.description.js";
3
- import "core-js/modules/es.object.to-string.js";
4
- import "core-js/modules/es.symbol.iterator.js";
5
- import "core-js/modules/es.array.iterator.js";
6
- import "core-js/modules/es.string.iterator.js";
7
- import "core-js/modules/web.dom-collections.iterator.js";
8
- import "core-js/modules/es.array.slice.js";
9
- import "core-js/modules/es.array.from.js";
10
- import "core-js/modules/es.regexp.exec.js";
11
-
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
-
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
-
16
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
-
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
19
-
20
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
21
-
22
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
-
24
- import { useEffect, useState } from "react";
25
- export function useWindowSize() {
26
- var _useState = useState({
27
- width: undefined,
28
- height: undefined
29
- }),
30
- _useState2 = _slicedToArray(_useState, 2),
31
- windowSize = _useState2[0],
32
- setWindowSize = _useState2[1];
33
-
34
- useEffect(function () {
35
- function handleResize() {
36
- setWindowSize({
37
- width: window.innerWidth,
38
- height: window.innerHeight
39
- });
40
- }
41
-
42
- window.addEventListener("resize", handleResize);
43
- handleResize();
44
- return function () {
45
- return window.removeEventListener("resize", handleResize);
46
- };
47
- }, []);
48
- return windowSize;
49
- }
50
- export var useComputedStyle = function useComputedStyle(ref, property) {
51
- var _useState3 = useState(),
52
- _useState4 = _slicedToArray(_useState3, 2),
53
- computedValue = _useState4[0],
54
- setComputedValue = _useState4[1];
55
-
56
- var windowSize = useWindowSize();
57
- useEffect(function () {
58
- if (typeof window !== "undefined") {
59
- var getStyle = function getStyle(style) {
60
- return window.getComputedStyle(ref.current).getPropertyValue(style);
61
- };
62
-
63
- setComputedValue(getStyle(property));
64
- }
65
- }, [windowSize]);
66
- return computedValue;
67
- };