Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 12:00 UTC
fix: Address PR feedback for Figure component
- Add priority prop for LCP optimization on above-the-fold images - Use size-appropriate default dimensions to minimize CLS - Improve sizes attribute with better breakpoints Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sushmithamallesh committed
Jan 28, 2026 at 15:34 UTC
1c48dcd54ad363b7b346d2d8dad73ec7996c037b
1 file changed
+20
-7
docs/components/figure.tsx
+20
-7
@@ -16,6 +16,8 @@ interface FigureProps {
16
className?: string;
17
width?: number;
18
height?: number;
19
+ /** Set to true for above-the-fold images to prioritize LCP */
20
+ priority?: boolean;
21
}
22
23
const sizeClasses: Record<FigureSize, string> = {
@@ -25,16 +27,26 @@ const sizeClasses: Record<FigureSize, string> = {
27
full: 'max-w-full', // Full-width diagrams
28
};
29
30
+// Default dimensions per size to minimize CLS
31
+const defaultDimensions: Record<FigureSize, { width: number; height: number }> = {
32
+ sm: { width: 300, height: 200 },
33
+ md: { width: 500, height: 333 },
34
+ lg: { width: 700, height: 467 },
35
+ full: { width: 900, height: 600 },
36
+};
37
+
38
+// Responsive sizes for optimal image loading
39
const sizesAttr: Record<FigureSize, string> = {
29
- sm: '(max-width: 300px) 100vw, 300px',
30
- md: '(max-width: 500px) 100vw, 500px',
31
- lg: '(max-width: 700px) 100vw, 700px',
32
- full: '(max-width: 768px) 100vw, (max-width: 1200px) 70vw, 900px',
40
+ sm: '(max-width: 640px) 100vw, 300px',
41
+ md: '(max-width: 640px) 100vw, 500px',
42
+ lg: '(max-width: 640px) 100vw, (max-width: 768px) 90vw, 700px',
43
+ full: '(max-width: 640px) 100vw, (max-width: 1024px) 90vw, min(900px, 70vw)',
44
};
45
35
-export function Figure({ src, alt, caption, size = 'full', className, width, height }: FigureProps) {
46
+export function Figure({ src, alt, caption, size = 'full', className, width, height, priority = false }: FigureProps) {
47
const [isLoaded, setIsLoaded] = useState(false);
48
const isConstrained = size !== 'full';
49
+ const dimensions = defaultDimensions[size];
50
51
return (
52
<figure className={cn('my-8', isConstrained && 'flex flex-col items-center', className)}>
@@ -42,9 +54,10 @@ export function Figure({ src, alt, caption, size = 'full', className, width, hei
54
<Image
55
src={src}
56
alt={alt}
45
- width={width || 1200}
46
- height={height || 800}
57
+ width={width || dimensions.width}
58
+ height={height || dimensions.height}
59
sizes={sizesAttr[size]}
60
+ priority={priority}
61
onLoad={() => setIsLoaded(true)}
62
className={cn(
63
'rounded-lg border border-fd-border transition-opacity duration-300',