项目作者: thousandsofraccoons

项目描述 :
React breadcrumbs navigation based on Router5 with automatic trail build
高级语言: TypeScript
项目地址: git://github.com/thousandsofraccoons/router5-breadcrumbs-react.git
创建时间: 2020-02-10T10:44:58Z
项目社区:https://github.com/thousandsofraccoons/router5-breadcrumbs-react

开源协议:MIT License

下载


router5-breadcrumbs-react

Breadcrumbs component, based on router5 and react.js which renders crumbs automatically written in less than 200 lines of code.

React breadcrumbs component download

NPM PRs Welcome npm

Install

  1. yarn add router5-breadcrumbs-react

Features

:paperclip: Microdata and semantics
:earth_asia: Translation support
:hamster: Tiny component (< 200 lines, ~3kb gzipped)
:scissors: Customizable icons
:heart: Tailwind default styles

Breadcrumbs usage

  1. import Breadcrumbs from 'router5-breadcrumbs-react'
  2. export const Page = () => {
  3. return (
  4. <>
  5. <Breadcrumbs />
  6. </>
  7. )
  8. }

Including breadcrumbs tag into page will automatically render trail to current page based on it’s path. It could be something like: “user > user-profile”. You can utilize it by using localization files, just add following to your json with translations:

  1. {
  2. "user": "User",
  3. "user-profile": "Profile"
  4. }

Or you can specify crumbs right in your router5 route files:
Tree structure also will work in the same way - just add “crumb” key to each children. Each hierarchical link will be passed translated if translation function is specified. See description of t props

  1. export const routes = [
  2. { name: 'user', path: '/user', crumb: 'User' },
  3. { name: 'user.profile', path: '/profile', crumb: 'Profile' },
  4. ]

Props

got

{[index: number]: string | React.ReactElement}

  1. export const Example = () => {
  2. return <Breadcrumbs got={{ 0: product_title }} />
  3. }

Allows to pass dynamic value resulted from fetch request to server. Starts from 0, root crumb not being count in.

children

string | React.ReactElement
default = undefined

  1. export const Example = () => {
  2. return <Breadcrumbs>{product_title}</Breadcrumbs>
  3. }

Allows to rewrite current page’s link with dynamic value.

hide

Array<string>
default = undefined

In some cases you would prefer to hide certain crumbs. For example if you have duplicated nodes in your route tree. Or in case when one view being returned for two different routes (for example if you using router5-tabs-react with redirect to *.tabs parameter)

  1. export const Example = () => {
  2. return <Breadcrumbs hide={['route.names', 'to.hide']} />
  3. }

t

function
default = (text: string) => text

To enable translation just pass translation function to component:

  1. import { useTranslation } from 'react-i18next'
  2. export const Example = () => {
  3. const { t } = useTranslation()
  4. return <Breadcrumbs t={t} />
  5. }

homeRouteName

string
default = 'home'

Name of route node which will be assigned to Home crumb

homeRouteLabel

string
default = 'Home'

  1. {
  2. strokeWidth: string
  3. fill: string
  4. stroke: string
  5. className: any
  6. }

Defines which label for root of the trail to display.

iconProps

  1. {
  2. strokeWidth: string
  3. fill: string
  4. stroke: string
  5. className: any
  6. }

Parameters, which will be applied to default Home Icon and Arrow Icons

forward

  1. {
  2. from: string // router paths
  3. to: string
  4. }

Use it if you want to overwrite links assigned by default.

classes

  1. {
  2. activeLink: string // clickable links style
  3. currentPage: string // classes for current page's label
  4. wrapper: string // <ol></ol> tag around trails
  5. }

default =

  1. {
  2. activeLink = 'flex items-baseline text-blue-700 hover:underline mx-2',
  3. currentPage = 'text-gray-500 ml-2',
  4. wrapper = 'flex items-baseline text-xl my-10 whitespace-no-wrap',
  5. }

Classnames for HTML elements.

icons

  1. {
  2. CustomHomeIcon: React.ReactElement
  3. CustomArrowIcon: React.ReactElement
  4. }

default = <></>

Check also

router5-tabs-react

https://github.com/thousandsofraccoons/router5-tabs-react

Tiny tabbed navigation component, which renders selected tab in active breadcrumb

Acknowledgements

Dee Money
Dee Money

License

MIT © https://github.com/thousandsofraccoons