Logo for Astro
Astro brand containers with optional home-page links.
Installation
bunx --bun shadcn@latest add @gnostic/logonpx shadcn@latest add @gnostic/logopnpm dlx shadcn@latest add @gnostic/logoComponent classes: Default Gnostic.
Complete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/logo/types.ts
import type { ImageMetadata } from 'astro'
import type { RemoteImageProps } from 'astro:assets'
import type { LocalImageProps } from 'astro:assets'
type SharedImageProps = Omit<RemoteImageProps | LocalImageProps, 'src'>
export type LogoImageProps = SharedImageProps & {
/**
* One image for both modes, or a light and dark pair.
*/
src?:
| ImageMetadata
| {
light: ImageMetadata
dark: ImageMetadata
}
}
src/components/ui/logo/index.ts
export { default as Logo } from "./logo.astro"
export { default as LogoImage } from "./logo-image.astro"
export { default as LogoText } from "./logo-text.astro"
src/components/ui/logo/logo-image.astro
---
import { Image } from "astro:assets"
import type { LogoImageProps } from "./types"
import { cn } from "cn"
type Props = LogoImageProps
const {
class: className,
src,
alt = "logo",
sizes = "200px",
widths = [200],
...props
} = Astro.props
const baseClasses = "w-auto shrink-0 h-6"
let srcLight: ImageMetadata | undefined = undefined
let srcDark: ImageMetadata | undefined = undefined
if (src && "light" in src && "dark" in src) {
srcLight = src.light
srcDark = src.dark
}
---
{srcLight && srcDark ? (
<>
<Image
class={cn(baseClasses, "dark:hidden", className)}
data-slot="logo-image"
src={srcLight}
fit="contain"
alt={alt}
sizes={sizes}
widths={widths}
{...(props as any)}
/>
<Image
class={cn(baseClasses, "hidden dark:block", className)}
data-slot="logo-image"
src={srcDark}
fit="contain"
sizes={sizes}
widths={widths}
alt={alt}
{...(props as any)}
/>
</>
) : src ? (
<Image
class={cn(baseClasses, className)}
data-slot="logo-image"
src={src}
fit="contain"
sizes={sizes}
widths={widths}
alt={alt}
{...(props as any)}
/>
) : null}
src/components/ui/logo/logo-text.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"span">
const { class: className, ...props } = Astro.props
---
<span class={cn("text-lg", className)} {...props}>
<slot />
</span>
src/components/ui/logo/logo.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"div"> & HTMLAttributes<"a">
const { class: className, href, ...props } = Astro.props
const Comp = href ? "a" : "div"
---
<Comp data-slot="logo" class={cn("flex h-10 items-center justify-start gap-2 text-base font-semibold whitespace-nowrap", className)} href={href} {...props}>
<slot />
</Comp>
Usage
import { Logo, LogoImage, LogoText } from "@/components/ui/logo"
import logo from "@/assets/logo.svg"
<Logo>
<LogoImage src={logo} alt="Logo" />
<LogoText>gnosticai UI</LogoText>
</Logo>
For theme-specific marks, pass both sources on src.
<Logo href="/">
<LogoImage src={{ light: logoLight, dark: logoDark }} alt="Logo" />
<LogoText>gnosticai UI</LogoText>
</Logo>
Notes
Logobecomes an anchor automatically when you passhref.LogoImageis optional, which makes text-only marks straightforward.- Use
srcfor a single logo. Pass{ light, dark }when the mark changes by theme. - Use
Logofor compact brand marks and site headers, not for general-purpose hero artwork.
Examples
Responsive Logo
Adjust the container width to see the logo image and text respond to the container width.
SVG Logo
The Logo accepts a default slot, where you can pass an SVG component.
API Reference
LogoImageProps
src?| ImageMetadata
| {
light: ImageMetadata
dark: ImageMetadata
}
One image for both modes, or a light and dark pair.
| ImageMetadata
| {
light: ImageMetadata
dark: ImageMetadata
}When to use Logo
Place a symbol, wordmark, or text inside Logo. Set href when it should act as a link. Keep the brand mark separate from navigation so it can be reused in headers and footers.
Keyboard and behavior
A linked image needs an accessible name for its destination. If the wordmark is also visible text, avoid announcing the name twice. Use a normal anchor for home navigation.
Theme and layout
Check the mark on light, dark, and tinted surfaces. Prefer artwork with an intentional dark-mode treatment instead of applying a filter that changes brand colors unpredictably.