Skip to main content

registerToolbarItem

registerToolbarItem(key: string, component: SvelteComponent)

this helper allows to register custom components as elements in the toolbar

Usage

Register custom component as toolbar's element

<script>
import { Toolbar, registerToolbarItem } from "wx-svelte-toolbar";
import { Text } from "wx-svelte-core";

// register custom component
registerToolbarItem("text", Text);
</script>

<Toolbar
items={[
{ id: "label", text: "Toolbar with text input" },
{ id: "search", comp: "text" },
]}
/>

Create custom button control for toolbar

in myControl.svelte

<script>
export let menu;
export let text;
</script>

<button class:menu onclick>{text}</button>

<style>
.menu {
font-weight: bold;
}
</style>
  • custom control can fire onclick event on activation
  • menu property will be set to true, when component is inside of popup menu
  • any other property set in the item object will be available

in App.svelte

<script>
import { Toolbar, registerToolbarItem } from "wx-svelte-toolbar";
import MyControl from "./MyControl.svelte";

// register custom component
registerToolbarItem("cb", MyControl);
</script>

<Toolbar
items={[
{ id: "label", text: "Toolbar with custom button" },
{ id: "search", comp: "cb" },
]}
/>

Create custom input control for toolbar

in myControl.svelte

<script>
export let value;
export let type = "text";
</script>

<input type="text" bind:value />
  • value property will contain initial value
  • changes to value will be reflected in toolbars state
  • any other property set in the item object will be available

in App.svelte

<script>
import { Toolbar, registerToolbarItem } from "wx-svelte-toolbar";
import MyControl from "./MyControl.svelte";

// register custom component
registerToolbarItem("ci", MyControl);
</script>

<Toolbar
items={[
{ id: "label", text: "Toolbar with custom input" },
{ id: "search", comp: "ci", type: "search" },
]}
/>