@guardian/interactive-component-library
TypeScript icon, indicating that this package has built-in type declarations

0.7.12 • Public • Published

@guardian/interactive-component-library

A set of reusable components for use in interactive pages, written in Preact using Atomic Design principles.

Install the component library in a new client project

npm install @guardian/interactive-component-library

Contributing to this repository

Building the project requires Node v16.18.1 or higher.

  1. Clone this repository
  2. Run corepack enable to enable pnpm
  3. Install dependencies with pnpm i
  4. Run pnpm dev to start the local Storybook server

Atomic design

The component library is structured according to Atomic Design principles, using the bottom three levels.

  1. Particles (renamed from atoms for obvious reasons)
  2. Molecules
  3. Organisms

Particles are the lowest level components that form the building blocks for everything else, e.g. a Button. Molecules represent more complex components (e.g. a Table) and often depend on particle components. Organisms combine the previous two levels into distinct sections of an interactive page, e.g. KeySeats.

Folders use the same naming structure, with particles, molecules and organisms folders in src/lib/components, to distinguish between the three different levels.

Adding a new component

Create a folder for your new component in the appropriate directory. The name of the folder should be the name of your component in Kebab case, i.e. src/lib/components/particles/my-new-component.

The folder should contain the following:

  • index.jsx containing the code for the actual component
  • [component-name].stories.jsx containing examples of how to use the component, written as Storybook stories
  • docs.mdx (optional) additional documentation for the component in Storybook

Developing and testing locally

During development, you'll often want to see how a component looks in the interactive page that you're working on, without rebuilding and publishing a new version of the component library. To facilitate this workflow, we use npm-link.

Here's how to set that up:

cd ~/projects/interactive-component-library       # go into the package directory
npm link                                          # creates global link
cd ~/projects/interactive-project                 # go into your project directory
npm link @guardian/interactive-component-library  # link-install the package

After you've done that, run pnpm build:lib:watch to package the library and rebuild on file changes.

To revert back to the version specified in your project‘s package.json:

npm uninstall --no-save @guardian/interactive-component-library && npm install

Publishing a new version

To publish a new version of the component library, follow these steps:

  1. Create a new release on GitHub (don't forget to write some release notes)
  2. Publishing the release triggers a workflow to package the library and publish it to the NPM registry. If the publish actions fails, you can also trigger it manually
  3. The publish action also creates a pull request to bump the version number. Merge the pull request to finish the release

Scripts

Always prepending pnpm:

  • dev: Start Storybook for local development
  • build: Builds the static storybook project
  • build:lib: Builds the component library into the dist folder
  • build:lib:watch: Same as previous command, but it watches /src folder and rebuilds on changes

Testing for dark mode in Storybook

Use the sun/moon button in the toolbar to switch between light and dark mode. Screenshot 2024-03-27 at 08 24 43 Screenshot 2024-03-27 at 08 24 32

Enabling dark mode applies .ios and .dark-mode classes to the <body> element, which in turn renders the story preview with dark mode colours (this behaviour can be customised in .storybook/preview.scss).

Note that enabling dark mode using this button does not affect the prefers-color-scheme CSS media feature. If your component uses prefers-color-scheme directly, you will also need to change your system or browser setting to see that styling take effect.

License

Apache 2.0

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.7.12939latest

Version History

VersionDownloads (Last 7 Days)Published
0.7.12939
0.7.112
0.7.100
0.7.90
0.7.80
0.7.71
0.7.60
0.7.50
0.7.41
0.7.30
0.7.20
0.7.11
0.7.00
0.6.01
0.5.70
0.5.60
0.5.50
0.5.40
0.5.30
0.5.20
0.5.10
0.5.00
0.4.50
0.4.40
0.4.30
0.4.20
0.4.11
0.4.02
0.3.20
0.3.2-rc10
0.3.10
0.3.00
0.2.00
0.2.0-rc41
0.2.0-rc30
0.2.0-rc20
0.2.0-rc10
0.1.00
0.1.0-alpha.590
0.2.0-rc-06ceabc.00
0.2.0-rc-2dff808.00
0.2.0-rc-a879fdc.00
0.2.0-rc-53483e0.00
0.2.0-rc-925bedb.00
0.1.0-alpha.580
0.1.0-alpha.570
0.1.0-alpha.530
0.1.0-alpha.520
0.1.0-alpha.510
0.1.0-alpha.500
0.1.0-alpha.490
0.1.0-alpha.480
0.1.0-alpha.470
0.1.0-alpha.460
0.1.0-alpha.450
0.1.0-alpha.440
0.1.0-alpha.430
0.1.0-alpha.420
0.1.0-alpha.410
0.1.0-alpha.400
0.1.0-alpha.391
0.1.0-alpha.380
0.1.0-alpha.370
0.1.0-alpha.360
0.1.0-alpha.350
0.1.0-alpha.340
0.1.0-alpha.330
0.1.0-alpha.320
0.1.0-alpha.310
0.1.0-alpha.300
0.1.0-alpha.290
0.1.0-alpha.280
0.1.0-alpha.271,054
0.1.0-alpha.260
0.1.0-alpha.250
0.1.0-alpha.240
0.1.0-alpha.230
0.1.0-alpha.220
0.1.0-alpha.210
0.1.0-alpha.202,329
0.1.0-alpha.191
0.1.0-alpha.181
0.1.0-alpha.171
0.1.0-alpha.161
0.1.0-alpha.151
0.1.0-alpha.141
0.1.0-alpha.130
0.1.0-alpha.120
0.1.0-alpha.110
0.1.0-alpha.100

Package Sidebar

Install

npm i @guardian/interactive-component-library

Weekly Downloads

4,339

Version

0.7.12

License

none

Unpacked Size

407 kB

Total Files

291

Last publish

Collaborators

  • ashcorrguardian
  • guardian-developers
  • akash1810
  • reetta
  • sndrs