Display numbers in a counter form, useful to catch the user's attention on the number of subscribers for example.

Overview

This component pretends to recreate an analogic counter like an old alarm clock, or score display. To be used when we want to show a number that represents a leading information.

Small counter



Medium counter



Large counter

Usage

Dependencies

To get the counter component working, include the dependencies in your project in the following order:

  1. npm
  2. Sass
  3. Pug
"design-system": "git+ssh://git@github.com/Selectra-Dev/design-system.git"
@import 'design-system/src/scss/02-molecules/counter';
include /node_modules/design-system/src/pug/02-molecules/counter

Basic code

The counter component is composed of :

  • A div parent element with the counter class.
  • A variable number of div child elements with the counter__item class, each one containing one of the numbers.

🧐 Please be careful when you input the number in the mixin: the order of the array (first parameter) will determine the order of the number displayed. Be sure it matches with the number you want.

Note the attributes here:

  • aria-label must be defined to explain the number on our counter component (see Aria-label below).
  • role="status" is set by default and is not customisable, it means this component is supposed to change quite often (see Role below).
  • aria-hidden="true" is set by default and is not customisable, it prevents the browser from reading the number twice (see Aria-hidden below).

  1. HTML
  2. Pug
<div class="counter counter--primary counter--xl" aria-label="Label" role="status">
  <div class="counter__item" aria-hidden="true">2</div>
  <div class="counter__item" aria-hidden="true">3</div>
  <div class="counter__item" aria-hidden="true">5</div>
  <div class="counter__item" aria-hidden="true">7</div>
</div>
+counter([2, 3, 5, 7], "primary", "xl")

Pug mixin

We created a pug mixin to implement the counter with ease, find the parameters below:

+counter(number, color, size, ariaLabel)
# Name Type Default Required Description
1 number Array 6, 8, 4, 9, 2, 0 Yes Set the numbers to be displayed. Will display a placeholder number (684920) if empty.
2 color String secondary No Choose between primary and secondary . Some projects include a ternary option.
3 size String md No Choose between xs (24.5px), sm (28px), md (35px), lg (42px) and xl (56px) sizes.
4 ariaLabel String Label Yes Set the label for screen readers. Must be co-related to the number displayed.

Modifiers

Add the following modifier to change the appearance of counter.

Color

Color modifier simply sets the color of the shapes behind the numbers.

Primary

Secondary

  1. HTML
  2. Pug
<!--Primary-->
<div class="counter counter--primary counter--md" aria-label="Label" role="status">

<!--Secondary-->
<div class="counter counter--secondary counter--md" aria-label="Label" role="status">
//- Primary
+counter('','primary')
//- Secondary
+counter('','secondary')

Size

Size modifier allows us to choose between 5 different sizes : xs, sm, md, lg and xl.

xs


sm


md


lg


xl
  1. HTML
  2. Pug
<!--Extra-small-->
<div class="counter counter--secondary counter--xs" aria-label="Label" role="status">

<!--Small-->
<div class="counter counter--secondary counter--sm" aria-label="Label" role="status">

<!--Medium-->
<div class="counter counter--secondary counter--md" aria-label="Label" role="status">

<!--Large-->
<div class="counter counter--secondary counter--lg" aria-label="Label" role="status">

<!--Extra-large-->
<div class="counter counter--secondary counter--xl" aria-label="Label" role="status">
//- Extra-small
+counter('','','xs')
//- Small
+counter('','','sm')
//- Medium
+counter('','','md')
//- Large
+counter('','','lg')
//- Extra-large
+counter('','','xl')

HTML attributes

Attributes for the counter are focused on accessibility.

Aria-label

The aria-label attribute is used to define a string that labels the current element.

🧐A11y wise: Use aria-label attribute in cases where a text label is not visible on the screen. If there is visible text labeling the element, use aria-labelledby instead (on the labelled element).


  1. HTML
  2. Pug
<div class="counter counter--secondary counter--xs aria-label="Current number of subscribers" role="status">
+counter('','','', 'Current number of subscribers')

Role

The role attribute is set by default to role="status" and is not customisable.

🧐A11y wise: This value is commonly used for the types of live regions whose content are advisory information for the user (but are not important enough to justify an alert).

When the role is added to an element, the browser will send out an accessible status event to assistive technology products which can then notify the user about it.

Often but not necessarily presented as a status bar.

Aria-hidden

The aria-hidden attribute affects the counter items. It is set by default to true and is not customisable. The result is that these elements will be ignored by assistive technologies.

🧐A11y wise: We don't want the child elements to be readable by assistive technologies because of two reasons:

  • the whole number has already be read by the user with the Aria Label
  • it would be nonsense to read the whole number one by one