@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
127 lines • 6.63 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 = ["icon", "iconColor", "iconPrefix", "dot", "info", "badge", "text", "setChildrenInstance", "parentInstance", "index", "url", "linkType", "style", "className", "renderIcon"];
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 { View, Text } from '@tarojs/components';
import { useState, useEffect, useCallback } from 'react';
import { jumpLink } from '../common/jumpLink';
import * as utils from '../wxs/utils';
import VanIcon from '../icon/index';
import { get } from '../default-props';
import * as computed from './wxs';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export function GridItem(props) {
var _useState = useState(get().GridItem),
_useState2 = _slicedToArray(_useState, 1),
d = _useState2[0];
var _d$props = _objectSpread(_objectSpread({}, d), props),
icon = _d$props.icon,
iconColor = _d$props.iconColor,
_d$props$iconPrefix = _d$props.iconPrefix,
iconPrefix = _d$props$iconPrefix === void 0 ? 'van-icon' : _d$props$iconPrefix,
dot = _d$props.dot,
info = _d$props.info,
badge = _d$props.badge,
text = _d$props.text,
setChildrenInstance = _d$props.setChildrenInstance,
parentInstance = _d$props.parentInstance,
index = _d$props.index,
url = _d$props.url,
linkType = _d$props.linkType,
style = _d$props.style,
className = _d$props.className,
renderIcon = _d$props.renderIcon,
others = _objectWithoutProperties(_d$props, _excluded);
var _useState3 = useState({}),
_useState4 = _slicedToArray(_useState3, 2),
parentState = _useState4[0],
setParentState = _useState4[1];
useEffect(function () {
setChildrenInstance(index, {
updateStyle: updateStyle
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[index, setChildrenInstance]);
useEffect(function () {
updateStyle();
// eslint-disable-next-line react-hooks/exhaustive-deps
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[parentInstance.columnNum]);
var updateStyle = useCallback(function () {
var columnNum = parentInstance.columnNum,
border = parentInstance.border,
square = parentInstance.square,
gutter = parentInstance.gutter,
clickable = parentInstance.clickable,
center = parentInstance.center,
direction = parentInstance.direction,
reverse = parentInstance.reverse,
iconSize = parentInstance.iconSize;
setParentState({
center: center,
border: border,
square: square,
gutter: gutter,
clickable: clickable,
direction: direction,
reverse: reverse,
iconSize: iconSize,
index: index,
columnNum: columnNum
});
}, [parentInstance, index]);
return /*#__PURE__*/_jsx(View, {
className: ' ' + utils.bem('grid-item', {
square: parentState === null || parentState === void 0 ? void 0 : parentState.square
}) + ' ' + className,
style: utils.style([computed.wrapperStyle({
square: parentState === null || parentState === void 0 ? void 0 : parentState.square,
gutter: parentState === null || parentState === void 0 ? void 0 : parentState.gutter,
columnNum: parentState === null || parentState === void 0 ? void 0 : parentState.columnNum,
index: parentState === null || parentState === void 0 ? void 0 : parentState.index
}), style]),
onClick: function onClick(e) {
var _others$onClick;
url && jumpLink(url, linkType);
others === null || others === void 0 ? void 0 : (_others$onClick = others.onClick) === null || _others$onClick === void 0 ? void 0 : _others$onClick.call(others, e);
},
children: /*#__PURE__*/_jsx(View, {
className: 'content-class ' + utils.bem('grid-item__content', [parentState === null || parentState === void 0 ? void 0 : parentState.direction, {
center: parentState === null || parentState === void 0 ? void 0 : parentState.center,
square: parentState === null || parentState === void 0 ? void 0 : parentState.square,
reverse: parentState === null || parentState === void 0 ? void 0 : parentState.reverse,
clickable: parentState === null || parentState === void 0 ? void 0 : parentState.clickable,
surround: (parentState === null || parentState === void 0 ? void 0 : parentState.border) && (parentState === null || parentState === void 0 ? void 0 : parentState.gutter)
}]) + ' ' + (parentState !== null && parentState !== void 0 && parentState.border ? 'van-hairline--surround' : ''),
style: computed.contentStyle({
square: parentState === null || parentState === void 0 ? void 0 : parentState.square,
gutter: parentState === null || parentState === void 0 ? void 0 : parentState.gutter
}),
children: others.children || /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(View, {
className: "van-grid-item__icon icon-class",
children: icon ? /*#__PURE__*/_jsx(VanIcon, {
name: icon,
color: iconColor,
classPrefix: iconPrefix,
dot: dot,
info: badge || info,
size: parentState === null || parentState === void 0 ? void 0 : parentState.iconSize
}) : renderIcon
}), /*#__PURE__*/_jsx(View, {
className: "van-grid-item__text text-class",
children: text ? /*#__PURE__*/_jsx(Text, {
children: text
}) : parentState.renderText
})]
})
})
});
}
export default GridItem;