diff --git a/src/app/components/interactive/ComponentPlayground.jsx b/src/app/components/interactive/ComponentPlayground.jsx index 82a3beb..c9a5ade 100644 --- a/src/app/components/interactive/ComponentPlayground.jsx +++ b/src/app/components/interactive/ComponentPlayground.jsx @@ -1,17 +1,17 @@ "use client"; -import { useState, useEffect } from 'react'; -import { - Settings, - Eye, - Code, - Copy, - RotateCcw, - Shuffle, - Sun, - Moon, - MousePointer, - Square, - Type, +import { useState, useEffect } from "react"; +import { + Settings, + Eye, + Code, + Copy, + RotateCcw, + Shuffle, + Sun, + Moon, + MousePointer, + Square, + Type, Palette, Zap, BarChart3, @@ -25,68 +25,79 @@ import { Info, Sparkles, Heart, - Star -} from 'lucide-react'; -import PrimaryButton from '../buttons/PrimaryButton'; -import SecondaryButton from '../buttons/SecondaryButton'; -import DangerButton from '../buttons/DangerButton'; -import SuccessButton from '../buttons/SuccessButton'; -import GhostButton from '../buttons/GhostButton'; -import OutlineButton from '../buttons/OutlineButton'; -import RainbowButton from '../buttons/RainbowButton'; -import SimpleCard from '../cards/SimpleCard'; -import FeatureCard from '../cards/FeatureCard'; -import PricingCard from '../cards/PricingCard'; -import UserCard from '../cards/UserCard'; -import DataCard from '../cards/DataCard'; -import TextInput from '../inputs/TextInput'; -import Select from '../inputs/Select'; -import Checkbox from '../inputs/Checkbox'; -import { useToast } from '../feedback/Toast'; + Star, +} from "lucide-react"; +import PrimaryButton from "../buttons/PrimaryButton"; +import SecondaryButton from "../buttons/SecondaryButton"; +import DangerButton from "../buttons/DangerButton"; +import SuccessButton from "../buttons/SuccessButton"; +import GhostButton from "../buttons/GhostButton"; +import OutlineButton from "../buttons/OutlineButton"; +import RainbowButton from "../buttons/RainbowButton"; +import SimpleCard from "../cards/SimpleCard"; +import FeatureCard from "../cards/FeatureCard"; +import PricingCard from "../cards/PricingCard"; +import UserCard from "../cards/UserCard"; +import DataCard from "../cards/DataCard"; +import TextInput from "../inputs/TextInput"; +import Select from "../inputs/Select"; +import Checkbox from "../inputs/Checkbox"; +import { useToast } from "../feedback/Toast"; export default function ComponentPlayground() { // Component Selection - const {addToast, ToastContainer} = useToast(); - const [selectedComponent, setSelectedComponent] = useState('button'); - const [selectedVariant, setSelectedVariant] = useState('primary'); + const { addToast, ToastContainer } = useToast(); + const [selectedComponent, setSelectedComponent] = useState("button"); + const [selectedVariant, setSelectedVariant] = useState("primary"); // Button States - const [buttonText, setButtonText] = useState('Click Me'); - const [buttonSize, setButtonSize] = useState('medium'); + const [buttonText, setButtonText] = useState("Click Me"); + const [buttonSize, setButtonSize] = useState("medium"); const [buttonDisabled, setButtonDisabled] = useState(false); const [buttonLoading, setButtonLoading] = useState(false); // Card States - const [cardTitle, setCardTitle] = useState('Sample Card'); - const [cardDescription, setCardDescription] = useState('This is a sample card description'); - const [cardImage, setCardImage] = useState('https://images.unsplash.com/photo-1557804506-669a67965ba0?w=400'); + const [cardTitle, setCardTitle] = useState("Sample Card"); + const [cardDescription, setCardDescription] = useState( + "This is a sample card description" + ); + const [cardImage, setCardImage] = useState( + "https://images.unsplash.com/photo-1557804506-669a67965ba0?w=400" + ); // Input States - const [inputLabel, setInputLabel] = useState('Sample Input'); - const [inputPlaceholder, setInputPlaceholder] = useState('Enter text here...'); + const [inputLabel, setInputLabel] = useState("Sample Input"); + const [inputPlaceholder, setInputPlaceholder] = + useState("Enter text here..."); const [inputRequired, setInputRequired] = useState(false); - const [inputError, setInputError] = useState(''); + const [inputError, setInputError] = useState(""); // Pricing Card States - const [pricingPlan, setPricingPlan] = useState('Pro'); - const [pricingPrice, setPricingPrice] = useState('$9/mo'); - const [pricingFeatures, setPricingFeatures] = useState(['10 projects', 'Priority support', 'Unlimited users']); + const [pricingPlan, setPricingPlan] = useState("Pro"); + const [pricingPrice, setPricingPrice] = useState("$9/mo"); + const [pricingFeatures, setPricingFeatures] = useState([ + "10 projects", + "Priority support", + "Unlimited users", + ]); // User Card States - const [userName, setUserName] = useState('John Doe'); - const [userEmail, setUserEmail] = useState('john@example.com'); - const [userRole, setUserRole] = useState('Software Engineer'); - const [userAvatar, setUserAvatar] = useState('https://i.pravatar.cc/150?img=1'); + const [userName, setUserName] = useState("John Doe"); + const [userEmail, setUserEmail] = useState("john@example.com"); + const [userRole, setUserRole] = useState("Software Engineer"); + const [userAvatar, setUserAvatar] = useState( + "https://i.pravatar.cc/150?img=1" + ); // Data Card States - const [dataTitle, setDataTitle] = useState('Active Projects'); - const [dataValue, setDataValue] = useState('27'); - const [dataIcon, setDataIcon] = useState('📂'); + const [dataTitle, setDataTitle] = useState("Active Projects"); + const [dataValue, setDataValue] = useState("27"); + const [dataIcon, setDataIcon] = useState("📂"); const [dataTrend, setDataTrend] = useState(8); // UI States - const [copiedCode, setCopiedCode] = useState(''); - const [previewMode, setPreviewMode] = useState('light'); + const [copiedCode, setCopiedCode] = useState(""); + const [previewMode, setPreviewMode] = useState("light"); const [showCode, setShowCode] = useState(true); // Favorites System @@ -96,64 +107,66 @@ export default function ComponentPlayground() { // Component variants mapping const componentVariants = { button: { - primary: { component: PrimaryButton, name: 'Primary Button' }, - secondary: { component: SecondaryButton, name: 'Secondary Button' }, - danger: { component: DangerButton, name: 'Danger Button' }, - success: { component: SuccessButton, name: 'Success Button' }, - ghost: { component: GhostButton, name: 'Ghost Button' }, - outline: { component: OutlineButton, name: 'Outline Button' }, - rainbow: { component: RainbowButton, name: 'Rainbow Button' } + primary: { component: PrimaryButton, name: "Primary Button" }, + secondary: { component: SecondaryButton, name: "Secondary Button" }, + danger: { component: DangerButton, name: "Danger Button" }, + success: { component: SuccessButton, name: "Success Button" }, + ghost: { component: GhostButton, name: "Ghost Button" }, + outline: { component: OutlineButton, name: "Outline Button" }, + rainbow: { component: RainbowButton, name: "Rainbow Button" }, }, card: { - simple: { component: SimpleCard, name: 'Simple Card' }, - feature: { component: FeatureCard, name: 'Feature Card' }, - pricing: { component: PricingCard, name: 'Pricing Card' }, - user: { component: UserCard, name: 'User Card' }, - data: { component: DataCard, name: 'Data Card' } + simple: { component: SimpleCard, name: "Simple Card" }, + feature: { component: FeatureCard, name: "Feature Card" }, + pricing: { component: PricingCard, name: "Pricing Card" }, + user: { component: UserCard, name: "User Card" }, + data: { component: DataCard, name: "Data Card" }, }, input: { - text: { component: TextInput, name: 'Text Input' }, - select: { component: Select, name: 'Select Dropdown' }, - checkbox: { component: Checkbox, name: 'Checkbox' } - } + text: { component: TextInput, name: "Text Input" }, + select: { component: Select, name: "Select Dropdown" }, + checkbox: { component: Checkbox, name: "Checkbox" }, + }, }; // Generate code based on current settings const generateCode = () => { const variant = componentVariants[selectedComponent]?.[selectedVariant]; - if (!variant) return ''; - - if (selectedComponent === 'button') { - const sizeClass = buttonSize === 'small' ? 'px-3 py-1 text-sm' : - buttonSize === 'large' ? 'px-6 py-3 text-lg' : 'px-4 py-2'; + if (!variant) return ""; + + if (selectedComponent === "button") { + const sizeClass = + buttonSize === "small" + ? "px-3 py-1 text-sm" + : buttonSize === "large" + ? "px-6 py-3 text-lg" + : "px-4 py-2"; return `<${variant.component.name} onClick={() => alert('Button clicked!')} - ${buttonDisabled ? 'disabled' : ''} - ${buttonLoading ? 'loading' : ''} + ${buttonDisabled ? "disabled" : ""} + ${buttonLoading ? "loading" : ""} className="${sizeClass}" > ${buttonText} `; - } - - else if (selectedComponent === 'card') { - if (selectedVariant === 'simple') { + } else if (selectedComponent === "card") { + if (selectedVariant === "simple") { return ``; - } else if (selectedVariant === 'feature') { + } else if (selectedVariant === "feature") { return ``; - } else if (selectedVariant === 'pricing') { + } else if (selectedVariant === "pricing") { return ``; - } else if (selectedVariant === 'user') { + } else if (selectedVariant === "user") { return ` alert('User card clicked!')} />`; - } else if (selectedVariant === 'data') { + } else if (selectedVariant === "data") { return ``; } - } - - else if (selectedComponent === 'input') { - if (selectedVariant === 'text') { + } else if (selectedComponent === "input") { + if (selectedVariant === "text") { return ``; - } else if (selectedVariant === 'select') { + } else if (selectedVariant === "select") { return ` @@ -473,17 +573,23 @@ export default function ComponentPlayground() {
-
+
{/* Controls Panel */}
-
+
-

+

Customization Controls

-
+
@@ -580,7 +692,9 @@ export default function ComponentPlayground() { onChange={(e) => setButtonDisabled(e.target.checked)} className="mr-2" /> - Disabled + + Disabled +
)} {/* Card Controls */} - {selectedComponent === 'card' && ( + {selectedComponent === "card" && ( <>
{/* Pricing Card Specific Controls */} - {selectedVariant === 'pricing' && ( + {selectedVariant === "pricing" && ( <>
@@ -652,8 +768,12 @@ export default function ComponentPlayground() { Features (comma separated) setPricingFeatures(e.target.value.split(', ').filter(f => f.trim()))} + value={pricingFeatures.join(", ")} + onChange={(e) => + setPricingFeatures( + e.target.value.split(", ").filter((f) => f.trim()) + ) + } placeholder="Feature 1, Feature 2, Feature 3" />
@@ -661,7 +781,7 @@ export default function ComponentPlayground() { )} {/* User Card Specific Controls */} - {selectedVariant === 'user' && ( + {selectedVariant === "user" && ( <>
@@ -709,7 +829,7 @@ export default function ComponentPlayground() { )} {/* Data Card Specific Controls */} - {selectedVariant === 'data' && ( + {selectedVariant === "data" && ( <>
@@ -751,7 +871,9 @@ export default function ComponentPlayground() { setDataTrend(parseInt(e.target.value) || 0)} + onChange={(e) => + setDataTrend(parseInt(e.target.value) || 0) + } className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white" placeholder="8" /> @@ -763,7 +885,7 @@ export default function ComponentPlayground() { )} {/* Input Controls */} - {selectedComponent === 'input' && ( + {selectedComponent === "input" && ( <>
- {selectedVariant === 'text' && ( + {selectedVariant === "text" && ( <>
@@ -818,8 +942,8 @@ export default function ComponentPlayground() { {/* Code Section */}
-
-
+
+
{showCode && (
-
-                  
+                
+                  
                     {generateCode()}
                   
                 
@@ -860,10 +984,10 @@ export default function ComponentPlayground() { {/* Preview Panel */}
-
+
-

+

Live Preview

@@ -875,42 +999,63 @@ export default function ComponentPlayground() { {/* Preview Container */}
-
-
- {renderComponent()} -
+
+
{renderComponent()}
{/* Component Info */} -
+
- Component Info + + Component Info +
-
-

Type: {selectedComponent.charAt(0).toUpperCase() + selectedComponent.slice(1)}

-

Variant: {componentVariants[selectedComponent]?.[selectedVariant]?.name}

-

Interactive: {selectedComponent === 'button' ? 'Yes (Click to test)' : selectedComponent === 'card' && selectedVariant === 'user' ? 'Yes (Click to test)' : 'Display only'}

+
+

+ Type:{" "} + {selectedComponent.charAt(0).toUpperCase() + + selectedComponent.slice(1)} +

+

+ Variant:{" "} + {componentVariants[selectedComponent]?.[selectedVariant]?.name} +

+

+ Interactive:{" "} + {selectedComponent === "button" + ? "Yes (Click to test)" + : selectedComponent === "card" && selectedVariant === "user" + ? "Yes (Click to test)" + : "Display only"} +

{/* Quick Actions */} -
- -
+
+ +
Reset
- -
+ +
Randomize
@@ -918,18 +1063,27 @@ export default function ComponentPlayground() {

- {favorite.componentType.charAt(0).toUpperCase() + favorite.componentType.slice(1)} Component + {favorite.componentType.charAt(0).toUpperCase() + + favorite.componentType.slice(1)}{" "} + Component

Added {new Date(favorite.addedAt).toLocaleDateString()} @@ -1011,91 +1178,146 @@ export default function ComponentPlayground() { {/* All Variants Showcase */}

- {selectedComponent === 'button' && } - {selectedComponent === 'card' && } - {selectedComponent === 'input' && } + {selectedComponent === "button" && ( + + )} + {selectedComponent === "card" && ( + + )} + {selectedComponent === "input" && ( + + )}

- All {selectedComponent.charAt(0).toUpperCase() + selectedComponent.slice(1)} Variants + All{" "} + {selectedComponent.charAt(0).toUpperCase() + + selectedComponent.slice(1)}{" "} + Variants

- {Object.entries(componentVariants[selectedComponent] || {}).map(([key, variant]) => ( -
-
-
setSelectedVariant(key)} - className={`cursor-pointer transition-all ${selectedVariant === key ? 'ring-2 ring-blue-500 ring-offset-2 dark:ring-offset-gray-800 rounded-lg' : ''}`} - > - {/* Render mini version of each variant */} - {selectedComponent === 'button' && ( - { - e.stopPropagation(); - setSelectedVariant(key); - }}> - {variant.name.split(' ')[0]} - - )} - {selectedComponent === 'card' && key === 'simple' && ( -
- -
- )} - {selectedComponent === 'card' && key === 'feature' && ( -
- -
- )} - {selectedComponent === 'card' && key === 'pricing' && ( -
- -
- )} - {selectedComponent === 'card' && key === 'user' && ( -
- -
- )} - {selectedComponent === 'card' && key === 'data' && ( -
- -
- )} - {selectedComponent === 'input' && ( -
+ {Object.entries(componentVariants[selectedComponent] || {}).map( + ([key, variant]) => ( +
+
+
setSelectedVariant(key)} + className={`cursor-pointer transition-all ${ + selectedVariant === key + ? "ring-2 ring-blue-500 ring-offset-2 dark:ring-offset-gray-800 rounded-lg" + : "" + }`} + > + {/* Render mini version of each variant */} + {selectedComponent === "button" && ( { } } : {})} - /> -
- )} + onClick={(e) => { + e.stopPropagation(); + setSelectedVariant(key); + }} + > + {variant.name.split(" ")[0]} + + )} + {selectedComponent === "card" && key === "simple" && ( +
+ +
+ )} + {selectedComponent === "card" && key === "feature" && ( +
+ +
+ )} + {selectedComponent === "card" && key === "pricing" && ( +
+ +
+ )} + {selectedComponent === "card" && key === "user" && ( +
+ +
+ )} + {selectedComponent === "card" && key === "data" && ( +
+ +
+ )} + {selectedComponent === "input" && ( +
+ {} } + : {})} + /> +
+ )} +
-
-
-

- {variant.name} -

- + title={ + isFavorite(selectedComponent, key) + ? "Remove from favorites" + : "Add to favorites" + } + > + + +
+

+ Click to customize +

-

- Click to customize -

-
- ))} + ) + )}
@@ -1103,30 +1325,34 @@ export default function ComponentPlayground() {
-

- Playground Stats -

+

Playground Stats

-
{Object.keys(componentVariants.button).length}
+
+ {Object.keys(componentVariants.button).length} +
Button Types
-
{Object.keys(componentVariants.card).length}
+
+ {Object.keys(componentVariants.card).length} +
Card Types
-
{Object.keys(componentVariants.input).length}
+
+ {Object.keys(componentVariants.input).length} +
Input Types
@@ -1141,4 +1367,4 @@ export default function ComponentPlayground() {
); -} \ No newline at end of file +}