### Install and Run Development Server (npm) Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Installs project dependencies using npm and starts the Next.js development server. Assumes Node.js 20+ is installed. The application will be accessible at http://localhost:3000. ```bash npm install npm run dev ``` -------------------------------- ### Build Storybook Locally (Bash) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md Command to build Storybook for local deployment. Requires npm and Storybook setup. Outputs to storybook-static directory. Assumes dependencies are installed. ```bash npm run build-storybook ``` -------------------------------- ### Set up and Deploy Storybook to GitHub Pages (Bash and JSON) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md Install gh-pages package, add a deploy script to package.json, and run the deployment. The script builds Storybook and publishes to GitHub Pages. Requires gh-pages dependency and GitHub repo with Pages enabled. ```bash npm install --save-dev gh-pages ``` ```json "deploy-storybook": "npm run build-storybook && gh-pages -d storybook-static" ``` ```bash npm run deploy-storybook ``` -------------------------------- ### Quick Deploy Commands for Storybook (Bash) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md Simple commands for building Storybook and deploying via Vercel CLI. Assumes Vercel is set up. Options for CLI or dashboard deployment. ```bash # Build Storybook npm run build-storybook # Deploy to Vercel (if using CLI) vercel --prod # Or use the Vercel dashboard for easier setup ``` -------------------------------- ### Deploy Storybook to Vercel using CLI (Bash) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md Install Vercel CLI and deploy Storybook to production. Requires global installation and Vercel account. Can specify project name and cwd. ```bash npm i -g vercel # Deploy Storybook vercel --prod --cwd . --name your-storybook-project ``` -------------------------------- ### Start and Build Storybook (npm) Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Commands to start the Storybook development server for interactive component exploration and to build static Storybook files for deployment. The dev server runs on http://localhost:6006. ```bash npm run storybook npm run build-storybook ``` -------------------------------- ### Automate Storybook Deployment to Vercel with GitHub Actions (YAML) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md GitHub Actions workflow to build and deploy Storybook on push to main branch. Requires Vercel token, org ID, and project ID as secrets. Uses actions for checkout, node setup, and Vercel deployment. ```yaml name: Deploy Storybook on: push: branches: [main] paths: - 'stories/**' - 'components/**' - '.storybook/**' jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '20' - run: npm ci - run: npm run build-storybook - uses: amondnet/vercel-action@v25 with: vercel-token: ${{ secrets.VERCEL_TOKEN }} vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} vercel-args: '--prod' working-directory: ./ scope: ${{ secrets.VERCEL_ORG_ID }} ``` -------------------------------- ### Configure Netlify for Storybook Deployment (TOML and Bash) Source: https://github.com/motaterry/design-system-playground/blob/main/STORYBOOK_DEPLOYMENT.md Create netlify.toml for Netlify deployment. Includes build command and publish directory. Build is done via npm run build-storybook. Requires connecting GitHub repo to Netlify for automated deploys. ```bash npm run build-storybook ``` ```toml [build] command = "npm run build-storybook" publish = "storybook-static" ``` -------------------------------- ### React TSX Component Usage Examples Source: https://github.com/motaterry/design-system-playground/blob/main/COMPONENT_EXTRACTION.md Demonstrates the usage of several components like AutocompleteInput, PriceCard, WeatherCard, CompareGate, and HeroSection in a React TypeScript environment. It shows how to import and configure these components with various props for different functionalities. ```tsx import { AutocompleteInput, ShareBlock, CostComparisonCard, PriceCard, WeatherCard, CompareGate, CompareResult, PageHeader, HeroSection } from "@/components" // Autocomplete with metrics // Price card with custom formatting `$${p.toFixed(2)}`} /> // Weather forecast // Comparison gate // Hero section ``` -------------------------------- ### Add New shadcn/ui Components Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Command to add new components from the shadcn/ui library to the project. This command installs dependencies and creates the component files, typically within the `components/ui/` directory. ```bash npx shadcn@latest add [component-name] # Example: Add the avatar component npx shadcn@latest add avatar ``` -------------------------------- ### Create Storybook Story File Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Template for creating a Storybook story file for a React component. It defines metadata, the component itself, and example stories, facilitating component testing and documentation within Storybook. ```tsx // stories/ComponentName.stories.tsx import type { Meta, StoryObj } from '@storybook/react' import { ComponentName } from '@/components/ui/component-name' const meta = { title: 'Components/ComponentName', component: ComponentName, parameters: { layout: 'centered', }, tags: ['autodocs'], } satisfies Meta export default meta type Story = StoryObj export const Default: Story = { args: { // component props }, } ``` -------------------------------- ### Theme Provider and Toggle with next-themes (React/TypeScript) Source: https://context7.com/motaterry/design-system-playground/llms.txt Shows next-themes setup for system-aware light/dark mode in a Next.js layout, a theme toggle component that switches between light/dark using Lucide icons, and a theme-aware UI component that reflects the current theme. ```tsx // Layout setup (app/layout.tsx) import { ThemeProvider } from "next-themes" import { Toaster } from "@/components/ui/sonner" export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {children} ) } // Theme toggle component import { useTheme } from "next-themes" import { Button } from "@/components/ui/button" import { Moon, Sun } from "lucide-react" export function ThemeToggle() { const { theme, setTheme } = useTheme() return ( ) } // Theme-aware component export function ThemedCard() { const { theme } = useTheme() return (

Current theme: {theme}

This card adapts to light/dark mode

) } ``` -------------------------------- ### Use CSS Variables with Tailwind Utilities Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Example of applying CSS variables, mapped through Tailwind configuration, to HTML elements for styling. This showcases the integration of design tokens into the UI components. ```tsx
Content
``` -------------------------------- ### CompareGate: Advanced Custom Result Rendering Source: https://context7.com/motaterry/design-system-playground/llms.txt Illustrates how to use CompareGate with custom result rendering. This example defines a `renderComparisonResult` function to display analysis based on user input, including difference calculation and conditional styling. It utilizes UI components from '@/components/ui/card'. ```tsx import { CompareGate } from "@/components/comparison/compare-gate" import { Card, CardContent } from "@/components/ui/card" // Advanced comparison with custom result rendering export function CompareWithResults() { const renderComparisonResult = (data: { value1: number; value2: number }) => { const difference = data.value1 - data.value2 const percentDiff = ((difference / data.value2) * 100).toFixed(1) const isAbove = difference > 0 return (

Comparison Results

Your Value

{data.value1.toFixed(2)}

Regional Average

{data.value2.toFixed(2)}

You are {Math.abs(parseFloat(percentDiff))}% {isAbove ? 'above' : 'below'} average

) } return ( parseFloat(value)} renderResult={renderComparisonResult} privacyTitle="🔒 Anonymous • Encrypted" privacyDescription="All comparisons are anonymized and encrypted end-to-end" /> ) } ``` -------------------------------- ### Create Card with Image using TypeScript Source: https://context7.com/motaterry/design-system-playground/llms.txt This snippet demonstrates how to create a card component that includes an image. The image is displayed prominently at the top, followed by the card header, content, and footer. This example is useful for visual content presentation. It uses React, TypeScript, and shadcn/ui. ```tsx import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card" import { Button } from "@/components/ui/button" // Card with image export function ImageCard() { return (
Farm aerial view
Sunrise Valley Farm Organic vegetables and grains

Award-winning sustainable farm practicing regenerative agriculture for over 20 years.

) } ``` -------------------------------- ### Display Complex Card with Data Grid using TypeScript Source: https://context7.com/motaterry/design-system-playground/llms.txt This example showcases a complex card component designed to display a grid of key metrics. It utilizes data mapping to render multiple data points, suitable for dashboards or overview pages. Dependencies include React, TypeScript, and shadcn/ui for card and button components. ```tsx import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card" import { Button } from "@/components/ui/button" // Complex card with data grid export function DataCard() { const metrics = [ { label: "Total Area", value: "250 hectares" }, { label: "Crop Yield", value: "8.5 tons/ha" }, { label: "Soil Quality", value: "Excellent" }, { label: "Water Usage", value: "Optimal" } ] return ( Farm Overview +12.5% Season 2024 Performance
{metrics.map((metric) => (

{metric.label}

{metric.value}

))}
) } ``` -------------------------------- ### Create Autocomplete Input in TSX Source: https://context7.com/motaterry/design-system-playground/llms.txt The AutocompleteInput component offers keyboard navigation, suggestion filtering, match highlighting, and optional metadata for trends. It relies on React hooks such as useState and useRef for state management. Inputs include value, onChange, and suggestions array; outputs trigger onSelect callbacks; limitations include lack of server-side API integration in examples. ```tsx import { AutocompleteInput } from "@/components/forms/autocomplete-input" import { useState, useRef } from "react" // Basic autocomplete with string array export function BasicAutocomplete() { const [value, setValue] = useState("") const suggestions = [ "Apple Farm", "Banana Plantation", "Cherry Orchard", "Date Palm Grove", "Elderberry Field" ] return ( { setValue(selected) console.log("Selected:", selected) }} suggestions={suggestions} placeholder="Search farms..." showSuggestionsOnFocus={true} /> ) } // Advanced autocomplete with metadata and trends export function AutocompleteWithMetrics() { const [farmName, setFarmName] = useState("") const farmOptions = [ { label: "Sunrise Organic Farm", value: "farm_001", metadata: { trend: "up", change: 12.5 } }, { label: "Valley View Ranch", value: "farm_002", metadata: { trend: "down", change: -3.2 } }, { label: "Mountain Peak Agriculture", value: "farm_003", metadata: { trend: "stable", change: 0.1 } } ] return ( setFarmName(selected)} suggestions={farmOptions} placeholder="Select farm..." showMetrics={true} className="w-full" /> ) } // Custom highlight function and imperative handle export function AutocompleteAdvanced() { const [query, setQuery] = useState("") const inputRef = useRef(null) const customHighlight = (text: string, query: string) => { // Custom logic for highlighting multiple matches const regex = new RegExp(`(${query})`, 'gi') const parts = text.split(regex) return parts.map((part, i) => ({ text: part, highlight: regex.test(part) })) } return (
console.log("Input focused")} onBlur={() => console.log("Input blurred")} />
) } ``` -------------------------------- ### Create Tabs Component using Radix UI in TypeScript (TSX) Source: https://context7.com/motaterry/design-system-playground/llms.txt Shows two implementations of an accessible tabs interface: a simple uncontrolled version and a controlled version with React state. Both examples use Radix UI primitives and Tailwind CSS classes for styling. The snippets illustrate how to structure tab lists, triggers, and content panels, and how to manage active tabs programmatically. ```tsx import { Tabs, TabsContent, TabsList, TabsTrigger } from \"@/components/ui/tabs\"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from \"@/components/ui/card\"; export function BasicTabs() { return ( Overview Analytics Reports Farm Overview Quick snapshot of your farm

Total production: 2,500 tons this season

Analytics Dashboard

Detailed performance metrics and trends

Reports

Generate and download reports

); } ``` ```tsx export function ControlledTabs() { const [activeTab, setActiveTab] = useState(\"crop\"); return ( Crop Data Livestock Equipment

Crop Management

Wheat: 500 acres Corn: 350 acres Soybeans: 250 acres

Livestock inventory and health tracking

Equipment maintenance schedules

); } ``` -------------------------------- ### Implement Theme Toggle in Next.js Source: https://github.com/motaterry/design-system-playground/blob/main/README.md React component for toggling between light and dark themes in a Next.js application. It uses `useState` for theme state and `useEffect` to update the document's class list for styling. Assumes a CSS setup where toggling a 'dark' class on the root element changes the theme. ```tsx import { useEffect, useState } from 'react' export function ThemeToggle() { const [theme, setTheme] = useState('light') useEffect(() => { document.documentElement.classList.toggle('dark', theme === 'dark') }, [theme]) return ( ) } ``` -------------------------------- ### Class Name Merging with cn() Utility in TSX Source: https://context7.com/motaterry/design-system-playground/llms.txt Provides a cn() utility function that combines clsx for conditional classes and tailwind-merge to resolve Tailwind CSS conflicts, enabling efficient class composition in React components. Depends on external libraries clsx and tailwind-merge, typically imported from a utils file. Takes variable class strings and boolean conditions as inputs; outputs a single merged className string. Assumes Tailwind CSS setup and may not handle non-Tailwind classes or complex overrides beyond merge rules. ```tsx import { cn } from "@/lib/utils" // Basic className merging export function ButtonWithConditional({ isActive }: { isActive: boolean }) { return ( ) } // Intelligent Tailwind class merging (prevents conflicts) export function SmartMerge() { // tailwind-merge resolves conflicts: p-4 wins over p-2 return (
This will have p-4 and bg-blue-500 (later values win)
) } // Reusable component with className override export function Card({ className, children }: { className?: string children: React.ReactNode }) { return (
{children}
) } // Usage with override export function CustomCard() { return ( Custom styled card with merged classes ) } // Complex conditional rendering export function Badge({ variant = "default", size = "md", className }: { variant?: "default" | "success" | "warning" | "danger" size?: "sm" | "md" | "lg" className?: string }) { return ( Badge ) } ``` -------------------------------- ### Build and Deploy Storybook Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Commands to build the static Storybook and deploy it to a hosting provider. Assumes npm is used for package management. ```bash # Build static Storybook npm run build-storybook # Deploy the storybook-static folder to your hosting provider ``` -------------------------------- ### Define CSS Variables and Tailwind Mapping Source: https://github.com/motaterry/design-system-playground/blob/main/README.md Demonstrates how to define CSS variables for design tokens (colors, radii) in `globals.css` and reference them within Tailwind CSS utility classes. This ensures design consistency between Figma and the application. ```css :root { --color-primary: 24 24 27; /* Update with your Figma token */ --radius-md: 0.5rem; } ``` -------------------------------- ### Create basic dialog component (React/TSX) Source: https://context7.com/motaterry/design-system-playground/llms.txt Basic dialog implementation using React and TypeScript. Includes trigger button, header, content area with form fields, and footer actions. Uses component composition pattern with Dialog primitives. ```tsx import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" // Basic dialog export function BasicDialog() { return ( Add Crop Information Enter the details for the new crop you want to track.
) } ``` -------------------------------- ### Button Component Usage and Variants (React) Source: https://context7.com/motaterry/design-system-playground/llms.txt Demonstrates the polymorphic Button component from shadcn/ui, showcasing basic usage with different variants (default, destructive, outline, secondary, ghost, link) and size options (sm, default, lg, icon). It also shows how to use the 'asChild' prop for rendering as a different element (e.g., an anchor tag) and managing component states like loading and disabled. ```tsx import { Button } from "@/components/ui/button" import React from "react" // Basic usage with variants export function ButtonExample() { return (
) } // Size variants export function ButtonSizes() { return (
) } // Polymorphic rendering with asChild export function ButtonAsLink() { return ( ) } // With custom styling and disabled state export function ButtonWithState() { const [loading, setLoading] = React.useState(false) return ( ) } ``` -------------------------------- ### CompareGate: Insufficient Sample State Handling Source: https://context7.com/motaterry/design-system-playground/llms.txt Shows how to configure the CompareGate component to display an 'insufficient sample' state. This is useful when a comparison requires a minimum number of participants for anonymity or statistical significance. It includes props for titles, messages, and invite actions. ```tsx import { CompareGate } from "@/components/comparison/compare-gate" // Insufficient sample state export function InsufficientSampleGate() { return ( { console.log("Opening invite modal...") }} /> ) } ``` -------------------------------- ### Render Basic Card Structure with TypeScript Source: https://context7.com/motaterry/design-system-playground/llms.txt This snippet demonstrates the basic structure of a card component using the compound component pattern. It includes a header with a title and description, a content area, and a footer with a button. This component is built using React and TypeScript with shadcn/ui components. ```tsx import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@/components/ui/card" import { Button } from "@/components/ui/button" // Basic card structure export function BasicCard() { return ( Farm Analytics View your farm's performance metrics

Your yield is 15% above regional average.

) } ``` -------------------------------- ### CompareGate: Basic Usage with Locked State Source: https://context7.com/motaterry/design-system-playground/llms.txt Demonstrates the basic implementation of the CompareGate component, focusing on its locked state and unlock functionality. It requires React's useState for managing the lock state and provides props for labels, placeholders, and submission handling. ```tsx import { CompareGate } from "@/components/comparison/compare-gate" import { useState } from "react" // Basic comparison with locked state export function BasicCompareGate() { const [isUnlocked, setIsUnlocked] = useState(false) return ( setIsUnlocked(true)} unlockButtonText="Unlock Comparison Tool" lockedImageUrl="/locked-data-bg.jpg" onSubmit={(data) => { console.log("Comparison data:", data) }} /> ) } ``` -------------------------------- ### Toast Notifications with Sonner (React/TypeScript) Source: https://context7.com/motaterry/design-system-playground/llms.txt Demonstrates Sonner toast API in React: success, error, info, and warning messages; action buttons; async promise handling with loading/success/error states; and custom duration and rich content using description and icons. ```tsx import { toast } from "sonner" import { Button } from "@/components/ui/button" // Basic toast notifications export function ToastExamples() { return (
) } // Toast with action button export function ToastWithAction() { return ( ) } // Toast for async operations export function AsyncToast() { const handleExport = () => { toast.promise( // Simulated async operation new Promise((resolve, reject) => { setTimeout(() => { Math.random() > 0.5 ? resolve({ data: "exported" }) : reject(new Error("Export failed")) }, 2000) }), { loading: "Exporting farm data...", success: "Export completed! Check your downloads.", error: "Export failed. Please try again.", } ) } return ( ) } // Toast with custom duration and rich content export function CustomToast() { return ( ) } ``` -------------------------------- ### Generate and Export Design Tokens in TSX Source: https://context7.com/motaterry/design-system-playground/llms.txt Implements a design token generator for creating project-specific tokens with light and dark themes, including programmatic export to JSON files. Depends on React hooks like useState for state management and Blob API for file downloads. Accepts no direct inputs but generates structured token objects; outputs downloadable JSON files. Limited to browser environments for file exports and assumes Tailwind CSS integration for usage. ```tsx // Token Generator Page Implementation (app/token-generator/page.tsx) // Access at: http://localhost:3000/token-generator import { useState } from "react" // After generating tokens, use them in your globals.css: /* :root { --color-primary: 210 100% 50%; // Generated from token generator --color-bg: 0 0% 100%; --radius-md: 0.5rem; } */ // Then reference in components: export function CustomBrandedButton() { return ( ) } // Programmatic token generation export function TokenExport() { const generateTokens = () => { const tokens = { project: { name: "My Farm App", description: "Agricultural management platform" }, tokens: { light: { bg: "0 0% 100%", primary: "142 76% 45%", // Green for agriculture success: "142 76% 45%", warning: "45 93% 47%", danger: "0 84% 60%" }, dark: { bg: "240 6% 4%", primary: "142 76% 55%", success: "142 76% 55%", warning: "45 93% 57%", danger: "0 84% 70%" }, radius: { sm: "0.375rem", md: "0.5rem", lg: "0.75rem" } }, generatedAt: new Date().toISOString() } // Export as JSON const blob = new Blob([JSON.stringify(tokens, null, 2)], { type: "application/json" }) const url = URL.createObjectURL(blob) const a = document.createElement("a") a.href = url a.download = "farm-app-tokens.json" a.click() } return ( ) } ``` -------------------------------- ### Display Weather Card in TSX Source: https://context7.com/motaterry/design-system-playground/llms.txt The WeatherCard component displays a 7-day weather forecast in a grid layout with temperature ranges, precipitation data, and customizable icons. It depends on React for rendering and expects forecast data as props. Inputs include title, days array with weather details; outputs render the visual card; limitations include reliance on static data without real-time API fetching. ```tsx import { WeatherCard } from "@/components/data-display/weather-card" // Basic 7-day forecast export function WeatherForecast() { const forecast = [ { day: "MON", icon: "sun", temp: { max: 28, min: 18 }, rain: 0 }, { day: "TUE", icon: "cloud", temp: { max: 25, min: 16 }, rain: 2 }, { day: "WED", icon: "cloudRain", temp: { max: 22, min: 14 }, rain: 15 }, { day: "THU", icon: "rain", temp: { max: 20, min: 13 }, rain: 25 }, { day: "FRI", icon: "cloudDrizzle", temp: { max: 23, min: 15 }, rain: 8 }, { day: "SAT", icon: "cloud", temp: { max: 26, min: 17 }, rain: 0 }, { day: "SUN", icon: "sun", temp: { max: 29, min: 19 }, rain: 0 } ] return ( ) } // Weather card with image header export function WeatherWithImage() { const forecast = [ { day: "MON", icon: "sun", temp: { max: 82, min: 64 } }, { day: "TUE", icon: "cloud", temp: { max: 77, min: 61 } }, { day: "WED", icon: "rain", temp: { max: 72, min: 59 }, rain: 0.6 }, { day: "THU", icon: "rain", temp: { max: 68, min: 55 }, rain: 1.2 }, { day: "FRI", icon: "cloudDrizzle", temp: { max: 73, min: 58 }, rain: 0.3 }, { day: "SAT", icon: "sun", temp: { max: 78, min: 62 } }, { day: "SUN", icon: "sun", temp: { max: 84, min: 66 } } ] return ( ) } ``` -------------------------------- ### Create controlled dialog with state (React/TSX) Source: https://context7.com/motaterry/design-system-playground/llms.txt Dialog component with controlled state management. Tracks form inputs, handles save action with state reset, and demonstrates controlled open/close behavior. Uses React hooks for state management. ```tsx // Controlled dialog with state export function ControlledDialog() { const [open, setOpen] = useState(false) const [cropData, setCropData] = useState({ name: "", area: "" }) const handleSave = () => { console.log("Saving crop:", cropData) setOpen(false) setCropData({ name: "", area: "" }) } return ( Crop Details This will be added to your farm management system.
setCropData({ ...cropData, name: e.target.value })} />
setCropData({ ...cropData, area: e.target.value })} />
) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.