chore: fixing the placement option in toast docs (#4857)

This commit is contained in:
Maharshi Alpesh 2025-02-19 16:20:27 +05:30 committed by GitHub
parent 943dfdbd66
commit 99d1674793
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 10 deletions

View File

@ -1,7 +1,7 @@
"use client";
import * as React from "react";
import {HeroUIProvider, ToastProvider} from "@heroui/react";
import {HeroUIProvider} from "@heroui/react";
import {ThemeProvider as NextThemesProvider} from "next-themes";
import {ThemeProviderProps} from "next-themes";
import {useRouter} from "next/navigation";
@ -44,7 +44,6 @@ export function Providers({children, themeProps}: ProvidersProps) {
return (
<ProviderWrapper>
<HeroUIProvider navigate={router.push}>
<ToastProvider />
<NextThemesProvider {...themeProps}>{children}</NextThemesProvider>
</HeroUIProvider>
</ProviderWrapper>

View File

@ -1,15 +1,26 @@
import {addToast, Button} from "@heroui/react";
import {addToast, ToastProvider, Button} from "@heroui/react";
import React from "react";
export default function App() {
const [placement, setPlacement] = React.useState("bottom-right");
return (
<div className="flex flex-wrap gap-2">
{["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"].map(
(position) => (
<>
<ToastProvider placement={placement} toastOffset={placement.includes("top") ? 60 : 0} />
<div className="flex flex-wrap gap-2">
{[
"top-left",
"top-center",
"top-right",
"bottom-left",
"bottom-center",
"bottom-right",
].map((position) => (
<Button
key={position}
variant={"flat"}
onPress={() => {
setPlacement(position);
addToast({
title: "Toast title",
description: "Toast displayed successfully",
@ -18,8 +29,8 @@ export default function App() {
>
{position}
</Button>
),
)}
</div>
))}
</div>
</>
);
}

View File

@ -303,7 +303,7 @@ Toast has the following slots:
},
{
attribute: "placement",
type: "bottom-right" | "bottom-left" | "bottom-center" | "top-right" | "top-left" | "top-center",
type: "bottom-right | bottom-left | bottom-center | top-right | top-left | top-center",
description: "The placement of the toast.",
default: "bottom-right"
},