Drupal Advent Calendar Day 20: Using Storybook to Preview Single Directory Components

Drupal Advent Calendar Day 20

Day 20 of the Drupal Advent Calendar, authored by James Shields, highlights a talk by Philip Norton at DrupalCamp Scotland that explores integrating Storybook with Drupal's Single Directory Components (SDCs).

The presentation focuses on how developers can streamline their workflow by building components once for Drupal and previewing them visually in Storybook, eliminating the need to duplicate front-end work. This approach aligns with modern theming practices and is compatible with emerging tools such as Drupal Canvas. The talk explains the structure and behaviour of SDCs, including how props and slots are defined using YAML and Twig. Norton details how Storybook stories are created through stories.twig files, which are converted into stories.json using Drush commands. Storybook then uses these JSON files to render interactive component previews.

He also covers technical aspects such as handling cross-origin resource sharing (CORS), avoiding the need to commit generated files, and organising stories to reflect real-world scenarios. Philip emphasises using Storybook not only as a development environment but also as a demonstration tool for clients. He discusses best practices, common challenges, and alternatives to Storybook, all while reinforcing the value of component-driven development. The session ultimately advocates for improved separation between Drupal templates and front-end design, making it easier to maintain and reuse components across projects. Slides and source code from the demo are made available for further exploration.

Disclosure: This content is produced with the assistance of AI.

Disclaimer: The opinions expressed in this story do not necessarily represent that of TheDropTimes. We regularly share third-party blog posts that feature Drupal in good faith. TDT recommends Reader's discretion while consuming such content, as the veracity/authenticity of the story depends on the blogger and their motives. 

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related Events

Upcoming Events

Latest Opportunities