@fluentui/react-northstar
Version:
A themable React component library.
126 lines (124 loc) • 6.41 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.Animation = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
var _invoke2 = _interopRequireDefault(require("lodash/invoke"));
var _reactBindings = require("@fluentui/react-bindings");
var _reactComponentRef = require("@fluentui/react-component-ref");
var _classnames = _interopRequireDefault(require("classnames"));
var PropTypes = _interopRequireWildcard(require("prop-types"));
var React = _interopRequireWildcard(require("react"));
var _reactTransitionGroup = require("react-transition-group");
var _utils = require("../../utils");
var _useAnimationStyles2 = require("./useAnimationStyles");
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); }
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; }
/**
* An Animation provides animation effects to rendered elements.
*/
var Animation = /*#__PURE__*/React.forwardRef(function (props, ref) {
var _props, _props3;
var context = (0, _reactBindings.useFluentContext)();
var _useTelemetry = (0, _reactBindings.useTelemetry)(Animation.displayName, context.telemetry),
setStart = _useTelemetry.setStart,
setEnd = _useTelemetry.setEnd;
setStart();
var appear = props.appear,
children = props.children,
className = props.className,
mountOnEnter = props.mountOnEnter,
timeout = props.timeout,
visible = props.visible,
unmountOnExit = props.unmountOnExit;
var handleAnimationEvent = function handleAnimationEvent(event) {
return function () {
(0, _invoke2.default)(props, event, null, props);
};
};
var _useAnimationStyles = (0, _useAnimationStyles2.useAnimationStyles)(Animation.displayName, props),
animationClasses = _useAnimationStyles.className,
animationDuration = _useAnimationStyles.animationDuration,
animationDelay = _useAnimationStyles.animationDelay;
var timeoutResult = timeout || (0, _reactBindings.unstable_calculateAnimationTimeout)(animationDuration, animationDelay) || 0;
var unhandledProps = (0, _reactBindings.useUnhandledProps)(Animation.handledProps, props);
var nodeRef = React.useRef();
var mergedRef = (0, _reactBindings.useMergedRefs)(ref, nodeRef);
if ((0, _isNil2.default)(children)) {
setEnd();
return null;
}
var isChildrenFunction = typeof children === 'function';
var child = (0, _utils.childrenExist)(children) && !isChildrenFunction && React.Children.only(children);
var element = /*#__PURE__*/React.createElement(_reactTransitionGroup.Transition, (0, _extends2.default)({
nodeRef: nodeRef,
in: visible,
appear: appear,
mountOnEnter: mountOnEnter,
unmountOnExit: unmountOnExit,
timeout: timeoutResult,
onEnter: handleAnimationEvent('onEnter'),
onEntering: handleAnimationEvent('onEntering'),
onEntered: handleAnimationEvent('onEntered'),
onExit: handleAnimationEvent('onExit'),
onExiting: handleAnimationEvent('onExiting'),
onExited: handleAnimationEvent('onExited')
}, unhandledProps, {
className: !isChildrenFunction ? (0, _classnames.default)(animationClasses, className, child == null ? void 0 : (_props = child.props) == null ? void 0 : _props.className) : ''
}), isChildrenFunction ?
// @ts-ignore - @types/react-transition-group doesn't actually include this API, nor is it documented
function (_ref) {
var _props2;
var state = _ref.state;
var childWithClasses = children({
classes: (0, _classnames.default)(animationClasses, className, child == null ? void 0 : (_props2 = child.props) == null ? void 0 : _props2.className),
state: state
});
return childWithClasses ? /*#__PURE__*/React.createElement(_reactComponentRef.Ref, {
innerRef: mergedRef
}, childWithClasses) : childWithClasses;
} : /*#__PURE__*/React.createElement(_reactComponentRef.Ref, {
innerRef: mergedRef
}, /*#__PURE__*/React.cloneElement(child, {
className: (0, _classnames.default)(animationClasses, className, child == null ? void 0 : (_props3 = child.props) == null ? void 0 : _props3.className)
})));
setEnd();
return element;
});
exports.Animation = Animation;
Animation.displayName = 'Animation';
Animation.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({
accessibility: false,
as: false,
content: false,
children: false
}), {
children: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
name: PropTypes.string,
delay: PropTypes.string,
direction: PropTypes.string,
duration: PropTypes.string,
fillMode: PropTypes.string,
iterationCount: PropTypes.string,
keyframeParams: PropTypes.object,
playState: PropTypes.string,
timingFunction: PropTypes.string,
visible: PropTypes.bool,
appear: PropTypes.bool,
mountOnEnter: PropTypes.bool,
unmountOnExit: PropTypes.bool,
timeout: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
appear: PropTypes.number,
enter: PropTypes.number,
exit: PropTypes.number
})]),
onEnter: PropTypes.func,
onEntering: PropTypes.func,
onEntered: PropTypes.func,
onExit: PropTypes.func,
onExiting: PropTypes.func,
onExited: PropTypes.func
});
Animation.handledProps = Object.keys(Animation.propTypes);
//# sourceMappingURL=Animation.js.map