'use client'; import { UserButton, useUser } from '@stackframe/stack'; import { Wrench } from "lucide-react"; import { useState } from "react"; import { DynamicCodeblock } from "../mdx/dynamic-code-block"; type UserButtonDemoProps = { showUserInfo: boolean, colorModeToggle: boolean, extraItems: boolean, } export function UserButtonDemo() { const [props, setProps] = useState({ showUserInfo: true, colorModeToggle: false, extraItems: false, }); // Get the actual logged-in user const user = useUser(); // Mock user data (used when no user is logged in) const mockUser = { displayName: "John Doe", primaryEmail: "john.doe@example.com", profileImageUrl: undefined, }; // Generate the code example based on current props const generateCodeExample = () => { const extraItemsCode = `[{ text: 'Custom Action', icon: , onClick: () => console.log('Custom action clicked') }]`; const propsArray = [`showUserInfo={${props.showUserInfo}}`]; if (props.colorModeToggle) { propsArray.push(`colorModeToggle={() => console.log("color mode toggle clicked")}`); } if (props.extraItems) { propsArray.push(`extraItems={${extraItemsCode}}`); } const propsCode = propsArray.join('\n '); return `import { UserButton } from "@stackframe/stack"; export function MyComponent() { return ( ); }`; }; return (
{/* Main demo area */}
{/* Controls Panel */}

Component Options

{/* Show User Info Toggle */}

Whether to display user information (display name and email) or only show the avatar.

{/* Color Mode Toggle */}

Function to be called when the color mode toggle button is clicked. If specified, a color mode toggle button will be shown.

{/* Extra Items Toggle */}

Additional menu items to display in the dropdown.

{/* Component Preview */}

Live Preview

{user ? ( ✓ Using your actual account ) : ( → Using mock data (sign in to see your account) )}
{/* Component demo label */}
Component Demo
console.log("color mode toggle clicked") : undefined} extraItems={props.extraItems ? [{ text: 'Custom Action', icon: , onClick: () => console.log('Custom action clicked') }] : undefined} />
{/* Code Example */}
); }