补充Schema

This commit is contained in:
liaoxuezhi 2020-09-08 23:35:05 +08:00
parent 3798822759
commit 89272480d4
9 changed files with 266 additions and 20 deletions

View File

@ -5,16 +5,9 @@ import {autobind} from '../utils/helper';
import {Icon} from '../components/icons';
import {resolveVariable} from '../utils/tpl-builtin';
import {filter} from '../utils/tpl';
import {AudioSchema} from '../schemas/Audio';
export interface AudioProps extends RendererProps {
className?: string;
inline?: boolean;
src?: string;
autoPlay?: boolean;
loop?: boolean;
rates?: number[];
controls?: string[];
}
export interface AudioProps extends RendererProps, AudioSchema {}
export interface AudioState {
src?: string;

View File

@ -1,10 +1,11 @@
import React from 'react';
import {Renderer, RendererProps} from '../factory';
import {Action} from '../types';
import {ButtonToolbarSchema} from '../schemas/ButtonToolbar';
export interface ButtonToolbarProps extends RendererProps {
buttons: Array<Action>;
}
export interface ButtonToolbarProps
extends RendererProps,
ButtonToolbarSchema {}
export default class ButtonToolbar extends React.Component<
ButtonToolbarProps,

View File

@ -13,8 +13,9 @@ import PopOver from './PopOver';
import {TableCell} from './Table';
import Copyable from './Copyable';
import {Icon} from '../components/icons';
import {CardSchema} from '../schemas/Card';
export interface CardProps extends RendererProps {
export interface CardProps extends RendererProps, CardSchema {
onCheck: (item: IItem) => void;
itemIndex?: number;
multiple?: boolean;
@ -305,7 +306,7 @@ export class Card extends React.Component<CardProps> {
const descPlaceholder =
header.descriptionPlaceholder || header.descPlaceholder;
const highlight = !!evalExpression(highlightTpl, data as object);
const highlight = !!evalExpression(highlightTpl!, data as object);
const avatar = filter(avatarTpl, data, '| raw');
const avatarText = filter(avatarTextTpl, data);
const title = filter(titleTpl, data);
@ -367,7 +368,7 @@ export class Card extends React.Component<CardProps> {
header.subTitleClassName || subTitleClassName
)}
>
{render('sub-title', subTitle || subTitlePlaceholder, {
{render('sub-title', subTitle || subTitlePlaceholder!, {
className: cx(!subTitle ? 'Card-placeholder' : undefined)
})}
</div>
@ -377,10 +378,12 @@ export class Card extends React.Component<CardProps> {
<div
className={cx(
'Card-desc',
header.descClassName || descClassName
header.descriptionClassName ||
header.descClassName ||
descClassName
)}
>
{render('desc', desc || descPlaceholder, {
{render('desc', desc || descPlaceholder!, {
className: !desc ? 'text-muted' : undefined
})}
</div>

26
src/schemas/Alert.ts Normal file
View File

@ -0,0 +1,26 @@
import {BaseSchema, SchemaCollection} from './Schema';
/**
* Alert https://baidu.gitee.io/amis/docs/components/alert
*/
export interface AlertSchema extends BaseSchema {
/**
*
*/
type: 'alert';
/**
*
*/
body: SchemaCollection;
/**
*
*/
level?: 'info' | 'warning' | 'error' | 'danger';
/**
*
*/
showCloseButton?: boolean;
}

41
src/schemas/Audio.ts Normal file
View File

@ -0,0 +1,41 @@
import {BaseSchema, SchemaCollection, SchemaUrlPath} from './Schema';
/**
* Audio https://baidu.gitee.io/amis/docs/components/audio
*/
export interface AudioSchema extends BaseSchema {
/**
*
*/
type: 'audio';
/**
*
*/
inline: boolean;
/**
* ", $
*/
src?: SchemaUrlPath;
/**
*
*/
loop?: boolean;
/**
*
*/
autoPlay?: boolean;
/**
*
*/
rates?: Array<number>;
/**
*
*/
controls?: Array<'rates' | 'play' | 'time' | 'process' | 'volume'>;
}

View File

@ -0,0 +1,47 @@
import {BaseSchema, SchemaClassName, SchemaExpression} from './Schema';
import {ActionSchema} from './Action';
/**
* Button Group https://baidu.gitee.io/amis/docs/components/button-group
*/
export interface ButtonGroupSchema extends BaseSchema {
/**
*
*/
type: 'button-group';
/**
* Button className
*/
btnClassName?: SchemaClassName;
/**
*
*/
buttons?: Array<ActionSchema>;
/**
*
*/
disabled?: boolean;
/**
* JS
*/
disabledOn?: SchemaExpression;
/**
*
*/
visible?: boolean;
/**
* JS
*/
visibleOn?: SchemaExpression;
/**
*
*/
size?: 'xs' | 'sm' | 'md' | 'lg';
}

View File

@ -0,0 +1,14 @@
import {BaseSchema} from './Schema';
import {ActionSchema} from './Action';
/**
* Button Toolar https://baidu.gitee.io/amis/docs/components/button-toolbar
*/
export interface ButtonToolbarSchema extends BaseSchema {
/**
*
*/
type: 'button-toolbar';
buttons: Array<ActionSchema>;
}

103
src/schemas/Card.ts Normal file
View File

@ -0,0 +1,103 @@
import {
BaseSchema,
SchemaClassName,
SchemaTpl,
SchemaUrlPath,
SchemaExpression,
SchemaCollection
} from './Schema';
import {ActionSchema} from './Action';
/**
* Card https://baidu.gitee.io/amis/docs/components/card
*/
export interface CardSchema extends BaseSchema {
/**
* card
*/
type: 'card';
/**
*
*/
header?: {
className?: SchemaClassName;
/**
*
*/
title?: SchemaTpl;
titleClassName?: string;
/**
*
*/
subTitle?: SchemaTpl;
subTitleClassName?: SchemaClassName;
subTitlePlaceholder?: string;
/**
*
*/
description?: SchemaTpl;
/**
*
*/
descriptionPlaceholder?: string;
/**
*
*/
descriptionClassName?: string;
/**
* @deprecated description
*/
desc?: SchemaTpl;
/**
* @deprecated descriptionPlaceholder
*/
descPlaceholder?: SchemaTpl;
/**
* @deprecated descriptionClassName
*/
descClassName?: SchemaClassName;
/**
*
*/
avatar?: SchemaUrlPath;
avatarText?: SchemaTpl;
avatarTextClassName?: SchemaClassName;
/**
*
*/
avatarClassName?: SchemaClassName;
/**
*
*/
imageClassName?: SchemaClassName;
/**
*
*/
highlight?: SchemaExpression;
highlightClassName?: SchemaClassName;
};
/**
*
*/
body?: SchemaCollection;
/**
*
*/
actions?: Array<ActionSchema>;
}

View File

@ -3,6 +3,10 @@ import {FormSchema} from './Form';
import {TplSchema} from './Tpl';
import {RemarkSchema} from './Remark';
import {ActionSchema} from './Action';
import {AlertSchema} from './Alert';
import {AudioSchema} from './Audio';
import {ButtonGroupSchema} from './ButtonGroup';
import {ButtonToolbarSchema} from './ButtonToolbar';
// 每加个类型,这补充一下。
export type SchemaType =
@ -13,14 +17,24 @@ export type SchemaType =
| 'remark'
| 'button'
| 'submit'
| 'reset';
| 'reset'
| 'alert'
| 'audio'
| 'button-group'
| 'button-toolbar'
| 'card';
export type SchemaObject =
| PageSchema
| FormSchema
| TplSchema
| RemarkSchema
| ActionSchema;
| ActionSchema
| AlertSchema
| AudioSchema
| ButtonGroupSchema
| ButtonToolbarSchema
| CardSchema;
export type SchemaCollection = SchemaObject | Array<SchemaObject> | SchemaTpl;
@ -61,7 +75,7 @@ export interface SchemaApiObject {
/**
* API
*/
url: string;
url: SchemaUrlPath;
/**
* . key `&` `$$` , data . $$ key . $ , key .
@ -163,6 +177,10 @@ export type SchemaSchema = string;
*/
export type SchemaIcon = string;
export type TokenizeableString = string;
export type SchemaUrlPath = TokenizeableString;
export type SchemaTooltip =
| string
| {