Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit d1cc698

Browse files
committed
updated darkModeButton format to match ui comp library
1 parent 0ee1c58 commit d1cc698

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

frontend/src/App.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { useQuery } from "@apollo/client";
33
import { gql } from './__generated__/gql';
44
import React from "react";
55
import { theme } from "./styles/theme"
6-
import { ChakraProvider, Alert, AlertIcon, AlertTitle, AlertDescription, Button, HStack, useColorMode } from "@chakra-ui/react";
6+
import { ChakraProvider, Alert, AlertIcon, AlertTitle, AlertDescription, Button, HStack, useColorMode, useColorModeValue } from "@chakra-ui/react";
77
import { Table } from "./components/Table";
88
import {Helmet} from 'react-helmet';
9-
import { DarkModeSwitch } from 'react-toggle-dark-mode';
109
import { DarkModeButton } from "./components/DarkModeButton";
1110

1211
const GET_INFO = gql(`
@@ -47,7 +46,7 @@ function DisplayPinInfo(): React.JSX.Element {
4746
const { colorMode, toggleColorMode } = useColorMode()
4847

4948
var loadingRows = loading ? 2 : 0
50-
var bgColour = colorMode === 'dark' ? "black" : "white"
49+
const bgColour = useColorModeValue('white', 'black')
5150

5251
if (error) return (
5352
<Alert status='error'>
@@ -92,12 +91,9 @@ function DisplayPinInfo(): React.JSX.Element {
9291
<>
9392
<div>
9493
<DarkModeButton
95-
aria-label='Search database'
9694
style={{ marginBottom: '1rem', marginLeft: '.25rem', marginTop: '.25rem', position: 'relative', left: '1875px'}}
97-
isDark={colorMode === 'dark'}
9895
onClick={toggleColorMode}
9996
variant={'unstyled'}
100-
colorScheme={colorMode === 'dark' ? '#a3a3a3' : 'white'}
10197
/>
10298
<Helmet>
10399
<style>{`body { background-color: ${bgColour} }`}</style>
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
import { IconButton, IconButtonProps} from '@chakra-ui/react'
2-
import React from 'react'
1+
import { IconButton, IconButtonProps, useColorMode, useColorModeValue } from '@chakra-ui/react'
32
import { SunIcon, MoonIcon } from '@chakra-ui/icons'
3+
import React from 'react'
44

5-
export interface DarkModeButtonProps extends IconButtonProps {
6-
isDark: boolean
7-
}
5+
export interface DarkModeButtonProps extends Omit<IconButtonProps, "aria-label"> { }
6+
7+
const DarkModeButton = ({ ...props }: DarkModeButtonProps) => {
8+
const { toggleColorMode } = useColorMode()
9+
10+
const label = useColorModeValue('Light Mode', 'Dark Mode')
11+
const iconColor = useColorModeValue('#2b2b2b', 'white')
12+
const icon = useColorModeValue(<SunIcon color={iconColor} />, <MoonIcon color={iconColor} />)
813

9-
const DarkModeButton = ({isDark, ...props}: DarkModeButtonProps) => {
1014
return (
11-
<IconButton icon={isDark ? <MoonIcon color='white'/> : <SunIcon color='#2b2b2b'/>} {...props}/>
15+
<IconButton
16+
aria-label={label}
17+
icon={icon}
18+
onClick={toggleColorMode}
19+
{...props}
20+
/>
1221
)
1322
}
1423

15-
export {DarkModeButton}
24+
export { DarkModeButton }

0 commit comments

Comments
 (0)