7.9.2 • Published 9 months ago

@financial-times/o-buttons v7.9.2

Weekly downloads
935
License
MIT
Repository
-
Last release
9 months ago

o-buttons

o-buttons provides Sass mixins and variables to create buttons.

Usage

Check out how to include Origami components in your project to get started with o-buttons.

Buttons allow users to interact with the page or product. Each page or product area (a form, modal, within an article) should not have more than 1 primary button, any remaining CTA's should be displayed as secondary or ghost buttons.

Buttons communicate actions that users can take. They are typically placed throughout your UI, in places like:

  • Dialogs
  • Modal windows
  • Forms
  • Cards
  • Toolbars

When not to use

If an action a user takes is navigational, e.g. going back, a button should not be used.

Accessibility

  • It is advisable to use colour combinations provided by the implementation. These combinations are ensured to comply with WCAG AA requirements. When customising colours, refer to colour guidelines to ensure accessibility.
  • In most cases, prefer using default size buttons over small buttons. Default sized buttons are easier for users to notice and press.

Markup

There are three types of buttons, primary, secondary, and ghost.

TypeSelectorBrand SupportPurpose
primary.o-buttons--primarycore, internal, whitelabelFor principal calls to action on the page. Primary buttons should only appear once per product area (not including the application header, modal dialog, onsite messaging or side panel).
secondary.o-buttons--secondarycore, internal, whitelabelFor secondary actions on each page or used in conjunction with a primary button. As part of a pair, the secondary button’s function is to perform the negative action of the set, such as “Cancel” or “Back”.
ghost.o-buttons--ghostcore, internal, whitelabelFor the least pronounced actions; often used in conjunction with a primary button. In a situation such as a progress flow, a ghost button may be paired with a primary and secondary button set, where the primary button is for ‘Save and continue’ the ghost button would be ‘Skip’.
<button class="o-buttons o-buttons--primary">Submit</button>
<button class="o-buttons o-buttons--secondary">Cancel</button>
<button class="o-buttons o-buttons--ghost">Options</button>

o-buttons CSS will work on <button> or <a> elements. It is important for accessibility that if you intend to style an <a> as a button, you give it the correct aria role.

The copy inside buttons should be concise and confirm the action a user is taking.

Themes

A theme may be applied to a button to change its appearance. o-buttons provides some themes by default:

ThemeSelectorWorks With TypesBrand Support
inverse.o-buttons--inverseprimary, secondary, ghostcore, internal
mono.o-buttons--monoprimary, secondary, ghostcore, internal
b2c.o-buttons--b2cprimarycore
professional.o-buttons--professionalprimary, secondary, ghostcore
professional-inverse.o-buttons--professional-inverseprimary, secondary, ghostcore
ft-live.o-buttons--ft-liveprimary, secondary, ghostcore
<button class="o-buttons o-buttons--primary o-buttons--inverse">Submit</button>
<button class="o-buttons o-buttons--secondary o-buttons--inverse">Cancel</button>

Sass users may create custom themes.

Sizes

Any button may be made larger using the o-buttons--big modifier class.

<button class="o-buttons o-buttons--primary o-buttons--big">Click Me</button>

Icons

To add an icon to your button add the class o-buttons-icon and o-buttons-icon--{icon-name} to your button.

Sass users may output any icon from the fticons set. However if you're using the Build Service a limited number of button icons are available. Limiting the number of icons keeps the CSS bundle smaller, but if you need an icon button that we don't currently support then please contact the Origami team:

  • arrow-left
  • arrow-right
  • upload
  • tick
  • plus
  • warning
  • arrow-down
  • arrow-up
  • grid
  • list
  • edit
  • download
  • search
  • refresh
  • cross
<button class="o-buttons o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-down">Down Arrow</button>
<button class="o-buttons o-buttons--secondary o-buttons-icon o-buttons-icon--download">Download</button>

If you would like your button to display only an icon, add the class o-buttons-icon--icon-only and provide a visually hidden label for screen-reader users with o-buttons-icon__label.

<button class="o-buttons o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-down o-buttons-icon--icon-only">
	<span class="o-buttons-icon__label">
		Down Arrow
	</span>
</button>

Groups

Wrap buttons with .o-buttons-group to group them together:

<div class="o-buttons-group">
	<button class="o-buttons o-buttons--secondary" aria-selected="true">One</button>
	<button class="o-buttons o-buttons--secondary">Two</button>
	<button class="o-buttons o-buttons--secondary">Three</button>
</div>

Pagination

For a pagination style wrap your buttons in .o-buttons-pagination. Most pagination usecases use an anchor a tags for links which look like buttons instead of a button tag. When using an anchor tag in pagination do not use the aria-selected data attribute. Instead use aria-current="page" to indicate the current page, this will highlight the button for the current page visually and to screen readers.

The following markup example shows pagination for 20 pages, where the 14th page is the current page. Following the pagination rules we recommend displaying no more than 7 pages and using the ellipsis element to show hidden results.

<div class="o-buttons-pagination">
	<a href="#" class="o-buttons o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-left o-buttons-icon--icon-only">
		<span class='o-buttons-icon__label'>Previous results</span>
	</a>

	<a href="#" class="o-buttons o-buttons--secondary">1</a>
	<span class="o-buttons-pagination__ellipsis">...</span>
	<a href="#" class="o-buttons o-buttons--secondary">13</a>
	<a href="#" class="o-buttons o-buttons--secondary" aria-current="page">14</a>
	<a href="#" class="o-buttons o-buttons--secondary">15</a>
	<span class="o-buttons-pagination__ellipsis">...</span>
	<a href="#" class="o-buttons o-buttons--secondary">20</a>

	<a href="#" class="o-buttons o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-right o-buttons-icon--icon-only">
		<span class='o-buttons-icon__label'>Next results</span>
	</a>
</div>

Pagination Rules

The number of pages to display is not enforced by Origami. However we recommend the following:

  • Show no more than 7 pages at a time. When there are more than 7 pages, hide more pages behind the pagination ellipsis in the following way. Given: - The selected page is below 3 show ellipsis with 3 pages either side. - The selected page is one of the last 2 pages show ellipsis with 3 pages either side. - The 3rd page is selected show 4 pages, the ellipsis, and 2 more pages. - The 3rd from last page is selected show 2 pages, the ellipsis, and 4 more pages. - The selected page is more than 3 from the first and last page show the first page, ellipsis, three pages, ellipsis, and the last page.

For an example see the pagination demos in the Origami registry.

Pagination Theme

A theme modifier such as o-buttons--inverse may be added to the buttons within a pagination block.

Pagination Size

Big buttons may also be used in a pagination style. Add the o-buttons--big modifier to each button and o-buttons-pagination__ellipsis--big to the ellipsis element.

<div class="o-buttons-pagination">
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-left o-buttons-icon--icon-only" disabled>
		<span class='o-buttons-icon__label'>Previous results</span>
	</a>

	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary" aria-current="page">1</a>
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary">2</a>
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary">3</a>
	<span class="o-buttons-pagination__ellipsis o-buttons-pagination__ellipsis--big">...</span>
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary">18</a>
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary">19</a>
	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary">20</a>

	<a href="#" class="o-buttons o-buttons--big o-buttons--secondary o-buttons-icon o-buttons-icon--arrow-right o-buttons-icon--icon-only">
		<span class='o-buttons-icon__label'>Next results</span>
	</a>
</div>

Disabled

Avoid disabled buttons unless user research shows they improve your interface. Disabled buttons have poor contrast which makes them difficult to read. They also do not give feedback to a user why they are disabled.

To make a button disabled add the disabled attribute. To visually hide the disabled button until it is active add the class o-buttons--hide-disabled.

<!-- Visibly disabled because of the `disabled` attribute. -->
<button class="o-buttons" disabled>My Button</button>

<!-- Visually hidden because of the `disabled` attribute and `o-buttons--hide-disabled`.-->
<button class="o-buttons o-buttons--hide-disabled" disabled>My Button</button>

Sass

To output default o-buttons CSS make a single call to the primary mixin oButtons. It is recommended that you pass an options map as the first argument to include only the button styles you need. Without the options map, all o-buttons styles are included.

@include oButtons($opts: (
	'sizes': ('big'), // e.g .o-buttons--big
	'types': ('primary', 'secondary', 'ghost'), // e.g .o-buttons--primary
	'themes': ('mono', 'inverse', 'b2c', 'professional', 'professional-inverse', 'ft-live'), // e.g .o-buttons--inverse
	'icons': ('arrow-left', 'arrow-right', 'search'), // any fticons, e.g .o-buttons-icons.o-buttons-icons--search
	'pagination': true, // .o-buttons-pagination
	'groups': true // .o-buttons-group
));

Custom Themes

To create a new button theme call oButtonsAddTheme with the colour of your theme along with the types of buttons and icons you would like to use with your theme, if any.

  • name: The name of your theme. This is used for the modifer class output o-buttons--{name}.
  • opts: A map of options for your theme. Keys include color and context. - color: The main colour of your button. Any o-colors palette colour name. - context (optional): The background colour your button is placed on. Defaults to the page colour (paper for the core brand, white otherwise). This is used to confirm accessibility and in some cases changes the colour of the button.
  • types: A list of button types your theme is used with.
  • icons: A list of icons your theme is used with. Any fticons icon name.
/// .o-buttons--my-special-button
@include oButtonsAddTheme(
	$name: 'my-special-button',
	$opts: ('color': 'claret-80'),
	$types: ('primary', 'secondary'),
	$icons: ('arrow-up', 'arrow-down')
);

Custom Markup

We recommend using o-buttons markup as this encourages CSS reuse and smaller bundle sizes. If you are unable to update your markup to use o-buttons classes, including those generated by oButtonsAddTheme, use oButtonsContent:

.my-button {
	@include oButtonsContent($opts: ('type': 'primary'));
}
.my-icon-button {
	@include oButtonsContent($opts: (
		'type': 'primary',
		'icon': 'arrow-right'
	));
}
.my-lemon-button {
	@include oButtonsContent($opts: (
		'type': 'primary',
		'theme': ('color': 'lemon')
	));
}

oButtonsContent has options to recreate all buttons, including for different sizes and icon only buttons. See the o-buttons SassDoc for more details and examples.

References

  • Hampus Sethfors explains the issues with disabled buttons in more detail in an axesslab.com article. In the article Hampus suggests alternative design approaches for common uses of disabled buttons.

Migration

StateMajor VersionLast Minor ReleaseMigration guide
✨ active7N/Amigrate to v7
⚠ maintained66.2migrate to v6
╳ deprecated55.16migrate to v5
╳ deprecated44.5-
╳ deprecated33.1-
╳ deprecated22.0-
╳ deprecated11.8-

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #origami-support or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.

7.9.2

9 months ago

7.8.4

1 year ago

7.8.3

1 year ago

7.8.2

1 year ago

7.9.1

1 year ago

7.9.0

1 year ago

7.8.0

2 years ago

7.8.1

2 years ago

7.7.5

2 years ago

7.7.4

2 years ago

7.7.3

2 years ago

7.7.2

2 years ago

7.7.1

2 years ago

7.7.0

2 years ago

7.6.0

3 years ago

7.3.0

3 years ago

7.4.0

3 years ago

7.2.2

3 years ago

7.2.1

3 years ago

7.5.0

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.2.0

3 years ago

7.0.2

3 years ago

7.0.1

3 years ago

0.0.0

3 years ago

7.0.0

3 years ago

7.0.0-0

4 years ago

7.0.0-beta.0

4 years ago

6.2.0

4 years ago

6.1.1

4 years ago

6.1.0

4 years ago

6.0.19

4 years ago

6.0.18

4 years ago

6.0.17

4 years ago

6.0.16

4 years ago

6.0.15

4 years ago

6.0.14

5 years ago

6.0.13

5 years ago

5.16.9

5 years ago

5.16.8

5 years ago

6.0.12

5 years ago

6.0.11

5 years ago

6.0.10

5 years ago

6.0.9

5 years ago

6.0.8

5 years ago

6.0.7

5 years ago

6.0.6

5 years ago

6.0.5

5 years ago

6.0.4

5 years ago

6.0.3

5 years ago

6.0.2

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

6.0.0-beta.4

5 years ago

6.0.0-beta.1.0.3

5 years ago

6.0.0-beta.1.0.2

5 years ago

6.0.0-beta.1.0.1

5 years ago

6.0.0-beta.1

5 years ago

5.16.7

5 years ago

5.16.6

5 years ago

5.16.5

5 years ago

5.16.4

6 years ago

5.16.3

6 years ago

5.16.2

6 years ago

5.16.1

6 years ago

5.16.0

6 years ago