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
00731b3e
Commit
00731b3e
authored
Jul 13, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transition
parent
0e286a6c
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 @
00731b3e
...
@@ -35,11 +35,11 @@
...
@@ -35,11 +35,11 @@
height
:
24px
;
height
:
24px
;
border-radius
:
12px
;
border-radius
:
12px
;
position
:
absolute
;
position
:
absolute
;
transform
:
translate
(
4
4
px
,
4px
);
transform
:
translate
(
4px
,
4px
);
}
}
.thumb
[
data-checked
]
{
.thumb
[
data-checked
]
{
transform
:
translate
(
4px
,
4px
);
transform
:
translate
(
4
4
px
,
4px
);
}
}
.nightIcon
{
.nightIcon
{
...
...
ui/header/ColorModeToggler.tsx
View file @
00731b3e
...
@@ -17,6 +17,8 @@ import { useColorMode, useColorModeValue } from '@chakra-ui/react';
...
@@ -17,6 +17,8 @@ import { useColorMode, useColorModeValue } from '@chakra-ui/react';
import
styles
from
'
./ColorModeToggler.module.css
'
;
import
styles
from
'
./ColorModeToggler.module.css
'
;
const
TRANSITION_DURATION
=
150
;
export
interface
ColorModeTogglerProps
export
interface
ColorModeTogglerProps
extends
Omit
<
UseCheckboxProps
,
'
isIndeterminate
'
>
,
extends
Omit
<
UseCheckboxProps
,
'
isIndeterminate
'
>
,
Omit
<
HTMLChakraProps
<
'
label
'
>
,
keyof
UseCheckboxProps
>
,
Omit
<
HTMLChakraProps
<
'
label
'
>
,
keyof
UseCheckboxProps
>
,
...
@@ -25,7 +27,8 @@ export interface ColorModeTogglerProps
...
@@ -25,7 +27,8 @@ export interface ColorModeTogglerProps
export
const
ColorModeToggler
=
forwardRef
<
ColorModeTogglerProps
,
'
input
'
>
((
props
,
ref
)
=>
{
export
const
ColorModeToggler
=
forwardRef
<
ColorModeTogglerProps
,
'
input
'
>
((
props
,
ref
)
=>
{
const
ownProps
=
omitThemingProps
(
props
);
const
ownProps
=
omitThemingProps
(
props
);
const
{
toggleColorMode
}
=
useColorMode
();
const
{
toggleColorMode
,
colorMode
}
=
useColorMode
();
const
[
isOn
,
setMode
]
=
React
.
useState
(
colorMode
===
'
light
'
);
const
{
const
{
state
,
state
,
...
@@ -34,17 +37,29 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
...
@@ -34,17 +37,29 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
getRootProps
,
getRootProps
,
}
=
useCheckbox
(
ownProps
);
}
=
useCheckbox
(
ownProps
);
const
trackStyles
:
SystemStyleObject
=
{
const
trackBg
=
useColorModeValue
(
'
blackAlpha.100
'
,
'
whiteAlpha.200
'
)
bg
:
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
=
{
const
handleInputChange
=
React
.
useCallback
(()
=>
{
bg
:
useColorModeValue
(
'
white
'
,
'
black
'
),
// 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
(
return
(
<
chakra
.
label
<
chakra
.
label
{
...
getRootProps
({
onChange
:
toggleColorMod
e
})
}
{
...
getRootProps
({
onChange
:
handleInputChang
e
})
}
className=
{
styles
.
root
}
className=
{
styles
.
root
}
>
>
<
input
className=
{
styles
.
input
}
{
...
getInputProps
({},
ref
)
}
/>
<
input
className=
{
styles
.
input
}
{
...
getInputProps
({},
ref
)
}
/>
...
@@ -56,7 +71,7 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
...
@@ -56,7 +71,7 @@ export const ColorModeToggler = forwardRef<ColorModeTogglerProps, 'input'>((prop
<
MoonIcon
className=
{
styles
.
nightIcon
}
boxSize=
{
4
}
color=
{
useColorModeValue
(
'
blue.600
'
,
'
white
'
)
}
/>
<
MoonIcon
className=
{
styles
.
nightIcon
}
boxSize=
{
4
}
color=
{
useColorModeValue
(
'
blue.600
'
,
'
white
'
)
}
/>
<
chakra
.
div
<
chakra
.
div
className=
{
styles
.
thumb
}
className=
{
styles
.
thumb
}
data
-
checked=
{
dataAttr
(
state
.
isChecked
)
}
data
-
checked=
{
dataAttr
(
isOn
)
}
data
-
hover=
{
dataAttr
(
state
.
isHovered
)
}
data
-
hover=
{
dataAttr
(
state
.
isHovered
)
}
__css=
{
thumbStyles
}
__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