Design Harmony: Themeable UI Components Module in Nuxt.js for Multiple Products

Design Harmony: Themeable UI Components Module in Nuxt.js for Multiple Products

Category

Design System

Case Study From

Bukalapak

01

The Story

A UI library can help developers have more fun and save time when building products because of its pre-built components that can be combined to create well-designed layouts. However, when working with multiple products, it is crucial to customize the UI library's theme to ensure each product has a unique style. I encountered this challenge while working in Bukapapak, where they used the same UI library for their subsidiaries. In such cases, it is necessary to configure the UI library to provide customizable themes that cater to specific needs and preferences.

Color token
Component theme

02

The Challenge

How might we simplify the customization process for a component's style with minimal configuration?

03

Implementation

The Concept

The concept of the themeable UI component module is to centralize the style of every component by utilizing the power of Tailwind. I prefer Tailwind because it makes implementing various design elements such as color, typography, size, and many others effortless. Additionally, with Tailwind, you can make minor tweaks to the component's style at the consumer level by overwriting the existing styles. This gives consumers greater control over their components and ensures they are tailored to their needs.

The concept of themeable UI components module

The Process to Create Module

Bukalapak's UI Component library was built using Vue 3, but the styling of each component is not optimized with Tailwind. To provide better customization options for the theme, it is imperative to rewrite the components using Tailwind and migrate them into the Nuxt module. This will enhance the capability to customize the theme and provide a better developer experience.

Define Tokens

Centralized component styling with tokens is a useful approach for creating themeable components. By defining tokens, we can easily change the theme of components by updating the tailwind config. This method simplifies theming and ensures consistency across all components.

This is an example of the preset for tokens that can be used on Tailwind configuration.

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    // Color (Output class: bg-primary, text-primary, border-primary, & etc)
    colors: {
      white: '#ffffff',
      black: '#000000',
      primary: {
        DEFAULT: '#E31E52',
        hover: '#cf0a3e',
        focus: '#bb002a',
        active: '#b10020',
        content: '#ffffff',
      },
      secondary: {
        DEFAULT: '#F2F2F2',
        hover: '#dedede',
        focus: '#cacaca',
        active: '#c0c0c0',
        content: '#3d3d3d',
      },
      neutral: {
        DEFAULT: '#3B373D',
        hover: '#272329',
        focus: '#130f15',
        active: '#09050b',
        content: '#ffffff',
      },
      accent: {
        DEFAULT: '#2B4AC7',
        hover: '#1736b3',
        focus: '#03229f',
        active: '#001895',
        content: '#ffffff',
      },
      success: {
        DEFAULT: '#B7EDB7',
        hover: '#a3d9a3',
        focus: '#8fc58f',
        active: '#85bb85',
        content: '#01271C',
      },
      info: {
        DEFAULT: '#D6E4FE',
        hover: '#c2d0ea',
        focus: '#aebcd6',
        active: '#a4b2cc',
        content: '#0E1A4C',
      },
      warning: {
        DEFAULT: '#FCDBB6',
        hover: '#e8c7a2',
        focus: '#d4b38e',
        active: '#caa984',
        content: '#4D2309',
      },
      error: {
        DEFAULT: '#FFD4D6',
        hover: '#ebc0c2',
        focus: '#d7acae',
        active: '#cda2a4',
        content: '#7A0602',
      },
    },
  },
}
Design Component

The UI Component module uses atoms-level components, offering consumers greater flexibility to customize styles than molecules-level components. This is because atoms-level components are more finely-grained and can be easily modified without disrupting other UI parts. With this approach, consumers can build more tailored and dynamic interfaces while maintaining consistency throughout the design.

This is an example component designed and implemented in Tailwind as a style:

<template>
  <div :class="capsuleClass">
    <!-- @slot Use slot for content -->
    <slot></slot>
  </div>
</template>

<script setup lang="ts">
import { computed, PropType } from 'vue'
import { CapsuleVariant, CapsuleSize } from '../../constants/components/bl-capsule'

const props = defineProps({
  /**
   * Style variation to give additional meaning
   */
  variation: {
    type: String as PropType<CapsuleVariant>,
    default: 'primary',
  },
  /**
   * The sizes of the capsule
   */
  size: {
    type: String as PropType<CapsuleSize>,
    default: 'medium',
  },
})

const capsuleClass = computed(() => {
  const className = 'bl-capsule'
  return [className, `${className}--${props.size}`, `${className}--${props.variation}`]
})

defineExpose({ capsuleClass })
</script>

<style lang="scss">
.bl-capsule {
  @apply bg-primary
  inline-flex
  items-center
  justify-center
  rounded-btn
  px-[8px]
  text-primary-content
  font-medium
  h-[20px]
  text-caption-12
  font-body;

  &--secondary {
    @apply bg-secondary text-secondary-content;
  }

  &--success {
    @apply bg-success text-secondary-content;
  }

  &--warning {
    @apply bg-warning text-warning-content;
  }

  &--info {
    @apply bg-info text-info-content;
  }

  &--error {
    @apply bg-error text-error-content;
  }

  &--small {
    @apply px-[4px] text-caption-10;
  }

  &--large {
    @apply py-[4px] h-[initial] text-body-16;
  }
}
</style>
Nuxt Module

The next step is to develop a UI module for Nuxt, a relatively simple process. We can follow the official guide provided by Nuxt for this purpose. However, ensuring that all components and tailwind configurations are correctly set up before publishing the module is crucial. This will ensure the module functions smoothly and delivers a seamless user experience.

Configuring the module for UI components is a straightforward process. All you need to do is use the function addComponentsDir to synchronize the components directory with the module. This will ensure the components are readily available and easily integrated into your Nuxt app. This is an example of the configuration for the UI component module in Bukalapak.

import { defineNuxtModule, addComponentsDir, createResolver } from '@nuxt/kit'

export interface ModuleOptions {
  preset?: string
}

export default defineNuxtModule<ModuleOptions>({
  meta: {
    name: '@bukalapak/bazaar-ui',
    configKey: 'bazaar',
    compatibility: {
      nuxt: '^3.5.0',
    },
  },
  defaults: {
    preset: '',
  },
  setup(moduleOptions, nuxt) {
    const { resolve } = createResolver(import.meta.url)
    // Standard components
    addComponentsDir({ path: resolve('./components') })
  },
})

Usage

Integrating the UI component module into the Nuxt app is a breeze. Start by installing the necessary dependencies, and then configure the nuxt.config.ts. Finally, customize the tailwind.config.ts file to your desired specifications. This straightforward process will allow you to implement UI components into the Nuxt app easily.

To enable the use of the UI component module in the Nuxt app, it must be added to the nuxt.config.ts file:

export default defineNuxtConfig({
  modules: ['@bukalapak/bazaar-ui'],
})

Configure the tailwind.config.ts to use a preset theme from the UI component module. It is recommended to use the @nuxtjs/tailwindcss module for better integration with Nuxt.

/** @type {import("tailwindcss").Config} */
module.exports = {
  presets: [require('@bukalapak/bazaar-ui/preset')],
  content: ['**/@bukalapak/bazaar-ui/dist/components/**/*.vue'],
  theme: {},
}

To customize the theme, simply add a token value for color or other settings. Then, refer the token key by UI components preset theme.

/** @type {import("tailwindcss").Config} */
module.exports = {
  presets: [require('@bukalapak/bazaar-ui/preset')],
  content: ['**/@bukalapak/bazaar-ui/dist/components/**/*.vue'],
  theme: {
    colors: {
      primary: {
        DEFAULT: '#59a624',
        hover: '#46841d',
        focus: '#356516',
        active: '#356516',
        content: '#ffffff',
      },
    },
  },
}

Lesson Learn

  • When designing a component, it's important to consider how its styling can be adjusted to the consumer's needs. Designing the component on an atom level is recommended to make this process as easy as possible, avoiding the complexity style. This approach allows for more granular adjustments to the component's style, resulting in a more flexible and adaptable end product.
  • Mapping the token for the tailwind config can be a challenging task. This is because it requires identifying the style for the entire component and ensuring that the token has been implemented correctly. It is important to pay close attention to detail and carefully analyze the code to make sure everything is working.

Share:

Let’s Connect

Have a product to build, a role to talk about, or just a good conversation about shipping? My inbox is open.

[email protected]

Location

Jakarta, Indonesia

© 2026 Nurul Furqon