React playground

Nova v3.38.0

Preview

React

nv-badge migration

Replacing the deprecated badge, with a colour mapping for each value.

← nv-badge

Migration Guide for nv-badge

In the latest version of the nv-badge component, we've made several important changes to the properties to improve usability and consistency. Below is a guide to help you update your existing badges from version 2 to version 3.

The component is deprecated#

nv-badge is deprecated and will be removed in a future major version. Which component replaces it depends on what the badge was used for:

UseReplacement
Labelling, categorisation, keywordsnv-tag
System-controlled statusnv-statusindicator
Interactive, selectable chips (filters, compact toggles)nv-pill

Colour mapping: status values#

The five status values map onto nv-statusindicator with emphasis="medium". The status names stay the same, and the medium emphasis uses the same --color-feedback-*-low-* text, border and background tokens as nv-badge, so the colour is unchanged. The default emphasis, low, has a border but no background.

nv-badgenv-statusindicator
color="error"status="error" emphasis="medium"
color="information"status="information" emphasis="medium"
color="neutral"status="neutral" emphasis="medium"
color="success"status="success" emphasis="medium"
color="warning"status="warning" emphasis="medium"

nv-statusindicator shows an icon that follows the status: circle-check for success, alert-circle for warning, alert-triangle for error, info-circle for information and help for neutral.

nv-badgenv-statusindicator
No leadIconhide-icon (label only, as before)
leadIcon="user"icon="user"

nv-statusindicator is static and cannot be dismissed. If you need a dismissible element, use nv-tag and pick a palette colour from the table below.

Colour mapping: palette colours#

The named and numeric colours map onto nv-tag. Both components draw from the same rainbow palette, so the colour carries over; nv-tag uses the lighter border token (--color-rainbow-N-border-light), so the outline is slightly softer.

nv-badgenv-tagPalette token
color="1", color="amber"color="amber"--color-rainbow-1-*
color="2", color="orange"color="orange"--color-rainbow-2-*
color="3"color="yellow"--color-rainbow-3-*
color="4"color="red"--color-rainbow-4-*
color="5", color="turquoise"color="turquoise"--color-rainbow-5-*
color="6", color="crimson"color="crimson"--color-rainbow-6-*
color="7"color="green"--color-rainbow-7-*
color="8", color="petrol"color="blue"--color-rainbow-8-*
color="9", color="lime"color="lime"--color-rainbow-9-*
color="10"color="grey"--color-rainbow-10-*

Do not substitute a palette colour for a status value: nv-tag's red is --color-rainbow-4-background (#f9e3e3), while nv-badge's error is --color-feedback-error-low-background (#ffeded). They are close but not the same, and only the status components track the feedback tokens.

Old Usage:

html<nv-badge label="Draft" color="10"></nv-badge>
<nv-badge label="Failed" color="error"></nv-badge>

New Usage:

html<nv-tag label="Draft" color="grey"></nv-tag>
<nv-statusindicator label="Failed" status="error" emphasis="medium" hide-icon></nv-statusindicator>

The sections below remain relevant while you are still on nv-badge.

Deprecations#

1. prop dismissal#

The dismissal property has been deprecated in favor of dismissible. This change aligns the property name more closely with its function, which is to determine whether the badge can be dismissed.

Old Usage:

html<nv-badge dismissal="true"></nv-badge>

New Usage:

html<nv-badge dismissible="true"></nv-badge>

2. prop icon#

The icon property has been deprecated in favor of leadIcon. This change clarifies that this icon appears at the leading edge of the badge.

Old Usage:

html<nv-badge icon="user"></nv-badge>

New Usage:

html<nv-badge leadIcon="user"></nv-badge>

3. prop iconLocation#

The iconLocation property has been deprecated. The badge now only supports a leading icon.

Old Usage:

html<nv-badge icon="user" iconLocation="left"></nv-badge>

New Usage:

html<nv-badge leadIcon="user"></nv-badge>

Breaking Changes#

1. event close -> closeClicked#

The close event has been renamed to closeClicked. This is more descriptive of the event's purpose, as the hiding of the badge could be intercepted by the preventAutoClose prop.

Old Usage:

html<nv-badge @close="handleClose"></nv-badge>

New Usage:

html<nv-badge @closeClicked="handleClose"></nv-badge>

New Properties#

1. hidden Property and hiddenChanged Event#

:warning: The new hidden property controls the visibility of the badge and supports animations. The hiddenChanged event emits when the hidden property changes.

Old Code:

html<nv-badge
  label="User Badge"
  dismissal="true"
  onClose="handleCloseEvent">
</nv-badge>

New Code:

html<nv-badge
  label="User Badge"
  dismissible="true"
  hidden="true"
  onHiddenChanged="handleVisibilityChange">
</nv-badge>

2. 'preventAutoClose': Provides a prop to prevent the badge from hiding automatically when the close button is clicked. This is useful for externally controlled component behavior.#

New Usage:

html<nv-alert dismissible prevent-auto-close></nv-alert>