feat: implement responsive expansion for Toaster component

This commit is contained in:
micha 2025-06-19 15:22:20 +02:00
parent 98f2395ff2
commit b3ee77f9a8
3 changed files with 20 additions and 4 deletions

View file

@ -155,7 +155,7 @@ h5 {
h6 { h6 {
font-family: var(--font-heading); font-family: var(--font-heading);
font-size: 24px; font-size: 20px;
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
line-height: normal; line-height: normal;

View file

@ -106,8 +106,7 @@ export const ToastInner: React.FC<ToastInnerProps> = ({
const Icon = Icons[iconKey] as React.ComponentType<Icons.LucideProps>; const Icon = Icons[iconKey] as React.ComponentType<Icons.LucideProps>;
return ( return (
// TODO: optimize Toaster for mobile <div className={`relative sm:w-120 rounded p-4 ${bgColor} select-none`}>
<div className={`relative w-120 rounded p-4 ${bgColor} select-none`}>
{/* Close Button */} {/* Close Button */}
<button <button
onClick={() => toast.dismiss(toastId)} onClick={() => toast.dismiss(toastId)}

View file

@ -2,10 +2,27 @@
import { useTheme } from 'next-themes'; import { useTheme } from 'next-themes';
import { Toaster as Sonner, ToasterProps } from 'sonner'; import { Toaster as Sonner, ToasterProps } from 'sonner';
import React from 'react';
const Toaster = ({ ...props }: ToasterProps) => { const Toaster = ({ ...props }: ToasterProps) => {
const { theme = 'system' } = useTheme(); const { theme = 'system' } = useTheme();
const [shouldExpand, setShouldExpand] = React.useState(false);
React.useEffect(() => {
const mediaQuery = window.matchMedia('(min-width: 600px)');
const handleScreenSizeChange = () => {
setShouldExpand(mediaQuery.matches);
};
handleScreenSizeChange(); // set initial value
mediaQuery.addEventListener('change', handleScreenSizeChange);
return () =>
mediaQuery.removeEventListener('change', handleScreenSizeChange);
}, []);
return ( return (
<Sonner <Sonner
theme={theme as ToasterProps['theme']} theme={theme as ToasterProps['theme']}
@ -28,7 +45,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
}} }}
swipeDirections={['left', 'right']} swipeDirections={['left', 'right']}
closeButton={true} closeButton={true}
expand={true} expand={shouldExpand}
{...props} {...props}
/> />
); );