-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from ryanhopperlowe/ui/fix/remove-flash-on-cr…
…eating/switching-threads fix: remove flash on creating new thread and switching threads
- Loading branch information
Showing
4 changed files
with
81 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
import { Loader2 } from "lucide-react"; | ||
import { ComponentProps } from "react"; | ||
|
||
import { cn } from "~/lib/utils"; | ||
|
||
export interface ISVGProps extends React.SVGProps<SVGSVGElement> { | ||
export interface LoadingSpinnerProps extends ComponentProps<typeof Loader2> { | ||
size?: number; | ||
className?: string; | ||
fillContainer?: boolean; | ||
classNames?: { | ||
root?: string; | ||
container?: string; | ||
}; | ||
} | ||
|
||
export const LoadingSpinner = ({ | ||
size = 24, | ||
className, | ||
fillContainer, | ||
classNames = {}, | ||
...props | ||
}: ISVGProps) => { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width={size} | ||
height={size} | ||
{...props} | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className={cn("animate-spin", className)} | ||
}: LoadingSpinnerProps) => { | ||
const content = ( | ||
<Loader2 className={cn("animate-spin", className)} {...props} /> | ||
); | ||
|
||
return fillContainer ? ( | ||
<div | ||
className={cn( | ||
"min-w-fit h-full flex-auto flex items-center justify-center", | ||
classNames.container | ||
)} | ||
> | ||
<path d="M21 12a9 9 0 1 1-6.219-8.56" /> | ||
</svg> | ||
{content} | ||
</div> | ||
) : ( | ||
content | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useCallback, useRef, useState } from "react"; | ||
|
||
export function useRefState<T>(initialValue: T) { | ||
const ref = useRef(initialValue); | ||
const [state, _setState] = useState(initialValue); | ||
|
||
const setState = useCallback((value: T) => { | ||
ref.current = value; | ||
_setState(value); | ||
}, []); | ||
|
||
return [ref, state, setState] as const; | ||
} |