@alifd/meet-react
Version:
Fusion Mobile React UI System Component
102 lines • 6.01 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { __rest } from "tslib";
import React, { createElement, isValidElement } from "react";
import classNames from 'classnames';
import { Text } from "@alifd/meet-react-component-one";
import View from '../view';
import Icon from '../icon';
import Progress from '../progress';
import { isNumber, isString } from '../utils';
var Item = function Item(props) {
var _props$prefix = props.prefix,
prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
order = props.order,
shape = props.shape,
_props$isFirst = props.isFirst,
isFirst = _props$isFirst === void 0 ? false : _props$isFirst,
_props$isLast = props.isLast,
isLast = _props$isLast === void 0 ? false : _props$isLast,
_props$disabled = props.disabled,
disabled = _props$disabled === void 0 ? false : _props$disabled,
_props$isPreDisabled = props.isPreDisabled,
isPreDisabled = _props$isPreDisabled === void 0 ? false : _props$isPreDisabled,
direction = props.direction,
percent = props.percent,
addon = props.addon,
title = props.title,
content = props.content,
status = props.status,
className = props.className,
icon = props.icon,
onClick = props.onClick,
others = __rest(props, ["prefix", "order", "shape", "isFirst", "isLast", "disabled", "isPreDisabled", "direction", "percent", "addon", "title", "content", "status", "className", "icon", "onClick"]);
var clsPrefix = "".concat(prefix, "step-item");
var isArrow = shape === 'arrow';
var isCircle = shape === 'circle';
var clses = {
item: classNames(clsPrefix, className, "".concat(clsPrefix, "--").concat(status), "".concat(clsPrefix, "--").concat(shape), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(clsPrefix, "--last"), isLast), "".concat(clsPrefix, "--first"), isFirst), "".concat(clsPrefix, "--disabled"), disabled), "".concat(clsPrefix, "--pre-disabled"), isPreDisabled)),
dot: classNames("".concat(clsPrefix, "-dot")),
indicator: "".concat(clsPrefix, "-indicator"),
hornLeft: classNames("".concat(clsPrefix, "-horn"), "".concat(clsPrefix, "-horn--left"), _defineProperty({}, "".concat(clsPrefix, "-horn--hide"), isFirst)),
hornRight: classNames("".concat(clsPrefix, "-horn"), "".concat(clsPrefix, "-horn--right"), _defineProperty({}, "".concat(clsPrefix, "-horn--hide"), isLast)),
node: classNames("".concat(clsPrefix, "-node"), _defineProperty({}, "".concat(clsPrefix, "-node--percent"), isCircle && isNumber(percent))),
addon: classNames("".concat(clsPrefix, "-addon"), _defineProperty({}, "".concat(clsPrefix, "-addon--first"), isFirst))
};
var renderCirleContent = function renderCirleContent() {
if (isCircle) {
if (isString(icon) && icon !== '') {
return /*#__PURE__*/React.createElement(Icon, {
name: icon,
size: "xs"
});
} else if (isValidElement(icon)) {
return icon;
} else if (status === 'finish') {
return /*#__PURE__*/React.createElement(Icon, {
name: "select",
size: "xs"
});
} else {
return (order || 0) + 1;
}
} else if (shape === 'arrow') {
return title;
} else {
return null;
}
};
return /*#__PURE__*/React.createElement(View, _extends({}, others, {
className: clses.item,
onClick: onClick
}), addon && ['dot', 'circle'].indexOf(shape) > -1 && direction === 'ver' ? /*#__PURE__*/React.createElement(View, {
className: clses.addon
}, addon) : null, /*#__PURE__*/React.createElement(View, {
className: clses.indicator
}, !isArrow || !isFirst ? /*#__PURE__*/React.createElement(View, {
className: clses.hornLeft
}) : null, isCircle && percent ? /*#__PURE__*/React.createElement(Progress, {
className: clses.node,
percent: percent,
shape: "circle"
}) : /*#__PURE__*/React.createElement(View, {
className: clses.node
}, " ", renderCirleContent()), !isArrow || !isLast ? /*#__PURE__*/React.createElement(View, {
className: clses.hornRight
}) : null), !isArrow ? /*#__PURE__*/React.createElement(View, {
className: "".concat(clsPrefix, "-body")
}, isValidElement(title) ? /*#__PURE__*/React.createElement(View, {
className: "".concat(clsPrefix, "-title")
}, title) : /*#__PURE__*/React.createElement(Text, {
className: "".concat(clsPrefix, "-title")
}, title || ' '), isValidElement(content) ? /*#__PURE__*/React.createElement(View, {
className: "".concat(clsPrefix, "-content")
}, content) : /*#__PURE__*/React.createElement(Text, {
className: "".concat(clsPrefix, "-content")
}, content || ' ')) : null);
};
Item.displayName = 'Step.Item';
export default Item;