@flodesk/grain 5.7.0 → 5.8.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.
@@ -9,6 +9,7 @@ export { Tab, TabGroup } from './tab';
9
9
  export { TextButton } from './text-button';
10
10
  export { IconToggleGroup, IconToggle } from './icon-toggle';
11
11
  export { TextToggleGroup, TextToggle } from './text-toggle';
12
+ export { Select } from './select';
12
13
  export { Stack } from './stack';
13
14
  export { Slider } from './slider';
14
15
  export { Spinner } from './spinner';
@@ -0,0 +1,121 @@
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
+ import "core-js/modules/es.symbol.description.js";
8
+ import "core-js/modules/es.object.to-string.js";
9
+ import "core-js/modules/es.symbol.iterator.js";
10
+ import "core-js/modules/es.array.iterator.js";
11
+ import "core-js/modules/es.string.iterator.js";
12
+ import "core-js/modules/web.dom-collections.iterator.js";
13
+ import "core-js/modules/es.array.from.js";
14
+ import "core-js/modules/es.regexp.exec.js";
15
+ var _excluded = ["children"],
16
+ _excluded2 = ["children", "isSelected", "isActive"];
17
+
18
+ var _templateObject, _templateObject2, _templateObject3;
19
+
20
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
+
22
+ 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."); }
23
+
24
+ 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); }
25
+
26
+ 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; }
27
+
28
+ 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; }
29
+
30
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
+
32
+ import "core-js/modules/es.object.assign.js";
33
+ import "core-js/modules/es.array.map.js";
34
+
35
+ 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; }
36
+
37
+ 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; }
38
+
39
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
40
+
41
+ import PropTypes from 'prop-types';
42
+ import React, { useState } from 'react';
43
+ import styled from '@emotion/styled';
44
+ import { Icon, Box, Text } from '.';
45
+ import { IconCheck, IconChevronDown } from '../icons';
46
+ import { Listbox } from '@headlessui/react';
47
+ import { getColor, getRadius, getShadow } from '../utilities';
48
+ var Options = styled(Listbox.Options)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 8px;\n margin: 0;\n position: absolute;\n background: white;\n box-shadow: ", ";\n border-radius: ", ";\n max-height: 468px;\n min-width: 160px;\n max-width: 240px;\n overflow: auto;\n\n &:focus {\n outline: none;\n }\n"])), getShadow('m'), getRadius('s'));
49
+ var SelectButtonWrapper = styled(Listbox.Button)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n gap: 8px;\n appearance: none;\n border: none;\n background: ", ";\n padding: 0 var(--grn-fieldXPadding);\n min-height: var(--grn-textBoxHeight-m);\n border-radius: ", ";\n font: inherit;\n color: inherit;\n cursor: pointer;\n max-width: 100%;\n text-align: left;\n"])), getColor('fade1'), getRadius('s'));
50
+
51
+ var SelectButton = function SelectButton(_ref) {
52
+ var children = _ref.children,
53
+ props = _objectWithoutProperties(_ref, _excluded);
54
+
55
+ return /*#__PURE__*/React.createElement(SelectButtonWrapper, props, /*#__PURE__*/React.createElement(Text, {
56
+ hasEllipsis: true,
57
+ weight: "medium"
58
+ }, children), /*#__PURE__*/React.createElement(Icon, {
59
+ icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
60
+ }));
61
+ };
62
+
63
+ var MenuItemWrapper = styled.li(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n gap: 8px;\n align-items: center;\n list-style: none;\n padding: 0 1rem;\n min-height: var(--grn-textBoxHeight-m);\n cursor: pointer;\n border-radius: ", ";\n"])), getRadius('s'));
64
+ var MenuItem = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
65
+ var children = _ref2.children,
66
+ isSelected = _ref2.isSelected,
67
+ isActive = _ref2.isActive,
68
+ props = _objectWithoutProperties(_ref2, _excluded2);
69
+
70
+ return /*#__PURE__*/React.createElement(MenuItemWrapper, Object.assign({
71
+ ref: ref,
72
+ isActive: isActive,
73
+ style: {
74
+ background: isActive ? getColor('overlay') : undefined
75
+ }
76
+ }, props), /*#__PURE__*/React.createElement(Text, {
77
+ hasEllipsis: true
78
+ }, children), isSelected && /*#__PURE__*/React.createElement(Box, {
79
+ marginLeft: "auto"
80
+ }, /*#__PURE__*/React.createElement(Icon, {
81
+ icon: /*#__PURE__*/React.createElement(IconCheck, null)
82
+ })));
83
+ });
84
+ export var Select = function Select(_ref3) {
85
+ var options = _ref3.options,
86
+ defaultOption = _ref3.defaultOption,
87
+ onChange = _ref3.onChange;
88
+
89
+ var _useState = useState(defaultOption || options[0]),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ selectedOption = _useState2[0],
92
+ setSelectedOption = _useState2[1];
93
+
94
+ var handleChange = function handleChange(option) {
95
+ setSelectedOption(option);
96
+ onChange && onChange(option);
97
+ };
98
+
99
+ return /*#__PURE__*/React.createElement(Listbox, {
100
+ value: selectedOption,
101
+ onChange: handleChange
102
+ }, /*#__PURE__*/React.createElement(SelectButton, null, selectedOption.content), /*#__PURE__*/React.createElement(Options, null, options.map(function (option, index) {
103
+ return /*#__PURE__*/React.createElement(Listbox.Option, {
104
+ key: index,
105
+ value: option,
106
+ as: React.Fragment
107
+ }, function (_ref4) {
108
+ var active = _ref4.active,
109
+ selected = _ref4.selected;
110
+ return /*#__PURE__*/React.createElement(MenuItem, {
111
+ isSelected: selected,
112
+ isActive: active
113
+ }, option.content);
114
+ });
115
+ })));
116
+ };
117
+ Select.propTypes = {
118
+ options: PropTypes.array,
119
+ defaultOption: PropTypes.object,
120
+ onChange: PropTypes.func
121
+ };
@@ -6,7 +6,7 @@ import "core-js/modules/es.array.index-of.js";
6
6
  import "core-js/modules/es.symbol.js";
7
7
  var _excluded = ["min", "max", "value", "step", "onChange"];
8
8
 
9
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
9
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
10
10
 
11
11
  import "core-js/modules/es.object.assign.js";
12
12
 
@@ -23,7 +23,8 @@ import { css } from '@emotion/react';
23
23
  var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --trackHeight: 2px;\n --sliderHeight: 16px;\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-content) 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
24
  var trackStyles = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 100%;\n height: var(--sliderHeight);\n cursor: pointer;\n background: transparent;\n"])));
25
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-content);\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);
26
+ var thumbFocusStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n box-shadow: 0 0 0 2px white, 0 0 0 4px var(--grn-color-selection);\n"])));
27
+ var InputWrapper = styled.input(_templateObject5 || (_templateObject5 = _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\n &::-moz-range-track {\n ", "\n }\n\n &::-webkit-slider-thumb {\n ", "\n }\n\n &::-moz-range-thumb {\n ", "\n }\n\n &:focus-visible::-webkit-slider-thumb {\n ", "\n }\n\n &:focus-visible::-moz-range-thumb {\n ", "\n }\n\n &:focus {\n outline: none;\n }\n"])), trackStyles, trackStyles, thumbStyles, thumbStyles, thumbFocusStyles, thumbFocusStyles);
27
28
  export var Slider = function Slider(_ref) {
28
29
  var _ref$min = _ref.min,
29
30
  min = _ref$min === void 0 ? 0 : _ref$min,
@@ -6,7 +6,7 @@ import "core-js/modules/es.array.index-of.js";
6
6
  import "core-js/modules/es.symbol.js";
7
7
  var _excluded = ["isDisabled", "isActive", "label", "id", "onChange"];
8
8
 
9
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
9
+ var _templateObject, _templateObject2;
10
10
 
11
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
12
 
@@ -22,18 +22,14 @@ var knobSizePx = 16;
22
22
  var trackOffset = 2;
23
23
  var trackWidth = 40;
24
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"])));
25
+ var Input = styled.input(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --trackInactiveColor: ", ";\n --trackActiveColor: ", ";\n --knobColor: ", ";\n\n appearance: none;\n height: ", "px;\n width: ", "px;\n display: block;\n border-radius: 1000px;\n transition: background-color ", ";\n cursor: pointer;\n margin: 0;\n position: relative;\n background-color: var(--trackInactiveColor);\n\n &:checked {\n background-color: var(--trackActiveColor);\n }\n\n &:after {\n content: '';\n position: absolute;\n left: ", "px;\n top: ", "px;\n height: ", "px;\n width: ", "px;\n border-radius: 100%;\n background-color: var(--knobColor);\n display: block;\n transition: transform ", ";\n pointer-events: none;\n }\n\n &:checked:after {\n transform: translateX(", "px);\n }\n"])), function (p) {
26
+ return getColor(p.disabled ? 'backgroundDisabled' : 'grey3');
27
+ }, function (p) {
28
+ return getColor(p.disabled ? 'backgroundDisabled' : 'content');
29
+ }, function (p) {
30
+ return p.disabled ? getColor('contentDisabled') : 'white';
31
+ }, trackHeight, trackWidth, getTransition('xFast'), trackOffset, trackOffset, knobSizePx, knobSizePx, getTransition('xFast'), trackWidth - knobSizePx - trackOffset * 2);
32
+ var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n align-items: center;\n width: fit-content;\n gap: 8px;\n"])));
37
33
  export var Switch = function Switch(_ref) {
38
34
  var isDisabled = _ref.isDisabled,
39
35
  isActive = _ref.isActive,
@@ -48,14 +44,7 @@ export var Switch = function Switch(_ref) {
48
44
  id: id,
49
45
  checked: isActive,
50
46
  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", {
47
+ }), label && /*#__PURE__*/React.createElement("label", {
59
48
  htmlFor: id
60
49
  }, label));
61
50
  };
@@ -44,7 +44,7 @@ import { css } from '@emotion/react';
44
44
  import { Box, Text } from '.';
45
45
  import { Icon } from './icon';
46
46
  import { transitions } from '../foundational';
47
- var variables = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --grn-fieldBorderColor: var(--grn-color-fade3);\n --grn-fieldBorderColor-hover: var(--grn-color-fade6);\n --grn-fieldBorderColor-focus: var(--grn-color-grey6);\n --grn-fieldXPadding: 12px;\n"])));
47
+ var variables = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --grn-fieldBorderColor: var(--grn-color-fade3);\n --grn-fieldBorderColor-hover: var(--grn-color-fade6);\n --grn-fieldBorderColor-focus: var(--grn-color-grey6);\n"])));
48
48
  var iconOffsetPx = 12;
49
49
  var iconTextGapPx = 8;
50
50
  var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n"])), variables);
@@ -2,8 +2,8 @@
2
2
  @import './components-variables.css';
3
3
 
4
4
  :root {
5
- --grn-letterSpacing-fixed: 1.3px;
6
- --grn-letterSpacing-relative: 0.07em;
5
+ --grn-letterSpacing-fixed: 1px;
6
+ --grn-letterSpacing-relative: 0.06em;
7
7
  --grn-letterSpacing-global: calc(var(--grn-letterSpacing-fixed) - var(--grn-letterSpacing-relative));
8
8
 
9
9
  --grn-lineHeight-fixed: 7px;
@@ -2,4 +2,5 @@
2
2
  --grn-textBoxHeight-s: 28px;
3
3
  --grn-textBoxHeight-m: 40px;
4
4
  --grn-clearButtonHeight-m: 36px;
5
+ --grn-fieldXPadding: 12px;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",
@@ -23,6 +23,7 @@
23
23
  "dependencies": {
24
24
  "@emotion/react": "^11.9.0",
25
25
  "@emotion/styled": "^11.8.1",
26
+ "@headlessui/react": "^1.6.6",
26
27
  "core-js": "^3.22.8",
27
28
  "prop-types": "^15.8.1"
28
29
  },