# Grid Pattern

Garis grid tipis di belakang konten, dengan sel sorotan yang berdenyut lembut dan pudar opsional.

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

## Kapan dipakai

Tekstur teknis mirip cetak biru di belakang hero, section fitur, atau kartu pendaftaran.

- Atur warna latar, padding, dan radius lewat class pada komponen
- Sorot sedikit sel saja (2 sampai 6) supaya pola tetap tenang
- Pilih cellSize supaya sel sorotan tidak berada di bawah judul utama

## Kode

### Blade

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

```blade
@props([
    'cellSize' => 32,
    'cells' => [],
    'color' => 'muted',
    'mask' => 'none',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 bg-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]';
    $cell = 'absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted/20',
        'primary' => 'text-primary/15',
        'success' => 'text-success/30',
        'warning' => 'text-warning/30',
        'danger' => 'text-danger/30',
    ];
    $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%)]',
    ];
    $keyframes = '@keyframes markas-grid-cell{50%{opacity:.4}}';
    $cellDelayMs = 800;

    $size = (float) $cellSize;
    $vars = '--markas-grid-size: '.$size.'px';
@endphp

<div {{ $attributes->merge(['style' => $vars])->class([$base]) }}>
    <style>{!! $keyframes !!}</style>
    <div aria-hidden="true" @class([$layer, $colors[$color] ?? $colors['muted'], $masks[$mask] ?? ''])>
        @foreach (array_values($cells) as $index => [$col, $row])
            {{-- Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). --}}
            <span class="{{ $cell }}" style="left: {{ $col * $size + 1 }}px; top: {{ $row * $size + 1 }}px; width: {{ $size - 1 }}px; height: {{ $size - 1 }}px; animation-delay: {{ $index * $cellDelayMs }}ms"></span>
        @endforeach
    </div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.grid-pattern :cells="[[2, 1], [10, 3]]" class="rounded-xl border border-line bg-surface px-6 py-12">
    <h2 class="text-2xl font-semibold text-ink">Rencanakan, bangun, dan rilis di satu tempat</h2>
    <x-markas.button>Mulai sekarang</x-markas.button>
</x-markas.grid-pattern>
```

Tidak butuh JavaScript atau Alpine.js.

### React

Simpan di `src/components/markas/GridPattern.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-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]";
const cell =
  "absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/20",
  primary: "text-primary/15",
  success: "text-success/30",
  warning: "text-warning/30",
  danger: "text-danger/30",
};
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 keyframes = "@keyframes markas-grid-cell{50%{opacity:.4}}";
const CELL_DELAY_MS = 800;
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

/** Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). */
const cellStyle = (
  [col, row]: [number, number],
  size: number,
  index: number,
) => ({
  left: `${col * size + 1}px`,
  top: `${row * size + 1}px`,
  width: `${size - 1}px`,
  height: `${size - 1}px`,
  animationDelay: `${index * CELL_DELAY_MS}ms`,
});

export type GridPatternProps = ComponentProps<"div"> & {
  cellSize?: number;
  cells?: [number, number][];
  color?: keyof typeof colors;
  mask?: keyof typeof masks;
};

export function GridPattern({
  cellSize = 32,
  cells = [],
  color = "muted",
  mask = "none",
  className,
  style,
  children,
  ...props
}: GridPatternProps) {
  const vars = { "--markas-grid-size": `${cellSize}px` } as CSSProperties;

  return (
    <div
      {...props}
      className={cx(base, className)}
      style={{ ...vars, ...style }}
    >
      <style>{keyframes}</style>
      <div aria-hidden="true" className={cx(layer, colors[color], masks[mask])}>
        {cells.map((position, index) => (
          <span
            key={position.join("-")}
            className={cell}
            style={cellStyle(position, cellSize, index)}
          />
        ))}
      </div>
      <div className={content}>{children}</div>
    </div>
  );
}
```

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

<GridPattern
  cells={[
    [2, 1],
    [10, 3],
  ]}
  className="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 className="text-2xl font-semibold text-ink">
    Rencanakan, bangun, dan rilis di satu tempat
  </h2>
  <Button>Mulai sekarang</Button>
</GridPattern>;
```

### Vue

Simpan di `src/components/markas/GridPattern.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-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]";
const cell =
  "absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/20",
  primary: "text-primary/15",
  success: "text-success/30",
  warning: "text-warning/30",
  danger: "text-danger/30",
};
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 keyframes = "@keyframes markas-grid-cell{50%{opacity:.4}}";
const CELL_DELAY_MS = 800;

/** Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). */
const cellStyle = (
  [col, row]: [number, number],
  size: number,
  index: number,
) => ({
  left: `${col * size + 1}px`,
  top: `${row * size + 1}px`,
  width: `${size - 1}px`,
  height: `${size - 1}px`,
  animationDelay: `${index * CELL_DELAY_MS}ms`,
});

const props = withDefaults(
  defineProps<{
    cellSize?: number;
    cells?: [number, number][];
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
  }>(),
  { cellSize: 32, cells: () => [], color: "muted", mask: "none" },
);

const vars = computed(() => ({ "--markas-grid-size": `${props.cellSize}px` }));
</script>

<template>
  <div :class="base" :style="vars">
    <component :is="'style'">{{ keyframes }}</component>
    <div
      aria-hidden="true"
      :class="[layer, colors[props.color], masks[props.mask]]"
    >
      <span
        v-for="(position, index) in props.cells"
        :key="position.join('-')"
        :class="cell"
        :style="cellStyle(position, props.cellSize, index)"
      />
    </div>
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <GridPattern
    :cells="[
      [2, 1],
      [10, 3],
    ]"
    class="rounded-xl border border-line bg-surface px-6 py-12"
  >
    <h2 class="text-2xl font-semibold text-ink">
      Rencanakan, bangun, dan rilis di satu tempat
    </h2>
    <Button>Mulai sekarang</Button>
  </GridPattern>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/GridPattern.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-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]";
  const cell =
    "absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none";
  const content = "relative";
  const colors = {
    muted: "text-muted/20",
    primary: "text-primary/15",
    success: "text-success/30",
    warning: "text-warning/30",
    danger: "text-danger/30",
  };
  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 keyframes = "@keyframes markas-grid-cell{50%{opacity:.4}}";
  const CELL_DELAY_MS = 800;

  /** Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). */
  const cellStyle = (
    [col, row]: [number, number],
    size: number,
    index: number,
  ) =>
    `left:${col * size + 1}px;top:${row * size + 1}px;width:${size - 1}px;height:${size - 1}px;animation-delay:${index * CELL_DELAY_MS}ms`;

  type Props = HTMLAttributes<HTMLDivElement> & {
    cellSize?: number;
    cells?: [number, number][];
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
    children?: Snippet;
  };

  let {
    cellSize = 32,
    cells = [],
    color = "muted",
    mask = "none",
    class: className,
    style,
    children,
    ...rest
  }: Props = $props();
</script>

<div
  {...rest}
  class={[base, className]}
  style="--markas-grid-size:{cellSize}px;{style ?? ''}"
>
  {@html `<style>${keyframes}</style>`}
  <div aria-hidden="true" class={[layer, colors[color], masks[mask]]}>
    {#each cells as position, index (position.join("-"))}
      <span class={cell} style={cellStyle(position, cellSize, index)}></span>
    {/each}
  </div>
  <div class={content}>{@render children?.()}</div>
</div>
```

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

<GridPattern
  cells={[
    [2, 1],
    [10, 3],
  ]}
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Rencanakan, bangun, dan rilis di satu tempat
  </h2>
  <Button>Mulai sekarang</Button>
</GridPattern>
```

### Astro

Simpan di `src/components/markas/GridPattern.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-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]";
const cell =
  "absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/20",
  primary: "text-primary/15",
  success: "text-success/30",
  warning: "text-warning/30",
  danger: "text-danger/30",
};
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 keyframes = "@keyframes markas-grid-cell{50%{opacity:.4}}";
const CELL_DELAY_MS = 800;

/** Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). */
const cellStyle = ([col, row]: [number, number], size: number, index: number) =>
  `left:${col * size + 1}px;top:${row * size + 1}px;width:${size - 1}px;height:${size - 1}px;animation-delay:${index * CELL_DELAY_MS}ms`;

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

const {
  cellSize = 32,
  cells = [],
  color = "muted",
  mask = "none",
  class: className,
  style,
  ...rest
} = Astro.props;
---

<div
  {...rest}
  class:list={[base, className]}
  style={`--markas-grid-size:${cellSize}px;${style ?? ""}`}
>
  <style is:inline set:html={keyframes} />
  <div aria-hidden="true" class:list={[layer, colors[color], masks[mask]]}>
    {
      cells.map((position, index) => (
        <span class={cell} style={cellStyle(position, cellSize, index)} />
      ))
    }
  </div>
  <div class={content}><slot /></div>
</div>
```

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

<GridPattern
  cells={[
    [2, 1],
    [10, 3],
  ]}
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Rencanakan, bangun, dan rilis di satu tempat
  </h2>
  <Button>Mulai sekarang</Button>
</GridPattern>
```

Tanpa JavaScript di browser; markup dirender di server.

### Angular

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

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

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)] [background-size:var(--markas-grid-size)_var(--markas-grid-size)]";
const cell =
  "absolute bg-current animate-[markas-grid-cell_4s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/20",
  primary: "text-primary/15",
  success: "text-success/30",
  warning: "text-warning/30",
  danger: "text-danger/30",
};
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 keyframes = "@keyframes markas-grid-cell{50%{opacity:.4}}";
const CELL_DELAY_MS = 800;

export type GridPatternColor = keyof typeof colors;
export type GridPatternMask = keyof typeof masks;

/** Posisi satu sel sorotan di dalam garis grid (kolom, baris mulai dari 0). */
const cellStyle = ([col, row]: [number, number], size: number, index: number) =>
  `left:${col * size + 1}px;top:${row * size + 1}px;width:${size - 1}px;height:${size - 1}px;animation-delay:${index * CELL_DELAY_MS}ms`;

/**
 * Attribute selector on a native div: the user's class, style, and attributes stay on the
 * root. The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-grid-pattern]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: {
    "[class]": "base",
    "[style.--markas-grid-size]": "cellSize() + 'px'",
  },
  template: `
    <div aria-hidden="true" [class]="layerClasses()">
      @for (item of highlights(); track item.key) {
        <span [class]="cell" [style]="item.style"></span>
      }
    </div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class GridPattern {
  readonly cellSize = input(32, { transform: numberAttribute });
  /** Highlighted cells as [column, row], counted from 0. */
  readonly cells = input<[number, number][]>([]);
  readonly color = input<GridPatternColor>("muted");
  readonly mask = input<GridPatternMask>("none");

  protected readonly base = base;
  protected readonly cell = cell;
  protected readonly content = content;
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]} ${masks[this.mask()]}`,
  );
  protected readonly highlights = computed(() =>
    this.cells().map((position, index) => ({
      key: position.join("-"),
      style: cellStyle(position, this.cellSize(), index),
    })),
  );
}
```

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

@Component({
  selector: "app-hero",
  imports: [Button, GridPattern],
  template: `
    <div
      markas-grid-pattern
      [cells]="cells"
      class="rounded-xl border border-line bg-surface px-6 py-12"
    >
      <h2 class="text-2xl font-semibold text-ink">
        Rencanakan, bangun, dan rilis di satu tempat
      </h2>
      <button markas-button>Mulai sekarang</button>
    </div>
  `,
})
export class Hero {
  readonly cells: [number, number][] = [
    [2, 1],
    [10, 3],
  ];
}
```

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

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `cellSize` | `number` | 32 | Lebar dan tinggi satu sel grid dalam piksel. |
| `cells` | `[column, row][]` | [] | Sel yang disorot, dihitung dari kiri atas mulai 0. Sel sorotan berdenyut bergantian. |
| `color` | `muted \| primary \| success \| warning \| danger` | muted | Warna token garis dan sel sorotan, sudah dilembutkan dengan opacity. |
| `mask` | `none \| radial \| linear` | none | Pudarkan grid ke arah tepi (radial) atau ke bawah (linear). |
| `children / slot` | `slot / ReactNode / snippet` | - | Konten yang tampil di atas grid. |

## Aksesibilitas

- Lapisan grid memakai aria-hidden dan mengabaikan pointer.
- Dengan reduced motion, sel sorotan diam dengan kekuatan penuh.

## Catatan

- `cells` menerima pasangan `[kolom, baris]` dari kiri atas, mulai 0.
- Sel sorotan berdenyut bergantian. Dengan reduced motion sel diam.
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
