fix: toast styles

This commit is contained in:
Junior Garcia 2025-02-16 12:15:26 -03:00
parent 7c41e278eb
commit b6a9cc1bb8
7 changed files with 31 additions and 30 deletions

View File

@ -0,0 +1,6 @@
---
"@heroui/toast": patch
"@heroui/theme": patch
---
Fix toast styles

View File

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

View File

@ -13,18 +13,24 @@ export function ScriptProviders({ isKapaEnabled = true }: { isKapaEnabled?: bool
}, []);
React.useEffect(() => {
function hideKapa() {
const kapaElements = document.querySelectorAll('[id^="kapa-"]');
const display = pathname.includes("toast") ? "none" : "block";
const display = pathname === "/docs/components/toast" ? "none" : "block";
kapaElements.forEach(element => (element as HTMLElement).style.display = display);
}, [pathname]);
if (!isKapaEnabled || !isMounted) {
kapaElements.forEach((element) => (element as HTMLElement).style.display = display);
}
setTimeout(() => {
hideKapa();
}, 500);
}, [pathname, isMounted]);
if (!isKapaEnabled) {
return null;
}
return (
<>
<Script
defer
data-modal-disclaimer="This is a custom LLM for HeroUI with access to all developer docs (heroui.com/docs) and GitHub Issues and PRs (github.com/heroui-inc/heroui)."
@ -36,6 +42,5 @@ export function ScriptProviders({ isKapaEnabled = true }: { isKapaEnabled?: bool
src="https://widget.kapa.ai/kapa-widget.bundle.js"
strategy="afterInteractive"
/>
</>
);
}

View File

@ -1,26 +1,15 @@
import {addToast, Button, ToastProvider} from "@heroui/react";
import {addToast, Button} 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) => (
<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",
@ -29,8 +18,8 @@ export default function App() {
>
{position}
</Button>
))}
</div>
</>
),
)}
</div>
);
}

View File

@ -127,7 +127,7 @@ describe("Toast", () => {
it("should work with placement", async () => {
const wrapper = render(
<>
<ToastProvider placement="left-bottom" />
<ToastProvider placement="bottom-left" />
<button
data-testid="button"
onClick={() => {
@ -144,7 +144,7 @@ describe("Toast", () => {
const region = wrapper.getByRole("region");
expect(region).toHaveAttribute("data-placement", "left-bottom");
expect(region).toHaveAttribute("data-placement", "bottom-left");
});
it("should have loading-icon when promise prop is passed.", async () => {

View File

@ -341,12 +341,12 @@ export function useToast<T extends ToastProps>(originalProps: UseToastProps<T>)
const getDragElasticConstraints = (placement: string) => {
const elasticConstraint = {top: 0, bottom: 0, right: 0, left: 0};
if (placement === "center-bottom") {
if (placement === "bottom-center") {
elasticConstraint.bottom = 1;
return elasticConstraint;
}
if (placement === "center-top") {
if (placement === "top-center") {
elasticConstraint.top = 1;
return elasticConstraint;

View File

@ -41,7 +41,7 @@ const toast = tv({
"outline-none",
"p-3 sm:mx-1",
"my-1",
"w-full sm:w-[356px]",
"w-full sm:w-[270px] md:w-[300px]",
"min-h-4",
],
title: ["text-small", "me-4", "text-foreground"],