mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-02-23 17:49:49 +08:00
component: avatar
This commit is contained in:
parent
eab659f2fa
commit
351ad47255
49
packages/arco-lib/src/components/Avatar.tsx
Normal file
49
packages/arco-lib/src/components/Avatar.tsx
Normal 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,
|
||||
};
|
9
packages/arco-lib/src/generated/types/Avatar.ts
Normal file
9
packages/arco-lib/src/generated/types/Avatar.ts
Normal 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']))
|
||||
};
|
@ -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[] = [];
|
||||
|
@ -155,4 +155,7 @@ ${Object.keys(props)
|
||||
{
|
||||
component: "Divider",
|
||||
},
|
||||
{
|
||||
component: "Avatar",
|
||||
},
|
||||
].forEach(generate);
|
||||
|
Loading…
Reference in New Issue
Block a user