Giter VIP home page Giter VIP logo

ember-breadcrumb-trail's Introduction

ember-breadcrumb-trail

CI Code Style: Prettier

ember-breadcrumb-trail is a minimalistic but very flexible breadcrumb management solution. It provides only 2 helpers but they give you complete control over the HTML structure, the components you use to render that structure and the needed data to make it all work. Bring your own everything!

This addon is heavily inspired by ember-page-title and the already existing breadcrumb addons.

Compatibility

  • Ember.js v3.16 or above (lower versions might work, but aren't tested)
  • Ember CLI v3.16 or above
  • Node.js v12 or above
  • Works with Embroider (safe and optimized) and FastBoot

Installation

ember install ember-breadcrumb-trail

Usage

{{breadcrumb}} helper

This helper allows you to add breadcrumbs and is the equivalent of the page-title helper but for breadcrumbs.

Positional argument(s)

Positional arguments are used as the title for the breadcrumb. Multiple positional arguments will be combined into a single title.

{{breadcrumb "Home"}}
{{! "Home" }}

{{breadcrumb "Hottest JS framework ๐Ÿ”ฅ: " this.hottestFramework}}
{{! "Hottest JS framework ๐Ÿ”ฅ: Ember" }}

The title can be accessed with the title property of the breadcrumb object.

Named arguments

Any data that you need to render your breadcrumbs can be passed in as named arguments. This can be used to pass route information so that the breadcrumb can be linked to it.

The named arguments will be available under the data property of the breadcrumb object.

{{breadcrumbs}} helper

This helper simply returns the registered breadcrumbs and can be used wherever you want to display them. The breadcrumb data can easily be looped over with {{#each}} and combined with other helpers if extra data manipulation is needed.

Returns

Array of registered breadcrumbs (objects)

Examples

a11y

This simple example implements an a11y friendly breadcrumb structure using Ember's <LinkTo> component and the {{has-next}} helper from ember-composable-helpers to determine if a breadcrumb is the last breadcrumb in the list.

<nav aria-label="Breadcrumb">
  <ol>
    {{#each (breadcrumbs) as |breadcrumb|}}
      <li>
        <LinkTo
          @route={{breadcrumb.data.route}}
          aria-current={{if (not (has-next breadcrumb breadcrumbs)) "page"}}
        >
          {{breadcrumb.title}}
        </LinkTo>
      </li>
    {{/each}}
  </ol>
</nav>

{{! index.hbs }}
{{breadcrumb "Home" route="index"}}

{{! about.hbs }}
{{breadcrumb "About" route="about"}}

A similar example where ember-link is used instead of <LinkTo>.

<nav aria-label="Breadcrumb">
  <ol>
    {{#each (breadcrumbs) as |breadcrumb|}}
      <li>
        <a
          href={{breadcrumb.data.link.href}}
          aria-current={{if (not (has-next breadcrumb breadcrumbs)) "page"}}
          {{on "click" breadcrumb.data.link.transitionTo}}
        >
          {{breadcrumb.title}}
        </a>
      </li>
    {{/each}}
  </ol>
</nav>

{{! blog.hbs }}
{{breadcrumb "Blog" link=(link "blog")}}

{{! blog/post.hbs }}
{{breadcrumb this.post.title link=(link "blog.post" this.post.id)}}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

ember-breadcrumb-trail's People

Contributors

ember-tomster avatar windvis avatar

Watchers

 avatar

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.