@nutui/nutui-react
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
47 lines (46 loc) • 2.23 kB
JavaScript
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React from "react";
import classNames from "classnames";
import { DataContext } from "./context";
import { ComponentDefaults } from "../../utils/typings";
var classPrefix = 'nut-row';
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
type: '',
justify: 'start',
align: 'flex-start',
wrap: 'nowrap',
gutter: '0'
});
export var Row = function(props) {
var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, children = _$_object_spread.children, type = _$_object_spread.type, justify = _$_object_spread.justify, align = _$_object_spread.align, wrap = _$_object_spread.wrap, gutter = _$_object_spread.gutter, onClick = _$_object_spread.onClick;
var getClass = function(prefix, type) {
var classType = type ? "nut-row-".concat(prefix, "-").concat(type) : '';
if (prefix) return classType;
if (type) return "nut-row-".concat(type);
return '';
};
var getClasses = function() {
return classNames(classPrefix, getClass('', type), getClass('justify', justify), getClass('align', align), getClass('flex', wrap));
};
var parentRow = {
gutter: gutter
};
return /*#__PURE__*/ React.createElement(DataContext.Provider, {
value: parentRow
}, /*#__PURE__*/ React.createElement("div", {
className: classNames(getClasses(), className),
style: style,
onClick: function(e) {
onClick === null || onClick === void 0 ? void 0 : onClick(e, 'row');
}
}, React.Children.map(children, function(child, index) {
var _child_type;
// @ts-ignore
return (child === null || child === void 0 ? void 0 : (_child_type = child.type) === null || _child_type === void 0 ? void 0 : _child_type.displayName) === 'NutCol' ? /*#__PURE__*/ React.cloneElement(child, {
isFirst: index === 0,
isLast: index === React.Children.count(children) - 1
}) : child;
})));
};
Row.displayName = 'NutRow';