From 4b4231781fafeaff37b6b70ba8d233368d9f3d10 Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 16 Feb 2025 12:17:16 +0800 Subject: [PATCH] feat: inline mode --- .../demos/schema-settings-render.tsx | 2 +- .../hooks/useSchemaSettingsRender.tsx | 13 +++++------ .../src/application/schema-settings/types.ts | 1 + .../src/schema-settings/SchemaSettings.tsx | 23 ++++++++++++++++++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/core/client/docs/zh-CN/core/ui-schema/demos/schema-settings-render.tsx b/packages/core/client/docs/zh-CN/core/ui-schema/demos/schema-settings-render.tsx index c0fde38eec..ec8052f253 100644 --- a/packages/core/client/docs/zh-CN/core/ui-schema/demos/schema-settings-render.tsx +++ b/packages/core/client/docs/zh-CN/core/ui-schema/demos/schema-settings-render.tsx @@ -101,7 +101,7 @@ const Demo = () => { return (
{render()}
-
可以进行参数的二次覆盖:{render({ style: { color: 'red' } })}
+
可以进行参数的二次覆盖:{render({ mode: 'inline', style: { color: 'red' } })}
); }; diff --git a/packages/core/client/src/application/schema-settings/hooks/useSchemaSettingsRender.tsx b/packages/core/client/src/application/schema-settings/hooks/useSchemaSettingsRender.tsx index eb5df07a43..cc332560e6 100644 --- a/packages/core/client/src/application/schema-settings/hooks/useSchemaSettingsRender.tsx +++ b/packages/core/client/src/application/schema-settings/hooks/useSchemaSettingsRender.tsx @@ -7,16 +7,15 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import { useMemo } from 'react'; -import { useApp } from '../../hooks'; -import { SchemaSettingOptions } from '../types'; -import React from 'react'; -import { SchemaSettingsWrapper } from '../components'; -import { SchemaSettingsProps } from '../../../schema-settings'; -import { Schema } from '@formily/json-schema'; import { GeneralField } from '@formily/core'; +import { Schema } from '@formily/json-schema'; +import React, { useMemo } from 'react'; import { Designable } from '../../../schema-component'; +import { SchemaSettingsProps } from '../../../schema-settings'; +import { useApp } from '../../hooks'; +import { SchemaSettingsWrapper } from '../components'; import { SchemaSettings } from '../SchemaSettings'; +import { SchemaSettingOptions } from '../types'; type UseSchemaSettingsRenderOptions = Omit, 'name' | 'items'> & Omit & { diff --git a/packages/core/client/src/application/schema-settings/types.ts b/packages/core/client/src/application/schema-settings/types.ts index 2f4fa59c81..ef8ada158b 100644 --- a/packages/core/client/src/application/schema-settings/types.ts +++ b/packages/core/client/src/application/schema-settings/types.ts @@ -22,6 +22,7 @@ import { export interface SchemaSettingOptions { name: string; + mode?: 'inline' | 'dropdown'; Component?: ComponentType; componentProps?: T; items: SchemaSettingsItemType[]; diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 9ae78a6154..be9a281da0 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -22,6 +22,7 @@ import { CascaderProps, ConfigProvider, Dropdown, + Menu, MenuItemProps, MenuProps, Modal, @@ -119,6 +120,7 @@ export interface SchemaSettingsProps { field?: GeneralField; fieldSchema?: Schema; children?: ReactNode; + mode?: 'inline' | 'dropdown'; } interface SchemaSettingsContextProps { @@ -167,7 +169,7 @@ export const SchemaSettingsProvider: React.FC = (pr return {children}; }; -export const SchemaSettingsDropdown: React.FC = React.memo((props) => { +const InternalSchemaSettingsDropdown: React.FC = React.memo((props) => { const { title, dn, ...others } = props; const [visible, setVisible] = useState(false); const { Component, getMenuItems } = useMenuItem(); @@ -232,6 +234,25 @@ export const SchemaSettingsDropdown: React.FC = React.memo( ); }); +const InternalSchemaSettingsMenu: React.FC = React.memo((props) => { + const { title, dn, ...others } = props; + const [visible, setVisible] = useState(true); + const { Component, getMenuItems } = useMenuItem(); + const items = getMenuItems(() => props.children); + + return ( + + + + + ); +}); + +export const SchemaSettingsDropdown: React.FC = React.memo((props) => { + const { mode } = props; + return mode === 'inline' ? : ; +}); + SchemaSettingsDropdown.displayName = 'SchemaSettingsDropdown'; const findGridSchema = (fieldSchema) => {