--- title: UI Primitives sidebarTitle: Primitives --- Spacedrive's UI is built on a set of reusable primitives from `@sd/ui`. These components provide consistent styling and behavior across the application. ## Design Principles ### Composition Over Configuration Primitives are simple, composable building blocks rather than complex configured components. ```tsx // Complex configuration // Composable primitives
{data.map(item => ( ))}
Name
{item.name}
``` ### Semantic Color Usage All primitives use semantic color tokens, never raw Tailwind colors. ```tsx // Raw colors
// Semantic colors
``` ### Consistent Patterns Common patterns are standardized across primitives: **Card Pattern:** ```tsx
{/* Content */}
``` **List Item Pattern:** ```tsx
{/* Content */}
``` **Table Pattern:** ```tsx
Column
Data
``` ## Core Primitives ### Button Versatile button component with multiple variants and sizes. ```tsx import { Button } from '@sd/ui'; ``` **Variants:** - `default` - Transparent with border, hover/active states - `gray` - App button background with hover/focus states - `accent` - Accent blue background with white text - `subtle` - Transparent border, subtle hover - `outline` - Sidebar line border style - `dotted` - Dashed border for add/create actions - `colored` - Custom colored backgrounds (pass bg color class) - `bare` - No styling whatsoever **Sizes:** - `xs` - Extra small (px-1.5 py-0.5, text-xs) - `sm` - Small (px-2 py-0.5, text-sm) - default - `md` - Medium (px-2.5 py-1.5, text-sm) - `lg` - Large (px-3 py-1.5, text-md) - `icon` - Square icon button (!p-1) **Best Practice:** Wrap icons and text in flex containers to prevent stacking: ```tsx ``` ### Input Form input with semantic styling and size variants. ```tsx import { Input, Label } from "@sd/ui";
; ``` **Variants:** - `default` - Standard input with border and background - `transparent` - Transparent background, no border on focus **Sizes:** - `xs` - 25px height - `sm` - 30px height (default) - `md` - 36px height - `lg` - 42px height - `xl` - 48px height **Props:** - `error` - Shows error state (red border/ring) - `icon` - Icon component or React node - `iconPosition` - `'left'` | `'right'` (default: `'left'`) - `right` - React node to display on the right side - `inputElementClassName` - Additional classes for the input element itself **Additional Components:** - `SearchInput` - Input with MagnifyingGlass icon pre-configured - `PasswordInput` - Input with eye icon toggle for show/hide password - `TextArea` - Multi-line text input with same styling system - `Label` - Semantic label component with slug prop for htmlFor ### Form Components React Hook Form integration with automatic validation display. ```tsx import { Form, InputField, z } from "@sd/ui/src/forms"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ username: z.string().min(3), email: z.string().email(), }); function MyForm() { const form = useForm({ resolver: zodResolver(schema), }); return (
); } ``` ### Switch Toggle switch for boolean settings. ```tsx import { Switch } from "@sd/ui"; const [enabled, setEnabled] = useState(false);
Enable Feature
Description
; ``` ### ShinyToggle Animated toggle component for switching between multiple options with a smooth glowing indicator. ```tsx import { ShinyToggle } from "@sd/ui"; const [view, setView] = useState<"grid" | "list">("grid"); ; ``` **Features:** - Smooth animated indicator using Framer Motion - Gradient background with glow effect - Optional count badges - Type-safe with generics - Fully accessible **Props:** - `value` - Current selected value (generic type T) - `onChange` - Callback when selection changes - `options` - Array of `{ value: T, label: ReactNode, count?: number }` - `className` - Additional classes for the container ### DropdownMenu Context menu and dropdown with Radix UI. ```tsx import { DropdownMenu } from "@sd/ui"; Open Menu}> ; ``` ## Glassmorphism Effect Spacedrive's signature glassmorphism effect combines backdrop blur, transparency, and gradient borders. ```tsx
{/* Top gradient border */}
{/* Bottom gradient border */}
{/* Content with noise texture */}
Content
``` **Noise Variants:** - `noise` - Base noise texture - `noise-faded` - Faded intensity - `noise-sm` - Small grain size ## Progress Bars Consistent progress bar pattern for resource usage. ```tsx
Storage 45/100 GB
``` **Color by type:** - Storage: `bg-accent` (blue) - AI/Compute: `bg-purple-500` - Bandwidth: `bg-green-500` - Progress: `bg-accent` - Success: `bg-green-400` ## Status Badges Standard status badge pattern. ```tsx const STATUS_CONFIG = { running: { color: "text-green-400", bg: "bg-green-500/20" }, stopped: { color: "text-gray-400", bg: "bg-gray-500/20" }, error: { color: "text-red-400", bg: "bg-red-500/20" }, };
Running
; ``` ## Empty States Pattern for when lists/grids are empty. ```tsx

No items yet

Description of what would appear here

``` ## Gradients ### Background Gradients ```tsx
Icon background
Gradient text
``` ### Border Gradients ```tsx
``` ## Typography Scale Consistent text sizing across the app. ```tsx

Page Title

Section Title

Description text

Helper text ``` **Scale:** - `text-xs` (12px) - Helper text, labels - `text-sm` (14px) - Body text, descriptions - `text-base` (16px) - Default body - `text-lg` (18px) - Subheadings - `text-xl` (20px) - Section titles - `text-2xl` (24px) - Card titles - `text-3xl` (30px) - Page titles ## Icons Use Phosphor Icons with consistent sizing and weights. ```tsx import { Icon } from '@phosphor-icons/react'; // Buttons, small UI // Medium UI elements // Large icons // Headers // Empty states ``` **Weight Guidelines:** - `regular` - Default, inactive states - `fill` - Active states, buttons, emphasis - `bold` - Strong emphasis ## Spacing Scale Consistent spacing using Tailwind's scale. **Common patterns:** - Card padding: `p-6` - Button padding: `px-3 py-1.5` (md), `px-2.5 py-1.5` (sm) - Section spacing: `space-y-4` or `space-y-6` - Grid gaps: `gap-4` or `gap-6` - Icon-text gap: `gap-2` or `gap-3` ## Accessibility ### Color Contrast All semantic colors meet WCAG AA standards: - `text-ink` on `bg-app` - AAA - `text-ink-dull` on `bg-app-box` - AA - `text-ink-faint` on `bg-app-input` - AA (minimum) ### Focus States Interactive elements include focus rings: ```tsx