Badge element

The vf-badge component is used to denote if a page, section, or link has a production state of alpha, beta or other information.

github location npm version

Usage

The vf-badge accepts a single text item of content.

content type variable description
text text

Links

The vf-badge component can also be a link using <a class="vf-badge" href="">badge title</a>.

Nunjucks and yml options

Nunjucks and YML variables available

variable options default
text
badge_href null
theme 'primary'
style 'outline'
override_class
id

Variants

alpha
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "element",
  "text": "alpha",
  "theme": "primary"
}
 %}
{% include "../path_to/vf-badge/vf-badge.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-badge', {
  "component-type": "element",
  "text": "alpha",
  "theme": "primary"
} %}
                
HTML
 <span class="vf-badge vf-badge--primary">alpha</span>
              

Examples

alpha
alpha
Installation info

This repository is distributed with npm. After installing npm and yarn, you can install vf-profile with this command.

$ yarn add --dev @visual-framework/vf-badge

Sass/CSS

The style files included are written in Sass. If you're using a VF-core project, you can import it like this:

@import "@visual-framework/vf-badge/index.scss";

Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter

Changelog

Changelog

2.0.1

  • Correct "secondry" typo.

2.0.0

  • makes the badges match the naming convention of the vf-button.
  • makes the badges match the styling of the vf-button.
  • removes any old deprecated variants and tidies up the code.

Migration Instructions

  • If you were using the "Outline Primary" variant you should use the "Secondary" variant now.
  • This replaces the classes of vf-badge--primary and vf-badge--outline with vf-badge--secondary.
  • IF you were using the "Default" variant you should use the "Tertiary" variant now.
  • This adds the class vf-badge--tertiary.

1.3.0

  • deprecates secondary and tertiary variants
  • makes the default the grey (tertiary) colour

1.2.2

  • changes any set- style functions to cleaner version

1.2.1

  • README cleanup

1.2.0

  • makes theme variant naming and decisions consistent

1.1.0

  • adds if statement to allow for context data to pass through

1.0.0 (2019-12-17)

  • Initial stable release

Assets



File system location: components/vf-badge

Find an issue on this page? Propose a change or discuss it.