@lobehub/ui 1.155.6 → 1.155.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,7 @@ var Collapse = /*#__PURE__*/memo(function (_ref) {
32
32
  return /*#__PURE__*/_jsx(AntdCollapse, _objectSpread({
33
33
  bordered: !gap && (variant === 'default' || variant === 'ghost'),
34
34
  className: cx(styles.group, !collapsible && styles.hideCollapsibleIcon, variantStyle, className),
35
+ collapsible: collapsible ? 'header' : 'icon',
35
36
  expandIcon: function expandIcon(_ref2) {
36
37
  var isActive = _ref2.isActive;
37
38
  return /*#__PURE__*/_jsx(Icon, {
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ import { FormVariant } from './FormGroup';
4
+ export interface FormFlatGroupProps extends FlexboxProps {
5
+ variant?: FormVariant;
6
+ }
7
+ declare const FormFlatGroup: import("react").NamedExoticComponent<FormFlatGroupProps>;
8
+ export default FormFlatGroup;
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["className", "children", "variant"];
6
+ import { useResponsive } from 'antd-style';
7
+ import { memo } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import { useStyles } from "./FormGroup";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ var FormFlatGroup = /*#__PURE__*/memo(function (_ref) {
12
+ var className = _ref.className,
13
+ children = _ref.children,
14
+ _ref$variant = _ref.variant,
15
+ variant = _ref$variant === void 0 ? 'default' : _ref$variant,
16
+ rest = _objectWithoutProperties(_ref, _excluded);
17
+ var _useResponsive = useResponsive(),
18
+ mobile = _useResponsive.mobile;
19
+ var _useStyles = useStyles(variant),
20
+ cx = _useStyles.cx,
21
+ styles = _useStyles.styles,
22
+ prefixCls = _useStyles.prefixCls;
23
+ var groupClassName = "".concat(prefixCls, "-form-group");
24
+ var variantStyle = cx(variant === 'default' && styles.defaultStyle, variant === 'block' && styles.blockStyle, variant === 'ghost' && styles.ghostStyle, variant === 'pure' && styles.pureStyle);
25
+ return mobile ? /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
26
+ className: cx(groupClassName, styles.mobileFlatGroup, styles.mobileGroupBody, className)
27
+ }, rest), {}, {
28
+ children: children
29
+ })) : /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
30
+ className: cx(groupClassName, styles.flatGroup, variantStyle, className)
31
+ }, rest), {}, {
32
+ children: children
33
+ }));
34
+ });
35
+ export default FormFlatGroup;
@@ -1,5 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type CollapseProps } from "../../Collapse";
3
+ import type { FormItemProps } from "./FormItem";
3
4
  import { type IconProps } from "../../Icon";
4
5
  export type FormVariant = 'default' | 'block' | 'ghost' | 'pure';
5
6
  export type ItemsType = 'group' | 'flat';
@@ -16,13 +17,25 @@ export declare const useStyles: (props?: unknown) => import("antd-style").Return
16
17
  pureTitle: import("antd-style").SerializedStyles;
17
18
  title: import("antd-style").SerializedStyles;
18
19
  }>;
19
- export interface FormGroupProps extends Omit<CollapseProps, 'collapsible'> {
20
+ export interface ItemGroup {
21
+ children: FormItemProps[] | ReactNode;
22
+ collapsible?: boolean;
23
+ defaultActive?: boolean;
24
+ extra?: ReactNode;
25
+ icon?: IconProps['icon'];
26
+ key?: string;
27
+ title: ReactNode;
28
+ variant?: FormVariant;
29
+ }
30
+ export interface FormGroupProps extends Omit<CollapseProps, 'collapsible' | 'items' | 'defaultActiveKey' | 'activeKey'> {
31
+ active?: boolean;
20
32
  children: ReactNode;
21
33
  collapsible?: boolean;
22
34
  defaultActive?: boolean;
23
35
  extra?: ReactNode;
24
36
  icon?: IconProps['icon'];
25
- itemsType?: ItemsType;
37
+ key?: string | number;
38
+ onCollapse?: (active: boolean) => void;
26
39
  title?: ReactNode;
27
40
  variant?: FormVariant;
28
41
  }
@@ -3,7 +3,7 @@
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
5
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
6
- var _excluded = ["className", "icon", "title", "children", "extra", "itemsType", "variant", "defaultActive", "collapsible"];
6
+ var _excluded = ["className", "icon", "title", "children", "extra", "variant", "defaultActive", "collapsible", "active", "key", "onCollapse"];
7
7
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
8
8
  import { createStyles, useResponsive } from 'antd-style';
9
9
  import { isUndefined } from 'lodash-es';
@@ -37,12 +37,15 @@ var FormGroup = /*#__PURE__*/memo(function (_ref2) {
37
37
  title = _ref2.title,
38
38
  children = _ref2.children,
39
39
  extra = _ref2.extra,
40
- itemsType = _ref2.itemsType,
41
40
  _ref2$variant = _ref2.variant,
42
41
  variant = _ref2$variant === void 0 ? 'default' : _ref2$variant,
43
42
  _ref2$defaultActive = _ref2.defaultActive,
44
43
  defaultActive = _ref2$defaultActive === void 0 ? true : _ref2$defaultActive,
45
44
  collapsible = _ref2.collapsible,
45
+ active = _ref2.active,
46
+ _ref2$key = _ref2.key,
47
+ key = _ref2$key === void 0 ? 'group' : _ref2$key,
48
+ onCollapse = _ref2.onCollapse,
46
49
  rest = _objectWithoutProperties(_ref2, _excluded);
47
50
  var _useResponsive = useResponsive(),
48
51
  mobile = _useResponsive.mobile;
@@ -54,7 +57,6 @@ var FormGroup = /*#__PURE__*/memo(function (_ref2) {
54
57
  var groupTitleClassName = "".concat(prefixCls, "-form-group-title");
55
58
  var groupHeaderClassName = "".concat(prefixCls, "-form-group-header");
56
59
  var groupContentClassName = "".concat(prefixCls, "-form-group-content");
57
- var variantStyle = cx(variant === 'default' && styles.defaultStyle, variant === 'block' && styles.blockStyle, variant === 'ghost' && styles.ghostStyle, variant === 'pure' && styles.pureStyle);
58
60
  var defaultCollapsible = isUndefined(collapsible) ? variant !== 'pure' : collapsible;
59
61
  var titleContent = /*#__PURE__*/_jsxs(Flexbox, {
60
62
  className: cx(groupTitleClassName, styles.title, variant === 'pure' && styles.pureTitle),
@@ -64,15 +66,6 @@ var FormGroup = /*#__PURE__*/memo(function (_ref2) {
64
66
  icon: icon
65
67
  }), title]
66
68
  });
67
- if (itemsType === 'flat') {
68
- return mobile ? /*#__PURE__*/_jsx(Flexbox, {
69
- className: cx(groupClassName, styles.mobileFlatGroup, styles.mobileGroupBody, className),
70
- children: children
71
- }) : /*#__PURE__*/_jsx(Flexbox, {
72
- className: cx(groupClassName, styles.flatGroup, variantStyle, className),
73
- children: children
74
- });
75
- }
76
69
  if (mobile) return /*#__PURE__*/_jsxs(Flexbox, {
77
70
  className: cx(groupClassName, className),
78
71
  children: [/*#__PURE__*/_jsxs(Flexbox, {
@@ -86,16 +79,20 @@ var FormGroup = /*#__PURE__*/memo(function (_ref2) {
86
79
  })]
87
80
  });
88
81
  return /*#__PURE__*/_jsx(Collapse, _objectSpread({
82
+ activeKey: isUndefined(active) ? undefined : active ? [key] : [],
89
83
  className: cx(groupClassName, className),
90
84
  collapsible: defaultCollapsible,
91
- defaultActiveKey: defaultActive ? [1] : undefined,
85
+ defaultActiveKey: defaultActive ? [key] : undefined,
92
86
  items: [{
93
87
  children: children,
94
88
  extra: extra,
95
- key: 1,
89
+ key: key,
96
90
  label: titleContent
97
91
  }],
92
+ onChange: function onChange(v) {
93
+ return onCollapse === null || onCollapse === void 0 ? void 0 : onCollapse(v.length > 0);
94
+ },
98
95
  variant: variant
99
- }, rest), 1);
96
+ }, rest));
100
97
  });
101
98
  export default FormGroup;
@@ -1,25 +1,21 @@
1
1
  import { Form as AntForm, FormProps as AntFormProps, type FormInstance } from 'antd';
2
2
  import { CSSProperties, type ReactNode, RefAttributes } from 'react';
3
- import FormGroup, { type FormGroupProps, FormVariant, ItemsType } from './components/FormGroup';
3
+ import FormGroup, { type FormVariant, type ItemGroup, type ItemsType } from './components/FormGroup';
4
4
  import FormItem, { type FormItemProps } from './components/FormItem';
5
- export interface ItemGroup {
6
- children: FormItemProps[] | ReactNode;
7
- defaultActive?: boolean;
8
- extra?: FormGroupProps['extra'];
9
- icon?: FormGroupProps['icon'];
10
- title: FormGroupProps['title'];
11
- }
12
5
  export interface FormProps extends Omit<AntFormProps, 'variant'> {
6
+ activeKey?: (string | number)[];
13
7
  children?: ReactNode;
14
8
  classNames?: {
15
9
  footer?: string;
16
10
  };
17
11
  collapsible?: boolean;
12
+ defaultActiveKey?: (string | number)[];
18
13
  footer?: ReactNode;
19
14
  gap?: number | string;
20
15
  itemMinWidth?: FormItemProps['minWidth'];
21
16
  items?: ItemGroup[] | FormItemProps[];
22
17
  itemsType?: ItemsType;
18
+ onCollapse?: (key: (string | number)[]) => void;
23
19
  styles?: {
24
20
  footer?: CSSProperties;
25
21
  };
package/es/Form/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  'use client';
2
2
 
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
4
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["className", "itemMinWidth", "footer", "form", "items", "children", "itemsType", "variant", "gap", "style", "collapsible", "classNames", "styles"];
6
+ var _excluded = ["className", "itemMinWidth", "footer", "form", "items", "children", "itemsType", "variant", "gap", "style", "collapsible", "classNames", "styles", "defaultActiveKey", "activeKey", "onCollapse"];
6
7
  import { Form as AntForm } from 'antd';
8
+ import { isUndefined } from 'lodash-es';
7
9
  import { forwardRef } from 'react';
10
+ import FormFlatGroup from "./components/FormFlatGroup";
8
11
  import FormFooter from "./components/FormFooter";
9
12
  import FormGroup from "./components/FormGroup";
10
13
  import FormItem from "./components/FormItem";
@@ -30,6 +33,9 @@ var FormParent = /*#__PURE__*/forwardRef(function (_ref, ref) {
30
33
  classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
31
34
  _ref$styles = _ref.styles,
32
35
  styles = _ref$styles === void 0 ? {} : _ref$styles,
36
+ defaultActiveKey = _ref.defaultActiveKey,
37
+ activeKey = _ref.activeKey,
38
+ _onCollapse = _ref.onCollapse,
33
39
  rest = _objectWithoutProperties(_ref, _excluded);
34
40
  var _useStyles = useStyles(),
35
41
  cx = _useStyles.cx,
@@ -41,19 +47,28 @@ var FormParent = /*#__PURE__*/forwardRef(function (_ref, ref) {
41
47
  }, item), itemIndex);
42
48
  };
43
49
  var mapTree = function mapTree(group, groupIndex) {
50
+ var key = (group === null || group === void 0 ? void 0 : group.key) || groupIndex;
44
51
  return /*#__PURE__*/_jsx(FormGroup, {
45
- collapsible: collapsible,
46
- defaultActive: group === null || group === void 0 ? void 0 : group.defaultActive,
52
+ active: activeKey && group !== null && group !== void 0 && group.key ? activeKey.includes(key) : undefined,
53
+ collapsible: isUndefined(group.collapsible) ? collapsible : group.collapsible,
54
+ defaultActive: defaultActiveKey && group !== null && group !== void 0 && group.key ? defaultActiveKey.includes(key) : group === null || group === void 0 ? void 0 : group.defaultActive,
47
55
  extra: group === null || group === void 0 ? void 0 : group.extra,
48
56
  icon: group === null || group === void 0 ? void 0 : group.icon,
57
+ onCollapse: function onCollapse(active) {
58
+ var keys = activeKey || defaultActiveKey || [];
59
+ keys = keys.filter(function (k) {
60
+ return k !== key;
61
+ });
62
+ _onCollapse === null || _onCollapse === void 0 || _onCollapse(active ? [].concat(_toConsumableArray(keys), [key]) : keys);
63
+ },
49
64
  title: group.title,
50
- variant: variant,
65
+ variant: (group === null || group === void 0 ? void 0 : group.variant) || variant,
51
66
  children: Array.isArray(group.children) ? group.children.filter(function (item) {
52
67
  return !item.hidden;
53
68
  }).map(function (item, i) {
54
69
  return mapFlat(item, i);
55
70
  }) : group.children
56
- }, groupIndex);
71
+ }, key);
57
72
  };
58
73
  return /*#__PURE__*/_jsxs(AntForm, _objectSpread(_objectSpread({
59
74
  className: cx(s.form, variant === 'pure' && s.pure, s.mobile, className),
@@ -67,8 +82,7 @@ var FormParent = /*#__PURE__*/forwardRef(function (_ref, ref) {
67
82
  }, rest), {}, {
68
83
  children: [items && (items === null || items === void 0 ? void 0 : items.length) > 0 ? itemsType === 'group' ? items === null || items === void 0 ? void 0 : items.map(function (item, i) {
69
84
  return mapTree(item, i);
70
- }) : /*#__PURE__*/_jsx(FormGroup, {
71
- itemsType: 'flat',
85
+ }) : /*#__PURE__*/_jsx(FormFlatGroup, {
72
86
  variant: variant,
73
87
  children: items === null || items === void 0 ? void 0 : items.filter(function (item) {
74
88
  return !item.hidden;
@@ -21,10 +21,10 @@ export { default as FileTypeIcon, type FileTypeIconProps } from './FileTypeIcon'
21
21
  export { default as FluentEmoji, type FluentEmojiProps } from './FluentEmoji';
22
22
  export { default as FontLoader, type FontLoaderProps } from './FontLoader';
23
23
  export { default as Footer, type FooterProps } from './Footer';
24
- export { default as Form, type FormInstance, type FormProps, type ItemGroup } from './Form';
24
+ export { default as Form, type FormInstance, type FormProps } from './Form';
25
25
  export { default as FormDivider, type FormDividerProps } from './Form/components/FormDivider';
26
26
  export { default as FormFooter, type FormFooterProps } from './Form/components/FormFooter';
27
- export { default as FormGroup, type FormGroupProps } from './Form/components/FormGroup';
27
+ export { default as FormGroup, type FormGroupProps, type ItemGroup, } from './Form/components/FormGroup';
28
28
  export { default as FormItem, type FormItemProps } from './Form/components/FormItem';
29
29
  export { default as FormTitle, type FormTitleProps } from './Form/components/FormTitle';
30
30
  export { default as FormModal, type FormModalProps } from './FormModal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.155.6",
3
+ "version": "1.155.7",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",