mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-28 20:25:29 +08:00
* feat(scaleable): add scaleable props to each component * chore(scaleable): update the exported type * feat: apply scaleable to components chore: remove with-default test: improve testcase for scaleable chore: resolve test warning ci: upgrade nodejs to latest lts docs: fix type error in document site * docs: update documents to be compatible with scaleable chore: fix build errors * chore: remove all size-related attributes docs: improve guide document * docs: add scaleable documentation test: update snapshots chore: remove unused * feat: add scaleable to grid components * docs: improve docs * test: update snapshots * fix(grid): fix basic component props
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import Link from '../link'
|
|
import { Props as LinkBasicProps } from '../link/link'
|
|
import React, { useMemo } from 'react'
|
|
import { pickChild } from '../utils/collections'
|
|
import BreadcrumbsSeparator from './breadcrumbs-separator'
|
|
|
|
interface Props {
|
|
href?: string
|
|
nextLink?: boolean
|
|
onClick?: (event: React.MouseEvent) => void
|
|
className?: string
|
|
}
|
|
|
|
const defaultProps = {
|
|
nextLink: false,
|
|
className: '',
|
|
}
|
|
|
|
type NativeAttrs = Omit<React.AnchorHTMLAttributes<any>, keyof Props>
|
|
type NativeLinkAttrs = Omit<NativeAttrs, keyof LinkBasicProps>
|
|
export type BreadcrumbsItemProps = Props & NativeLinkAttrs
|
|
|
|
const BreadcrumbsItem = React.forwardRef<
|
|
HTMLAnchorElement,
|
|
React.PropsWithChildren<BreadcrumbsItemProps>
|
|
>(
|
|
(
|
|
{
|
|
href,
|
|
nextLink,
|
|
onClick,
|
|
children,
|
|
className,
|
|
...props
|
|
}: BreadcrumbsItemProps & typeof defaultProps,
|
|
ref: React.Ref<HTMLAnchorElement>,
|
|
) => {
|
|
const isLink = useMemo(() => href !== undefined || nextLink, [href, nextLink])
|
|
const [withoutSepChildren] = pickChild(children, BreadcrumbsSeparator)
|
|
const clickHandler = (event: React.MouseEvent) => {
|
|
onClick && onClick(event)
|
|
}
|
|
|
|
if (!isLink) {
|
|
return (
|
|
<span className={`breadcrums-item ${className}`} onClick={clickHandler}>
|
|
{withoutSepChildren}
|
|
</span>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Link
|
|
className={`breadcrums-item ${className}`}
|
|
href={href}
|
|
onClick={clickHandler}
|
|
ref={ref}
|
|
{...props}>
|
|
{withoutSepChildren}
|
|
</Link>
|
|
)
|
|
},
|
|
)
|
|
|
|
BreadcrumbsItem.defaultProps = defaultProps
|
|
BreadcrumbsItem.displayName = 'GeistBreadcrumbsItem'
|
|
export default BreadcrumbsItem
|