UNPKG

@oceanbase/ui

Version:

The UI library based on OceanBase Design

153 lines (151 loc) 6.72 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/Action/Group.tsx var Group_exports = {}; __export(Group_exports, { default: () => Group_default }); module.exports = __toCommonJS(Group_exports); var import_react = __toESM(require("react")); var import_design = require("@oceanbase/design"); var import_icons = require("@oceanbase/icons"); var import_lodash = require("lodash"); var import_style = __toESM(require("./style")); var getOrder = ({ type, fixed }) => { const ORDER_SET = { primary: 3, fixed: 2, default: 0 }; let order = ORDER_SET.default; if (type === "primary") { order += ORDER_SET.primary; } if (fixed) { order += ORDER_SET.fixed; } return order; }; var Group_default = ({ prefixCls: customizePrefixCls, size = 3, children, dropDownPlacement, shouldVisible, shouldDisabled, enableLoading, moreText, moreType, buttonSize }) => { const { getPrefixCls } = (0, import_react.useContext)(import_design.ConfigProvider.ConfigContext); const prefixCls = getPrefixCls("action", customizePrefixCls); const { wrapSSR } = (0, import_style.default)(prefixCls); const visibleActions = Array.isArray(children) ? children.filter((c) => { if ((0, import_lodash.isBoolean)(c.props.visible) && shouldVisible) return c.props.visible && shouldVisible(c.key); if ((0, import_lodash.isBoolean)(c.props.visible)) return c.props.visible; else if (shouldVisible) return shouldVisible(c.key); return true; }) : [children]; const visibleActionsSort = visibleActions.slice(0); visibleActionsSort.sort((a, b) => { const orderA = getOrder(a.props); const orderB = getOrder(b.props); return orderB - orderA; }); const fixedSize = visibleActionsSort.filter( (action) => action.props.type === "primary" || action.props.fixed ).length; const realSize = (0, import_lodash.max)([fixedSize, size]); const mainActions = visibleActionsSort.slice(0, realSize); const ellipsisActions = visibleActionsSort.slice(realSize); let ellipsisType = "link"; if (visibleActionsSort.some((action) => action.type.__DISPLAY_NAME === "button")) { ellipsisType = "button"; } if (visibleActionsSort.some((action) => action.type.__DISPLAY_NAME === "link")) { ellipsisType = "link"; } ellipsisType = moreType ?? ellipsisType; const getDefaultDisabled = (key) => (shouldDisabled == null ? void 0 : shouldDisabled(key)) ?? false; let moreDom; if (ellipsisType === "button") { moreDom = /* @__PURE__ */ import_react.default.createElement( import_design.Button, { size: buttonSize, icon: moreText ? void 0 : /* @__PURE__ */ import_react.default.createElement(import_icons.EllipsisOutlined, { style: { cursor: "pointer" } }) }, moreText ); } else { moreDom = /* @__PURE__ */ import_react.default.createElement(import_design.Typography.Link, null, moreText ?? /* @__PURE__ */ import_react.default.createElement(import_icons.EllipsisOutlined, { style: { cursor: "pointer" } })); } return wrapSSR( /* @__PURE__ */ import_react.default.createElement(import_design.Space, { size: ellipsisType === "button" ? 8 : 16 }, mainActions.map((action) => { return import_react.default.cloneElement(action, { // size should be covered by action props size: buttonSize, ...action.props, key: action.key, enableLoading, disabled: (0, import_lodash.isBoolean)(action.props.disabled) ? action.props.disabled : getDefaultDisabled(action.key) }); }), ellipsisActions.length > 0 && /* @__PURE__ */ import_react.default.createElement( import_design.Dropdown, { placement: dropDownPlacement, overlay: /* @__PURE__ */ import_react.default.createElement(import_design.Menu, { className: `${prefixCls}-more-menu` }, ellipsisActions.map((action, index) => { const actionKey = action.key; let disabled = false; if ((0, import_lodash.isBoolean)(action.props.disabled)) disabled = action.props.disabled; else if (shouldDisabled) disabled = shouldDisabled(action.key); const actionDisabled = action.props.loading || ((0, import_lodash.isBoolean)(action.props.disabled) ? action.props.disabled : getDefaultDisabled(action.key)); return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement( import_design.Menu.Item, { key: actionKey ?? index.toString(), onClick: ({ domEvent }) => { var _a, _b; (_b = (_a = action.props).onClick) == null ? void 0 : _b.call( _a, domEvent ); }, ...(0, import_lodash.omit)(action.props, ["disabled"]), disabled: actionDisabled }, /* @__PURE__ */ import_react.default.createElement(import_design.Tooltip, { title: action.props.tooltip }, action.props.loading && /* @__PURE__ */ import_react.default.createElement(import_icons.LoadingOutlined, null), " ", action.props.children || action) ), action.props.divider && /* @__PURE__ */ import_react.default.createElement(import_design.Menu.Divider, null)); })) }, moreDom )) ); };