Skip to content

Commit

Permalink
[@mantine/core] Add option to keep transitions when color scheme chan…
Browse files Browse the repository at this point in the history
…ges in useMantineColorScheme hook (#5092)
  • Loading branch information
rtivital committed Oct 22, 2023
1 parent 8fe8b0b commit 1896312
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function disableTransition() {
return clear;
}

export function useMantineColorScheme() {
export function useMantineColorScheme({ keepTransitions }: { keepTransitions?: boolean }) {
const clearStylesRef = useRef<() => void>();
const timeoutRef = useRef<number>();
const ctx = useContext(MantineContext);
Expand All @@ -26,7 +26,7 @@ export function useMantineColorScheme() {

const setColorScheme = (value: MantineColorScheme) => {
ctx.setColorScheme(value);
clearStylesRef.current = disableTransition();
clearStylesRef.current = keepTransitions ? () => {} : disableTransition();
window.clearTimeout(timeoutRef.current);
timeoutRef.current = window.setTimeout(() => {
clearStylesRef.current?.();
Expand All @@ -35,7 +35,7 @@ export function useMantineColorScheme() {

const clearColorScheme = () => {
ctx.clearColorScheme();
clearStylesRef.current = disableTransition();
clearStylesRef.current = keepTransitions ? () => {} : disableTransition();
window.clearTimeout(timeoutRef.current);
timeoutRef.current = window.setTimeout(() => {
clearStylesRef.current?.();
Expand Down

0 comments on commit 1896312

Please sign in to comment.