.do

UI Components

Use React components to create interactive, styled content in MDX

UI Components

Use React components to create interactive, styled content:

<Callout type="info">
  This is an informational callout component with custom styling.
</Callout>

<Tabs>
  <Tab title="JavaScript">
    ```js
    console.log("Hello, World!")
    ```
  </Tab>
  <Tab title="TypeScript">
    ```ts
    console.log("Hello, World!" as string)
    ```
  </Tab>
</Tabs>

<Chart data={chartData} type="line" />

<Button onClick={() => alert('Clicked!')}>
  Interactive Button
</Button>

Components can be:

  • Interactive: Buttons, forms, tabs, accordions, modals
  • Data-driven: Charts, tables, dashboards, visualizations
  • Styled: Using Tailwind, CSS-in-JS, or any styling solution
  • Composable: Build complex UIs from simple, reusable components
  • Accessible: Following WCAG guidelines and best practices

Why UI Components?

UI components in MDX provide:

  • Rich interactions: Create engaging user experiences
  • Reusability: Define once, use everywhere
  • Consistency: Maintain design system standards
  • Data visualization: Present complex data visually
  • Accessibility: Built-in ARIA attributes and keyboard navigation
  • Type safety: Full TypeScript support

Basic Components

Callouts

Highlight important information:

<Callout type="info">
  This is an informational message
</Callout>

<Callout type="warning">
  This is a warning
</Callout>

<Callout type="error">
  This is an error message
</Callout>

<Callout type="success">
  Operation completed successfully
</Callout>

Buttons

Create interactive buttons:

<Button>Default Button</Button>

<Button variant="primary">Primary Action</Button>

<Button variant="secondary">Secondary Action</Button>

<Button variant="danger">Delete</Button>

<Button href="/docs">Link Button</Button>

Cards

Group related content:

<Card title="Getting Started">
  Follow this guide to get started with MDX
</Card>

<Card title="API Reference" icon="📚">
  Complete API documentation
</Card>

Layout Components

Grid

Create responsive grid layouts:

<Grid cols={3}>
  <Card title="SDK">TypeScript SDK</Card>
  <Card title="CLI">Command-line tool</Card>
  <Card title="MCP">Protocol server</Card>
</Grid>

<Grid cols={2} gap="large">
  <div>Column 1</div>
  <div>Column 2</div>
</Grid>

Flex

Flexible box layouts:

<Flex direction="row" align="center" justify="space-between">
  <div>Left content</div>
  <div>Right content</div>
</Flex>

<Flex direction="column" gap="medium">
  <Card>Item 1</Card>
  <Card>Item 2</Card>
  <Card>Item 3</Card>
</Flex>

Container

Center and constrain content width:

<Container>
  <h1>Page Title</h1>
  <p>This content is centered and has a maximum width</p>
</Container>

<Container size="small">
  Narrow container
</Container>

<Container size="large">
  Wide container
</Container>

Interactive Components

Tabs

Organize content into tabs:

<Tabs>
  <Tab title="Installation">
    ## Installation

    Install using pnpm:
    \`\`\`bash
    pnpm install mdxld
    \`\`\`
  </Tab>

  <Tab title="Usage">
    ## Usage

    Import and use:
    \`\`\`typescript
    import { parse } from 'mdxld'
    \`\`\`
  </Tab>

  <Tab title="Examples">
    ## Examples

    See examples below...
  </Tab>
</Tabs>

Accordion

Collapsible content sections:

<Accordion>
  <AccordionItem title="What is MDX?">
    MDX is a format that combines Markdown with JSX.
  </AccordionItem>

  <AccordionItem title="How do I get started?">
    Install the package and import components.
  </AccordionItem>

  <AccordionItem title="Is it production ready?">
    Yes, MDX is used by many production applications.
  </AccordionItem>
</Accordion>

Display content in overlays:

'use client'

import { useState } from 'react'

export function ModalDemo() {
  const [open, setOpen] = useState(false)

  return (
    <>
      <Button onClick={() => setOpen(true)}>
        Open Modal
      </Button>

      <Modal open={open} onClose={() => setOpen(false)}>
        <h2>Modal Title</h2>
        <p>Modal content goes here</p>
      </Modal>
    </>
  )
}

<ModalDemo />

Data Visualization

Tables

Display tabular data:

<Table
  columns={[
    { key: 'name', label: 'Name' },
    { key: 'role', label: 'Role' },
    { key: 'status', label: 'Status' }
  ]}
  data={[
    { name: 'Alice', role: 'Developer', status: 'Active' },
    { name: 'Bob', role: 'Designer', status: 'Active' },
    { name: 'Carol', role: 'Manager', status: 'Away' }
  ]}
/>

Charts

Visualize data with charts:

export const salesData = [
  { month: 'Jan', sales: 4000 },
  { month: 'Feb', sales: 3000 },
  { month: 'Mar', sales: 5000 },
  { month: 'Apr', sales: 4500 },
]

<Chart
  type="line"
  data={salesData}
  xKey="month"
  yKey="sales"
  title="Monthly Sales"
/>

<Chart
  type="bar"
  data={salesData}
  xKey="month"
  yKey="sales"
/>

Stats

Display key metrics:

<Stats
  items={[
    { label: 'Total Users', value: '10,245', change: '+12%' },
    { label: 'Revenue', value: '$45.2K', change: '+23%' },
    { label: 'Conversion', value: '3.2%', change: '-2%' }
  ]}
/>

Marketing Components

Hero

Create hero sections:

<Hero
  title="Welcome to .do Platform"
  subtitle="Business-as-Code for autonomous operations"
  cta={
    <Button variant="primary" size="large" href="/get-started">
      Get Started
    </Button>
  }
  image="/hero-image.png"
/>

Features

Showcase product features:

<Features
  items={[
    {
      icon: "⚡",
      title: "Fast",
      description: "Edge-first architecture for global performance"
    },
    {
      icon: "🔒",
      title: "Secure",
      description: "Built-in security and compliance"
    },
    {
      icon: "🌍",
      title: "Global",
      description: "Worldwide distribution on Cloudflare"
    }
  ]}
/>

Pricing

Display pricing tiers:

<Pricing
  plans={[
    {
      name: 'Starter',
      price: '$0',
      features: ['10 projects', '100 GB storage', 'Community support'],
      cta: <Button>Start Free</Button>
    },
    {
      name: 'Pro',
      price: '$29',
      features: ['Unlimited projects', '1 TB storage', 'Priority support'],
      cta: <Button variant="primary">Upgrade to Pro</Button>,
      highlighted: true
    },
    {
      name: 'Enterprise',
      price: 'Custom',
      features: ['Custom limits', 'Dedicated support', 'SLA'],
      cta: <Button>Contact Sales</Button>
    }
  ]}
/>

Testimonials

Show customer testimonials:

<Testimonials
  items={[
    {
      quote: "MDX transformed how we build documentation",
      author: "Jane Developer",
      role: "CTO at TechCorp",
      avatar: "/avatars/jane.jpg"
    },
    {
      quote: "The best way to combine code and content",
      author: "John Designer",
      role: "Lead Designer at StartupCo",
      avatar: "/avatars/john.jpg"
    }
  ]}
/>

Form Components

Input

Text input fields:

'use client'

import { useState } from 'react'

export function InputDemo() {
  const [value, setValue] = useState('')

  return (
    <Input
      value={value}
      onChange={(e) => setValue(e.target.value)}
      placeholder="Enter text..."
      label="Name"
    />
  )
}

<InputDemo />

Select

Dropdown selects:

<Select
  options={[
    { value: 'js', label: 'JavaScript' },
    { value: 'ts', label: 'TypeScript' },
    { value: 'py', label: 'Python' }
  ]}
  placeholder="Choose language"
  label="Programming Language"
/>

Form

Complete forms:

'use client'

export function ContactForm() {
  const handleSubmit = (e) => {
    e.preventDefault()
    // Handle form submission
  }

  return (
    <Form onSubmit={handleSubmit}>
      <Input name="name" label="Name" required />
      <Input name="email" label="Email" type="email" required />
      <Textarea name="message" label="Message" rows={4} />
      <Button type="submit">Send Message</Button>
    </Form>
  )
}

<ContactForm />

Custom Components

Creating Components

Define custom components:

// components/Badge.tsx
export interface BadgeProps {
  children: React.ReactNode
  variant?: 'default' | 'success' | 'warning' | 'error'
}

export function Badge({ children, variant = 'default' }: BadgeProps) {
  return (
    <span className={`badge badge-${variant}`}>
      {children}
    </span>
  )
}

Use in MDX:

import { Badge } from '@/components/Badge'

<Badge variant="success">New</Badge>
<Badge variant="warning">Beta</Badge>
<Badge variant="error">Deprecated</Badge>

Component Libraries

MDXUI

Use the MDXUI component library:

pnpm install mdxui
import { Hero, Features, Pricing } from 'mdxui'

<Hero
  title="Build with MDXUI"
  cta={<Button>Get Started</Button>}
/>

<Features items={featureList} />

<Pricing plans={pricingPlans} />

Third-Party Libraries

Integrate any React component library:

import { Button, Card } from '@shadcn/ui'
import { LineChart } from 'recharts'
import { Accordion } from '@radix-ui/react-accordion'

<Button>shadcn/ui Button</Button>
<LineChart data={chartData} />
<Accordion>...</Accordion>

Styling

Tailwind CSS

Use Tailwind classes:

<div className="bg-blue-500 text-white p-4 rounded-lg">
  Styled with Tailwind
</div>

CSS-in-JS

Use styled-components or emotion:

import styled from 'styled-components'

export const StyledBox = styled.div`
  background: #f0f0f0;
  padding: 1rem;
  border-radius: 0.5rem;
`

<StyledBox>Styled content</StyledBox>

CSS Modules

Import CSS modules:

import styles from './component.module.css'

<div className={styles.container}>
  Styled with CSS modules
</div>

Accessibility

ARIA Attributes

Add accessibility attributes:

<Button
  aria-label="Close dialog"
  aria-pressed={isPressed}
>
  Close
</Button>

Keyboard Navigation

Components support keyboard navigation:

<Tabs>
  {/* Tabs support arrow key navigation */}
  <Tab title="Tab 1">Content 1</Tab>
  <Tab title="Tab 2">Content 2</Tab>
</Tabs>

Screen Readers

Use semantic HTML and labels:

<nav aria-label="Main navigation">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/docs">Docs</a></li>
  </ul>
</nav>

Next Steps