An open API service indexing awesome lists of open source software.

https://github.com/soybeanjs/soybean-ui

A powerful and elegant Vue 3 component system with headless primitives and ready-to-use styled wrappers.
https://github.com/soybeanjs/soybean-ui

radix-vue shadcn-ui uikit unocss vue3

Last synced: about 1 month ago
JSON representation

A powerful and elegant Vue 3 component system with headless primitives and ready-to-use styled wrappers.

Awesome Lists containing this project

README

          



Logo

# SoybeanUI

English | [δΈ­ζ–‡](./README.zh-CN.md)

[![license](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
[![github stars](https://img.shields.io/github/stars/soybeanjs/soybean-ui)](https://github.com/soybeanjs/soybean-ui)

SoybeanUI is an elegant, modern, accessible and high-quality UI component library with shadcn-like design for Vue 3, built on top of a robust headless foundation. It provides a comprehensive set of accessible, customizable, and performant components.

## πŸ“š Architecture

SoybeanUI is built on a strict **two-layer separation** model:

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ @soybeanjs/ui (src/) β”‚
β”‚ S-prefixed components (SButton…) β”‚
β”‚ UnoCSS classes Β· tailwind-variants β”‚
β”‚ provideXUi(ui) ──────────────────┐ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”˜
β”‚ style injection
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
β”‚ @soybeanjs/headless (headless/) β”‚
β”‚ Logic Β· State Β· A11y Β· Keyboard nav β”‚
β”‚ useUiContext() reads injected classes β”‚
β”‚ Zero styles β€” works with any CSS β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Packages

| Package | Role | Components |
| ----------------------- | --------------------------------- | --------------------------------- |
| **@soybeanjs/headless** | Logic, state, a11y. Zero styles. | 95 component dirs, 25 composables |
| **@soybeanjs/ui** | Styled wrappers. UnoCSS + `tv()`. | 91 `S`-prefixed components |

**Data flow is strictly one-way**: `headless` β†’ `src`. The styled layer never imports from headless's internals β€” it injects style tokens via `provideXUi(computedUi)` which headless components read through `useUiContext()`.

Some multi-slot headless components also expose `Compact` aggregators, such as `AccordionCompact` and `TableCompact`. They keep item iteration and default content/icon composition inside headless, while the UI layer stays focused on styling and prop forwarding.

Current Compact-style coverage also includes flows such as card, date-field, dialog, editable, hover-card, layout, navigation-menu, pagination, popover, and stepper, when those structures are stable enough to live in headless.

### Style Injection

Every multi-slot headless component exposes a `provide{Name}Ui` function. The styled wrapper computes classes using `tailwind-variants` and injects them:

```ts
// In the styled wrapper (src/)
const ui = computed(() =>
mergeVariants(
accordionVariants({ size: props.size }), // tv() output
props.ui, // user overrides
{ root: props.class } // class prop
)
);
provideAccordionUi(ui); // headless reads this via useAccordionUi()
```

### Theme System

- **`ThemeColor`** β€” 8 semantic colors: `primary` Β· `destructive` Β· `success` Β· `warning` Β· `info` Β· `carbon` Β· `secondary` Β· `accent`
- **`ThemeSize`** β€” 6 sizes: `xs` Β· `sm` Β· `md` Β· `lg` Β· `xl` Β· `2xl` (base 16px at `md`)
- **`ConfigProvider`** β€” sets global `dir`, `locale`, `nonce`, and default `tooltip` config for the entire component tree, including RTL layout switching
- **`cn()`** β€” Tailwind-aware class merge (`clsx` + `tailwind-merge`), used for conflict-free class composition

### Locale Support

`ConfigProvider` supports the following locale bundles:

| Code | Language |
| ------- | ------------------- |
| `zh-CN` | Simplified Chinese |
| `zh-TW` | Traditional Chinese |
| `en` | English |
| `ar` | Arabic |
| `ja` | Japanese |
| `ko` | Korean |
| `de` | German |
| `fr` | French |
| `es` | Spanish |
| `pt-BR` | Portuguese (Brazil) |
| `ru` | Russian |
| `tr` | Turkish |
| `id` | Indonesian |

Only `en` and `zh-CN` are pre-registered by default. `registerLocale` supports two registration styles:

- Pass a `LocaleRegistry` object. Built-in locale files from `@soybeanjs/headless/locale/{code}` already export this shape, including `dir` metadata.
- Pass a locale key plus `LocaleMessages` for a lightweight custom locale.

The shorthand `registerLocale(key, messages)` form uses the key as the locale name and falls back to `ltr`. Use the object form when you need explicit metadata such as `rtl`.

```ts
import { en, registerLocale } from '@soybeanjs/headless/locale';
import type { LocaleMessages } from '@soybeanjs/headless/locale';
import ar from '@soybeanjs/headless/locale/ar';

registerLocale(ar);

const customMessages: LocaleMessages = {
...en.messages,
pagination: {
...en.messages.pagination,
nextPage: 'Next β†’',
prevPage: '← Prev'
}
};

registerLocale('custom', customMessages);
```

### Package Exports

**@soybeanjs/headless** ships fine-grained sub-paths:

```ts
import { AccordionRoot } from '@soybeanjs/headless'; // all components
import { useControllableState } from '@soybeanjs/headless/composables'; // 25 composables
import { transformPropsToContext } from '@soybeanjs/headless/shared'; // pure TS utils
import { createMonth } from '@soybeanjs/headless/date'; // shared date helpers
import * as Headless from '@soybeanjs/headless/namespaced'; // namespace object
import type { AccordionUiSlot } from '@soybeanjs/headless/accordion'; // per-component
import type { UiClass } from '@soybeanjs/headless/types'; // shared type surface
```

**@soybeanjs/ui** exports:

```ts
import { SButton, SAccordion } from '@soybeanjs/ui'; // all components
import '@soybeanjs/ui/styles.css'; // pre-built UnoCSS stylesheet
// Also: @soybeanjs/ui/nuxt Β· @soybeanjs/ui/resolver
```

## πŸ›  Development Workflow

If you contribute new public components, exports, or API descriptions, keep generated surfaces in sync through the official scripts instead of editing generated files by hand.

```bash
pnpm sui headless # sync headless component names and namespaced exports
pnpm sui ui # sync ui component names
pnpm sui api # regenerate docs api json and locale baseline data
pnpm sui api-locales # refresh api locale template data only
pnpm sui changelog # regenerate docs changelog json and locale baseline data
pnpm sui api-translate -- --locale zh-CN
pnpm sui changelog-translate -- --locale zh-CN
```

The docs site now renders component docs through `UsageCode`, `PlaygroundGallery`, and `ComponentApi`. Component detail pages and `/releases` also read generated changelog data from `docs/src/generated/changelog/` and `docs/src/generated/changelog-locales/`.

Public API or demo delivery changes should keep docs, playground examples, and generated API data aligned. Changelog mapping, release presentation, and changelog locale template changes should keep generated changelog data aligned as well.

## πŸ“¦ Installation

### Using the Styled UI Library (Recommended)

If you want ready-to-use components with a modern design:

```bash
pnpm add @soybeanjs/ui
```

### Using the Headless Library

If you want to build your own design system from scratch:

```bash
pnpm add @soybeanjs/headless
```

## πŸš€ Usage

### @soybeanjs/ui

1. **Import Styles**

Import the CSS file in your main entry file (e.g., `main.ts`):

```ts
import '@soybeanjs/ui/styles.css';
```

2. **Global Registration (Optional)**

You can register components globally or import them on demand.

3. **On-demand Import (Recommended)**

We recommend using `unplugin-vue-components` for auto-importing components.

```ts
// vite.config.ts
import Components from 'unplugin-vue-components/vite';
import UiResolver from '@soybeanjs/ui/resolver';

export default defineConfig({
plugins: [
Components({
resolvers: [UiResolver()]
})
]
});
```

4. **Nuxt Module**

```ts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@soybeanjs/ui/nuxt']
});
```

### @soybeanjs/headless

The headless components provide the functionality without the styles.

For data-driven multi-slot patterns, prefer the exported `Compact` variant when it exists. It is the headless entry point for opinionated composition, while the regular parts remain available for fully manual assembly.

```vue

import { AccordionRoot, AccordionItem, AccordionTrigger, AccordionContent } from '@soybeanjs/headless';



Is it accessible?
Yes. It adheres to the WAI-ARIA design pattern.

```

## ✨ Features

- **Accessible**: Follows WAI-ARIA patterns for roles, focus management, and keyboard navigation.
- **RTL ready**: Switch supported components between LTR and RTL layouts with `ConfigProvider`.
- **Headless-first**: Logic and styles are fully separated β€” use `@soybeanjs/headless` alone to build any design system.
- **Type Safe**: Written in strict TypeScript. All props, emits, slots, and context values are typed.
- **Customizable at every level**: Override individual slot classes via the `ui` prop, or swap the entire style layer.
- **Lightweight & Tree-shakable**: Import only the components you use. Each component is individually tree-shakable.
- **Nuxt ready**: First-class Nuxt module with auto-registration (`@soybeanjs/ui/nuxt`).
- **unplugin support**: Auto-import resolver for `unplugin-vue-components` (`@soybeanjs/ui/resolver`).

## πŸ’ Credits

- [reka-ui](https://github.com/unovue/reka-ui)
- [oku-ui](https://github.com/oku-ui/primitives)
- [shadcn-vue](https://github.com/unovue/shadcn-vue)
- [shadcn/ui](https://github.com/shadcn/ui)
- [nuxt-ui](https://github.com/nuxt/ui)
- [unocss](https://github.com/unocss/unocss)