Skip to content

Commit

Permalink
feat: add notiolink config for theme
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorusclarence committed Feb 6, 2022
1 parent 04deb21 commit 3c9bf0d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
8 changes: 7 additions & 1 deletion notiolink.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ module.exports = {
/** Without additional '/' on the end, e.g. https://theodorusclarence.com */
deployUrl: 'https://notiolink.thcl.dev',

/** Make this to false */
/**
* Color theme for the app
* @type {'light' | 'dark' | 'milky' | 'street' | 'monokai'}
*/
theme: 'dark',

/** REQUIRED CONFIG: Set this to 'false' */
demoMode: 'true',
};
24 changes: 16 additions & 8 deletions src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import clsx from 'clsx';
import * as React from 'react';

import { demoMode } from '@/lib/config';
import { demoMode, theme as configTheme } from '@/lib/config';

export const themeColor = {
light: 'light',
dark: 'dark',
milky: 'theme-milky',
street: 'theme-street dark',
monokai: 'theme-monokai dark',
};

export default function Layout({ children }: { children: React.ReactNode }) {
const [theme, setTheme] = React.useState('dark');
const [theme, setTheme] = React.useState(themeColor[configTheme]);

return (
<div className={theme}>
Expand All @@ -14,18 +22,18 @@ export default function Layout({ children }: { children: React.ReactNode }) {
'milky:bg-[#fff5e3] street:bg-street-800'
)}
>
{demoMode && (
{demoMode === 'true' && (
<select
name='theme'
className='fixed top-4 left-4 rounded bg-transparent'
value={theme}
onChange={(e) => setTheme(e.target.value)}
>
<option value='light'>light</option>
<option value='dark'>dark</option>
<option value='theme-milky'>milky</option>
<option value='theme-street dark'>street</option>
<option value='theme-monokai dark'>monokai</option>
{Object.entries(themeColor).map(([theme, themeClass]) => (
<option key={theme} value={themeClass}>
{theme}
</option>
))}
</select>
)}
{children}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getSiteConfig } from '@/lib/get-config-value';

import { themeColor } from '@/components/layout/Layout';

// general site config
export const appName = getSiteConfig('appName');
export const seoDescription = getSiteConfig('seoDescription');
export const deployUrl = getSiteConfig('deployUrl');
export const demoMode = getSiteConfig('demoMode');
export const demoMode = getSiteConfig('demoMode', 'false');
export const theme = getSiteConfig('theme') as keyof typeof themeColor;

1 comment on commit 3c9bf0d

@vercel
Copy link

@vercel vercel bot commented on 3c9bf0d Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.