@flodesk/grain 3.0.2 → 3.1.1

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.
@@ -8,4 +8,5 @@ export { IconButton } from './icon-button';
8
8
  export { TextButton } from './text-button';
9
9
  export { IconToggleGroup, IconToggle } from './icon-toggle';
10
10
  export { TextToggleGroup, TextToggle } from './text-toggle';
11
- export { Stack } from './stack';
11
+ export { Stack } from './stack';
12
+ export { Slider } from './slider';
@@ -0,0 +1,60 @@
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 = ["min", "max", "value", "step", "onChange"];
8
+
9
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
10
+
11
+ import "core-js/modules/es.object.assign.js";
12
+
13
+ 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; }
14
+
15
+ 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; }
16
+
17
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
18
+
19
+ import { PropTypes } from 'prop-types';
20
+ import React from 'react';
21
+ import styled from '@emotion/styled';
22
+ import { css } from '@emotion/react';
23
+ var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --trackHeight: 2px;\n --sliderHeight: 12px;\n --thumbSize: var(--sliderHeight);\n\n position: relative;\n\n &:after {\n content: '';\n width: 100%;\n height: var(--trackHeight);\n top: 0;\n bottom: 0;\n margin: auto;\n background: linear-gradient(\n 90deg,\n var(--grn-color-body) 0 var(--value),\n var(--grn-color-fade2) var(--value) 100%\n );\n display: block;\n position: absolute;\n border-radius: 100px;\n }\n"])));
24
+ var trackStyles = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 100%;\n height: var(--sliderHeight);\n cursor: pointer;\n background: transparent;\n"])));
25
+ var thumbStyles = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n -webkit-appearance: none;\n height: var(--thumbSize);\n width: var(--thumbSize);\n border-radius: 100px;\n background: var(--grn-color-body);\n cursor: pointer;\n"])));
26
+ var InputWrapper = styled.input(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n -webkit-appearance: none;\n width: 100%;\n margin: 0;\n display: block;\n background: transparent;\n\n &::-webkit-slider-runnable-track {\n ", "\n }\n &::-moz-range-track {\n ", "\n }\n\n &::-webkit-slider-thumb {\n ", "\n }\n &::-moz-range-thumb {\n ", "\n }\n"])), trackStyles, trackStyles, thumbStyles, thumbStyles);
27
+ export var Slider = function Slider(_ref) {
28
+ var _ref$min = _ref.min,
29
+ min = _ref$min === void 0 ? 0 : _ref$min,
30
+ _ref$max = _ref.max,
31
+ max = _ref$max === void 0 ? 100 : _ref$max,
32
+ value = _ref.value,
33
+ step = _ref.step,
34
+ onChange = _ref.onChange,
35
+ props = _objectWithoutProperties(_ref, _excluded);
36
+
37
+ var getPercentage = function getPercentage() {
38
+ return (value - min) / (max - min) * 100;
39
+ };
40
+
41
+ return /*#__PURE__*/React.createElement(Wrapper, {
42
+ style: {
43
+ '--value': "".concat(getPercentage(), "%")
44
+ }
45
+ }, /*#__PURE__*/React.createElement(InputWrapper, Object.assign({
46
+ type: "range",
47
+ min: min,
48
+ max: max,
49
+ value: value,
50
+ step: step,
51
+ onChange: onChange
52
+ }, props)));
53
+ };
54
+ Slider.propTypes = {
55
+ min: PropTypes.number,
56
+ max: PropTypes.number,
57
+ value: PropTypes.number,
58
+ step: PropTypes.number,
59
+ onChange: PropTypes.func
60
+ };
@@ -13,7 +13,6 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import "core-js/modules/es.array.concat.js";
14
14
  import "core-js/modules/es.array.map.js";
15
15
  import "core-js/modules/es.object.entries.js";
16
- import "core-js/modules/es.array.reverse.js";
17
16
  import "core-js/modules/es.symbol.js";
18
17
  import "core-js/modules/es.symbol.description.js";
19
18
  import "core-js/modules/es.object.to-string.js";
@@ -40,20 +39,23 @@ export var getMediaCss = function getMediaCss(mediaQuery, property, value) {
40
39
  return "\n ".concat(mediaQuery, " {\n ").concat(property, ": ").concat(getValue(value), ";\n }\n ");
41
40
  };
42
41
  export var mapObjToMedia = function mapObjToMedia(property, obj, type) {
43
- var varPrefix = varInfo[type].prefix;
42
+ var checkValueInVars = function checkValueInVars(value) {
43
+ if (type && value in vars[type]) {
44
+ var varPrefix = varInfo[type].prefix;
45
+ return getCssVar(varPrefix, value);
46
+ }
47
+
48
+ return value;
49
+ };
50
+
44
51
  var declarations = Object.entries(obj).map(function (_ref) {
45
52
  var _ref2 = _slicedToArray(_ref, 2),
46
53
  mediaQuery = _ref2[0],
47
54
  value = _ref2[1];
48
55
 
49
- if (value in vars[type]) {
50
- return getMediaCss(mediaQuery, property, getCssVar(varPrefix, value));
51
- }
52
-
53
- return getMediaCss(mediaQuery, property, value);
54
- }); // reverse array to make sure max-widths correctly override
55
-
56
- declarations.reverse().join('');
56
+ return getMediaCss(mediaQuery, property, checkValueInVars(value));
57
+ });
58
+ declarations.join('');
57
59
  return declarations;
58
60
  };
59
61
  export var getDimension = function getDimension(dimension) {
@@ -61,14 +63,14 @@ export var getDimension = function getDimension(dimension) {
61
63
  if (isString(dimension)) return dimension;
62
64
  if (isNumber(dimension)) return u(dimension);
63
65
  };
64
- export var getSpace = function getSpace(value) {
65
- if (value in vars.spaces) {
66
- return getCssVar(varInfo.spaces.prefix, value);
66
+ export var getSpace = function getSpace(space) {
67
+ if (space in vars.spaces) {
68
+ return getCssVar(varInfo.spaces.prefix, space);
67
69
  }
68
70
 
69
- if (value === 0) return value;
70
- if (isString(value)) return value;
71
- if (isNumber(value)) return u(value);
71
+ if (space === 0) return space;
72
+ if (isString(space)) return space;
73
+ if (isNumber(space)) return u(space);
72
74
  };
73
75
  export var getResponsiveDimension = function getResponsiveDimension(property, dimension) {
74
76
  if (!dimension) return;
@@ -105,22 +107,12 @@ export var getResponsiveTextSize = function getResponsiveTextSize(size) {
105
107
 
106
108
  return "".concat(property, ": ").concat(getTextSize(size));
107
109
  };
108
- export var mapColumnsToMedia = function mapColumnsToMedia(property, obj) {
109
- var declarations = Object.entries(obj).map(function (_ref3) {
110
- var _ref4 = _slicedToArray(_ref3, 2),
111
- breakpoint = _ref4[0],
112
- value = _ref4[1];
113
-
114
- return getMediaCss(breakpoint, property, value);
115
- });
116
- return declarations.join('');
117
- };
118
110
  export var getResponsiveGridColumns = function getResponsiveGridColumns(columns) {
119
111
  if (!columns) return;
120
112
  var property = 'grid-template-columns';
121
113
 
122
114
  if (isObject(columns)) {
123
- return mapColumnsToMedia(property, columns);
115
+ return mapObjToMedia(property, columns);
124
116
  }
125
117
 
126
118
  return "".concat(property, ": ").concat(columns);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",