UNPKG

@nutui/nutui-react

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

48 lines (47 loc) 2.04 kB
import { _ as _define_property } from "@swc/helpers/_/_define_property"; import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props"; import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array"; import React, { useState } from "react"; import classNames from "classnames"; import { ComponentDefaults } from "../../utils/typings"; var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), { type: 'shake', action: 'initial', loop: false, onClick: function(event) {} }); var classPrefix = 'nut-animate'; export var Animate = function(props) { var _ref = _object_spread({}, defaultProps, props), className = _ref.className, type = _ref.type, action = _ref.action, loop = _ref.loop, onClick = _ref.onClick, children = _ref.children, rest = _object_without_properties(_ref, [ "className", "type", "action", "loop", "onClick", "children" ]); var _useState = _sliced_to_array(useState(false), 2), clicked = _useState[0], setClicked = _useState[1]; var _obj; var classes = classNames((_obj = { 'nut-ani-container': true }, _define_property(_obj, "".concat(classPrefix, "-").concat(type), action === 'initial' || clicked), _define_property(_obj, "loop", loop), _obj), className); var handleClick = function(event) { setClicked(true); // 如果不是无限循环,清除类名 if (!loop) { setTimeout(function() { return setClicked(false); }, 1000); } onClick(event); }; return /*#__PURE__*/ React.createElement("div", { className: "nut-animate" }, /*#__PURE__*/ React.createElement("div", _object_spread({ className: classes, onClick: handleClick }, rest), children)); }; Animate.displayName = 'NutAnimate';