@leanspec/ui-components
v0.2.23
Published
Framework-agnostic, tree-shakeable UI components for LeanSpec
Maintainers
Readme
@leanspec/ui-components
Framework-agnostic, tree-shakeable UI components for LeanSpec.
Installation
npm install @leanspec/ui-components
# or
pnpm add @leanspec/ui-componentsUsage
import { StatusBadge, PriorityBadge, SpecCard, EmptyState, SearchInput } from '@leanspec/ui-components';
import '@leanspec/ui-components/styles.css';
function MyComponent() {
return (
<div>
<SearchInput placeholder="Search specs..." onSearch={(q) => console.log(q)} />
<StatusBadge status="in-progress" />
<PriorityBadge priority="high" />
<SpecCard
spec={{
specNumber: 185,
specName: 'ui-components',
title: 'UI Components',
status: 'in-progress',
priority: 'high',
tags: ['ui', 'components'],
updatedAt: new Date().toISOString(),
}}
/>
</div>
);
}Components
Spec Components
StatusBadge- Display spec status with iconPriorityBadge- Display spec priority with iconSpecCard- Compact spec card for listsSpecMetadata- Metadata display card with all spec detailsTagBadge- Display a single tagTagList- Display multiple tags with truncation
Project Components
ProjectAvatar- Avatar with initials and color from project nameProjectCard- Project card with avatar, description, stats, and tagsProjectSwitcher- Project switcher dropdown (framework-agnostic with callbacks)ProjectDialog- Project creation/edit dialog (framework-agnostic with callbacks)
Stats Components
StatsCard- Single stat card with icon and trend indicatorStatsOverview- Grid of stats cards for project overviewProgressBar- Horizontal progress bar with variants
Search & Filter Components
SearchInput- Search input with keyboard shortcut hintFilterSelect- Dropdown filter componentSearchResults- Search results grid display
Graph Components
SpecDependencyGraph- Interactive dependency graph using ReactFlow (framework-agnostic with callbacks)
Navigation Components
ThemeToggle- Light/dark theme toggle buttonBackToTop- Floating scroll-to-top button
UI Components (shadcn/ui)
Accordion- Collapsible content sectionsAlert- Feedback messages with variantsAvatar- Avatar with image and fallback (with size variants)Badge- Base badge component with variantsButton- Button with variants (default, destructive, outline, secondary, ghost, link)ButtonGroup- Group of related buttonsCard- Card container with header, content, footerCarousel- Slideable content carouselCollapsible- Expandable/collapsible contentCommand- Command palette componentDialog- Modal dialog componentDropdownMenu- Dropdown menu with nested itemsHoverCard- Content shown on hoverInput- Form input fieldInputGroup- Input with prefix/suffix addonsPopover- Floating content containerProgress- Progress bar indicatorScrollArea- Custom scrollable containerSelect- Dropdown select component (with size variants)Separator- Horizontal or vertical dividerSkeleton- Loading placeholderSwitch- Toggle switchTabs- Tabbed content navigationTextarea- Multi-line text inputTooltip- Contextual information on hover
AI Elements (Chat/Agent UI)
All 48 AI Elements components for building AI chat interfaces:
Agent,AgentTools,AgentTool- AI agent displayArtifact- Code/content artifactsAttachments- File attachmentsAudioPlayer- Audio playbackCanvas- Drawing canvasChainOfThought,Reasoning- AI reasoning displayCodeBlock- Syntax-highlighted code with copyConfirmation- User confirmation dialogsConversation,ConversationContent- Chat containerMessage,MessageContent,MessageResponse- Chat messagesLoader,Shimmer- Loading indicatorsPromptInput,PromptInputTextarea- Chat inputTerminal- Terminal output displayTool,ToolExecution- Tool call visualization- And many more...
Layout Components
EmptyState- Empty state placeholder with icon, title, description, actionSpecListSkeleton- Loading skeleton for spec listSpecDetailSkeleton- Loading skeleton for spec detailStatsCardSkeleton- Loading skeleton for stats cardKanbanBoardSkeleton- Loading skeleton for kanban boardProjectCardSkeleton- Loading skeleton for project cardSidebarSkeleton- Loading skeleton for sidebarContentSkeleton- Generic content skeleton
Hooks
useLocalStorage- Persist state in localStorageuseDebounce- Debounce a valueuseDebouncedCallback- Debounce a callback functionuseTheme- Theme state management with localStorage persistence
Utilities
cn- Merge Tailwind CSS classesformatDate- Format date in readable formatformatDateTime- Format date with timeformatRelativeTime- Format relative time (e.g., "2 days ago")formatDuration- Format duration between datesgetColorFromString- Generate consistent color from stringgetContrastColor- Get contrasting text color for backgroundgetInitials- Get initials from name stringPROJECT_COLORS- Predefined color palette
Types
All spec-related TypeScript types are exported:
Spec,LightweightSpec,SidebarSpecSpecStatus,SpecPriorityStatsResult,DependencyGraph, etc.
Advanced Usage Examples
Using SpecDependencyGraph
import { SpecDependencyGraph } from '@leanspec/ui-components';
function MyDependencyView({ relationships, specNumber, specTitle }) {
return (
<div style={{ height: '600px' }}>
<SpecDependencyGraph
relationships={relationships}
specNumber={specNumber}
specTitle={specTitle}
onNodeClick={(specId) => {
// Handle navigation to spec
router.push(`/specs/${specId}`);
}}
labels={{
title: 'Dependencies',
subtitle: 'Click to navigate',
}}
/>
</div>
);
}Using ProjectSwitcher
import { ProjectSwitcher } from '@leanspec/ui-components';
function MyProjectSwitcher({ currentProject, projects }) {
return (
<ProjectSwitcher
currentProject={currentProject}
projects={projects}
onProjectSelect={(projectId) => {
// Handle project switching
router.push(`/projects/${projectId}`);
}}
onAddProject={() => {
// Open project creation dialog
setShowDialog(true);
}}
onManageProjects={() => {
// Navigate to project management
router.push('/projects');
}}
/>
);
}Using ProjectDialog
import { ProjectDialog } from '@leanspec/ui-components';
function MyProjectDialog({ open, onOpenChange }) {
return (
<ProjectDialog
open={open}
onOpenChange={onOpenChange}
onSubmit={async (path) => {
// Handle project creation
await createProject(path);
onOpenChange(false);
}}
onBrowseFolder={async () => {
// Show native file picker (Tauri/Electron)
const result = await window.__TAURI__.dialog.open({
directory: true,
});
return result;
}}
/>
);
}Using SearchResults
import { SearchResults } from '@leanspec/ui-components';
function MySearch({ query, results, isSearching }) {
return (
<SearchResults
query={query}
results={results}
isSearching={isSearching}
onSpecClick={(specId) => {
router.push(`/specs/${specId}`);
}}
/>
);
}Development
# Install dependencies
pnpm install
# Build the library
pnpm build
# Run tests
pnpm testLicense
MIT
