mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-28 20:25:29 +08:00
style(prettier): format code style
This commit is contained in:
@@ -7,27 +7,27 @@ describe(' User', () => {
|
||||
const wrapper = mount(<User name="witt" />)
|
||||
expect(() => wrapper.unmount()).not.toThrow()
|
||||
})
|
||||
|
||||
|
||||
it('should support image and text', () => {
|
||||
const wrapper = render(
|
||||
<div>
|
||||
<User name="witt" text="witt" />
|
||||
<User name="witt" src="https://unix.bio/assets/avatar.png" />
|
||||
</div>
|
||||
</div>,
|
||||
)
|
||||
expect(wrapper).toMatchSnapshot()
|
||||
})
|
||||
|
||||
|
||||
it('should render description correctly', () => {
|
||||
const wrapper = mount(<User name="witt">description</User>)
|
||||
expect(wrapper.text().toLowerCase()).toContain('description')
|
||||
})
|
||||
|
||||
|
||||
it('should render link on user.link', () => {
|
||||
const wrapper = mount(
|
||||
<User name="witt">
|
||||
<User.Link href="https://twitter.com/echo_witt">twitter</User.Link>
|
||||
</User>
|
||||
</User>,
|
||||
)
|
||||
const link = wrapper.find('a')
|
||||
expect(link.length).not.toBe(0)
|
||||
|
||||
@@ -14,22 +14,22 @@ const defaultProps = {
|
||||
type NativeAttrs = Omit<React.AnchorHTMLAttributes<any>, keyof Props>
|
||||
export type UserLinkProps = Props & typeof defaultProps & NativeAttrs
|
||||
|
||||
const UserLink = React.forwardRef<HTMLAnchorElement, React.PropsWithChildren<UserLinkProps>>(({
|
||||
href, className, children, ...props
|
||||
}, ref: React.Ref<HTMLAnchorElement>) => {
|
||||
return (
|
||||
<div className={className} {...props}>
|
||||
<Link ref={ref} href={href} pure color target="_blank" rel="noopener">
|
||||
{children}
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
div :global(a:hover) {
|
||||
opacity: .7;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
const UserLink = React.forwardRef<HTMLAnchorElement, React.PropsWithChildren<UserLinkProps>>(
|
||||
({ href, className, children, ...props }, ref: React.Ref<HTMLAnchorElement>) => {
|
||||
return (
|
||||
<div className={className} {...props}>
|
||||
<Link ref={ref} href={href} pure color target="_blank" rel="noopener">
|
||||
{children}
|
||||
</Link>
|
||||
<style jsx>{`
|
||||
div :global(a:hover) {
|
||||
opacity: 0.7;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
const MemoUserLink = React.memo(UserLink)
|
||||
|
||||
|
||||
@@ -18,10 +18,15 @@ type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
|
||||
export type UserProps = Props & typeof defaultProps & NativeAttrs
|
||||
|
||||
const User: React.FC<React.PropsWithChildren<UserProps>> = ({
|
||||
src, text, name, children, className, ...props
|
||||
src,
|
||||
text,
|
||||
name,
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const theme = useTheme()
|
||||
|
||||
|
||||
return (
|
||||
<div className={`user ${className}`} {...props}>
|
||||
<Avatar src={src} text={text} size={32} />
|
||||
@@ -39,16 +44,16 @@ const User: React.FC<React.PropsWithChildren<UserProps>> = ({
|
||||
width: max-content;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
|
||||
.names {
|
||||
margin-left: ${theme.layout.gapHalf};
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
.name {
|
||||
font-size: .89rem;
|
||||
font-size: 0.89rem;
|
||||
color: ${theme.palette.accents_8};
|
||||
line-height: 1.1rem;
|
||||
text-transform: capitalize;
|
||||
@@ -57,16 +62,16 @@ const User: React.FC<React.PropsWithChildren<UserProps>> = ({
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
.social {
|
||||
font-size: .75rem;
|
||||
font-size: 0.75rem;
|
||||
color: ${theme.palette.accents_6};
|
||||
}
|
||||
|
||||
|
||||
.social :global(*:first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
|
||||
.social :global(*:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
@@ -78,7 +83,9 @@ const User: React.FC<React.PropsWithChildren<UserProps>> = ({
|
||||
type MemoUserComponent<P = {}> = React.NamedExoticComponent<P> & {
|
||||
Link: typeof UserLink
|
||||
}
|
||||
type ComponentProps = Partial<typeof defaultProps> & Omit<Props, keyof typeof defaultProps> & NativeAttrs
|
||||
type ComponentProps = Partial<typeof defaultProps> &
|
||||
Omit<Props, keyof typeof defaultProps> &
|
||||
NativeAttrs
|
||||
|
||||
User.defaultProps = defaultProps
|
||||
|
||||
|
||||
Reference in New Issue
Block a user