Getting Started
Edit This PageThis page will guide you through the process of adding Fluid to your existing Svelte project. If you don’t have a Svelte or SvelteKit project already, you can create one using this guide.
Step 1: Install the Library
This will install Fluid and it’s required dependencies. This can be done using a package manager of your choice.
Step 2: Add Theme File
Fluent Svelte components use a set of common resources to style their elements. These values are defined in a theme file that must be imported into your project before components can render properly.
src/App.svelte
(or src/routes/__layout.svelte
if using SvelteKit)
<script>
import "@riversidevalley/fluid/theme.css";
</script>
Alternatively, you can import the theme file from a CDN (though this generally isn’t recommended).
<style>
@import url("https://unpkg.com/@riversidevalley/fluid/theme.css");
/* ...or @import url("https://cdn.jsdelivr.net/npm/@riversidevalley/fluid/theme.css"); */
</style>
Step 3: Importing a Component
Components are exported from a single index file in the library. They can be imported and used in your project like so:
<script>
import { Button, Checkbox } from "@riversidevalley/fluid";
</script>
<Button>Click me!</Button>
<Checkbox>Check me!</Checkbox>
Alternatively you can import under a namespace:
<script>
import * as Fluent from "@riversidevalley/fluid";
</script>
<Fluent.Button>Click me!</Fluent.Button>
<Fluent.Checkbox>Check me!</Fluent.Checkbox>
Svelte REPL Usage
@riversidevalley/fluid
components can also be imported into the Svelte REPL.
In the REPL, packages are automatically installed by name when using an import
statement, so the installation step can be skipped. Because the REPL doesn’t support importing CSS in node_modules
, we’ll need to import the theme file through a CDN.
<script>
import { Button, Checkbox } from "@riversidevalley/fluid";
</script>
<button>Click me!</button>
<style>
@import url("https://unpkg.com/@riversidevalley/fluid/theme.css");
/* Some base styles to get things looking right. */
:global(body) {
background-color: var(--fds-solid-background-base);
color: var(--fds-text-primary);
}
</style>
View this in the REPL