修改 Action 的配置

This commit is contained in:
2betop 2020-09-08 19:55:33 +08:00
parent 784ad4f6c8
commit 3798822759
4 changed files with 213 additions and 41 deletions

View File

@ -235,7 +235,7 @@ export default class PlayGround extends React.Component {
}
const json = {
$schema: `${host}/schemas/page.json#`,
$schema: `${host}/schema.json#`,
...JSON.parse(schemaContent)
};

View File

@ -39,49 +39,53 @@ const ActionProps = [
'requireSelected'
];
import {filterContents} from './Remark';
import {ClassNamesFn, themeable} from '../theme';
import {ClassNamesFn, themeable, ThemeProps} from '../theme';
import {autobind} from '../utils/helper';
import {
ButtonSchema,
ActionSchema,
AjaxActionSchema,
UrlActionSchema,
LinkActionSchema,
DialogActionSchema,
CopyActionSchema,
OtherActionSchema,
ReloadActionSchema,
DrawerActionSchema
} from '../schemas/Action';
export interface ActionProps {
className?: string;
type: 'submit' | 'reset' | 'button';
actionType?: string;
label?: string;
icon?: string;
iconClassName?: string;
size?: 'xs' | 'sm' | 'md' | 'lg';
level?: 'info' | 'success' | 'warning' | 'danger' | 'link';
onAction?: (e: React.MouseEvent<any> | void | null, action: object) => void;
export interface ActionProps
extends ButtonSchema,
ThemeProps,
AjaxActionSchema,
UrlActionSchema,
LinkActionSchema,
DialogActionSchema,
DrawerActionSchema,
CopyActionSchema,
ReloadActionSchema,
OtherActionSchema {
actionType: any;
onAction?: (
e: React.MouseEvent<any> | void | null,
action: ActionSchema
) => void;
isCurrentUrl?: (link: string) => boolean;
onClick?: (e: React.MouseEvent<any>, props: any) => void;
primary?: boolean;
activeClassName: string;
componentClass: React.ReactType;
tooltipPlacement: 'bottom' | 'top' | 'right' | 'left' | undefined;
disabled?: boolean;
block?: boolean;
tooltipContainer?: any;
data?: any;
link?: string;
disabledTip?: string;
tooltip?: any;
isMenuItem?: boolean;
active?: boolean;
activeLevel?: string;
tooltipContainer?: any;
classPrefix: string;
classnames: ClassNamesFn;
}
const allowedType = ['button', 'submit', 'reset'];
export class Action extends React.Component<ActionProps> {
static defaultProps: Pick<
ActionProps,
'type' | 'componentClass' | 'tooltipPlacement' | 'activeClassName'
> = {
type: 'button',
componentClass: 'button',
tooltipPlacement: 'bottom',
static defaultProps = {
type: 'button' as 'button',
componentClass: 'button' as React.ReactType,
tooltipPlacement: 'bottom' as 'bottom',
activeClassName: 'is-active'
};
@ -98,7 +102,7 @@ export class Action extends React.Component<ActionProps> {
}
e.preventDefault();
const action = pick(this.props, ActionProps);
const action = pick(this.props, ActionProps) as ActionSchema;
onAction(e, action);
}
@ -217,7 +221,8 @@ export class ActionRenderer extends React.Component<
return (
<Action
{...rest}
{...(rest as any)}
type="button"
disabled={disabled || btnDisabled}
onAction={this.handleAction}
isCurrentUrl={this.isCurrentAction}

View File

@ -3,88 +3,226 @@ import {
SchemaExpression,
SchemaApi,
SchemaReload,
SchemaTpl
SchemaTpl,
SchemaIcon,
BaseSchema,
SchemaTooltip
} from './Schema';
export type ButtonSchema = {
export interface ButtonSchema extends BaseSchema {
/**
*
*/
block?: boolean;
className?: SchemaClassName;
/**
*
*/
disabled?: boolean;
/**
*
*/
disabledOn?: SchemaExpression;
/**
*
*/
disabledTip?: string;
/**
*
* @deprecated visible
*/
hidden?: boolean;
/**
*
* @deprecated visibleOn
*/
hiddenOn?: SchemaExpression;
icon?: string;
/**
* iconfont
*/
icon?: SchemaIcon;
/**
* icon css
*/
iconClassName?: SchemaClassName;
/**
*
*/
label?: string;
/**
*
*/
level?: 'info' | 'success' | 'warning' | 'danger' | 'link' | 'primary';
/**
* @deprecated level
*/
primary?: boolean;
/**
*
*/
size?: 'xs' | 'sm' | 'md' | 'lg';
tooltip?: string;
tooltip?: SchemaTooltip;
tooltipPlacement?: 'top' | 'right' | 'bottom' | 'left';
/**
* buttonsubmit或者reset三种类型
*/
type: 'button' | 'submit' | 'reset';
/**
*
*/
visible?: boolean;
/**
*
*/
visibleOn?: SchemaExpression;
/**
*
*/
confirmText?: string;
};
/**
* form中
*/
required?: Array<string>;
/**
*
*/
activeLevel?: string;
/**
*
*/
activeClassName: string;
/**
*
*/
close?: boolean | string;
/**
* false
*/
requireSelected?: boolean;
}
export interface AjaxActionSchema extends ButtonSchema {
/**
* ajax
*/
actionType: 'ajax';
/**
* ajax
*/
api: SchemaApi;
// todo
feedback?: any;
reload?: SchemaReload;
redirect?: string;
}
export interface UrlActionSchema extends ButtonSchema {
/**
*
*/
actionType: 'url';
/**
*
*/
blank?: boolean;
/**
*
*/
url: string;
}
export interface DialogActionSchema extends ButtonSchema {
/**
*
*/
actionType: 'dialog';
// todo
dialog: any;
/**
*
*/
nextCondition?: SchemaExpression;
reload?: SchemaReload;
redirect?: string;
}
export interface DrawerActionSchema extends ButtonSchema {
/**
*
*/
actionType: 'drawer';
// todo
drawer: any;
/**
*
*/
nextCondition?: SchemaExpression;
reload?: SchemaReload;
redirect?: string;
}
export interface CopyActionSchema extends ButtonSchema {
/**
*
*/
actionType: 'copy';
/**
*
*/
copy: SchemaTpl;
}
export interface LinkActionSchema extends ButtonSchema {
/**
* url
*/
actionType: 'link';
/**
*
*/
link: string;
}
export interface ReloadActionSchema extends ButtonSchema {
/**
*
*/
actionType: 'reload';
/**
*
*/
target: SchemaReload;
}

View File

@ -2,10 +2,25 @@ import {PageSchema} from './Page';
import {FormSchema} from './Form';
import {TplSchema} from './Tpl';
import {RemarkSchema} from './Remark';
import {ActionSchema} from './Action';
// 每加个类型,这补充一下。
export type SchemaType = 'page' | 'form' | 'tpl' | 'html' | 'remark';
export type SchemaObject = PageSchema | FormSchema | TplSchema | RemarkSchema;
export type SchemaType =
| 'page'
| 'form'
| 'tpl'
| 'html'
| 'remark'
| 'button'
| 'submit'
| 'reset';
export type SchemaObject =
| PageSchema
| FormSchema
| TplSchema
| RemarkSchema
| ActionSchema;
export type SchemaCollection = SchemaObject | Array<SchemaObject> | SchemaTpl;
@ -148,6 +163,20 @@ export type SchemaSchema = string;
*/
export type SchemaIcon = string;
export type SchemaTooltip =
| string
| {
/**
*
*/
title?: string;
/**
*
*/
content: string;
};
export interface BaseSchema {
$schema?: SchemaSchema;
type: SchemaType;