Skip to content

Commit 8be0e27

Browse files
Shrinks99claude
andauthored
Fix Toast colours (#60)
Co-authored-by: Claude <claude@users.noreply.github.com>
1 parent de13bb9 commit 8be0e27

6 files changed

Lines changed: 73 additions & 85 deletions

File tree

packages/demo/src/components/demo/toast.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import { Button, useToast, ToastAction } from "@eqtylab/equality";
33
export const ToastDemo = ({
44
variant = "default",
55
}: {
6-
variant?:
7-
| "default"
8-
| "danger"
9-
| "warning"
10-
| "success"
11-
| "with-title"
12-
| "with-action";
6+
variant?: "default" | "danger" | "warning" | "success" | "with-action";
137
}) => {
148
const { toast } = useToast();
159

@@ -80,23 +74,6 @@ export const ToastDemo = ({
8074
);
8175
}
8276

83-
if (variant === "with-title") {
84-
return (
85-
<Button
86-
size="sm"
87-
onClick={() => {
88-
toast({
89-
variant: "default",
90-
title: "Notification",
91-
description: "This toast includes both a title and description.",
92-
});
93-
}}
94-
>
95-
Show Toast with Title
96-
</Button>
97-
);
98-
}
99-
10077
if (variant === "with-action") {
10178
return (
10279
<Button

packages/demo/src/content/components/toast.mdx

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import { ToastRoot } from "@eqtylab/equality";
1111

1212
## Overview
1313

14-
---
14+
The Toast component provides a non-intrusive way to display notifications to users. It supports status-dependant variants, optional (though suggested) titles and descriptions, and action buttons. Toasts automatically dismiss after a delay and can be manually dismissed via a close button.
1515

16-
The Toast component provides a non-intrusive way to display notifications to users. Built on top of Radix UI primitives, it supports multiple variants (default, danger, warning, success), optional titles and descriptions, and action buttons. Toasts automatically dismiss after a delay and can be manually dismissed via a close button.
16+
Because toasts disappear automatically after five seconds, it is not recommended to make any actions surfaced within them solely available in the toast. For example, this could be used to give users an opportunity to undo their previous action, but the undo action should also be made available outside of the toast component.
1717

1818
## Variants
1919

20+
When `title` is present, toasts display variant-specific icons by default.
21+
2022
### Default
2123

2224
<ToastDemo client:only="react" />
@@ -33,25 +35,21 @@ The Toast component provides a non-intrusive way to display notifications to use
3335

3436
<ToastDemo client:only="react" variant="success" />
3537

36-
### With Title
37-
38-
<ToastDemo client:only="react" variant="with-title" />
39-
4038
### With Action
4139

4240
<ToastDemo client:only="react" variant="with-action" />
4341

4442
## Usage
4543

46-
---
44+
Import the components and hooks:
4745

48-
### Setup
46+
```tsx
47+
import { ToastRoot, useToast } from "@eqtylab/equality";
48+
```
4949

50-
First, add the `ToastRoot` component to your application root. This component provides the toast context and viewport:
50+
First, add the `ToastRoot` component to your application root:
5151

5252
```tsx
53-
import { ToastRoot } from "@eqtylab/equality";
54-
5553
function App() {
5654
return (
5755
<>
@@ -62,67 +60,59 @@ function App() {
6260
}
6361
```
6462

65-
### Basic Usage
66-
67-
Import the `useToast` hook in any component where you want to display toasts:
63+
Basic usage with the `useToast` hook:
6864

6965
```tsx
70-
import { useToast } from "@eqtylab/equality";
71-
7266
function MyComponent() {
7367
const { toast } = useToast();
7468

7569
const handleClick = () => {
7670
toast({
77-
description: "This is a toast notification.",
71+
title: "Success",
72+
description: "Your changes have been saved.",
73+
variant: "success",
7874
});
7975
};
8076

8177
return <button onClick={handleClick}>Show Toast</button>;
8278
}
8379
```
8480

85-
### Toast API
81+
## Props
8682

87-
The `toast` function accepts the following options:
83+
| Name | Description | Type | Default | Required |
84+
| -------------- | --------------------------------------------------------------------------- | ----------------------------------------- | --------------------- | -------- |
85+
| `variant` | Visual style of the toast with default icon | `default`, `danger`, `warning`, `success` | `default` ||
86+
| `title` | Title text displayed with an icon | `React.ReactNode` | - ||
87+
| `description` | Main message content | `React.ReactNode` | - ||
88+
| `icon` | Custom icon (string for Lucide icon name or React element, null to disable) | `string \| React.ReactElement \| null` | Variant-specific icon ||
89+
| `action` | Action button element | `ToastActionElement` | - ||
90+
| `open` | Control the open state | `boolean` | `true` ||
91+
| `onOpenChange` | Callback when open state changes | `(open: boolean) => void` | - ||
8892

89-
- `variant?: "default" | "danger" | "warning" | "success"` - Visual variant of the toast
90-
- `title?: React.ReactNode` - Optional title displayed at the top of the toast
91-
- `description?: React.ReactNode` - Main message content
92-
- `action?: ToastActionElement` - Optional action button element
93-
- `open?: boolean` - Control the open state (defaults to `true`)
94-
- `onOpenChange?: (open: boolean) => void` - Callback when open state changes
93+
### Toast Instance Methods
9594

96-
The `toast` function returns an object with:
95+
The `toast` function returns an object with the following methods:
9796

98-
- `id: string` - Unique identifier for the toast
99-
- `dismiss: () => void` - Function to manually dismiss the toast
100-
- `update: (props: ToasterToast) => void` - Function to update the toast properties
97+
| Method | Description | Type |
98+
| --------- | --------------------------------------- | ------------------------------- |
99+
| `id` | Unique identifier for the toast | `string` |
100+
| `dismiss` | Function to manually dismiss the toast | `() => void` |
101+
| `update` | Function to update the toast properties | `(props: ToasterToast) => void` |
101102

102-
### Examples
103+
## Examples
103104

104-
#### Basic Toast
105+
### Basic Toast
105106

106107
```tsx
107-
import { useToast } from "@eqtylab/equality";
108-
109108
const { toast } = useToast();
110109

111110
toast({
112111
description: "Your changes have been saved.",
113112
});
114113
```
115114

116-
#### Toast with Title
117-
118-
```tsx
119-
toast({
120-
title: "Success",
121-
description: "Your changes have been saved successfully.",
122-
});
123-
```
124-
125-
#### Toast with Variant
115+
### Toast with Title and Variant
126116

127117
```tsx
128118
toast({
@@ -132,12 +122,10 @@ toast({
132122
});
133123
```
134124

135-
#### Toast with Action
125+
### Toast with Action
136126

137127
```tsx
138-
import { useToast, ToastAction } from "@eqtylab/equality";
139-
140-
const { toast } = useToast();
128+
import { ToastAction } from "@eqtylab/equality";
141129

142130
toast({
143131
title: "Action Required",
@@ -146,11 +134,9 @@ toast({
146134
});
147135
```
148136

149-
#### Updating a Toast
137+
### Updating a Toast
150138

151139
```tsx
152-
const { toast } = useToast();
153-
154140
const toastInstance = toast({
155141
description: "Uploading...",
156142
});
@@ -162,11 +148,9 @@ toastInstance.update({
162148
});
163149
```
164150

165-
#### Dismissing a Toast
151+
### Dismissing a Toast
166152

167153
```tsx
168-
const { toast } = useToast();
169-
170154
const toastInstance = toast({
171155
description: "Processing...",
172156
});

packages/ui/src/components/toast/toast-components.module.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
.toast--default {
2424
--mix-color: var(--color-brand-primary);
2525
--hover-darken: 50%;
26-
@apply border-brand-primary text-brand-primary bg-mixed-dark;
26+
@apply border-badge-text-primary bg-badge-background-primary text-badge-text-primary;
2727
}
2828

2929
.toast--danger {
30-
@apply border-red-400 bg-red-800 text-red-400;
30+
@apply border-badge-text-danger bg-badge-background-danger text-badge-text-danger;
3131
}
3232

3333
.toast--warning {
34-
@apply border-yellow-400 bg-yellow-800 text-yellow-400;
34+
@apply border-badge-text-warning bg-badge-background-warning text-badge-text-warning;
3535
}
3636

3737
.toast--success {
38-
@apply border-emerald-400 bg-emerald-800 text-emerald-400;
38+
@apply border-badge-text-success bg-badge-background-success text-badge-text-success;
3939
}
4040

4141
.toast-action {
@@ -86,5 +86,5 @@
8686
}
8787

8888
.toast-description {
89-
@apply text-text-secondary text-sm;
89+
@apply text-sm;
9090
}

packages/ui/src/components/toast/toast.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
.toast-action {
88
@apply mt-2 flex justify-end gap-1;
99
}
10+
11+
.toast-title-container {
12+
@apply flex gap-2;
13+
}

packages/ui/src/components/toast/toast.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Icon } from '@/components/icon/icon';
12
import {
23
ToastClose,
34
ToastContainer,
@@ -14,12 +15,33 @@ interface ToastProps {
1415
}
1516

1617
const Toast = ({ toast }: ToastProps) => {
17-
const { id, title, description, action, ...props } = toast;
18+
const { id, title, description, action, icon, variant, ...props } = toast;
19+
20+
// Default icons based on variant
21+
const getDefaultIcon = () => {
22+
switch (variant) {
23+
case 'success':
24+
return 'Check';
25+
case 'warning':
26+
return 'AlertOctagon';
27+
case 'danger':
28+
return 'AlertTriangle';
29+
default:
30+
return 'Info';
31+
}
32+
};
33+
34+
const displayIcon = icon !== undefined ? icon : getDefaultIcon();
1835

1936
return (
20-
<ToastContainer {...props}>
37+
<ToastContainer {...props} variant={variant}>
2138
<div className={styles['toast-copy']}>
22-
{title && <ToastTitle>{title}</ToastTitle>}
39+
{title && (
40+
<div className={styles['toast-title-container']}>
41+
{displayIcon && <Icon icon={displayIcon} size="sm" background="transparent" />}
42+
<ToastTitle>{title}</ToastTitle>
43+
</div>
44+
)}
2345
{description && <ToastDescription>{description}</ToastDescription>}
2446
</div>
2547
{action && <div className={styles['toast-action']}>{action}</div>}

packages/ui/src/hooks/use-toast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type ToasterToast = ToastProps & {
1010
title?: React.ReactNode;
1111
description?: React.ReactNode;
1212
action?: ToastActionElement;
13+
icon?: string | React.ReactElement;
1314
};
1415

1516
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)