@nutui/nutui-react-taro
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
67 lines (66 loc) • 3.46 kB
JavaScript
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 React, { useContext } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
import { CellGroup } from "../cellgroup/cellgroup";
import CellGroupContext from "../cellgroup/context";
import { useRtl } from "../configprovider/index";
import { pxTransform } from "../../utils/taro/px-transform";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
title: null,
description: null,
extra: null,
radius: '6px',
align: 'flex-start',
clickable: false,
isLast: false,
onClick: function(event) {}
});
var classPrefix = 'nut-cell';
export var Cell = function(props) {
var ctx = useContext(CellGroupContext);
var _$_object_spread = _object_spread({}, defaultProps, props), children = _$_object_spread.children, onClick = _$_object_spread.onClick, title = _$_object_spread.title, description = _$_object_spread.description, extra = _$_object_spread.extra, radius = _$_object_spread.radius, align = _$_object_spread.align, isLast = _$_object_spread.isLast, className = _$_object_spread.className, style = _$_object_spread.style, clickable = _$_object_spread.clickable;
var rtl = useRtl();
var handleClick = function(event) {
onClick(event);
};
var radiusNumber = Number(String(radius).replace(/[^\d]/g, ''));
var baseStyle = _object_spread_props(_object_spread({}, style), {
borderRadius: pxTransform(radiusNumber),
alignItems: align
});
var _obj;
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(View, {
hoverStyle: {
opacity: clickable ? 0.7 : 1
},
className: "".concat(classNames([
classPrefix,
className,
_define_property({}, "".concat(classPrefix, "-group-item"), ctx === null || ctx === void 0 ? void 0 : ctx.group)
], clickable ? "".concat(classPrefix, "-clickable") : '')),
onClick: function(event) {
return handleClick(event);
},
style: baseStyle
}, children || /*#__PURE__*/ React.createElement(React.Fragment, null, title || description ? /*#__PURE__*/ React.createElement(View, {
className: "".concat(classPrefix, "-left")
}, title ? /*#__PURE__*/ React.createElement(View, {
className: "".concat(classPrefix, "-title")
}, title) : null, description ? /*#__PURE__*/ React.createElement(View, {
className: "".concat(classPrefix, "-description")
}, description) : null) : null, extra ? /*#__PURE__*/ React.createElement(View, {
className: "".concat(classPrefix, "-extra")
}, extra) : null)), (ctx === null || ctx === void 0 ? void 0 : ctx.divider) && !isLast ? /*#__PURE__*/ React.createElement(View, {
className: classNames([
(_obj = {}, _define_property(_obj, "".concat(classPrefix, "-divider"), true), _define_property(_obj, "".concat(classPrefix, "-divider-rtl"), rtl), _obj)
])
}, /*#__PURE__*/ React.createElement(View, {
className: "".concat(classPrefix, "-divider-inner")
})) : null);
};
Cell.displayName = 'NutCell';
Cell.Group = CellGroup;