Creating docs examples

From handsontable/handsontable · View interactive version

Creating docs examples is an AI agent skill from the GitHub repository handsontable/handsontable. Use when creating code examples for documentation pages - JavaScript, TypeScript, React, Angular, and Vue variants with proper imports, registration, and license key

How to use this skill

Skill file

Creating Documentation Code Examples

File structure

docs/content/guides/category/feature/
  feature.md                 # The guide page
  javascript/example1.ts     # Primary source; example1.js is generated
  react/example1.tsx         # Primary source; example1.jsx is generated
  angular/example1.ts        # plus example1.html (outer wrapper)
  vue/example1.vue           # TypeScript SFC (`<script setup lang="ts">`)

Rules

Required in every example

  1. Base import and explicit registration (tree-shaking examples import individual plugins and cell types instead of registerAllModules()):

```js

import Handsontable from 'handsontable/base';

import { registerAllModules } from 'handsontable/registry';

registerAllModules();

```

  1. The license key stays a commented-out placeholder, never a key value: // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/. In JSX it is the first attribute (// licenseKey="your-license-key" // get a key at ...), because the generated .jsx loses a comment that follows the last attribute; in a Vue or HTML template it is an <!-- license-key="your-license-key" (get a key at ...) --> comment above the tag.
  2. Container, typed in the .ts and .tsx files: const container = document.querySelector<HTMLElement>('#example1')!;. An untyped querySelector returns Element | null, which fails with TS2345 in a new file, and it also hides every later error in the settings object from the type check (see docs/AGENTS.md, "Type-checking the examples"). The generated .js file keeps the plain document.querySelector('#example1').

React (TSX/JSX)

import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
registerAllModules();

const App = () => {
  return (
    <HotTable
      // licenseKey="your-license-key" // get a key at https://handsontable.com/pricing/
      data={data}
    />
  );
};

Angular

The docs site bootstraps Angular examples with JIT in the browser, which cannot load external files and lacks decorator metadata:

The .ts file holds app.component.ts and app.config.ts as separate /* file: ... */ sections:

/* file: app.component.ts */
import { Component } from '@angular/core';
import { GridSettings, HotTableModule } from '@handsontable/angular-wrapper';

@Component({
  standalone: true,
  imports: [HotTableModule],
  selector: 'example1-feature-name',
  template: `
    <div>
      <hot-table [data]="data" [settings]="gridSettings"></hot-table>
    </div>
  `,
})
export class AppComponent {
  readonly data = [...];
  readonly gridSettings: GridSettings = { ... };
}
/* end-file */

/* file: app.config.ts */
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { registerAllModules } from 'handsontable/registry';
import { HOT_GLOBAL_CONFIG, HotGlobalConfig } from '@handsontable/angular-wrapper';

registerAllModules();

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    {
      provide: HOT_GLOBAL_CONFIG,
      useValue: {
        // license: 'your-license-key', // get a key at https://handsontable.com/pricing/
      } as HotGlobalConfig,
    },
  ],
};
/* end-file */

angular/example1.html:

<div>
  <example1-feature-name></example1-feature-name>
</div>

Edit on StackBlitz: docs/public/example-tabs.js merges each framework's companion example*.html into the generated app shell (parseDocsExampleHtmlForStackBlitz uses the browser DOMParser to collect style nodes for <head> and drops script nodes from the body fragment; mergeCompanionHtmlForStackBlitz wires it into the StackBlitz template). Examples with no HTML tab keep the default mount markup.

See skill angular-wrapper-dev for the full reference.

Vue 3

Write every new or updated example as a TypeScript SFC: one exampleN.vue per example, Composition API, <script setup lang="ts">. The example-runner (docs/src/scripts/example-runner.ts) loads vue/example*.vue and mounts them with createApp(). When you touch an old split exampleN.js + exampleN.html example, migrate it to a .vue SFC. New examples use the Composition API, not defineComponent with data()/methods.

<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';

registerAllModules();

const hotSettings = ref<GridSettings>({
  data: [
    ['Acme Corp', 'Q1 2025', '$4.2M'],
    ['Vertex Industries', 'Q1 2025', '$18.7M'],
  ],
  colHeaders: true,
  height: 'auto',
  // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>

<template>
  <div id="example1">
    <HotTable :settings="hotSettings" />
  </div>
</template>
const hotRef = useTemplateRef<InstanceType<typeof HotTable>>('hotRef');   // <HotTable ref="hotRef" :settings="hotSettings" />
const dropdownRef = useTemplateRef<HTMLDivElement>('dropdownRef');         // <div ref="dropdownRef" class="theme-dropdown">

Access the grid with hotRef.value?.hotInstance, a DOM element with dropdownRef.value.

Presets on the ::: example directive select dependencies: :vue3 (default), :vue3-languages, :vue3-vuex. Match the preset to the feature.

Embedding a Vue SFC (single tab, no --html / --js):

::: example #example1 :vue3

@[code](@/content/guides/category/feature/vue/example1.vue)

:::

See skill vue-wrapper-dev for wrapper behavior.

Embedding in the guide

Embed the files with @[code] inside an ::: example container; syntax in the writing-docs-pages skill.

Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.