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

Angular

As of version 3.0.0-alpha.0 vf-badge has experimental Angular support. This package was generated with Angular version 15.2.0 and has been tested on application with Angular version 15.2.0.

  1. install yarn add @visual-framework/vf-badge
  2. import in your app.module
    import { VfBadgeAngularModule } from '@visual-framework/vf-badge/vf-badge.angular';
    
    @NgModule({
      imports: [VfBadgeAngularModule, YourOtherModules],
      ...
    })
    
  3. can be used as
    <vf-badge [text]="'alpha'" [theme]="'primary'" [id]="'Badge1'"></vf-badge>
    
  4. add to your styles.scss
    @import '../node_modules/@visual-framework/vf-sass-config/index.scss';
    @import "../node_modules/@visual-framework/vf-badge/vf-badge.scss";
    
    you should also install vf-sass-starter for the styles

Usage:

<vf-badge [text]="'alpha'" [theme]="'primary'" [id]="'Badge1'"></vf-badge>

React

As of version 3.0.0-alpha.1 vf-badge has experimental React support which has been tested on react version 18.2.0

  1. install yarn add @visual-framework/vf-badge
  2. import in the JS file wheree you want to include this component
    import VfBadge from '@visual-framework/vf-badge/vf-badge.react';
    
    Make sure you have the jsx support enabled with babel. Alternatively, you can also copy the vf-badge.react.js file from below to your react project and import as per the location.
    
  3. can be used as
    <VfBadge text="ALPHA" theme="primary" id="Badge1"/>
    
  4. add beloow to your CSS file
    @import '~@visual-framework/vf-sass-config/index.scss';
    @import '~@visual-framework/vf-badge/vf-badge.css';
    
    you should also install and import vf-sass-starter for the styles

Usage:

<VfBadge text="ALPHA" theme="primary" id="Badge1"/>

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",
  
  }
%}
                
Angular syntax
<vf-badge [text]="'alpha'" [theme]="'primary'" [id]="'Badge1'"/>
                  
React syntax
<VfBadge text="ALPHA" theme="primary" id="Badge1"/>
                  
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

3.0.5

3.0.4

3.0.3

3.0.2

3.0.1

  • Version bump

3.0.0

  • Version bump

3.0.0-alpha.2

3.0.0-alpha.1

  • Added : Angular syntax for different variants as compared to common syntax
  • Added : Experimental React support for Badge component

3.0.0-alpha.0

  • Added : Experimental Angular support for Badge

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.

AI Assistant

Welcome! I'm here to help

Try asking me:

Disclaimer: This chatbot is designed to assist you with general information and basic inquiries. See our disclaimer notes.

Review AI generated content for accuracy. Leave feedback.

Close chat and delete conversation?

Are you sure you want to close the chat?
Your current conversation history will be permanently deleted.