Giter Club home page Giter Club logo

router5-breadcrumbs-react's Introduction

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

yarn add router5-breadcrumbs-react

Features

๐Ÿ“Ž Microdata and semantics
๐ŸŒ Translation support
๐Ÿน Tiny component (< 200 lines, ~3kb gzipped)
โœ‚๏ธ Customizable icons
โค๏ธ Tailwind default styles

Breadcrumbs usage

import Breadcrumbs from 'router5-breadcrumbs-react'

export const Page = () => {
  return (
    <>
      <Breadcrumbs />
    </>
  )
}

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:

{
  "user": "User",
  "user-profile": "Profile"
}

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

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

Props

got

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

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

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

export const Example = () => {
  return <Breadcrumbs>{product_title}</Breadcrumbs>
}

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)

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

t

function
default = (text: string) => text

To enable translation just pass translation function to component:

import { useTranslation } from 'react-i18next'

export const Example = () => {
  const { t } = useTranslation()
  return <Breadcrumbs t={t} />
}

homeRouteName

string default = 'home'

Name of route node which will be assigned to Home crumb

homeRouteLabel

string default = 'Home'

{
  strokeWidth: string
  fill: string
  stroke: string
  className: any
}

Defines which label for root of the trail to display.

iconProps

{
  strokeWidth: string
  fill: string
  stroke: string
  className: any
}

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

forward

{
  from: string // router paths
  to: string
}

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

classes

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

default =

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

Classnames for HTML elements.

icons

{
  CustomHomeIcon: React.ReactElement
  CustomArrowIcon: React.ReactElement
}

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

router5-breadcrumbs-react's People

Contributors

multipliedtwice avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

router5-breadcrumbs-react's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.