Merge pull request #24 from webzard-io/improve

feat(table): expand properties spec
This commit is contained in:
MrWindlike 2022-02-14 11:36:52 +08:00 committed by Bowen Tan
parent 69ba766ab6
commit 19f09a7067
3 changed files with 67 additions and 17 deletions

View File

@ -281,7 +281,6 @@ export const exampleProperties: Static<typeof TablePropsSchema> = {
})),
pagination: {
pageSize: 6,
current: 0,
},
tableLayoutFixed: false,
borderCell: false,

View File

@ -4,10 +4,12 @@ import { StringUnion } from '../../sunmao-helper';
import { EventHandlerSchema, ModuleSchema } from '@sunmao-ui/runtime'
export const ColumnSchema = Type.Object({
title: Type.String(),
dataIndex: Type.String(),
title: Type.String({ title: 'title' }),
dataIndex: Type.String({
title: 'dataIndex',
description:'The key corresponding to the column data in the data item is used to display the value'
}),
sorter: Type.Boolean(),
filter: Type.Boolean(),
sortDirections: Type.Optional(Type.Array(StringUnion(["descend", "ascend"]))),
defaultSortOrder: Type.Optional(StringUnion(["descend", "ascend"])),
type: Type.Optional(Type.KeyOf(
@ -23,21 +25,64 @@ export const ColumnSchema = Type.Object({
text: Type.String(),
handlers: Type.Array(EventHandlerSchema),
})),
module: Type.Optional(ModuleSchema)
module: Type.Optional(ModuleSchema),
filter: Type.Boolean({
title: 'filter'
}),
})
export const TablePropsSchema = Type.Object({
data: Type.Array(Type.Any()),
columns: Type.Array(ColumnSchema),
tableLayoutFixed: Type.Boolean(),
borderCell: Type.Boolean(),
stripe: Type.Boolean(),
data: Type.Array(Type.Any(), {
title: 'data',
widget: 'CodeEditor',
description: 'display data',
category: 'Data',
weight: 0
}),
columns: Type.Array(ColumnSchema, {
title: 'columns',
widget: 'ColumnsForm',
description: '',
category: 'Columns',
weight: 0
}),
tableLayoutFixed: Type.Boolean({
title: 'tableLayoutFixed',
description: "The table's table-layout property is set to fixed. After set to fixed, the width of the table will not be stretched by the content beyond 100%",
category: 'Layout',
weight: 1
}),
borderCell: Type.Boolean({
title: 'borderCell',
description: 'Whether to display the table cell border',
category: 'Style',
weight: 1
}),
stripe: Type.Boolean({
title: 'stripe',
widget: 'boolean',
description: 'Whether to show stripe style',
category: 'Style',
weight: 2
}),
pagination: Type.Object({
pageSize: Type.Number(),
current: Type.Number(),
}),
size: StringUnion(['default', 'middle', 'small', 'mini']),
pagePosition: StringUnion(['br', 'bl', 'tr', 'tl', 'topCenter', 'bottomCenter']),
rowSelectionType: StringUnion(["checkbox", "radio", "default"]),
size: StringUnion(['default', 'middle', 'small', 'mini'], {
title: 'size',
description: 'table size',
category: 'Style',
weight: 0
}),
pagePosition: StringUnion(['br', 'bl', 'tr', 'tl', 'topCenter', 'bottomCenter'], {
title: 'pagePosition',
description: '',
category: 'Style',
weight: 10
}),
rowSelectionType: StringUnion(["checkbox", "radio", "default"], {
title: 'rowSelectionType',
category: 'Basic',
weight: 3
}),
});

View File

@ -8,14 +8,20 @@ export type IntoStringUnion<T> = {
[K in keyof T]: T[K] extends string ? TLiteral<T[K]> : never;
};
export function StringUnion<T extends string[]>(values: [...T]) {
export function StringUnion<T extends string[]>(values: [...T], options?: any) {
return Type.KeyOf(
Type.Object(
values.reduce((prev, cur) => {
prev[cur] = Type.Boolean();
return prev;
}, {} as Record<T[number], any>)
)
), {
title: options?.title,
widget: 'mulitiSelectInput',
description: options?.descrition,
category: options?.category,
weight: options?.weight
}
);
}