@flodesk/grain 5.8.0 → 5.9.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.
@@ -1,44 +1,25 @@
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
1
  import "core-js/modules/es.object.keys.js";
5
2
  import "core-js/modules/es.array.index-of.js";
6
3
  import "core-js/modules/es.symbol.js";
7
- var _excluded = ["children", "gap", "alignItems", "justifyItems", "justifyContent", "alignContent", "columns", "autoFlow", "width", "height"];
4
+ import "core-js/modules/es.array.slice.js";
5
+ import "core-js/modules/es.object.freeze.js";
6
+ import "core-js/modules/es.object.define-properties.js";
8
7
 
9
8
  var _templateObject;
10
9
 
10
+ var _excluded = ["children", "gap", "alignItems", "justifyItems", "justifyContent", "alignContent", "columns", "autoFlow", "width", "height"];
11
11
  import "core-js/modules/es.object.assign.js";
12
12
 
13
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
14
+
13
15
  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
16
 
15
17
  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
18
 
17
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
18
-
19
19
  import { getResponsiveDimension, getResponsiveGridColumns, getResponsiveSpace } from '../utilities';
20
20
  import React from 'react';
21
- import styled from '@emotion/styled';
21
+ import { css } from '@emotion/react';
22
22
  import { types } from '../types';
23
- var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: grid;\n ", ";\n ", ";\n ", ";\n justify-items: ", ";\n align-items: ", ";\n justify-content: ", ";\n align-content: ", ";\n ", ";\n ", ";\n"])), function (p) {
24
- return !p.columns && "grid-auto-flow: ".concat(p.autoFlow);
25
- }, function (p) {
26
- return getResponsiveSpace('gap', p.gap);
27
- }, function (p) {
28
- return getResponsiveGridColumns(p.columns);
29
- }, function (p) {
30
- return p.justifyItems;
31
- }, function (p) {
32
- return p.alignItems;
33
- }, function (p) {
34
- return p.justifyContent;
35
- }, function (p) {
36
- return p.alignContent;
37
- }, function (p) {
38
- return getResponsiveDimension('width', p.width);
39
- }, function (p) {
40
- return getResponsiveDimension('height', p.height);
41
- });
42
23
  export var Arrange = function Arrange(_ref) {
43
24
  var children = _ref.children,
44
25
  gap = _ref.gap,
@@ -55,16 +36,8 @@ export var Arrange = function Arrange(_ref) {
55
36
  height = _ref.height,
56
37
  props = _objectWithoutProperties(_ref, _excluded);
57
38
 
58
- return /*#__PURE__*/React.createElement(Wrapper, Object.assign({
59
- gap: gap,
60
- columns: columns,
61
- autoFlow: autoFlow,
62
- alignItems: alignItems,
63
- justifyItems: justifyItems,
64
- justifyContent: justifyContent,
65
- alignContent: alignContent,
66
- width: width,
67
- height: height
39
+ return /*#__PURE__*/React.createElement("div", Object.assign({
40
+ css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: grid;\n ", ";\n ", ";\n ", ";\n justify-items: ", ";\n align-items: ", ";\n justify-content: ", ";\n align-content: ", ";\n ", ";\n ", ";\n "])), !columns && "grid-auto-flow: ".concat(autoFlow), getResponsiveSpace('gap', gap), getResponsiveGridColumns(columns), justifyItems, alignItems, justifyContent, alignContent, getResponsiveDimension('width', width), getResponsiveDimension('height', height))
68
41
  }, props), children);
69
42
  };
70
43
  Arrange.propTypes = {
@@ -0,0 +1,138 @@
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.symbol.js";
5
+ import "core-js/modules/es.symbol.description.js";
6
+ import "core-js/modules/es.symbol.iterator.js";
7
+ import "core-js/modules/es.array.iterator.js";
8
+ import "core-js/modules/es.string.iterator.js";
9
+ import "core-js/modules/web.dom-collections.iterator.js";
10
+ import "core-js/modules/es.array.from.js";
11
+ import "core-js/modules/es.regexp.exec.js";
12
+
13
+ var _templateObject;
14
+
15
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
+
17
+ 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."); }
18
+
19
+ 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); }
20
+
21
+ 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; }
22
+
23
+ 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; }
24
+
25
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
+
27
+ import "core-js/modules/es.object.assign.js";
28
+ import "core-js/modules/es.array.filter.js";
29
+ import "core-js/modules/es.object.to-string.js";
30
+ import "core-js/modules/es.array.includes.js";
31
+ import "core-js/modules/es.string.includes.js";
32
+ import "core-js/modules/es.array.map.js";
33
+
34
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
35
+
36
+ import PropTypes from 'prop-types';
37
+ import React, { useState } from 'react';
38
+ import styled from '@emotion/styled';
39
+ import { Icon, Box, Text } from '.';
40
+ import { IconChevronDown } from '../icons';
41
+ import { Combobox } from '@headlessui/react';
42
+ import { types } from '../types';
43
+ import { fieldStyles, fieldXPadding, focusFieldStyles, Menu, MenuItem } from '../foundational';
44
+ var Input = styled(Combobox.Input)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n ", ";\n"])), fieldStyles({
45
+ paddingRight: '32px'
46
+ }), focusFieldStyles);
47
+
48
+ var Root = function Root(_ref) {
49
+ var props = Object.assign({}, _ref);
50
+ return /*#__PURE__*/React.createElement(Box, Object.assign({}, props, {
51
+ position: "relative"
52
+ }));
53
+ };
54
+
55
+ var Trigger = function Trigger(_ref2) {
56
+ var props = Object.assign({}, _ref2);
57
+ return /*#__PURE__*/React.createElement(Box, Object.assign({}, props, {
58
+ position: "relative"
59
+ }));
60
+ };
61
+
62
+ var EmptyState = function EmptyState() {
63
+ return /*#__PURE__*/React.createElement(Box, {
64
+ padding: "s"
65
+ }, /*#__PURE__*/React.createElement(Text, {
66
+ color: "content2"
67
+ }, "No results"));
68
+ };
69
+
70
+ export var Autocomplete = function Autocomplete(_ref3) {
71
+ var options = _ref3.options,
72
+ defaultOption = _ref3.defaultOption,
73
+ onChange = _ref3.onChange;
74
+
75
+ var _useState = useState(defaultOption || {}),
76
+ _useState2 = _slicedToArray(_useState, 2),
77
+ selectedOption = _useState2[0],
78
+ setSelectedOption = _useState2[1];
79
+
80
+ var _useState3 = useState(''),
81
+ _useState4 = _slicedToArray(_useState3, 2),
82
+ query = _useState4[0],
83
+ setQuery = _useState4[1];
84
+
85
+ var handleChange = function handleChange(option) {
86
+ setSelectedOption(option);
87
+ onChange && onChange(option);
88
+ setQuery('');
89
+ };
90
+
91
+ var filteredOptions = query === '' ? options : options.filter(function (option) {
92
+ return option.value.toLowerCase().includes(query.toLowerCase());
93
+ });
94
+ return /*#__PURE__*/React.createElement(Combobox, {
95
+ as: Root,
96
+ value: selectedOption,
97
+ onChange: handleChange
98
+ }, /*#__PURE__*/React.createElement(Combobox.Button, {
99
+ as: Trigger
100
+ }, /*#__PURE__*/React.createElement(Input, {
101
+ autocomplete: "off",
102
+ onChange: function onChange(event) {
103
+ return setQuery(event.target.value);
104
+ },
105
+ placeholder: "Start typing"
106
+ }), /*#__PURE__*/React.createElement(Box, {
107
+ right: fieldXPadding,
108
+ position: "absolute",
109
+ top: "0px",
110
+ bottom: "0px",
111
+ margin: "auto",
112
+ height: "fit-content"
113
+ }, /*#__PURE__*/React.createElement(Icon, {
114
+ icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
115
+ }))), /*#__PURE__*/React.createElement(Combobox.Options, {
116
+ as: Menu
117
+ }, filteredOptions.map(function (option, index) {
118
+ return /*#__PURE__*/React.createElement(Combobox.Option, {
119
+ key: index,
120
+ value: option.value,
121
+ as: React.Fragment
122
+ }, function (_ref4) {
123
+ var active = _ref4.active,
124
+ selected = _ref4.selected;
125
+ return /*#__PURE__*/React.createElement(MenuItem, {
126
+ isSelected: selected,
127
+ isActive: active
128
+ }, option.content);
129
+ });
130
+ }), !Boolean(filteredOptions.length) && /*#__PURE__*/React.createElement(EmptyState, null)));
131
+ };
132
+ Autocomplete.propTypes = {
133
+ options: PropTypes.array,
134
+ defaultOption: PropTypes.object,
135
+ onChange: PropTypes.func,
136
+ menuAlign: PropTypes.oneOf(['left', 'right']),
137
+ menuWidth: types.dimension
138
+ };
@@ -1,86 +1,27 @@
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
1
  import "core-js/modules/es.object.keys.js";
5
2
  import "core-js/modules/es.array.index-of.js";
6
3
  import "core-js/modules/es.symbol.js";
7
- var _excluded = ["children", "color", "backgroundColor", "borderColor", "borderWidth", "borderSide", "width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "radius", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY", "position", "top", "bottom", "left", "right", "shadow", "overflow", "aspectRatio", "zIndex"];
4
+ import "core-js/modules/es.array.slice.js";
5
+ import "core-js/modules/es.object.freeze.js";
6
+ import "core-js/modules/es.object.define-properties.js";
8
7
 
9
8
  var _templateObject;
10
9
 
10
+ var _excluded = ["children", "color", "backgroundColor", "borderColor", "borderWidth", "borderSide", "width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "radius", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY", "position", "top", "bottom", "left", "right", "shadow", "overflow", "aspectRatio", "zIndex"];
11
11
  import "core-js/modules/es.object.assign.js";
12
12
 
13
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
14
+
13
15
  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
16
 
15
17
  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
18
 
17
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
18
-
19
19
  import { getBorder, getColor, getRadius, getResponsiveSpace, getShadow, getResponsiveDimension } from '../utilities';
20
- import React from 'react';
21
- import styled from '@emotion/styled';
20
+ import React, { forwardRef } from 'react';
21
+ import { css } from '@emotion/react';
22
22
  import { types } from '../types';
23
23
  import PropTypes from 'prop-types';
24
- var Wrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n color: ", ";\n background-color: ", ";\n\n position: ", ";\n border-radius: ", ";\n box-shadow: ", ";\n overflow: ", ";\n aspect-ratio: ", ";\n ", ";\n"])), function (p) {
25
- return getBorder(p.borderSide, p.borderWidth, p.borderColor);
26
- }, function (p) {
27
- return getResponsiveSpace('padding', p.padding);
28
- }, function (p) {
29
- return getResponsiveSpace('padding-top', p.paddingTop);
30
- }, function (p) {
31
- return getResponsiveSpace('padding-bottom', p.paddingBottom);
32
- }, function (p) {
33
- return getResponsiveSpace('padding-left', p.paddingLeft);
34
- }, function (p) {
35
- return getResponsiveSpace('padding-right', p.paddingRight);
36
- }, function (p) {
37
- return getResponsiveSpace('margin', p.margin);
38
- }, function (p) {
39
- return getResponsiveSpace('margin-top', p.marginTop);
40
- }, function (p) {
41
- return getResponsiveSpace('margin-bottom', p.marginBottom);
42
- }, function (p) {
43
- return getResponsiveSpace('margin-left', p.marginLeft);
44
- }, function (p) {
45
- return getResponsiveSpace('margin-right', p.marginRight);
46
- }, function (p) {
47
- return getResponsiveSpace('top', p.top);
48
- }, function (p) {
49
- return getResponsiveSpace('bottom', p.bottom);
50
- }, function (p) {
51
- return getResponsiveSpace('left', p.left);
52
- }, function (p) {
53
- return getResponsiveSpace('right', p.right);
54
- }, function (p) {
55
- return getResponsiveDimension('width', p.width);
56
- }, function (p) {
57
- return getResponsiveDimension('min-width', p.minWidth);
58
- }, function (p) {
59
- return getResponsiveDimension('max-width', p.maxWidth);
60
- }, function (p) {
61
- return getResponsiveDimension('height', p.height);
62
- }, function (p) {
63
- return getResponsiveDimension('min-height', p.minHeight);
64
- }, function (p) {
65
- return getResponsiveDimension('max-height', p.maxHeight);
66
- }, function (p) {
67
- return getColor(p.color);
68
- }, function (p) {
69
- return getColor(p.backgroundColor);
70
- }, function (p) {
71
- return p.position;
72
- }, function (p) {
73
- return getRadius(p.radius);
74
- }, function (p) {
75
- return getShadow(p.shadow);
76
- }, function (p) {
77
- return p.overflow;
78
- }, function (p) {
79
- return p.aspectRatio;
80
- }, function (p) {
81
- return p.zIndex && "z-index: ".concat(p.zIndex);
82
- });
83
- export var Box = function Box(_ref) {
24
+ export var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
84
25
  var children = _ref.children,
85
26
  color = _ref.color,
86
27
  backgroundColor = _ref.backgroundColor,
@@ -121,40 +62,11 @@ export var Box = function Box(_ref) {
121
62
  zIndex = _ref.zIndex,
122
63
  props = _objectWithoutProperties(_ref, _excluded);
123
64
 
124
- return /*#__PURE__*/React.createElement(Wrapper, Object.assign({
125
- backgroundColor: backgroundColor,
126
- color: color,
127
- borderSide: borderSide,
128
- borderWidth: borderWidth,
129
- borderColor: borderColor,
130
- width: width,
131
- minWidth: minWidth,
132
- maxWidth: maxWidth,
133
- height: height,
134
- minHeight: minHeight,
135
- maxHeight: maxHeight,
136
- radius: radius,
137
- padding: padding,
138
- paddingTop: paddingY || paddingTop,
139
- paddingBottom: paddingY || paddingBottom,
140
- paddingLeft: paddingX || paddingLeft,
141
- paddingRight: paddingX || paddingRight,
142
- margin: margin,
143
- marginTop: marginY || marginTop,
144
- marginBottom: marginY || marginBottom,
145
- marginLeft: marginX || marginLeft,
146
- marginRight: marginX || marginRight,
147
- position: position,
148
- top: top,
149
- bottom: bottom,
150
- left: left,
151
- right: right,
152
- shadow: shadow,
153
- overflow: overflow,
154
- aspectRatio: aspectRatio,
155
- zIndex: zIndex
65
+ return /*#__PURE__*/React.createElement("div", Object.assign({
66
+ ref: ref,
67
+ css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n color: ", ";\n background-color: ", ";\n position: ", ";\n border-radius: ", ";\n box-shadow: ", ";\n overflow: ", ";\n aspect-ratio: ", ";\n z-index: ", ";\n "])), getBorder(borderSide, borderWidth, borderColor), getResponsiveSpace('padding', padding), getResponsiveSpace('padding-top', paddingTop), getResponsiveSpace('padding-bottom', paddingBottom), getResponsiveSpace('padding-left', paddingLeft), getResponsiveSpace('padding-right', paddingRight), getResponsiveSpace('margin', margin), getResponsiveSpace('margin-top', marginTop), getResponsiveSpace('margin-bottom', marginBottom), getResponsiveSpace('margin-left', marginLeft), getResponsiveSpace('margin-right', marginRight), getResponsiveSpace('top', top), getResponsiveSpace('bottom', bottom), getResponsiveSpace('left', left), getResponsiveSpace('right', right), getResponsiveDimension('width', width), getResponsiveDimension('min-width', minWidth), getResponsiveDimension('max-width', maxWidth), getResponsiveDimension('height', height), getResponsiveDimension('min-height', minHeight), getResponsiveDimension('max-height', maxHeight), getColor(color), getColor(backgroundColor), position, getRadius(radius), getShadow(shadow), overflow, aspectRatio, zIndex)
156
68
  }, props), children);
157
- };
69
+ });
158
70
  Box.propTypes = {
159
71
  color: types.color,
160
72
  backgroundColor: types.color,
@@ -13,4 +13,5 @@ export { Select } from './select';
13
13
  export { Stack } from './stack';
14
14
  export { Slider } from './slider';
15
15
  export { Spinner } from './spinner';
16
- export { Switch } from './switch';
16
+ export { Switch } from './switch';
17
+ export { Autocomplete } from './autocomplete';
@@ -12,10 +12,9 @@ import "core-js/modules/es.string.iterator.js";
12
12
  import "core-js/modules/web.dom-collections.iterator.js";
13
13
  import "core-js/modules/es.array.from.js";
14
14
  import "core-js/modules/es.regexp.exec.js";
15
- var _excluded = ["children"],
16
- _excluded2 = ["children", "isSelected", "isActive"];
15
+ var _excluded = ["children"];
17
16
 
18
- var _templateObject, _templateObject2, _templateObject3;
17
+ var _templateObject;
19
18
 
20
19
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
20
 
@@ -42,11 +41,12 @@ import PropTypes from 'prop-types';
42
41
  import React, { useState } from 'react';
43
42
  import styled from '@emotion/styled';
44
43
  import { Icon, Box, Text } from '.';
45
- import { IconCheck, IconChevronDown } from '../icons';
44
+ import { IconChevronDown } from '../icons';
46
45
  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'));
46
+ import { getColor, getRadius } from '../utilities';
47
+ import { types } from '../types';
48
+ import { Menu, MenuItem } from '../foundational';
49
+ var SelectButtonWrapper = styled(Listbox.Button)(_templateObject || (_templateObject = _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 width: 100%;\n text-align: left;\n"])), getColor('fade1'), getRadius('s'));
50
50
 
51
51
  var SelectButton = function SelectButton(_ref) {
52
52
  var children = _ref.children,
@@ -55,38 +55,30 @@ var SelectButton = function SelectButton(_ref) {
55
55
  return /*#__PURE__*/React.createElement(SelectButtonWrapper, props, /*#__PURE__*/React.createElement(Text, {
56
56
  hasEllipsis: true,
57
57
  weight: "medium"
58
- }, children), /*#__PURE__*/React.createElement(Icon, {
58
+ }, children), /*#__PURE__*/React.createElement(Box, {
59
+ marginLeft: "auto"
60
+ }, /*#__PURE__*/React.createElement(Icon, {
59
61
  icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
62
+ })));
63
+ };
64
+
65
+ var SelectRoot = function SelectRoot(_ref2) {
66
+ var props = Object.assign({}, _ref2);
67
+ return /*#__PURE__*/React.createElement(Box, Object.assign({}, props, {
68
+ position: "relative"
60
69
  }));
61
70
  };
62
71
 
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
72
  export var Select = function Select(_ref3) {
85
73
  var options = _ref3.options,
86
74
  defaultOption = _ref3.defaultOption,
87
- onChange = _ref3.onChange;
75
+ onChange = _ref3.onChange,
76
+ _ref3$menuAlign = _ref3.menuAlign,
77
+ menuAlign = _ref3$menuAlign === void 0 ? 'left' : _ref3$menuAlign,
78
+ _ref3$menuWidth = _ref3.menuWidth,
79
+ menuWidth = _ref3$menuWidth === void 0 ? '240px' : _ref3$menuWidth;
88
80
 
89
- var _useState = useState(defaultOption || options[0]),
81
+ var _useState = useState(defaultOption || {}),
90
82
  _useState2 = _slicedToArray(_useState, 2),
91
83
  selectedOption = _useState2[0],
92
84
  setSelectedOption = _useState2[1];
@@ -97,11 +89,16 @@ export var Select = function Select(_ref3) {
97
89
  };
98
90
 
99
91
  return /*#__PURE__*/React.createElement(Listbox, {
92
+ as: SelectRoot,
100
93
  value: selectedOption,
101
94
  onChange: handleChange
102
- }, /*#__PURE__*/React.createElement(SelectButton, null, selectedOption.content), /*#__PURE__*/React.createElement(Options, null, options.map(function (option, index) {
95
+ }, /*#__PURE__*/React.createElement(SelectButton, null, selectedOption.content), /*#__PURE__*/React.createElement(Listbox.Options, {
96
+ menuAlign: menuAlign,
97
+ menuWidth: menuWidth,
98
+ as: Menu
99
+ }, options.map(function (option) {
103
100
  return /*#__PURE__*/React.createElement(Listbox.Option, {
104
- key: index,
101
+ key: option.id,
105
102
  value: option,
106
103
  as: React.Fragment
107
104
  }, function (_ref4) {
@@ -117,5 +114,7 @@ export var Select = function Select(_ref3) {
117
114
  Select.propTypes = {
118
115
  options: PropTypes.array,
119
116
  defaultOption: PropTypes.object,
120
- onChange: PropTypes.func
117
+ onChange: PropTypes.func,
118
+ menuAlign: PropTypes.oneOf(['left', 'right']),
119
+ menuWidth: types.dimension
121
120
  };
@@ -36,25 +36,25 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
36
36
 
37
37
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
38
38
 
39
- import { getColor, getRadius } from '../utilities';
40
39
  import PropTypes from 'prop-types';
41
40
  import React from 'react';
42
41
  import styled from '@emotion/styled';
43
42
  import { css } from '@emotion/react';
44
43
  import { Box, Text } from '.';
45
44
  import { Icon } from './icon';
46
- import { transitions } from '../foundational';
45
+ import { fieldStyles, focusFieldStyles } from '../foundational';
47
46
  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
47
  var iconOffsetPx = 12;
49
48
  var iconTextGapPx = 8;
50
49
  var Wrapper = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n"])), variables);
51
50
  var Label = styled.label(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: block;\n margin-bottom: 4px;\n"])));
52
- var InputField = styled.input(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n appearance: none;\n border: none;\n font: inherit;\n color: inherit;\n background-color: transparent;\n transition-property: border-color;\n width: 100%;\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 var(--grn-fieldXPadding) 0 ", ";\n outline: none;\n border: 1px solid ", ";\n\n &::placeholder {\n color: ", ";\n }\n\n ", "\n"])), transitions, getRadius('s'), function (p) {
53
- return p.paddingLeft;
51
+ var InputField = styled.input(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", ";\n\n ", ";\n"])), function (p) {
52
+ return fieldStyles({
53
+ paddingLeft: p.paddingLeft,
54
+ borderColor: p.hasError ? 'var(--grn-color-danger)' : 'var(--grn-fieldBorderColor)'
55
+ });
54
56
  }, function (p) {
55
- return p.hasError ? 'var(--grn-color-danger)' : 'var(--grn-fieldBorderColor)';
56
- }, getColor('grey5'), function (p) {
57
- return !p.hasError && "\n &:hover {\n border-color: var(--grn-fieldBorderColor-hover);\n }\n\n &:focus {\n transition: 0s;\n border-color: var(--grn-fieldBorderColor-focus);\n }\n ";
57
+ return !p.hasError && focusFieldStyles;
58
58
  });
59
59
  var IconSection = styled.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n margin: auto;\n left: ", "px;\n top: 0;\n bottom: 0;\n height: fit-content;\n pointer-events: none;\n"])), iconOffsetPx);
60
60
  export var TextInput = function TextInput(_ref) {
@@ -1,41 +1,26 @@
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
1
  import "core-js/modules/es.object.keys.js";
5
2
  import "core-js/modules/es.array.index-of.js";
6
3
  import "core-js/modules/es.symbol.js";
7
- var _excluded = ["children", "size", "weight", "color", "tag", "hasEllipsis", "ellipsisLines", "align"];
4
+ import "core-js/modules/es.array.slice.js";
5
+ import "core-js/modules/es.object.freeze.js";
6
+ import "core-js/modules/es.object.define-properties.js";
8
7
 
9
8
  var _templateObject;
10
9
 
10
+ var _excluded = ["children", "size", "weight", "color", "tag", "hasEllipsis", "ellipsisLines", "align"];
11
11
  import "core-js/modules/es.object.assign.js";
12
12
 
13
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
14
+
13
15
  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
16
 
15
17
  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
18
 
17
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
18
-
19
19
  import { getColor, getResponsiveTextSize, getWeight } from '../utilities';
20
20
  import PropTypes from 'prop-types';
21
21
  import React from 'react';
22
- import styled from '@emotion/styled';
22
+ import { css } from '@emotion/react';
23
23
  import { types } from '../types';
24
- var Wrapper = styled.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n ", ";\n font-weight: ", ";\n color: ", ";\n text-align: ", ";\n\n ", ";\n ", ";\n ", ";\n"])), function (p) {
25
- return getResponsiveTextSize(p.size);
26
- }, function (p) {
27
- return getWeight(p.weight);
28
- }, function (p) {
29
- return getColor(p.color);
30
- }, function (p) {
31
- return p.align;
32
- }, function (p) {
33
- return p.hasEllipsis && "\n overflow: hidden;\n text-overflow: ellipsis;\n ";
34
- }, function (p) {
35
- return p.hasEllipsis && !p.ellipsisLines && "\n white-space: nowrap;\n ";
36
- }, function (p) {
37
- return p.hasEllipsis && p.ellipsisLines && "\n display: -webkit-box;\n -webkit-line-clamp: ".concat(p.ellipsisLines, ";\n -webkit-box-orient: vertical;\n ");
38
- });
39
24
  export var Text = function Text(_ref) {
40
25
  var children = _ref.children,
41
26
  _ref$size = _ref.size,
@@ -50,14 +35,9 @@ export var Text = function Text(_ref) {
50
35
  align = _ref.align,
51
36
  props = _objectWithoutProperties(_ref, _excluded);
52
37
 
53
- return /*#__PURE__*/React.createElement(Wrapper, Object.assign({
54
- size: size,
55
- weight: weight,
56
- color: color,
57
- as: tag,
58
- hasEllipsis: hasEllipsis,
59
- ellipsisLines: ellipsisLines,
60
- align: align
38
+ var Tag = tag;
39
+ return /*#__PURE__*/React.createElement(Tag, Object.assign({
40
+ css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n ", ";\n font-weight: ", ";\n color: ", ";\n text-align: ", ";\n\n ", ";\n\n ", ";\n "])), getResponsiveTextSize(size), getWeight(weight), getColor(color), align, hasEllipsis && "\n overflow: hidden;\n text-overflow: ellipsis;\n ".concat(!ellipsisLines && "white-space: nowrap", ";\n "), hasEllipsis && ellipsisLines && "\n display: -webkit-box;\n -webkit-line-clamp: ".concat(ellipsisLines, ";\n -webkit-box-orient: vertical;\n "))
61
41
  }, props), children);
62
42
  };
63
43
  Text.propTypes = {
@@ -1,13 +1,65 @@
1
1
  import "core-js/modules/es.array.slice.js";
2
2
  import "core-js/modules/es.object.freeze.js";
3
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 = ["children", "isSelected", "isActive"];
4
8
 
5
- var _templateObject, _templateObject2;
9
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
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; }
6
16
 
7
17
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
8
18
 
9
19
  import styled from '@emotion/styled';
10
20
  import { css } from '@emotion/react';
11
- import { getColor, getRadius, getTransition, getWeight } from '../utilities';
21
+ import { getColor, getDimension, getRadius, getShadow, getTransition, getWeight } from '../utilities';
22
+ import { Box, Icon, Text } from '../components';
23
+ import { IconCheck } from '../icons';
24
+ import { forwardRef } from 'react';
25
+ export var fieldXPadding = '12px';
12
26
  export var transitions = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n transition: ", ";\n\n &:hover {\n transition: ", ";\n }\n\n &:active {\n transition: 0s;\n }\n"])), getTransition('slow'), getTransition('fast'));
13
- export var ClearButtonBox = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n --grn-borderColor-active: var(--grn-color-fade5);\n\n appearance: none;\n border: 1px solid transparent;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n cursor: pointer;\n font-weight: ", ";\n border-radius: ", ";\n height: var(--grn-clearButtonHeight-m);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n\n &:hover {\n background-color: var(--grn-color-backgroundOverlay);\n }\n\n &:active {\n border-color: var(--grn-borderColor-active);\n outline-color: var(--grn-borderColor-active);\n background-color: transparent;\n }\n\n &:disabled {\n color: ", ";\n cursor: default;\n border-color: transparent;\n\n &:hover {\n background-color: transparent;\n }\n }\n"])), transitions, getWeight('medium'), getRadius('s'), getColor('contentDisabled'));
27
+ export var ClearButtonBox = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n --grn-borderColor-active: var(--grn-color-fade5);\n\n appearance: none;\n border: 1px solid transparent;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n cursor: pointer;\n font-weight: ", ";\n border-radius: ", ";\n height: var(--grn-clearButtonHeight-m);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n\n &:hover {\n background-color: var(--grn-color-backgroundOverlay);\n }\n\n &:active {\n border-color: var(--grn-borderColor-active);\n outline-color: var(--grn-borderColor-active);\n background-color: transparent;\n }\n\n &:disabled {\n color: ", ";\n cursor: default;\n border-color: transparent;\n\n &:hover {\n background-color: transparent;\n }\n }\n"])), transitions, getWeight('medium'), getRadius('s'), getColor('contentDisabled'));
28
+ export var fieldStyles = function fieldStyles(_ref) {
29
+ var _ref$paddingLeft = _ref.paddingLeft,
30
+ paddingLeft = _ref$paddingLeft === void 0 ? '12px' : _ref$paddingLeft,
31
+ _ref$paddingRight = _ref.paddingRight,
32
+ paddingRight = _ref$paddingRight === void 0 ? '12px' : _ref$paddingRight,
33
+ _ref$borderColor = _ref.borderColor,
34
+ borderColor = _ref$borderColor === void 0 ? 'var(--grn-color-fade3)' : _ref$borderColor;
35
+ return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n --grn-fieldBorderColor-hover: var(--grn-color-fade6);\n --grn-fieldBorderColor-focus: var(--grn-color-grey6);\n\n ", ";\n appearance: none;\n border: none;\n font: inherit;\n color: inherit;\n background-color: transparent;\n transition-property: border-color;\n width: 100%;\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 ", " 0 ", ";\n outline: none;\n border: 1px solid ", ";\n\n &::placeholder {\n color: ", ";\n }\n"])), transitions, getRadius('s'), paddingRight, paddingLeft, borderColor, getColor('grey5'));
36
+ };
37
+ export var focusFieldStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n &:hover {\n border-color: var(--grn-fieldBorderColor-hover);\n }\n\n &:focus {\n transition: 0s;\n border-color: var(--grn-fieldBorderColor-focus);\n }\n"])));
38
+ export var Menu = styled.ul(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding: 8px;\n margin: 0;\n position: absolute;\n background: white;\n box-shadow: ", ";\n border-radius: ", ";\n max-height: 468px;\n overflow: auto;\n width: ", ";\n ", "\n\n &:focus {\n outline: none;\n }\n"])), getShadow('m'), getRadius('s'), function (_ref2) {
39
+ var menuWidth = _ref2.menuWidth;
40
+ return getDimension(menuWidth);
41
+ }, function (_ref3) {
42
+ var menuAlign = _ref3.menuAlign;
43
+ return "".concat(menuAlign, ": 0;");
44
+ });
45
+ var MenuItemWrapper = styled.li(_templateObject6 || (_templateObject6 = _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'));
46
+ export var MenuItem = /*#__PURE__*/forwardRef(function (_ref4, ref) {
47
+ var children = _ref4.children,
48
+ isSelected = _ref4.isSelected,
49
+ isActive = _ref4.isActive,
50
+ props = _objectWithoutProperties(_ref4, _excluded);
51
+
52
+ return /*#__PURE__*/React.createElement(MenuItemWrapper, Object.assign({
53
+ ref: ref,
54
+ isActive: isActive,
55
+ style: {
56
+ background: isActive ? getColor('overlay') : undefined
57
+ }
58
+ }, props), /*#__PURE__*/React.createElement(Text, {
59
+ hasEllipsis: true
60
+ }, children), isSelected && /*#__PURE__*/React.createElement(Box, {
61
+ marginLeft: "auto"
62
+ }, /*#__PURE__*/React.createElement(Icon, {
63
+ icon: /*#__PURE__*/React.createElement(IconCheck, null)
64
+ })));
65
+ });
package/es/hooks/index.js CHANGED
@@ -1 +1,3 @@
1
- export { useMedia } from './useMedia';
1
+ export { useMedia } from './useMedia';
2
+ export { useKeyPress } from './useKeyPress';
3
+ export { useOnClickOutside } from './useOnClickOutside';
@@ -0,0 +1,56 @@
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 useKeyPress(targetKey) {
26
+ var _useState = useState(false),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ keyPressed = _useState2[0],
29
+ setKeyPressed = _useState2[1];
30
+
31
+ function downHandler(_ref) {
32
+ var key = _ref.key;
33
+
34
+ if (key === targetKey) {
35
+ setKeyPressed(true);
36
+ }
37
+ }
38
+
39
+ var upHandler = function upHandler(_ref2) {
40
+ var key = _ref2.key;
41
+
42
+ if (key === targetKey) {
43
+ setKeyPressed(false);
44
+ }
45
+ };
46
+
47
+ useEffect(function () {
48
+ window.addEventListener('keydown', downHandler);
49
+ window.addEventListener('keyup', upHandler);
50
+ return function () {
51
+ window.removeEventListener('keydown', downHandler);
52
+ window.removeEventListener('keyup', upHandler);
53
+ };
54
+ }, []);
55
+ return keyPressed;
56
+ }
@@ -0,0 +1,19 @@
1
+ import { useEffect } from 'react';
2
+ export function useOnClickOutside(ref, handler) {
3
+ useEffect(function () {
4
+ var listener = function listener(event) {
5
+ if (!ref.current || ref.current.contains(event.target)) {
6
+ return;
7
+ }
8
+
9
+ handler(event);
10
+ };
11
+
12
+ document.addEventListener('mousedown', listener);
13
+ document.addEventListener('touchstart', listener);
14
+ return function () {
15
+ document.removeEventListener('mousedown', listener);
16
+ document.removeEventListener('touchstart', listener);
17
+ };
18
+ }, [ref, handler]);
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "5.8.0",
3
+ "version": "5.9.0",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",
@@ -23,7 +23,6 @@
23
23
  "dependencies": {
24
24
  "@emotion/react": "^11.9.0",
25
25
  "@emotion/styled": "^11.8.1",
26
- "@headlessui/react": "^1.6.6",
27
26
  "core-js": "^3.22.8",
28
27
  "prop-types": "^15.8.1"
29
28
  },
@@ -36,6 +35,8 @@
36
35
  "@babel/plugin-transform-runtime": "^7.18.2",
37
36
  "@babel/preset-env": "^7.18.2",
38
37
  "@babel/preset-react": "^7.17.12",
38
+ "@emotion/babel-preset-css-prop": "^11.10.0",
39
+ "@headlessui/react": "^1.6.6",
39
40
  "@mdx-js/loader": "^2.1.1",
40
41
  "@next/mdx": "^12.1.6",
41
42
  "@semantic-release/git": "^10.0.1",