Implemented theme system
This commit is contained in:
parent
e211919ab1
commit
57f73e904c
|
@ -1,4 +1,4 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import { defineConfig, squooshImageService } from 'astro/config';
|
||||
|
||||
import tailwind from "@astrojs/tailwind";
|
||||
|
||||
|
@ -7,5 +7,8 @@ export default defineConfig({
|
|||
publicDir: "static",
|
||||
outDir: "public",
|
||||
|
||||
integrations: [tailwind()]
|
||||
integrations: [tailwind()],
|
||||
image:{
|
||||
service: squooshImageService()
|
||||
}
|
||||
});
|
|
@ -1,61 +0,0 @@
|
|||
---
|
||||
interface Props {
|
||||
title: string;
|
||||
body: string;
|
||||
href: string;
|
||||
}
|
||||
|
||||
const { href, title, body } = Astro.props;
|
||||
---
|
||||
|
||||
<li class="link-card">
|
||||
<a href={href}>
|
||||
<h2>
|
||||
{title}
|
||||
<span>→</span>
|
||||
</h2>
|
||||
<p>
|
||||
{body}
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
<style>
|
||||
.link-card {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
padding: 1px;
|
||||
background-color: #23262d;
|
||||
background-image: none;
|
||||
background-size: 400%;
|
||||
border-radius: 7px;
|
||||
background-position: 100%;
|
||||
transition: background-position 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
.link-card > a {
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
line-height: 1.4;
|
||||
padding: calc(1.5rem - 1px);
|
||||
border-radius: 8px;
|
||||
color: white;
|
||||
background-color: #23262d;
|
||||
opacity: 0.8;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
transition: color 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
p {
|
||||
margin-top: 0.5rem;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.link-card:is(:hover, :focus-within) {
|
||||
background-position: 0;
|
||||
background-image: var(--accent-gradient);
|
||||
}
|
||||
.link-card:is(:hover, :focus-within) h2 {
|
||||
color: rgb(var(--accent-light));
|
||||
}
|
||||
</style>
|
36
src/components/ThemeToggle.astro
Normal file
36
src/components/ThemeToggle.astro
Normal file
|
@ -0,0 +1,36 @@
|
|||
<button id="ThemeToggle" class="absolute top-4 right-4 bg-primary text-primary-content p-2 rounded-full" title="toggle website dark theme">
|
||||
<span class="inline dark:hidden">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
|
||||
<path d="M12 2.25a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0V3a.75.75 0 0 1 .75-.75ZM7.5 12a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM18.894 6.166a.75.75 0 0 0-1.06-1.06l-1.591 1.59a.75.75 0 1 0 1.06 1.061l1.591-1.59ZM21.75 12a.75.75 0 0 1-.75.75h-2.25a.75.75 0 0 1 0-1.5H21a.75.75 0 0 1 .75.75ZM17.834 18.894a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 1 0-1.061 1.06l1.59 1.591ZM12 18a.75.75 0 0 1 .75.75V21a.75.75 0 0 1-1.5 0v-2.25A.75.75 0 0 1 12 18ZM7.758 17.303a.75.75 0 0 0-1.061-1.06l-1.591 1.59a.75.75 0 0 0 1.06 1.061l1.591-1.59ZM6 12a.75.75 0 0 1-.75.75H3a.75.75 0 0 1 0-1.5h2.25A.75.75 0 0 1 6 12ZM6.697 7.757a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 0 0-1.061 1.06l1.59 1.591Z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="hidden dark:inline">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
|
||||
<path fill-rule="evenodd" d="M9.528 1.718a.75.75 0 0 1 .162.819A8.97 8.97 0 0 0 9 6a9 9 0 0 0 9 9 8.97 8.97 0 0 0 3.463-.69.75.75 0 0 1 .981.98 10.503 10.503 0 0 1-9.694 6.46c-5.799 0-10.5-4.7-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 0 1 .818.162Z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<script>
|
||||
const toggle = document.getElementById("ThemeToggle");
|
||||
|
||||
if (toggle) {
|
||||
toggle.addEventListener("click", function (){
|
||||
console.log("switching theme...")
|
||||
let theme = document.documentElement.dataset.theme;
|
||||
if (theme === "light") {
|
||||
document.documentElement.dataset.theme = "dark";
|
||||
localStorage.theme = "dark";
|
||||
} else if (theme === "dark") {
|
||||
document.documentElement.dataset.theme = "light";
|
||||
localStorage.theme = "light";
|
||||
} else {
|
||||
document.documentElement.dataset.theme = "dark";
|
||||
localStorage.theme = "dark";
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
|
@ -1,4 +1,9 @@
|
|||
---
|
||||
import '../styles/style.css';
|
||||
import ThemeToggle from "../components/ThemeToggle.astro";
|
||||
import {Image} from "astro:assets"
|
||||
import logo from "./logo.svg"
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
}
|
||||
|
@ -15,37 +20,20 @@ const { title } = Astro.props;
|
|||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
<script is:inline>
|
||||
document.documentElement.dataset.theme = ("theme" in localStorage) ?
|
||||
localStorage.theme :
|
||||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light");
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="p-4 md:px-12 flex items-center justify-center">
|
||||
<Image class="w-1/2 md:w-auto h-auto md:h-56" src={logo} alt="Winter Software" />
|
||||
<ThemeToggle />
|
||||
</header>
|
||||
<slot />
|
||||
<footer class="p-2 bg-base-300">
|
||||
<p>test bg-base-300</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
<style is:global>
|
||||
:root {
|
||||
--accent: 136, 58, 234;
|
||||
--accent-light: 224, 204, 250;
|
||||
--accent-dark: 49, 10, 101;
|
||||
--accent-gradient: linear-gradient(
|
||||
45deg,
|
||||
rgb(var(--accent)),
|
||||
rgb(var(--accent-light)) 30%,
|
||||
white 60%
|
||||
);
|
||||
}
|
||||
html {
|
||||
font-family: system-ui, sans-serif;
|
||||
background: #13151a;
|
||||
background-size: 224px;
|
||||
}
|
||||
code {
|
||||
font-family:
|
||||
Menlo,
|
||||
Monaco,
|
||||
Lucida Console,
|
||||
Liberation Mono,
|
||||
DejaVu Sans Mono,
|
||||
Bitstream Vera Sans Mono,
|
||||
Courier New,
|
||||
monospace;
|
||||
}
|
||||
</style>
|
||||
|
|
122
src/layouts/logo.svg
Normal file
122
src/layouts/logo.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 33 KiB |
|
@ -1,123 +1,19 @@
|
|||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import Card from '../components/Card.astro';
|
||||
---
|
||||
|
||||
<Layout title="Welcome to Astro.">
|
||||
<main>
|
||||
<svg
|
||||
class="astro-a"
|
||||
width="495"
|
||||
height="623"
|
||||
viewBox="0 0 495 623"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M167.19 364.254C83.4786 364.254 0 404.819 0 404.819C0 404.819 141.781 19.4876 142.087 18.7291C146.434 7.33701 153.027 0 162.289 0H332.441C341.703 0 348.574 7.33701 352.643 18.7291C352.92 19.5022 494.716 404.819 494.716 404.819C494.716 404.819 426.67 364.254 327.525 364.254L264.41 169.408C262.047 159.985 255.147 153.581 247.358 153.581C239.569 153.581 232.669 159.985 230.306 169.408L167.19 364.254ZM160.869 530.172C160.877 530.18 160.885 530.187 160.894 530.195L160.867 530.181C160.868 530.178 160.868 530.175 160.869 530.172ZM136.218 411.348C124.476 450.467 132.698 504.458 160.869 530.172C160.997 529.696 161.125 529.242 161.248 528.804C161.502 527.907 161.737 527.073 161.917 526.233C165.446 509.895 178.754 499.52 195.577 500.01C211.969 500.487 220.67 508.765 223.202 527.254C224.141 534.12 224.23 541.131 224.319 548.105C224.328 548.834 224.337 549.563 224.347 550.291C224.563 566.098 228.657 580.707 237.264 593.914C245.413 606.426 256.108 615.943 270.749 622.478C270.593 621.952 270.463 621.508 270.35 621.126C270.045 620.086 269.872 619.499 269.685 618.911C258.909 585.935 266.668 563.266 295.344 543.933C298.254 541.971 301.187 540.041 304.12 538.112C310.591 533.854 317.059 529.599 323.279 525.007C345.88 508.329 360.09 486.327 363.431 457.844C364.805 446.148 363.781 434.657 359.848 423.275C358.176 424.287 356.587 425.295 355.042 426.275C351.744 428.366 348.647 430.33 345.382 431.934C303.466 452.507 259.152 455.053 214.03 448.245C184.802 443.834 156.584 436.019 136.218 411.348Z"
|
||||
fill="url(#paint0_linear_1805_24383)"></path>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="paint0_linear_1805_24383"
|
||||
x1="247.358"
|
||||
y1="0"
|
||||
x2="247.358"
|
||||
y2="622.479"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
>
|
||||
<stop stop-opacity="0.9"></stop>
|
||||
<stop offset="1" stop-opacity="0.2"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
|
||||
<p class="instructions">
|
||||
To get started, open the directory <code>src/pages</code> in your project.<br />
|
||||
<strong>Code Challenge:</strong> Tweak the "Welcome to Astro" message above.
|
||||
</p>
|
||||
<ul role="list" class="link-card-grid">
|
||||
<Card
|
||||
href="https://docs.astro.build/"
|
||||
title="Documentation"
|
||||
body="Learn how Astro works and explore the official API docs."
|
||||
/>
|
||||
<Card
|
||||
href="https://astro.build/integrations/"
|
||||
title="Integrations"
|
||||
body="Supercharge your project with new frameworks and libraries."
|
||||
/>
|
||||
<Card
|
||||
href="https://astro.build/themes/"
|
||||
title="Themes"
|
||||
body="Explore a galaxy of community-built starter themes."
|
||||
/>
|
||||
<Card
|
||||
href="https://astro.build/chat/"
|
||||
title="Community"
|
||||
body="Come say hi to our amazing Discord community. ❤️"
|
||||
/>
|
||||
</ul>
|
||||
<main class="container mx-auto p-4 md:px-12">
|
||||
<h1 class="mb-2 text-3xl">Welcome to <span class="text-gradient">Astro</span></h1>
|
||||
|
||||
<div class="mb-2 p-8 bg-primary text-primary-content rounded-sm">
|
||||
<p>Test primary</p>
|
||||
</div>
|
||||
<div class="mb-2 p-8 bg-secondary text-secondary-content rounded-sm">
|
||||
<p>Test secondary</p>
|
||||
</div>
|
||||
<div class="mb-2 p-8 bg-neutral text-neutral-content rounded-sm">
|
||||
<p>Test neutral</p>
|
||||
</div>
|
||||
</main>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
main {
|
||||
margin: auto;
|
||||
padding: 1rem;
|
||||
width: 800px;
|
||||
max-width: calc(100% - 2rem);
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.astro-a {
|
||||
position: absolute;
|
||||
top: -32px;
|
||||
left: 50%;
|
||||
transform: translatex(-50%);
|
||||
width: 220px;
|
||||
height: auto;
|
||||
z-index: -1;
|
||||
}
|
||||
h1 {
|
||||
font-size: 4rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
text-align: center;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
.text-gradient {
|
||||
background-image: var(--accent-gradient);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-size: 400%;
|
||||
background-position: 0%;
|
||||
}
|
||||
.instructions {
|
||||
margin-bottom: 2rem;
|
||||
border: 1px solid rgba(var(--accent-light), 25%);
|
||||
background: linear-gradient(rgba(var(--accent-dark), 66%), rgba(var(--accent-dark), 33%));
|
||||
padding: 1.5rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.instructions code {
|
||||
font-size: 0.8em;
|
||||
font-weight: bold;
|
||||
background: rgba(var(--accent-light), 12%);
|
||||
color: rgb(var(--accent-light));
|
||||
border-radius: 4px;
|
||||
padding: 0.3em 0.4em;
|
||||
}
|
||||
.instructions strong {
|
||||
color: rgb(var(--accent-light));
|
||||
}
|
||||
.link-card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
||||
gap: 2rem;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
73
src/styles/style.css
Normal file
73
src/styles/style.css
Normal file
|
@ -0,0 +1,73 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
html, body {
|
||||
@apply bg-base-100 text-base-content;
|
||||
}
|
||||
|
||||
html, body,
|
||||
header, footer, main, article, section,
|
||||
div, span {
|
||||
@apply transition-colors ease-linear duration-300;
|
||||
}
|
||||
|
||||
:root {
|
||||
--color-primary: 117 0 174;
|
||||
--color-primary-content: 255 255 255;
|
||||
--color-secondary: 174 171 0;
|
||||
--color-secondary-content: 0 0 0;
|
||||
--color-neutral: 227 213 246;
|
||||
--color-neutral-content: 0 0 0;
|
||||
|
||||
--color-base-100: 15 15 10;
|
||||
--color-base-200: 25 25 20;
|
||||
--color-base-300: 50 50 45;
|
||||
--color-base-content: 255 255 255;
|
||||
}
|
||||
|
||||
[data-theme="light"] {
|
||||
--color-primary: 197 82 255;
|
||||
--color-primary-content: 0 0 0;
|
||||
--color-secondary: 255 252 82;
|
||||
--color-secondary-content: 0 0 0;
|
||||
--color-neutral: 23 9 42;
|
||||
--color-neutral-content: 255 255 255;
|
||||
|
||||
--color-base-100: 240 240 230;
|
||||
--color-base-200: 225 225 215;
|
||||
--color-base-300: 205 205 195;
|
||||
--color-base-content: 0 0 0;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--color-primary: 197 82 255;
|
||||
--color-primary-content: 0 0 0;
|
||||
--color-secondary: 255 252 82;
|
||||
--color-secondary-content: 0 0 0;
|
||||
--color-neutral: 23 9 42;
|
||||
--color-neutral-content: 255 255 255;
|
||||
|
||||
--color-base-100: 240 240 230;
|
||||
--color-base-200: 225 225 215;
|
||||
--color-base-300: 205 205 195;
|
||||
--color-base-content: 0 0 0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--color-primary: 117 0 174;
|
||||
--color-primary-content: 255 255 255;
|
||||
--color-secondary: 174 171 0;
|
||||
--color-secondary-content: 0 0 0;
|
||||
--color-neutral: 227 213 246;
|
||||
--color-neutral-content: 0 0 0;
|
||||
|
||||
--color-base-100: 15 15 10;
|
||||
--color-base-200: 25 25 20;
|
||||
--color-base-300: 50 50 45;
|
||||
--color-base-content: 255 255 255;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 749 B After Width: | Height: | Size: 45 KiB |
|
@ -1,8 +1,37 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
import defaultTheme from 'tailwindcss/defaultTheme'
|
||||
|
||||
export default {
|
||||
darkMode: ['selector', '[data-theme="dark"]'],
|
||||
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
|
||||
theme: {
|
||||
extend: {},
|
||||
extend: {
|
||||
colors: {
|
||||
primary: 'rgb(var(--color-primary) / <alpha-value>)',
|
||||
'primary-content': 'rgb(var(--color-primary-content) / <alpha-value>)',
|
||||
secondary: 'rgb(var(--color-secondary) / <alpha-value>)',
|
||||
'secondary-content': 'rgb(var(--color-secondary-content) / <alpha-value>)',
|
||||
neutral: 'rgb(var(--color-neutral) / <alpha-value>)',
|
||||
'neutral-content': 'rgb(var(--color-neutral-content) / <alpha-value>)',
|
||||
|
||||
base: {
|
||||
100: 'rgb(var(--color-base-100) / <alpha-value>)',
|
||||
200: 'rgb(var(--color-base-200) / <alpha-value>)',
|
||||
300: 'rgb(var(--color-base-300) / <alpha-value>)',
|
||||
},
|
||||
'base-content': 'rgb(var(--color-base-content) / <alpha-value>)',
|
||||
},
|
||||
fontSize: {
|
||||
sm: '0.750rem',
|
||||
base: '1rem',
|
||||
lg: '1.1rem',
|
||||
xl: '1.333rem',
|
||||
'2xl': '1.777rem',
|
||||
'3xl': '2.369rem',
|
||||
'4xl': '3.158rem',
|
||||
'5xl': '4.210rem'
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue