@carbon/ibm-products 1.55.2 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +579 -0
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +1 -1
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon.css +579 -0
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +1 -1
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +579 -0
- package/css/index.css.map +1 -1
- package/css/index.min.css +1 -1
- package/css/index.min.css.map +1 -1
- package/es/components/Carousel/Carousel.js +15 -5
- package/es/components/Coachmark/Coachmark.js +243 -0
- package/es/components/Coachmark/CoachmarkDragbar.js +137 -0
- package/es/components/Coachmark/CoachmarkHeader.js +88 -0
- package/es/components/Coachmark/CoachmarkOverlay.js +139 -0
- package/es/components/Coachmark/CoachmarkTagline.js +93 -0
- package/es/components/Coachmark/index.js +10 -0
- package/es/components/Coachmark/utils/constants.js +76 -0
- package/es/components/Coachmark/utils/context.js +5 -0
- package/es/components/Coachmark/utils/enums.js +40 -0
- package/es/components/Coachmark/utils/helpers.js +11 -0
- package/es/components/Coachmark/utils/hooks.js +54 -0
- package/es/components/CoachmarkBeacon/CoachmarkBeacon.js +90 -0
- package/es/components/CoachmarkBeacon/index.js +8 -0
- package/es/components/CoachmarkButton/CoachmarkButton.js +72 -0
- package/es/components/CoachmarkButton/index.js +8 -0
- package/es/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
- package/es/components/CoachmarkFixed/index.js +8 -0
- package/es/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +86 -0
- package/es/components/CoachmarkOverlayElement/index.js +8 -0
- package/es/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +175 -0
- package/es/components/CoachmarkOverlayElements/index.js +8 -0
- package/es/components/CoachmarkStack/CoachmarkStack.js +260 -0
- package/es/components/CoachmarkStack/CoachmarkStackHome.js +157 -0
- package/es/components/CoachmarkStack/index.js +8 -0
- package/es/components/NotificationsPanel/NotificationsPanel.js +3 -2
- package/es/components/index.js +7 -0
- package/es/global/js/package-settings.js +8 -1
- package/lib/components/Carousel/Carousel.js +15 -5
- package/lib/components/Coachmark/Coachmark.js +247 -0
- package/lib/components/Coachmark/CoachmarkDragbar.js +137 -0
- package/lib/components/Coachmark/CoachmarkHeader.js +85 -0
- package/lib/components/Coachmark/CoachmarkOverlay.js +139 -0
- package/lib/components/Coachmark/CoachmarkTagline.js +90 -0
- package/lib/components/Coachmark/index.js +38 -0
- package/lib/components/Coachmark/utils/constants.js +82 -0
- package/lib/components/Coachmark/utils/context.js +13 -0
- package/lib/components/Coachmark/utils/enums.js +49 -0
- package/lib/components/Coachmark/utils/helpers.js +17 -0
- package/lib/components/Coachmark/utils/hooks.js +60 -0
- package/lib/components/CoachmarkBeacon/CoachmarkBeacon.js +87 -0
- package/lib/components/CoachmarkBeacon/index.js +12 -0
- package/lib/components/CoachmarkButton/CoachmarkButton.js +69 -0
- package/lib/components/CoachmarkButton/index.js +12 -0
- package/lib/components/CoachmarkFixed/CoachmarkFixed.js +201 -0
- package/lib/components/CoachmarkFixed/index.js +12 -0
- package/lib/components/CoachmarkOverlayElement/CoachmarkOverlayElement.js +83 -0
- package/lib/components/CoachmarkOverlayElement/index.js +12 -0
- package/lib/components/CoachmarkOverlayElements/CoachmarkOverlayElements.js +176 -0
- package/lib/components/CoachmarkOverlayElements/index.js +12 -0
- package/lib/components/CoachmarkStack/CoachmarkStack.js +264 -0
- package/lib/components/CoachmarkStack/CoachmarkStackHome.js +160 -0
- package/lib/components/CoachmarkStack/index.js +12 -0
- package/lib/components/NotificationsPanel/NotificationsPanel.js +3 -2
- package/lib/components/index.js +49 -0
- package/lib/global/js/package-settings.js +8 -1
- package/package.json +2 -2
- package/scss/components/Carousel/_carousel.scss +3 -0
- package/scss/components/Coachmark/_index.scss +11 -0
- package/scss/components/Coachmark/_storybook-styles.scss +20 -0
- package/scss/components/Coachmark/styles/_coachmark-dragbar.scss +74 -0
- package/scss/components/Coachmark/styles/_coachmark-header.scss +58 -0
- package/scss/components/Coachmark/styles/_coachmark-overlay.scss +327 -0
- package/scss/components/Coachmark/styles/_coachmark-tagline.scss +118 -0
- package/scss/components/CoachmarkBeacon/_coachmark-beacon.scss +166 -0
- package/scss/components/CoachmarkBeacon/_index.scss +8 -0
- package/scss/components/CoachmarkBeacon/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkButton/_coachmark-button.scss +34 -0
- package/scss/components/CoachmarkButton/_index.scss +8 -0
- package/scss/components/CoachmarkButton/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkFixed/_coachmark-fixed.scss +34 -0
- package/scss/components/CoachmarkFixed/_index.scss +8 -0
- package/scss/components/CoachmarkFixed/_storybook-styles.scss +10 -0
- package/scss/components/CoachmarkOverlayElement/_coachmark-overlay-element.scss +50 -0
- package/scss/components/CoachmarkOverlayElement/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElement/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkOverlayElements/_coachmark-overlay-elements.scss +40 -0
- package/scss/components/CoachmarkOverlayElements/_index.scss +8 -0
- package/scss/components/CoachmarkOverlayElements/_storybook-styles.scss +19 -0
- package/scss/components/CoachmarkStack/_coachmark-stack.scss +85 -0
- package/scss/components/CoachmarkStack/_index.scss +8 -0
- package/scss/components/CoachmarkStack/_storybook-styles.scss +10 -0
- package/scss/components/_index.scss +7 -1
@@ -0,0 +1,86 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
var _excluded = ["button", "className", "description", "title"];
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2023, 2023
|
6
|
+
*
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
9
|
+
*/
|
10
|
+
|
11
|
+
// Import portions of React that are needed.
|
12
|
+
import React from 'react';
|
13
|
+
|
14
|
+
// Other standard imports.
|
15
|
+
import PropTypes from 'prop-types';
|
16
|
+
import cx from 'classnames';
|
17
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
18
|
+
import { pkg /*, carbon */ } from '../../settings';
|
19
|
+
|
20
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
21
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-overlay-element");
|
22
|
+
var componentName = 'CoachmarkOverlayElement';
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Component to be displayed within a CoachmarkOverlayElements container.
|
26
|
+
* Can be used 1 to N number, to display content in a Coachmark's overlay
|
27
|
+
* in a carousel fashion.
|
28
|
+
*/
|
29
|
+
export var CoachmarkOverlayElement = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
30
|
+
var button = _ref.button,
|
31
|
+
className = _ref.className,
|
32
|
+
description = _ref.description,
|
33
|
+
title = _ref.title,
|
34
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
35
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
36
|
+
className: cx(blockClass,
|
37
|
+
// Apply the block class to the main HTML element
|
38
|
+
className,
|
39
|
+
// Apply any supplied class names to the main HTML element.
|
40
|
+
// example: `${blockClass}__template-string-class-${kind}-n-${size}`,
|
41
|
+
{
|
42
|
+
// switched classes dependant on props or state
|
43
|
+
// example: [`${blockClass}__here-if-small`]: size === 'sm',
|
44
|
+
}),
|
45
|
+
ref: ref
|
46
|
+
// role="main"
|
47
|
+
}, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("div", {
|
48
|
+
className: "".concat(blockClass, "__content")
|
49
|
+
}, title && /*#__PURE__*/React.createElement("h2", {
|
50
|
+
className: "".concat(blockClass, "__title")
|
51
|
+
}, title), description && /*#__PURE__*/React.createElement("p", {
|
52
|
+
className: "".concat(blockClass, "__body")
|
53
|
+
}, description)), button && /*#__PURE__*/React.createElement("div", {
|
54
|
+
className: "".concat(blockClass, "__button")
|
55
|
+
}, button));
|
56
|
+
});
|
57
|
+
|
58
|
+
// Return a placeholder if not released and not enabled by feature flag
|
59
|
+
CoachmarkOverlayElement = pkg.checkComponentEnabled(CoachmarkOverlayElement, componentName);
|
60
|
+
|
61
|
+
// The display name of the component, used by React. Note that displayName
|
62
|
+
// is used in preference to relying on function.name.
|
63
|
+
CoachmarkOverlayElement.displayName = componentName;
|
64
|
+
|
65
|
+
// The types and DocGen commentary for the component props,
|
66
|
+
// in alphabetical order (for consistency).
|
67
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
68
|
+
CoachmarkOverlayElement.propTypes = {
|
69
|
+
/**
|
70
|
+
* An optional button can be rendered below the description.
|
71
|
+
* This can be a link, button, Coachmark button, etc.
|
72
|
+
*/
|
73
|
+
button: PropTypes.node,
|
74
|
+
/**
|
75
|
+
* Optional class name for this component.
|
76
|
+
*/
|
77
|
+
className: PropTypes.string,
|
78
|
+
/**
|
79
|
+
* The description of the Coachmark.
|
80
|
+
*/
|
81
|
+
description: PropTypes.node.isRequired,
|
82
|
+
/**
|
83
|
+
* The title of the Coachmark.
|
84
|
+
*/
|
85
|
+
title: PropTypes.string.isRequired
|
86
|
+
};
|
@@ -0,0 +1,175 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
+
var _excluded = ["className", "children", "media", "nextButtonText", "previousButtonLabel", "closeButtonLabel"];
|
5
|
+
/**
|
6
|
+
* Copyright IBM Corp. 2023, 2023
|
7
|
+
*
|
8
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
10
|
+
*/
|
11
|
+
|
12
|
+
import React, { Children, useEffect, useRef, useState } from 'react';
|
13
|
+
import { Button } from 'carbon-components-react';
|
14
|
+
import cx from 'classnames';
|
15
|
+
import PropTypes from 'prop-types';
|
16
|
+
import { useCoachmark } from '../Coachmark';
|
17
|
+
import { clamp } from 'lodash';
|
18
|
+
import pconsole from '../../global/js/utils/pconsole';
|
19
|
+
//TODO THIS PATH WILL NEED TO BE UPDATED ONCE IN IBM PRODUCTS
|
20
|
+
import { Carousel } from '../Carousel';
|
21
|
+
//TODO THIS PATH WILL NEED TO BE UPDATED ONCE IN IBM PRODUCTS
|
22
|
+
import { SteppedAnimatedMedia } from '../SteppedAnimatedMedia';
|
23
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
24
|
+
import { pkg /*, carbon */ } from '../../settings';
|
25
|
+
|
26
|
+
// The block part of our conventional BEM class names (blockClass__E--M).
|
27
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-overlay-elements");
|
28
|
+
var componentName = 'CoachmarkOverlayElements';
|
29
|
+
var defaults = {
|
30
|
+
nextButtonText: 'Next',
|
31
|
+
previousButtonLabel: 'Back',
|
32
|
+
closeButtonLabel: 'Got it'
|
33
|
+
};
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Composable container to allow for the displaying of CoachmarkOverlayElement
|
37
|
+
* components in a carousel fashion.
|
38
|
+
*/
|
39
|
+
export var CoachmarkOverlayElements = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
40
|
+
var className = _ref.className,
|
41
|
+
children = _ref.children,
|
42
|
+
media = _ref.media,
|
43
|
+
_ref$nextButtonText = _ref.nextButtonText,
|
44
|
+
nextButtonText = _ref$nextButtonText === void 0 ? defaults.nextButtonText : _ref$nextButtonText,
|
45
|
+
_ref$previousButtonLa = _ref.previousButtonLabel,
|
46
|
+
previousButtonLabel = _ref$previousButtonLa === void 0 ? defaults.previousButtonLabel : _ref$previousButtonLa,
|
47
|
+
_ref$closeButtonLabel = _ref.closeButtonLabel,
|
48
|
+
closeButtonLabel = _ref$closeButtonLabel === void 0 ? defaults.closeButtonLabel : _ref$closeButtonLabel,
|
49
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
50
|
+
var buttonFocusRef = useRef();
|
51
|
+
var scrollRef = useRef();
|
52
|
+
var _useState = useState(0),
|
53
|
+
_useState2 = _slicedToArray(_useState, 2),
|
54
|
+
scrollPosition = _useState2[0],
|
55
|
+
setScrollPosition = _useState2[1];
|
56
|
+
var _useState3 = useState(0),
|
57
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
58
|
+
currentProgStep = _useState4[0],
|
59
|
+
setCurrentProgStep = _useState4[1];
|
60
|
+
var coachmark = useCoachmark();
|
61
|
+
var numProgSteps = Children.count(children);
|
62
|
+
var progStepFloor = 0;
|
63
|
+
var progStepCeil = numProgSteps - 1;
|
64
|
+
useEffect(function () {
|
65
|
+
// On mount, one of the two primary buttons ("next" or "close")
|
66
|
+
// will be rendered and must have focus. (a11y)
|
67
|
+
if (buttonFocusRef.current) {
|
68
|
+
buttonFocusRef.current.focus();
|
69
|
+
}
|
70
|
+
}, []);
|
71
|
+
if (!coachmark) {
|
72
|
+
return pconsole.warn("The ".concat(componentName, " is a composable container element which should be used only within the scope of a Coachmark or a CoachmarkFixed component."));
|
73
|
+
}
|
74
|
+
return /*#__PURE__*/React.createElement("section", _extends({}, rest, {
|
75
|
+
className: cx(blockClass,
|
76
|
+
// Apply the block class to the main HTML element
|
77
|
+
className,
|
78
|
+
// Apply any supplied class names to the main HTML element.
|
79
|
+
// example: `${blockClass}__template-string-class-${kind}-n-${size}`,
|
80
|
+
{
|
81
|
+
// switched classes dependant on props or state
|
82
|
+
// example: [`${blockClass}__here-if-small`]: size === 'sm',
|
83
|
+
}),
|
84
|
+
ref: ref
|
85
|
+
// role="main"
|
86
|
+
}, getDevtoolsProps(componentName)), media && (media.render ? media.render() : /*#__PURE__*/React.createElement(SteppedAnimatedMedia, {
|
87
|
+
className: "".concat(blockClass, "__element-stepped-media"),
|
88
|
+
filePaths: media.filePaths,
|
89
|
+
playStep: currentProgStep
|
90
|
+
})), numProgSteps === 1 ? /*#__PURE__*/React.createElement(React.Fragment, null, children, closeButtonLabel && /*#__PURE__*/React.createElement("div", {
|
91
|
+
className: cx("".concat(blockClass, "__footer"), 'coachmark-carousel-controls')
|
92
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({
|
93
|
+
size: "sm"
|
94
|
+
}, coachmark.closeButtonProps), closeButtonLabel))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Carousel, {
|
95
|
+
disableArrowScroll: true,
|
96
|
+
ref: scrollRef
|
97
|
+
}, children), /*#__PURE__*/React.createElement("div", {
|
98
|
+
className: cx("".concat(blockClass, "__footer"))
|
99
|
+
}, /*#__PURE__*/React.createElement("div", {
|
100
|
+
className: "".concat(blockClass, "--controls-progress")
|
101
|
+
}, "".concat(currentProgStep + 1, " / ").concat(numProgSteps)), scrollPosition > 0 && /*#__PURE__*/React.createElement(Button, {
|
102
|
+
size: "sm",
|
103
|
+
kind: "ghost",
|
104
|
+
title: previousButtonLabel,
|
105
|
+
disabled: scrollPosition === 0,
|
106
|
+
onClick: function onClick() {
|
107
|
+
var targetStep = clamp(currentProgStep - 1, progStepFloor, progStepCeil);
|
108
|
+
scrollRef.current.scrollToView(targetStep).then(function (scrollPercentage) {
|
109
|
+
setScrollPosition(scrollPercentage);
|
110
|
+
});
|
111
|
+
setCurrentProgStep(targetStep);
|
112
|
+
}
|
113
|
+
}, previousButtonLabel), currentProgStep < progStepCeil ? /*#__PURE__*/React.createElement(Button, {
|
114
|
+
size: "sm",
|
115
|
+
ref: buttonFocusRef,
|
116
|
+
title: nextButtonText,
|
117
|
+
disabled: scrollPosition === 1,
|
118
|
+
onClick: function onClick() {
|
119
|
+
var targetStep = clamp(currentProgStep + 1, progStepFloor, progStepCeil);
|
120
|
+
scrollRef.current.scrollToView(targetStep).then(function (scrollPercentage) {
|
121
|
+
setScrollPosition(scrollPercentage);
|
122
|
+
});
|
123
|
+
setCurrentProgStep(targetStep);
|
124
|
+
}
|
125
|
+
}, nextButtonText) : closeButtonLabel && /*#__PURE__*/React.createElement(Button, _extends({
|
126
|
+
size: "sm",
|
127
|
+
ref: buttonFocusRef
|
128
|
+
}, coachmark.closeButtonProps), closeButtonLabel))));
|
129
|
+
});
|
130
|
+
|
131
|
+
// Return a placeholder if not released and not enabled by feature flag
|
132
|
+
CoachmarkOverlayElements = pkg.checkComponentEnabled(CoachmarkOverlayElements, componentName);
|
133
|
+
|
134
|
+
// The display name of the component, used by React. Note that displayName
|
135
|
+
// is used in preference to relying on function.name.
|
136
|
+
CoachmarkOverlayElements.displayName = componentName;
|
137
|
+
|
138
|
+
// The types and DocGen commentary for the component props,
|
139
|
+
// in alphabetical order (for consistency).
|
140
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
141
|
+
CoachmarkOverlayElements.propTypes = {
|
142
|
+
// TODO: UPDATE COMMENT HERE - UPDATE MDX TO HAVE DIRECTION TO USE ONLY OVERLAY ELEMENTS>...CoachmarkOverlayElements will accept only one or more CoachmarkOverlayElement as child components.
|
143
|
+
|
144
|
+
/**
|
145
|
+
* CoachmarkOverlayElements should be used with one or many CoachmarkOverlayElement components as children.
|
146
|
+
* @see CoachmarkOverlayElement
|
147
|
+
*/
|
148
|
+
children: PropTypes.node.isRequired,
|
149
|
+
/**
|
150
|
+
* Optional class name for this component.
|
151
|
+
*/
|
152
|
+
className: PropTypes.string,
|
153
|
+
/**
|
154
|
+
* The label for the Close button.
|
155
|
+
*/
|
156
|
+
closeButtonLabel: PropTypes.string,
|
157
|
+
/**
|
158
|
+
* The object describing an image in one of two shapes.
|
159
|
+
* If a single media element is required, use `{render}`.
|
160
|
+
* If a stepped animation is required, use `{filePaths}`.
|
161
|
+
*/
|
162
|
+
media: PropTypes.oneOfType([PropTypes.shape({
|
163
|
+
render: PropTypes.func
|
164
|
+
}), PropTypes.shape({
|
165
|
+
filePaths: PropTypes.arrayOf(PropTypes.string)
|
166
|
+
})]),
|
167
|
+
/**
|
168
|
+
* The label for the Next button.
|
169
|
+
*/
|
170
|
+
nextButtonText: PropTypes.string,
|
171
|
+
/**
|
172
|
+
* The label for the Previous button.
|
173
|
+
*/
|
174
|
+
previousButtonLabel: PropTypes.string
|
175
|
+
};
|
@@ -0,0 +1,260 @@
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
+
var _excluded = ["children", "className", "onClose", "description", "media", "navLinkLabels", "portalTarget", "closeButtonLabel", "tagline", "theme", "title"];
|
5
|
+
/**
|
6
|
+
* Copyright IBM Corp. 2023, 2023
|
7
|
+
*
|
8
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
10
|
+
*/
|
11
|
+
|
12
|
+
import React, { Children, useEffect, useRef, useState } from 'react';
|
13
|
+
import { createPortal } from 'react-dom';
|
14
|
+
import PropTypes from 'prop-types';
|
15
|
+
import cx from 'classnames';
|
16
|
+
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
17
|
+
import { pkg } from '../../settings';
|
18
|
+
import { CoachmarkOverlay } from '../Coachmark/CoachmarkOverlay';
|
19
|
+
import { CoachmarkStackHome } from './CoachmarkStackHome';
|
20
|
+
import { CoachmarkTagline } from '../Coachmark/CoachmarkTagline';
|
21
|
+
import { CoachmarkContext } from '../Coachmark/utils/context';
|
22
|
+
import { COACHMARK_OVERLAY_KIND } from '../Coachmark/utils/enums';
|
23
|
+
var blockClass = "".concat(pkg.prefix, "--coachmark-stack");
|
24
|
+
var elementBlockClass = "".concat(pkg.prefix, "--coachmark-stack-element");
|
25
|
+
var componentName = 'CoachmarkStack';
|
26
|
+
var defaults = {
|
27
|
+
onClose: function onClose() {},
|
28
|
+
// Pass through to CoachmarkStackHome
|
29
|
+
theme: 'light'
|
30
|
+
};
|
31
|
+
|
32
|
+
// NOTE
|
33
|
+
// The stack is limited to a depth of two Coachmarks:
|
34
|
+
// - a single parent CoachmarkStackHome
|
35
|
+
// - a single child Coachmark when stacked
|
36
|
+
// The parent will include links to all the children.
|
37
|
+
// No child Coachmark will include links to any other child Coachmarks.
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Stacked coachmarks are used to call out specific functionality or concepts
|
41
|
+
* within the UI that may not be intuitive but are important for the
|
42
|
+
* user to gain understanding of the product's main value and discover new use cases.
|
43
|
+
* This variant allows the stacking of multiple coachmark overlays to be displayed by interacting with the tagline.
|
44
|
+
*/
|
45
|
+
export var CoachmarkStack = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
46
|
+
var _document$querySelect;
|
47
|
+
var children = _ref.children,
|
48
|
+
className = _ref.className,
|
49
|
+
_ref$onClose = _ref.onClose,
|
50
|
+
onClose = _ref$onClose === void 0 ? defaults.onClose : _ref$onClose,
|
51
|
+
description = _ref.description,
|
52
|
+
media = _ref.media,
|
53
|
+
navLinkLabels = _ref.navLinkLabels,
|
54
|
+
_ref$portalTarget = _ref.portalTarget,
|
55
|
+
portalTarget = _ref$portalTarget === void 0 ? defaults.portalTarget : _ref$portalTarget,
|
56
|
+
closeButtonLabel = _ref.closeButtonLabel,
|
57
|
+
tagline = _ref.tagline,
|
58
|
+
_ref$theme = _ref.theme,
|
59
|
+
theme = _ref$theme === void 0 ? defaults.theme : _ref$theme,
|
60
|
+
title = _ref.title,
|
61
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
62
|
+
var portalNode = portalTarget ? (_document$querySelect = document.querySelector(portalTarget)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector('body') : document.querySelector('body');
|
63
|
+
var stackHomeRef = useRef();
|
64
|
+
var stackedCoachmarkRefs = useRef([]);
|
65
|
+
var _useState = useState(false),
|
66
|
+
_useState2 = _slicedToArray(_useState, 2),
|
67
|
+
isOpen = _useState2[0],
|
68
|
+
setIsOpen = _useState2[1];
|
69
|
+
// selectedItemNumber -1 = parent close button was clicked, remove entire stack
|
70
|
+
// selectedItemNumber 0 = (default) the parent is visible, all children are hidden
|
71
|
+
// selectedItemNumber 1+ = a child is visible and stacked atop the parent
|
72
|
+
var _useState3 = useState(0),
|
73
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
74
|
+
selectedItemNumber = _useState4[0],
|
75
|
+
setSelectedItemNumber = _useState4[1];
|
76
|
+
// // The parent height and width values to return to after unstacked
|
77
|
+
var _useState5 = useState(null),
|
78
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
79
|
+
parentHeight = _useState6[0],
|
80
|
+
setParentHeight = _useState6[1];
|
81
|
+
// parent height = child height when stacked behind a child that is shorter
|
82
|
+
var childArray = Children.toArray(children);
|
83
|
+
var mountedRef = useRef();
|
84
|
+
// same value as CSS animation speed
|
85
|
+
var delayMs = 240;
|
86
|
+
|
87
|
+
// Unmount or unstack a child
|
88
|
+
var handleClickNavItem = function handleClickNavItem(itemNumber) {
|
89
|
+
setSelectedItemNumber(itemNumber);
|
90
|
+
};
|
91
|
+
var handleClose = function handleClose(isParentCloseButton) {
|
92
|
+
if (isParentCloseButton) {
|
93
|
+
// Trigger slide-out animation
|
94
|
+
setSelectedItemNumber(-1);
|
95
|
+
|
96
|
+
// Unmount after animation is complete
|
97
|
+
var timer = setTimeout(function () {
|
98
|
+
setIsOpen(false);
|
99
|
+
onClose();
|
100
|
+
}, delayMs);
|
101
|
+
return function () {
|
102
|
+
return clearTimeout(timer);
|
103
|
+
};
|
104
|
+
} else {
|
105
|
+
// Unstack child
|
106
|
+
setSelectedItemNumber(0);
|
107
|
+
}
|
108
|
+
};
|
109
|
+
var contextValue = {
|
110
|
+
buttonProps: {
|
111
|
+
'aria-expanded': isOpen,
|
112
|
+
onClick: function onClick() {
|
113
|
+
setIsOpen(true);
|
114
|
+
},
|
115
|
+
// Compensate for accidental open/close on double-click.
|
116
|
+
// Only open on double-click.
|
117
|
+
onDoubleClick: function onDoubleClick() {
|
118
|
+
setIsOpen(true);
|
119
|
+
}
|
120
|
+
},
|
121
|
+
closeButtonProps: {
|
122
|
+
onClick: function onClick() {
|
123
|
+
return handleClose(false);
|
124
|
+
}
|
125
|
+
},
|
126
|
+
isOpen: isOpen
|
127
|
+
};
|
128
|
+
useEffect(function () {
|
129
|
+
mountedRef.current = true;
|
130
|
+
return function () {
|
131
|
+
mountedRef.current = false;
|
132
|
+
};
|
133
|
+
}, []);
|
134
|
+
useEffect(function () {
|
135
|
+
setTimeout(function () {
|
136
|
+
if (stackHomeRef.current) {
|
137
|
+
setParentHeight(stackHomeRef.current.clientHeight);
|
138
|
+
}
|
139
|
+
}, 0);
|
140
|
+
}, [stackHomeRef]);
|
141
|
+
useEffect(function () {
|
142
|
+
var targetSelectedItem = selectedItemNumber - 1;
|
143
|
+
if (!parentHeight) {
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
stackHomeRef.current.style.height = "".concat(parentHeight, "px");
|
147
|
+
if (!isOpen || targetSelectedItem < 0) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
var targetHomeHeight = stackedCoachmarkRefs.current[targetSelectedItem].clientHeight;
|
151
|
+
stackHomeRef.current.style.height = "".concat(targetHomeHeight, "px");
|
152
|
+
}, [selectedItemNumber, isOpen, parentHeight]);
|
153
|
+
var wrappedChildren = Children.map(childArray, function (child, idx) {
|
154
|
+
var mountedClass = mountedRef.current ? "".concat(elementBlockClass, "--is-mounted") : '';
|
155
|
+
return /*#__PURE__*/React.createElement(CoachmarkOverlay, {
|
156
|
+
key: idx,
|
157
|
+
ref: function ref(_ref2) {
|
158
|
+
return stackedCoachmarkRefs.current[idx] = _ref2;
|
159
|
+
},
|
160
|
+
kind: COACHMARK_OVERLAY_KIND.STACKED,
|
161
|
+
onClose: function onClose() {
|
162
|
+
return handleClose(false);
|
163
|
+
},
|
164
|
+
theme: theme,
|
165
|
+
fixedIsVisible: false,
|
166
|
+
className: cx(elementBlockClass, mountedClass, idx === selectedItemNumber - 1 && "".concat(elementBlockClass, "--is-visible"), mountedRef.current && "".concat(elementBlockClass, "--is-mounted"))
|
167
|
+
}, child);
|
168
|
+
});
|
169
|
+
return /*#__PURE__*/React.createElement(CoachmarkContext.Provider, {
|
170
|
+
value: contextValue
|
171
|
+
}, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
172
|
+
className: cx(blockClass, "".concat(pkg.prefix, "--coachmark-overlay--stack"), className),
|
173
|
+
ref: ref
|
174
|
+
}, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(CoachmarkTagline, {
|
175
|
+
title: tagline,
|
176
|
+
onClose: onClose
|
177
|
+
}), /*#__PURE__*/React.createElement(CoachmarkStackHome, {
|
178
|
+
ref: stackHomeRef,
|
179
|
+
className: cx("".concat(pkg.prefix, "--coachmark-overlay"), "".concat(pkg.prefix, "--coachmark-overlay__").concat(theme), elementBlockClass, selectedItemNumber > 0 && "".concat(elementBlockClass, "--is-stacked"), selectedItemNumber > 0 && "".concat(elementBlockClass, "--is-stacked__").concat(theme), isOpen && "".concat(elementBlockClass, "--is-visible"), mountedRef.current && "".concat(elementBlockClass, "--is-mounted")),
|
180
|
+
description: description,
|
181
|
+
media: media,
|
182
|
+
navLinkLabels: navLinkLabels,
|
183
|
+
onClickNavItem: handleClickNavItem,
|
184
|
+
onClose: function onClose() {
|
185
|
+
handleClose(true);
|
186
|
+
},
|
187
|
+
portalTarget: portalTarget,
|
188
|
+
closeButtonLabel: closeButtonLabel,
|
189
|
+
title: title
|
190
|
+
}), /*#__PURE__*/createPortal(wrappedChildren, portalNode)));
|
191
|
+
});
|
192
|
+
|
193
|
+
// Return a placeholder if not released and not enabled by feature flag
|
194
|
+
CoachmarkStack = pkg.checkComponentEnabled(CoachmarkStack, componentName);
|
195
|
+
|
196
|
+
// The display name of the component, used by React. Note that displayName
|
197
|
+
// is used in preference to relying on function.name.
|
198
|
+
CoachmarkStack.displayName = componentName;
|
199
|
+
|
200
|
+
// The types and DocGen commentary for the component props,
|
201
|
+
// in alphabetical order (for consistency).
|
202
|
+
// See https://www.npmjs.com/package/prop-types#usage.
|
203
|
+
CoachmarkStack.propTypes = {
|
204
|
+
/**
|
205
|
+
* CoachmarkStack should use a single CoachmarkOverlayElements component as a child.
|
206
|
+
*/
|
207
|
+
children: PropTypes.node.isRequired,
|
208
|
+
/**
|
209
|
+
* Provide an optional class to be applied to the containing node.
|
210
|
+
*/
|
211
|
+
className: PropTypes.string,
|
212
|
+
/**
|
213
|
+
* The label for the button that will close the Stack
|
214
|
+
*/
|
215
|
+
closeButtonLabel: PropTypes.string,
|
216
|
+
// Pass through to CoachmarkStackHome
|
217
|
+
/**
|
218
|
+
* The description of the Coachmark.
|
219
|
+
*/
|
220
|
+
description: PropTypes.node.isRequired,
|
221
|
+
/**
|
222
|
+
* The object describing an image in one of two shapes.
|
223
|
+
*
|
224
|
+
* If a single media element is required, use `{render}`.
|
225
|
+
*
|
226
|
+
* If a stepped animation is required, use `{filePaths}`.
|
227
|
+
*
|
228
|
+
* @see {@link MEDIA_PROP_TYPE}.
|
229
|
+
*/
|
230
|
+
media: PropTypes.oneOfType([PropTypes.shape({
|
231
|
+
render: PropTypes.func
|
232
|
+
}), PropTypes.shape({
|
233
|
+
filePaths: PropTypes.arrayOf(PropTypes.string)
|
234
|
+
})]),
|
235
|
+
/**
|
236
|
+
* The labels used to link to the stackable Coachmarks.
|
237
|
+
*/
|
238
|
+
navLinkLabels: PropTypes.arrayOf(PropTypes.string).isRequired,
|
239
|
+
/**
|
240
|
+
* Function to call when the CoachmarkStack closes.
|
241
|
+
*/
|
242
|
+
onClose: PropTypes.func,
|
243
|
+
/**
|
244
|
+
* Where in the DOM to render the stack.
|
245
|
+
* The default is `document.body`.
|
246
|
+
*/
|
247
|
+
portalTarget: PropTypes.string,
|
248
|
+
/**
|
249
|
+
* The tagline title which will be fixed to the bottom right of the window and will serve as the display trigger.
|
250
|
+
*/
|
251
|
+
tagline: PropTypes.string.isRequired,
|
252
|
+
/**
|
253
|
+
* Determines the theme of the component.
|
254
|
+
*/
|
255
|
+
theme: PropTypes.oneOf(['light', 'dark']),
|
256
|
+
/**
|
257
|
+
* The title of the Coachmark.
|
258
|
+
*/
|
259
|
+
title: PropTypes.string.isRequired
|
260
|
+
};
|