adjoe Engineers’ Blog
 /  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.

Technical Account Manager (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).

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. 

Our US HQ launched in the beginning of 2023. Since its inception the US office has played a critical role in adjoe’s massive year-over-year growth, and we’ve continued to grow our investment in the US as a key source of future growth. Be the next tech-driven, ambitious talent to join our growing US team!

Meet Your Team: Playtime Supply

Playtime Supply is building a unique software solution for app and game developers that puts users’ needs first. Instead of traditional monetization mechanisms, Playtime builds an engaging ad experience in which users can play and earn rewards for various new mobile games in Playtime. To predict which mobile game will best suit a user, the team has introduced ML algorithms.

To build this rewarded experience, adjoe’s backend reliably handles more than 200 million users – remaining stable despite impressive growth in the user base. And imagine this: adjoe’s Golang event consumer applications assign rewards equivalent to 700 months of time spent in Playtime every day to its users. 

The software depends on two main components.
1) adjoe’s Android mobile SDK – written in a combination of Java and Kotlin – which can be bundled by developers in their apps. 
2) The team’s highly scalable Golang backend, which is hosted on AWS and is otherwise responsible for developing a modern React (TypeScript) dashboard that provides adjoe’s clients and Business team colleagues with fast-loading insights.
What You Will Do:
  • Manage the technical onboarding of our newest app partners and ensure a smooth implementation process. 
  • Become the link between various stakeholders, teams, and clients to provide clients with solutions to maximize their business goals. 
  • Assist the supply business team by providing them with data-driven insights into how they can reach their KPIs based on the analysis, aggregation, and visualization of adjoe’s data. 
  • Put on your detective hat and support publishers with issues they may face when integrating adjoe, ranging all the way from basic issues in their mobile app code to fine-tuning configurations.
  • Proactively identify integration issues that publishers may face and work with the product team to create solutions for these issues.
  • Contribute to maintaining easy-to-understand documentation of the integration process.
  • Be part of an international English-speaking team dedicated to scaling our adtech platform beyond our hundreds of millions of monthly active users.
  • Who You Are:
  • You have a skill for communicating complex technical information to business teams and partners. 
  • You are able to turn data into clear and actionable insights and document these in understandable spreadsheets or wiki pages to drive business growth. 
  • You thrive in a team environment and are an excellent cross-team communicator.
  • You have excellent analytical and communication skills and can use SQL to query databases.
  • Basic Knowledge of HTML and JavaScript & you know you don’t eat cookies in IT.
  • 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 or have experience building your own apps.
  • 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