Svelte
Here’s an example using the ES module in a Svelte or SvelteKit app.
Add the library using npm/yarn/pnpm
npm add -D @trebco/treb
npm add -D @trebco/treb
In a svelte module, import the TREB global instance and the stylesheet;
then call CreateSpreadsheet
to mount the component
<script lang="ts">// import the onMount handler from svelteimport { onMount } from 'svelte';// import TREB module and options typeimport { TREB, type EmbeddedSpreadsheetOptions } from '@trebco/treb';// pass any options as a parameterexport let options: EmbeddedSpreadsheetOptions = {};// reference to the HTML node we will use to mount the spreadsheetlet container: HTMLElement;onMount(() => {// create spreadsheet, passing options// and a reference to the container nodeTREB.CreateSpreadsheet({...options,container,});});</script><div bind:this={container}></div>
<script lang="ts">// import the onMount handler from svelteimport { onMount } from 'svelte';// import TREB module and options typeimport { TREB, type EmbeddedSpreadsheetOptions } from '@trebco/treb';// pass any options as a parameterexport let options: EmbeddedSpreadsheetOptions = {};// reference to the HTML node we will use to mount the spreadsheetlet container: HTMLElement;onMount(() => {// create spreadsheet, passing options// and a reference to the container nodeTREB.CreateSpreadsheet({...options,container,});});</script><div bind:this={container}></div>
<script>// import the onMount handler from svelteimport { onMount } from 'svelte';// import TREB moduleimport { TREB } from '@trebco/treb';// pass any options as a parameterexport let options = {};// reference to the HTML node we will use to mount the spreadsheetlet container;onMount(() => {// create spreadsheet, passing options// and a reference to the container nodeTREB.CreateSpreadsheet({...options,container,});});</script><div bind:this={container}></div>
<script>// import the onMount handler from svelteimport { onMount } from 'svelte';// import TREB moduleimport { TREB } from '@trebco/treb';// pass any options as a parameterexport let options = {};// reference to the HTML node we will use to mount the spreadsheetlet container;onMount(() => {// create spreadsheet, passing options// and a reference to the container nodeTREB.CreateSpreadsheet({...options,container,});});</script><div bind:this={container}></div>
We call CreateSpreadsheet
in a svelte onMount
handler so it’s only called
client-side (it skips server-side rendering).