Skip to content

Commit

Permalink
Merge pull request #95 from almond-bongbong/bugfix/maintain-theme-on-…
Browse files Browse the repository at this point in the history
…update

🐛 Maintain theme on update
  • Loading branch information
almond-bongbong authored Jul 25, 2024
2 parents bb59a5e + a9de86a commit aba669b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
16 changes: 16 additions & 0 deletions __tests__/toast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,20 @@ describe('toast', () => {

screen.getByText(TOAST_TEXT);
});

it('should retain the theme when updating the toast with an options object', async () => {
const TOAST_TEXT = generateMessage();
const UPDATED_TEXT = generateMessage();
const toastContentClassName = 'toast-theme-content';

const toastInstance = await act(() => toast(TOAST_TEXT, { theme: 'dark' }));

const toastDOM = screen.getByText(TOAST_TEXT);
expect(toastDOM).toHaveClass(toastContentClassName);

await act(() => toastInstance.update({ message: UPDATED_TEXT }));

const updatedToastDOM = screen.getByText(UPDATED_TEXT);
expect(updatedToastDOM).toHaveClass(toastContentClassName);
});
});
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"typescript": "^5.0.2",
"vite": "^4.5.3"
}
}
}
24 changes: 23 additions & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,11 @@ js-sdsl@^4.1.4:
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.4.0.tgz#8b437dbe642daa95760400b602378ed8ffea8430"
integrity sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
Expand Down Expand Up @@ -910,6 +915,13 @@ lodash.merge@^4.6.2:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
Expand Down Expand Up @@ -1061,6 +1073,7 @@ queue-microtask@^1.2.2:

"react-dom@link:../node_modules/react-dom":
version "0.0.0"
uid ""

react-router-dom@^6.11.1:
version "6.11.1"
Expand All @@ -1078,10 +1091,12 @@ [email protected]:
"@remix-run/router" "1.6.1"

"react-simple-toasts@link:..":
version "5.10.0"
version "0.0.0"
uid ""

"react@link:../node_modules/react":
version "0.0.0"
uid ""

resolve-from@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -1114,6 +1129,13 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

scheduler@^0.23.0:
version "0.23.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.2.tgz#414ba64a3b282892e944cf2108ecc078d115cdc3"
integrity sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==
dependencies:
loose-envify "^1.1.0"

semver@^7.3.7:
version "7.5.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"dist"
],
"engines": {
"node": ">=16.17.0"
"node": ">=16.17.0 <=20.x"
},
"sideEffects": false,
"keywords": [
Expand All @@ -85,5 +85,6 @@
"toast-notification",
"toastify",
"react-toastify"
]
],
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import postcss from 'rollup-plugin-postcss';
import eslint from '@rollup/plugin-eslint';
import json from '@rollup/plugin-json';
import autoprefixer from 'autoprefixer';
import terser from "@rollup/plugin-terser";
import terser from '@rollup/plugin-terser';

import pkg from './package.json' assert { type: 'json' };

Expand Down
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ function renderToast(
const finalLoading = isToastUpdateOptions(messageOrOptions)
? messageOrOptions.loading ?? loading
: false;
const finalTheme = isToastUpdateOptions(messageOrOptions) ? messageOrOptions.theme : theme;
const finalTheme = isToastUpdateOptions(messageOrOptions)
? messageOrOptions.theme || theme
: theme;

toastComponentList[index].message = finalMessage;
toastComponentList[index].component = (
Expand Down
4 changes: 4 additions & 0 deletions src/lib/type-guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ReactNode } from 'react';
import { ToastUpdateOptions } from '../type/common';

/**
* Check if the updateOptions is a ToastUpdateOptions
* @param updateOptions
*/
export const isToastUpdateOptions = (
updateOptions: ReactNode | ToastUpdateOptions,
): updateOptions is ToastUpdateOptions => {
Expand Down

0 comments on commit aba669b

Please sign in to comment.