Readme Badge
shieldcn/readme-badgeFreeComponent
Renders a shieldcn badge image with optional link wrapping. Works with any badge URL — shieldcn, shields.io, or custom images.
Live preview
live · rendered by the registry
Rendered by shieldcn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shieldcn.dev/r/readme-badge.jsonSource
1/**2 * shieldcn3 * ReadmeBadge4 * by Justin Levine5 * shieldcn.dev6 *7 * Renders a shieldcn badge image with optional link wrapping.8 * Works with any shieldcn badge URL or any image URL.9 *10 * Props:11 * - src: badge image URL (shieldcn, shields.io, or any image)12 * - alt: accessible alt text for the badge13 * - href?: optional link URL — wraps the badge in an anchor tag14 * - height?: image height in pixels (default 20)15 * - className?: class name for the outer element (link or image)16 * - imgClassName?: class name for the img element (when href is set)17 */1819import * as React from "react"20import { cn } from "@/lib/utils"2122interface ReadmeBadgeProps extends React.ComponentProps<"img"> {23 /** Badge image URL. */24 src: string25 /** Accessible alt text. */26 alt: string27 /** Optional link — wraps badge in an anchor. */28 href?: string29 /** Image height in pixels. @default 20 */30 height?: number31 /** Class name for the outer element. */32 className?: string33 /** Class name for the img element when wrapped in a link. */34 imgClassName?: string35}3637function ReadmeBadge({38 src,39 alt,40 href,41 height = 20,42 className,43 imgClassName,44 ...props45}: ReadmeBadgeProps) {46 const img = (47 // eslint-disable-next-line @next/next/no-img-element48 <img49 src={src}50 alt={alt}51 height={height}52 className={cn(53 "inline-block align-middle",54 href ? imgClassName : className55 )}56 loading="lazy"57 decoding="async"58 {...props}59 />60 )6162 if (href) {63 return (64 <a65 href={href}66 target="_blank"67 rel="noopener noreferrer"68 className={cn("inline-flex", className)}69 >70 {img}71 </a>72 )73 }7475 return img76}7778export { ReadmeBadge }79export type { ReadmeBadgeProps }
Files it writes
More from shieldcn
All 3 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Badge Previewbadge-preview | shieldcn | Components | Free | no deps | |
| Readme Badge Rowreadme-badge-row | shieldcn | Components | Free | no deps |
