@flodesk/grain 5.5.2 → 5.7.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
@@ -44,6 +44,6 @@ import { Text, Button, Input } from '@flodesk/grain';
44
44
  .dashboard-header {
45
45
  font-size: var(--grn-text-xl);
46
46
  margin-bottom: var(--grn-space-l);
47
- color: var(--grn-color-contentDimmed);
47
+ color: var(--grn-color-content2);
48
48
  }
49
49
  ```
@@ -4,7 +4,7 @@ import "core-js/modules/es.object.define-properties.js";
4
4
  import "core-js/modules/es.object.keys.js";
5
5
  import "core-js/modules/es.array.index-of.js";
6
6
  import "core-js/modules/es.symbol.js";
7
- var _excluded = ["children", "variant", "isDisabled", "icon", "hasFullWidth", "hasSpinner"];
7
+ var _excluded = ["children", "variant", "isDisabled", "icon", "iconPosition", "hasFullWidth", "hasSpinner"];
8
8
 
9
9
  var _templateObject, _templateObject2, _templateObject3, _templateObject4;
10
10
 
@@ -31,11 +31,13 @@ var variants = {
31
31
  primary: accentCss,
32
32
  accent: accentCss
33
33
  };
34
- var Wrapper = styled.button(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n ", ";\n appearance: none;\n border: none;\n font-family: inherit;\n font-size: inherit;\n cursor: pointer;\n border-width: 1px;\n border-style: solid;\n font-weight: ", ";\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 var(--grn-paddingX-m);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 12px;\n\n ", ";\n ", ";\n\n &:disabled {\n color: ", ";\n background-color: ", ";\n border-color: transparent;\n cursor: default;\n }\n"])), variables, transitions, getWeight('medium'), getRadius('s'), function (p) {
34
+ var Wrapper = styled.button(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n ", ";\n appearance: none;\n border: none;\n font-family: inherit;\n font-size: inherit;\n cursor: pointer;\n border-width: 1px;\n border-style: solid;\n font-weight: ", ";\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 var(--grn-paddingX-m);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 12px;\n\n ", ";\n ", ";\n\n &:disabled {\n color: ", ";\n background-color: ", ";\n border-color: transparent;\n cursor: default;\n }\n\n .buttonIcon {\n ", ";\n }\n"])), variables, transitions, getWeight('medium'), getRadius('s'), function (p) {
35
35
  return !p.isDisabled && variants[p.variant];
36
36
  }, function (p) {
37
37
  return p.hasFullWidth && "width: 100%";
38
- }, getColor('contentDisabled'), getColor('backgroundDisabled'));
38
+ }, getColor('contentDisabled'), getColor('backgroundDisabled'), function (p) {
39
+ return p.iconPosition === 'right' && "order: 1";
40
+ });
39
41
 
40
42
  var checkDeprecatedVariant = function checkDeprecatedVariant(variant) {
41
43
  if (variant === 'primary') {
@@ -49,6 +51,8 @@ export var Button = function Button(_ref) {
49
51
  variant = _ref$variant === void 0 ? 'neutral' : _ref$variant,
50
52
  isDisabled = _ref.isDisabled,
51
53
  icon = _ref.icon,
54
+ _ref$iconPosition = _ref.iconPosition,
55
+ iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
52
56
  hasFullWidth = _ref.hasFullWidth,
53
57
  hasSpinner = _ref.hasSpinner,
54
58
  props = _objectWithoutProperties(_ref, _excluded);
@@ -58,18 +62,21 @@ export var Button = function Button(_ref) {
58
62
  variant: variant,
59
63
  disabled: isDisabled,
60
64
  icon: icon,
65
+ iconPosition: iconPosition,
61
66
  hasFullWidth: hasFullWidth,
62
67
  hasSpinner: hasSpinner
63
68
  }, props), hasSpinner && /*#__PURE__*/React.createElement(Spinner, {
64
69
  color: "currentColor"
65
70
  }), icon && /*#__PURE__*/React.createElement(Icon, {
66
71
  icon: icon,
67
- color: "currentColor"
72
+ color: "currentColor",
73
+ className: "buttonIcon"
68
74
  }), children);
69
75
  };
70
76
  Button.propTypes = {
71
77
  children: PropTypes.node,
72
78
  icon: PropTypes.node,
79
+ iconPosition: PropTypes.oneOf(['left', 'right']),
73
80
  variant: PropTypes.oneOf(['neutral', 'accent']),
74
81
  onClick: PropTypes.func,
75
82
  isDisabled: PropTypes.bool,
@@ -26,7 +26,7 @@ import { css } from '@emotion/react';
26
26
  import { types } from '../types';
27
27
  var variables = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --grn-borderColor-hover: var(--grn-color-fade4);\n --grn-borderColor-active: var(--grn-color-grey8);\n --grn-width: calc(var(--grn-textBoxHeight-m) + 2px);\n"])));
28
28
  var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n border: 1px solid var(--grn-color-border);\n border-radius: var(--grn-radius-s);\n width: fit-content;\n"])));
29
- var ItemWrapper = styled.button(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", ";\n appearance: none;\n border: none;\n border-left: 1px solid transparent;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n min-width: var(--grn-width);\n height: calc(var(--grn-textBoxHeight-m) - 2px);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n color: var(--grn-color-contentDimmed);\n transition: color ", ";\n\n ", ";\n\n & + .IconToggle {\n border-color: var(--grn-color-border);\n }\n\n &:after {\n content: '';\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n transition: ", ";\n ", ";\n }\n\n &:first-of-type {\n min-width: calc(var(--grn-width) - 1px);\n }\n\n &:first-of-type:after {\n width: calc(100% + 1px);\n left: -1px;\n border-radius: var(--grn-radius-s) 0 0 var(--grn-radius-s);\n }\n\n &:last-child:after {\n border-radius: 0 var(--grn-radius-s) var(--grn-radius-s) 0;\n }\n\n &:hover {\n color: var(--grn-color-content);\n }\n"])), variables, getWeight('medium'), getTransition('fast'), function (p) {
29
+ var ItemWrapper = styled.button(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", ";\n appearance: none;\n border: none;\n border-left: 1px solid transparent;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n min-width: var(--grn-width);\n height: calc(var(--grn-textBoxHeight-m) - 2px);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n position: relative;\n color: var(--grn-color-content2);\n transition: color ", ";\n\n ", ";\n\n & + .IconToggle {\n border-color: var(--grn-color-border);\n }\n\n &:after {\n content: '';\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n transition: ", ";\n ", ";\n }\n\n &:first-of-type {\n min-width: calc(var(--grn-width) - 1px);\n }\n\n &:first-of-type:after {\n width: calc(100% + 1px);\n left: -1px;\n border-radius: var(--grn-radius-s) 0 0 var(--grn-radius-s);\n }\n\n &:last-child:after {\n border-radius: 0 var(--grn-radius-s) var(--grn-radius-s) 0;\n }\n\n &:hover {\n color: var(--grn-color-content);\n }\n"])), variables, getWeight('medium'), getTransition('fast'), function (p) {
30
30
  return p.isActive && "\n color: var(--grn-color-content);\n ";
31
31
  }, getTransition('xFast'), function (p) {
32
32
  return p.isActive && "box-shadow: 0 0 0 1px var(--grn-color-grey6)";
@@ -11,4 +11,5 @@ export { IconToggleGroup, IconToggle } from './icon-toggle';
11
11
  export { TextToggleGroup, TextToggle } from './text-toggle';
12
12
  export { Stack } from './stack';
13
13
  export { Slider } from './slider';
14
- export { Spinner } from './spinner';
14
+ export { Spinner } from './spinner';
15
+ export { Switch } from './switch';
@@ -0,0 +1,68 @@
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 = ["isDisabled", "isActive", "label", "id", "onChange"];
8
+
9
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
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 { getColor, getTransition } from '../utilities';
18
+ import React from 'react';
19
+ import styled from '@emotion/styled';
20
+ import PropTypes from 'prop-types';
21
+ var knobSizePx = 16;
22
+ var trackOffset = 2;
23
+ var trackWidth = 40;
24
+ var trackHeight = knobSizePx + trackOffset * 2;
25
+ var trackInactiveColor = getColor('grey3');
26
+ var trackActiveColor = getColor('content');
27
+ var Input = styled.input(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n opacity: 0;\n\n &:checked ~ .Track {\n background-color: ", ";\n\n .Knob {\n transform: translateX(", "px);\n }\n }\n"])), function (p) {
28
+ return p.disabled ? getColor('backgroundDisabled') : trackActiveColor;
29
+ }, trackWidth - knobSizePx - trackOffset * 2);
30
+ var Track = styled.label(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n height: ", "px;\n width: ", "px;\n display: block;\n position: relative;\n border-radius: 1000px;\n transition: ", ";\n cursor: pointer;\n background-color: ", ";\n"])), trackHeight, trackWidth, getTransition('xFast'), function (p) {
31
+ return p.isDisabled ? getColor('backgroundDisabled') : trackInactiveColor;
32
+ });
33
+ var Knob = styled.span(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: absolute;\n left: ", "px;\n top: ", "px;\n height: ", "px;\n width: ", "px;\n border-radius: 100%;\n background-color: ", ";\n display: block;\n transition: ", ";\n"])), trackOffset, trackOffset, knobSizePx, knobSizePx, function (p) {
34
+ return p.isDisabled ? getColor('contentDisabled') : 'white';
35
+ }, getTransition('xFast'));
36
+ var Wrapper = styled.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n align-items: center;\n width: fit-content;\n gap: 8px;\n"])));
37
+ export var Switch = function Switch(_ref) {
38
+ var isDisabled = _ref.isDisabled,
39
+ isActive = _ref.isActive,
40
+ label = _ref.label,
41
+ id = _ref.id,
42
+ onChange = _ref.onChange,
43
+ props = _objectWithoutProperties(_ref, _excluded);
44
+
45
+ return /*#__PURE__*/React.createElement(Wrapper, props, /*#__PURE__*/React.createElement(Input, {
46
+ type: "checkbox",
47
+ disabled: isDisabled,
48
+ id: id,
49
+ checked: isActive,
50
+ onChange: onChange
51
+ }), /*#__PURE__*/React.createElement(Track, {
52
+ htmlFor: id,
53
+ className: "Track",
54
+ isDisabled: isDisabled
55
+ }, /*#__PURE__*/React.createElement(Knob, {
56
+ className: "Knob",
57
+ isDisabled: isDisabled
58
+ })), label && /*#__PURE__*/React.createElement("label", {
59
+ htmlFor: id
60
+ }, label));
61
+ };
62
+ Switch.propTypes = {
63
+ id: PropTypes.string.isRequired,
64
+ onChange: PropTypes.func,
65
+ isDisabled: PropTypes.bool,
66
+ isActive: PropTypes.bool,
67
+ label: PropTypes.string
68
+ };
@@ -25,7 +25,7 @@ import { types } from '../types';
25
25
  var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n gap: var(--grn-space-l);\n width: fit-content;\n align-items: stretch;\n height: ", ";\n"])), function (p) {
26
26
  return getDimension(p.height);
27
27
  });
28
- var TabWrapper = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n appearance: none;\n border: none;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n height: 100%;\n background-color: transparent;\n color: var(--grn-color-contentDimmed);\n border-radius: 0;\n white-space: nowrap;\n transition: color ", ", box-shadow ", ";\n\n &:hover {\n color: var(--grn-color-content);\n }\n\n ", ";\n"])), getWeight('medium'), getTransition('fast'), getTransition('xFast'), function (p) {
28
+ var TabWrapper = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n appearance: none;\n border: none;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n height: 100%;\n background-color: transparent;\n color: var(--grn-color-content2);\n border-radius: 0;\n white-space: nowrap;\n transition: color ", ", box-shadow ", ";\n\n &:hover {\n color: var(--grn-color-content);\n }\n\n ", ";\n"])), getWeight('medium'), getTransition('fast'), getTransition('xFast'), function (p) {
29
29
  return p.isActive && "\n box-shadow: inset 0 -2px 0 var(--grn-color-grey6);\n color: var(--grn-color-content);\n ";
30
30
  });
31
31
  export var Tab = function Tab(_ref) {
@@ -22,7 +22,7 @@ import React from 'react';
22
22
  import styled from '@emotion/styled';
23
23
  import PropTypes from 'prop-types';
24
24
  var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n border: 1px solid var(--grn-color-border);\n border-radius: 1000px;\n width: fit-content;\n"])));
25
- var ItemWrapper = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n appearance: none;\n border: none;\n padding: 0 16px;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n height: calc(var(--grn-textBoxHeight-m) - 2px);\n background-color: transparent;\n position: relative;\n color: var(--grn-color-contentDimmed);\n border-radius: 1000px;\n white-space: nowrap;\n transition: color ", ", box-shadow ", ";\n\n &:hover {\n color: var(--grn-color-content);\n }\n\n ", ";\n"])), getWeight('medium'), getTransition('fast'), getTransition('xFast'), function (p) {
25
+ var ItemWrapper = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n appearance: none;\n border: none;\n padding: 0 16px;\n font-family: inherit;\n font-size: inherit;\n font-weight: ", ";\n cursor: pointer;\n height: calc(var(--grn-textBoxHeight-m) - 2px);\n background-color: transparent;\n position: relative;\n color: var(--grn-color-content2);\n border-radius: 1000px;\n white-space: nowrap;\n transition: color ", ", box-shadow ", ";\n\n &:hover {\n color: var(--grn-color-content);\n }\n\n ", ";\n"])), getWeight('medium'), getTransition('fast'), getTransition('xFast'), function (p) {
26
26
  return p.isActive && "\n box-shadow: 0 0 0 1px var(--grn-color-grey6);\n color: var(--grn-color-content);\n ";
27
27
  });
28
28
  export var TextToggle = function TextToggle(_ref) {
package/es/types.js CHANGED
@@ -19,7 +19,7 @@ export var types = {
19
19
  textAlign: PropTypes.oneOf(['left', 'center', 'right']),
20
20
  overflow: PropTypes.oneOf(['visible', 'hidden', 'scroll', 'auto']),
21
21
  fieldSize: PropTypes.oneOf(['s', 'm']),
22
- textTag: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span']),
22
+ textTag: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'label']),
23
23
  responsiveColumns: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
24
24
  autoFlow: PropTypes.oneOf(autoFlows),
25
25
  gridItemsAlignment: PropTypes.oneOf(gridItemsAlignments),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "5.5.2",
3
+ "version": "5.7.0",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",