Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
97577c6b
Unverified
Commit
97577c6b
authored
Jul 15, 2022
by
N
Committed by
GitHub
Jul 15, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #47 from blockscout/dark-theme-2
dark mode: custom switcher
parents
2867abd1
00731b3e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
11 deletions
+26
-11
ColorModeToggler.module.css
ui/header/ColorModeToggler.module.css
+2
-2
ColorModeToggler.tsx
ui/header/ColorModeToggler.tsx
+24
-9
No files found.
ui/header/ColorModeToggler.module.css
View file @
97577c6b
...
...
@@ -35,11 +35,11 @@
height
:
24px
;
border-radius
:
12px
;
position
:
absolute
;
transform
:
translate
(
4
4
px
,
4px
);
transform
:
translate
(
4px
,
4px
);
}
.thumb
[
data-checked
]
{
transform
:
translate
(
4px
,
4px
);
transform
:
translate
(
4
4
px
,
4px
);
}
.nightIcon
{
...
...
ui/header/ColorModeToggler.tsx
View file @
97577c6b
...
...
@@ -17,6 +17,8 @@ import { useColorMode, useColorModeValue } from '@chakra-ui/react';
import
styles
from
'
./ColorModeToggler.module.css
'
;
const
TRANSITION_DURATION
=
150
;
export
interface
ColorModeTogglerProps
extends
Omit
<
UseCheckboxProps
,
'
isIndeterminate
'
>
,
Omit
<
HTMLChakraProps
<
'
label
'
>
,
keyof
UseCheckboxProps
>
,
...
...
@@ -25,7 +27,8 @@ export interface ColorModeTogglerProps
export
const
ColorModeToggler
=
forwardRef
<
ColorModeTogglerProps
,
'
input
'
>
((
props
,
ref
)
=>
{
const
ownProps
=
omitThemingProps
(
props
);
const
{
toggleColorMode
}
=
useColorMode
();
const
{
toggleColorMode
,
colorMode
}
=
useColorMode
();
const
[
isOn
,
setMode
]
=
React
.
useState
(
colorMode
===
'
light
'
);
const
{
state
,
...
...
@@ -34,17 +37,29 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
getRootProps
,
}
=
useCheckbox
(
ownProps
);
const
trackStyles
:
SystemStyleObject
=
{
bg
:
useColorModeValue
(
'
blackAlpha.100
'
,
'
whiteAlpha.200
'
),
}
const
trackBg
=
useColorModeValue
(
'
blackAlpha.100
'
,
'
whiteAlpha.200
'
)
const
thumbBg
=
useColorModeValue
(
'
white
'
,
'
black
'
)
const
trackStyles
:
SystemStyleObject
=
React
.
useMemo
(()
=>
({
bg
:
trackBg
,
}),
[
trackBg
])
const
thumbStyles
:
SystemStyleObject
=
React
.
useMemo
(()
=>
({
bg
:
thumbBg
,
transitionProperty
:
'
transform
'
,
transitionDuration
:
`
${
TRANSITION_DURATION
}
ms`
,
}),
[
thumbBg
])
const
thumbStyles
:
SystemStyleObject
=
{
bg
:
useColorModeValue
(
'
white
'
,
'
black
'
),
}
const
handleInputChange
=
React
.
useCallback
(()
=>
{
// was not able to make transition while consuming flag value from chakra's useColorMode hook
// that's why there is a local state for toggler and this fancy window.setTimeout
setMode
((
isOn
)
=>
!
isOn
);
window
.
setTimeout
(
toggleColorMode
,
TRANSITION_DURATION
);
},
[
toggleColorMode
]);
return
(
<
chakra
.
label
{
...
getRootProps
({
onChange
:
toggleColorMod
e
})
}
{
...
getRootProps
({
onChange
:
handleInputChang
e
})
}
className=
{
styles
.
root
}
>
<
input
className=
{
styles
.
input
}
{
...
getInputProps
({},
ref
)
}
/>
...
...
@@ -56,7 +71,7 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
<
MoonIcon
className=
{
styles
.
nightIcon
}
boxSize=
{
4
}
color=
{
useColorModeValue
(
'
blue.600
'
,
'
white
'
)
}
/>
<
chakra
.
div
className=
{
styles
.
thumb
}
data
-
checked=
{
dataAttr
(
state
.
isChecked
)
}
data
-
checked=
{
dataAttr
(
isOn
)
}
data
-
hover=
{
dataAttr
(
state
.
isHovered
)
}
__css=
{
thumbStyles
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment