feat(client): add disabled option to props of SchemaSettingsItem (#4817)

* feat(client): add disabled option to props of SchemaSettingsItem

* docs(client): add doc and demo

* feat(client): add disabled option to SchemaInitializerItem
This commit is contained in:
Junyi 2024-07-05 13:28:59 +08:00 committed by GitHub
parent b3c0e5fbe3
commit 0ba1bca5d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 9 deletions

View File

@ -26,6 +26,12 @@ const mySettings = new SchemaSettings({
name: 'markdown', name: 'markdown',
Component: MarkdownEdit, Component: MarkdownEdit,
}, },
{
name: 'disabled',
Component() {
return <SchemaSettingsItem title="Disabled" disabled />;
},
},
], ],
}); });

View File

@ -26,6 +26,12 @@ const mySettings = new SchemaSettings({
name: 'markdown', name: 'markdown',
Component: MarkdownEdit, Component: MarkdownEdit,
}, },
{
name: 'disabled',
Component() {
return <SchemaSettingsItem title="Disabled" disabled />;
},
},
], ],
}); });

View File

@ -24,6 +24,7 @@ export interface SchemaInitializerItemProps {
icon?: React.ReactNode; icon?: React.ReactNode;
title?: React.ReactNode; title?: React.ReactNode;
items?: any[]; items?: any[];
disabled?: boolean;
onClick?: (args?: any) => any; onClick?: (args?: any) => any;
applyMenuStyle?: boolean; applyMenuStyle?: boolean;
children?: ReactNode; children?: ReactNode;
@ -41,6 +42,7 @@ export const SchemaInitializerItem = memo(
name = uid(), name = uid(),
applyMenuStyle = true, applyMenuStyle = true,
className, className,
disabled,
items, items,
icon, icon,
title, title,
@ -89,7 +91,10 @@ export const SchemaInitializerItem = memo(
> >
<div <div
{...attribute} {...attribute}
className={classNames({ [`${componentCls}-menu-item`]: applyMenuStyle }, className)} className={classNames(
{ [`${componentCls}-menu-item`]: applyMenuStyle, [`${componentCls}-menu-item-disabled`]: disabled },
className,
)}
style={style} style={style}
> >
{children || ( {children || (

View File

@ -24,7 +24,8 @@ export const SchemaInitializerSwitch: FC<SchemaInitializerSwitchItemProps> = (pr
return ( return (
<SchemaInitializerItem {...resets} closeInitializerMenuWhenClick={false}> <SchemaInitializerItem {...resets} closeInitializerMenuWhenClick={false}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}> <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
{compile(title)} <Switch style={{ marginLeft: 20 }} size={'small'} checked={checked} /> {compile(title)}
<Switch disabled={props.disabled} style={{ marginLeft: 20 }} size={'small'} checked={checked} />
</div> </div>
</SchemaInitializerItem> </SchemaInitializerItem>
); );

View File

@ -35,11 +35,18 @@ export const useSchemaInitializerStyles = genStyleHook('nb-schema-initializer',
// height: token.controlHeight, // height: token.controlHeight,
lineHeight: `${token.controlHeight}px`, lineHeight: `${token.controlHeight}px`,
color: token.colorText, color: token.colorText,
cursor: 'pointer',
'&:hover': { [`&:not(${componentCls}-menu-item-disabled)`]: {
borderRadius: token.borderRadiusSM, cursor: 'pointer',
backgroundColor: token.colorBgTextHover, [`&:hover`]: {
borderRadius: token.borderRadiusSM,
backgroundColor: token.colorBgTextHover,
},
},
[`&${componentCls}-menu-item-disabled`]: {
cursor: 'not-allowed',
color: token.colorTextDisabled,
}, },
}, },
}, },

View File

@ -321,6 +321,7 @@ export function AfterSuccess() {
export function RemoveButton( export function RemoveButton(
props: { props: {
onConfirmOk?: ModalProps['onOk']; onConfirmOk?: ModalProps['onOk'];
disabled?: boolean;
} = {}, } = {},
) { ) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -335,6 +336,7 @@ export function RemoveButton(
breakRemoveOn={(s) => { breakRemoveOn={(s) => {
return s['x-component'] === 'Space' || s['x-component'].endsWith('ActionBar'); return s['x-component'] === 'Space' || s['x-component'].endsWith('ActionBar');
}} }}
disabled={props.disabled}
confirm={{ confirm={{
title: t('Delete action'), title: t('Delete action'),
onOk: props.onConfirmOk, onOk: props.onConfirmOk,

View File

@ -446,12 +446,13 @@ export const SchemaSettingsDivider = function Divider() {
}; };
export interface SchemaSettingsRemoveProps { export interface SchemaSettingsRemoveProps {
disabled?: boolean;
confirm?: ModalFuncProps; confirm?: ModalFuncProps;
removeParentsIfNoChildren?: boolean; removeParentsIfNoChildren?: boolean;
breakRemoveOn?: ISchema | ((s: ISchema) => boolean); breakRemoveOn?: ISchema | ((s: ISchema) => boolean);
} }
export const SchemaSettingsRemove: FC<SchemaSettingsRemoveProps> = (props) => { export const SchemaSettingsRemove: FC<SchemaSettingsRemoveProps> = (props) => {
const { confirm, removeParentsIfNoChildren, breakRemoveOn } = props; const { disabled, confirm, removeParentsIfNoChildren, breakRemoveOn } = props;
const { dn, template } = useSchemaSettings(); const { dn, template } = useSchemaSettings();
const { t } = useTranslation(); const { t } = useTranslation();
const field = useField<Field>(); const field = useField<Field>();
@ -464,6 +465,7 @@ export const SchemaSettingsRemove: FC<SchemaSettingsRemoveProps> = (props) => {
return ( return (
<SchemaSettingsItem <SchemaSettingsItem
disabled={disabled}
title="Delete" title="Delete"
eventKey="remove" eventKey="remove"
onClick={() => { onClick={() => {

View File

@ -1,5 +1,3 @@
import React from 'react'; import React from 'react';
import { Input } from 'antd'; import { Input } from 'antd';
import { import {
@ -119,6 +117,17 @@ const mySchemaSetting = new SchemaSettings({
}, },
}, },
}, },
{
name: 'demo10', // 唯一标识
type: 'item', // 文本类型
componentProps: {
title: 'Disabled title',
onClick() {
alert('Disabled');
},
disabled: true,
},
},
], ],
}); });