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 49 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
976c903
feat: initial commit
macci001 Dec 21, 2024
f1b5089
chore: adding the animation
macci001 Dec 24, 2024
3c60244
chore: nits
macci001 Dec 24, 2024
ff91ad1
chore: fixes and adding draft1 of stories
macci001 Dec 25, 2024
312aa31
chore: adding the docs draft
macci001 Dec 26, 2024
d2b0e6a
chore: adding the swiping interaction for toast removal
macci001 Dec 26, 2024
4a74835
chore: adding the tests
macci001 Dec 27, 2024
c5325f2
fix: improving the progress bar logix
macci001 Dec 27, 2024
926f5d1
chore: refactoring and refining the animations
macci001 Dec 27, 2024
021be8f
fix: making the animations compatible with the positons
macci001 Dec 28, 2024
4e09810
chore: fixing the styles
macci001 Dec 28, 2024
95cd0f9
chore: modifying the animations
macci001 Dec 30, 2024
bd0ac74
chore: improving the animations
macci001 Dec 31, 2024
91b9eee
chore: adding the decorator to the story-book
macci001 Dec 31, 2024
a7fad47
chore: fixing the animations and positions
macci001 Jan 1, 2025
6249473
fix: handle expand region on touch
macci001 Jan 1, 2025
70dbdb7
feat: adding the promises support
macci001 Jan 1, 2025
30daf7c
chore: updating the styles
macci001 Jan 1, 2025
e938e09
chore: improving styles
macci001 Jan 2, 2025
153857d
chore: styles correction
jrgarciadev Jan 5, 2025
ad25bff
fix: adding junior's suggestions
macci001 Jan 6, 2025
4a79ed7
chore: correcting styles
macci001 Jan 6, 2025
db3ad3a
fix: fixing the timer behavior
macci001 Jan 8, 2025
5d76c68
chore: adding the spinner to the toast
macci001 Jan 8, 2025
5b0f424
chore: full width for mobile
macci001 Jan 8, 2025
db7dd13
chore: modifying styles
macci001 Jan 8, 2025
0fa2031
chore: fixing the positions on smaller devices
macci001 Jan 8, 2025
42130bb
chore: adding story with description
macci001 Jan 8, 2025
df8e41c
chore: adding credits for sonner
macci001 Jan 8, 2025
da2820b
fix: adding junior's suggestions
macci001 Jan 8, 2025
ab222e1
chore: adding the exit animation
macci001 Jan 8, 2025
22d638b
fix: adding junior's suggestions
macci001 Jan 9, 2025
3dd9e0e
chore: improving the swipe animations
macci001 Jan 9, 2025
a431a38
fix: fixing the swipe animations on touch
macci001 Jan 10, 2025
14af24f
chore: adding tests
macci001 Jan 10, 2025
8352cc8
chore: adding swipe threshild and initial position variable
macci001 Jan 10, 2025
5562ba1
fix: fixing autoclose in timeout
macci001 Jan 10, 2025
91b44bb
chore: modifying the docs
macci001 Jan 10, 2025
b4225e7
chore: fixing the conflict
macci001 Jan 20, 2025
90f223c
chore: adding marcus' suggestions
macci001 Jan 20, 2025
8197ece
chore: adding the bottom animations
macci001 Jan 21, 2025
55328b5
chore: modying docs
macci001 Jan 21, 2025
f08752b
chore: removing nextui references
macci001 Jan 21, 2025
383833e
chore: adding info about the provider
macci001 Jan 21, 2025
993c64a
chore: updating the docs
macci001 Jan 21, 2025
6190836
chore: versions in package.json
macci001 Jan 21, 2025
05e06b9
chore: nits
macci001 Jan 21, 2025
18455c7
chore: adding junior's suggestions
macci001 Jan 21, 2025
5904d13
chore: nits
macci001 Jan 22, 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 @@
---
"@nextui-org/shared-icons": patch
"@nextui-org/toast": patch
"@nextui-org/theme": patch
macci001 marked this conversation as resolved.
Show resolved Hide resolved
---

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
28 changes: 28 additions & 0 deletions apps/docs/content/components/toast/color.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {addToast, Button} from "@heroui/react";

export default function App() {
return (
<>
<div className="flex flex-wrap gap-x-2">
{["default", "primary", "secondary", "success", "warning", "danger"].map((color) => (
<Button
key={color}
// @ts-ignore
color={color}
variant={"solid"}
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
// @ts-ignore
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 Color from "./color.raw.jsx?raw";

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

export default {
...react,
};
54 changes: 54 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,54 @@
import {addToast, Button, cn} from "@heroui/react";

const CustomToastComponent = () => {
return (
<>
<Button
variant="solid"
onPress={() => {
addToast({
title: "Sucessful!",
description: "Document uploaded to cloud successful.",
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 CustomStyles from "./custom-styles.raw.jsx?raw";

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

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 provider from "./provider";
import types from "./types";

export const toastContent = {
color,
variants,
customStyles,
radius,
placement,
provider,
types,
};
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-x-2">
{[
"left-top",
"right-top",
"center-top",
"left-bottom",
"right-bottom",
"center-bottom",
].map((position) => (
<Button
key={position}
variant={"solid"}
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 Position from "./placement.raw.jsx?raw";

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

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

export default function App({children}) {
return <ToastProvider>{children}</ToastProvider>;
}
9 changes: 9 additions & 0 deletions apps/docs/content/components/toast/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Provider from "./provider.raw.jsx?raw";

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

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

export default function App() {
return (
<>
<div className="flex flex-wrap gap-x-2">
{["none", "sm", "md", "lg", "full"].map((radius) => (
<Button
key={radius}
radius={radius}
variant={"solid"}
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
// @ts-ignore
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 Radius from "./radius.raw.jsx?raw";

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

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

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

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

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

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

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

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

<Button
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/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Types from "./types.raw.jsx?raw";

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

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

export default function App() {
return (
<>
<div className="flex flex-wrap gap-x-2">
{[
["solid", "solid"],
["bordered", "bordered"],
["flat", "faded"],
].map((variant) => (
<Button
key={variant[0]}
// @ts-ignore
variant={variant[1]}
onPress={() =>
addToast({
title: "Toast title",
description: "Toast displayed successfully",
// @ts-ignore
variant: variant[0],
color: "secondary",
})
}
>
{variant[0]}
</Button>
))}
</div>
</>
);
}
Loading
Loading