Files
tansy-ui/apps/docs/src/GettingStarted.mdx
T
thekhalidsha 9255b255a6
CI / check (push) Successful in 3m9s
Release / publish (push) Failing after 1m22s
Package Tansy UI as @openkhalix/tansy-ui in a monorepo (v0.4.0)
Restructure the repo into npm workspaces so the component kit publishes as
its own package, like MUI and shadcn/ui:

- packages/ui: @openkhalix/tansy-ui (published), with components, stories,
  tests, tokens and the library build
- packages/brand: private logo and catalogue data shared by both apps
- apps/site: the landing page
- apps/docs: Storybook

The package:
- MIT licence (copyright OpenKhalix)
- per-component ES modules and type declarations
- "use client" on component modules so they import into Next.js Server
  Components; helpers stay server-safe
- tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps
  without Tailwind
- lucide-react 1.x, whose types compile against current React 19 types

The apps resolve the package through a "source" export condition, so they
hot-reload component edits, while outside users get dist/.

scripts/test-package.mjs packs the package and installs the tarball into
Vite + Tailwind (strict types), plain React and Next.js apps; each must
build and render correctly. Gitea workflows run CI on push and publish to
npm when a vX.Y.Z tag matching the package version is pushed.
2026-09-29 09:24:03 +05:30

90 lines
3.3 KiB
Plaintext

import { Meta, Source } from '@storybook/addon-docs/blocks'
import { DocHero } from './DocBlocks'
<Meta title="Introduction/Getting started" />
<DocHero title="Getting started">
Install one package, add one line of CSS, and every component is ready to use in any React 19 app, with or without Tailwind.
</DocHero>
## Requirements
| Dependency | Version | Why |
|---|---|---|
| React and React DOM | 19 | Peer dependency. Components take `ref` as a normal prop |
| Tailwind CSS | 4, optional | With Tailwind, your build generates the utilities; without it, use the prebuilt `styles.css` |
| `@base-ui/react` | 1.8+ | Accessible behaviour: focus management, keyboard navigation, popups. Installed with the package |
| `lucide-react` | 1.x | The icons components draw themselves (chevrons, close, status icons). Installed with the package |
| `clsx` + `tailwind-merge` | 2 and 3 | `cn()` merges class names so your `className` always wins |
## 1. Install
<Source language="bash" code={`npm install @openkhalix/tansy-ui`} />
## 2. Add the styles
**With Tailwind CSS v4** (recommended). Import the tokens after Tailwind, and let Tailwind scan the package for the classes it uses:
<Source
language="css"
code={`@import "tailwindcss";
@import "@openkhalix/tansy-ui/tokens.css";
@source "../node_modules/@openkhalix/tansy-ui/dist";`}
/>
**Without Tailwind.** Import the prebuilt stylesheet once. It includes the tokens, the utilities the components use, and a modern CSS reset the components rely on:
<Source language="ts" code={`import '@openkhalix/tansy-ui/styles.css'`} />
## 3. Render components
<Source
language="tsx"
code={`import { Mail } from 'lucide-react'
import { Button, FeaturedInput, Select, Switch } from '@openkhalix/tansy-ui'
export function InviteForm() {
return (
<form className="grid max-w-sm gap-5">
<FeaturedInput label="Work email" type="email" startIcon={<Mail />} required />
<Select
label="Team"
options={[
{ value: 'design', label: 'Design' },
{ value: 'engineering', label: 'Engineering' },
]}
/>
<Switch label="Send a welcome email" defaultChecked />
<Button type="submit">Send invite</Button>
</form>
)
}`}
/>
Every form component takes the same field props, `label`, `description`, `error` and `required`, and links them to the control for screen readers. Values work controlled (`value` and `onValueChange`) or uncontrolled (`defaultValue`).
## Next.js
Components are marked `"use client"`, so you can import them straight into Server Components. Helpers like `cn` and `applyPalette` stay server-safe.
## 4. Dark mode
Add the `dark` class to `<html>`. The surface, border and text tokens switch, and every component and popup follows:
<Source language="tsx" code={`document.documentElement.classList.toggle('dark', prefersDark)`} />
## 5. Pick a palette (optional)
Classic Blue is the default. Apply another palette to any element; everything inside it re-themes, including popups when you apply it to `<html>`:
<Source
language="tsx"
code={`import { applyPalette } from '@openkhalix/tansy-ui'
applyPalette(document.documentElement, 'emerald')`}
/>
## Fonts
The Tansy brand uses Schibsted Grotesk for headings, Instrument Sans for text and JetBrains Mono for code, all from Google Fonts. Components inherit your app's font, so these are optional.