@flodesk/grain 1.5.1 → 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/README.md CHANGED
@@ -1,34 +1,35 @@
1
- This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1
+ # Grain design system
2
2
 
3
- ## Getting Started
3
+ ## Installation
4
4
 
5
- First, run the development server:
6
-
7
- ```bash
8
- npm run dev
9
- # or
10
- yarn dev
5
+ ```
6
+ npm install @flodesk/grain
11
7
  ```
12
8
 
13
- Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14
-
15
- You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16
-
17
- [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
9
+ ### Add base styles
18
10
 
19
- The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
11
+ `base.css` contains all Grain global styles. Import it in the highest component possible so that it's accessible everywhere in the UI.
20
12
 
21
- ## Learn More
13
+ ```js
14
+ import "@flodesk/grain/es/styles/base.css";
15
+ ```
22
16
 
23
- To learn more about Next.js, take a look at the following resources:
17
+ ## Usage
24
18
 
25
- - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26
- - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
19
+ ### Component usage
27
20
 
28
- You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
21
+ ```jsx
22
+ import { Text, Button, Input } from "@flodesk/grain";
29
23
 
30
- ## Deploy on Vercel
24
+ <Text>Content</Text>;
25
+ ```
31
26
 
32
- The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
27
+ ### CSS variable usage
33
28
 
34
- Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
29
+ ```css
30
+ .dashboard-header {
31
+ font-size: var(--grn-text-xl);
32
+ margin-bottom: var(--grn-space-l);
33
+ color: var(--grn-color-bodyDimmed);
34
+ }
35
+ ```
@@ -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
+ };
@@ -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
  };
@@ -26,7 +26,9 @@
26
26
  }
27
27
 
28
28
  :root {
29
- --grn-color-grey8: hsl(0 0% 7%);
29
+ --grey8-HSL: 0 0% 7%;
30
+
31
+ --grn-color-grey8: hsl(var(--grey8-HSL));
30
32
  --grn-color-grey7: hsl(0 0% 20%);
31
33
  --grn-color-grey6: hsl(0 0% 32%);
32
34
  --grn-color-grey5: hsl(0 0% 44%);
@@ -35,12 +37,18 @@
35
37
  --grn-color-grey2: hsl(0 0% 87%);
36
38
  --grn-color-grey1: hsl(0 0% 96%);
37
39
 
40
+ --grn-color-blue: hsl(218 74% 54%);
41
+ --grn-color-red: hsl(6 66% 65%);
42
+
38
43
  --grn-color-body: var(--grn-color-grey8);
39
- --grn-color-bodyDimmed: hsl(0 0% 7% / 50%);
40
- --grn-color-primary: var(--grn-color-grey8);
44
+ --grn-color-bodyDimmed: hsl(var(--grey8-HSL) / 50%);
45
+ --grn-color-accent: var(--grn-color-grey8);
41
46
  --grn-color-backgroundSecondary: hsl(0 0% 100%);
42
47
  --grn-color-background: var(--grn-color-grey1);
43
- --grn-color-border: hsl(0 0% 7% / 9%);
48
+ --grn-color-overlay: hsl(var(--grey8-HSL) / 7%);
49
+ --grn-color-border: hsl(var(--grey8-HSL) / 9%);
50
+ --grn-color-selection: var(--grn-color-blue);
51
+ --grn-color-danger: var(--grn-color-red);
44
52
  }
45
53
 
46
54
  * {
@@ -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
+ };
@@ -1,29 +1,63 @@
1
1
  import "core-js/modules/es.array.concat.js";
2
2
  import "core-js/modules/es.array.includes.js";
3
3
  import "core-js/modules/es.string.includes.js";
4
- import { cssVarOptions, grnPrefix } from "../variables";
4
+ import { cssVars, grnPrefix } from "../variables";
5
5
  export var getCssVarCore = function getCssVarCore(type, value) {
6
6
  return "".concat(grnPrefix).concat(type, "-").concat(value);
7
7
  };
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
- if (cssVarOptions.colors.includes(color)) {
17
+ if (cssVars.colors.includes(color)) {
13
18
  return getCssVar("color", color);
14
19
  }
15
20
 
16
21
  return color;
17
22
  };
18
23
  export var getTextSize = function getTextSize(size) {
19
- if (cssVarOptions.textSizes.includes(size)) {
24
+ if (cssVars.textSizes.includes(size)) {
20
25
  return getCssVar("text", size);
21
26
  }
22
27
 
23
28
  return size;
24
29
  };
25
30
  export var getWeight = function getWeight(weight) {
26
- if (cssVarOptions.weights.includes(weight)) {
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
  };
@@ -31,10 +31,11 @@ for (var step = 1; step < greysAmount + 1; step++) {
31
31
 
32
32
  export var grnPrefix = "--grn-";
33
33
  export var greys = greysArray.reverse();
34
- export var semanticColors = ["body", "bodyDimmed", "primary", "backgroundSecondary", "background", "border"];
35
- export var cssVarOptions = {
34
+ export var semanticColors = ["body", "bodyDimmed", "accent", "backgroundSecondary", "background", "overlay", "border", "selection", "danger"];
35
+ export var baseColors = ["blue", "red"];
36
+ export var cssVars = {
36
37
  textSizes: ["s", "m", "l", "xl", "xxl"],
37
38
  spaces: ["xs", "s", "m", "l", "xl", "xxl"],
38
39
  weights: ["normal", "medium", "semiBold"],
39
- colors: [].concat(_toConsumableArray(greys), semanticColors)
40
+ colors: [].concat(_toConsumableArray(greys), baseColors, semanticColors)
40
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "1.5.1",
3
+ "version": "2.1.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
- };