component: avatar

This commit is contained in:
Yanzhen Yu 2021-12-27 17:06:39 +08:00 committed by Bowen Tan
parent eab659f2fa
commit 351ad47255
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import { Avatar as BaseAvatar } from "@arco-design/web-react";
import { ComponentImplementation, Slot } from "@sunmao-ui/runtime";
import { createComponent } from "@sunmao-ui/core";
import { css, cx } from "@emotion/css";
import { Type, Static } from "@sinclair/typebox";
import { FALLBACK_METADATA, getComponentProps } from "../sunmao-helper";
import { AvatarPropsSchema as BaseAvatarPropsSchema } from "../generated/types/Avatar";
const AvatarPropsSchema = Type.Object({
...BaseAvatarPropsSchema,
className: Type.Optional(Type.String()),
});
const AvatarStateSchema = Type.Object({});
const AvatarImpl: ComponentImplementation<Static<typeof AvatarPropsSchema>> = (
props
) => {
const { slotsMap, customStyle } = props;
const { className, ...cProps } = getComponentProps(props);
return (
<BaseAvatar
className={cx(className, css(customStyle?.content))}
{...cProps}
>
<Slot slotsMap={slotsMap} slot="content" />
</BaseAvatar>
);
};
export const Avatar = {
...createComponent({
version: "arco/v1",
metadata: {
...FALLBACK_METADATA,
name: "avatar",
displayName: "Avatar",
},
spec: {
properties: AvatarPropsSchema,
state: AvatarStateSchema,
methods: [],
slots: ["content"],
styleSlots: ["content"],
events: [],
},
}),
impl: AvatarImpl,
};

View File

@ -0,0 +1,9 @@
import { Type } from "@sinclair/typebox";
import { IntoStringUnion, StringUnion } from '../../sunmao-helper';
export const AvatarPropsSchema = {
'shape': Type.Optional(StringUnion(['circle', 'square'])),
'autoFixFontSize': Type.Optional(Type.Boolean()),
'triggerType': Type.Optional(StringUnion(['button', 'mask']))
};

View File

@ -9,6 +9,7 @@ import { Dropdown } from "./components/Dropdown";
import { Space } from "./components/Space";
import { Input } from "./components/Input";
import { Divider } from "./components/Divider";
import { Avatar } from "./components/Avatar";
type Component = Parameters<Registry["registerComponent"]>[0];
type Trait = Parameters<Registry["registerTrait"]>[0];
@ -28,6 +29,7 @@ export const components: Component[] = [
Space,
Input,
Divider,
Avatar,
];
export const traits: Trait[] = [];
export const modules: Module[] = [];

View File

@ -155,4 +155,7 @@ ${Object.keys(props)
{
component: "Divider",
},
{
component: "Avatar",
},
].forEach(generate);