UNPKG

@atlaskit/onboarding

Version:

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

69 lines (65 loc) 2.43 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { createContext } from 'react'; import noop from '@atlaskit/ds-lib/noop'; const SpotlightTransitionContext = /*#__PURE__*/createContext({ isOpen: true, onExited: noop }); // checks if children exist and are truthy const hasChildren = children => { var _React$Children$map, _React$Children$map$f; return React.Children.count(children) > 0 && (((_React$Children$map = React.Children.map(children || false, child => !!child)) === null || _React$Children$map === void 0 ? void 0 : (_React$Children$map$f = _React$Children$map.filter(Boolean)) === null || _React$Children$map$f === void 0 ? void 0 : _React$Children$map$f.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 class SpotlightTransition extends React.Component { constructor(...args) { super(...args); _defineProperty(this, "state", { currentChildren: undefined }); _defineProperty(this, "onExited", () => { this.setState({ currentChildren: this.props.children }); }); } static getDerivedStateFromProps(props, state) { const { currentChildren: previousChildren } = state; const exiting = hasChildren(previousChildren) && !hasChildren(props.children); return { currentChildren: exiting ? previousChildren : props.children }; } render() { return /*#__PURE__*/React.createElement(SpotlightTransitionContext.Provider, { value: { onExited: this.onExited, isOpen: hasChildren(this.props.children) } }, this.state.currentChildren); } } /** * __Spotlight transition consumer__ * * Used to consume the spotlight transition context through render props. * * @internal */ export const 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;