# Ripple Background

Lingkaran konsentris yang berdenyut dari tengah, cocok di belakang logo, avatar, atau ikon status.

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

## Kapan dipakai

Titik fokus di tengah: menghubungkan perangkat, panggilan aktif, hub integrasi, atau keadaan menunggu.

- Atur warna latar, padding, dan radius lewat class pada komponen
- Letakkan konten di tengah supaya berada di pusat lingkaran
- Sesuaikan size dengan elemen tengah, sedikit lebih besar dari ikon atau avatar

## Kode

### Blade

Simpan di `resources/views/components/markas/ripple-background.blade.php`. Tanpa dependensi tambahan.

```blade
@props([
    'rings' => 6,
    'size' => 120,
    'gap' => 64,
    'color' => 'muted',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]';
    $ring = 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted',
        'primary' => 'text-primary',
        'success' => 'text-success',
        'warning' => 'text-warning',
        'danger' => 'text-danger',
    ];
    $keyframes = '@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}';
    $ringDelayMs = 120;
    $maxRings = 12;

    // Lingkaran ke-i: makin luar makin besar dan makin pudar, dengan jeda supaya denyut merambat dari tengah.
    $ringStyles = [];
    $total = max(0, min((int) $rings, $maxRings));
    for ($i = 0; $i < $total; $i++) {
        $diameter = (float) $size + $i * (float) $gap;
        $ringStyles[] = 'width: '.$diameter.'px; height: '.$diameter.'px; opacity: '.(max(1, 6 - $i) / 10).'; animation-delay: '.($i * $ringDelayMs).'ms';
    }
@endphp

<div {{ $attributes->class([$base]) }}>
    <style>{!! $keyframes !!}</style>
    <div aria-hidden="true" @class([$layer, $colors[$color] ?? $colors['muted']])>
        @foreach ($ringStyles as $style)
            <span class="{{ $ring }}" style="{{ $style }}"></span>
        @endforeach
    </div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.ripple-background :size="88" :gap="56" class="grid h-48 place-items-center rounded-xl bg-canvas">
    <span class="grid size-14 place-items-center rounded-full border border-line bg-surface">MC</span>
</x-markas.ripple-background>
```

Tidak butuh JavaScript atau Alpine.js.

### React

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

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

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]";
const ring =
  "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes =
  "@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}";
const RING_DELAY_MS = 120;
const MAX_RINGS = 12;
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

/** Lingkaran ke-i: makin luar makin besar dan makin pudar, dengan jeda supaya denyut merambat dari tengah. */
function makeRings(rings: number, size: number, gap: number) {
  const total = Math.max(0, Math.min(Math.trunc(rings), MAX_RINGS));
  return Array.from({ length: total }, (_, index) => ({
    width: `${size + index * gap}px`,
    height: `${size + index * gap}px`,
    opacity: Math.max(1, 6 - index) / 10,
    animationDelay: `${index * RING_DELAY_MS}ms`,
  }));
}

export type RippleBackgroundProps = ComponentProps<"div"> & {
  rings?: number;
  size?: number;
  gap?: number;
  color?: keyof typeof colors;
};

export function RippleBackground({
  rings = 6,
  size = 120,
  gap = 64,
  color = "muted",
  className,
  children,
  ...props
}: RippleBackgroundProps) {
  return (
    <div {...props} className={cx(base, className)}>
      <style>{keyframes}</style>
      <div aria-hidden="true" className={cx(layer, colors[color])}>
        {makeRings(rings, size, gap).map((style, index) => (
          <span key={index} className={ring} style={style} />
        ))}
      </div>
      <div className={content}>{children}</div>
    </div>
  );
}
```

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

<RippleBackground
  size={88}
  gap={56}
  className="grid h-48 place-items-center rounded-xl bg-canvas"
>
  <span className="grid size-14 place-items-center rounded-full border border-line bg-surface">
    MC
  </span>
</RippleBackground>;
```

### Vue

Simpan di `src/components/markas/RippleBackground.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 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]";
const ring =
  "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes =
  "@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}";
const RING_DELAY_MS = 120;
const MAX_RINGS = 12;

/** Lingkaran ke-i: makin luar makin besar dan makin pudar, dengan jeda supaya denyut merambat dari tengah. */
function makeRings(rings: number, size: number, gap: number) {
  const total = Math.max(0, Math.min(Math.trunc(rings), MAX_RINGS));
  return Array.from({ length: total }, (_, index) => ({
    width: `${size + index * gap}px`,
    height: `${size + index * gap}px`,
    opacity: Math.max(1, 6 - index) / 10,
    animationDelay: `${index * RING_DELAY_MS}ms`,
  }));
}

const props = withDefaults(
  defineProps<{
    rings?: number;
    size?: number;
    gap?: number;
    color?: keyof typeof colors;
  }>(),
  { rings: 6, size: 120, gap: 64, color: "muted" },
);

const ringStyles = computed(() =>
  makeRings(props.rings, props.size, props.gap),
);
</script>

<template>
  <div :class="base">
    <component :is="'style'">{{ keyframes }}</component>
    <div aria-hidden="true" :class="[layer, colors[props.color]]">
      <span
        v-for="(style, index) in ringStyles"
        :key="index"
        :class="ring"
        :style="style"
      />
    </div>
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <RippleBackground
    :size="88"
    :gap="56"
    class="grid h-48 place-items-center rounded-xl bg-canvas"
  >
    <span
      class="grid size-14 place-items-center rounded-full border border-line bg-surface"
      >MC</span
    >
  </RippleBackground>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/RippleBackground.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 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]";
  const ring =
    "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none";
  const content = "relative";
  const colors = {
    muted: "text-muted",
    primary: "text-primary",
    success: "text-success",
    warning: "text-warning",
    danger: "text-danger",
  };
  const keyframes =
    "@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}";
  const RING_DELAY_MS = 120;
  const MAX_RINGS = 12;

  /** Ring i: the further out, the larger and fainter, with a delay so the pulse travels from the center. */
  function makeRings(rings: number, size: number, gap: number) {
    const total = Math.max(0, Math.min(Math.trunc(rings), MAX_RINGS));
    return Array.from({ length: total }, (_, index) => {
      const diameter = size + index * gap;
      const opacity = Math.max(1, 6 - index) / 10;
      return `width: ${diameter}px; height: ${diameter}px; opacity: ${opacity}; animation-delay: ${index * RING_DELAY_MS}ms`;
    });
  }

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

  let {
    rings = 6,
    size = 120,
    gap = 64,
    color = "muted",
    class: className,
    children,
    ...rest
  }: Props = $props();

  const items = $derived(makeRings(rings, size, gap));
</script>

<div {...rest} class={[base, className]}>
  {@html `<style>${keyframes}</style>`}
  <div aria-hidden="true" class={[layer, colors[color]]}>
    {#each items as style, index (index)}
      <span class={ring} {style}></span>
    {/each}
  </div>
  <div class={content}>{@render children?.()}</div>
</div>
```

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

<RippleBackground
  size={88}
  gap={56}
  class="grid h-48 place-items-center rounded-xl bg-canvas"
>
  <span
    class="grid size-14 place-items-center rounded-full border border-line bg-surface"
  >
    MC
  </span>
</RippleBackground>
```

### Astro

Simpan di `src/components/markas/RippleBackground.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 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]";
const ring =
  "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes =
  "@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}";
const RING_DELAY_MS = 120;
const MAX_RINGS = 12;

/** Ring i: the further out, the larger and fainter, with a delay so the pulse travels from the center. */
function makeRings(rings: number, size: number, gap: number) {
  const total = Math.max(0, Math.min(Math.trunc(rings), MAX_RINGS));
  return Array.from({ length: total }, (_, index) => ({
    width: `${size + index * gap}px`,
    height: `${size + index * gap}px`,
    opacity: Math.max(1, 6 - index) / 10,
    animationDelay: `${index * RING_DELAY_MS}ms`,
  }));
}

type Props = HTMLAttributes<"div"> & {
  rings?: number;
  size?: number;
  gap?: number;
  color?: keyof typeof colors;
};

const {
  rings = 6,
  size = 120,
  gap = 64,
  color = "muted",
  class: className,
  ...rest
} = Astro.props;
---

<div {...rest} class:list={[base, className]}>
  <style is:inline set:html={keyframes} />
  <div aria-hidden="true" class:list={[layer, colors[color]]}>
    {makeRings(rings, size, gap).map((style) => <span class={ring} style={style} />)}
  </div>
  <div class={content}><slot /></div>
</div>
```

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

<RippleBackground
  size={88}
  gap={56}
  class="grid h-48 place-items-center rounded-xl bg-canvas"
>
  <span class="grid size-14 place-items-center rounded-full border border-line bg-surface">
    MC
  </span>
</RippleBackground>
```

### Angular

Simpan di `src/app/markas/ripple-background.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 [mask-image:radial-gradient(circle_at_center,black_30%,transparent_80%)]";
const ring =
  "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 animate-[markas-ripple_3.4s_ease-in-out_infinite] rounded-full border border-current bg-current/5 motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes =
  "@keyframes markas-ripple{0%,100%{transform:scale(1)}50%{transform:scale(.92)}}";
const RING_DELAY_MS = 120;
const MAX_RINGS = 12;

export type RippleBackgroundColor = keyof typeof colors;

/** Ring i: the further out, the larger and fainter, with a delay so the pulse travels from the center. */
function makeRings(rings: number, size: number, gap: number) {
  const total = Math.max(0, Math.min(Math.trunc(rings), MAX_RINGS));
  return Array.from({ length: total }, (_, index) => {
    const diameter = size + index * gap;
    const opacity = Math.max(1, 6 - index) / 10;
    return `width: ${diameter}px; height: ${diameter}px; opacity: ${opacity}; animation-delay: ${index * RING_DELAY_MS}ms`;
  });
}

/**
 * Attribute selector on the native root div: the user's class and attributes stay on it.
 * The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-ripple-background]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: { "[class]": "base" },
  template: `
    <div aria-hidden="true" [class]="layerClasses()">
      @for (style of items(); track $index) {
        <span [class]="ring" [style]="style"></span>
      }
    </div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class RippleBackground {
  readonly rings = input(6, { transform: numberAttribute });
  readonly size = input(120, { transform: numberAttribute });
  readonly gap = input(64, { transform: numberAttribute });
  readonly color = input<RippleBackgroundColor>("muted");

  protected readonly base = base;
  protected readonly ring = ring;
  protected readonly content = content;
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]}`,
  );
  protected readonly items = computed(() =>
    makeRings(this.rings(), this.size(), this.gap()),
  );
}
```

```ts
import { Component } from "@angular/core";
import { RippleBackground } from "./markas/ripple-background.component";

@Component({
  selector: "app-call",
  imports: [RippleBackground],
  template: `
    <div
      markas-ripple-background
      size="88"
      gap="56"
      class="grid h-48 place-items-center rounded-xl bg-canvas"
    >
      <span
        class="grid size-14 place-items-center rounded-full border border-line bg-surface"
      >
        MC
      </span>
    </div>
  `,
})
export class Call {}
```

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

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `rings` | `number` | 6 | Jumlah lingkaran, maksimal 12. |
| `size` | `number` | 120 | Diameter lingkaran paling dalam dalam piksel. |
| `gap` | `number` | 64 | Pertambahan diameter tiap lingkaran dari lingkaran sebelumnya, dalam piksel. |
| `color` | `muted \| primary \| success \| warning \| danger` | muted | Warna token lingkaran. Lingkaran luar memudar otomatis. |
| `children / slot` | `slot / ReactNode` | - | Konten yang tampil di atas lingkaran, biasanya di tengah. |

## Aksesibilitas

- Lapisan lingkaran memakai aria-hidden dan mengabaikan pointer.
- Dengan reduced motion, lingkaran berhenti berdenyut.
- Kalau denyut punya arti (misalnya sedang mencari), sampaikan juga lewat teks.

## Catatan

- Lingkaran berada di tengah komponen. Letakkan ikon atau avatar di tengah dengan `grid place-items-center`.
- Kalau denyut punya arti, misalnya sedang mencari, sampaikan juga lewat teks (misalnya dengan `role="status"`).
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
