Documentation Upgrade
Start here
The toast system is a small context-based API rather than a single component. Create the context once, mount a container once, and then call `toast.add(...)` anywhere below that tree.
Copy-paste examples
These snippets intentionally show the full public API surface the live demo relies on.
Create the toast system in a layout
Mount the context and container once at the top of the route tree.
// src/routes/+layout.svelte
<script lang="ts">
import { createCwToastContext, CwToastContainer } from '@cropwatchdevelopment/cwui';
createCwToastContext(5);
</script>
<slot />
<CwToastContainer />
Trigger success, warning, and sticky toasts
Use the toast API anywhere below the provider.
<script lang="ts">
import { CwButton, useCwToast } from '@cropwatchdevelopment/cwui';
const toast = useCwToast();
</script>
<CwButton onclick={() => toast.add({ tone: 'success', message: 'Saved!' })}>
Show success
</CwButton>
<CwButton
variant="secondary"
onclick={() =>
toast.add({
tone: 'warning',
message: 'Gateway has not checked in for 15 minutes.',
duration: 10000,
dismissible: true
})
}
>
Show warning
</CwButton>