Skip to content

Commit ad046d0

Browse files
sarahdayanclaude
andauthored
docs(examples): add expense splitter README, demo, and docs (#827)
## Summary - Add a full-featured expense splitter example (React + Vite + Tailwind) demonstrating `allocate()`, balance tracking, and optimal debt settlement - Add README and docs entry for the example - Deploy the example on Vercel at `v2.dinerojs.com/examples/expense-splitter/` - Rename "Sandboxes" to "Demos" across the docs site ## Test plan - [ ] Run `npm run build -w @dinero.js/example-expense-splitter` and verify it builds - [ ] Run `npm run dev -w @dinero.js/example-expense-splitter` and verify the app works locally - [ ] Verify the base path (`/examples/expense-splitter/`) is reflected in the built assets - [ ] Verify the docs site builds with `npm run docs:build` - [ ] Verify `/sandboxes` redirects to `/demos` --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8348918 commit ad046d0

35 files changed

+2534
-245
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export default defineConfig({
268268
text: 'Resources',
269269
items: [
270270
{ text: 'About', link: '/about' },
271-
{ text: 'Sandboxes', link: '/sandboxes' },
271+
{ text: 'Demos', link: '/demos' },
272272
],
273273
},
274274
],

docs/demos.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Demos
3+
description: Check out Dinero.js in action in working demos.
4+
---
5+
6+
# Demos
7+
8+
If you learn better by seeing code in action, or want to start from an existing project, check out the Dinero.js demos.
9+
10+
## Shopping cart with React
11+
12+
This demo showcases Dinero.js in action in a [React](https://reactjs.org/)-powered shopping cart.
13+
14+
[![Shopping cart with React](/images/examples/cart-react.png)](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/cart-react)
15+
16+
[View demo](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/cart-react)
17+
18+
## Shopping cart with Vue.js
19+
20+
This demo showcases Dinero.js in action in a [Vue.js](https://vuejs.org/)-powered shopping cart.
21+
22+
[![Shopping cart with Vue.js](/images/examples/cart-vue.png)](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/cart-vue)
23+
24+
[View demo](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/cart-vue)
25+
26+
## Pricing page with React
27+
28+
This demo showcases Dinero.js in action in a [React](https://reactjs.org/)-powered pricing page.
29+
30+
[![Pricing page with React](/images/examples/pricing-react.png)](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/pricing-react)
31+
32+
[View demo](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/pricing-react)
33+
34+
## Expense splitter
35+
36+
This demo showcases Dinero.js in action in a [React](https://reactjs.org/)-powered expense splitter. It demonstrates fair bill splitting with `allocate()`, balance tracking, and optimal debt settlement.
37+
38+
[View demo](https://v2.dinerojs.com/examples/expense-splitter/)
39+
40+
## Starter playground
41+
42+
This demo lets you try Dinero.js in a minimal environment. It's ideal to reproduce issues.
43+
44+
[![Starter playground](/images/examples/starter.png)](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/starter)
45+
46+
[View demo](https://codesandbox.io/s/github/dinerojs/dinero.js/tree/main/examples/starter)

docs/sandboxes.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/vercel.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://openapi.vercel.sh/vercel.json",
3-
"buildCommand": "npx vitepress build",
3+
"buildCommand": "npx vitepress build && cd ../examples/expense-splitter && npm install && npm run build && mkdir -p ../../docs/.vitepress/dist/examples/expense-splitter && cp -r dist/* ../../docs/.vitepress/dist/examples/expense-splitter",
44
"outputDirectory": ".vitepress/dist",
55
"redirects": [
66
{
@@ -37,6 +37,11 @@
3737
"source": "/docs/:path*",
3838
"destination": "/:path*",
3939
"statusCode": 308
40+
},
41+
{
42+
"source": "/sandboxes",
43+
"destination": "/demos",
44+
"statusCode": 308
4045
}
4146
]
4247
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Expense Splitter
2+
3+
A React app that splits expenses between friends and calculates optimal settlements, powered by [Dinero.js](https://v2.dinerojs.com).
4+
5+
## What you'll learn
6+
7+
This example demonstrates how to use Dinero.js to solve real-world money problems:
8+
9+
- **Splitting bills fairly** with `allocate()`, handling remainders so no cent is lost
10+
- **Tracking balances** with `add()` and `subtract()` to know who owes whom
11+
- **Simplifying debts** with `compare()`, `greaterThan()`, and `isZero()` to minimize the number of payments
12+
- **Formatting currency** with `toDecimal()` and `Intl.NumberFormat`
13+
- **Persisting money objects** with `toSnapshot()` and `dinero()` for LocalStorage serialization
14+
15+
## Getting started
16+
17+
1. Install dependencies from the **repository root**:
18+
19+
```sh
20+
npm install
21+
```
22+
23+
2. Navigate to the example:
24+
25+
```sh
26+
cd examples/expense-splitter
27+
```
28+
29+
3. Start the dev server:
30+
31+
```sh
32+
npm run dev
33+
```
34+
35+
## Learn more
36+
37+
Check out the [Dinero.js documentation](https://v2.dinerojs.com) to explore the full API.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Dinero.js &amp; React | Expense Splitter</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@dinero.js/example-expense-splitter",
3+
"version": "2.0.0-alpha.15",
4+
"type": "module",
5+
"scripts": {
6+
"build:clean": "rimraf ./dist",
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"serve": "vite preview"
10+
},
11+
"dependencies": {
12+
"dinero.js": "2.0.0-alpha.16",
13+
"react": "^19.0.0",
14+
"react-dom": "^19.0.0"
15+
},
16+
"devDependencies": {
17+
"@tailwindcss/forms": "^0.5.0",
18+
"@types/react": "^19.0.0",
19+
"@types/react-dom": "^19.0.0",
20+
"@vitejs/plugin-react": "^4.3.0",
21+
"autoprefixer": "^10.4.0",
22+
"postcss": "^8.4.0",
23+
"tailwindcss": "^3.4.0",
24+
"typescript": "^5.7.0",
25+
"vite": "^6.0.0"
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
};
Lines changed: 11 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)