Primitives

Vector

Display SVG graphics inline with color inheritance support

The Vector component renders SVG files inline, allowing them to inherit colors from CSS text color classes. Perfect for logos, icons, and illustrations that need to adapt to different color schemes.

Responsive layout (default)

SVG scales to fit container width and inherits text color via currentColor.

responsive
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="w-64 text-primary">
  <Vector src={demoSvg} ariaLabel="Compass icon" />
</div>

Color inheritance

The Vector component uses currentColor to inherit from text color classes.

color-inheritance
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="flex gap-6">
  <div class="w-32 text-primary">
    <Vector src={demoSvg} ariaLabel="Primary compass" />
  </div>
  <div class="w-32 text-secondary">
    <Vector src={demoSvg} ariaLabel="Secondary compass" />
  </div>
  <div class="w-32 text-accent">
    <Vector src={demoSvg} ariaLabel="Accent compass" />
  </div>
  <div class="w-32 text-error">
    <Vector src={demoSvg} ariaLabel="Error compass" />
  </div>
</div>

Fixed size

Use fixed layout with explicit width and height for precise dimensions.

fixed-size
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="flex gap-6 items-center">
  <div class="text-primary">
    <Vector src={demoSvg} layout="fixed" width={128} height={128} ariaLabel="Large compass" />
  </div>
  <div class="text-secondary">
    <Vector src={demoSvg} layout="fixed" width={64} height={64} ariaLabel="Medium compass" />
  </div>
  <div class="text-accent">
    <Vector src={demoSvg} layout="fixed" width={32} height={32} ariaLabel="Small compass" />
  </div>
</div>

Alignment

Control horizontal alignment with the align prop: left, center, or right.

alignment
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="space-y-4">
  <div class="text-primary">
    <Vector
      src={demoSvg}
      layout="fixed"
      width={100}
      height={100}
      align="left"
      ariaLabel="Left aligned"
    />
  </div>
  <div class="text-secondary">
    <Vector
      src={demoSvg}
      layout="fixed"
      width={100}
      height={100}
      align="center"
      ariaLabel="Center aligned"
    />
  </div>
  <div class="text-accent">
    <Vector
      src={demoSvg}
      layout="fixed"
      width={100}
      height={100}
      align="right"
      ariaLabel="Right aligned"
    />
  </div>
</div>

Fill layout

SVG fills the entire container dimensions. Useful for background graphics.

fill
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="h-64">
  <div class="text-primary/20 h-full">
    <Vector src={demoSvg} layout="fill" ariaLabel="Background compass" />
  </div>
</div>

Preserve original colors

Use preserveColors to keep the SVG’s original colors instead of applying currentColor.

With currentColor

Original colors

preserve-colors
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="flex gap-12">
  <div class="w-32">
    <div class="text-primary">
      <Vector src={demoSvg} ariaLabel="With currentColor" />
    </div>
    <p class="text-xs mt-2 text-center">With currentColor</p>
  </div>
  <div class="w-32">
    <Vector src={demoSvg} preserveColors ariaLabel="Original colors" />
    <p class="text-xs mt-2 text-center">Original colors</p>
  </div>
</div>

Custom classes

Add custom Tailwind classes for additional styling like opacity, filters, and transforms.

custom-classes
---
import Vector from '@alfadormx/blocks/primitives/Vector.astro';

const demoSvg = 'https://www.svgrepo.com/show/513167/basketball.svg';
---

<div class="flex gap-6">
  <div class="w-32 text-primary">
    <Vector src={demoSvg} class="opacity-50" ariaLabel="Semi-transparent" />
  </div>
  <div class="w-32 text-secondary">
    <Vector src={demoSvg} class="rotate-45" ariaLabel="Rotated 45 degrees" />
  </div>
  <div class="w-32 text-accent">
    <Vector
      src={demoSvg}
      class="scale-110 hover:scale-125 transition-transform"
      ariaLabel="Scalable"
    />
  </div>
</div>

API Reference

PropTypeDefaultDescription
srcstring | ImageMetadata—The SVG source: a path/URL string (root-relative, relative, external, or raw `<svg>` markup) or an imported `ImageMetadata` object, used to load the SVG content.
layoutVectorLayout'responsive'Layout mode controlling the wrapper's sizing behavior: 'responsive' fills width/height and centers content, 'fixed' sizes to the given width/height, 'intrinsic' sizes to the SVG's natural dimensions, 'fill' stretches to fill the container (default: 'responsive').
widthnumber | string—Width of the wrapper; applied as inline CSS (in px if a number) only when layout is 'fixed'.
heightnumber | string—Height of the wrapper; applied as inline CSS (in px if a number) only when layout is 'fixed'.
alignVectorAlign—Horizontal alignment of the SVG within the wrapper for non-'fill' layouts.
classstring''Additional CSS class names appended to the wrapper element (default: '').
ariaLabelstring—Accessible label added as `aria-label` on the rendered `<svg>` element (also sets `role="img"`) when provided.
preserveColorsbooleanfalseWhen true, keeps the SVG's original fill/stroke colors instead of replacing them with `currentColor` (default: false).