Skip to content

Getting Started

Get up and running with MIDDAG React UI in under five minutes.

Run the wizard from your plugin project root:

# Community (no auth needed)
npx create-middag-ui

# PRO (source maps, mock SPA, full exports)
npx @middag-io/create-middag-ui

For CI or scripted setups, use --yes to skip all prompts:

npx create-middag-ui --yes            # defaults: ui/, public registry
npx create-middag-ui --yes --github   # defaults: ui/, GitHub Packages

The wizard:

  1. Detects your host — finds version.php (Moodle) or wp-config.php (WordPress)
  2. Asks for target directory — default ui/, or pass as argument: npx create-middag-ui mydir
  3. Configures registry — npm public (no auth) or GitHub Packages (with source, needs token)
  4. Scaffolds config + demo files — package.json, tsconfig, Vite config, custom block example, standalone component
  5. Runs npm install — automatically installs all dependencies
  6. Shows next steps — how to start the dev server and integrate with your platform

Steps 2–3 are skipped when --yes is used. Host detection (step 1) always runs automatically.

After the wizard completes:

cd ui
npm run dev    # Opens at http://localhost:5174

You should see a working admin page with a “Setup Complete” metric card and an example data table. That’s your first PageContract rendering.

Manual Install

If you prefer to set things up yourself instead of using the wizard:

Option A: npm public registry (no auth needed)

# Install the compiled package directly from npm
npm install @middag-io/react react react-dom @inertiajs/react @inertiajs/core

Option B: GitHub Packages (includes TypeScript source)

# Configure GitHub Packages in your global ~/.npmrc
echo "@middag-io:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN" >> ~/.npmrc

# Install the package with full source
npm install @middag-io/react react react-dom @inertiajs/react @inertiajs/core

Create a token at github.com/settings/tokens with the read:packages scope. See Authentication for details.

Import & Register

Call registerDefaults() once at your app entry point to populate the shell, layout, and block registries with all built-in components:

// main.tsx (ESM consumers -- Moodle, standalone)
import { registerDefaults } from '@middag-io/react';
import '@middag-io/react/style.css';

// Register all built-in shells, layouts, and blocks
registerDefaults();

Wrap with Providers

Wrap your app root with the required providers:

// App.tsx
import { I18nProvider } from '@middag-io/react';

function App({ children }) {
    return (
        <I18nProvider
            locale="en"
            resolve={(key) => translations[key] ?? key}
        >
            {children}
        </I18nProvider>
    );
}

Render ContractPage

Pass a PageContract object to ContractPage and it handles the rest — resolving the shell, layout, and blocks from the registries:

// MyPage.tsx
import { ContractPage } from '@middag-io/react';
import type { PageContract } from '@middag-io/react';

const contract: PageContract = {
    version: '1',
    shell: 'product',
    page: {
        key: 'users',
        title: 'Users',
        breadcrumbs: [
            { label: 'Home', href: '/' },
            { label: 'Users' },
        ],
    },
    layout: {
        template: 'stack',
        regions: {
            content: [
                {
                    type: 'dense_table',
                    key: 'users-table',
                    data: {
                        columns: [
                            { key: 'name', label: 'Name' },
                            { key: 'email', label: 'Email' },
                        ],
                        rows: [
                            { id: '1', cells: { name: 'Alice', email: 'alice@example.com' } },
                        ],
                    },
                },
            ],
        },
    },
};

export default function UsersPage() {
    return <ContractPage contract={contract} />;
}

Send Contract from Backend

In Moodle, use the Inertia adapter to send the contract as page props:

// PHP -- Moodle Controller
return $this->inertia->render('ContractPage', [
    'contract' => [
        'version' => '1',
        'shell'   => 'product',
        'page'    => [
            'key'         => 'users',
            'title'       => get_string('users', 'local_myplugin'),
            'breadcrumbs' => [
                ['label' => 'Home', 'href' => '/'],
                ['label' => get_string('users', 'local_myplugin')],
            ],
        ],
        'layout' => [
            'template' => 'stack',
            'regions'  => [
                'content' => [
                    [
                        'type' => 'dense_table',
                        'key'  => 'users-table',
                        'data' => $table_data,
                    ],
                ],
            ],
        ],
    ],
]);

What’s Next

Now that you have a working setup, explore the rest of the documentation:

Navigation

Type to search…

↑↓ navigate↵ selectEsc close