Skip to content

Commit

Permalink
Fix: Add loader to Icon to prevent layout shifts/flickering (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Herrmann authored Aug 28, 2023
2 parents b4fb58d + 2d6ee12 commit 2884d2e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/Icon/index.tsx
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} />;
}

0 comments on commit 2884d2e

Please sign in to comment.