Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add theming toggle

Joshen Lim3721f880d821
diff --git a/www/components/Footer/index.tsx b/www/components/Footer/index.tsx
index d330afc1047..bda79ccead6 100644
--- a/www/components/Footer/index.tsx
+++ b/www/components/Footer/index.tsx
@@ -1,6 +1,71 @@
+import { useState, useEffect } from 'react'
import FooterLinks from "data/Footer.json"
-const Footer = () => {
+type Props = {
+ updateTheme: Function
+}
+
+const Footer = (props: Props) => {
+ const { updateTheme } = props
+ const [darkMode, setDarkMode] = useState<boolean>(true)
+
+ useEffect(() => {
+ const isDarkMode = localStorage.getItem('supabaseDarkMode')
+ if (isDarkMode) setDarkMode(isDarkMode === 'true')
+ }, [])
+
+ const toggleDarkMode = () => {
+ localStorage.setItem('supabaseDarkMode', (!darkMode).toString())
+ updateTheme(!darkMode)
+ setDarkMode(!darkMode)
+ }
+
+ const SunEmoji = () => (
+ <svg
+ width="32"
+ height="32"
+ fill="none"
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M16 2a1.4 1.4 0 011.4 1.4v1.4a1.4 1.4 0 11-2.8 0V3.4A1.4 1.4 0 0116 2zM6.1 6.1a1.4 1.4 0 011.98 0l.99.99a1.4 1.4 0 11-1.98 1.98l-.99-.99a1.4 1.4 0 010-1.98zm19.8 0a1.4 1.4 0 010 1.98l-.99.99a1.4 1.4 0 01-1.98-1.98l.99-.99a1.4 1.4 0 011.98 0zM9 16a7 7 0 1114 0 7 7 0 01-14 0zm-7 0a1.4 1.4 0 011.4-1.4h1.4a1.4 1.4 0 110 2.8H3.4A1.4 1.4 0 012 16zm23.8 0a1.4 1.4 0 011.4-1.4h1.4a1.4 1.4 0 110 2.8h-1.4a1.4 1.4 0 01-1.4-1.4zm-2.87 6.93a1.4 1.4 0 011.98 0l.99.99a1.4 1.4 0 01-1.98 1.98l-.99-.99a1.4 1.4 0 010-1.98zm-15.84 0a1.4 1.4 0 011.98 1.98l-.99.99a1.4 1.4 0 01-1.98-1.98l.99-.99zM16 25.8a1.4 1.4 0 011.4 1.4v1.4a1.4 1.4 0 11-2.8 0v-1.4a1.4 1.4 0 011.4-1.4z"
+ fill="url(#paint0_linear)"
+ />
+ <defs>
+ <linearGradient
+ id="paint0_linear" x1="2" y1="2" x2="30" y2="30"
+ gradientUnits="userSpaceOnUse"
+ >
+ <stop
+ className="transition-all duration-200"
+ stopColor="#FACC15"
+ />
+ <stop
+ className="transition-all duration-200"
+ offset="1"
+ stopColor="#FA9D16"
+ />
+ </linearGradient>
+ </defs>
+ </svg>
+ )
+
+ const MoonEmoji = () => (
+ <svg
+ width="24"
+ height="24"
+ fill="currentColor"
+ className="transition-colors duration-200 text-gray-300"
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M9.353 2.939a1 1 0 01.22 1.08 8 8 0 0010.408 10.408 1 1 0 011.301 1.3A10.003 10.003 0 0112 22C6.477 22 2 17.523 2 12c0-4.207 2.598-7.805 6.273-9.282a1 1 0 011.08.22z"
+ />
+ </svg>
+ )
+
return (
<footer className="bg-white dark:bg-dark-400" aria-labelledby="footerHeading">
<h2 id="footerHeading" className="sr-only">Footer</h2>
@@ -58,10 +123,33 @@ const Footer = () => {
</div>
</div>
</div>
- <div className="mt-12 border-t border-gray-200 pt-8">
+ <div className="mt-12 border-t border-gray-200 pt-8 flex justify-between">
<p className="text-base text-gray-400">
&copy; Supabase Inc
</p>
+ <div className="flex items-center">
+ <SunEmoji />
+ <button
+ type="button"
+ aria-pressed="false"
+ className={`
+ relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer
+ transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2
+ focus:ring-brand-500 ${darkMode ? 'bg-dark-200' : 'bg-gray-200'} mx-5
+ `}
+ onClick={() => toggleDarkMode()}
+ >
+ <span className="sr-only">Toggle Themes</span>
+ <span
+ aria-hidden="true"
+ className={`
+ ${darkMode ? 'translate-x-5' : 'translate-x-0'} inline-block h-5 w-5 rounded-full
+ bg-white shadow-lg transform ring-0 transition ease-in-out duration-200
+ `}
+ />
+ </button>
+ <MoonEmoji />
+ </div>
</div>
</div>
</footer>
diff --git a/www/components/layout.tsx b/www/components/layout.tsx
index 938b9a0e70b..278ee0bd106 100644
--- a/www/components/layout.tsx
+++ b/www/components/layout.tsx
@@ -1,3 +1,4 @@
+import { useEffect } from 'react'
import Nav from 'components/Nav/index'
import Footer from 'components/Footer/index'
import Meta from 'components/meta'
@@ -8,6 +9,16 @@ type Props = {
}
const Layout = ({ preview, children }: Props) => {
+
+ useEffect(() => {
+ const darkMode = localStorage.getItem('supabaseDarkMode')
+ if (darkMode) document.documentElement.className = darkMode === 'true' ? 'dark' : ''
+ }, [])
+
+ const updateTheme = (isDarkMode: boolean) => {
+ document.documentElement.className = isDarkMode ? 'dark' : ''
+ }
+
return (
<>
<Meta />
@@ -15,7 +26,7 @@ const Layout = ({ preview, children }: Props) => {
<div className="min-h-screen bg-gray-100">
<main>{children}</main>
</div>
- <Footer />
+ <Footer updateTheme={updateTheme} />
</>
)
}