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

https://github.com/kaihotz/kai-ui

A design system composed out of custom react components, supporting dark and light mode
https://github.com/kaihotz/kai-ui

css-variables dark-mode dark-theme design-system react react-components scss-styles storybook

Last synced: 2 months ago
JSON representation

A design system composed out of custom react components, supporting dark and light mode

Awesome Lists containing this project

README

          

# kai-ui

A modern, TypeScript-based React component library built with Vite, featuring a comprehensive collection of customizable UI components with built-in theming support.

[![Version](https://img.shields.io/badge/version-5.1.0-blue.svg)](https://github.com/KaiHotz/kai-ui)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ๐Ÿš€ Features

- **๐ŸŽจ Comprehensive Component Library** - 30+ production-ready components including forms, charts, tables, and navigation
- **๐ŸŒ“ Theme System** - Built-in light/dark mode support with customizable themes
- **๐Ÿ“ฆ Tree-shakeable** - Optimized bundle size with ES modules
- **๐Ÿ”ท TypeScript First** - Full TypeScript support with comprehensive type definitions
- **โšก Modern Stack** - Built with Vite, React 19, and SWC for optimal performance
- **๐ŸŽญ Storybook Integration** - Interactive component documentation and development
- **โœ… Fully Tested** - Comprehensive test coverage with Vitest and React Testing Library
- **โ™ฟ Accessible** - WCAG compliant components
- **๐ŸŽฏ SCSS Styling** - Flexible styling with SCSS and BEM methodology

## ๐Ÿ“ฆ Installation

```bash
npm install kai-ui
# or
yarn add kai-ui
```

### Peer Dependencies

This library requires the following peer dependencies:

```bash
npm install react react-dom @floating-ui/react react-hook-form react-icons react-tooltip react-transition-group ag-grid-community ag-grid-react clsx date-fns highcharts highcharts-react-official highcharts-custom-events lodash yup
```

## ๐Ÿ—๏ธ Architecture

### Project Structure

```
kai-ui/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ components/ # UI components
โ”‚ โ”‚ โ”œโ”€โ”€ Accordion/
โ”‚ โ”‚ โ”œโ”€โ”€ Avatar/
โ”‚ โ”‚ โ”œโ”€โ”€ Button/
โ”‚ โ”‚ โ”œโ”€โ”€ Charts/
โ”‚ โ”‚ โ”œโ”€โ”€ DataTable/
โ”‚ โ”‚ โ”œโ”€โ”€ Forms/
โ”‚ โ”‚ โ””โ”€โ”€ ...
โ”‚ โ”œโ”€โ”€ hooks/ # Custom React hooks
โ”‚ โ”œโ”€โ”€ providers/ # Context providers (Theme, etc.)
โ”‚ โ”œโ”€โ”€ styles/ # Global styles and theming
โ”‚ โ””โ”€โ”€ utils/ # Utility functions
```

### Component Architecture

Each component follows a consistent structure:

- **Component File** (`*.tsx`) - Main component implementation
- **Styles** (`*.scss`) - Component-specific styles using BEM methodology
- **Stories** (`*.stories.tsx`) - Storybook documentation
- **Tests** (`*.test.tsx`) - Unit tests with Vitest
- **Types** - TypeScript interfaces exported for consumers
- **Index** (`index.ts`) - Clean exports

### Design Principles

1. **Composition over Configuration** - Components are designed to be composed together
2. **Prop-driven** - Behavior controlled through clear, typed props
3. **Accessibility First** - ARIA attributes and keyboard navigation built-in
4. **Theme Integration** - All components respect the global theme system
5. **Performance Optimized** - Minimal re-renders and optimized bundle size

## ๐ŸŽฏ Usage

### Basic Setup

```tsx
import { ThemeProvider } from 'kai-ui';
import 'kai-ui/styles.css';

function App() {
return {/* Your app content */};
}
```

### Using Components

```tsx
import { Button, Input, Modal, DataTable } from 'kai-ui';

function MyComponent() {
return (


console.log('clicked')}>
Click Me



);
}
```

### Theme System

The library includes a built-in theme system with light and dark modes:

```tsx
import { useTheme } from 'kai-ui';

function ThemeToggle() {
const { theme, isDark, setTheme } = useTheme();

return setTheme(isDark ? 'light' : 'dark')}>Current: {theme};
}
```

Theme preferences are automatically:

- Persisted to localStorage
- Synchronized with system preferences
- Applied via CSS custom properties

### Custom Hooks

The library provides several custom hooks:

```tsx
import { useClickOutside, useCloseByEscape, useCountdown, useEventListener, useTheme } from 'kai-ui';

function MyComponent() {
const ref = useClickOutside(() => console.log('Clicked outside'));
useCloseByEscape(() => console.log('Escape pressed'));

return

Content
;
}
```

## ๐Ÿ“š Component Categories

### Layout & Navigation

- **Accordion** - Collapsible content sections
- **Drawer** - Side panel with slide-in animation
- **Modal** - Dialog overlays
- **SideNav** - Sidebar navigation
- **Tabs** - Tabbed interfaces
- **Stepper** - Multi-step workflows

### Forms & Inputs

- **Button** - Multiple variants (primary, secondary, tertiary, ghost, danger)
- **Checkbox** - Single and grouped checkboxes
- **ColorPicker** - Color selection with presets
- **DatePicker** - Date and range selection
- **Input** - Text input with validation
- **Radio** - Radio button groups
- **Select** - Dropdown selection
- **Switch** - Toggle switches
- **Textarea** - Multi-line text input
- **Forms** - Complete form components with validation

### Data Display

- **Avatar** - User avatars with initials fallback
- **DataRows** - Key-value data display
- **DataTable** - Advanced data grid (powered by AG Grid)
- **HeatMapCalendar** - Calendar-based heatmaps
- **Score** - Rating display
- **Label** - Status badges and labels

### Charts & Visualization

- **Chart** - Base chart component
- **DateTimeSeries** - Time-based line charts
- **PieChart** - Circular data visualization
- **SpiderWebChart** - Radar/spider charts

### Feedback & Overlays

- **Backdrop** - Modal backdrops
- **Hint** - Tooltips and hints
- **Spinner** - Loading indicators
- **ContextMenu** - Right-click menus
- **MenuButton** - Dropdown action menus

### Navigation

- **Pagination** - Page navigation controls
- **PseudoLink** - Link-styled buttons

## ๐Ÿ› ๏ธ Development

### Prerequisites

- Node.js >= 22
- Yarn or npm

### Scripts

```bash
# Install dependencies
yarn install

# Start Storybook development server
yarn storybook

# Build the library
yarn build

# Run tests
yarn test

# Run linting
yarn lint

# Fix linting issues
yarn lint:fix

# Type checking
yarn check-types

# CI pipeline (lint + test)
yarn ci
```

### Building

The library is built using Vite with the following optimizations:

- **TypeScript declarations** generated with `vite-plugin-dts`
- **Tree-shaking** enabled with ES modules
- **Code splitting** for optimal chunk sizes
- **SVG as React components** with `vite-plugin-svgr`
- **Minification** with Terser
- **Peer dependencies** externalized to reduce bundle size

Build output structure:

```
dist/
โ”œโ”€โ”€ index.js # Main entry point
โ”œโ”€โ”€ index.d.ts # Type definitions
โ”œโ”€โ”€ styles.css # Bundled styles
โ””โ”€โ”€ src/ # Individual component types
```

## ๐Ÿงช Testing

Tests are written using:

- **Vitest** - Fast unit test runner
- **React Testing Library** - Component testing utilities
- **@testing-library/jest-dom** - Custom matchers

Run tests:

```bash
yarn test # Watch mode
yarn ci # Single run (CI)
```

## ๐Ÿ“– Storybook

Interactive component documentation is available via Storybook:

```bash
yarn storybook
```

Access at http://localhost:6006

Build static Storybook:

```bash
yarn storybook:build
```

## ๐ŸŽจ Styling

### SCSS Architecture

The library uses SCSS with a BEM-inspired methodology:

```scss
// Global styles
@import 'kai-ui/dist/styles.css';

// Component-specific
.ui-btn {
&--primary {
/* ... */
}
&--secondary {
/* ... */
}
&--small {
/* ... */
}
}
```

### CSS Custom Properties

Theming is implemented using CSS custom properties:

```scss
:root {
--color-primary: #007bff;
--color-background: #ffffff;
--font-family-base: 'Inter', sans-serif;
// ... more variables
}

[data-theme='dark'] {
--color-background: #1a1a1a;
// ... dark theme overrides
}
```

### Custom Fonts

The library includes custom font faces. Ensure fonts are properly loaded:

```tsx
import 'kai-ui/dist/styles.css'; // Includes font faces
```

## ๐Ÿค Contributing

Contributions are welcome! Please follow these guidelines:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Write tests for new functionality
4. Ensure all tests pass (`yarn ci`)
5. Commit changes (`git commit -m 'Add amazing feature'`)
6. Push to branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request

### Code Style

- Follow existing patterns and conventions
- Use TypeScript for all new code
- Write tests for components and hooks
- Document props with JSDoc comments
- Create Storybook stories for visual components

## ๐Ÿ“„ License

MIT ยฉ Kai Hotz

## ๐Ÿ”— Links

- [GitHub Repository](https://github.com/KaiHotz/kai-ui)
- [NPM Package](https://npm.pkg.github.com/KaiHotz)
- [Issues](https://github.com/KaiHotz/kai-ui/issues)

## ๐Ÿ’ก Utilities

The library provides utility functions for common tasks:

- `capitalizeWords()` - String formatting
- `cleanObj()` - Object sanitization
- `getInitials()` - Extract initials from names
- `highlightText()` - Text highlighting
- `isEditableElement()` - DOM element checks
- `getCSSVariable()` - Theme variable access
- And more...

## ๐ŸŒŸ Acknowledgments

Built with:

- [React](https://react.dev/)
- [TypeScript](https://www.typescriptlang.org/)
- [Vite](https://vitejs.dev/)
- [Storybook](https://storybook.js.org/)
- [AG Grid](https://www.ag-grid.com/)
- [Highcharts](https://www.highcharts.com/)
- [date-fns](https://date-fns.org/)