UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

56 lines 3.5 kB
import { rpx2vw4style as __rpx2vw__ } from "@alifd/babel-runtime-jsx-style-transform"; 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, forwardRef, useContext } from "react"; import classnames from 'classnames'; import List from '../list'; import View from '../view'; import MenuContext from './menu-context'; import { DEFAULT_INLINE_INDENT } from './constant'; var SubMenu = function SubMenu(props, ref) { var context = useContext(MenuContext); var className = props.className, containerClassName = props.containerClassName, containerStyle = props.containerStyle, children = props.children, label = props.label, loading = props.loading, keyPath = props.keyPath, _props$depth = props.depth, depth = _props$depth === void 0 ? 1 : _props$depth, others = __rest(props, ["className", "containerClassName", "containerStyle", "children", "label", "loading", "keyPath", "depth"]); var prefix = context.prefix, _context$inlineIndent = context.inlineIndent, inlineIndent = _context$inlineIndent === void 0 ? DEFAULT_INLINE_INDENT : _context$inlineIndent, openKeys = context.openKeys, onOpen = context.onOpen; var open = keyPath && openKeys.includes(keyPath); var handleOpen = function handleOpen() { if (!loading) { onOpen({ key: keyPath, open: !open }); } }; return /*#__PURE__*/React.createElement(View, _extends({}, others, { ref: ref, className: containerClassName, style: __rpx2vw__(containerStyle) }), /*#__PURE__*/React.createElement(List.Item, { className: classnames("".concat(prefix, "menu-sub-menu"), className, _defineProperty({}, "".concat(prefix, "menu-sub-menu--loading"), loading)), title: label, arrow: loading ? 'loading' : open ? 'up' : 'down', onClick: handleOpen }), /*#__PURE__*/React.createElement(View, { className: classnames("".concat(prefix, "menu-sub-menu-list"), _defineProperty({}, "".concat(prefix, "menu-sub-menu-list--open"), open)), style: __rpx2vw__({ textIndent: "".concat(inlineIndent * 2 * depth, "rpx") }) }, children)); }; export default /*#__PURE__*/forwardRef(SubMenu);