Nasimunreleased, after 0.12.0
Get started

Installation

Install @nyxon/nasim with its peers, pin React Aria to one copy, add the stylesheet and the font.

Nasim is a package of compiled JavaScript with its 'use client' directives kept, so a Next.js app needs no transpilePackages and a Vite app needs no configuration. It is styled with Tailwind CSS v4.

The package and its peers

npm install @nyxon/nasim

npm 7 and later install the peers with it. pnpm and Yarn do not: add these to the app yourself (pnpm add …, yarn add …). The ranges are those of the published package:

  • react ^19.2.0
  • react-dom ^19.2.0
  • tailwindcss ^4.3.0
  • @heroui/styles 3.2.8
  • react-aria-components 1.22.1
  • @internationalized/string ^3.2.10
  • @internationalized/date ^3.12.4
  • react-hook-form ^7.81.0
  • zod ^4.6.5

react-hook-form and zod are required even in an app without forms, because the forms are exported from the main entry; a page that renders no form does not bundle them.

One copy of React Aria

Every copy of React Aria has its own locale context. With two copies in the app, parts built on one would ignore the Persian locale the other carries (the date picker's month and year buttons, for one). So pin the set Nasim is built with in the app's package.json. overrides is npm's name for it; pnpm reads pnpm.overrides, Yarn resolutions:

"overrides": {
  "react-aria": "3.53.1",
  "react-stately": "3.51.0",
  "react-aria-components": "1.22.1",
  "@internationalized/string": "3.2.10"
}

Then npm ls react-aria-components @internationalized/string must show each package once.

The stylesheet

The stylesheet that imports Tailwind adds one line. It brings HeroUI's styles, Nasim's tokens and font rules, and an @source for Nasim's files, which Tailwind would otherwise skip in node_modules:

@import 'tailwindcss';
@import '@nyxon/nasim/styles.css';

It works with @tailwindcss/postcss, @tailwindcss/vite and Next's Turbopack (with PostCSS or the @tailwindcss/turbopack loader).

The font

Nasim names Vazirmatn and never downloads it: the app loads it. Use the vazirmatn package's Vazirmatn[wght].woff2, the cut that has Latin letters and digits. The non-Latin cut (Vazirmatn-NL) needs a Latin face in front of it, or Latin text falls back to Tahoma. When the app exposes the font as --font-vazirmatn (Next's next/font), Nasim uses that variable; otherwise it asks for the family Vazirmatn, which the app declares with an @font-face.

npm install vazirmatn

A Next.js app

In an App Router app (create-next-app), install Nasim, the font and Tailwind's PostCSS plugin:

npm install @nyxon/nasim vazirmatn
npm install -D tailwindcss @tailwindcss/postcss

Then the files to touch:

postcss.config.mjs
export default { plugins: { '@tailwindcss/postcss': {} } };
app/globals.css
@import 'tailwindcss';
@import '@nyxon/nasim/styles.css';
app/fonts.ts
import localFont from 'next/font/local';

export const vazirmatn = localFont({
  src: '../node_modules/vazirmatn/fonts/webfonts/Vazirmatn[wght].woff2',
  variable: '--font-vazirmatn',
  weight: '100 900',
  display: 'swap',
});
app/providers.tsx
'use client';

import {
  NasimProvider,
  type NasimNavigateOptions,
  type ThemeMode,
} from '@nyxon/nasim';
import { useRouter } from 'next/navigation';
import { type ReactNode, useCallback } from 'react';

// initialMode: the saved theme as the server read it (Setup, «The first paint and the theme»).
export function Providers({
  children,
  initialMode,
}: {
  children: ReactNode;
  initialMode?: ThemeMode;
}) {
  const router = useRouter();
  // Stable, so React Aria does not rebuild every link on each render.
  const navigate = useCallback(
    (href: string, options?: NasimNavigateOptions) =>
      options?.replace
        ? router.replace(href, { scroll: options.scroll })
        : router.push(href, { scroll: options?.scroll }),
    [router],
  );
  return (
    <NasimProvider navigate={navigate} initialMode={initialMode}>
      {children}
    </NasimProvider>
  );
}
app/layout.tsx
import type { ReactNode } from 'react';
import { vazirmatn } from './fonts';
import './globals.css';
import { Providers } from './providers';

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html
      lang="fa"
      dir="rtl"
      className={vazirmatn.variable}
      suppressHydrationWarning
    >
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

suppressHydrationWarning is there because the theme controller writes its class and data-theme on <html> after hydration. A page may now import parts from @nyxon/nasim; Setup says which ones a Server Component can render.

A Vite app

In a React app made with Vite (npm create vite@latest and its React template), install Nasim, the font, and Tailwind's and React's Vite plugins:

npm install @nyxon/nasim vazirmatn
npm install -D tailwindcss @tailwindcss/vite @vitejs/plugin-react

Then the files to touch:

vite.config.ts
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

export default defineConfig({ plugins: [react(), tailwindcss()] });
index.html
<!doctype html>
<html lang="fa" dir="rtl">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

The font file is copied from node_modules/vazirmatn/fonts/webfonts/ to public/fonts/, and declared under the family name Nasim asks for:

src/index.css
@import 'tailwindcss';
@import '@nyxon/nasim/styles.css';

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn[wght].woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
src/main.tsx
import { NasimProvider } from '@nyxon/nasim';
import { createRoot } from 'react-dom/client';
import { App } from './App';
import './index.css';

createRoot(document.getElementById('root')!).render(
  <NasimProvider>
    <App />
  </NasimProvider>,
);

With a router, hand NasimProvider its navigate (and useHref, for a router with a base path), as Setup shows. Vite ignores 'use client'.

On this page