# Dot Pattern

Grid titik kecil di belakang konten, dengan pudar radial atau linear opsional. Murni CSS, tanpa JavaScript.

- Kategori: Latar
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/dot-pattern.json
- CLI: `npx markasui@latest add dot-pattern`

## Kapan dipakai

Tekstur tenang di belakang hero, kartu CTA, empty state, atau section tanpa gambar.

- Atur warna latar, padding, dan radius lewat class pada komponen
- Pakai mask=radial di belakang teks tengah supaya titik memudar di bawah judul
- Pakai spacing antara 12 dan 28 untuk sebagian besar tata letak

## Kode

### Blade

Simpan di `resources/views/components/markas/dot-pattern.blade.php`. Tanpa dependensi tambahan.

```blade
@props([
    'spacing' => 16,
    'dotSize' => 1,
    'color' => 'muted',
    'mask' => 'none',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted/50',
        'primary' => 'text-primary/40',
        'success' => 'text-success/50',
        'warning' => 'text-warning/50',
        'danger' => 'text-danger/50',
    ];
    $masks = [
        'none' => '',
        'radial' => '[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]',
        'linear' => '[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]',
    ];

    $vars = '--markas-dot-spacing: '.(float) $spacing.'px; --markas-dot-size: '.(float) $dotSize.'px';
@endphp

<div {{ $attributes->merge(['style' => $vars])->class([$base]) }}>
    <div aria-hidden="true" @class([$layer, $colors[$color] ?? $colors['muted'], $masks[$mask] ?? ''])></div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.dot-pattern mask="radial" class="rounded-xl border border-line bg-surface px-6 py-12">
    <h2 class="text-2xl font-semibold text-ink">Bangun antarmuka yang terasa akrab</h2>
    <x-markas.button>Mulai sekarang</x-markas.button>
</x-markas.dot-pattern>
```

Tidak butuh JavaScript atau Alpine.js.

### React

Simpan di `src/components/markas/DotPattern.tsx`. Tanpa dependensi tambahan.

```tsx
import type { ComponentProps, CSSProperties } from "react";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type DotPatternProps = ComponentProps<"div"> & {
  spacing?: number;
  dotSize?: number;
  color?: keyof typeof colors;
  mask?: keyof typeof masks;
};

export function DotPattern({
  spacing = 16,
  dotSize = 1,
  color = "muted",
  mask = "none",
  className,
  style,
  children,
  ...props
}: DotPatternProps) {
  const vars = {
    "--markas-dot-spacing": `${spacing}px`,
    "--markas-dot-size": `${dotSize}px`,
  } as CSSProperties;

  return (
    <div
      {...props}
      className={cx(base, className)}
      style={{ ...vars, ...style }}
    >
      <div
        aria-hidden="true"
        className={cx(layer, colors[color], masks[mask])}
      />
      <div className={content}>{children}</div>
    </div>
  );
}
```

```tsx
import { Button } from "@/components/markas/Button";
import { DotPattern } from "@/components/markas/DotPattern";

<DotPattern
  mask="radial"
  className="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 className="text-2xl font-semibold text-ink">
    Bangun antarmuka yang terasa akrab
  </h2>
  <Button>Mulai sekarang</Button>
</DotPattern>;
```

### Vue

Simpan di `src/components/markas/DotPattern.vue`. Tanpa dependensi tambahan.

```vue
<script setup lang="ts">
import { computed } from "vue";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

const props = withDefaults(
  defineProps<{
    spacing?: number;
    dotSize?: number;
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
  }>(),
  { spacing: 16, dotSize: 1, color: "muted", mask: "none" },
);

const vars = computed(() => ({
  "--markas-dot-spacing": `${props.spacing}px`,
  "--markas-dot-size": `${props.dotSize}px`,
}));
</script>

<template>
  <div :class="base" :style="vars">
    <div
      aria-hidden="true"
      :class="[layer, colors[props.color], masks[props.mask]]"
    />
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <DotPattern
    mask="radial"
    class="rounded-xl border border-line bg-surface px-6 py-12"
  >
    <h2 class="text-2xl font-semibold text-ink">
      Bangun antarmuka yang terasa akrab
    </h2>
    <Button>Mulai sekarang</Button>
  </DotPattern>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/DotPattern.svelte`. Tanpa dependensi tambahan.

```svelte
<script lang="ts">
  import type { Snippet } from "svelte";
  import type { HTMLAttributes } from "svelte/elements";

  const base = "relative isolate overflow-hidden";
  const layer =
    "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
  const content = "relative";
  const colors = {
    muted: "text-muted/50",
    primary: "text-primary/40",
    success: "text-success/50",
    warning: "text-warning/50",
    danger: "text-danger/50",
  };
  const masks = {
    none: "",
    radial:
      "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
    linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
  };

  type Props = HTMLAttributes<HTMLDivElement> & {
    spacing?: number;
    dotSize?: number;
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
    children?: Snippet;
  };

  let {
    spacing = 16,
    dotSize = 1,
    color = "muted",
    mask = "none",
    class: className,
    style,
    children,
    ...rest
  }: Props = $props();
</script>

<div
  {...rest}
  class={[base, className]}
  style="--markas-dot-spacing:{spacing}px;--markas-dot-size:{dotSize}px;{style ??
    ''}"
>
  <div aria-hidden="true" class={[layer, colors[color], masks[mask]]}></div>
  <div class={content}>{@render children?.()}</div>
</div>
```

```svelte
<script lang="ts">
  import Button from "$lib/components/markas/Button.svelte";
  import DotPattern from "$lib/components/markas/DotPattern.svelte";
</script>

<DotPattern
  mask="radial"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Bangun antarmuka yang terasa akrab
  </h2>
  <Button>Mulai sekarang</Button>
</DotPattern>
```

### Astro

Simpan di `src/components/markas/DotPattern.astro`. Tanpa dependensi tambahan.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

type Props = Omit<HTMLAttributes<"div">, "style"> & {
  spacing?: number;
  dotSize?: number;
  color?: keyof typeof colors;
  mask?: keyof typeof masks;
  style?: string;
};

const {
  spacing = 16,
  dotSize = 1,
  color = "muted",
  mask = "none",
  class: className,
  style,
  ...rest
} = Astro.props;
---

<div
  {...rest}
  class:list={[base, className]}
  style={`--markas-dot-spacing:${spacing}px;--markas-dot-size:${dotSize}px;${style ?? ""}`}
>
  <div aria-hidden="true" class:list={[layer, colors[color], masks[mask]]}></div>
  <div class={content}><slot /></div>
</div>
```

```astro
---
import Button from "@/components/markas/Button.astro";
import DotPattern from "@/components/markas/DotPattern.astro";
---

<DotPattern
  mask="radial"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Bangun antarmuka yang terasa akrab
  </h2>
  <Button>Mulai sekarang</Button>
</DotPattern>
```

Tanpa JavaScript di browser; markup dirender di server.

### Angular

Simpan di `src/app/markas/dot-pattern.component.ts`. Tanpa dependensi tambahan.

```ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
  numberAttribute,
} from "@angular/core";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

export type DotPatternColor = keyof typeof colors;
export type DotPatternMask = keyof typeof masks;

/** Attribute selector on a native div: the user's class, style, and attributes stay on the root. */
@Component({
  selector: "div[markas-dot-pattern]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    "[class]": "base",
    "[style.--markas-dot-spacing]": "spacing() + 'px'",
    "[style.--markas-dot-size]": "dotSize() + 'px'",
  },
  template: `
    <div aria-hidden="true" [class]="layerClasses()"></div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class DotPattern {
  readonly spacing = input(16, { transform: numberAttribute });
  readonly dotSize = input(1, { transform: numberAttribute });
  readonly color = input<DotPatternColor>("muted");
  readonly mask = input<DotPatternMask>("none");

  protected readonly base = base;
  protected readonly content = content;
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]} ${masks[this.mask()]}`,
  );
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { DotPattern } from "./markas/dot-pattern.component";

@Component({
  selector: "app-hero",
  imports: [Button, DotPattern],
  template: `
    <div
      markas-dot-pattern
      mask="radial"
      class="rounded-xl border border-line bg-surface px-6 py-12"
    >
      <h2 class="text-2xl font-semibold text-ink">
        Bangun antarmuka yang terasa akrab
      </h2>
      <button markas-button>Mulai sekarang</button>
    </div>
  `,
})
export class Hero {}
```

Komponen ini berupa atribut pada div, jadi class, style, dan atribut lain tetap di elemen akar.

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `spacing` | `number` | 16 | Jarak antartitik dalam piksel. Nilai lebih kecil membuat pola lebih rapat. |
| `dotSize` | `number` | 1 | Jari-jari titik dalam piksel. |
| `color` | `muted \| primary \| success \| warning \| danger` | muted | Warna token titik, sudah dilembutkan dengan opacity. |
| `mask` | `none \| radial \| linear` | none | Pudarkan titik ke arah tepi (radial) atau ke bawah (linear). |
| `children / slot` | `slot / ReactNode / snippet` | - | Konten yang tampil di atas pola. |

## Aksesibilitas

- Lapisan pola memakai aria-hidden dan mengabaikan pointer, jadi hanya konten yang dibacakan dan bisa diklik.
- Perhatikan kontras teks: pasang pola di bg-surface atau bg-canvas dan pakai mask di belakang teks panjang.

## Catatan

- `spacing` dan `dotSize` dalam piksel. Pakai `color` untuk warna token dan `mask` untuk memudarkan tepi.
- Murni CSS: tanpa JavaScript dan tanpa animasi, jadi tidak membebani runtime.
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
