An open API service indexing awesome lists of open source software.

https://github.com/oscarrc/crust

Don't throw the crust. An opinionated, crisp, and zero-waste toast library built natively for Astro and React.
https://github.com/oscarrc/crust

astro astrojs react reactjs toast toast-notifications

Last synced: 2 days ago
JSON representation

Don't throw the crust. An opinionated, crisp, and zero-waste toast library built natively for Astro and React.

Awesome Lists containing this project

README

          

# 🍞 Crust

[![npm](https://img.shields.io/npm/v/@oscarrc/crust)](https://www.npmjs.com/package/@oscarrc/crust)
[![CI](https://github.com/oscarrc/crust/actions/workflows/ci.yml/badge.svg)](https://github.com/oscarrc/crust/actions/workflows/ci.yml)
[![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)

Don't throw the crust. An opinionated, crisp, and zero-waste toast library built natively for Astro and React.

Most toast libraries are bloated white bread. They force you into wrapper fatigue, endless configuration files, and a hard React dependency just to slide a notification onto the screen.

**Crust is different.** The renderer is vanilla DOM β€” a React-free Astro site is a first-class citizen, and React gets a thin, concurrent-safe bridge on top. Warm matte surfaces, a capsule that grows into a card as one continuous surface, and rock-solid defaults. Take it or leave it β€” just like the crust.

**[Docs & playground β†’](https://crust.oscarrc.me)**

---

## Why Crust?

- πŸš€ **Astro-first, honestly.** The core renders with plain DOM. No React island required to *show* toasts β€” React is an optional peer dependency.
- πŸ«™ **One shared store.** Trigger from an Astro ``, a React island, or anywhere else: same toaster, same stack, no provider, no context.
- πŸ”₯ **Crisp & opinionated.** A tactile morph-expand interaction and an organic motion profile (ease-out-quint, nothing over 320ms, zero bounce). No spending 40 minutes tweaking cubic-bΓ©ziers.
- β™Ώ **Accessible by default.** `aria-live` region, keyboard-reachable dismiss, timers that pause while you read, and `prefers-reduced-motion` as a first-class theme.
- πŸ“¦ **Zero-waste footprint.** ESM-only, ~2 KB of JS, one CSS file, no dependencies.

## Quickstart

Install the package:

```bash
pnpm add @oscarrc/crust
```

Import the styles and mount the toaster once, at the root of your layout β€” no React, no provider:

```ts
import '@oscarrc/crust/styles.css';
import { mountToaster } from '@oscarrc/crust/vanilla';

mountToaster(); // bottom-right by default
```

Then bake toasts from anywhere:

```ts
import { toast } from '@oscarrc/crust/vanilla';

toast.success('Fresh bread out of the oven!');

// A message makes a toast expandable β€” it morphs open on hover/focus/tap,
// or on its own with `expandAfter`:
toast('Order update', {
message: 'Your order shipped today.',
expandAfter: 2000 // auto-expands 2s after becoming visible
});

// Async flows: loading β†’ success/error, opening the outcome by itself:
toast.promise(saveDraft(), {
loading: 'Saving…',
success: (draft) => ({ title: 'Saved', message: `β€œ${draft.name}” is safe.` }),
error: 'Save failed'
}, { expandOnSettle: true });
```

That's the whole setup. For React islands, view transitions, theming, and the rest, read on β€” or head to the **[docs & playground](https://crust.oscarrc.me)**.

## Usage

### 1. Pure Astro / vanilla JS β€” zero React

```astro
---
// src/layouts/Layout.astro
import '@oscarrc/crust/styles.css';
---
<html>
<body>
<slot />
<script>
import { mountToaster } from '@oscarrc/crust/vanilla';
mountToaster();