From ae4e1cd1649789bbce4455887c797a2f302b741c Mon Sep 17 00:00:00 2001 From: jorgeAgoiz Date: Wed, 1 Nov 2023 12:08:22 +0100 Subject: [PATCH 1/3] feat: :sparkles: cancel and action button custom styles Provide custom styles to cancel and action buttons --- src/index.tsx | 8 ++++++++ src/types.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 0c2af4a..d54179f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -43,6 +43,8 @@ interface ToastProps { closeButton: boolean; interacting: boolean; style?: React.CSSProperties; + cancelButtonStyle?: React.CSSProperties; + actionButtonStyle?: React.CSSProperties; duration?: number; className?: string; unstyled?: boolean; @@ -63,6 +65,8 @@ const Toast = (props: ToastProps) => { removeToast, closeButton, style, + cancelButtonStyle, + actionButtonStyle, className = '', descriptionClassName = '', duration: durationFromToaster, @@ -346,6 +350,7 @@ const Toast = (props: ToastProps) => { - + @@ -132,8 +146,8 @@ export default function Home({ searchParams }: any) { onClick={() => { const toastId = toast('My Unupdated Toast', { duration: 10000, - }); - toast('My Updated Toast', { + }); + toast('My Updated Toast', { id: toastId, duration: 10000, }); @@ -143,7 +157,15 @@ export default function Home({ searchParams }: any) { {showAutoClose ?
: null} {showDismiss ?
: null} - + ); } diff --git a/test/tests/basic.spec.ts b/test/tests/basic.spec.ts index de74409..f450701 100644 --- a/test/tests/basic.spec.ts +++ b/test/tests/basic.spec.ts @@ -7,7 +7,7 @@ test.beforeEach(async ({ page }) => { test.describe('Basic functionality', () => { test('toast is rendered and disappears after the default timeout', async ({ page }) => { await page.getByTestId('default-button').click(); - await expect(page.locator('[data-sonner-toast]')).toHaveCount(0); + await expect(page.locator('[data-sonner-toast]')).toHaveCount(1); await expect(page.locator('[data-sonner-toast]')).toHaveCount(0); }); @@ -165,4 +165,18 @@ test.describe('Basic functionality', () => { await expect(page.getByText('My Unupdated Toast')).toHaveCount(0); await expect(page.getByText('My Updated Toast')).toHaveCount(1); }); + + test('cancel button is rendered with custom styles', async ({ page }) => { + await page.getByTestId('custom-cancel-button-toast').click(); + const button = await page.locator('[data-cancel]'); + + await expect(button).toHaveCSS('background-color', 'rgb(254, 226, 226)'); + }); + + test('action button is rendered with custom styles', async ({ page }) => { + await page.getByTestId('action').click(); + const button = await page.locator('[data-button]'); + + await expect(button).toHaveCSS('background-color', 'rgb(219, 239, 255)'); + }); }); From 3b832e1a11a1426d2925a524b7c21276c21fbd49 Mon Sep 17 00:00:00 2001 From: jorgeAgoiz Date: Wed, 1 Nov 2023 14:05:18 +0100 Subject: [PATCH 3/3] refactor: :rewind: remove duration remove duration on default-button --- test/src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx index 0b5c52e..598cf3d 100644 --- a/test/src/app/page.tsx +++ b/test/src/app/page.tsx @@ -16,7 +16,7 @@ export default function Home({ searchParams }: any) { -