feat: implement responsive expansion for Toaster component
This commit is contained in:
parent
d97d2c84d2
commit
a469948da5
3 changed files with 20 additions and 4 deletions
|
@ -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;
|
||||||
|
|
|
@ -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)}
|
||||||
|
|
|
@ -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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue