-
Notifications
You must be signed in to change notification settings - Fork 1
feat/themes #526
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
base: main
Are you sure you want to change the base?
feat/themes #526
Changes from 8 commits
50f6c8a
f612602
34023eb
a704774
ea12ed3
1130d3e
f90b7c4
4d74d26
5e27670
d2af6a2
beb8805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use client' | ||
|
|
||
| import { applyTheme, themes } from '@/app/users/[username]/(user-admin)/theme/theme' | ||
| import { useEffect } from 'react' | ||
| import type { ThemeName } from '@/app/users/[username]/(user-admin)/theme/theme' | ||
|
|
||
| export default function ThemeEnabler() { | ||
| useEffect(() => { | ||
| const saved = localStorage.getItem('theme') as ThemeName | ||
| if (saved && themes[saved]) { | ||
| applyTheme(saved) | ||
| } | ||
| }, []) | ||
| return (<span></span>) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,8 @@ export default function Locker() { | |
| return ( | ||
| <div className={styles.wrapper}> | ||
| <h3>Skapreservasjoner</h3> | ||
| <Link href={'/admin/lockers/location'}>Oppret ny skaplokasjon</Link> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm I see we have added aria-labels many places. Good ideas (should probably be a lint rule). But why are they written in english? |
||
| <Link href={'/admin/lockers/locker'}>Opprett nytt skap</Link> | ||
| <Link aria-label={'Create new locker location'} href={'/admin/lockers/location'}>Oppret ny skaplokasjon</Link> | ||
|
kake21 marked this conversation as resolved.
Outdated
|
||
| <Link aria-label={'Create new locker'} href={'/admin/lockers/locker'}>Opprett nytt skap</Link> | ||
| </div> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import { unwrapActionReturn } from './redirectToErrorPage' | |
| import { frontpageAuth } from '@/services/frontpage/auth' | ||
| import { ServerSession } from '@/auth/session/ServerSession' | ||
| import type { Metadata } from 'next' | ||
| import ThemeEnabler from '@/UI/ThemeEnabler' | ||
|
|
||
| config.autoAddCss = false | ||
|
|
||
|
|
@@ -51,6 +52,7 @@ export default async function RootLayout({ children }: PropTypes) { | |
| return ( | ||
| <html lang="en"> | ||
| <body className={`${inter.className} ${styles.body}`}> | ||
| <ThemeEnabler></ThemeEnabler> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. autoclose this one maybe |
||
| <SessionProvider session={session}> | ||
| <DefaultPermissionsProvider defaultPermissions={defaultPermissions}> | ||
| <EditModeProvider> | ||
|
|
@@ -59,9 +61,9 @@ export default async function RootLayout({ children }: PropTypes) { | |
| <div className={styles.navBar}> | ||
| <NavBar profile={profile} canEditSpecialCmsImage={canEditSpecialCmsImage} /> | ||
| </div> | ||
| <div className={styles.content}> | ||
| <main className={styles.content}> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably a good idea as long as no pages use main internally |
||
| {children} | ||
| </div> | ||
| </main> | ||
| <div className={styles.footer}> | ||
| <Footer canEditSpecialCmsImage={canEditSpecialCmsImage} /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,10 @@ | ||
| 'use client' | ||
|
|
||
| import styles from './page.module.scss' | ||
|
|
||
| enum ThemeName { | ||
| Standard = 'Standard', | ||
| Light = 'Light', | ||
| Solarized = 'Solarized', | ||
| StjerneInnbygger = 'StjerneInnbygger', | ||
| } | ||
|
|
||
| type ThemeColors = { | ||
| primary: string; | ||
| secondary: string; | ||
| layer: string; | ||
| text: string; | ||
| textMuted: string; | ||
| }; | ||
|
|
||
| const themes: Record<ThemeName, ThemeColors> = { | ||
| [ThemeName.Standard]: { | ||
| primary: 'hsl(210, 70%, 50%)', | ||
| secondary: 'hsl(210, 5%, 12%)', | ||
| layer: 'hsl(210, 0%, 0%, 20%)', | ||
| text: 'hsl(0, 0%, 80%)', | ||
| textMuted: 'hsl(0, 0%, 70%)', | ||
| }, | ||
| [ThemeName.Light]: { | ||
| primary: 'hsl(210, 98%, 50%)', | ||
| secondary: 'hsl(210, 18%, 95%)', | ||
| layer: 'hsl(0, 0%, 0%, 5%)', | ||
| text: 'hsl(0, 0%, 10%)', | ||
| textMuted: 'hsl(0, 0%, 20%)', | ||
| }, | ||
| [ThemeName.Solarized]: { | ||
| primary: 'hsl(210, 98%, 50%)', | ||
| secondary: 'hsl(44, 87%, 94%)', | ||
| layer: 'hsl(0, 0%, 50%, 15%)', | ||
| text: 'hsl(196, 13%, 45%)', | ||
| textMuted: 'hsl(180, 7%, 60%)', | ||
| }, | ||
| [ThemeName.StjerneInnbygger]: { | ||
| primary: 'hsl(207, 91%, 65%)', | ||
| secondary: 'hsl(202, 64%, 10%)', | ||
| layer: 'hsla(211, 48.1%, 35.5%, 0.18)', | ||
| text: 'hsl(0, 0%, 80%)', | ||
| textMuted: 'hsl(0, 0%, 70%)', | ||
| }, | ||
| } | ||
| import { themes, applyTheme } from './theme' | ||
| import type { ThemeName } from './theme' | ||
|
|
||
| export default function ThemeForm() { | ||
| function applyTheme(name: ThemeName): void { | ||
| const colors = themes[name] | ||
| const root = document.documentElement | ||
| Object.entries(colors).forEach(([key, value]) => { | ||
| root.style.setProperty(`--${key}`, value) | ||
| }) | ||
| } | ||
|
|
||
| return ( | ||
| <div className={styles.ThemeWrapper}> | ||
| {Object.entries(themes).map(([name, colors]) => ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can avoid type cast by looping over enum values |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| export enum ThemeName { | ||
| Standard = 'Standard', | ||
| Light = 'Light', | ||
| Solarized = 'Solarized', | ||
| StjerneInnbygger = 'StjerneInnbygger', | ||
| } | ||
|
|
||
| type ThemeColors = { | ||
| primary: string; | ||
| secondary: string; | ||
| layer: string; | ||
| text: string; | ||
| textMuted: string; | ||
| }; | ||
|
|
||
| export const themes: Record<ThemeName, ThemeColors> = { | ||
| [ThemeName.Standard]: { | ||
| primary: 'hsl(210, 70%, 50%)', | ||
| secondary: 'hsl(210, 5%, 12%)', | ||
| layer: 'hsl(210, 0%, 0%, 20%)', | ||
| text: 'hsl(0, 0%, 80%)', | ||
| textMuted: 'hsl(0, 0%, 70%)', | ||
| }, | ||
| [ThemeName.Light]: { | ||
| primary: 'hsl(210, 98%, 50%)', | ||
| secondary: 'hsl(210, 18%, 95%)', | ||
| layer: 'hsl(0, 0%, 0%, 5%)', | ||
| text: 'hsl(0, 0%, 10%)', | ||
| textMuted: 'hsl(0, 0%, 20%)', | ||
| }, | ||
| [ThemeName.Solarized]: { | ||
| primary: 'hsl(210, 98%, 50%)', | ||
| secondary: 'hsl(44, 87%, 94%)', | ||
| layer: 'hsl(0, 0%, 50%, 15%)', | ||
|
kake21 marked this conversation as resolved.
Outdated
|
||
| text: 'hsl(196, 13%, 45%)', | ||
| textMuted: 'hsl(180, 7%, 60%)', | ||
| }, | ||
| [ThemeName.StjerneInnbygger]: { | ||
| primary: 'hsl(207, 91%, 65%)', | ||
| secondary: 'hsl(202, 64%, 10%)', | ||
| layer: 'hsla(211, 48.1%, 35.5%, 0.18)', | ||
| text: 'hsl(0, 0%, 80%)', | ||
| textMuted: 'hsl(0, 0%, 70%)', | ||
| }, | ||
| } | ||
|
|
||
| export function applyTheme(name: ThemeName): void { | ||
| localStorage.setItem('theme', name) | ||
| const colors = themes[name] | ||
| const root = document.documentElement | ||
| Object.entries(colors).forEach(([key, value]) => { | ||
| root.style.setProperty(`--${key}`, value) | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.