mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
feat: inline mode
This commit is contained in:
parent
9b412b1a23
commit
4b4231781f
@ -101,7 +101,7 @@ const Demo = () => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>{render()}</div>
|
<div>{render()}</div>
|
||||||
<div>可以进行参数的二次覆盖:{render({ style: { color: 'red' } })}</div>
|
<div>可以进行参数的二次覆盖:{render({ mode: 'inline', style: { color: 'red' } })}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -7,16 +7,15 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* 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 { GeneralField } from '@formily/core';
|
||||||
|
import { Schema } from '@formily/json-schema';
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
import { Designable } from '../../../schema-component';
|
import { Designable } from '../../../schema-component';
|
||||||
|
import { SchemaSettingsProps } from '../../../schema-settings';
|
||||||
|
import { useApp } from '../../hooks';
|
||||||
|
import { SchemaSettingsWrapper } from '../components';
|
||||||
import { SchemaSettings } from '../SchemaSettings';
|
import { SchemaSettings } from '../SchemaSettings';
|
||||||
|
import { SchemaSettingOptions } from '../types';
|
||||||
|
|
||||||
type UseSchemaSettingsRenderOptions<T = {}> = Omit<SchemaSettingOptions<T>, 'name' | 'items'> &
|
type UseSchemaSettingsRenderOptions<T = {}> = Omit<SchemaSettingOptions<T>, 'name' | 'items'> &
|
||||||
Omit<SchemaSettingsProps, 'title' | 'children'> & {
|
Omit<SchemaSettingsProps, 'title' | 'children'> & {
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
|
|
||||||
export interface SchemaSettingOptions<T = {}> {
|
export interface SchemaSettingOptions<T = {}> {
|
||||||
name: string;
|
name: string;
|
||||||
|
mode?: 'inline' | 'dropdown';
|
||||||
Component?: ComponentType<T>;
|
Component?: ComponentType<T>;
|
||||||
componentProps?: T;
|
componentProps?: T;
|
||||||
items: SchemaSettingsItemType[];
|
items: SchemaSettingsItemType[];
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
CascaderProps,
|
CascaderProps,
|
||||||
ConfigProvider,
|
ConfigProvider,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
|
Menu,
|
||||||
MenuItemProps,
|
MenuItemProps,
|
||||||
MenuProps,
|
MenuProps,
|
||||||
Modal,
|
Modal,
|
||||||
@ -119,6 +120,7 @@ export interface SchemaSettingsProps {
|
|||||||
field?: GeneralField;
|
field?: GeneralField;
|
||||||
fieldSchema?: Schema;
|
fieldSchema?: Schema;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
mode?: 'inline' | 'dropdown';
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SchemaSettingsContextProps<T = any> {
|
interface SchemaSettingsContextProps<T = any> {
|
||||||
@ -167,7 +169,7 @@ export const SchemaSettingsProvider: React.FC<SchemaSettingsProviderProps> = (pr
|
|||||||
return <SchemaSettingsContext.Provider value={value}>{children}</SchemaSettingsContext.Provider>;
|
return <SchemaSettingsContext.Provider value={value}>{children}</SchemaSettingsContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SchemaSettingsDropdown: React.FC<SchemaSettingsProps> = React.memo((props) => {
|
const InternalSchemaSettingsDropdown: React.FC<SchemaSettingsProps> = React.memo((props) => {
|
||||||
const { title, dn, ...others } = props;
|
const { title, dn, ...others } = props;
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const { Component, getMenuItems } = useMenuItem();
|
const { Component, getMenuItems } = useMenuItem();
|
||||||
@ -232,6 +234,25 @@ export const SchemaSettingsDropdown: React.FC<SchemaSettingsProps> = React.memo(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const InternalSchemaSettingsMenu: React.FC<SchemaSettingsProps> = React.memo((props) => {
|
||||||
|
const { title, dn, ...others } = props;
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
const { Component, getMenuItems } = useMenuItem();
|
||||||
|
const items = getMenuItems(() => props.children);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SchemaSettingsProvider visible={visible} setVisible={setVisible} dn={dn} {...others}>
|
||||||
|
<Component />
|
||||||
|
<Menu items={items} />
|
||||||
|
</SchemaSettingsProvider>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SchemaSettingsDropdown: React.FC<SchemaSettingsProps> = React.memo((props) => {
|
||||||
|
const { mode } = props;
|
||||||
|
return mode === 'inline' ? <InternalSchemaSettingsMenu {...props} /> : <InternalSchemaSettingsDropdown {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
SchemaSettingsDropdown.displayName = 'SchemaSettingsDropdown';
|
SchemaSettingsDropdown.displayName = 'SchemaSettingsDropdown';
|
||||||
|
|
||||||
const findGridSchema = (fieldSchema) => {
|
const findGridSchema = (fieldSchema) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user