UNPKG

vantui-edit

Version:

一套适用于Taro3及React的vantui组件库

91 lines (85 loc) 4.22 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; var _excluded = ["row", "animate", "avatar", "avatarShape", "avatarSize", "titleWidth", "title", "rowWidth", "loading", "children", "style", "className"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import { pxTransform } from '@tarojs/taro'; import { useState, useEffect } from 'react'; import { View } from '@tarojs/components'; import * as utils from '../wxs/utils'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; export function Skeleton(props) { var _useState = useState({ isArray: false, rowArray: [] }), _useState2 = _slicedToArray(_useState, 2), state = _useState2[0], setState = _useState2[1]; var isArray = state.isArray, rowArray = state.rowArray; var _props$row = props.row, row = _props$row === void 0 ? 0 : _props$row, _props$animate = props.animate, animate = _props$animate === void 0 ? true : _props$animate, avatar = props.avatar, _props$avatarShape = props.avatarShape, avatarShape = _props$avatarShape === void 0 ? 'round' : _props$avatarShape, _props$avatarSize = props.avatarSize, avatarSize = _props$avatarSize === void 0 ? pxTransform(64) : _props$avatarSize, _props$titleWidth = props.titleWidth, titleWidth = _props$titleWidth === void 0 ? '40%' : _props$titleWidth, title = props.title, _props$rowWidth = props.rowWidth, rowWidth = _props$rowWidth === void 0 ? '100%' : _props$rowWidth, _props$loading = props.loading, loading = _props$loading === void 0 ? true : _props$loading, children = props.children, style = props.style, className = props.className, others = _objectWithoutProperties(props, _excluded); useEffect(function () { setState(function (pre) { return _objectSpread(_objectSpread({}, pre), {}, { rowArray: Array.from({ length: row }) }); }); }, [row]); useEffect(function () { setState(function (pre) { return _objectSpread(_objectSpread({}, pre), {}, { isArray: rowWidth instanceof Array }); }); }, [rowWidth]); return loading ? /*#__PURE__*/_jsxs(View, _objectSpread(_objectSpread({ className: ' ' + utils.bem('skeleton', [{ animate: animate }]) + " ".concat(className || ''), style: style }, others), {}, { children: [avatar && /*#__PURE__*/_jsx(View, { className: 'avatar-class ' + utils.bem('skeleton__avatar', [avatarShape]), style: 'width:' + avatarSize + ';height:' + avatarSize }), /*#__PURE__*/_jsxs(View, { className: utils.bem('skeleton__content'), children: [title && /*#__PURE__*/_jsx(View, { className: 'title-class ' + utils.bem('skeleton__title'), style: 'width:' + titleWidth }), rowArray.map(function (_item, index) { return /*#__PURE__*/_jsx(View, { className: 'row-class ' + utils.bem('skeleton__row'), style: 'width:' + (isArray ? rowWidth[index] : rowWidth) }, index); })] })] })) : /*#__PURE__*/_jsx(View, { className: utils.bem('skeleton__content'), children: children }); } export default Skeleton;