@flodesk/grain 1.6.0 → 2.0.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
|
|
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
|
|
14
|
+
import "@flodesk/grain/es/styles/base.css";
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -9,7 +9,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
|
|
|
9
9
|
import { getColor, getTextSize, getWeight } from '../../utilities';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import React from "react";
|
|
12
|
-
import {
|
|
12
|
+
import { cssVars } from '../../variables';
|
|
13
13
|
import styled from "@emotion/styled";
|
|
14
14
|
var Wrapper = styled.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n font-size: ", ";\n font-weight: ", ";\n color: ", ";\n"])), function (p) {
|
|
15
15
|
return getTextSize(p.size);
|
|
@@ -32,7 +32,7 @@ export var Text = function Text(_ref) {
|
|
|
32
32
|
}, children);
|
|
33
33
|
};
|
|
34
34
|
Text.propTypes = {
|
|
35
|
-
size: PropTypes.oneOf(
|
|
36
|
-
weight: PropTypes.oneOf(
|
|
37
|
-
color: PropTypes.oneOfType([PropTypes.oneOf(
|
|
35
|
+
size: PropTypes.oneOf(cssVars.textSizes),
|
|
36
|
+
weight: PropTypes.oneOf(cssVars.weights),
|
|
37
|
+
color: PropTypes.oneOfType([PropTypes.oneOf(cssVars.weights), PropTypes.string])
|
|
38
38
|
};
|
|
File without changes
|
package/es/utilities/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
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
|
};
|
|
@@ -9,21 +9,21 @@ export var getCssVar = function getCssVar(type, value) {
|
|
|
9
9
|
return "var(".concat(getCssVarCore(type, value), ")");
|
|
10
10
|
};
|
|
11
11
|
export var getColor = function getColor(color) {
|
|
12
|
-
if (
|
|
12
|
+
if (cssVars.colors.includes(color)) {
|
|
13
13
|
return getCssVar("color", color);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return color;
|
|
17
17
|
};
|
|
18
18
|
export var getTextSize = function getTextSize(size) {
|
|
19
|
-
if (
|
|
19
|
+
if (cssVars.textSizes.includes(size)) {
|
|
20
20
|
return getCssVar("text", size);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
return size;
|
|
24
24
|
};
|
|
25
25
|
export var getWeight = function getWeight(weight) {
|
|
26
|
-
if (
|
|
26
|
+
if (cssVars.weights.includes(weight)) {
|
|
27
27
|
return getCssVar("weight", weight);
|
|
28
28
|
}
|
|
29
29
|
};
|
package/es/variables/index.js
CHANGED
|
@@ -33,7 +33,7 @@ export var grnPrefix = "--grn-";
|
|
|
33
33
|
export var greys = greysArray.reverse();
|
|
34
34
|
export var semanticColors = ["body", "bodyDimmed", "accent", "backgroundSecondary", "background", "overlay", "border", "selection", "danger"];
|
|
35
35
|
export var baseColors = ["blue", "red"];
|
|
36
|
-
export var
|
|
36
|
+
export var cssVars = {
|
|
37
37
|
textSizes: ["s", "m", "l", "xl", "xxl"],
|
|
38
38
|
spaces: ["xs", "s", "m", "l", "xl", "xxl"],
|
|
39
39
|
weights: ["normal", "medium", "semiBold"],
|
package/package.json
CHANGED
|
@@ -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
|
-
};
|