Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create background component #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gxcko.me/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</script>
</head>
<body>

<div id="root"></div>

<script type="module" src="src/main.tsx"></script>
Expand Down
19 changes: 19 additions & 0 deletions gxcko.me/src/components/Background.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {useTheme} from "../contexts/ThemeContext.tsx";

interface BackgroundProps {
dialogOpen: boolean;
}

export default function Background({ dialogOpen }: BackgroundProps) {
const {theme} = useTheme();

if (theme === 'light') {
return null;
} else if (dialogOpen) {
return null;
}

return (
<div id="background"></div>
);
}
7 changes: 6 additions & 1 deletion gxcko.me/src/components/DarkModeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React, {useEffect, useRef} from "react";
import {useTheme} from "../contexts/ThemeContext.tsx";
import {checkCookiesAccepted, getCookie, setCookie} from "./CookiePopup.tsx";
import {useBlur} from "../contexts/BlurContext.tsx";
import Background from "./Background.tsx";

const DarkModeToggle: React.FC = () => {
const {theme, toggleTheme} = useTheme();
const {blur, toggleBlur} = useBlur();
const dialogRef = useRef<HTMLDialogElement>(null);
const dialogShown = useRef(false);
const dialogOpen = useRef(false);

useEffect(() => {
if (!getCookie('dialogShown') && !dialogShown.current) {
Expand All @@ -21,6 +23,7 @@ const DarkModeToggle: React.FC = () => {
const dialog = dialogRef.current;

if (dialog) {
dialogOpen.current = true;
if (typeof dialog.showModal === "function") {
dialog.showModal();
} else {
Expand Down Expand Up @@ -61,6 +64,7 @@ const DarkModeToggle: React.FC = () => {
if (confirmBtn === null) console.warn('Confirm button not found');
document.removeEventListener('click', handler);
toggleBlur();
dialogOpen.current = false;
}, 1000); // Delay equal to the transition duration
} else {
console.warn('Dialog element not found');
Expand Down Expand Up @@ -105,6 +109,7 @@ const DarkModeToggle: React.FC = () => {
`}
</style>
</noscript>
<Background dialogOpen={dialogOpen.current}/>
<dialog ref={dialogRef} id="darkModeDia" className={theme === 'dark' ? 'dark' : ''}>
<p>Would you like to toggle the dark mode?</p>
<div className="button-container">
Expand All @@ -118,4 +123,4 @@ const DarkModeToggle: React.FC = () => {
)
}

export default DarkModeToggle;
export default DarkModeToggle;
14 changes: 12 additions & 2 deletions gxcko.me/styles/backgrounds.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
body {
background-color: #ffffff;
color: #000000;
font-family: "Aptos", serif;
transition: all 1s ease-in-out;
}
Expand All @@ -15,6 +13,18 @@ body.inBackground {
transition: all 1s ease-in-out;
}

#background {
display: block;
position: fixed;
left: -50%;
top: -50%;
z-index: -1;
width: 200%;
height: 200%;
background-color: #222222;
transition: all 1s ease-in-out;
}

.bubble {
background: lightgray;
padding: 20px;
Expand Down
Loading