@spaced-out/ui-design-system 0.1.12 → 0.1.14

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/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.1.14](https://github.com/spaced-out/ui-design-system/compare/v0.1.13...v0.1.14) (2023-04-17)
6
+
7
+
8
+ ### Features
9
+
10
+ * focus manager component ([#102](https://github.com/spaced-out/ui-design-system/issues/102)) ([734c2a5](https://github.com/spaced-out/ui-design-system/commit/734c2a5315a9548bcbf9653b8bafd54af1d97b6a))
11
+
12
+ ### [0.1.13](https://github.com/spaced-out/ui-design-system/compare/v0.1.12...v0.1.13) (2023-04-14)
13
+
14
+
15
+ ### Features
16
+
17
+ * added escape button capabilities to click-away ([#99](https://github.com/spaced-out/ui-design-system/issues/99)) ([79cff71](https://github.com/spaced-out/ui-design-system/commit/79cff71912d3e92d9ea12c95f543aa3c623df143))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * docs update ([78756c0](https://github.com/spaced-out/ui-design-system/commit/78756c066afdcd2574e8eaa70db94c3ddc638cf2))
23
+ * docs update ([10ac5a6](https://github.com/spaced-out/ui-design-system/commit/10ac5a69d98744f16540efb61d9b1fdce5a2620f))
24
+ * fixed elevation story ([ef5cf99](https://github.com/spaced-out/ui-design-system/commit/ef5cf99f3655edb606ec6141701f596759cb0713))
25
+ * removed file extensions ([1e9b6fa](https://github.com/spaced-out/ui-design-system/commit/1e9b6fade3557f55baf9ba37c6dbc49bb180b7bc))
26
+ * stories docs reuired optional props fix ([bdf9592](https://github.com/spaced-out/ui-design-system/commit/bdf959298f5c77890ac3f7c62c74960b4a6ce738))
27
+ * support button classnames in button dropdown ([#100](https://github.com/spaced-out/ui-design-system/issues/100)) ([26c68f7](https://github.com/spaced-out/ui-design-system/commit/26c68f7f8aa1264cf1868bd250021767b888f4d2))
28
+ * truncate word break changes ([#98](https://github.com/spaced-out/ui-design-system/issues/98)) ([0ff5cc1](https://github.com/spaced-out/ui-design-system/commit/0ff5cc1cc730350e449d9d42015b57a46ad5a302))
29
+
5
30
  ### [0.1.12](https://github.com/spaced-out/ui-design-system/compare/v0.1.11...v0.1.12) (2023-04-12)
6
31
 
7
32
 
@@ -6,6 +6,9 @@
6
6
  "card": {
7
7
  "value": "{baseElevation.4.value}"
8
8
  },
9
+ "tooltip": {
10
+ "value": "{baseElevation.4.value}"
11
+ },
9
12
  "menu": {
10
13
  "value": "{baseElevation.12.value}"
11
14
  },
@@ -17,9 +20,6 @@
17
20
  },
18
21
  "toast": {
19
22
  "value": "{baseElevation.60.value}"
20
- },
21
- "tooltip": {
22
- "value": "{baseElevation.4.value}"
23
23
  }
24
24
  }
25
25
  }
@@ -86,7 +86,8 @@ const ButtonDropdown = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
86
86
  },
87
87
  isFluid: isFluid,
88
88
  classNames: {
89
- wrapper: classNames?.buttonWrapper
89
+ wrapper: classNames?.buttonWrapper,
90
+ icon: classNames?.buttonIcon
90
91
  }
91
92
  }), children), isOpen && menu && /*#__PURE__*/React.createElement("div", {
92
93
  onClickCapture: cancelNext,
@@ -39,6 +39,7 @@ export type AnchorType = $Values<typeof ANCHOR_POSITION_TYPE>;
39
39
  type ClassNames = $ReadOnly<{
40
40
  buttonWrapper?: string,
41
41
  dropdownContainer?: string,
42
+ buttonIcon?: string,
42
43
  }>;
43
44
 
44
45
  export type ButtonDropdownProps = {
@@ -117,7 +118,10 @@ export const ButtonDropdown: React$AbstractComponent<
117
118
  onOpen();
118
119
  }}
119
120
  isFluid={isFluid}
120
- classNames={{wrapper: classNames?.buttonWrapper}}
121
+ classNames={{
122
+ wrapper: classNames?.buttonWrapper,
123
+ icon: classNames?.buttonIcon,
124
+ }}
121
125
  >
122
126
  {children}
123
127
  </Button>
@@ -3,16 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "Dropdown", {
7
- enumerable: true,
8
- get: function () {
9
- return _Dropdown.Dropdown;
10
- }
11
- });
12
- Object.defineProperty(exports, "DropdownProps", {
13
- enumerable: true,
14
- get: function () {
15
- return _Dropdown.DropdownProps;
16
- }
17
- });
18
- var _Dropdown = require("./Dropdown");
6
+ var _Dropdown = require("./Dropdown");
7
+ Object.keys(_Dropdown).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Dropdown[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Dropdown[key];
14
+ }
15
+ });
16
+ });
@@ -1,4 +1,3 @@
1
1
  // @flow strict
2
2
 
3
- export {Dropdown} from './Dropdown';
4
- export {DropdownProps} from './Dropdown';
3
+ export * from './Dropdown';
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FocusManager = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _reactDomInteractions = require("@floating-ui/react-dom-interactions");
9
+ var _classify = _interopRequireDefault(require("../../utils/classify"));
10
+ var _FocusManagerModule = _interopRequireDefault(require("./FocusManager.module.css"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
15
+ const FocusManager = props => {
16
+ const {
17
+ floating,
18
+ context
19
+ } = (0, _reactDomInteractions.useFloating)();
20
+ const {
21
+ classNames,
22
+ children,
23
+ initialFocus = -1,
24
+ ...restFloatingFocusManagerProps
25
+ } = props;
26
+ return /*#__PURE__*/React.createElement(_reactDomInteractions.FloatingFocusManager, _extends({
27
+ context: context,
28
+ initialFocus: initialFocus
29
+ }, restFloatingFocusManagerProps), /*#__PURE__*/React.createElement("div", {
30
+ ref: floating,
31
+ "data-testid": "FocusManager",
32
+ className: (0, _classify.default)(_FocusManagerModule.default.wrapper, classNames?.wrapper)
33
+ }, children));
34
+ };
35
+ exports.FocusManager = FocusManager;
@@ -0,0 +1,50 @@
1
+ // @flow strict
2
+
3
+ import * as React from 'react';
4
+ import {
5
+ // $FlowFixMe[untyped-import]
6
+ FloatingFocusManager,
7
+ // $FlowFixMe[untyped-import]
8
+ useFloating,
9
+ } from '@floating-ui/react-dom-interactions';
10
+
11
+ import classify from '../../utils/classify';
12
+
13
+ import css from './FocusManager.module.css';
14
+
15
+
16
+ type ClassNames = $ReadOnly<{wrapper?: string}>;
17
+
18
+ export type FocusManagerProps = {
19
+ classNames?: ClassNames,
20
+ children?: React.Node,
21
+ initialFocus?: number,
22
+ returnFocus?: boolean,
23
+ guards?: boolean,
24
+ };
25
+
26
+ export const FocusManager = (props: FocusManagerProps): React.Node => {
27
+ const {floating, context} = useFloating();
28
+ const {
29
+ classNames,
30
+ children,
31
+ initialFocus = -1,
32
+ ...restFloatingFocusManagerProps
33
+ } = props;
34
+
35
+ return (
36
+ <FloatingFocusManager
37
+ context={context}
38
+ initialFocus={initialFocus}
39
+ {...restFloatingFocusManagerProps}
40
+ >
41
+ <div
42
+ ref={floating}
43
+ data-testid="FocusManager"
44
+ className={classify(css.wrapper, classNames?.wrapper)}
45
+ >
46
+ {children}
47
+ </div>
48
+ </FloatingFocusManager>
49
+ );
50
+ };
@@ -0,0 +1,3 @@
1
+ .wrapper {
2
+ display: flex;
3
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _FocusManager = require("./FocusManager");
7
+ Object.keys(_FocusManager).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _FocusManager[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _FocusManager[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,3 @@
1
+ // @flow strict
2
+
3
+ export * from './FocusManager';
@@ -44,7 +44,7 @@ type InContextAlertBaseProps = {
44
44
 
45
45
  export type InContextAlertProps = {
46
46
  ...InContextAlertBaseProps,
47
- semantic: AlertSemanticType,
47
+ semantic?: AlertSemanticType,
48
48
  leftIconName?: string,
49
49
  leftIconType?: IconType,
50
50
  };
@@ -13,7 +13,7 @@ import css from './OptionButton.module.css';
13
13
 
14
14
  export type OptionButtonProps = {
15
15
  ...ButtonProps,
16
- menu: MenuProps,
16
+ menu?: MenuProps,
17
17
  anchorPosition?: AnchorType,
18
18
  onOptionSelect?: (option: MenuOption) => mixed,
19
19
  onButtonClick?: ?(SyntheticEvent<HTMLElement>) => mixed,
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.PaginationItem = exports.PaginationButton = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _classify = _interopRequireDefault(require("../../utils/classify"));
9
- var _Button = require("../Button/Button.js");
10
- var _Text = require("../Text/Text.js");
9
+ var _Button = require("../Button");
10
+ var _Text = require("../Text");
11
11
  var _PaginationModule = _interopRequireDefault(require("./Pagination.module.css"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -3,10 +3,10 @@
3
3
  import * as React from 'react';
4
4
 
5
5
  import classify from '../../utils/classify';
6
- import {Button} from '../Button/Button.js';
7
- import {ButtonTextSmall} from '../Text/Text.js';
6
+ import {Button} from '../Button';
7
+ import {ButtonTextSmall} from '../Text';
8
8
 
9
- import type {PaginationItemProps} from './Pagination.js';
9
+ import type {PaginationItemProps} from './Pagination';
10
10
 
11
11
  import css from './Pagination.module.css';
12
12
 
@@ -15,12 +15,15 @@ const BaseTruncate = /*#__PURE__*/React.forwardRef((_ref, ref) => {
15
15
  let {
16
16
  children,
17
17
  line = 1,
18
- showFullTextOnHover = false
18
+ showFullTextOnHover = false,
19
+ wordBreak = 'break-all',
20
+ className
19
21
  } = _ref;
20
22
  return /*#__PURE__*/React.createElement("span", {
21
- className: (0, _classify.classify)(_TruncateModule.default.truncateLineClamp),
23
+ className: (0, _classify.classify)(_TruncateModule.default.truncateLineClamp, className),
22
24
  style: {
23
- WebkitLineClamp: `${line}`
25
+ '--line-clamp': line,
26
+ '--word-break': wordBreak
24
27
  },
25
28
  title: showFullTextOnHover ? children : '',
26
29
  ref: ref
@@ -31,7 +34,9 @@ const Truncate = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
31
34
  let {
32
35
  children,
33
36
  line = 1,
34
- showFullTextOnHover = false
37
+ showFullTextOnHover = false,
38
+ wordBreak = 'break-all',
39
+ className: truncateClassName
35
40
  } = _ref2;
36
41
  const arrayChildren = React.Children.toArray(children);
37
42
  if (arrayChildren.length) {
@@ -42,9 +47,10 @@ const Truncate = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
42
47
  children
43
48
  } = child.props;
44
49
  return /*#__PURE__*/React.cloneElement(child, {
45
- className: (0, _classify.classify)(_TruncateModule.default.truncateLineClamp, className),
50
+ className: (0, _classify.classify)(_TruncateModule.default.truncateLineClamp, className, truncateClassName),
46
51
  style: {
47
- WebkitLineClamp: `${line}`
52
+ '--line-clamp': line,
53
+ '--word-break': wordBreak
48
54
  },
49
55
  title: showFullTextOnHover ? children : '',
50
56
  ref
@@ -53,7 +59,9 @@ const Truncate = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
53
59
  return /*#__PURE__*/React.createElement(BaseTruncate, {
54
60
  line: line,
55
61
  showFullTextOnHover: showFullTextOnHover,
56
- ref: ref
62
+ ref: ref,
63
+ wordBreak: wordBreak,
64
+ className: truncateClassName
57
65
  }, children);
58
66
  }
59
67
  return null;
@@ -11,6 +11,8 @@ export type TruncateProps = {
11
11
  children?: React.Node,
12
12
  line?: number,
13
13
  showFullTextOnHover?: boolean,
14
+ wordBreak?: string,
15
+ className?: string,
14
16
  };
15
17
 
16
18
  export const BaseTruncate: React$AbstractComponent<
@@ -18,12 +20,18 @@ export const BaseTruncate: React$AbstractComponent<
18
20
  HTMLSpanElement,
19
21
  > = React.forwardRef<TruncateProps, HTMLSpanElement>(
20
22
  (
21
- {children, line = 1, showFullTextOnHover = false}: TruncateProps,
23
+ {
24
+ children,
25
+ line = 1,
26
+ showFullTextOnHover = false,
27
+ wordBreak = 'break-all',
28
+ className,
29
+ }: TruncateProps,
22
30
  ref,
23
31
  ): React.Node => (
24
32
  <span
25
- className={classify(css.truncateLineClamp)}
26
- style={{WebkitLineClamp: `${line}`}}
33
+ className={classify(css.truncateLineClamp, className)}
34
+ style={{'--line-clamp': line, '--word-break': wordBreak}}
27
35
  title={showFullTextOnHover ? children : ''}
28
36
  ref={ref}
29
37
  >
@@ -35,7 +43,13 @@ export const BaseTruncate: React$AbstractComponent<
35
43
  export const Truncate: React$AbstractComponent<TruncateProps, HTMLSpanElement> =
36
44
  React.forwardRef<TruncateProps, HTMLSpanElement>(
37
45
  (
38
- {children, line = 1, showFullTextOnHover = false}: TruncateProps,
46
+ {
47
+ children,
48
+ line = 1,
49
+ showFullTextOnHover = false,
50
+ wordBreak = 'break-all',
51
+ className: truncateClassName,
52
+ }: TruncateProps,
39
53
  ref,
40
54
  ): React.Node => {
41
55
  const arrayChildren = React.Children.toArray(children);
@@ -45,8 +59,12 @@ export const Truncate: React$AbstractComponent<TruncateProps, HTMLSpanElement> =
45
59
  const {className, children} = child.props;
46
60
 
47
61
  return React.cloneElement(child, {
48
- className: classify(css.truncateLineClamp, className),
49
- style: {WebkitLineClamp: `${line}`},
62
+ className: classify(
63
+ css.truncateLineClamp,
64
+ className,
65
+ truncateClassName,
66
+ ),
67
+ style: {'--line-clamp': line, '--word-break': wordBreak},
50
68
  title: showFullTextOnHover ? children : '',
51
69
  ref,
52
70
  });
@@ -56,6 +74,8 @@ export const Truncate: React$AbstractComponent<TruncateProps, HTMLSpanElement> =
56
74
  line={line}
57
75
  showFullTextOnHover={showFullTextOnHover}
58
76
  ref={ref}
77
+ wordBreak={wordBreak}
78
+ className={truncateClassName}
59
79
  >
60
80
  {children}
61
81
  </BaseTruncate>
@@ -1,5 +1,3 @@
1
1
  .truncateLineClamp {
2
- display: -webkit-box;
3
- -webkit-box-orient: vertical;
4
- overflow: hidden;
2
+ composes: truncate from '../../styles/typography.module.css';
5
3
  }
@@ -3,7 +3,7 @@
3
3
  import type {
4
4
  PaginationBaseProps,
5
5
  PaginationItemProps,
6
- } from '../components/Pagination/Pagination.js';
6
+ } from '../components/Pagination';
7
7
  import {range} from '../utils/helpers';
8
8
 
9
9
 
@@ -233,9 +233,13 @@
233
233
  }
234
234
 
235
235
  .truncate {
236
- white-space: nowrap;
236
+ --line-clamp: 1;
237
+ --word-break: break-all;
238
+ -webkit-line-clamp: var(--line-clamp);
239
+ display: -webkit-box;
240
+ -webkit-box-orient: vertical;
237
241
  overflow: hidden;
238
- text-overflow: ellipsis;
242
+ word-break: var(--word-break);
239
243
  }
240
244
 
241
245
  .highlightText {
@@ -2,6 +2,8 @@
2
2
 
3
3
  @value elevationCard: 4;
4
4
 
5
+ @value elevationTooltip: 4;
6
+
5
7
  @value elevationMenu: 12;
6
8
 
7
9
  @value elevationBackdrop: 40;
@@ -9,5 +11,3 @@
9
11
  @value elevationModal: 40;
10
12
 
11
13
  @value elevationToast: 60;
12
-
13
- @value elevationTooltip: 4;
@@ -9,6 +9,8 @@ const elevationNone = '0';
9
9
  exports.elevationNone = elevationNone;
10
10
  const elevationCard = '4';
11
11
  exports.elevationCard = elevationCard;
12
+ const elevationTooltip = '4';
13
+ exports.elevationTooltip = elevationTooltip;
12
14
  const elevationMenu = '12';
13
15
  exports.elevationMenu = elevationMenu;
14
16
  const elevationBackdrop = '40';
@@ -16,6 +18,4 @@ exports.elevationBackdrop = elevationBackdrop;
16
18
  const elevationModal = '40';
17
19
  exports.elevationModal = elevationModal;
18
20
  const elevationToast = '60';
19
- exports.elevationToast = elevationToast;
20
- const elevationTooltip = '4';
21
- exports.elevationTooltip = elevationTooltip;
21
+ exports.elevationToast = elevationToast;
@@ -4,6 +4,8 @@ export const elevationNone = '0';
4
4
 
5
5
  export const elevationCard = '4';
6
6
 
7
+ export const elevationTooltip = '4';
8
+
7
9
  export const elevationMenu = '12';
8
10
 
9
11
  export const elevationBackdrop = '40';
@@ -11,5 +13,3 @@ export const elevationBackdrop = '40';
11
13
  export const elevationModal = '40';
12
14
 
13
15
  export const elevationToast = '60';
14
-
15
- export const elevationTooltip = '4';
@@ -49,6 +49,11 @@ class ClickAway extends React.Component {
49
49
  }, this.handleOnChange);
50
50
  }
51
51
  });
52
+ _defineProperty(this, "handleCloseOnEscapeKeypress", evt => {
53
+ if (evt?.key === 'Escape') {
54
+ this.forceClose();
55
+ }
56
+ });
52
57
  _defineProperty(this, "forceClose", () => {
53
58
  this.setState({
54
59
  isOpen: false
@@ -74,13 +79,18 @@ class ClickAway extends React.Component {
74
79
  if (prevState.isOpen !== isOpen) {
75
80
  if (this.state.isOpen) {
76
81
  window.document.addEventListener('click', this.handleCloseClick);
82
+ if (this.props.closeOnEscapeKeypress) {
83
+ window.document.addEventListener('keyup', this.handleCloseOnEscapeKeypress);
84
+ }
77
85
  } else {
78
86
  window.document.removeEventListener('click', this.handleCloseClick);
87
+ window.document.removeEventListener('keyup', this.handleCloseOnEscapeKeypress);
79
88
  }
80
89
  }
81
90
  }
82
91
  componentWillUnmount() {
83
92
  window.document.removeEventListener('click', this.handleCloseClick);
93
+ window.document.removeEventListener('keyup', this.handleCloseOnEscapeKeypress);
84
94
  }
85
95
  render() {
86
96
  const {
@@ -106,5 +116,6 @@ class ClickAway extends React.Component {
106
116
  }
107
117
  exports.ClickAway = ClickAway;
108
118
  _defineProperty(ClickAway, "defaultProps", {
109
- shouldCancel: () => false
119
+ shouldCancel: () => false,
120
+ closeOnEscapeKeypress: true
110
121
  });
@@ -17,6 +17,7 @@ export type ChildProps = {
17
17
  };
18
18
 
19
19
  type ClickAwayProps = {
20
+ closeOnEscapeKeypress?: boolean,
20
21
  children: (props: ChildProps) => React.Node,
21
22
  shouldCancel: (event: MouseEvent) => boolean,
22
23
  onChange?: (isOpen: boolean) => mixed,
@@ -31,9 +32,13 @@ type ClickAwayState = {
31
32
  // TODO(Nishant): Make this a functional component
32
33
 
33
34
  export class ClickAway extends React.Component<ClickAwayProps, ClickAwayState> {
34
- static defaultProps: {shouldCancel: () => boolean} = {
35
- shouldCancel: () => false,
36
- };
35
+ static defaultProps: {
36
+ shouldCancel: () => boolean,
37
+ closeOnEscapeKeypress?: boolean,
38
+ } = {
39
+ shouldCancel: () => false,
40
+ closeOnEscapeKeypress: true,
41
+ };
37
42
 
38
43
  state: ClickAwayState = {
39
44
  isOpen: false,
@@ -58,14 +63,28 @@ export class ClickAway extends React.Component<ClickAwayProps, ClickAwayState> {
58
63
  if (prevState.isOpen !== isOpen) {
59
64
  if (this.state.isOpen) {
60
65
  window.document.addEventListener('click', this.handleCloseClick);
66
+ if (this.props.closeOnEscapeKeypress) {
67
+ window.document.addEventListener(
68
+ 'keyup',
69
+ this.handleCloseOnEscapeKeypress,
70
+ );
71
+ }
61
72
  } else {
62
73
  window.document.removeEventListener('click', this.handleCloseClick);
74
+ window.document.removeEventListener(
75
+ 'keyup',
76
+ this.handleCloseOnEscapeKeypress,
77
+ );
63
78
  }
64
79
  }
65
80
  }
66
81
 
67
82
  componentWillUnmount() {
68
83
  window.document.removeEventListener('click', this.handleCloseClick);
84
+ window.document.removeEventListener(
85
+ 'keyup',
86
+ this.handleCloseOnEscapeKeypress,
87
+ );
69
88
  }
70
89
 
71
90
  render(): React.Node {
@@ -115,6 +134,14 @@ export class ClickAway extends React.Component<ClickAwayProps, ClickAwayState> {
115
134
  }
116
135
  };
117
136
 
137
+ handleCloseOnEscapeKeypress: (
138
+ evt?: SyntheticKeyboardEvent<EventTarget>,
139
+ ) => void = (evt?: SyntheticKeyboardEvent<EventTarget>) => {
140
+ if (evt?.key === 'Escape') {
141
+ this.forceClose();
142
+ }
143
+ };
144
+
118
145
  forceClose: () => void = () => {
119
146
  this.setState({isOpen: false}, this.handleOnChange);
120
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {
@@ -121,6 +121,7 @@
121
121
  }
122
122
  },
123
123
  "volta": {
124
- "node": "16.16.0"
124
+ "node": "16.16.0",
125
+ "yarn": "1.22.19"
125
126
  }
126
127
  }