Overview
Learn how to install Flexiboards and create your first Flexiboard.
Installation
Flexiboards is available from npm, and can be installed using your preferred package manager:
npm install svelte-flexiboardspnpm add svelte-flexiboardsyarn add svelte-flexiboardsFlexiboards was built from the ground up to be a Svelte 5 library, so it is incompatible with Svelte 4 or earlier.
Anatomy of a Flexiboard
Flexiboards are constructed from a series of components, namely FlexiBoard, FlexiTarget, and FlexiWidget. When used together, they allow you to build drag-and-drop grids for various use cases.
Below is a diagram showing the anatomy of a Flexiboard that would be used for a todos board.
<FlexiBoard>
 <FlexiTarget>
 <FlexiWidget>
 Snippet | Component
<FlexiTarget>
 <FlexiWidget>
 Snippet | Component
<FlexiWidget>
 Snippet | Component
Here’s how you would create a board like this in Svelte, using Flexiboards:
Incomplete
Done
Loading code...
<script lang="ts">
	import {
		FlexiBoard,
		FlexiTarget,
		FlexiWidget,
		type FlexiWidgetController
	} from 'svelte-flexiboards';
</script>
<div class="not-prose">
	<FlexiBoard
		class="flex flex-col justify-center gap-8 lg:flex-row"
		config={{
			targetDefaults: {
				layout: {
					type: 'flow',
					flowAxis: 'row',
					placementStrategy: 'append'
				}
			},
			widgetDefaults: {
				draggable: true,
				className: (widget: FlexiWidgetController) => {
					return [
						'bg-muted px-4 py-2 rounded-lg w-64',
						widget.isShadow && 'opacity-50',
						widget.isGrabbed && 'animate-pulse opacity-50'
					];
				}
			}
		}}
	>
		<div class="rounded-xl border bg-background px-4 py-2">
			<h5 class="mb-4 text-lg font-semibold">Incomplete</h5>
			<FlexiTarget key="todo" class="gap-2">
				<FlexiWidget>Study for exam</FlexiWidget>
				<FlexiWidget>Research for project</FlexiWidget>
			</FlexiTarget>
		</div>
		<div class="rounded-xl border bg-background px-4 py-2">
			<h5 class="mb-4 text-lg font-semibold">Done</h5>
			<FlexiTarget key="done" class="gap-2">
				<FlexiWidget>Purchase eggs</FlexiWidget>
				<FlexiWidget>Recharge car</FlexiWidget>
				<FlexiWidget>Feed the cat</FlexiWidget>
			</FlexiTarget>
		</div>
	</FlexiBoard>
</div>
In a Flexiboard, each of these components serves a specific purpose:
- FlexiBoardis the main container for the board, creating the drag-and-drop environment. It isolates the targets and widgets; you can have multiple boards on a single page, but widgets cannot be dragged between different FlexiBoards.
- FlexiTargetis a dropzone and container for widgets. You can store widgets within it in a customisable layout, and you can move widgets between different FlexiTargets of the same board.
- FlexiWidgetis the widget itself. These can be moved, resized, and customised in a number of ways. Within a FlexiWidget, you can render content in two ways: either you can use the- childrensnippet, or you can use the- componentprop to render any custom component of your choosing. You can also combine them, which is helpful if you want to have a series of consistent looking widgets that can still render their own component.