Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Logo for Astro

Astro brand containers with optional home-page links.

Installation

bunx --bun shadcn@latest add @gnostic/logo
npx shadcn@latest add @gnostic/logo
pnpm dlx shadcn@latest add @gnostic/logo

Component 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

  • Logo becomes an anchor automatically when you pass href.
  • LogoImage is optional, which makes text-only marks straightforward.
  • Use src for a single logo. Pass { light, dark } when the mark changes by theme.
  • Use Logo for compact brand marks and site headers, not for general-purpose hero artwork.

Examples

Adjust the container width to see the logo image and text respond to the container width.

The Logo accepts a default slot, where you can pass an SVG component.

API Reference

LogoImageProps

PropType
src?| ImageMetadata | { light: ImageMetadata dark: ImageMetadata }

One image for both modes, or a light and dark pair.

Type| ImageMetadata | { light: ImageMetadata dark: ImageMetadata }

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.