Skip to content

Components

Views

Write one page for several frameworks or languages, and let readers pick theirs.

Wrap each alternative in <View title="...">. The page header gets a selector listing every view title on the page, and picking one shows the matching view everywhere on the page. Try the selector in this page's header.

Getting started

Install the React package and render the widget inside your app.

npm install @acme/widget-react
jsx
import { Widget } from "@acme/widget-react";

export function App() {
  return <Widget theme="light" />;
}

Install the Vue package and register the component.

npm install @acme/widget-vue
html
<script setup>
import { Widget } from "@acme/widget-vue";
</script>

<template>
  <Widget theme="light" />
</template>

Theming

The same pick applies to every group of views on the page.

Pass theme="dark" to <Widget> to follow a dark page.

Bind :theme="mode" on <Widget> to follow the page's mode.

Views usage

Give the views of each alternative the same title, and repeat the set wherever the content differs.

html
<View title="React">

```jsx
<Widget theme="light" />
```

</View>

<View title="Vue">

```html
<Widget theme="light" />
```

</View>

Leave a blank line around Markdown inside a view, such as code blocks and lists, as with any component.

Behavior

  • One selector per page: it sits in the page header, next to Copy content, and lists the titles in the order they first appear.
  • Remembered: the pick is remembered across the site by title, so a reader who picks Vue sees the Vue views on every page that has them. A page without that title shows its first one.
  • No flash: the remembered view is chosen before the page first paints, so a returning reader never sees the first view flash by.
  • Search and AI: every view is part of the page's text, so search and AI tools see all of them.

Use views when most of a page is shared and only some parts differ. When a whole block is an either-or, such as a single code sample, tabs or code tabs keep the choice next to the content.

Headings inside a view appear in the "On this page" list for every view. Prefer bold text over headings inside views.

Properties

titlestringrequired

The view's name in the selector. Views with the same title belong to the same alternative.

childrennoderequired

The content shown when this view is picked.