Skip to content

Commit

Permalink
fix: theme was not used when passed to Toaster
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnartorfis committed Sep 10, 2024
1 parent c64256a commit 34904f5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const App: React.FC = () => {
swipToDismissDirection="up"
visibleToasts={4}
closeButton
theme="system"
icons={{
error: <Text>💥</Text>,
loading: <Text>🔄</Text>,
Expand Down
9 changes: 8 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ToastPosition, ToastSwipeDirection, ToastVariant } from './types';
import type {
ToastPosition,
ToastSwipeDirection,
ToastTheme,
ToastVariant,
} from './types';

export const toastDefaultValues: {
duration: number;
Expand All @@ -14,6 +19,7 @@ export const toastDefaultValues: {
pauseWhenPageIsHidden: boolean;
cn: (...classes: Array<string | undefined>) => string;
gap: number;
theme: ToastTheme;
} = {
duration: 4000,
position: 'top-center',
Expand All @@ -28,4 +34,5 @@ export const toastDefaultValues: {
pauseWhenPageIsHidden: false,
cn: (...classes) => classes.filter(Boolean).join(' '),
gap: 14,
theme: 'system',
};
3 changes: 3 additions & 0 deletions src/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const ToasterUI: React.FC<ToasterProps> = ({
pauseWhenPageIsHidden,
cn,
gap,
theme,
...props
}) => {
const [toasts, setToasts] = React.useState<ToastProps[]>([]);
Expand Down Expand Up @@ -163,6 +164,7 @@ export const ToasterUI: React.FC<ToasterProps> = ({
pauseWhenPageIsHidden ?? toastDefaultValues.pauseWhenPageIsHidden,
cn: cn ?? toastDefaultValues.cn,
gap: gap ?? toastDefaultValues.gap,
theme: theme ?? toastDefaultValues.theme,
}),
[
duration,
Expand All @@ -177,6 +179,7 @@ export const ToasterUI: React.FC<ToasterProps> = ({
pauseWhenPageIsHidden,
cn,
gap,
theme,
]
);

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export type ToasterContextType = Required<
| 'pauseWhenPageIsHidden'
| 'cn'
| 'gap'
| 'theme'
>
> & {
addToast: AddToastContextHandler;
Expand Down
5 changes: 3 additions & 2 deletions src/use-colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const dark: typeof light = {
};

export const useColors = (ivertProps?: boolean) => {
const { invert: invertCtx } = useToastContext();
const scheme = useColorScheme();
const { invert: invertCtx, theme } = useToastContext();
const systemScheme = useColorScheme();
const scheme = theme === 'system' ? systemScheme : theme;
const invert = ivertProps ?? invertCtx;

if (scheme === 'dark') {
Expand Down

0 comments on commit 34904f5

Please sign in to comment.