# Dynamic Island

Pill hitam terinspirasi Dynamic Island iPhone. Memuai mulus antara keadaan idle, compact, dan expanded sambil kontennya crossfade.

- Kategori: MarkasUI
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/dynamic-island.json
- CLI: `npx markasui@latest add dynamic-island`

## Kapan dipakai

Pill status yang playful untuk timer, musik, panggilan, unggahan, atau pembayaran di atas layout mobile atau kerangka aplikasi.

- Jaga isi compact berupa ikon di kiri dan nilai singkat di kanan
- Pakai expanded hanya untuk hal yang butuh perhatian atau aksi
- Isi announcements untuk perubahan yang perlu didengar, misalnya panggilan masuk
- Timpa --island-expanded-width dan --island-expanded-height bila isi kartu butuh ruang lebih

## Kode

### Blade

Simpan di `resources/views/components/markas/dynamic-island.blade.php`. Dependensi: alpinejs.

```blade
@props([
    'state' => 'idle',
    'announcements' => [],
    'islandLabel' => 'Live activity',
])

@php
    // The island re-scopes the theme with the dark class, so it reads as a black pill in both modes.
    $root = 'dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]';
    $panel = 'absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm';
    $panels = [
        'idle' => 'grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center',
        'compact' => 'flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium',
        'expanded' => 'h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4',
    ];
    $side = 'flex min-w-0 items-center gap-2';
    $srOnly = 'sr-only';

    $slots = $__laravel_slots ?? [];
@endphp

{{-- Controlled from outside: bind a parent value with x-model, it is the island's state. --}}
<div
    x-data="{ state: @js($state), announcements: @js((object) $announcements) }"
    x-modelable="state"
    role="region"
    aria-label="{{ $islandLabel }}"
    data-state="{{ $state }}"
    x-bind:data-state="state"
    {{ $attributes->class([$root]) }}
>
    @foreach (['idle', 'compact', 'expanded'] as $name)
        <div
            data-state="{{ $state === $name ? 'active' : 'inactive' }}"
            @if ($state !== $name) inert @endif
            x-bind:data-state="state === '{{ $name }}' ? 'active' : 'inactive'"
            x-bind:inert="state !== '{{ $name }}'"
            class="{{ $panel }} {{ $panels[$name] }}"
        >
            @if ($name === 'compact')
                <div class="{{ $side }}">{{ $slots['leading'] ?? '' }}</div>
                <div class="{{ $side }}">{{ $slots['trailing'] ?? '' }}</div>
            @else
                {{ $slots[$name] ?? '' }}
            @endif
        </div>
    @endforeach
    <p aria-live="polite" class="{{ $srOnly }}" x-text="announcements[state] ?? ''">{{ $announcements[$state] ?? '' }}</p>
</div>
```

```blade
<div x-data="{ island: 'compact' }">
    <x-markas.dynamic-island
        state="compact"
        x-model="island"
        island-label="Aktivitas langsung"
        :announcements="['expanded' => 'Timer fokus, sisa 12 menit']"
    >
        <x-slot:leading><svg aria-hidden="true">...</svg></x-slot:leading>
        <x-slot:trailing><span class="tabular-nums">12:48</span></x-slot:trailing>
        <x-slot:expanded>
            <p>Timer fokus</p>
            <button type="button" x-on:click="island = 'idle'">Selesai</button>
        </x-slot:expanded>
    </x-markas.dynamic-island>
    <button type="button" x-on:click="island = 'expanded'">Lihat timer</button>
</div>
```

### React

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

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

/** The island re-scopes the theme with the dark class, so it reads as a black pill in both modes. */
const root =
  "dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]";
const panel =
  "absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm";
const panels = {
  idle: "grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center",
  compact:
    "flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium",
  expanded:
    "h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4",
};
const side = "flex min-w-0 items-center gap-2";
const srOnly = "sr-only";

const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type DynamicIslandState = "idle" | "compact" | "expanded";

export type DynamicIslandProps = ComponentProps<"div"> & {
  state?: DynamicIslandState;
  /** Content of the small idle pill, usually empty. */
  idle?: ReactNode;
  /** Left side of the compact pill, such as an icon. */
  leading?: ReactNode;
  /** Right side of the compact pill, such as a time or level. */
  trailing?: ReactNode;
  /** Content of the large card. */
  expanded?: ReactNode;
  /** Text read by screen readers when the island moves to a state. */
  announcements?: Partial<Record<DynamicIslandState, string>>;
  islandLabel?: string;
};

export function DynamicIsland({
  state = "idle",
  idle,
  leading,
  trailing,
  expanded,
  announcements = {},
  islandLabel = "Live activity",
  className,
  ...props
}: DynamicIslandProps) {
  const panelProps = (name: DynamicIslandState) => ({
    "data-state": state === name ? "active" : "inactive",
    inert: state !== name,
    className: cx(panel, panels[name]),
  });
  return (
    <div
      role="region"
      aria-label={islandLabel}
      data-state={state}
      className={cx(root, className)}
      {...props}
    >
      <div {...panelProps("idle")}>{idle}</div>
      <div {...panelProps("compact")}>
        <div className={side}>{leading}</div>
        <div className={side}>{trailing}</div>
      </div>
      <div {...panelProps("expanded")}>{expanded}</div>
      <p aria-live="polite" className={srOnly}>
        {announcements[state] ?? ""}
      </p>
    </div>
  );
}
```

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

<DynamicIsland
  state={state}
  islandLabel="Aktivitas langsung"
  leading={<IkonTimer />}
  trailing={<span className="tabular-nums">12:48</span>}
  expanded={<KartuTimer onSelesai={() => setState("idle")} />}
  announcements={{ expanded: "Timer fokus, sisa 12 menit" }}
/>;
```

### Vue

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

```vue
<script setup lang="ts">
export type DynamicIslandState = "idle" | "compact" | "expanded";

const props = withDefaults(
  defineProps<{
    state?: DynamicIslandState;
    /** Text read by screen readers when the island moves to a state. */
    announcements?: Partial<Record<DynamicIslandState, string>>;
    islandLabel?: string;
  }>(),
  { state: "idle", announcements: () => ({}), islandLabel: "Live activity" },
);

/** The island re-scopes the theme with the dark class, so it reads as a black pill in both modes. */
const root =
  "dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]";
const panel =
  "absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm";
const panels = {
  idle: "grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center",
  compact:
    "flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium",
  expanded:
    "h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4",
};
const side = "flex min-w-0 items-center gap-2";
const srOnly = "sr-only";

const stateOf = (name: DynamicIslandState) =>
  props.state === name ? "active" : "inactive";
</script>

<template>
  <div
    role="region"
    :aria-label="props.islandLabel"
    :data-state="props.state"
    :class="root"
  >
    <div
      :data-state="stateOf('idle')"
      :inert="props.state !== 'idle' || undefined"
      :class="[panel, panels.idle]"
    >
      <slot name="idle" />
    </div>
    <div
      :data-state="stateOf('compact')"
      :inert="props.state !== 'compact' || undefined"
      :class="[panel, panels.compact]"
    >
      <div :class="side"><slot name="leading" /></div>
      <div :class="side"><slot name="trailing" /></div>
    </div>
    <div
      :data-state="stateOf('expanded')"
      :inert="props.state !== 'expanded' || undefined"
      :class="[panel, panels.expanded]"
    >
      <slot name="expanded" />
    </div>
    <p aria-live="polite" :class="srOnly">
      {{ props.announcements[props.state] ?? "" }}
    </p>
  </div>
</template>
```

```vue
<script setup lang="ts">
import DynamicIsland from "@/components/markas/DynamicIsland.vue";
</script>

<template>
  <DynamicIsland
    :state="state"
    island-label="Aktivitas langsung"
    :announcements="{ expanded: 'Timer fokus' }"
  >
    <template #leading><IkonTimer /></template>
    <template #trailing><span class="tabular-nums">12:48</span></template>
    <template #expanded><KartuTimer @selesai="state = 'idle'" /></template>
  </DynamicIsland>
</template>
```

### Svelte

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

```svelte
<script lang="ts" module>
  export type DynamicIslandState = "idle" | "compact" | "expanded";
</script>

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

  /** The island re-scopes the theme with the dark class, so it reads as a black pill in both modes. */
  const root =
    "dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]";
  const panel =
    "absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm";
  const panels = {
    idle: "grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center",
    compact:
      "flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium",
    expanded:
      "h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4",
  };
  const side = "flex min-w-0 items-center gap-2";
  const srOnly = "sr-only";

  type Props = HTMLAttributes<HTMLDivElement> & {
    state?: DynamicIslandState;
    /** Content of the small idle pill, usually empty. */
    idle?: Snippet;
    /** Left side of the compact pill, such as an icon. */
    leading?: Snippet;
    /** Right side of the compact pill, such as a time or level. */
    trailing?: Snippet;
    /** Content of the large card. */
    expanded?: Snippet;
    /** Text read by screen readers when the island moves to a state. */
    announcements?: Partial<Record<DynamicIslandState, string>>;
    islandLabel?: string;
  };

  let {
    state = "idle",
    idle,
    leading,
    trailing,
    expanded,
    announcements = {},
    islandLabel = "Live activity",
    class: className,
    ...rest
  }: Props = $props();

  const stateOf = (name: DynamicIslandState) =>
    state === name ? "active" : "inactive";
</script>

<div
  role="region"
  aria-label={islandLabel}
  data-state={state}
  class={[root, className]}
  {...rest}
>
  <div
    data-state={stateOf("idle")}
    inert={state !== "idle"}
    class={[panel, panels.idle]}
  >
    {@render idle?.()}
  </div>
  <div
    data-state={stateOf("compact")}
    inert={state !== "compact"}
    class={[panel, panels.compact]}
  >
    <div class={side}>{@render leading?.()}</div>
    <div class={side}>{@render trailing?.()}</div>
  </div>
  <div
    data-state={stateOf("expanded")}
    inert={state !== "expanded"}
    class={[panel, panels.expanded]}
  >
    {@render expanded?.()}
  </div>
  <p aria-live="polite" class={srOnly}>{announcements[state] ?? ""}</p>
</div>
```

```svelte
<script lang="ts">
  import DynamicIsland, {
    type DynamicIslandState,
  } from "$lib/components/markas/DynamicIsland.svelte";

  let state = $state<DynamicIslandState>("compact");
</script>

<DynamicIsland
  {state}
  announcements={{ expanded: "Focus timer, 12 minutes left" }}
>
  {#snippet leading()}<TimerIcon />{/snippet}
  {#snippet trailing()}<span class="tabular-nums">12:48</span>{/snippet}
  {#snippet expanded()}
    <TimerCard onEnd={() => (state = "idle")} />
  {/snippet}
</DynamicIsland>
```

### Astro

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

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

export type DynamicIslandState = "idle" | "compact" | "expanded";

/** The island re-scopes the theme with the dark class, so it reads as a black pill in both modes. */
const root =
  "dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]";
const panel =
  "absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm";
const panels = {
  idle: "grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center",
  compact:
    "flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium",
  expanded:
    "h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4",
};
const side = "flex min-w-0 items-center gap-2";
const srOnly = "sr-only";

type Props = HTMLAttributes<"div"> & {
  /** First state. Change it later with setAttribute("state", ...) on markas-dynamic-island. */
  state?: DynamicIslandState;
  /** Text read by screen readers when the island moves to a state. */
  announcements?: Partial<Record<DynamicIslandState, string>>;
  islandLabel?: string;
};

const {
  state = "idle",
  announcements = {},
  islandLabel = "Live activity",
  class: className,
  ...rest
} = Astro.props;

const stateOf = (name: DynamicIslandState) => (state === name ? "active" : "inactive");
---

<markas-dynamic-island
  class="contents"
  state={state}
  data-announcements={JSON.stringify(announcements)}
>
  <div
    role="region"
    aria-label={islandLabel}
    data-state={state}
    class:list={[root, className]}
    {...rest}
  >
    <div
      data-state={stateOf("idle")}
      data-panel="idle"
      inert={state !== "idle"}
      class:list={[panel, panels.idle]}
    >
      <slot name="idle" />
    </div>
    <div
      data-state={stateOf("compact")}
      data-panel="compact"
      inert={state !== "compact"}
      class:list={[panel, panels.compact]}
    >
      <div class={side}><slot name="leading" /></div>
      <div class={side}><slot name="trailing" /></div>
    </div>
    <div
      data-state={stateOf("expanded")}
      data-panel="expanded"
      inert={state !== "expanded"}
      class:list={[panel, panels.expanded]}
    >
      <slot name="expanded" />
    </div>
    <p aria-live="polite" class={srOnly}>{announcements[state] ?? ""}</p>
  </div>
</markas-dynamic-island>

<script>
  // Controlled from outside: set the state attribute (island.setAttribute("state", "expanded"))
  // and the island morphs. A custom element, so it also works for markup added later.
  class MarkasDynamicIsland extends HTMLElement {
    static observedAttributes = ["state"];

    attributeChangedCallback() {
      const state = this.getAttribute("state") ?? "idle";
      const region = this.querySelector<HTMLElement>("[role=region]");
      if (!region) return;
      region.dataset.state = state;
      this.querySelectorAll<HTMLElement>("[data-panel]").forEach((panel) => {
        const active = panel.dataset.panel === state;
        panel.dataset.state = active ? "active" : "inactive";
        panel.inert = !active;
      });
      const announcements = JSON.parse(this.dataset.announcements ?? "{}");
      const live = region.querySelector("[aria-live]");
      if (live) live.textContent = announcements[state] ?? "";
    }
  }

  if (!customElements.get("markas-dynamic-island"))
    customElements.define("markas-dynamic-island", MarkasDynamicIsland);
</script>
```

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

<DynamicIsland
  state="compact"
  announcements={{ expanded: "Focus timer, 12 minutes left" }}
>
  <TimerIcon slot="leading" />
  <span slot="trailing" class="tabular-nums">12:48</span>
  <TimerCard slot="expanded" />
</DynamicIsland>

<script>
  document
    .querySelector("markas-dynamic-island")
    ?.setAttribute("state", "expanded");
</script>
```

Island merender state pertama di server. Ubah setelahnya dengan mengatur atribut `state` di `markas-dynamic-island`; panel, inert, dan pengumuman ikut berubah.

### Angular

Simpan di `src/app/markas/dynamic-island.component.ts`. Tanpa dependensi tambahan.

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

export type DynamicIslandState = "idle" | "compact" | "expanded";

/** The island re-scopes the theme with the dark class, so it reads as a black pill in both modes. */
const root =
  "dark relative mx-auto max-w-full overflow-hidden bg-canvas text-ink ring-1 ring-line transition-[width,height,border-radius] duration-500 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none data-[state=compact]:h-9 data-[state=compact]:w-[var(--island-compact-width,15rem)] data-[state=compact]:rounded-[18px] data-[state=expanded]:h-[var(--island-expanded-height,9.5rem)] data-[state=expanded]:w-[var(--island-expanded-width,22rem)] data-[state=expanded]:rounded-[32px] data-[state=idle]:h-9 data-[state=idle]:w-[var(--island-idle-width,7.5rem)] data-[state=idle]:rounded-[18px]";
const panel =
  "absolute top-0 left-1/2 max-w-[100cqw] origin-top -translate-x-1/2 transition-[opacity,scale,filter] duration-300 ease-out motion-reduce:transition-none data-[state=active]:delay-150 data-[state=inactive]:pointer-events-none data-[state=inactive]:scale-90 data-[state=inactive]:opacity-0 data-[state=inactive]:blur-sm";
const panels = {
  idle: "grid h-9 w-[var(--island-idle-width,7.5rem)] place-items-center",
  compact:
    "flex h-9 w-[var(--island-compact-width,15rem)] items-center justify-between gap-3 px-3 text-xs font-medium",
  expanded:
    "h-[var(--island-expanded-height,9.5rem)] w-[var(--island-expanded-width,22rem)] p-4",
};
const side = "flex min-w-0 items-center gap-2";
const srOnly = "sr-only";

/**
 * Slots: elements with the `idle`, `leading`, `trailing`, or `expanded` attribute (an
 * ng-container works). Host stays out of layout; class moves to the region.
 */
@Component({
  selector: "markas-dynamic-island",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: "contents" },
  template: `
    <div
      role="region"
      [attr.aria-label]="islandLabel()"
      [attr.data-state]="state()"
      [class]="rootClasses()"
    >
      <div
        [attr.data-state]="stateOf('idle')"
        [attr.inert]="state() !== 'idle' ? '' : null"
        [class]="panelIdle"
      >
        <ng-content select="[idle]" />
      </div>
      <div
        [attr.data-state]="stateOf('compact')"
        [attr.inert]="state() !== 'compact' ? '' : null"
        [class]="panelCompact"
      >
        <div [class]="side"><ng-content select="[leading]" /></div>
        <div [class]="side"><ng-content select="[trailing]" /></div>
      </div>
      <div
        [attr.data-state]="stateOf('expanded')"
        [attr.inert]="state() !== 'expanded' ? '' : null"
        [class]="panelExpanded"
      >
        <ng-content select="[expanded]" />
      </div>
      <p aria-live="polite" [class]="srOnly">{{ announcement() }}</p>
    </div>
  `,
})
export class DynamicIsland {
  readonly state = input<DynamicIslandState>("idle");
  /** Text read by screen readers when the island moves to a state. */
  readonly announcements = input<Partial<Record<DynamicIslandState, string>>>(
    {},
  );
  readonly islandLabel = input("Live activity");
  readonly userClass = input("", { alias: "class" });

  protected readonly panelIdle = `${panel} ${panels.idle}`;
  protected readonly panelCompact = `${panel} ${panels.compact}`;
  protected readonly panelExpanded = `${panel} ${panels.expanded}`;
  protected readonly side = side;
  protected readonly srOnly = srOnly;
  protected readonly rootClasses = computed(() =>
    [root, this.userClass()].filter(Boolean).join(" "),
  );
  protected readonly announcement = computed(
    () => this.announcements()[this.state()] ?? "",
  );

  protected stateOf(name: DynamicIslandState) {
    return this.state() === name ? "active" : "inactive";
  }
}
```

```ts
import { Component, signal } from "@angular/core";
import {
  DynamicIsland,
  type DynamicIslandState,
} from "./markas/dynamic-island.component";

@Component({
  selector: "app-timer-island",
  imports: [DynamicIsland],
  template: `
    <markas-dynamic-island [state]="state()" [announcements]="announcements">
      <span leading class="size-2 rounded-full bg-warning"></span>
      <span trailing class="tabular-nums">12:48</span>
      <div expanded>
        <button type="button" (click)="state.set('idle')">End</button>
      </div>
    </markas-dynamic-island>
  `,
})
export class TimerIsland {
  state = signal<DynamicIslandState>("compact");
  announcements = { expanded: "Focus timer, 12 minutes left" };
}
```

Elemen dengan atribut `idle`, `leading`, `trailing`, atau `expanded` mengisi slot yang sesuai. `ng-container` juga bisa.

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `state` | `"idle" \| "compact" \| "expanded"` | idle | Keadaan saat ini, dikendalikan dari luar. Blade juga mengikuti nilai induk yang diikat dengan x-model. |
| `idle` | `ReactNode / slot` | - | Isi pill idle kecil, biasanya kosong. |
| `leading` | `ReactNode / slot` | - | Sisi kiri pill compact, misalnya ikon atau sampul album. |
| `trailing` | `ReactNode / slot` | - | Sisi kanan pill compact, misalnya timer atau nilai singkat. |
| `expanded` | `ReactNode / slot` | - | Isi kartu besar, cukup untuk teks dan tombol. |
| `announcements` | `{ idle?: string; compact?: string; expanded?: string }` | {} | Teks yang dibacakan live region polite saat island pindah ke keadaan itu. Isi hanya keadaan yang penting. |
| `islandLabel` | `string` | Live activity | Nama aksesibel region island. Default "Live activity", isi misalnya "Aktivitas langsung". |
| `state attribute` | `idle \| compact \| expanded` | - | Khusus Astro. Atur atribut state di markas-dynamic-island dari script untuk mengubah island setelah render pertama. |

## Aksesibilitas

- Island adalah region bernama islandLabel. Isi keadaan yang tidak tampil bersifat inert, jadi tidak bisa difokus atau dibaca.
- Paragraf aria-live="polite" tersembunyi membacakan pengumuman keadaan saat ini, jadi perubahan penting terdengar tanpa memindah fokus.
- Perubahan ukuran dan crossfade murni transisi CSS. Dengan reduced motion island langsung melompat ke ukuran baru.
- Beri aria-label pada tombol ikon di dalam slot, dan letakkan kontrol yang mengubah keadaan di luar island.

## Catatan

- Lebar, tinggi, dan radius sudut bergerak dengan satu transisi CSS yang memantul halus. Konten baru memudar masuk dan menajam sesaat kemudian.
- Isi setiap keadaan tetap di ukuran akhirnya dan terungkap oleh pill yang membesar, jadi teks tidak bergeser selama animasi.
- Island menambahkan class dark ke dirinya, jadi tampil sebagai pill hitam di halaman terang dan pill bercincin di halaman gelap, dan komponen di dalamnya memakai token gelap.
- Ukuran diambil dari `--island-idle-width`, `--island-compact-width`, `--island-expanded-width`, dan `--island-expanded-height` (default 7.5rem, 15rem, 22rem, 9.5rem).
- Island tidak pernah lebih lebar dari induknya. Isinya dibatasi oleh size container terdekat, atau layar kalau tidak ada, jadi beri induk yang sempit class `@container` (seperti di contoh) supaya isinya ikut muat.
