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.
---
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.
---
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.
---
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.
---
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.
---
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
---
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.
---
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
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | 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. |
| layout | VectorLayout | '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'). |
| width | number | string | — | Width of the wrapper; applied as inline CSS (in px if a number) only when layout is 'fixed'. |
| height | number | string | — | Height of the wrapper; applied as inline CSS (in px if a number) only when layout is 'fixed'. |
| align | VectorAlign | — | Horizontal alignment of the SVG within the wrapper for non-'fill' layouts. |
| class | string | '' | Additional CSS class names appended to the wrapper element (default: ''). |
| ariaLabel | string | — | Accessible label added as `aria-label` on the rendered `<svg>` element (also sets `role="img"`) when provided. |
| preserveColors | boolean | false | When true, keeps the SVG's original fill/stroke colors instead of replacing them with `currentColor` (default: false). |