Skip to main content

Installation

Get started with Spar in minutes. This guide covers installation, setup, and basic configuration for a React project.

Requirements​

Before installing Spar, ensure the project meets these requirements:

  • Node.js: >=22.18.0
  • React: >=19.0.0
  • TypeScript: >=5.0.0 (recommended)
  • pnpm: >=10.0.0 (if using pnpm)

Package Manager​

Spar is available on npm and can be installed with any package manager.

npm install @turkish-technology/spar

Framework Guides​

Spar works seamlessly with modern React frameworks.

React​

Import components into React files and start developing:

src/App.tsx
import { Button } from '@turkish-technology/spar';
import './App.css';

function App() {
return (
<Button className="my-button" onClick={() => console.log('Clicked!')}>
Click me
</Button>
);
}

Next.js​

Spar is compatible with Next.js 14+ and the App Router.

All published Spar entrypoints are client-marked modules, so importing a Spar component from an App Router page or layout creates a client boundary automatically:

import * as Accordion from '@turkish-technology/spar/accordion';
import * as Breadcrumb from '@turkish-technology/spar/breadcrumb';
import * as Dialog from '@turkish-technology/spar/dialog';
import { Button } from '@turkish-technology/spar/button';

App Router Page Example​

app/page.tsx
import * as Breadcrumb from '@turkish-technology/spar/breadcrumb';
import { Button } from '@turkish-technology/spar/button';

export default function Home() {
return (
<main>
<Breadcrumb.Root>
<Breadcrumb.List>
<Breadcrumb.Item>
<Breadcrumb.Link href="/">Home</Breadcrumb.Link>
</Breadcrumb.Item>
<Breadcrumb.Separator />
<Breadcrumb.Item>
<Breadcrumb.Page>Dashboard</Breadcrumb.Page>
</Breadcrumb.Item>
</Breadcrumb.List>
</Breadcrumb.Root>
<h1>Welcome to Spar + Next.js</h1>
<Button>Click me</Button>
</main>
);
}

Client Component Example​

For components that require state (controlled mode), wrap them in a Client Component:

app/components/AccordionSection.tsx
'use client';

import { useState } from 'react';
import * as Accordion from '@turkish-technology/spar/accordion';

export function AccordionSection() {
const [value, setValue] = useState<string | string[]>('');

return (
<Accordion.Root value={value} onValueChange={setValue}>
<Accordion.Item value="faq-1">
<Accordion.Header>
<Accordion.Trigger>What is Spar?</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content>
Spar is a headless React component library.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);
}

Available Sub-path Imports​

Import PathComponents
@turkish-technology/spar/accordionRoot, Item, Header, Trigger, Content
@turkish-technology/spar/breadcrumbRoot, List, Item, Link, Page, Separator
@turkish-technology/spar/buttonButton
@turkish-technology/spar/checkboxCheckbox
@turkish-technology/spar/collapsibleRoot, Trigger, Content
@turkish-technology/spar/dialogRoot, Trigger, Overlay, Content, Title, Description, Close
@turkish-technology/spar/dropdown-menuRoot, Trigger, Content, Item, Separator, Label, Group, Arrow
@turkish-technology/spar/inputRoot, Field, Label, Description, ErrorMessage
@turkish-technology/spar/labelLabel
@turkish-technology/spar/popoverRoot, Trigger, Content, Arrow, Close
@turkish-technology/spar/radioRoot, Group, Item
@turkish-technology/spar/selectRoot, Trigger, Value, Content, Item, Group, Label, ItemText, Separator, Arrow
@turkish-technology/spar/switchSwitch, useSwitch
@turkish-technology/spar/tabsRoot, List, Trigger, Content
@turkish-technology/spar/tooltipProvider, Root, Trigger, Content, Arrow

Next Steps​

After installing Spar:

  1. Explore Components: Check out the Components page to see all available components
  2. Learn Patterns: Read component documentation for usage examples
  3. Style Components: Choose a preferred styling solution and customize
  4. Build Accessible UIs: All components come with built-in accessibility

Getting Help​

Need help with installation or setup?