Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toast): introduce Toast component #4437

Open
wants to merge 61 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a3cf23b
feat: initial commit
macci001 Dec 21, 2024
7024325
chore: adding the animation
macci001 Dec 24, 2024
40eeaa9
chore: nits
macci001 Dec 24, 2024
49e9ece
chore: fixes and adding draft1 of stories
macci001 Dec 25, 2024
e975810
chore: adding the docs draft
macci001 Dec 26, 2024
71c94b3
chore: adding the swiping interaction for toast removal
macci001 Dec 26, 2024
20b4427
chore: adding the tests
macci001 Dec 27, 2024
7f450ae
fix: improving the progress bar logix
macci001 Dec 27, 2024
aa5ff15
chore: refactoring and refining the animations
macci001 Dec 27, 2024
2f12b56
fix: making the animations compatible with the positons
macci001 Dec 28, 2024
2c40c5a
chore: fixing the styles
macci001 Dec 28, 2024
e7cffe2
chore: modifying the animations
macci001 Dec 30, 2024
3473cbd
chore: improving the animations
macci001 Dec 31, 2024
3fa4abb
chore: adding the decorator to the story-book
macci001 Dec 31, 2024
6ed1793
chore: fixing the animations and positions
macci001 Jan 1, 2025
4110aa8
fix: handle expand region on touch
macci001 Jan 1, 2025
1c782c1
feat: adding the promises support
macci001 Jan 1, 2025
38eaa79
chore: updating the styles
macci001 Jan 1, 2025
c72c2af
chore: improving styles
macci001 Jan 2, 2025
9f98f70
chore: styles correction
jrgarciadev Jan 5, 2025
157cf05
fix: adding junior's suggestions
macci001 Jan 6, 2025
c545654
chore: correcting styles
macci001 Jan 6, 2025
39487ac
fix: fixing the timer behavior
macci001 Jan 8, 2025
ded71ee
chore: adding the spinner to the toast
macci001 Jan 8, 2025
4a0c476
chore: full width for mobile
macci001 Jan 8, 2025
5ee89a7
chore: modifying styles
macci001 Jan 8, 2025
bef0ebe
chore: fixing the positions on smaller devices
macci001 Jan 8, 2025
66594b5
chore: adding story with description
macci001 Jan 8, 2025
5313bf4
chore: adding credits for sonner
macci001 Jan 8, 2025
ed70ae4
fix: adding junior's suggestions
macci001 Jan 8, 2025
30ede46
chore: adding the exit animation
macci001 Jan 8, 2025
c9e4bf1
fix: adding junior's suggestions
macci001 Jan 9, 2025
915f7a7
chore: improving the swipe animations
macci001 Jan 9, 2025
faddd87
fix: fixing the swipe animations on touch
macci001 Jan 10, 2025
cd7e4e6
chore: adding tests
macci001 Jan 10, 2025
abd64eb
chore: adding swipe threshild and initial position variable
macci001 Jan 10, 2025
adb5bf9
fix: fixing autoclose in timeout
macci001 Jan 10, 2025
1ce6cb6
chore: modifying the docs
macci001 Jan 10, 2025
e48d507
chore: fixing the conflict
macci001 Jan 20, 2025
4704bea
chore: adding marcus' suggestions
macci001 Jan 20, 2025
f5b2e94
chore: adding the bottom animations
macci001 Jan 21, 2025
33d4ff0
chore: modying docs
macci001 Jan 21, 2025
998faca
chore: removing nextui references
macci001 Jan 21, 2025
c9b38f1
chore: adding info about the provider
macci001 Jan 21, 2025
f8b0068
chore: updating the docs
macci001 Jan 21, 2025
8e8d151
chore: versions in package.json
macci001 Jan 21, 2025
7aef756
chore: nits
macci001 Jan 21, 2025
c49802b
chore: adding junior's suggestions
macci001 Jan 21, 2025
7b59e74
chore: nits
macci001 Jan 22, 2025
9e07f09
fix: applying junior's suggestions
macci001 Jan 24, 2025
4f2c491
chore: adding junior's suggestions
macci001 Jan 27, 2025
4bf2ce6
chore: using domMax
macci001 Jan 27, 2025
d493491
fix: adding Marcus's suggestions
macci001 Jan 28, 2025
70815b6
chore: add global toast props and custom close icon
jrgarciadev Jan 29, 2025
c185a94
chore: adding the defaultTimout provider prop
macci001 Jan 30, 2025
37af67c
chore: modifying defaultTimeout
macci001 Jan 30, 2025
68f2e8d
chore: nits
macci001 Jan 30, 2025
c522947
fix: adding Marcus' suggestions
macci001 Jan 30, 2025
1a04b3f
chore: fixing bg
macci001 Jan 30, 2025
b28cdb7
Merge branch 'canary' into macci001/eng-1736
wingkwong Jan 30, 2025
98331a2
chore(deps): bump RA deps
wingkwong Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/shaggy-beers-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@heroui/shared-icons": patch
"@heroui/toast": patch
"@heroui/theme": patch
---

Introducing the toast component(#2560)
2 changes: 1 addition & 1 deletion apps/docs/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"title": "Toast",
"keywords": "toast, notification, message",
"path": "/docs/components/toast.mdx",
"comingSoon": true
"newPost": true
},
{
"key": "textarea",
Expand Down
24 changes: 24 additions & 0 deletions apps/docs/content/components/toast/color.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {addToast, Button} from "@heroui/react";

export default function App() {
return (
<div className="flex flex-wrap gap-2">
{["default", "primary", "secondary", "success", "warning", "danger"].map((color) => (
<Button
key={color}
color={color}
variant={"flat"}
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
color: color,
})
}
>
{color}
</Button>
))}
</div>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./color.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
44 changes: 44 additions & 0 deletions apps/docs/content/components/toast/custom-close-icon.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {addToast, Button} from "@heroui/react";

const CustomToastComponent = () => {
return (
<Button
variant="flat"
onPress={() => {
addToast({
hideIcon: true,
title: "Toast Title",
description: "Toast Description",
classNames: {
closeButton: "opacity-100 absolute right-4 top-1/2 -translate-y-1/2",
},
closeIcon: (
<svg
fill="none"
height="32"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
width="32"
>
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
),
});
}}
>
Show Toast
</Button>
);
};

export default function App() {
return (
<div className="flex gap-2">
<CustomToastComponent />
</div>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/custom-close-icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./custom-close-icon.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
50 changes: 50 additions & 0 deletions apps/docs/content/components/toast/custom-styles.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {addToast, Button, cn} from "@heroui/react";

const CustomToastComponent = () => {
return (
<Button
variant="flat"
onPress={() => {
addToast({
title: "Successfull!",
description: "Document uploaded to cloud successfully.",
classNames: {
base: cn([
"bg-default-50 dark:bg-background shadow-sm",
"border-1",
"relative before:content-[''] before:absolute before:z-10",
"before:left-0 before:top-[-1px] before:bottom-[-1px] before:w-1",
"rounded-l-none border-l-0",
"min-w-[350px]",
"rounded-md",
"flex flex-col items-start",
"before:bg-primary border-primary-200 dark:border-primary-100",
,
]),
icon: "w-6 h-6 fill-current",
},
endContent: (
<div className="ms-11 my-2 flex gap-x-2">
<Button color={"primary"} size="sm" variant="bordered">
View Document
</Button>
<Button className="underline-offset-2" color={"primary"} size="sm" variant="light">
Maybe Later
</Button>
</div>
),
});
}}
>
Show Toast
</Button>
);
};

export default function App() {
return (
<div className="flex gap-2">
<CustomToastComponent />
</div>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/custom-styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./custom-styles.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
17 changes: 17 additions & 0 deletions apps/docs/content/components/toast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import color from "./color";
import variants from "./variants";
import customStyles from "./custom-styles";
import radius from "./radius";
import placement from "./placement";
import usage from "./usage";
import customCloseIcon from "./custom-close-icon";

export const toastContent = {
color,
variants,
customStyles,
radius,
placement,
usage,
customCloseIcon,
};
36 changes: 36 additions & 0 deletions apps/docs/content/components/toast/placement.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {addToast, Button, ToastProvider} from "@heroui/react";
import React from "react";

export default function App() {
const [placement, setPlacement] = React.useState("right-bottom");

return (
<>
<ToastProvider placement={placement} toastOffset={placement.includes("top") ? 60 : 0} />
<div className="flex flex-wrap gap-2">
{[
"left-top",
"right-top",
"center-top",
"left-bottom",
"right-bottom",
"center-bottom",
].map((position) => (
<Button
key={position}
variant={"flat"}
onPress={() => {
setPlacement(position);
addToast({
title: "Toast title",
description: "Toast displayed successfully",
});
}}
>
{position}
</Button>
))}
</div>
</>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/placement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./placement.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
24 changes: 24 additions & 0 deletions apps/docs/content/components/toast/radius.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {addToast, Button} from "@heroui/react";

export default function App() {
return (
<div className="flex flex-wrap gap-2">
{["none", "sm", "md", "lg", "full"].map((radius) => (
<Button
key={radius}
radius={radius}
variant={"flat"}
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
radius: radius,
})
}
>
{radius}
</Button>
))}
</div>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/radius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./radius.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
118 changes: 118 additions & 0 deletions apps/docs/content/components/toast/usage.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import {addToast, Button} from "@heroui/react";

export default function App() {
return (
<div className="flex flex-wrap gap-2">
<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
});
}}
>
Default
</Button>

<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
description: "Toast Description",
});
}}
>
With Description
</Button>

<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
description: "Toast Description",
hideIcon: true,
});
}}
>
Hidden Icon
</Button>

<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
description: "Toast Description",
promise: new Promise((resolve) => setTimeout(resolve, 3000)),
});
}}
>
Promise (3000ms)
</Button>

<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
description: "Toast Description",
endContent: (
<Button size="sm" variant="flat">
Upgrade
</Button>
),
variant: "faded",
});
}}
>
With endContent
</Button>

<Button
variant="flat"
onPress={() => {
addToast({
title: "Toast Title",
description: "Toast Description",
timeout: 3000,
shouldShowTimeoutProgess: true,
});
}}
>
Show Timeout Progress (3000ms)
</Button>

<Button
variant="flat"
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
icon: (
<svg height={24} viewBox="0 0 24 24" width={24}>
<g
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit={10}
strokeWidth={1.5}
>
<path
d="M11.845 21.662C8.153 21.662 5 21.088 5 18.787s3.133-4.425 6.845-4.425c3.692 0 6.845 2.1 6.845 4.4s-3.134 2.9-6.845 2.9z"
data-name="Stroke 1"
/>
<path d="M11.837 11.174a4.372 4.372 0 10-.031 0z" data-name="Stroke 3" />
</g>
</svg>
),
})
}
>
Custom Icon
</Button>
</div>
);
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import App from "./usage.raw.jsx?raw";

const react = {
"/App.jsx": App,
};

export default {
...react,
};
Loading