@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
106 lines (105 loc) • 8.7 kB
JavaScript
'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 = ["className", "icon", "title", "children", "extra", "variant", "defaultActive", "collapsible", "active", "keyValue", "onCollapse"];
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
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; }
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import { createStyles, useResponsive } from 'antd-style';
import { isUndefined } from 'lodash-es';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import Collapse from "../../Collapse";
import Icon from "../../Icon";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export var useStyles = createStyles(function (_ref) {
var prefixCls = _ref.prefixCls,
css = _ref.css,
token = _ref.token,
responsive = _ref.responsive;
return {
blockStyle: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background: ", ";\n border: none;\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadiusLG),
defaultStyle: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.colorBorderSecondary, token.borderRadiusLG),
flatGroup: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: hidden;\n padding-inline: 16px;\n "]))),
ghostStyle: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n background: transparent;\n border: 1px solid ", ";\n "])), token.colorBorderSecondary),
icon: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n transition: all 100ms ", ";\n "])), token.motionEaseOut),
mobileFlatGroup: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n border-radius: ", "px;\n "])), token.borderRadiusLG),
mobileGroupBody: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n padding-block: 0;\n padding-inline: 16px;\n background: ", ";\n "])), token.colorBgContainer),
mobileGroupHeader: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n padding: 16px;\n background: ", ";\n "])), token.colorBgLayout),
pure: css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n .", "-collapse-content-box {\n .", "-form-item:first-child {\n border-block-start: 1px solid ", ";\n }\n }\n "])), prefixCls, prefixCls, token.colorFillSecondary),
pureStyle: css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n padding: 0;\n background: transparent;\n border: none;\n border-radius: 0;\n "]))),
pureTitle: css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n font-size: 18px;\n font-weight: 700;\n line-height: 24px;\n "]))),
title: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n align-items: center;\n font-size: 16px;\n font-weight: 600;\n\n .anticon {\n color: ", ";\n }\n\n ", " {\n font-size: 14px;\n font-weight: 400;\n opacity: 0.5;\n }\n "])), token.colorPrimary, responsive.mobile)
};
});
var FormGroup = /*#__PURE__*/memo(function (_ref2) {
var className = _ref2.className,
icon = _ref2.icon,
title = _ref2.title,
children = _ref2.children,
extra = _ref2.extra,
_ref2$variant = _ref2.variant,
variant = _ref2$variant === void 0 ? 'default' : _ref2$variant,
_ref2$defaultActive = _ref2.defaultActive,
defaultActive = _ref2$defaultActive === void 0 ? true : _ref2$defaultActive,
collapsible = _ref2.collapsible,
active = _ref2.active,
_ref2$keyValue = _ref2.keyValue,
keyValue = _ref2$keyValue === void 0 ? 'group' : _ref2$keyValue,
onCollapse = _ref2.onCollapse,
rest = _objectWithoutProperties(_ref2, _excluded);
var _useResponsive = useResponsive(),
mobile = _useResponsive.mobile;
var _useStyles = useStyles(variant),
cx = _useStyles.cx,
styles = _useStyles.styles,
prefixCls = _useStyles.prefixCls;
var groupClassName = "".concat(prefixCls, "-form-group");
var groupTitleClassName = "".concat(prefixCls, "-form-group-title");
var groupHeaderClassName = "".concat(prefixCls, "-form-group-header");
var groupContentClassName = "".concat(prefixCls, "-form-group-content");
var defaultCollapsible = isUndefined(collapsible) ? variant !== 'pure' : collapsible;
var titleContent = /*#__PURE__*/_jsxs(Flexbox, {
className: cx(groupTitleClassName, styles.title, variant === 'pure' && styles.pureTitle),
gap: 8,
horizontal: true,
children: [icon && /*#__PURE__*/_jsx(Icon, {
icon: icon
}), title]
});
if (mobile) return /*#__PURE__*/_jsxs(Flexbox, {
className: cx(groupClassName, className),
children: [/*#__PURE__*/_jsxs(Flexbox, {
className: cx(groupHeaderClassName, styles.mobileGroupHeader),
horizontal: true,
justify: 'space-between',
children: [titleContent, extra]
}), /*#__PURE__*/_jsx("div", {
className: cx(groupContentClassName, styles.mobileGroupBody),
children: children
})]
});
return /*#__PURE__*/_jsx(Collapse, _objectSpread({
activeKey: isUndefined(active) ? undefined : active ? [keyValue] : [],
className: cx(groupClassName, variant === 'pure' && styles.pure, className),
collapsible: defaultCollapsible,
defaultActiveKey: defaultActive ? [keyValue] : undefined,
items: [{
children: children,
extra: extra,
key: keyValue,
label: titleContent
}],
onChange: function onChange(v) {
return onCollapse === null || onCollapse === void 0 ? void 0 : onCollapse(v.length > 0);
},
variant: variant
}, rest));
});
export default FormGroup;