Flowbite
Installation
npm i @sjsf/flowbite-theme
yarn add @sjsf/flowbite-theme
pnpm add @sjsf/flowbite-theme
bun add @sjsf/flowbite-theme
Install Flowbite Svelte
Quickstart - Flowbite Svelte
Setup styles
There is two ways to setup styles:
- Tailwind configuration
import flowbite from 'flowbite/plugin';import { THEME_CONTENT, FLOWBITE_CONTENT } from '@sjsf/flowbite-theme/preset'
/** @type {import('tailwindcss').Config} */export default { content: ['./src/**/*.{html,js,svelte,ts}', THEME_CONTENT, FLOWBITE_CONTENT], plugins: [flowbite],}
- Inject prepared styles (not recommended)
// Inject them as you likeimport flowbiteStyles from "@sjsf/flowbite-theme/styles.css?inline";
Additional widgets
toggle
Demo
<script lang="ts"> import { RawForm } from "@sjsf/form"; import { theme } from "@sjsf/flowbite-theme";
import { useAstro } from "@/astro.svelte"; import { createCustomForm } from "@/components/custom-form";
import { schema, uiSchema } from "./_demo-schema";
const astro = useAstro();
const form = createCustomForm({ ...theme, schema, uiSchema, });</script>
<RawForm {form} novalidate class="flex flex-col gap-4 mb-4 {astro.darkOrLight}"/>
<pre>{JSON.stringify(form.value, null, 2)}</pre>
import type { Schema, UiSchemaRoot } from "@sjsf/form";
export const schema: Schema = { type: "object", title: "Demo schema", properties: { checkbox: { type: "boolean", }, number: { type: "number", minimum: 5, }, range: { type: "integer", }, text: { type: "string", }, textarea: { type: "string", }, file: { type: "string", format: "data-url", }, select: { type: "string", enum: ["one", "two", "three"], }, multiSelect: { type: "array", items: { type: "string", enum: ["one", "two", "three"], }, uniqueItems: true, }, radio: { type: "string", enum: ["one", "two", "three"], }, checkboxes: { type: "array", items: { type: "string", enum: ["one", "two", "three"], }, uniqueItems: true, }, array: { type: "array", items: { type: "string", }, } }, additionalProperties: { type: "integer", }};
export const uiSchema: UiSchemaRoot = { range: { "ui:options": { "input": { type: "range", } } }, textarea: { "ui:widget": "textarea", }, radio: { "ui:widget": "radio", }, checkboxes: { "ui:widget": "checkboxes", }}