Skip to content

Commit

Permalink
add header & switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Nov 18, 2023
1 parent fb743d6 commit 6f3f36e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
7 changes: 7 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import react from "@astrojs/react";

// https://astro.build/config
export default defineConfig({
integrations: [react()]
});
3 changes: 2 additions & 1 deletion src/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineConfig } from 'astro/config';
import tailwind from "@astrojs/tailwind";
import sitemap from "@astrojs/sitemap";
import react from "@astrojs/react";

export default defineConfig({
integrations: [tailwind(), sitemap()],
integrations: [tailwind(), sitemap(), react()],
site: "https://jspce.ame-x.net", // 暫定
});
5 changes: 5 additions & 0 deletions src/src/layout/Footer/Footer.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
---
<footer>
footer
</footer>
8 changes: 8 additions & 0 deletions src/src/layout/Header/Header.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
import { Switcher } from "./SwitchLiteDark.tsx";
---
<header>
header
<Switcher client:load />
</header>
27 changes: 27 additions & 0 deletions src/src/layout/Header/SwitchLiteDark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useState } from 'react';

function SwitchButton(props) {
return (
<></>
)
}

export function Switcher() {

if (typeof localStorage === 'undefined' || localStorage === undefined) {
return <button>Switch!</button>
}

const [theme, setTheme] = useState(localStorage.getItem('theme') || 'light');
console.log(theme);

const handleSwitch = () => {
const newTheme = theme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
};

return (
<button onClick={handleSwitch}>Switch!</button>
);
}
5 changes: 5 additions & 0 deletions src/src/layout/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
import BaseHead from './BaseHead.astro';
import Header from './Header/Header.astro';
import Footer from './Footer/Footer.astro';
interface Props {
title?: string;
description?: string;
Expand All @@ -13,8 +16,10 @@ const { title, description, image } = Astro.props as Props;
<html lang="ja">
<BaseHead title={title ?? "JSPCE - JavaScript Professional Certification Examination"} description={description ?? "JavaScript Professional Certification Examination Offical Site"} image={image ?? "/favicon.png"} />
<body>
<Header />
<div id="__nuxt" style={{ display: "contents" }}>
<slot />
</div>
<Footer />
</body>
</html>
7 changes: 7 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}

0 comments on commit 6f3f36e

Please sign in to comment.