Scenarios

Scenarios let you define named sets of mock data and state overrides for a component or page so you can preview and test different states directly on the canvas. Instead of manually changing test values or triggering live API requests every time you want to check a different state, you can switch between saved scenarios from the canvas top bar.

Why use scenarios

Components and pages often behave differently depending on their inputs, internal state, fetched data, or surrounding context. With scenarios, you can preview each state on demand without changing your component's logic or initial values:

  • Component variants: Preview a button as primary, secondary, or disabled, or view a card with short versus long text
  • API states: Test loading skeletons, empty lists, populated data, and error messages without calling a live back end
  • Page routes: Switch between different dynamic path parameters and query parameters on a page
  • Context states: Preview how a component renders for a logged-out visitor, a signed-in member, or an admin user
Info

Scenarios only apply while previewing in the Nordcraft editor. They are excluded from production builds and do not affect your published website or exported web components.

Switching scenarios

The scenario selector appears on the left side of the canvas top bar, displaying the name of the active scenario or No scenario when none is active.

The Nordcraft editor with the scenario dropdown open in the canvas top bar, showing available scenarios and the Edit scenarios action.

  1. 1
    Click the scenario dropdown in the canvas top bar
  2. 2
    Select a scenario from the list to apply it immediately to the canvas

Scenarios are listed alphabetically, and the default scenario is marked with a Default badge. When you select a scenario, Nordcraft adds a test-scenario query parameter to the editor URL so reloading the page or sharing the link opens the same scenario.

Creating and managing scenarios

Creating your first scenario

  1. 1
    Open the scenario dropdown in the canvas top bar
  2. 2
    Click New scenario

Nordcraft creates Scenario 1, marks it as the Default scenario, fills it with the current live values from the canvas (attributes, variables, and for pages, path and query parameters), applies it, and opens the Edit scenarios dialog.

Opening the scenario editor

When a component or page already has at least one scenario, open the scenario dropdown in the canvas top bar and click Edit scenarios to open the draggable Edit scenarios dialog.

The Edit scenarios dialog open in the Nordcraft editor, showing the scenario list on the left and override sections on the right.

The dialog has two areas:

  • Left panel (Scenarios): Lists every scenario on the component or page and lets you add, switch, rename, duplicate, or delete scenarios
  • Main panel: Displays the toolbar and override sections for the currently selected scenario

Changes you make in the Edit scenarios dialog save directly to the component or page and update the canvas immediately.

Managing scenarios in the list

  • Add a scenario: Click the + button in the Scenarios header to create a new empty scenario and apply it to the canvas
  • Select a scenario: Click any scenario in the list to switch to it on the canvas
  • Rename a scenario: Click an already-selected scenario, press Enter, or right-click and choose Rename. Press Enter to confirm or Escape to cancel. Scenario names must be unique within the component or page.
  • Make default: Right-click a scenario and select Make default to apply it automatically whenever you open the component or page
  • Duplicate a scenario: Right-click a scenario and select Duplicate to copy its overrides into a new scenario
  • Delete a scenario: Right-click a scenario and select Delete, or press Backspace or Delete while the scenario row is focused. If you delete the default scenario while other scenarios exist, the first remaining scenario alphabetically becomes the new default.

Quick toolbar actions

At the top of the main panel, two actions let you populate or reset the selected scenario quickly:

  • Use current values: Captures the current live values from the canvas for attributes, variables, and (for pages) path and query parameters, while keeping existing API and context overrides unchanged
  • Delete all: Removes all custom overrides from the selected scenario while keeping its default status

Overriding data in a scenario

Scenarios use partial overrides. You only need to add overrides for the specific items that matter for a scenario - any attribute, variable, or URL parameter you leave out keeps its regular test value or initial value.

Each override section appears only when the component or page defines items of that type. Click the + button in a section header to add an override, or click the - button next to an item to remove its override and return to the default value.

For attributes, URL parameters, variables, and API fields, you can enter strings, numbers, booleans, null, or JSON objects and arrays (starting with { or [), or use the type selector next to the input (String, Number, Boolean, Null).

Attributes

Available on components only. Override any component attribute to preview different inputs without editing the attribute's base test value.

Path and query parameters

Available on pages only. Override dynamic Path parameters and Query parameters defined in the page's route configuration to test how the page renders for different URLs.

Variables

Available on components and pages. Override the initial value of any variable to jump straight into a specific UI state, such as an open modal, an active tab, or a validation error.

APIs

Available on components and pages. Override the state of any API without making a live network request:

  • Loading: Toggle the Loading switch to simulate an in-flight request (isLoading)
  • Data / Error: Choose between Data and Error to provide a mock response payload or a mock error payload
  • Response details: Click the + button next to Response details to override HTTP response metadata:
    • status: Mock HTTP status code (such as 200, 404, or 500)
    • headers: Mock HTTP response headers as a JSON object
    • performance: Mock request timing values (requestStart, responseStart, responseEnd)
    • debug: Optional debug payload for the API response
Warning

Do not store sensitive data, such as access tokens, API keys, passwords, or real user data, in API response overrides. Scenario data is saved in your project files and is visible to everyone with access to the project (and publicly in public projects). Always use mock or anonymized placeholder data instead.

Contexts

Available on components and pages that subscribe to one or more context providers. A context override replaces the data received from a provider with one of the scenarios defined on that provider component.

Only subscribed context providers that define at least one scenario appear in the + menu. After adding a provider, choose which of its scenarios to apply from the dropdown.

Tip

If a context provider has a Default scenario, consumer components automatically use that provider scenario in the editor unless you select a different scenario in the consumer's Contexts section.

Default scenarios

Each component or page can have one Default scenario:

  • The first scenario you create on a component or page is marked as Default automatically
  • When you open a component or page without a test-scenario URL parameter, its default scenario is applied automatically on the canvas
  • When another component subscribes to this component as a context provider, the default scenario provides its preview data unless overridden

Validating scenarios

The issues panel automatically checks your scenarios for stale or invalid references, including:

  • Overrides referencing an attribute, variable, API, path parameter, or query parameter that was renamed or deleted
  • Context overrides referencing a provider the component is no longer subscribed to, or a provider scenario that no longer exists
  • Multiple scenarios marked as default on the same component or page

Each scenario issue includes an auto-fix to remove the invalid reference. See Scenarios issue rules for the full list of checks.

To customize the visual backdrop around your component on the canvas, see canvas styles.

Edit article
Help Forum