Walking the Line Between Flexibility and Consistency in Component Libraries

Rate this content
Bookmark

Design systems aim to bring consistency to a brand's design and make the UI development productive. Component libraries with well thought API can make this a breeze. But, sometimes an API choice can accidentally overstep and slow the team down! There's a balance there... somewhere. Let's explore some of the problems and possible creative solutions.

FAQ

Primer is a React component library used by GitHub's design system team to create consistent and flexible user interfaces across the platform.

Primer, compared to Shopify's Polaris, offers a balance between flexibility and consistency tailored to GitHub's specific needs. Polaris is highly opinionated with a strict API for predictable results, while Material UI offers extensive flexibility and customization options, suitable for a wide range of applications.

The design of a component library like Primer is influenced by whether it is built for a specific product or is open source, the centralization of design decisions, the maturity of design patterns, and the specific needs and context of the company or product it is intended for.

An action list in GitHub's component library is a configurable component used to display a list of items or actions, where each item can trigger a specific function, and additional properties like icons or dividers can be included.

GitHub ensures flexibility in their component API by allowing for composition over configuration, enabling users to customize components by assembling them from smaller, configurable parts. This approach allows for better adaptation to various use cases while maintaining control over the components.

Slots in GitHub's component design allow for inserting specific types of child components into predefined places within a parent component. This technique ensures that components maintain a consistent structure while allowing for flexibility and customization in the content they display.

GitHub handles the integration of user-defined content through the use of slots, which provide designated areas for custom content while maintaining the structural integrity and design consistency of the component.

Siddharth Kshetrapal
Siddharth Kshetrapal
27 min
17 Jun, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk discusses the comparison between Polaris and Material UI component libraries in terms of consistency and flexibility. It highlights the use of the action list pattern and the customization options available for the action list component. The Talk also emphasizes the introduction of a composite component to improve API flexibility. Additionally, it mentions the importance of finding the right balance between flexibility and consistency and the use of types to enforce specific child components.

1. Introduction to Component Libraries

Short description:

I'm Sid, a maintainer of Primer, the React component library used by GitHub. I'll discuss consistency and flexibility in component libraries by comparing Polaris and Material UI. Polaris provides a descriptive way to create banners with various components and actions. Material UI, on the other hand, uses alerts instead of banners with different severity levels and customizable icons.

So, let's go. I'm Sid. I work on the design system team at GitHub, and I am one of the maintainers of Primer which is the React component library that other teams at GitHub use to build the things that you actually like to use.

So before I start, I kind of want to give a warning. So GitHub is part of Microsoft now, so I have to say this, these opinions are my own and not of my employer yet. I'm trying to change them, I'm working on it. I haven't been there long enough, so give me a while. All right.

So let's talk about consistency and flexibility when it comes to component libraries. So the thing with component libraries is that there's no one true answer, and it really depends on a bunch of context. So when I started, I started looking at other component libraries, so that's big enough. I looked at Polaris, which is Shopify's design system, and I looked at Material UI, which is an open source component library, and this is one component that they have both, like So with Polaris, how you create this banner is you say I want a banner. The status of this banner is critical. And here's the title. And it renders all of that. The icon is there. The cross button is there. All of that is there. And if you want to add an action, you say action object where you say this is the content, and if this is clicked, this is the function that you should call. So very, very descriptive. There's a lot of config here. If I have to build the same thing with Material UI, that looks something like this. I have an alert. They don't call it banner, they call it alert. Doesn't matter. And you give it a severity of error. And then you can pass it an icon. So it could be any icon. It doesn't have to be this icon. You could basically give any icon.

2. Flexibility in Component Libraries

Short description:

Material UI and Polaris have different levels of flexibility in their component APIs. Polaris is highly opinionated with a strict API, leading to consistent outcomes. Material UI, as an open-source library, offers a highly flexible API that depends on the company and context. When considering a component library, factors such as product type, design decision centralization, and pattern maturity determine the appropriate level of flexibility.

It's very flexible. And then it also lets you overwrite some of the CSS. So I can actually change the border color here like I have. And then finally... Ouch. Okay. Finally, if I want some content inside it, there is an alert title. But if I want a button, I can just bring my own button and put it there. And then I'm responsible for this margin that you see here. Okay.

So if you compare these two component APIs, they're creating the same component, but there's a lot of difference between what the API looks like and how much flexibility do you have. And that brings me to the spectrum of flexibility. So, when I think of Shopify as Polaris, I think Polaris is somewhere here, where it's very opinionated, it has an extremely strict API, and that leads to these predictable, consistent outcomes. You can use the alert wherever you want, you get something similar. But of course, it can get a bit rigid and restricting if you're experimenting with it. On the other hand, Material UI is probably all the way here. It's open source, so there is no assumption of context. It has to have a very flexible API, because the Material team cannot really guess what you'll use it for. Which means it kind of depends on your company, your context. And if you're not careful, if you use Material UI as your design system, it can become messy or fragmented or you just need a lot of guardrails in place.

So, when I was looking at Primer React, I was like, okay, where do we lie? Or if you're thinking about it for your component library? The answer of course always is it depends. And it depends on these factors too. Is it built for a specific product or is it open source? Is the design decision centralized because you have a certain design team or do individual products have their own design team? So is it scattered? How old is the product? How mature are the patterns? If you already have established patterns, then it's easier to be more consistent, versus If you're still finding the patterns, then it's better to be more flexible. And I looked at this and I was like, we built for a specific product. We do have a centralized design team. We have established patterns. So GitHub is like super old. So probably somewhere here, like this is how much flexibility we probably should allow. So to showcase this, I looked at this component. This is a, this is kind of a common pattern that you've seen a bunch of places.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Design Systems: Walking the Line Between Flexibility and Consistency
React Advanced Conference 2021React Advanced Conference 2021
47 min
Design Systems: Walking the Line Between Flexibility and Consistency
Top Content
Design systems aim to bring consistency to a brand's design and make the UI development productive. Component libraries with well-thought API can make this a breeze. But, sometimes an API choice can accidentally overstep and slow the team down! There's a balance there... somewhere. Let's explore some of the problems and possible creative solutions.
Towards a Standard Library for JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
Towards a Standard Library for JavaScript Runtimes
Top Content
You can check the slides for James' talk here.
Build a Design System with React and Tailwind CSS
React Summit 2022React Summit 2022
27 min
Build a Design System with React and Tailwind CSS
Top Content
Tailwind CSS, with its utility-first approach is known for speeding up the development process. Combining it with the power of React, let’s see how you can build a custom design system for your project to further speed it up, make it scalable and also easy to maintain.
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
React Summit 2022React Summit 2022
17 min
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
Top Content
There are many ways of authoring components in React, and doing it right might not be that easy, especially when components get more complex. In this talk, you will learn how to build future-proof React components. We will cover two different approaches to building components - Composition and Configuration, to build the same component using both approaches and explore their advantages and disadvantages.
Building Cross-Platform Component Libraries for Web and Native with React
React Advanced Conference 2021React Advanced Conference 2021
21 min
Building Cross-Platform Component Libraries for Web and Native with React
Top Content
Building products for multiple platforms such as web and mobile often requires separate code-based despite most of the components being identical in look and feel. Is there a way where we could use shared React component library on different platforms and save time? In this presentation I'll demonstrate one way to build truly cross-platform component library with a unique approach of using React & React Native in combination.
Find Out If Your Design System Is Better Than Nothing
React Summit 2022React Summit 2022
20 min
Find Out If Your Design System Is Better Than Nothing
Building a design system is not enough. Your dev team has to prefer it over one-off components and third-party libraries. Otherwise, the whole effort is a waste of time. Learn how to use static code analysis to measure if your design system wins over the internal competition and data-driven ways to improve your position.

Workshops on related topic

Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
React Summit 2023React Summit 2023
137 min
Build a Data-Rich Beautiful Dashboard With MUI X's Data Grid and Joy UI
Top Content
WorkshopFree
Sam Sycamore
Siriwat (Jun) Kunaporn
2 authors
Learn how to put MUI’s complete ecosystem to use to build a beautiful and sophisticated project management dashboard in a fraction of the time that it would take to construct it from scratch. In particular, we’ll see how to integrate the MUI X Data Grid with Joy UI, our newest component library and sibling to the industry-standard Material UI.
Table of contents:- Introducing our project and tools- App setup and package installation- Constructing the dashboard- Prototyping, styling, and themes - Joy UI features- Filtering, sorting, editing - Data Grid features- Conclusion, final thoughts, Q&A
Rapid UI Development in React: Harnessing Custom Component Libraries & Design Systems
React Advanced Conference 2022React Advanced Conference 2022
118 min
Rapid UI Development in React: Harnessing Custom Component Libraries & Design Systems
Workshop
Richard Moss
Richard Moss
In this workshop, we'll take a tour through the most effective approaches to building out scalable UI components that enhance developer productivity and happiness :-) This will involve a mix of hands-on exercises and presentations, covering the more advanced aspects of the popular styled-components library, including theming and implementing styled-system utilities via style props for rapid UI development, and culminating in how you can build up your own scalable custom component library.
We will focus on both the ideal scenario---where you work on a greenfield project---along with tactics to incrementally adopt a design system and modern approaches to styling in an existing legacy codebase with some tech debt (often the case!). By the end of the workshop, you should feel that you have an understanding of the tradeoffs between different approaches and feel confident to start implementing the options available to move towards using a design system based component library in the codebase you work on.
Prerequisites: - Familiarity with and experience working on large react codebases- A good understanding of common approaches to styling in React