React component library for Castor.

Usage no npm install needed!

<script type="module">
  import onfidoCastorReact from 'https://cdn.skypack.dev/@onfido/castor-react';


Castor React

npm version Bundle size

Castor React is Onfido's design system addition. It provides React component library.

Get started

Install packages

npm install @onfido/castor @onfido/castor-react

Follow Castor instructions for initial setup.

If you plan to use Icon component, also install Castor Icons package:

npm install @onfido/castor-icons

Then (only once) inline the SVG sprite in your app:

import { Icons } from '@onfido/castor-icons';
import React, { Fragment } from 'react';

const App = () => (
    <Icons />
    {/* ...anything else e.g. app routes */}

Use components

Include any Castor component and use it within JSX directly.

import { Button } from '@onfido/castor-react';

Then use within your JSX app. For example, as a "destructive" kind:

import React, { Fragment } from 'react';

const App = () => (
    <Button kind="destructive">Destructive Button</Button>

Please note that Castor is exported as an ECMAScript module targeting ECMAScript 2019.

You may wish to configure your bundler to transpile to a different module syntax, and/or to target a lower ECMAScript version.

For example, you might choose UMD module syntax targeting ES5 if your app needs to support IE11 (please note that Castor is not tested in Internet Explorer).

Use with TypeScript

Components extend base prop types with JSX additions.

When using with TypeScript, always import types from @onfido/castor-react.

Please note that the @onfido/castor-icons package is a peer dependency and is required to be installed for types to work properly. Yarn and newer versions of npm (using lockfile v2) will resolve it, otherwise it must be installed manually even if you don't plan to use icons.

Make custom styled components

You should use props for each component modifier, but it is also possible to create custom styled components.

For example, if you'd like a round button, you could create a component using "full" border-radius token:

import styled from '@emotion/styled';
import { borderRadius } from '@onfido/castor';
import { Button } from '@onfido/castor-react';

const RoundButton = styled(Button)({
  borderRadius: borderRadius('full'),

Use for prototyping

If you need to prototype with Castor, the quickest way is to use the generated single file global Castor exposed as IIFE module:

<script src="https://cdn.jsdelivr.net/npm/@onfido/castor-react/prototype.min.js"></script>

You can also use any previously released version (v1.2.0 and up), for example:

<script src="https://cdn.jsdelivr.net/npm/@onfido/castor-react@1.2.0/prototype.min.js"></script>

The same prototype file (not minified) is located on each npm package version.

For modern browsers you may use ECMAScript modules directly via Skypack:

<script type="module">
  import { borderRadius } from 'https://cdn.skypack.dev/@onfido/castor';
  import { Button } from 'https://cdn.skypack.dev/@onfido/castor-react';

  // all other app code

Also it is easy to use Skypack distributions with Deno.