Design system with Storybook for a Liferay portal: how we built it

Design system with Storybook for a Liferay portal: how we built it
Liferay and portals
Alejandro Muñoz del Prado

Alejandro Muñoz del Prado

Equipo técnico

November 23, 2026
6 min read
Share:

When a component is built directly inside the Liferay theme, it's hard to tell whether it works on its own or because it's dragging along styles, scripts and context from the surrounding portal. We prefer to develop each piece in isolation, test it without that dependency, and only afterwards bring it into the theme or the client extensions. Storybook is the tool that lets us make that cut.

Computer screen showing a component library in Storybook

Why we separate the component from the portal

A Liferay portal loads themes, fragments, widgets and client extensions at the same time. If you develop a component inside that environment, any visual glitch could be coming from a dozen different places: a global CSS rule overriding yours, a script from another widget modifying the DOM, a theme variable that changes depending on the page. Isolating the component in Storybook removes that noise. What you see in the story is exactly the component, with its props, its states, and nothing else.

This has a practical consequence: the component is designed, reviewed and approved before any site exists where it has to fit. The design team and the development team discuss the same isolated piece, without the conversation getting contaminated by integration problems that aren't relevant yet.

How we organise the repository

In a recent project, abahanavillas, we split the work into three parts within the same repository: storybook, where the documented components and their stories live; cis, the client extensions that expose those components as widgets or fragments consumable from Liferay; and portal, the theme project that finally integrates them.

The flow always goes in the same direction: first the component is created and documented in Storybook, then it's packaged as a client extension, and finally it's consumed from the theme or from a portal page. Reversing that order (touching the component directly inside the theme) is what leads to duplicated logic and losing track of which version of the component is deployed where.

A basic story

A story for a button component, with its main variants, looks as simple as this:

TypeScript
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';

const meta: Meta<typeof Button> = {
  title: 'Componentes/Button',
  component: Button,
  args: {
    variant: 'primary',
    label: 'Reservar ahora',
  },
};
export default meta;

type Story = StoryObj<typeof Button>;

export const Primario: Story = {};

export const Secundario: Story = {
  args: { variant: 'secondary' },
};

export const Deshabilitado: Story = {
  args: { disabled: true },
};

None of this depends on Liferay. The component can be reviewed, versioned and tested without spinning up an entire portal, which hugely speeds up the iteration cycle with design.

Design tokens as the single source of truth

A design system without tokens ends up being a collection of components with colours and spacings set by hand on each one. We define tokens (colour, typography, spacing, border radii) as centralised CSS variables, and both Storybook and the Liferay theme consume them from the same place.

CSS
:root {
  --color-primary-500: #1b4332;
  --color-primary-100: #d8f3dc;
  --space-sm: 8px;
  --space-md: 16px;
  --radius-base: 6px;
  --font-family-base: 'Inter', sans-serif;
}

The component never writes a colour or a size as a raw value. It uses the token. If the brand palette changes tomorrow, you touch a single file and every component, in Storybook and in the portal, updates in the same way. That way, a redesign can be resolved in a day, instead of spending several weeks hunting down stray values scattered across the code.

Colour swatches arranged as a metaphor for design tokens

Portals and applications built to last for years. And someone to maintain them.

We build and maintain portals, intranets and applications. And we rescue existing ones: we update them, tidy them up and leave them maintainable.

See portals and development

Accessibility within the story

We check accessibility right in the story itself, with the same tool the design team uses to approve the component, instead of leaving it for when it's already integrated into a real portal page. We add Storybook's accessibility addon to every story, so that any contrast issue, ARIA labelling problem or focus order mistake shows up right there, next to the component.

TypeScript
export const Primario: Story = {
  parameters: {
    a11y: {
      config: {
        rules: [{ id: 'color-contrast', enabled: true }],
      },
    },
  },
};

This avoids the usual scenario: a component that passes every visual review but turns out to be unusable with a keyboard or a screen reader, and which gets discovered late, with the portal already in production.

Interaction tests on the story itself

Besides documenting how a component looks, Storybook lets us check how it behaves. With play functions we simulate clicks, form typing or keyboard navigation directly on the story, without needing to spin up the whole portal for every test.

TypeScript
import { expect, userEvent, within } from '@storybook/test';

export const EnvioFormulario: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const input = canvas.getByLabelText('Correo electrónico');
    await userEvent.type(input, 'contacto@abahanavillas.com');
    await userEvent.click(canvas.getByRole('button', { name: 'Enviar' }));
    await expect(canvas.getByText('Gracias por tu mensaje')).toBeInTheDocument();
  },
};

These tests run in the continuous integration pipeline, before the component is packaged as a client extension. If someone breaks a form's behaviour while touching the component, the failure shows up in storybook, not three weeks later in a production incident opened by a portal user.

Stacked building blocks as a metaphor for reusable components

From the component to the theme and the client extensions

Once the component is documented, tested and approved in Storybook, it's time to bring it into Liferay. Here we distinguish two paths, depending on where the component needs to live:

  • •If the component is part of the overall visual structure (header, footer, navigation), we add it to the theme, sharing the same CSS tokens that Storybook already uses.
  • •If the component is a functional piece that a content editor needs to be able to place on any page, we package it as a client extension, inside the repository's cis module, so that Liferay exposes it as a widget independent from the theme.

The common mistake is treating these two options as alternatives and picking one for the whole project, when the sensible approach is to decide case by case, even component by component. A brand button goes in the theme. A booking block that a content manager needs to move between pages goes as a client extension.

Packaging as a client extension

The definition file for a client extension that exposes a component already tested in Storybook is straightforward:

YAML
name: reserva-widget
type: customElement
baseURL: https://static.abahanavillas.com/widgets
cssURLs:
  - reserva-widget.css
urls:
  - reserva-widget.js
htmlElementName: reserva-widget
instanceable: true

There's little mystery to the YAML. What matters to us is that the component being packaged here is the very same one that already went through the stories, the interaction tests and the accessibility review. There's no second, hastily written version of the button living inside the theme.

What doesn't get fully automated

Keeping Storybook, the tokens and the client extensions in sync with the theme demands discipline from the team; tools help, but they aren't enough on their own. We use AI agents to generate the skeleton of new stories or to spot stray tokens that should be coming from the shared variable, but there's always a person reviewing before the component is signed off as approved. The decision of what goes in the theme and what goes as a client extension, and how each interaction gets tested, remains a design call that shouldn't be fully delegated.

If you're starting a design system for a Liferay portal, our recommendation is to start small: instead of setting up Storybook with every possible addon, pick three or four real components from the project, document them with their tokens and their accessibility, and check that this whole loop (story, test, client extension, portal) works before scaling it to the rest.

Tags:liferayclient extensionsstorybookdesign systemaccesibilidadtokens de diseño

Portals and applications built to last for years. And someone to maintain them.

We build and maintain portals, intranets and applications. And we rescue existing ones: we update them, tidy them up and leave them maintainable.

See portals and development