/  Frontend  /  What Is Storybook
decorative purple image with triangles and storybook logo
Frontend

Building a Component Library with Storybook for a Frontend Dashboard

Frontend developers at adjoe are currently working hard to reimagine our dashboards. This is so that Supply and Demand partners can view statistics, run ad campaigns, and bring new apps live with our Playtime SDK. This means coming up with a new look, new features, and a new codebase with state-of-the-art frameworks.

When working on React components that are based on a custom design kit made by our designers, it’s important to keep an eye on various elements. These include expected behavior as well as design implementation details like colors, borders, and margins. You should also have an overview of the components that have already been implemented in order to construct complex pages. To solve these criteria, we implemented Storybook, a component library framework, into our codebase.

In the following series of short articles, I – as a frontend developer – will show you what the codebase should look like in order to get the most out of the tool. I’ll also lead you through the process of integrating a Storybook component library.

What Is Storybook?

Storybook is a third-party package for frontend projects. It adds a component library to a project that can be run locally or deployed to either Storybook’s own hosting service Chromatic or to a custom service. 

Components are added to the library by adding a .stories file next to the component. This imports and renders it with user-controlled props. In addition, prop commenting and MDX can add documentation to the story. Thus, Storybook becomes an interactive list of all your components that also works as component documentation.

screenshot of building a component library with Storybook

How Should My Codebase Look for Storybook to Work?

I first brought up the idea to use Storybook in our codebase during a company hackathon. Back then, I tried to implement it in our dashboards. 

This turned out to be unsuccessful, as our dashboard code was using complex containers. This meant that writing stories for these components was nearly impossible due to how they used global store and API calls within them. 

In order to write efficient stories for your components, you have to make sure that they are as isolated as possible, working only with the props they get from their parent. That also means that you should only write stories for components, not containers. It is possible to use plugins for Storybook to mock API calls and global store. However, in my opinion, this is not the intended use of the tool.

How Do I Integrate Storybook into My Project?

First of all, you have to make sure that you already have an established project. Storybook only works in already existing codebases. This is due to how it looks through your project before setting it up correctly.

Then, installation is as easy as running one command:

npx storybook init

It will look through the codebase in order to implement the correct settings. After it has finished, you can open the storybook with one of the following commands depending on your project’s setup:

yarn storybook
npm storybook

These commands will open the Storybook local page in your browser. It will show you some tutorial pages and default components to get you started.

Storybook will automatically look for .stories.* files in your project. But you can change the search path easily by editing the main.js file created in the .storybook folder. Here, you can also add plugins and change options.

module.exports = {
 "stories": [
   "../**/*.stories.@(js|jsx|ts|tsx|mdx)",
 ],
 "addons": [
   "@storybook/addon-links",
   "@storybook/addon-essentials",
   "@storybook/addon-interactions",
   "storybook-addon-react-router-v6",
 ],
 "framework": "@storybook/react",
 "core": {
   "builder": "@storybook/builder-webpack5"
 }
}

Based on the styling approach you use, you might also find that your stories are not using the style of your project. In our dashboards, we use MUI theme for global style guidelines. In order to make sure all story components are using this theme, we had to add a new file to the .storybook folder: preview.js.

Here, you are able to set decorators, an array of functions that get the story as a parameter, and return the customized JSX element. In our example, we added the MUI license key for paid MUI components in use and wrapped the story in our theme.

export const decorators = [
 (Story) => {
   setMuiLicenseKey();
   const ThemedStory = withTheme(Story);

   return (
     <ThemedStory />
   )
 },
];

At this stage, you can browse through your stories locally. But what if you want to share your storybooks with your colleagues?

There are two options to host your storybook online. You can either use your own hosting service, or you can use Chromatic, a hosting service uniquely made for Storybook. There, you can set up your project, set up access settings, leave design reviews, and use versioning for your uploads.

To create a new project, you first have to create a Chromatic account and initially adjust some settings. Follow the setup instructions, and you will get a secret Chromatic token that you can use to upload your storybook to the platform. You can upload it manually via the command:

yarn chromatic —-chromatic-token=YOUR_TOKEN

You can also set up your pipeline to upload it automatically in your CI. This is the recommended way of loading your storybook. Chromatic also expects the upload to be performed on a consistent branch, so make sure you upload it via your develop or master branch. 

In our case, we created a new GitLab job to upload the storybook after our test pipeline on the master branch was successful.

job-upload-storybook:
 image: node:latest
 stage: upload
 environment:
   name: test
 except:
   variables:
     - $TEST_SKIP == "yes"
     - $TB_SKIP == "yes"
 script:
   - docker stop storybook || true
   - docker rm storybook || true
   - docker run --name storybook -td -v $(pwd):/usr/src/project --env CHROMATIC_PROJECT_TOKEN=$CHROMATIC_PROJECT_TOKEN node:latest
   - docker exec storybook sh -c 'cd usr/src/project/beta; yarn bootstrap; yarn chromatic'
   - docker stop storybook
   - docker rm storybook
 only:
   - master

With this we made sure that the new version of Storybook always has an “ancestor” version to compare it to, and thus makes the automatic UI comparison work correctly. More on that feature in a later article.

What’s Next?

After building a component library with Storybook, you should have a constantly up-to-date Storybook to use for documenting and viewing components. It will also automatically check for UI differences between your upload and the last version uploaded. You can review these changes to accept or deny them.

Stay tuned for my next article, in which you will learn how we wrote stories for small and complex components. These small components include buttons and complex components include dropdowns or filters. I’ll also talk about utilizing everything the Storybook stories writing toolkit has to offer.

Client Solutions Lead (f/m/d)

  • adjoe
  • Playtime Supply
  • Full-time
Every great app out there deserves to be connected with the right users and the right revenue streams. And adjoe will give this to them.

adjoe is a leading mobile ad platform developing cutting-edge advertising and monetization solutions that take its app partners’ business to the next level. Our unique ad unit Playtime has made us one of the fastest-growing ad platforms and top-ranking user acquisition sources for app publishers worldwide (ranked #1 for growth in the AppsFlyer Index). And that’s just the start: We’ve just launched our programmatic in-app platform in order to disrupt the status quo of mobile ad monetization. Again. 

Home to an advanced tech stack, powerful financial backing from Bertelsmann, and a long-term growth mindset, adjoe is part of the AppLike Group ecosystem. A hub of disruption and thought leadership in the app economy, with a driven and dynamic workforce to be reckoned with. 

Be the next tech-driven, ambitious talent to join our growing teams!

Meet Your Team: Customer Service

Big ambitions lead to a big impact – and big revenue numbers. 

Your role will be to lead and build a Global Customer Service Organization that services both our business partners as well as our B2C customers. You will be reporting into the CRO and align with your peers in New Business and Account Management in order to provide the best technical support and service to our publisher partners and advertisers. 
What You Will Do:
  • Manage a team of Technical Account Managers. They ensure the technical onboarding of our newest app partners and a smooth SDK implementation process. 
  • Manage a team of B2C support agents. They are problem solvers for our mobile gamers, who have technical issues related to our partners’ games.
  • Become the link between various stakeholders, teams, and clients to provide solutions to maximize their business goals. 
  • Evolve our service organization based on our geographical expansion as well as service and organizational needs arising from growing business with Enterprise clients. 
  • Ensure a consistent level of knowledge and quality in the execution of your teams.
  • Collaborate with the product and technical teams to ensure our platform meets client needs and provides a positive user experience.
  • Ensure up-to-date product and technical documentation in alignment with our product team. 
  • Be part of an international English-speaking management team dedicated to scaling our adtech platform beyond our hundreds of millions of monthly active users.
  • Who You Are:
  • Minimum 3 years of experience in a leadership role within a service organization, preferably in the (mobile) ad tech industry.
  • Proven track record of building and managing high-performing teams.
  • Strong analytical and problem-solving skills with the ability to work with data –  use SQL to query databases, Excel and other analytics tools
  • Ability to build and maintain strong relationships with clients and colleagues.
  • You thrive in a team environment and are an excellent cross-team collaborator with excellent analytical and communication skills
  • Basic Knowledge of HTML and JavaScript or one basic programming or scripting language 
  • You have a working knowledge of how different technical systems communicate with each other, such as being able to test HTTP REST endpoints and understand what could go wrong when they don’t work.
  • Plus: You are familiar with Java/Kotlin/Swift or have experience building your own apps.
  • Plus: Understanding of the mobile ad tech landscape and current best practices.
  • Heard of Our Perks?
  • Work-Life Package: 2 remote days per week, 30 vacation days, 3 weeks per year of remote work, flexible working hours, dog-friendly kick-ass office in the center of the city.
  • Wealth building: virtual stock options for all our regular employees.
  • Relocation Package: Visa & legal support, relocation bonus, reimbursement of German Classes costs and more.
  • Happy Belly Package: Monthly company lunch, tons of free snacks and drinks, free breakfast & fresh delicious pastries every Monday
  • Physical & Mental Health Package: In-house gym with personal trainer, various classes like Yoga with expert teachers.
  • Activity Package: Regular team and company events, hackathons.
  • Education Package: Opportunities to boost your professional development with courses and trainings directly connected to your career goals 
  • Free of charge access to our EAP (Employee Assistance Program) which is a counseling service designed to support your mental health and well-being.
  • Build our signature product

    See vacancies