# Philosophy

Why another React UI library, and the principles behind its components.

Yet another React UI library? Here's what makes this one different.

## Minimal dependencies

Components depend on React and [Base UI](https://base-ui.com), which handles focus, keyboard
navigation and ARIA. That's it. [Calendar](https://ui.jarv.is/components/calendar.md), [Carousel](https://ui.jarv.is/components/carousel.md)
and the [charts](https://ui.jarv.is/components/bar-chart.md) borrow ideas from
[React DayPicker](https://daypicker.dev), [Embla Carousel](https://www.embla-carousel.com) and
[Recharts](https://recharts.org) respectively, without pulling in code they'd mostly leave unused.

Syntax highlighting is bring-your-own. [Code Block](https://ui.jarv.is/components/code-block.md) and
[Markdown](https://ui.jarv.is/components/markdown.md) render tokens from popular highlighters, such as
[Shiki](https://shiki.style), [TanStack Highlight](https://tanstack.com/highlight/latest) or
[`@pierre/highlights`](https://diffs.com/highlights), rather than choosing one for you.

There are two exceptions:

- [Markdown](https://ui.jarv.is/components/markdown.md) uses [TanStack Markdown](https://tanstack.com/markdown/latest).
  It's small, handles streaming and parses on the server.
- [useShortcut](https://ui.jarv.is/hooks/use-shortcut.md) uses [TanStack Hotkeys](https://tanstack.com/hotkeys).
  Keyboard layouts and platform modifiers are hard to get right, and it's small and headless.

## Modern CSS and browser APIs

If the browser can do something, the components don't reimplement it in JavaScript.

- [Textarea](https://ui.jarv.is/components/textarea.md) grows with `field-sizing: content`.
- [Carousel](https://ui.jarv.is/components/carousel.md) is native scrolling with CSS scroll snap.
- [Card](https://ui.jarv.is/components/card.md) and [Field](https://ui.jarv.is/components/field.md) adapt to their container with container
  queries.
- [Tag Input](https://ui.jarv.is/components/tag-input.md) animates new tags with `@starting-style`.
- [Marquee](https://ui.jarv.is/components/marquee.md) runs on the Web Animations API.
- Dates and numbers are formatted with `Intl`.

Browsers without a feature get a working fallback, such as a textarea that scrolls instead of
growing.

## Server first

Components render on the server and hydrate without mismatches. Those without state, such as
[Button](https://ui.jarv.is/components/button.md), [Table](https://ui.jarv.is/components/table.md) and [Markdown](https://ui.jarv.is/components/markdown.md),
skip `"use client"` and render in a React Server Component, so only the interactive parts ship to
the browser. Nothing reads `window` or storage during render, and `Intl` formatting takes a
`locale` so the server and the browser format the same way.
[Installation](https://ui.jarv.is/docs/installation.md) covers using them from server components.

## Pixel perfect

Every component is checked in light and dark mode, at phone width, and in every state: hover,
pressed, focus, disabled, invalid and pending. Hairline dividers keep their contrast, small
controls get 24px hit areas, focus rings are offset to fit where they sit, and fields stay at 16px
on phones so Safari doesn't zoom in.

If something is a pixel off, I treat it as a bug.
[Open an issue](https://github.com/jakejarvis/jarvis-ui/issues).
