mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-02 09:08:52 +08:00
37 lines
931 B
TypeScript
37 lines
931 B
TypeScript
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<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} color target="_blank" rel="noopener">
|
|
{children}
|
|
</Link>
|
|
<style jsx>{`
|
|
div :global(a:hover) {
|
|
opacity: 0.7;
|
|
}
|
|
`}</style>
|
|
</div>
|
|
)
|
|
},
|
|
)
|
|
|
|
const MemoUserLink = React.memo(UserLink)
|
|
|
|
export default withDefaults(MemoUserLink, defaultProps)
|