@atlaskit/blanket 12.2.2

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Blanket
2
+
3
+ The main purpose of the blanket component is to provide the overlay layer for components such as a modal dialog or a tooltip.
4
+
5
+ ## Installation
6
+
7
+ yarn add @atlaskit/blanket
8
+
9
+ ## Usage
10
+
11
+ Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/core/blanket).
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+
3
+ import Blanket from '../src';
4
+
5
+ export default () => <Blanket />;
@@ -0,0 +1,58 @@
1
+ // eslint-disable-next-line @repo/internal/fs/filename-pattern-match
2
+ import React, { useState } from 'react';
3
+
4
+ import { fireEvent } from '@testing-library/dom';
5
+ import {
6
+ InteractionTaskArgs,
7
+ PublicInteractionTask,
8
+ } from 'storybook-addon-performance';
9
+
10
+ import Blanket from '../src';
11
+
12
+ const BlanketPerformance = () => {
13
+ const [isBlanketVisible, setIsBlanketVisible] = useState(true);
14
+
15
+ const toggleBlanketVisibility = () => {
16
+ setIsBlanketVisible(!isBlanketVisible);
17
+ };
18
+
19
+ return (
20
+ <>
21
+ <button onClick={toggleBlanketVisibility} data-testid="toggleButton">
22
+ Toggle blanket
23
+ </button>
24
+
25
+ <Blanket isTinted={isBlanketVisible} shouldAllowClickThrough={true} />
26
+ </>
27
+ );
28
+ };
29
+
30
+ const interactionTasks: PublicInteractionTask[] = [
31
+ {
32
+ name: 'onHide',
33
+ description: 'Hide blanket by changing its isTinted prop',
34
+ run: async ({
35
+ container,
36
+ controls,
37
+ }: InteractionTaskArgs): Promise<void> => {
38
+ const toggleButton = container.querySelector(
39
+ `[data-testid="toggleButton"]`,
40
+ )!;
41
+
42
+ await controls.time(async () => {
43
+ await fireEvent.click(toggleButton);
44
+ });
45
+ },
46
+ },
47
+ ];
48
+
49
+ BlanketPerformance.story = {
50
+ name: 'Hide Blanklet',
51
+ parameters: {
52
+ performance: {
53
+ interactions: interactionTasks,
54
+ },
55
+ },
56
+ };
57
+
58
+ export default BlanketPerformance;
@@ -0,0 +1,56 @@
1
+ // eslint-disable-next-line @repo/internal/fs/filename-pattern-match
2
+ import React, { useState } from 'react';
3
+
4
+ import { fireEvent } from '@testing-library/dom';
5
+ import {
6
+ InteractionTaskArgs,
7
+ PublicInteractionTask,
8
+ } from 'storybook-addon-performance';
9
+
10
+ import Blanket from '../src';
11
+
12
+ const BlanketPerformance = () => {
13
+ const [isBlanketVisible, setIsBlanketVisible] = useState(false);
14
+
15
+ const toggleBlanketVisibility = () => {
16
+ setIsBlanketVisible(!isBlanketVisible);
17
+ };
18
+
19
+ return (
20
+ <>
21
+ <button onClick={toggleBlanketVisibility} data-testid="toggleButton">
22
+ Toggle blanket
23
+ </button>
24
+ <Blanket isTinted={isBlanketVisible} shouldAllowClickThrough={true} />
25
+ </>
26
+ );
27
+ };
28
+
29
+ const interactionTasks: PublicInteractionTask[] = [
30
+ {
31
+ name: 'onShow',
32
+ description: 'Show blanket by changing its isTinted prop',
33
+ run: async ({
34
+ container,
35
+ controls,
36
+ }: InteractionTaskArgs): Promise<void> => {
37
+ const toggleButton = container.querySelector(
38
+ `[data-testid="toggleButton"]`,
39
+ )!;
40
+ await controls.time(async () => {
41
+ await fireEvent.click(toggleButton);
42
+ });
43
+ },
44
+ },
45
+ ];
46
+
47
+ BlanketPerformance.story = {
48
+ name: 'Show Blanklet',
49
+ parameters: {
50
+ performance: {
51
+ interactions: interactionTasks,
52
+ },
53
+ },
54
+ };
55
+
56
+ export default BlanketPerformance;
@@ -0,0 +1,14 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+ import React from 'react';
3
+
4
+ import Blanket from '../src';
5
+
6
+ const BlanketPerformance = () => {
7
+ return <Blanket isTinted={true} shouldAllowClickThrough={false} />;
8
+ };
9
+
10
+ BlanketPerformance.story = {
11
+ name: 'Blanket with shouldAllowClickThrough disabled',
12
+ };
13
+
14
+ export default BlanketPerformance;
@@ -0,0 +1,14 @@
1
+ /* eslint-disable @repo/internal/fs/filename-pattern-match */
2
+ import React from 'react';
3
+
4
+ import Blanket from '../src';
5
+
6
+ const BlanketPerformance = () => {
7
+ return <Blanket isTinted={true} shouldAllowClickThrough={true} />;
8
+ };
9
+
10
+ BlanketPerformance.story = {
11
+ name: 'Blanket with shouldAllowClickThrough enabled',
12
+ };
13
+
14
+ export default BlanketPerformance;
@@ -0,0 +1,18 @@
1
+ import { JSCodeshift } from 'jscodeshift';
2
+ import { Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import {
5
+ createTransformer,
6
+ hasImportDeclaration,
7
+ } from '@atlaskit/codemod-utils';
8
+
9
+ import { BLANKET_PACKAGE_NAME } from './internal/constants';
10
+ import { renameCanClickThrough } from './migrations/rename-canclickthrough-to-shouldallowclickthrough';
11
+
12
+ const transformer = createTransformer(
13
+ [renameCanClickThrough],
14
+ (j: JSCodeshift, source: Collection<Node>) =>
15
+ hasImportDeclaration(j, source, BLANKET_PACKAGE_NAME),
16
+ );
17
+
18
+ export default transformer;
@@ -0,0 +1,167 @@
1
+ import { createTransformer } from '@atlaskit/codemod-utils';
2
+
3
+ import { renameCanClickThrough } from '../migrations/rename-canclickthrough-to-shouldallowclickthrough';
4
+
5
+ const transformer = createTransformer([renameCanClickThrough]);
6
+
7
+ const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
8
+
9
+ describe('Blanket codemods', () => {
10
+ defineInlineTest(
11
+ { default: transformer, parser: 'tsx' },
12
+ {},
13
+ `
14
+ import React from 'react';
15
+ import Blanket from '@atlaskit/blanket';
16
+
17
+ const App = () => {
18
+ return (
19
+ <Blanket
20
+ canClickThrough
21
+ />
22
+ );
23
+ }
24
+ `,
25
+ `
26
+ import React from 'react';
27
+ import Blanket from '@atlaskit/blanket';
28
+
29
+ const App = () => {
30
+ return (
31
+ <Blanket
32
+ shouldAllowClickThrough
33
+ />
34
+ );
35
+ }
36
+ `,
37
+ `should rename the "canClickThrough" prop to "shouldAllowClickThrough" prop`,
38
+ );
39
+ defineInlineTest(
40
+ { default: transformer, parser: 'tsx' },
41
+ {},
42
+ `
43
+ import React from 'react';
44
+ import Blanket from '@atlaskit/blanket';
45
+
46
+ const App = () => {
47
+ return (
48
+ <Blanket
49
+ canClickThrough={true}
50
+ />
51
+ );
52
+ }
53
+ `,
54
+ `
55
+ import React from 'react';
56
+ import Blanket from '@atlaskit/blanket';
57
+
58
+ const App = () => {
59
+ return (
60
+ <Blanket
61
+ shouldAllowClickThrough={true}
62
+ />
63
+ );
64
+ }
65
+ `,
66
+ `should rename the "canClickThrough" prop to "shouldAllowClickThrough" prop`,
67
+ );
68
+ defineInlineTest(
69
+ { default: transformer, parser: 'tsx' },
70
+ {},
71
+ `
72
+ import React from 'react';
73
+ import Blanket from '@atlaskit/blanket';
74
+
75
+ const App = () => {
76
+ return (
77
+ <Blanket
78
+ isTinted={false}
79
+ canClickThrough={true}
80
+ testId="blanket"
81
+ />
82
+ );
83
+ }
84
+ `,
85
+ `
86
+ import React from 'react';
87
+ import Blanket from '@atlaskit/blanket';
88
+
89
+ const App = () => {
90
+ return (
91
+ <Blanket
92
+ isTinted={false}
93
+ shouldAllowClickThrough={true}
94
+ testId="blanket"
95
+ />
96
+ );
97
+ }
98
+ `,
99
+ `should rename only "canClickThrough" prop and leave other props unaffected`,
100
+ );
101
+ defineInlineTest(
102
+ { default: transformer, parser: 'tsx' },
103
+ {},
104
+ `
105
+ import React from 'react';
106
+ import Blanket from '@atlaskit/blanket';
107
+ const shouldAllowClickThrough = false;
108
+ const App = () => {
109
+ return (
110
+ <Blanket
111
+ isTinted={false}
112
+ canClickThrough={shouldAllowClickThrough}
113
+ testId="blanket"
114
+ />
115
+ );
116
+ }
117
+ `,
118
+ `
119
+ import React from 'react';
120
+ import Blanket from '@atlaskit/blanket';
121
+ const shouldAllowClickThrough = false;
122
+ const App = () => {
123
+ return (
124
+ <Blanket
125
+ isTinted={false}
126
+ shouldAllowClickThrough={shouldAllowClickThrough}
127
+ testId="blanket"
128
+ />
129
+ );
130
+ }
131
+ `,
132
+ `should rename the "canClickThrough" prop when its value is a variable`,
133
+ );
134
+ defineInlineTest(
135
+ { default: transformer, parser: 'tsx' },
136
+ {},
137
+ `
138
+ import React from 'react';
139
+ import Blanket from '@atlaskit/blanket';
140
+ const shouldAllowClickThrough = false;
141
+ const App = () => {
142
+ return (
143
+ <Blanket
144
+ isTinted={false}
145
+ canClickThrough={true && shouldAllowClickThrough || false}
146
+ testId="blanket"
147
+ />
148
+ );
149
+ }
150
+ `,
151
+ `
152
+ import React from 'react';
153
+ import Blanket from '@atlaskit/blanket';
154
+ const shouldAllowClickThrough = false;
155
+ const App = () => {
156
+ return (
157
+ <Blanket
158
+ isTinted={false}
159
+ shouldAllowClickThrough={true && shouldAllowClickThrough || false}
160
+ testId="blanket"
161
+ />
162
+ );
163
+ }
164
+ `,
165
+ `should rename the "canClickThrough" prop when its value is a complex expression`,
166
+ );
167
+ });
@@ -0,0 +1,3 @@
1
+ export const BLANKET_PACKAGE_NAME = '@atlaskit/blanket';
2
+ export const OLD_CLICK_THROUGH_PROP_NAME = 'canClickThrough';
3
+ export const NEW_CLICK_THROUGH_PROP_NAME = 'shouldAllowClickThrough';
@@ -0,0 +1,13 @@
1
+ import { createRenameFuncFor } from '@atlaskit/codemod-utils';
2
+
3
+ import {
4
+ BLANKET_PACKAGE_NAME,
5
+ NEW_CLICK_THROUGH_PROP_NAME,
6
+ OLD_CLICK_THROUGH_PROP_NAME,
7
+ } from '../internal/constants';
8
+
9
+ export const renameCanClickThrough = createRenameFuncFor(
10
+ BLANKET_PACKAGE_NAME,
11
+ OLD_CLICK_THROUGH_PROP_NAME,
12
+ NEW_CLICK_THROUGH_PROP_NAME,
13
+ );
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _core = require("@emotion/core");
17
+
18
+ var _usePlatformLeafEventHandler = require("@atlaskit/analytics-next/usePlatformLeafEventHandler");
19
+
20
+ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
21
+
22
+ var _colors = require("@atlaskit/theme/colors");
23
+
24
+ var _components = require("@atlaskit/theme/components");
25
+
26
+ var _constants = require("@atlaskit/theme/constants");
27
+
28
+ var _tokens = require("@atlaskit/tokens");
29
+
30
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
+
32
+ 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; }
33
+
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
35
+
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
37
+
38
+ var packageName = "@atlaskit/blanket";
39
+ var packageVersion = "12.2.2";
40
+ var analyticsAttributes = {
41
+ componentName: 'blanket',
42
+ packageName: packageName,
43
+ packageVersion: packageVersion
44
+ };
45
+ var baseStyles = (0, _core.css)({
46
+ position: 'fixed',
47
+ zIndex: _constants.layers.blanket(),
48
+ top: 0,
49
+ right: 0,
50
+ bottom: 0,
51
+ left: 0,
52
+ overflowY: 'auto',
53
+ pointerEvents: 'initial'
54
+ });
55
+ var shouldAllowClickThroughStyles = (0, _core.css)({
56
+ pointerEvents: 'none'
57
+ });
58
+ var invisibleStyles = (0, _core.css)({
59
+ backgroundColor: 'transparent'
60
+ });
61
+ var lightBgStyles = (0, _core.css)({
62
+ backgroundColor: (0, _tokens.token)('color.background.blanket', _colors.N100A)
63
+ });
64
+ var darkBgStyles = (0, _core.css)({
65
+ backgroundColor: (0, _tokens.token)('color.background.blanket', _colors.DN90A)
66
+ });
67
+ var backgroundStyle = {
68
+ light: lightBgStyles,
69
+ dark: darkBgStyles
70
+ };
71
+ /**
72
+ * __Blanket__
73
+ *
74
+ * A Blanket provides the overlay layer for components such as a modal dialog or a tooltip
75
+ *
76
+ * - [Examples](https://atlaskit.atlassian.com/examples/design-system/blanket/basic-usage)
77
+ */
78
+
79
+ var Blanket = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(function Blanket(_ref, ref) {
80
+ var _ref$shouldAllowClick = _ref.shouldAllowClickThrough,
81
+ shouldAllowClickThrough = _ref$shouldAllowClick === void 0 ? false : _ref$shouldAllowClick,
82
+ _ref$isTinted = _ref.isTinted,
83
+ isTinted = _ref$isTinted === void 0 ? false : _ref$isTinted,
84
+ _ref$onBlanketClicked = _ref.onBlanketClicked,
85
+ onBlanketClicked = _ref$onBlanketClicked === void 0 ? _noop.default : _ref$onBlanketClicked,
86
+ testId = _ref.testId,
87
+ children = _ref.children,
88
+ analyticsContext = _ref.analyticsContext;
89
+
90
+ var _useGlobalTheme = (0, _components.useGlobalTheme)(),
91
+ mode = _useGlobalTheme.mode;
92
+
93
+ var onBlanketClickedWithAnalytics = (0, _usePlatformLeafEventHandler.usePlatformLeafEventHandler)(_objectSpread({
94
+ fn: onBlanketClicked,
95
+ action: 'clicked',
96
+ analyticsData: analyticsContext
97
+ }, analyticsAttributes));
98
+ var blanketClickOutsideChildren = (0, _react.useCallback)(function (e) {
99
+ return e.currentTarget === e.target ? onBlanketClickedWithAnalytics(e) : undefined;
100
+ }, [onBlanketClickedWithAnalytics]);
101
+ var onClick = shouldAllowClickThrough ? undefined : blanketClickOutsideChildren;
102
+ return (0, _core.jsx)("div", {
103
+ role: "presentation",
104
+ css: [baseStyles, shouldAllowClickThrough && shouldAllowClickThroughStyles, backgroundStyle[mode], !isTinted && invisibleStyles],
105
+ onClick: onClick,
106
+ "data-testid": testId,
107
+ ref: ref
108
+ }, children);
109
+ }));
110
+ Blanket.displayName = 'Blanket';
111
+ var _default = Blanket;
112
+ exports.default = _default;