@gizwits/vantui
Version:
机智云组件库
118 lines • 5.4 kB
JavaScript
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["icon", "iconColor", "iconPrefix", "dot", "info", "badge", "text", "setChildrenInstance", "parentInstance", "index", "url", "linkType", "style", "className"];
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 * 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 icon = props.icon,
iconColor = props.iconColor,
_props$iconPrefix = props.iconPrefix,
iconPrefix = _props$iconPrefix === void 0 ? 'van-icon' : _props$iconPrefix,
dot = props.dot,
info = props.info,
badge = props.badge,
text = props.text,
setChildrenInstance = props.setChildrenInstance,
parentInstance = props.parentInstance,
index = props.index,
url = props.url,
linkType = props.linkType,
style = props.style,
className = props.className,
others = _objectWithoutProperties(props, _excluded);
var _useState = useState({}),
_useState2 = _slicedToArray(_useState, 2),
parentState = _useState2[0],
setParentState = _useState2[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
}) : parentState.renderIcon
}), /*#__PURE__*/_jsx(View, {
className: "van-grid-item__text text-class",
children: text ? /*#__PURE__*/_jsx(Text, {
children: text
}) : parentState.renderText
})]
})
})
});
}
export default GridItem;