@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
91 lines • 4.49 kB
JavaScript
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 { get } from '../default-props';
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 _useState3 = useState(get().Skeleton),
_useState4 = _slicedToArray(_useState3, 1),
d = _useState4[0];
var isArray = state.isArray,
rowArray = state.rowArray;
var _d$props = _objectSpread(_objectSpread({}, d), props),
_d$props$row = _d$props.row,
row = _d$props$row === void 0 ? 0 : _d$props$row,
_d$props$animate = _d$props.animate,
animate = _d$props$animate === void 0 ? true : _d$props$animate,
avatar = _d$props.avatar,
_d$props$avatarShape = _d$props.avatarShape,
avatarShape = _d$props$avatarShape === void 0 ? 'round' : _d$props$avatarShape,
_d$props$avatarSize = _d$props.avatarSize,
avatarSize = _d$props$avatarSize === void 0 ? pxTransform(64) : _d$props$avatarSize,
_d$props$titleWidth = _d$props.titleWidth,
titleWidth = _d$props$titleWidth === void 0 ? '40%' : _d$props$titleWidth,
title = _d$props.title,
_d$props$rowWidth = _d$props.rowWidth,
rowWidth = _d$props$rowWidth === void 0 ? '100%' : _d$props$rowWidth,
_d$props$loading = _d$props.loading,
loading = _d$props$loading === void 0 ? true : _d$props$loading,
children = _d$props.children,
style = _d$props.style,
className = _d$props.className,
others = _objectWithoutProperties(_d$props, _excluded);
useEffect(function () {
setState(function (pre) {
// @ts-ignore
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;