Dot pattern
surfacesGratisMITEt stille prikmønster bag indholdet, tegnet med ren CSS.
npx shadcn@latest add https://mikkelmanniche.dk/lab/r/dot-pattern.jsonPreview
Forhåndsvisningen kunne ikke hentes.
Live demo i det mørke tema.
Kode
Installér
npx shadcn@latest add https://mikkelmanniche.dk/lab/r/dot-pattern.jsonMed registret tilføjet (components.json)
npx shadcn@latest add @manniche/dot-patternBrug
dot-pattern-demo.tsx
import { DotPattern } from '@/components/dot-pattern'
export default function DotPatternDemo() {
return (
<DotPattern className="rounded-3xl px-6 py-14 text-center">
<p className="font-serif text-2xl">Depth without images</p>
</DotPattern>
)
}Kilde
dot-pattern.tsx
import type { CSSProperties, HTMLAttributes } from 'react'
import { cn } from '@/lib/utils'
export type DotPatternProps = HTMLAttributes<HTMLDivElement> & {
/** Distance between dots in pixels. */
spacing?: number
/** Fade the dots out towards the edges. */
vignette?: boolean
}
/**
* A quiet dot grid behind content, drawn with CSS gradients only. No images, no motion.
* The dots take the foreground colour at low strength, so they work in light and dark.
*/
export function DotPattern({ spacing = 18, vignette = true, className, style, children, ...rest }: DotPatternProps) {
return (
<div
style={{ '--dot-gap': `${spacing}px`, ...style } as CSSProperties}
className={cn(
'relative isolate overflow-hidden rounded-2xl bg-card',
'bg-[radial-gradient(color-mix(in_oklch,var(--color-foreground)_16%,transparent)_1px,transparent_1.5px)] bg-size-[var(--dot-gap)_var(--dot-gap)]',
className,
)}
{...rest}
>
{vignette && (
<span
aria-hidden
className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(ellipse_at_center,transparent_30%,var(--color-card)_78%)]"
/>
)}
{children}
</div>
)
}Props
DotPatternProps
| Prop | Type | Standard | Hvad den gør |
|---|---|---|---|
spacing | number | 18 | Distance between dots in pixels. |
vignette | boolean | true | Fade the dots out towards the edges. |
Tager også alle props fra HTMLAttributes<HTMLDivElement>.
A11y
Skærmlæser
Decorative only, with no interactive parts. The dots are a CSS background; the vignette span (vignette, default true) is aria-hidden.