@flodesk/grain 5.5.3 → 5.7.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.
@@ -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,
@@ -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,63 @@
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;
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 appearance: none;\n height: ", "px;\n width: ", "px;\n background-color: ", ";\n display: block;\n border-radius: 1000px;\n transition: ", ";\n cursor: pointer;\n margin: 0;\n\n &:checked {\n background-color: ", ";\n\n & ~ .Knob {\n transform: translateX(", "px);\n }\n }\n"])), trackHeight, trackWidth, function (p) {
28
+ return p.isDisabled ? getColor('backgroundDisabled') : trackInactiveColor;
29
+ }, getTransition('xFast'), function (p) {
30
+ return p.disabled ? getColor('backgroundDisabled') : trackActiveColor;
31
+ }, trackWidth - knobSizePx - trackOffset * 2);
32
+ var Knob = styled.span(_templateObject2 || (_templateObject2 = _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 pointer-events: none;\n"])), trackOffset, trackOffset, knobSizePx, knobSizePx, function (p) {
33
+ return p.isDisabled ? getColor('contentDisabled') : 'white';
34
+ }, getTransition('xFast'));
35
+ var Wrapper = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n align-items: center;\n width: fit-content;\n gap: 8px;\n position: relative;\n"])));
36
+ export var Switch = function Switch(_ref) {
37
+ var isDisabled = _ref.isDisabled,
38
+ isActive = _ref.isActive,
39
+ label = _ref.label,
40
+ id = _ref.id,
41
+ onChange = _ref.onChange,
42
+ props = _objectWithoutProperties(_ref, _excluded);
43
+
44
+ return /*#__PURE__*/React.createElement(Wrapper, props, /*#__PURE__*/React.createElement(Input, {
45
+ type: "checkbox",
46
+ disabled: isDisabled,
47
+ id: id,
48
+ checked: isActive,
49
+ onChange: onChange
50
+ }), /*#__PURE__*/React.createElement(Knob, {
51
+ className: "Knob",
52
+ isDisabled: isDisabled
53
+ }), label && /*#__PURE__*/React.createElement("label", {
54
+ htmlFor: id
55
+ }, label));
56
+ };
57
+ Switch.propTypes = {
58
+ id: PropTypes.string.isRequired,
59
+ onChange: PropTypes.func,
60
+ isDisabled: PropTypes.bool,
61
+ isActive: PropTypes.bool,
62
+ label: PropTypes.string
63
+ };
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.3",
3
+ "version": "5.7.1",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",