Created
October 9, 2024 20:40
-
-
Save paulweezydesign/71cb54647ff415126fbf6f9022d759fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import clsx from "clsx"; | |
export default function ToggleMessage() { | |
const [visible, setVisible] = React.useState(false); | |
const toggleVisibility = () => { | |
setVisible(!visible); | |
}; | |
return ( | |
<div className="relative"> | |
<button | |
className="bg-blue-500 text-white py-2 px-4 rounded" | |
onClick={toggleVisibility} | |
> | |
Toggle Message | |
</button> | |
<section | |
className={clsx( | |
"bg-red-500 text-white shadow-lg shadow-black p-4 h-screen w-screen md:w-[350px] z-50 fixed top-0 left-0 transition-transform duration-300", | |
{ | |
"transform translate-x-0": visible, | |
"transform -translate-x-full": !visible, | |
} | |
)} | |
> | |
The message is now visible! | |
<button | |
className="absolute top-0 right-0 p-2 text-white text-2xl" | |
onClick={toggleVisibility} | |
> | |
× | |
</button> | |
</section> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment