Adding an example to the Gallery
We welcome anyone to submit an example to our gallery.
Overview
Add your example to the website in the directory packages/website/src/examples
. Before submitting
a pull request, make sure you have done the following:
- Made a directory with all of the required files
- Updated the list of examples in
examples-list.tsx
to include yours - Added light and dark screenshots of your example to the
_previews
directory aspng
files - Verified the example works in each of our supported UI frameworks (how-to guide here)
Required Files
Your directory should be called your-example-name
. In it, you will need to have files for all
of our supported UI frameworks (angular, react, svelte and vanilla typescript) as well as a data
and index
file. The structure looks like:
your-example
├── data.ts
├── index.tsx
├── your-example.component.html # ┓
├── your-example.component.ts # ┠ angular
├── your-example.module.ts # ┛
├── your-example.svelte # svelte
├── your-example.ts # typescript
├── your-example.tsx # react
What to include in index.tsx
All example index files look roughly the same, you will just need to fill in the highlighted lines. You can copy and paste the following:
/* eslint-disable import/no-unresolved, import/no-webpack-loader-syntax, @typescript-eslint/no-var-requires */
import React from 'react'
import BrowserOnly from '@docusaurus/BrowserOnly'
import { Example } from '@site/src/types/example'
const pathname = ''
const example: Example = {
component: () => <BrowserOnly>{() => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const Component = require(`./${pathname}.tsx`).default
return <Component />
}}</BrowserOnly>,
pathname,
title: '',
description: <div></div>,
codeReact: require(`!!raw-loader!./${pathname}.tsx`).default,
codeTs: require(`!!raw-loader!./${pathname}.ts`).default,
codeAngular: {
html: require(`!!raw-loader!./${pathname}.component.html`).default,
component: require(`!!raw-loader!./${pathname}.component.ts`).default,
module: require(`!!raw-loader!./${pathname}.module.ts`).default,
},
codeSvelte: require(`!!raw-loader!./${pathname}.svelte`).default,
data: require('!!raw-loader!./data').default,
preview: require(`../_previews/${pathname}.png`).default,
previewDark: require(`../_previews/${pathname}-dark.png`).default,
}
export default example
- pathname should correspond to your directory name
- title should reference the library component(s) your using
- description should be a brief description of your visualization with any data sources cited
Testing each framework
Before you submit a pull request, be sure you have verified that the example works for each
framework on your local machine. In the packages/website
directory, you can view your example
by following the steps below:
React
- Run the command
npm run start
- Open localhost:9300 and navigate to your example's page
TypeScript
Same steps above, but add &ts
to the end of the url.
Svelte
- Add your example's
svelte
file path to theimports
array insrc-demo/svelte-gallery.svelte
- From the terminal, run the command
cd packages/svelte
npm run gallery
Vue
- Add your example's
vue
file path to theimports
array insrc-demo/App.vue
- From the terminal, run the command
cd packages/vue
npm run gallery
Solid
- Add your example's
-solid.tsx
file path to theimports
array insrc-demo/app.tsx
- From the terminal, run the command
cd packages/solid
npm run gallery
Angular
- Import your angular module in
gallery/src/main.ts
- Add the imported module to the
imports
field in theNgModule
decorator:
@NgModule({
declarations: [AppComponent],
imports: [... /* your angular module here */],
bootstrap: [AppComponent],
providers: [BrowserModule],
})
- Add the example component's selector to the
Component
decorator'stemplate
field:
@Component({
selector: 'app-component',
template: `
...
<!-- your angular selector -->
`
})
- From the terminal, run the command
cd packages/angular
npm run gallery