diff --git a/components/index.ts b/components/index.ts index fc60bd3..ff434b4 100644 --- a/components/index.ts +++ b/components/index.ts @@ -49,3 +49,4 @@ export { default as Tooltip } from './tooltip' export { default as Popover } from './popover' export { default as Slider } from './slider' export { default as Divider } from './divider' +export { default as User } from './user' diff --git a/components/user/index.ts b/components/user/index.ts new file mode 100644 index 0000000..ec638af --- /dev/null +++ b/components/user/index.ts @@ -0,0 +1,6 @@ +import User from './user' +import UserLink from './user-link' + +User.Link = UserLink + +export default User diff --git a/components/user/user-link.tsx b/components/user/user-link.tsx new file mode 100644 index 0000000..639f769 --- /dev/null +++ b/components/user/user-link.tsx @@ -0,0 +1,37 @@ +import React from 'react' +import Link from '../link' +import withDefaults from '../utils/with-defaults' + +interface Props { + href?: string + className?: string +} + +const defaultProps = { + className: '', +} + +type NativeAttrs = Omit, keyof Props> +export type UserLinkProps = Props & typeof defaultProps & NativeAttrs + +const UserLink = React.memo( + React.forwardRef>(({ + href, className, children, ...props + }, ref: React.Ref) => { + + return ( +
+ + {children} + + +
+ ) + }) +) + +export default withDefaults(UserLink, defaultProps) diff --git a/components/user/user.tsx b/components/user/user.tsx new file mode 100644 index 0000000..b145331 --- /dev/null +++ b/components/user/user.tsx @@ -0,0 +1,86 @@ +import React, { ReactNode } from 'react' +import Avatar from '../avatar' +import useTheme from '../styles/use-theme' +import UserLink from './user-link' + +interface Props { + name: ReactNode | string + src?: string + text?: string + className?: string +} + +const defaultProps = { + className: '', +} + +type NativeAttrs = Omit, keyof Props> +export type UserProps = Props & typeof defaultProps & NativeAttrs + +const User: React.FC> = ({ + src, text, name, children, className, ...props +}) => { + const theme = useTheme() + + return ( +
+ +
+ {name} + {children} +
+ + +
+ ) +} + +type UserComponent

= React.FC

& { + Link: typeof UserLink +} + +type ComponentProps = Partial & Omit & NativeAttrs + +(User as UserComponent).defaultProps = defaultProps + +export default User as UserComponent