Developer documentation
This component library lives as a combination of NextJS compatible server and client React components. They are written in a combination of typescript and javascript. Typescript is used primarily where types are important, ie, while data fetching and validating. Javascript is preferred when the component needs to just display something without any logic. The only reason for using Javascript in these cases is to reduce the amount of overhead in creating a single display component.
Low-level Components vs. CMS aware components
Low level components are components that do not carry opinons about data structures. Often the sections of this design system that are setup under foundations and patterns fall under this low level component library.
CMS aware components on the other hand are tightly coupled to how Agility CMS supplies its data on query.
Low level Component Library
There are a number of low-level components that are stored in the
@boystown/components
library (under packages/components
). These components
are unopinionated about where they are used and set some basic style and design
principles (colors, variants, etc.). These components can be used in any React
project regardless of the underlying data structures.
Adding a component is as simple as creating a directory for the component, with
an index.js|ts
file that exports the component. It can then be referenced
using the following code
import { NamedComponent } from '@boystown/components/<component_dir>';
CMS-aware Components
All CMS-aware components are stored in the @boystown/website
project (under
apps/website/src/components
). These components use the main component library
@boystown/components
as building blocks but are aware that the props they are
receiving may be coming from Agility CMS.
Hooks and Providers
The codebase contains a number of common hooks and providers used by multiple components, including providers to calculate screen size, providers to handle gestures and search. Please familiarize yourself by looking through the /packages/hooks
directory.
Data fetch helpers
A number of helpers exist in the codebase to fetch data. This pattern is highly encouraged as it allows us to use the same fetch patterns universally (on the client and server).
Common Developer workflows
The following outline the recommended workflow for creating new features.
Creating new CMS components
- Review the component visually and document its
props
with a designer on the same call. Verbalize how you would like to build this component with its controls. - Check if the component has the common patterns of
headings
content
orbuttons
in it. - Check if the component has child lists (think of a component like a Carousel). Make sure you are following appropriate naming conventions.
- Spend an hour playing with components in the CMS to see if you can achieve the new component with what exists - or even achieve 90% of what you need without new code. Don't be afraid to ask why we need a new component.
- Model the component in the CMS, ensure your model takes into account any common patterns.
- Identify the lower level components needed to create your main component. Often this would be headings, actions, taxonomies and more. Make sure you are familiar with the patterns section of this guide.
- Create a CMS component that simply echoes the props out. Make sure your data is flowing correctly before moving to the front end. Ensure you place a
docblock
with@params
documenting your props in the code. - Create your final component. Re review the props in the code.
- Work with a designer to build a page / section for this new component
Creating new data sources
- Review a couple of the files in
/packages/lib
to understand common patterns for data fetching. - If you need to combine more than one data source, think about the tasks and promises that have to be executed.
- Think about sensible defaults for the data sources and the types of data
- Write it in typescript only
- Check your fetch calls both on the client and the server. If they do not work on the client, consider moving the fetch call into a proxy behind an
api
route.