# Retro Grid

Lantai grid perspektif 3D yang bergerak ke arah penonton, untuk hero dan section peluncuran yang berani.

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

## Kapan dipakai

Latar yang ceria dan energik untuk hero peluncuran, halaman 404, atau CTA acara.

- Atur warna latar, padding, dan radius lewat class pada komponen
- Beri tinggi yang cukup (minimal 240px) supaya perspektif terbaca
- Buat judul singkat; grid muncul di belakang bagian tengah area

## Kode

### Blade

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

```blade
@props([
    'cellSize' => 60,
    'angle' => 65,
    'color' => 'muted',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]';
    $plane = 'absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]';
    $grid = 'absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted/40',
        'primary' => 'text-primary/30',
        'success' => 'text-success/50',
        'warning' => 'text-warning/50',
        'danger' => 'text-danger/50',
    ];
    $keyframes = '@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}';

    $vars = '--markas-retro-cell: '.(float) $cellSize.'px; --markas-retro-angle: '.(float) $angle.'deg';
@endphp

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

```blade
<x-markas.retro-grid :cell-size="48" color="primary" class="rounded-xl border border-line bg-surface px-6 py-12">
    <h2 class="text-2xl font-semibold text-ink">Rilis masa depan</h2>
    <x-markas.button>Mulai sekarang</x-markas.button>
</x-markas.retro-grid>
```

Tidak butuh JavaScript atau Alpine.js.

### React

Simpan di `src/components/markas/RetroGrid.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 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]";
const plane = "absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]";
const grid =
  "absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/40",
  primary: "text-primary/30",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const keyframes =
  "@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}";
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type RetroGridProps = ComponentProps<"div"> & {
  cellSize?: number;
  angle?: number;
  color?: keyof typeof colors;
};

export function RetroGrid({
  cellSize = 60,
  angle = 65,
  color = "muted",
  className,
  style,
  children,
  ...props
}: RetroGridProps) {
  const vars = {
    "--markas-retro-cell": `${cellSize}px`,
    "--markas-retro-angle": `${angle}deg`,
  } as CSSProperties;

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

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

<RetroGrid
  cellSize={48}
  color="primary"
  className="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 className="text-2xl font-semibold text-ink">Rilis masa depan</h2>
  <Button>Mulai sekarang</Button>
</RetroGrid>;
```

### Vue

Simpan di `src/components/markas/RetroGrid.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 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]";
const plane = "absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]";
const grid =
  "absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/40",
  primary: "text-primary/30",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const keyframes =
  "@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}";

const props = withDefaults(
  defineProps<{
    cellSize?: number;
    angle?: number;
    color?: keyof typeof colors;
  }>(),
  { cellSize: 60, angle: 65, color: "muted" },
);

const vars = computed(() => ({
  "--markas-retro-cell": `${props.cellSize}px`,
  "--markas-retro-angle": `${props.angle}deg`,
}));
</script>

<template>
  <div :class="base" :style="vars">
    <component :is="'style'">{{ keyframes }}</component>
    <div aria-hidden="true" :class="[layer, colors[props.color]]">
      <div :class="plane">
        <div :class="grid" />
      </div>
    </div>
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <RetroGrid
    :cell-size="48"
    color="primary"
    class="rounded-xl border border-line bg-surface px-6 py-12"
  >
    <h2 class="text-2xl font-semibold text-ink">Rilis masa depan</h2>
    <Button>Mulai sekarang</Button>
  </RetroGrid>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/RetroGrid.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 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]";
  const plane =
    "absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]";
  const grid =
    "absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none";
  const content = "relative";
  const colors = {
    muted: "text-muted/40",
    primary: "text-primary/30",
    success: "text-success/50",
    warning: "text-warning/50",
    danger: "text-danger/50",
  };
  const keyframes =
    "@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}";

  type Props = HTMLAttributes<HTMLDivElement> & {
    cellSize?: number;
    angle?: number;
    color?: keyof typeof colors;
    children?: Snippet;
  };

  let {
    cellSize = 60,
    angle = 65,
    color = "muted",
    class: className,
    style,
    children,
    ...rest
  }: Props = $props();

  const vars = $derived(
    `--markas-retro-cell: ${cellSize}px; --markas-retro-angle: ${angle}deg${style ? `; ${style}` : ""}`,
  );
</script>

<div {...rest} class={[base, className]} style={vars}>
  {@html `<style>${keyframes}</style>`}
  <div aria-hidden="true" class={[layer, colors[color]]}>
    <div class={plane}>
      <div class={grid}></div>
    </div>
  </div>
  <div class={content}>{@render children?.()}</div>
</div>
```

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

<RetroGrid
  cellSize={48}
  color="primary"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">Ship the future</h2>
  <Button>Get started</Button>
</RetroGrid>
```

### Astro

Simpan di `src/components/markas/RetroGrid.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 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]";
const plane = "absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]";
const grid =
  "absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/40",
  primary: "text-primary/30",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const keyframes =
  "@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}";

type Props = HTMLAttributes<"div"> & {
  cellSize?: number;
  angle?: number;
  color?: keyof typeof colors;
};

const {
  cellSize = 60,
  angle = 65,
  color = "muted",
  class: className,
  style,
  ...rest
} = Astro.props;
const vars = `--markas-retro-cell: ${cellSize}px; --markas-retro-angle: ${angle}deg`;
const userStyle = typeof style === "string" ? style : "";
---

<div
  {...rest}
  class:list={[base, className]}
  style={userStyle ? `${vars}; ${userStyle}` : vars}
>
  <style is:inline set:html={keyframes} />
  <div aria-hidden="true" class:list={[layer, colors[color]]}>
    <div class={plane}>
      <div class={grid}></div>
    </div>
  </div>
  <div class={content}><slot /></div>
</div>
```

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

<RetroGrid
  cellSize={48}
  color="primary"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">Ship the future</h2>
  <Button>Get started</Button>
</RetroGrid>
```

### Angular

Simpan di `src/app/markas/retro-grid.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 overflow-hidden [perspective:200px] [mask-image:linear-gradient(to_bottom,transparent_15%,black_60%)]";
const plane = "absolute inset-0 [transform:rotateX(var(--markas-retro-angle))]";
const grid =
  "absolute -top-full -left-[150%] h-[400%] w-[400%] animate-[markas-retro-grid_1s_linear_infinite] bg-[linear-gradient(to_right,currentColor_1px,transparent_0),linear-gradient(to_bottom,currentColor_1px,transparent_0)] [background-size:var(--markas-retro-cell)_var(--markas-retro-cell)] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted/40",
  primary: "text-primary/30",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const keyframes =
  "@keyframes markas-retro-grid{from{transform:translateY(calc(var(--markas-retro-cell)*-1))}to{transform:translateY(0)}}";

export type RetroGridColor = keyof typeof colors;

/**
 * Attribute selector on the native root div: the user's class, style, and attributes stay
 * on it. The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-retro-grid]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: {
    "[class]": "base",
    "[style.--markas-retro-cell]": "cellSize() + 'px'",
    "[style.--markas-retro-angle]": "angle() + 'deg'",
  },
  template: `
    <div aria-hidden="true" [class]="layerClasses()">
      <div [class]="plane"><div [class]="grid"></div></div>
    </div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class RetroGrid {
  readonly cellSize = input(60, { transform: numberAttribute });
  readonly angle = input(65, { transform: numberAttribute });
  readonly color = input<RetroGridColor>("muted");

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

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

@Component({
  selector: "app-beta",
  imports: [Button, RetroGrid],
  template: `
    <div
      markas-retro-grid
      cellSize="48"
      color="primary"
      class="rounded-xl border border-line bg-surface px-6 py-12"
    >
      <h2 class="text-2xl font-semibold text-ink">Ship the future</h2>
      <button markas-button>Get started</button>
    </div>
  `,
})
export class Beta {}
```

Angular memakai attribute selector pada div native, jadi `class`, `aria-*`, dan atribut lain tetap di elemen akar.

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `cellSize` | `number` | 60 | Ukuran satu sel grid dalam piksel sebelum perspektif. Grid bergerak satu sel per detik. |
| `angle` | `number` | 65 | Kemiringan lantai grid dalam derajat. Nilai lebih besar terlihat lebih datar. |
| `color` | `muted \| primary \| success \| warning \| danger` | muted | Warna token garis grid, sudah dilembutkan dengan opacity. |
| `children / slot` | `slot / ReactNode` | - | Konten yang tampil di atas grid. |

## Aksesibilitas

- Lapisan grid memakai aria-hidden dan mengabaikan pointer.
- Dengan reduced motion, grid berhenti bergerak.

## Catatan

- Beri komponen tinggi yang cukup (minimal 240px) supaya perspektif punya ruang.
- Grid bergerak satu sel per detik ke arah penonton. Dengan reduced motion grid berhenti.
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
