Your first island
Build a complete two-state island with a typed configuration and a working toggle.
Two states, one surface
This example starts as a compact status pill and expands into a confirmation card. The button controls the active state. All styles are inline, so you can try it without Tailwind.
"use client";
import { useState } from "react";
import DynamicIsland, {
type DynamicIslandComponent,
} from "ob-react-dynamic-island";
type IslandState = "idle" | "expanded";
const components = {
idle: {
animatedConfig: { width: 132, height: 40, borderRadius: 24 },
render: () => <span style={{ fontSize: 13 }}>All up to date</span>,
},
expanded: {
animatedConfig: { width: 280, height: 128, borderRadius: 32 },
render: () => (
<div style={{ padding: 24, textAlign: "center" }}>
<strong style={{ display: "block", marginBottom: 8 }}>
Changes saved
</strong>
<span style={{ color: "#a1a1aa", fontSize: 14 }}>
Your workspace is ready for what comes next.
</span>
</div>
),
},
} satisfies Record<IslandState, DynamicIslandComponent<IslandState>>;
export default function StatusIsland() {
const [state, setState] = useState<IslandState>("idle");
return (
<div
style={{
display: "grid",
justifyItems: "center",
gap: 24,
padding: 32,
fontFamily: "system-ui, sans-serif",
}}
>
<div
style={{
display: "grid",
placeItems: "center",
minHeight: 160,
}}
>
<DynamicIsland
value={state}
components={components}
style={{
position: "relative",
overflow: "hidden",
background: "#09090b",
color: "#fafafa",
}}
contentProps={{
style: {
width: "100%",
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
overflow: "hidden",
},
}}
/>
</div>
<button
type="button"
aria-pressed={state === "expanded"}
onClick={() => {
setState((current) => (current === "idle" ? "expanded" : "idle"));
}}
>
Toggle details
</button>
</div>
);
}Define the state map
Each entry in components requires two properties:
animatedConfigdescribes the container's animation target, such as its width, height, and border radius.renderreturns the React content for that state. It receives the active state key as its argument.
Using a string union with satisfies checks the configuration while keeping each key precise. Add more entries as your interface grows.
Control the active state
DynamicIsland is controlled: it displays the state specified by value. It does not create timers, manage a queue, or decide when to expand. Connect your application state to value and update it from a button, a request result, or another event.
Use a valid state key
value must always match an entry in components. The component does not
provide a fallback for an unknown key. Validate values from URLs or external
data before using them.
Keep application state outside the view
The content wrapper is keyed by value. Switching to another state replaces the wrapper and mounts the new view. Keep data that should survive those switches, such as playback position or form values, in a parent component.
You can also change the current state's animatedConfig without changing value. The container animates to the new target while its content stays mounted. The morph example explores this pattern.
Tune the next step
Use animation settings to adjust the feel, review accessibility before shipping, or explore the complete component API.