Skip to content

Commit

Permalink
feat: add dark mode, sync from system (#14)
Browse files Browse the repository at this point in the history
* feat: fix css unset hover for dark mode

* feat: add dark mode, sync from system

* fix: ts standard
  • Loading branch information
fouwels authored Dec 29, 2023
1 parent a7c71e2 commit 2e5fae8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function banner (): undefined {
)
}
banner()

const router = ReactRouter.createHashRouter([
{
path: '',
Expand Down
15 changes: 15 additions & 0 deletions lib/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as React from 'react'
import * as Polaris from '@cloudscape-design/components'
import { PolarisTopNavigation } from '../../localisation/en-gb'
import { Inspect } from '../exp/panopticon'
import * as PolarisStyles from '@cloudscape-design/global-styles'

export function Header (): React.ReactElement {
const [identifier, setIdentifier] = React.useState<string | undefined>()
const [dark, setDark] = React.useState(window.matchMedia('(prefers-color-scheme: dark)').matches)

React.useEffect(() => {
const run = async (): Promise<void> => {
Expand All @@ -18,6 +20,10 @@ export function Header (): React.ReactElement {
void run()
}, [])

React.useEffect(() => {
dark ? PolarisStyles.applyMode(PolarisStyles.Mode.Dark) : PolarisStyles.applyMode(PolarisStyles.Mode.Light)
})

const identity: Polaris.TopNavigationProps.Identity = {
href: '#',
title: 'Fouwels',
Expand All @@ -28,6 +34,15 @@ export function Header (): React.ReactElement {
}

const utilities: Polaris.TopNavigationProps.Utility[] = [
{
type: 'button',
onClick: () => {
setDark(!dark)
},
iconName: (() => {
return dark ? 'star' : 'star-filled'
})()
},
{
type: 'button',
text: identifier === undefined ? 'Identifier Not Known' : identifier,
Expand Down
2 changes: 1 addition & 1 deletion lib/components/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function Navigation (): React.ReactElement {
{ type: 'divider' },
{
type: 'link',
text: 'Experimental',
text: 'Experiment',
href: '#/experiments',
external: false
},
Expand Down
4 changes: 1 addition & 3 deletions lib/exp/knock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export async function RFC5245 (callback: RFC5245Callback): Promise<void> {
}, () => { })
}



export function Knock (): React.ReactElement {
const [candidate, setCandidate] = React.useState<Candidate | undefined>()

Expand All @@ -90,4 +88,4 @@ export function Knock (): React.ReactElement {
</Polaris.Container>
</>
)
}
}
2 changes: 1 addition & 1 deletion static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body {
}

a {
color: black;
color: unset;
text-decoration: none;
}

Expand Down

0 comments on commit 2e5fae8

Please sign in to comment.