-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Add loader to Icon to prevent layout shifts/flickering (#54)
- Loading branch information
Showing
1 changed file
with
10 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import styled from "@emotion/styled"; | ||
import { LucideProps } from "lucide-react"; | ||
import dynamicIconImports from "lucide-react/dynamicIconImports"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const Loader = styled.span({ | ||
display: "inline-block", | ||
}); | ||
|
||
export interface IconProps extends LucideProps { | ||
name: keyof typeof dynamicIconImports; | ||
} | ||
|
||
export default function Icon({ name, ...props }: IconProps) { | ||
const LucideIcon = dynamic(dynamicIconImports[name]); | ||
return <LucideIcon {...props} />; | ||
export default function Icon({ name, size = 24, ...props }: IconProps) { | ||
const LucideIcon = dynamic(dynamicIconImports[name], { | ||
loading: () => <Loader style={{ width: size, height: size }} />, | ||
}); | ||
return <LucideIcon size={size} {...props} />; | ||
} |