Using Components (o3) via npm
Origami components are published to npm as Custom Elements, and other standards based web component technologies.
This guide aims to take you through the key steps to install and use Origami components. Familiarity with npm, CSS, and JavaScript is assumed. We also assume your project includes a build step e.g. webpack, vite, postcss.
If you are having difficulty getting Origami working for your setup, please reach out to the team. We can help you get setup and update our documentation as needed.
Install
To begin install @financial-times/o3-foundation
as a peer dependency, along with any other Origami packages you need.
For example purposes we’ll include:
@financial-times/o3-foundation
@financial-times/o3-tooltip
@financial-times/o3-button
If you’re working on a component or similar project, which other projects will depend on, we recommend using a caret ^
version range when installing Origami components. This will help to avoid peer dependency conflicts. E.g. @financial-times/o3-foundation^1.2.0
would allow any version at >=1.2.0 <2.0.0
.
Provide HTML
Origami supports multiple brands and themes. First set your brand using the data attribute data-o3-brand
on a parent element. Optionally, apply a theme using the data-o3-theme
data attribute. Supported themes are documented in a component’s Storybook.
Next we need to include the HTML for our components. We can do this in one of two ways:
- Copy-paste markup from Storybook. Or;
- Import a JSX template from the component.
We recommend JSX templates for React projects. This will reduce the number of markup changes required when upgrading to future versions of Origami; and provide markup autocompletion through type definitions.
HTML from Storybook
This example shows including a button which is described by an “onboarding tooltip”. It includes HTML copied from the HTML tab in Storybook:
HTML via JSX
This example shows including a button which is described by an “onboarding tooltip” using the component’s JSX:
Import CSS
Origami packages include component CSS for each supported brand /css/[brand].css
. Import these to your CSS globally. For example, for the core
brand:
Import client-side JavaScript
Client-side JavaScript for Origami packages if referenced in the browser
field of their package.json
where relevant. These are Custom Elements (web components), which are defined automatically on import.
In our example, only o3-tooltip
has client side JavaScript.
React compatibility
React users need to take extra steps to initialise component JavaScript using useEffect
, and may need to ensure the correct resolution of JSX with a more explicit import. Here’s the same example for a default Next.js project:
Although out of scope for this introduction, care must also be taken when working with objects as properties and events. This will be resolved in React 19.
Figma Dev Mode
Origami v3 (o3) aims to align Figma and our web implementation as much as possible. That means you can see at a glance which components a designer has used, what component properties (variants) they have selected, and what design tokens they have used e.g. for colours, spacing, and typography.
We recommend reading Figma’s documentation to get the most out of Dev Mode. However we’ll highlight a few key benefits here.
Figma Access
First ensure you have access to Figma’s Dev Mode. If not, request access from the Collaboration Tooling team.
Figma to CSS
Where a design uses a Figma Style or Figma Variable from Origami, you can copy this straight from Dev Mode.
The screenshot below shows an example design with Dev Mode enabled. By selecting the design we can see a CSS snippet which includes a real Origami CSS Custom Property --o3-spacing-m
:
Figma to JSX
Where possible we align Figma Variants to our JSX properties. After selecting an Origami component in a design, you can reference these values when setting JSX properties.
In the following screenshot we have selected a button and can see we need to include a button with type='primary'
set.
Figma to Storybook
After selecting an Origami component within a design we can also use Dev Mode to jump to design guidelines, Storybook, and any other developer resources.
VSCode extension recommendations
Figma For VSCode
Similar to Dev Mode, Figma for VSCode allows you to navigate and inspect design files within your text editor. These benefit from code auto completion based on the selected design.
The following screenshot shows Figma For VSCode suggesting the --o3-spacing-m
CSS Custom Property based on the selected Figma design.
CSS Variable Autocomplete
CSS Variable Autocomplete makes applying Origami foundations such as colours, typography, and spacing far easier as these are published as CSS Custom Properties. Instead of referencing documentation or design files, this plugin allows for autocompletion based on memory and search.
By default CSS Variable Autocomplete does not look for CSS in node_modules
. We recommend setting its configuration to specify which CSS to use for autocompletion. This will vary per project. E.g: