change style trait params to array

This commit is contained in:
Bowen Tan 2021-12-16 17:14:06 +08:00
parent 736ef98bd0
commit 9ae0623a7a
2 changed files with 24 additions and 18 deletions

View File

@ -82,9 +82,13 @@ export const ApplicationFixture: Record<string, Application> = {
{
type: 'core/v1/style',
properties: {
styleSlot: 'content',
style: "{{!usersTable.selectedItem ? 'display: none' : ''}}",
},
styles: [
{
styleSlot: 'content',
style: "{{!usersTable.selectedItem ? 'display: none' : ''}}",
},
]
}
},
],
},
@ -110,7 +114,7 @@ export const ApplicationFixture: Record<string, Application> = {
},
{
type: 'core/v1/style',
properties: { styleSlot: 'content', style: 'padding: 0; border: none' },
properties: { styles: [{styleSlot: 'content', style: 'padding: 0; border: none' }]},
},
],
},
@ -174,7 +178,7 @@ export const ApplicationFixture: Record<string, Application> = {
},
{
type: 'core/v1/style',
properties: { styleSlot: 'content', style: 'padding: 0; border: none' },
properties: { styles: [{styleSlot: 'content', style: 'padding: 0; border: none' }]},
},
],
},
@ -241,7 +245,6 @@ export const ApplicationFixture: Record<string, Application> = {
type: 'core/v1/slot',
properties: { container: { id: 'hstack4', slot: 'content' } },
},
{ type: 'core/v1/style', properties: { string: { kind: {}, type: {} } } },
],
},
{
@ -255,7 +258,7 @@ export const ApplicationFixture: Record<string, Application> = {
},
{
type: 'core/v1/style',
properties: { styleSlot: 'content', style: 'padding: 0; border: none' },
properties: { styles: [{styleSlot: 'content', style: 'padding: 0; border: none' }]},
},
],
},
@ -281,7 +284,7 @@ export const ApplicationFixture: Record<string, Application> = {
},
{
type: 'core/v1/style',
properties: { styleSlot: 'content', style: 'padding: 0; border: none' },
properties: { styles: [{styleSlot: 'content', style: 'padding: 0; border: none' }]},
},
],
},
@ -329,7 +332,7 @@ export const ApplicationFixture: Record<string, Application> = {
},
{
type: 'core/v1/style',
properties: { styleSlot: 'content', style: 'padding: 0; border: none' },
properties: { styles: [{styleSlot: 'content', style: 'padding: 0; border: none' }]},
},
],
},

View File

@ -2,22 +2,25 @@ import { createTrait } from '@sunmao-ui/core';
import { Static, Type } from '@sinclair/typebox';
import { TraitImplementation } from '../../types/RuntimeSchema';
const StyleTrait: TraitImplementation<Static<typeof PropsSchema>> = ({
styleSlot,
style,
}) => {
const StyleTrait: TraitImplementation<Static<typeof PropsSchema>> = ({ styles }) => {
const customStyle: Record<string, string> = {};
styles.forEach(style => {
customStyle[style.styleSlot] = style.style;
});
return {
props: {
customStyle: {
[styleSlot]: style,
},
customStyle,
},
};
};
const PropsSchema = Type.Object({
styleSlot: Type.String(),
style: Type.String(),
styles: Type.Array(
Type.Object({
styleSlot: Type.String(),
style: Type.String(),
})
),
});
export default {