UNPKG

@atlaskit/onboarding

Version:

An onboarding spotlight introduces new features to users through focused messages or multi-step tours.

96 lines (92 loc) 5.11 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.SpotlightTransitionConsumer = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireWildcard(require("react")); var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(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; })(); } var SpotlightTransitionContext = /*#__PURE__*/(0, _react.createContext)({ isOpen: true, onExited: _noop.default }); // checks if children exist and are truthy var hasChildren = function hasChildren(children) { var _React$Children$map; return _react.default.Children.count(children) > 0 && (((_React$Children$map = _react.default.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; (0, _classCallCheck2.default)(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)); (0, _defineProperty2.default)(_this, "state", { currentChildren: undefined }); (0, _defineProperty2.default)(_this, "onExited", function () { _this.setState({ currentChildren: _this.props.children }); }); return _this; } (0, _inherits2.default)(SpotlightTransition, _React$Component); return (0, _createClass2.default)(SpotlightTransition, [{ key: "render", value: function render() { return /*#__PURE__*/_react.default.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.default.Component); /** * __Spotlight transition consumer__ * * Used to consume the spotlight transition context through render props. * * @internal */ var SpotlightTransitionConsumer = exports.SpotlightTransitionConsumer = SpotlightTransitionContext.Consumer; // eslint-disable-next-line @repo/internal/react/require-jsdoc // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports var _default = exports.default = SpotlightTransition;