Lab - Add a Subcategory Listing in Catalyst
This lab focuses on enhancing your storefront’s category pages with a dynamic subcategory listing. You will learn to efficiently fetch and display data using a custom GraphQL query, streamed rendering, and reusable React components. You will also explore styling and customization by creating and applying new Tailwind CSS variables, giving you full control over the look and feel of your new feature.
In this lab, you will:
- Add a subcategory listing feature to your storefront’s category pages
- Practice writing GraphQL queries, streaming data with Stream, and building React components
- Create new Tailwind CSS variables and utilize them in your presentation
Prerequisites
- Node.js 24 or later
- A Catalyst project set up locally, as completed in the previous exercise
- Category and product data as described below
Catalog Data Prerequisites
You’ll be implementing the same essential feature as the subcategory listing you added in Stencil, so you’ll need the same catalog data structure. As a reminder, this includes:
- At least one category accessible from the main menu and containing at least three enabled subcategories
- Enabled products assigned to all subcategories mentioned above
Remember that your Catalyst storefront is separate from your Stencil storefront, with its own category tree, so you’ll need to take the same steps to configure categories appropriately. Also, note that any products originally assigned only to your Stencil storefront channel are not automatically assigned to your Catalyst channel, so either add your original products to the Catalyst channel or assign your Catalyst sample products to the new categories.
See the “Add a Subcategory Listing in Stencil” lab for more details on setting up your catalog data.
Setup
If your dev server is not currently running, start it by running the following command in the project’s root directory:
The Subcategory Listing
In the Catalyst implementation of the subcategory listing, you’ll take advantage of existing Soul components and existing style variables to keep a consistent look and feel with the rest of the theme. In addition, you’ll have full control over the GraphQL query used to load the subcategory data, so this version will include images.

Step 1: Add the Subcategory List Logic
In this section, you’ll implement the appropriate GraphQL to load a category’s subcategories.
- Create the file components/subcategory-list/component-data.ts and add the following content.
This defines a GraphQL query for site.categoryTree, selecting the immediate children of the root category identified by $categoryId, then utilizes the API client to make this request in getSubcategories.
This API client request follows the typical Catalyst pattern, including passing in a logged-in customer’s unique token.
- Open the main category route file, app/[locale]/(default)/(faceted)/category/[slug]/page.tsx.
- Add imports for your query function and for the ProductListSkeleton component near the top of the file, alongside the existing
@/vibesand~/imports.
The category page already imports Stream and Streamable, since it uses them to load the product list, filters, and pagination. You’ll use the same tools for your subcategory data.
- Locate the Category component definition and add a streamable for your subcategory data immediately before the component’s returned JSX.
The categoryId and customerAccessToken values are already defined earlier in the component, where the page uses them for its other data requests.
Notice that this code doesn’t await the result of getSubcategories. Streamable.from wraps the request so that it runs without blocking the rendering of the page. Recall from the Performance Checklist that wrapping components that rely on dynamic data in Stream or Suspense keeps slower content from holding up the rest of the page. Awaiting the subcategory query here would delay the entire page, including the header and the Makeswift content, until the query completes.
- Locate the ProductsListSection component in the returned JSX and wrap it in a Stream that renders a placeholder when subcategories are found.
Stream accepts the streamable as its value and a function as its child. Once the subcategory request resolves, Stream calls that function with the resulting subcategories array. The function renders the placeholder if the array contains any items and falls back to the usual ProductsListSection otherwise. Leave all of the existing props on ProductsListSection as they are.
Until the request resolves, Stream displays its fallback. ProductListSkeleton is the same loading state the framework uses for the product grid, so shoppers see a consistent placeholder no matter which content eventually appears.
Because the subcategory list replaces only the product grid, the rest of the page is unaffected. The Makeswift Slot components above and below the grid and the CategoryViewed analytics event at the end of the JSX still render on categories that have subcategories.
- Browse to a category with subcategories and verify that your placeholder is displayed instead of a product list.
- Browse to a category without subcategories and verify that the product list still displays as usual.
Step 2: Add the Subcategory List Component
- Create the file components/subcategory-list/index.tsx and add the following initial content.
This defines some initial imports and a React component that accepts props including a title and a subcategories array. All React components in Catalyst utilize TypeScript for predictability and type safety. Notice that the return type of the getSubcategories function you previously created is used to inform TypeScript what the subcategories prop data should look like.
getSubcategories is an asynchronous function that initially returns a Promise. The type expression above uses Awaited to specify the data ultimately returned from that Promise. This matches the value that Stream passes to its render function on the category page.
- Replace the return statement with JSX to display the category name and loop through the subcategories.
Compared with the mark-up included in the Stencil component template, this is more verbose. However, this is primarily due to the inclusion of Tailwind CSS utility classes directly in the mark-up. No separate CSS will be necessary to provide the styling of your component.
The design principles of Tailwind CSS keep styling closely coupled with components, providing the ability to modify components with greater confidence of avoiding unintentional side effects in other areas of the theme. Using this model, efficient styling often involves smart use of reusable components, as well as style variables used throughout the theme. The heading in your JSX includes an example of a reference to a value in the theme’s common color palette (“contrast-400”) with the class text-contrast-400.
The component code currently loops through the subcategories but renders only an empty element for each. Let’s fill this section out next.
- Replace the empty <div> within the loop with a Card for each subcategory.
This addition takes advantage of the built-in Card component from the Soul library, allowing this implementation to do the UI heavy lifting. All that’s needed is providing a link target, image information, and title for the card.
Now that your subcategory component is fully fleshed out, it’s time to replace your initial placeholder with it.
- Open the file app/[locale]/(default)/(faceted)/category/[slug]/page.tsx and add an import for your component near the top of the file, alongside your getSubcategories import.
- Locate the placeholder text inside the Stream render function and replace it with your component.
- Browse to the category page again and verify that the full content of the subcategory listing is displayed.
Step 3: Create Style Variables
In this final step, you’ll practice creating configurable variables to control aspects of the styling for your custom component.
New color variables for a scenario like this are probably inadvisable in a real-world application. Catalyst comes with an extensive pre-defined palette of color variables, from primary to accent to contrast colors, designed to keep the color scheme cohesive throughout the theme. For any given component, you should first consider whether values from the existing palette are appropriate. The variables you’ll create here are simply a convenient example of customizable CSS and Tailwind config.
In this case, you’ve deferred most of the structure of your component to the built-in Card, so your theming options are limited to what this component exposes. While you could implement your own UI instead, in order to create more customizable theme values, Card does include styling controlled by CSS variables, such as —card-light-text, which controls the default color of the card titles.
You’ll start by defining a value for this CSS variable on a wrapping element directly in your component.
- Open the file components/subcategory-list/index.tsx.
- Locate the <div> element immediately above your loop through subcategories and add a style prop with a value for the CSS variable.
With this structure in place, you’ll now add CSS variables specific to your subcategory list component in the appropriate global file, then use the appropriate values from these variables instead of the hard-coded values.
- Open the file globals.css and add variables to the :root block as follows.
Notice that these values are bare HSL triplets (hue, saturation, and lightness) rather than complete color values like hsl(96 25% 68%). This matches the convention Catalyst uses for its own theme colors, such as —primary and —contrast-400 in the same :root block. Each consumer of the variable wraps it in hsl(). Because the variable holds only the color channels, a consumer can also add an alpha value when needed (for example, hsl(var(--subcategory-list-heading) / 50%)).
- Open components/subcategory-list/index.tsx and update your style property.
You now have something of a CSS variable chain, with a more specific variable (the one for the subcategory listing) being passed as the value of a less specific variable (the one for the Card component in this particular context). Since —subcategory-list-light-text holds a bare HSL triplet, it’s wrapped in hsl() here to produce a complete color value for —card-light-text.
- Browse to the category page again and verify that the new default style value takes effect.
One of the CSS variables you created - subcategory-list-heading - hasn’t yet been utilized. For this value, you’ll practice expanding the Tailwind color palette and making use of a normal Tailwind utility class.
- Open the file tailwind.config.js.
- Locate the colors object under theme.extend and add the new value.
This utilizes your CSS variable to supply the color subcategoryListHeading, which can now be used in various classes that use color names (such as bg-subcategoryListHeading or text-subcategoryListHeading). Compare it with the existing primary entry directly below: both wrap a bare HSL triplet in hsl().
- Open the file components/subcategory-list/index.tsx, locate the <h1> element, and replace “text-contrast-400” with “text-subcategoryListHeading”.
- Browse to the category page again and verify that the new default style value takes effect for the page heading.
Taking It Further
Recall that in the Stencil subcategory listing lab, you were encouraged to explore the use of additional config files to make your new theme settings editable by admin users in the Theme Styles interface.
The CSS variables you’ve created here can similarly be exposed as customizable global style properties in the Makeswift visual editor.
The general steps involved with this process are:
- Remove the hard-coded CSS variables from globals.css.
- Add a component group for your property controls with a schema object in lib/makeswift/components/site-theme/components.
- Register your group in lib/makeswift/components/site-theme/components/index.ts.
- Implement appropriate Makeswift controls for each property in the components file.
- Ensure that the name of your Makeswift schema object (subcategoryList) and the keys for each property (for example, lightText) match the CSS variables you are using in your component (for example, —subcategory-list-light-text).
The full details are outside the scope of our focus in this course. Continue your Catalyst journey with Catalyst Core and Makeswift Core to learn more about the dynamic component that powers global style properties.