@atlaskit/onboarding
Version:
An onboarding spotlight introduces new features to users through focused messages or multi-step tours.
87 lines (84 loc) • 3.76 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React, { createContext } from 'react';
import noop from '@atlaskit/ds-lib/noop';
var SpotlightTransitionContext = /*#__PURE__*/createContext({
isOpen: true,
onExited: noop
});
// checks if children exist and are truthy
var hasChildren = function hasChildren(children) {
var _React$Children$map;
return React.Children.count(children) > 0 && (((_React$Children$map = React.Children.map(children || false, function (child) {
return !!child;
})) === null || _React$Children$map === void 0 || (_React$Children$map = _React$Children$map.filter(Boolean)) === null || _React$Children$map === void 0 ? void 0 : _React$Children$map.length) || 0) > 0;
};
/**
* __Spotlight transition__
*
* A spotlight transition holds onto spotlights so they can fade out when exiting the viewport.
*
* - [Examples](https://atlassian.design/components/onboarding/examples)
* - [Code](https://atlassian.design/components/onboarding/code)
* - [Usage](https://atlassian.design/components/onboarding/usage)
*
* @deprecated Use `@atlaskit/spotlight` instead.
*/
// eslint-disable-next-line @repo/internal/react/no-class-components
var SpotlightTransition = /*#__PURE__*/function (_React$Component) {
function SpotlightTransition() {
var _this;
_classCallCheck(this, SpotlightTransition);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, SpotlightTransition, [].concat(args));
_defineProperty(_this, "state", {
currentChildren: undefined
});
_defineProperty(_this, "onExited", function () {
_this.setState({
currentChildren: _this.props.children
});
});
return _this;
}
_inherits(SpotlightTransition, _React$Component);
return _createClass(SpotlightTransition, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(SpotlightTransitionContext.Provider, {
value: {
onExited: this.onExited,
isOpen: hasChildren(this.props.children)
}
}, this.state.currentChildren);
}
}], [{
key: "getDerivedStateFromProps",
value: function getDerivedStateFromProps(props, state) {
var previousChildren = state.currentChildren;
var exiting = hasChildren(previousChildren) && !hasChildren(props.children);
return {
currentChildren: exiting ? previousChildren : props.children
};
}
}]);
}(React.Component);
/**
* __Spotlight transition consumer__
*
* Used to consume the spotlight transition context through render props.
*
* @internal
*/
export var SpotlightTransitionConsumer = SpotlightTransitionContext.Consumer;
// eslint-disable-next-line @repo/internal/react/require-jsdoc
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export default SpotlightTransition;