@pingux/astro 1.0.0-alpha.5 → 1.0.0-alpha.9

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/lib/cjs/components/AccordionItem/AccordionItem.js +3 -1
  3. package/lib/cjs/components/CopyText/CopyText.js +3 -73
  4. package/lib/cjs/components/Tab/Tab.js +10 -3
  5. package/lib/cjs/components/Tabs/Tabs.js +4 -1
  6. package/lib/cjs/components/Tabs/Tabs.stories.js +57 -2
  7. package/lib/cjs/components/Tabs/Tabs.test.js +34 -0
  8. package/lib/cjs/hooks/useCopyToClipboard/index.js +18 -0
  9. package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.js +83 -0
  10. package/lib/cjs/hooks/useCopyToClipboard/useCopyToClipboard.test.js +79 -0
  11. package/lib/cjs/recipes/CopyToClipboard.stories.js +45 -0
  12. package/lib/cjs/recipes/RadioButtonsWithLinks.stories.js +146 -0
  13. package/lib/cjs/styles/forms/input.js +11 -0
  14. package/lib/cjs/styles/variants/accordion.js +2 -2
  15. package/lib/cjs/styles/variants/tabs.js +1 -0
  16. package/lib/components/AccordionItem/AccordionItem.js +3 -1
  17. package/lib/components/CopyText/CopyText.js +2 -71
  18. package/lib/components/Tab/Tab.js +10 -3
  19. package/lib/components/Tabs/Tabs.js +4 -1
  20. package/lib/components/Tabs/Tabs.stories.js +53 -0
  21. package/lib/components/Tabs/Tabs.test.js +38 -0
  22. package/lib/hooks/useCopyToClipboard/index.js +1 -0
  23. package/lib/hooks/useCopyToClipboard/useCopyToClipboard.js +69 -0
  24. package/lib/hooks/useCopyToClipboard/useCopyToClipboard.test.js +64 -0
  25. package/lib/recipes/CopyToClipboard.stories.js +25 -0
  26. package/lib/recipes/RadioButtonsWithLinks.stories.js +120 -0
  27. package/lib/styles/forms/input.js +11 -0
  28. package/lib/styles/variants/accordion.js +2 -2
  29. package/lib/styles/variants/tabs.js +1 -0
  30. package/package.json +2 -2
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
8
+
9
+ _Object$defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+
13
+ exports.Default = exports["default"] = void 0;
14
+
15
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
16
+
17
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
18
+
19
+ var _react = _interopRequireWildcard(require("react"));
20
+
21
+ var _CloseIcon = _interopRequireDefault(require("mdi-react/CloseIcon"));
22
+
23
+ var _index = require("../index");
24
+
25
+ var _RadioField = _interopRequireDefault(require("../components/RadioField"));
26
+
27
+ var _RadioGroupField = _interopRequireDefault(require("../components/RadioGroupField"));
28
+
29
+ var _react2 = require("@emotion/react");
30
+
31
+ var _default = {
32
+ title: 'Recipes/RadioButtonsWithLinks'
33
+ };
34
+ exports["default"] = _default;
35
+
36
+ var Default = function Default() {
37
+ var roles = [{
38
+ name: 'Client Application Developer'
39
+ }, {
40
+ name: 'Environment Admin',
41
+ isDisabled: true
42
+ }, {
43
+ name: 'Identity Data Admin',
44
+ isDisabled: true
45
+ }, {
46
+ name: 'Organization Admin'
47
+ }];
48
+ var titleSx = {
49
+ fontSize: 'md',
50
+ color: 'neutral.20',
51
+ fontWeight: 2
52
+ };
53
+ var subtitleSx = {
54
+ fontSize: 'md',
55
+ color: 'neutral.10'
56
+ };
57
+
58
+ var RadioFieldWithButton = function RadioFieldWithButton(_ref) {
59
+ var fieldName = _ref.fieldName,
60
+ isDisabled = _ref.isDisabled;
61
+
62
+ var _useState = (0, _react.useState)(false),
63
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
64
+ isOpen = _useState2[0],
65
+ setIsOpen = _useState2[1];
66
+
67
+ return (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Box, {
68
+ isRow: true,
69
+ alignItems: "center"
70
+ }, (0, _react2.jsx)(_RadioField["default"], {
71
+ value: fieldName,
72
+ label: fieldName,
73
+ isDisabled: isDisabled
74
+ }), (0, _react2.jsx)(_index.Button, {
75
+ variant: "text",
76
+ mb: "xs",
77
+ ml: "md",
78
+ onPress: function onPress() {
79
+ return setIsOpen(function (prev) {
80
+ return !prev;
81
+ });
82
+ },
83
+ isDisabled: isDisabled
84
+ }, "".concat(isOpen ? 'Hide' : 'Show', " Permissions"))), isOpen && (0, _react2.jsx)(PermissionsList, {
85
+ onPress: function onPress() {
86
+ return setIsOpen(false);
87
+ }
88
+ }));
89
+ };
90
+
91
+ var PermissionsList = function PermissionsList(_ref2) {
92
+ var onPress = _ref2.onPress;
93
+ return (0, _react2.jsx)(_index.Box, {
94
+ p: "md",
95
+ bg: "neutral.95"
96
+ }, (0, _react2.jsx)(_index.Box, {
97
+ isRow: true,
98
+ justifyContent: "space-between",
99
+ mb: "sm"
100
+ }, (0, _react2.jsx)(_index.Text, {
101
+ sx: {
102
+ fontWeight: 2
103
+ }
104
+ }, "Permissions"), (0, _react2.jsx)(_index.IconButton, {
105
+ onPress: onPress
106
+ }, (0, _react2.jsx)(_index.Icon, {
107
+ icon: _CloseIcon["default"]
108
+ }))), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Text, {
109
+ sx: titleSx,
110
+ mb: "xs"
111
+ }, "Resource"), (0, _react2.jsx)(_index.Text, {
112
+ sx: subtitleSx,
113
+ mb: "sm"
114
+ }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."), (0, _react2.jsx)(_index.Text, {
115
+ sx: titleSx,
116
+ mb: "xs"
117
+ }, "Push Credentials"), (0, _react2.jsx)(_index.Text, {
118
+ sx: subtitleSx,
119
+ mb: "sm"
120
+ }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod"), (0, _react2.jsx)(_index.Text, {
121
+ sx: titleSx,
122
+ mb: "xs"
123
+ }, "Organization"), (0, _react2.jsx)(_index.Text, {
124
+ sx: subtitleSx,
125
+ mb: "sm"
126
+ }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco"), (0, _react2.jsx)(_index.Text, {
127
+ sx: titleSx,
128
+ mb: "xs"
129
+ }, "Image"), (0, _react2.jsx)(_index.Text, {
130
+ sx: subtitleSx,
131
+ mb: "sm"
132
+ }, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod")));
133
+ };
134
+
135
+ return (0, _react2.jsx)(_RadioGroupField["default"], null, (0, _map["default"])(roles).call(roles, function (_ref3) {
136
+ var name = _ref3.name,
137
+ isDisabled = _ref3.isDisabled;
138
+ return (0, _react2.jsx)(RadioFieldWithButton, {
139
+ fieldName: name,
140
+ isDisabled: isDisabled,
141
+ key: name
142
+ });
143
+ }));
144
+ };
145
+
146
+ exports.Default = Default;
@@ -71,6 +71,17 @@ var input = _objectSpread(_objectSpread({}, _text.text.inputValue), {}, {
71
71
  '&::placeholder': _text.text.placeholder,
72
72
  '&::-ms-expand': {
73
73
  display: 'none'
74
+ },
75
+ '&::-webkit-contacts-auto-fill-button, &::-webkit-credentials-auto-fill-button': {
76
+ visibility: 'hidden',
77
+ display: 'none !important',
78
+ pointerEvents: 'none',
79
+ height: 0,
80
+ width: 0,
81
+ margin: 0
82
+ },
83
+ '&::-ms-reveal, &::-ms-clear': {
84
+ display: 'none'
74
85
  }
75
86
  }); // Example variant input
76
87
 
@@ -23,12 +23,12 @@ var accordionTitle = {
23
23
  var accordion = {
24
24
  display: 'flex',
25
25
  mt: '5px',
26
- mb: '5px',
26
+ mb: '20px',
27
27
  alignItems: 'flex-start'
28
28
  };
29
29
  var accordionBody = {
30
30
  display: 'none !important',
31
- p: 'md',
31
+ pt: 'md',
32
32
  width: '100%',
33
33
  '.is-open &': {
34
34
  display: 'flex !important'
@@ -14,6 +14,7 @@ var tab = {
14
14
  display: 'inline-flex',
15
15
  outline: 'none',
16
16
  transform: 'translateY(1px)',
17
+ width: '100%',
17
18
  '&.is-focused': {
18
19
  boxShadow: 'focus'
19
20
  },
@@ -80,7 +80,9 @@ var AccordionItem = /*#__PURE__*/forwardRef(function (props, ref) {
80
80
  "aria-label": ariaLabel || 'Accordion',
81
81
  ref: buttonRef,
82
82
  sx: {
83
- display: 'flex'
83
+ display: 'flex',
84
+ px: '0',
85
+ height: 'unset'
84
86
  },
85
87
  variant: "accordionHeader",
86
88
  className: buttonClasses
@@ -1,6 +1,4 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
- import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
3
- import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
4
2
  import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
5
3
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
6
4
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
@@ -11,6 +9,7 @@ import { Pressable, useHover } from '@react-aria/interactions';
11
9
  import { mergeProps } from '@react-aria/utils';
12
10
  import { Box, Button, Tooltip, TooltipTrigger } from '../../index';
13
11
  import CopyButton from './CopyButton';
12
+ import useCopyToClipboard from '../../hooks/useCopyToClipboard';
14
13
  import { jsx as ___EmotionJSX } from "@emotion/react";
15
14
 
16
15
  var TooltipWrapper = function TooltipWrapper(_ref) {
@@ -75,75 +74,7 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
75
74
 
76
75
  return undefined;
77
76
  }, [isCopied]);
78
-
79
- var copyToClipboard = /*#__PURE__*/function () {
80
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
81
- var textArea, isSuccessful;
82
- return _regeneratorRuntime.wrap(function _callee$(_context) {
83
- while (1) {
84
- switch (_context.prev = _context.next) {
85
- case 0:
86
- _context.prev = 0;
87
-
88
- if (!navigator.clipboard) {
89
- _context.next = 7;
90
- break;
91
- }
92
-
93
- _context.next = 4;
94
- return navigator.clipboard.writeText(value);
95
-
96
- case 4:
97
- setIsCopied(true);
98
- _context.next = 20;
99
- break;
100
-
101
- case 7:
102
- // Workaround for copying in insecure origin
103
- textArea = document.createElement('textarea');
104
- textArea.value = value;
105
- textArea.style.position = 'fixed';
106
- document.body.appendChild(textArea);
107
- textArea.focus();
108
- textArea.select();
109
- isSuccessful = document.execCommand('copy');
110
- textArea.remove();
111
-
112
- if (!isSuccessful) {
113
- _context.next = 19;
114
- break;
115
- }
116
-
117
- setIsCopied(isSuccessful);
118
- _context.next = 20;
119
- break;
120
-
121
- case 19:
122
- throw new Error('Unable to copy message');
123
-
124
- case 20:
125
- _context.next = 25;
126
- break;
127
-
128
- case 22:
129
- _context.prev = 22;
130
- _context.t0 = _context["catch"](0);
131
- // eslint-disable-next-line no-console
132
- console.error('Failed to copy: ', _context.t0);
133
-
134
- case 25:
135
- case "end":
136
- return _context.stop();
137
- }
138
- }
139
- }, _callee, null, [[0, 22]]);
140
- }));
141
-
142
- return function copyToClipboard() {
143
- return _ref2.apply(this, arguments);
144
- };
145
- }();
146
-
77
+ var copyToClipboard = useCopyToClipboard(value, setIsCopied);
147
78
  var content = mode === 'link' ? children : ___EmotionJSX(Button, _extends({
148
79
  variant: "quiet",
149
80
  onPress: copyToClipboard,
@@ -21,6 +21,7 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
21
21
  tabsDisabled = props.isDisabled,
22
22
  orientation = props.orientation,
23
23
  mode = props.mode,
24
+ slots = props.slots,
24
25
  tooltipTriggerProps = props.tooltipTriggerProps;
25
26
  var key = item.key,
26
27
  rendered = item.rendered,
@@ -70,14 +71,16 @@ export var CollectionTab = /*#__PURE__*/forwardRef(function (props, ref) {
70
71
  }, state, tabRef),
71
72
  tabProps = _useTab.tabProps;
72
73
 
73
- var tab = ___EmotionJSX(Box, _extends({
74
+ var tab = ___EmotionJSX(Box, {
75
+ isRow: true
76
+ }, slots === null || slots === void 0 ? void 0 : slots.beforeTab, ___EmotionJSX(Box, _extends({
74
77
  className: classNames,
75
78
  variant: "tab"
76
79
  }, mergeProps(focusProps, hoverProps, tabProps), otherItemProps, {
77
80
  ref: tabRef
78
81
  }), icon, ___EmotionJSX(Text, _extends({
79
82
  variant: "tabLabel"
80
- }, tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, tabLineProps));
83
+ }, tabLabelProps), rendered), isSelected && !isDisabled && ___EmotionJSX(TabLine, tabLineProps)), slots === null || slots === void 0 ? void 0 : slots.afterTab);
81
84
 
82
85
  if (mode === 'tooltip') {
83
86
  return ___EmotionJSX(React.Fragment, null, separator, ___EmotionJSX(TooltipTrigger, _extends({}, tooltipTriggerProps, {
@@ -100,7 +103,11 @@ CollectionTab.propTypes = {
100
103
  }),
101
104
  mode: PropTypes.oneOf(['default', 'tooltip']),
102
105
  orientation: PropTypes.oneOf(['horizontal', 'vertical']),
103
- tooltipTriggerProps: PropTypes.shape({})
106
+ tooltipTriggerProps: PropTypes.shape({}),
107
+ slots: PropTypes.shape({
108
+ beforeTab: PropTypes.node,
109
+ afterTab: PropTypes.node
110
+ })
104
111
  };
105
112
 
106
113
  var TabLine = function TabLine(props) {
@@ -71,12 +71,15 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
71
71
  }, tabListProps, raTabListProps, {
72
72
  ref: tabListRef
73
73
  }), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
74
+ var _item$props;
75
+
74
76
  return ___EmotionJSX(CollectionTab, {
75
77
  key: item.key,
76
78
  item: item,
77
79
  isDisabled: isDisabled,
78
80
  orientation: orientation,
79
- mode: mode
81
+ mode: mode,
82
+ slots: item === null || item === void 0 ? void 0 : (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.slots
80
83
  });
81
84
  })), ___EmotionJSX(Box, _extends({
82
85
  variant: "tabPanel",
@@ -2,10 +2,12 @@ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
2
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
3
3
  import React, { useState } from 'react';
4
4
  import Earth from 'mdi-react/GlobeModelIcon';
5
+ import LockIcon from 'mdi-react/LockIcon';
5
6
  import Tabs from './Tabs';
6
7
  import Tab from '../Tab';
7
8
  import Icon from '../Icon';
8
9
  import Text from '../Text';
10
+ import { Chip } from '../../index';
9
11
  import { jsx as ___EmotionJSX } from "@emotion/react";
10
12
  export default {
11
13
  title: 'Tabs',
@@ -184,4 +186,55 @@ export var TabPanelProps = function TabPanelProps() {
184
186
  title: item.name
185
187
  }, item.children);
186
188
  });
189
+ };
190
+ export var ContentSlots = function ContentSlots() {
191
+ var beforeTabNode = ___EmotionJSX(Icon, {
192
+ icon: LockIcon,
193
+ sx: {
194
+ marginTop: 10,
195
+ marginRight: 5
196
+ }
197
+ });
198
+
199
+ var nodeSx = {
200
+ alignItems: 'center',
201
+ backgroundColor: 'neutral.95',
202
+ borderRadius: '50%',
203
+ color: 'neutral.30',
204
+ fontSize: 'sm',
205
+ height: 20,
206
+ justifyContent: 'center',
207
+ marginLeft: 6,
208
+ marginTop: 10,
209
+ minWidth: 20
210
+ };
211
+
212
+ var afterTabNode = ___EmotionJSX(Chip, {
213
+ sx: nodeSx
214
+ }, "14");
215
+
216
+ return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Tabs, {
217
+ items: tabs,
218
+ mb: 50
219
+ }, ___EmotionJSX(Tab, {
220
+ key: "tab1",
221
+ title: "Tab 1",
222
+ slots: {
223
+ beforeTab: beforeTabNode
224
+ }
225
+ }, ___EmotionJSX(Text, null, "This is content for Tab 1")), ___EmotionJSX(Tab, {
226
+ key: "tab2",
227
+ title: "Tab 2"
228
+ }, ___EmotionJSX(Text, null, "This is content for Tab 2"))), ___EmotionJSX(Tabs, {
229
+ items: tabs
230
+ }, ___EmotionJSX(Tab, {
231
+ key: "tab1",
232
+ title: "Tab 1"
233
+ }, ___EmotionJSX(Text, null, "Compose Filter")), ___EmotionJSX(Tab, {
234
+ key: "tab2",
235
+ title: "Tab 2",
236
+ slots: {
237
+ afterTab: afterTabNode
238
+ }
239
+ }, ___EmotionJSX(Text, null, "Users Matched"))));
187
240
  };
@@ -351,4 +351,42 @@ test('hover tab style', function () {
351
351
  expect(tab0).not.toHaveClass('is-hovered');
352
352
  userEvent.hover(tab0);
353
353
  expect(tab0).toHaveClass('is-hovered');
354
+ });
355
+ test('will render slots.beforeTab if provided', function () {
356
+ var testText = 'test-text';
357
+
358
+ var testComponent = ___EmotionJSX("div", null, testText);
359
+
360
+ var tabs = [{
361
+ name: 'Tab 1',
362
+ children: 'Tab 1 body',
363
+ props: {
364
+ slots: {
365
+ beforeTab: testComponent
366
+ }
367
+ }
368
+ }];
369
+ getComponent({}, {
370
+ tabs: tabs
371
+ });
372
+ expect(screen.getByText(testText)).toBeInTheDocument();
373
+ });
374
+ test('will render slots.afterTab if provided', function () {
375
+ var testText = 'test-text';
376
+
377
+ var testComponent = ___EmotionJSX("div", null, testText);
378
+
379
+ var tabs = [{
380
+ name: 'Tab 1',
381
+ children: 'Tab 1 body',
382
+ props: {
383
+ slots: {
384
+ afterTab: testComponent
385
+ }
386
+ }
387
+ }];
388
+ getComponent({}, {
389
+ tabs: tabs
390
+ });
391
+ expect(screen.getByText(testText)).toBeInTheDocument();
354
392
  });
@@ -0,0 +1 @@
1
+ export { default } from './useCopyToClipboard';
@@ -0,0 +1,69 @@
1
+ import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
3
+
4
+ var useCopyToClipboard = function useCopyToClipboard(value) {
5
+ var setIsCopied = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
6
+ return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
7
+ var textArea, isSuccessful;
8
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
9
+ while (1) {
10
+ switch (_context.prev = _context.next) {
11
+ case 0:
12
+ _context.prev = 0;
13
+
14
+ if (!navigator.clipboard) {
15
+ _context.next = 7;
16
+ break;
17
+ }
18
+
19
+ _context.next = 4;
20
+ return navigator.clipboard.writeText(value);
21
+
22
+ case 4:
23
+ setIsCopied(true);
24
+ _context.next = 20;
25
+ break;
26
+
27
+ case 7:
28
+ // Workaround for copying in insecure origin
29
+ textArea = document.createElement('textarea');
30
+ textArea.value = value;
31
+ textArea.style.position = 'fixed';
32
+ document.body.appendChild(textArea);
33
+ textArea.focus();
34
+ textArea.select();
35
+ isSuccessful = document.execCommand('copy');
36
+ textArea.remove();
37
+
38
+ if (!isSuccessful) {
39
+ _context.next = 19;
40
+ break;
41
+ }
42
+
43
+ setIsCopied(isSuccessful);
44
+ _context.next = 20;
45
+ break;
46
+
47
+ case 19:
48
+ throw new Error('Unable to copy message');
49
+
50
+ case 20:
51
+ _context.next = 25;
52
+ break;
53
+
54
+ case 22:
55
+ _context.prev = 22;
56
+ _context.t0 = _context["catch"](0);
57
+ // eslint-disable-next-line no-console
58
+ console.error('Failed to copy: ', _context.t0);
59
+
60
+ case 25:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }
65
+ }, _callee, null, [[0, 22]]);
66
+ }));
67
+ };
68
+
69
+ export default useCopyToClipboard;
@@ -0,0 +1,64 @@
1
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
2
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
3
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
4
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
5
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
6
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
7
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
8
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
9
+ import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
10
+ import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
11
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
12
+
13
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
14
+
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source), true)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
+
17
+ import useCopyToClipboard from './useCopyToClipboard';
18
+ var mockCopyText = 'test';
19
+
20
+ var originalClipboard = _objectSpread({}, global.navigator.clipboard);
21
+
22
+ var originalExecCommand = global.document.execCommand;
23
+ beforeEach(function () {
24
+ global.navigator.clipboard = {
25
+ writeText: jest.fn()
26
+ };
27
+ global.document.execCommand = jest.fn();
28
+ global.document.execCommand.mockReturnValue(true);
29
+ });
30
+ afterEach(function () {
31
+ jest.resetAllMocks();
32
+ global.navigator.clipboard = originalClipboard;
33
+ global.document.execCommand = originalExecCommand;
34
+ });
35
+ test('default return', function () {
36
+ var copyToClipboard = useCopyToClipboard();
37
+ expect(copyToClipboard).toEqual(expect.any(Function));
38
+ });
39
+ test('should copy text that passed in props', function () {
40
+ var copyToClipboard = useCopyToClipboard(mockCopyText);
41
+ copyToClipboard();
42
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(mockCopyText);
43
+ });
44
+ test('should call setIsCopied once function will be called', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
45
+ var mockSetIsCopied, copyToClipboard;
46
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
47
+ while (1) {
48
+ switch (_context.prev = _context.next) {
49
+ case 0:
50
+ mockSetIsCopied = jest.fn();
51
+ copyToClipboard = useCopyToClipboard(mockCopyText, mockSetIsCopied);
52
+ _context.next = 4;
53
+ return copyToClipboard();
54
+
55
+ case 4:
56
+ expect(mockSetIsCopied).toHaveBeenCalledWith(true);
57
+
58
+ case 5:
59
+ case "end":
60
+ return _context.stop();
61
+ }
62
+ }
63
+ }, _callee);
64
+ })));
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { Box, Button, Text } from '../index';
3
+ import useCopyToClipboard from '../hooks/useCopyToClipboard';
4
+ import { jsx as ___EmotionJSX } from "@emotion/react";
5
+ export default {
6
+ title: 'Recipes/CopyToClipboard'
7
+ };
8
+ export var Default = function Default() {
9
+ var textToCopy = 'eyJraWQiOiI4YTg5MmY3ZS1iNTk1LTRkYWQtODBlNC0yMzA4ODkyZTczZDQiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczovL2FwaS5waW5nb25lLmNvbSIsImF1dGhVcmwiOiJodHRwczovL2F1dGgucGluZ29uZS5jb20iLCJjb25zb2xlVXJsIjoiaHR0cHM6Ly9jb25zb2xlLnBpbmdvbmUuY29tIiwiZW52aXJvbm1lbnROYW1lIjoiTW9udGFuYSIsImVudmlyb25tZW50SWQiOiJhYzc2NWQ0Ny1kMDM2LTQ1MGUtODFjMS1mYjQ1NDMxMjM1NjYiLCJvcmdhbml6YXRpb25OYW1lIjoiaW50ZXJuYWxfZXJpa2FhbGRlYm9yZ2hfMjUyMDc1MDMxIiwib3JnYW5pemF0aW9uSWQiOiJkMDYzMmYwZi03YjQ2LTQ5ZjUtYjgyYS1kZWU5MWQ3MDY3ODYiLCJnYXRld2F5TmFtZSI6ImRzZHMiLCJnYXRld2F5SWQiOiJiMDVmNGU5Yy1jMzRiLTRlZTMtYTYyNS01ZGFiNjlkYTE1YTEiLCJnYXRld2F5VHlwZSI6IlBJTkdfRkVERVJBVEUiLCJ0YXJnZXRDbHVzdGVyRW52aXJvbm1lbnQiOiJQUk9EIiwidGFyZ2V0R2VvZ3JhcGh5IjoiTkEiLCJyZWdpb24iOiJOb3J0aCBBbWVyaWNhIiwianRpIjoiMTUwYTQ0OTktZjIyYi00YWVhLWIzY2UtYWM2YWY1NjVjNjk5IiwiaXNzIjoid3NzOi8vZ2F0ZXdheXMucGluZ29uZS5jb20iLCJpYXQiOjE2MjYyODEyMTZ9.JJ9wwqTxQWUwz2vmU0yE54xuYff51xbirzZuEUxd8GDzV45bnpbmx460CY8g9ccdmOjvfVF4RPPsawpKuMZH271tDlLZl67iknxDVWBZSih9K6v0RAmsmNriR4OyOFOkGrULCIz3ISyPWeItp1AVuue_8guWR63KzYg32aPC4SgmOrc2myq9N6XNU2H1KybETbG_s5-VU_cUqaXn7GUzhL2_W6CSVrrlE1cYfjC7pxMKFm4vvIw_KcNYVGO1K6oYgzRZ4A8toQHIdlGB8L-wkCt442LdC93OjoQdkLuGzmXnO8BUohWea-Dn35gGHoH-H1BRQTya_H9AKyWMxCw-vg';
10
+ var copyToClipboard = useCopyToClipboard(textToCopy);
11
+ return ___EmotionJSX(Box, {
12
+ bg: "accent.99",
13
+ py: "md",
14
+ px: "xl"
15
+ }, ___EmotionJSX(Text, {
16
+ sx: {
17
+ wordBreak: 'break-all'
18
+ }
19
+ }, textToCopy), ___EmotionJSX(Button, {
20
+ variant: "inline",
21
+ my: "lg",
22
+ onPress: copyToClipboard,
23
+ "aria-label": "Copy Text To Clipboard"
24
+ }, "Copy To Clipboard"));
25
+ };