UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

135 lines (134 loc) 7.06 kB
'use client'; 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); } var _excluded = ["variant", "disabled", "shadow", "glass", "actionIconProps", "items", "horizontal", "menu", "onActionClick", "className", "size", "ref"], _excluded2 = ["icon", "key", "label", "onClick", "danger"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } 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); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import { cva } from 'class-variance-authority'; import { MoreHorizontal } from 'lucide-react'; import { memo, useMemo } from 'react'; import { Center } from 'react-layout-kit'; import ActionIcon from "../ActionIcon"; import Dropdown from "../Dropdown"; import { useStyles } from "./style"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var ActionIconGroup = /*#__PURE__*/memo(function (_ref) { var _ref$variant = _ref.variant, variant = _ref$variant === void 0 ? 'filled' : _ref$variant, disabled = _ref.disabled, shadow = _ref.shadow, glass = _ref.glass, actionIconProps = _ref.actionIconProps, _ref$items = _ref.items, items = _ref$items === void 0 ? [] : _ref$items, _ref$horizontal = _ref.horizontal, horizontal = _ref$horizontal === void 0 ? true : _ref$horizontal, menu = _ref.menu, onActionClick = _ref.onActionClick, className = _ref.className, _ref$size = _ref.size, size = _ref$size === void 0 ? 'small' : _ref$size, ref = _ref.ref, rest = _objectWithoutProperties(_ref, _excluded); var _useStyles = useStyles(), cx = _useStyles.cx, styles = _useStyles.styles; var variants = useMemo(function () { return cva(styles.root, { defaultVariants: { disabled: false, glass: false, shadow: false, variant: 'outlined' }, /* eslint-disable sort-keys-fix/sort-keys-fix */ variants: { variant: { filled: styles.filled, outlined: styles.outlined, borderless: styles.borderless }, glass: { false: null, true: styles.glass }, shadow: { false: null, true: styles.shadow }, disabled: { false: null, true: styles.disabled } } /* eslint-enable sort-keys-fix/sort-keys-fix */ }); }, [styles]); var tooltipPlacement = useMemo(function () { var _actionIconProps$tool; return actionIconProps !== null && actionIconProps !== void 0 && (_actionIconProps$tool = actionIconProps.tooltipProps) !== null && _actionIconProps$tool !== void 0 && _actionIconProps$tool.placement || horizontal ? 'top' : 'right'; }, [actionIconProps, horizontal]); return /*#__PURE__*/_jsxs(Center, _objectSpread(_objectSpread({ className: cx(variants({ disabled: disabled, glass: glass, shadow: shadow, variant: variant }), className), horizontal: horizontal, padding: 2, ref: ref }, rest), {}, { children: [(items === null || items === void 0 ? void 0 : items.length) > 0 && items.map(function (item) { var icon = item.icon, key = item.key, label = item.label, _onClick = item.onClick, danger = item.danger, itemRest = _objectWithoutProperties(item, _excluded2); return /*#__PURE__*/_jsx(ActionIcon, _objectSpread(_objectSpread({ danger: danger, icon: icon, onClick: function onClick(e) { onActionClick === null || onActionClick === void 0 || onActionClick({ domEvent: e, key: String(key), keyPath: [String(key)] }); _onClick === null || _onClick === void 0 || _onClick(e); }, size: size, title: label, tooltipProps: { placement: tooltipPlacement } }, actionIconProps), {}, { disabled: disabled || (itemRest === null || itemRest === void 0 ? void 0 : itemRest.disabled) }), key); }), menu && /*#__PURE__*/_jsx(Dropdown, { menu: _objectSpread(_objectSpread({}, menu), {}, { onClick: function onClick(item) { onActionClick === null || onActionClick === void 0 || onActionClick(item); } }), trigger: ['click'], children: /*#__PURE__*/_jsx(ActionIcon, _objectSpread(_objectSpread({ disabled: disabled, icon: MoreHorizontal, size: size }, actionIconProps), {}, { tooltipProps: _objectSpread({ placement: tooltipPlacement }, actionIconProps === null || actionIconProps === void 0 ? void 0 : actionIconProps.tooltipProps) }), "more") })] })); }); ActionIconGroup.displayName = 'ActionIconGroup'; export default ActionIconGroup;