Getting Started

Webpack & Bundlers

Import BIMA UI into any bundler — webpack, Vite, Rollup, or Parcel — and wire it into React or Vue. Or pull in only the tokens for a Tailwind theme.

Install

Add the package to your project first. It is a single dependency-free package, so there is nothing else to install.

npm install @milvikbima/ui
# or
yarn add @milvikbima/ui
# or
pnpm add @milvikbima/ui

Importing the CSS

There are two equivalent ways to pull in the stylesheet. From a CSS or SCSS file, use an @import:

/* In your global stylesheet (styles.css / app.scss) */
@import "@milvikbima/ui/dist/bima.css";

From a JavaScript or TypeScript entry file, import it as a side-effecting module. Modern bundlers (webpack, Vite, Rollup, Parcel) understand CSS imports and will extract the stylesheet into your build:

// main.js / main.ts — your application entry
import '@milvikbima/ui/dist/bima.css';
import '@milvikbima/ui/dist/bima.js';   // optional — only for interactive components

The package sets "sideEffects": ["*.css"], so bundlers will not tree-shake away your CSS import. You can safely import the stylesheet from your entry file and trust it survives a production build.

How the JS initialises

The script self-initialises on DOMContentLoaded — it scans the document once and wires up every component it finds (modal, accordion, tabs, dropdown, toast, carousel, custom select, offcanvas, tooltip, scrollspy). It also exposes a global window.BIMA for imperative control.

When you render markup after that first scan — which is the norm in React, Vue, or any SPA — call BIMA.init(root) to wire up the newly inserted subtree:

// After inserting new markup into the DOM:
BIMA.init(containerElement);   // re-scans just that subtree

// BIMA.init() with no argument re-scans the whole document.
BIMA.init();

BIMA.init() is idempotent per element, but only acts on markup present at call time. In component frameworks, call it after the DOM updates (e.g. in a React effect or a Vue onMounted/nextTick) so the freshly rendered nodes get wired up.

React

Import the CSS (and optionally the JS) once in your application root, then use the bima-* classes via className. When a component renders interactive BIMA markup dynamically, call BIMA.init against its DOM node in an effect:

// main.jsx — import once at the app entry
import '@milvikbima/ui/dist/bima.css';
import '@milvikbima/ui/dist/bima.js';
import { createRoot } from 'react-dom/client';
import App from './App';

createRoot(document.getElementById('root')).render(<App />);
// A component that renders an interactive BIMA accordion
import { useEffect, useRef } from 'react';

export default function FaqList({ items }) {
  const ref = useRef(null);

  // Re-scan this subtree after it renders so data-bima-* wires up.
  useEffect(() => {
    if (ref.current) window.BIMA.init(ref.current);
  }, [items]);

  return (
    <div ref={ref} className="bima-accordion">
      {items.map((item) => (
        <div className="bima-accordion__item" key={item.id}>
          <button
            className="bima-accordion__btn"
            data-bima-toggle="collapse"
            data-bima-target={`#${item.id}`}
          >
            {item.question}
          </button>
          <div className="bima-accordion__panel" id={item.id}>
            <div className="bima-accordion__body">{item.answer}</div>
          </div>
        </div>
      ))}
    </div>
  );
}

Static (non-interactive) BIMA markup — buttons, cards, badges, the grid — needs no JavaScript at all; just apply the classes:

Rendered
<button className="bima-btn bima-btn--primary">Primary</button>
<button className="bima-btn bima-btn--secondary">Secondary</button>
<span className="bima-badge bima-badge--success">Rendered</span>

Vue

The pattern mirrors React. Import the assets in your entry file, use class in templates, and re-scan dynamically rendered markup with a template ref inside onMounted (after nextTick if the markup depends on reactive data):

// main.js — Vue app entry
import '@milvikbima/ui/dist/bima.css';
import '@milvikbima/ui/dist/bima.js';
import { createApp } from 'vue';
import App from './App.vue';

createApp(App).mount('#app');
<!-- FaqList.vue -->
<script setup>
import { ref, onMounted, nextTick } from 'vue';

const root = ref(null);

onMounted(async () => {
  await nextTick();
  if (root.value) window.BIMA.init(root.value);
});
</script>

<template>
  <div ref="root" class="bima-accordion">
    <div class="bima-accordion__item" v-for="item in items" :key="item.id">
      <button class="bima-accordion__btn"
              data-bima-toggle="collapse"
              :data-bima-target="`#${item.id}`">
        {{ item.question }}
      </button>
      <div class="bima-accordion__panel" :id="item.id">
        <div class="bima-accordion__body">{{ item.answer }}</div>
      </div>
    </div>
  </div>
</template>

Tokens-only for Tailwind

If you build on Tailwind, Ant Design, or MUI you usually don't want BIMA's component CSS — you want its values. Import only the tokens entry, which resolves to tokens/variables.css and defines every --bima-* custom property and nothing else:

/* In your Tailwind entry CSS, before @tailwind */
@import "@milvikbima/ui/tokens";

@tailwind base;
@tailwind components;
@tailwind utilities;

Then reference the tokens from theme.extend so Tailwind generates utilities backed by the BIMA values:

// tailwind.config.js
export default {
  theme: {
    extend: {
      colors: {
        navy:    'var(--bima-navy)',
        blue:    'var(--bima-blue)',
        sky:     'var(--bima-sky)',
        success: 'var(--bima-success)',
        warning: 'var(--bima-warning)',
        error:   'var(--bima-error)',
      },
      fontFamily: {
        display: 'var(--bima-font-display)',
        body:    'var(--bima-font-body)',
      },
      borderRadius: {
        bima:  'var(--bima-radius-bima)',
        pill:  'var(--bima-radius-pill)',
      },
      boxShadow: {
        card: 'var(--bima-shadow-card)',
      },
    },
  },
};

Importing the tokens stylesheet declares the variables on :root at runtime; the Tailwind config just references them with var(--bima-*). That means a single token override (or dark-mode flip) instantly re-themes every Tailwind utility built on it. See CSS Variables for how overriding works.

Next steps