# Sync Status

`SyncStatus` shows if local edits are saved. The values follow [Liveblocks' Yjs sync status](https://liveblocks.io/docs/api-reference/liveblocks-yjs) (`loading`, `synchronizing`, `synchronized`), plus `error` for a failed save. The parts match [Kibo UI's Status](https://www.kibo-ui.com/components/status).

_Interactive preview available on the rendered documentation page._


## Installation

Install `@vite-hub/ui` as [Installation](https://vitehub.dev/docs/ui/installation) shows. `vite-hub/nuxt` auto-imports the parts. In Vue with Vite, import them from `vite-hub/ui`:

```ts
import { SyncStatus, SyncStatusIndicator, SyncStatusLabel } from "vite-hub/ui";
```

## Usage

Derive the status from the Realtime room:

```ts
import { computed, ref } from "vue"
import type { SyncStatusValue } from "vite-hub/ui";
import { useRealtimeTiptap } from "vite-hub/realtime/vue";

const realtime = useRealtimeTiptap("docs", "guides/welcome.md");
const failed = ref(false);
const sync = computed<SyncStatusValue>(() => {
  if (!realtime.synced.value) return "loading";
  if (realtime.history.pending.value) return "synchronizing";
  return failed.value ? "error" : "synchronized";
});

// `history.checkpoint()` saves the room to the Workspace and rejects when the save fails.
async function save() {
  try {
    await realtime.history.checkpoint();
    failed.value = false;
  } catch {
    failed.value = true;
  }
}
```

```vue
<template>
  <SyncStatus :status="sync" />
</template>
```

## Composition

```text
SyncStatus
├── SyncStatusIndicator
└── SyncStatusLabel
```

Without children, `SyncStatus` renders both parts.

## Features

- Four states with default labels: "Loading", "Saving", "Saved", and "Not saved".
- Pending states pulse, except with reduced motion.
- Every part has `data-status` for styling each state.
- Pair it with [Connection Status](https://vitehub.dev/docs/ui/connection-status). An offline editor can still have unsaved edits.

## Custom Label

Put details such as the save time in `SyncStatusLabel`. Its default slot receives `{ status }`.

_Interactive preview available on the rendered documentation page._


## Accessibility

`SyncStatus` has `role="status"`, so screen readers announce "Saved" or "Not saved" without moving focus. The indicator is decorative and only the error state changes text color, so the label carries the meaning.

## API Reference

### SyncStatus

The root. Renders a `div` with `data-slot="sync-status"` and `data-status`.

#### Props

| Prop     | Type                                                           | Default  | Description               |
| -------- | -------------------------------------------------------------- | -------- | ------------------------- |
| `status` | `"loading" \| "synchronizing" \| "synchronized" \| "error"`    | Required | Where local edits stand.  |

### SyncStatusIndicator

A dot that shows the status. No props. Renders a `span` with `data-slot="sync-status-indicator"`.

### SyncStatusLabel

The status as text. The default slot receives `{ status }`. No props. Renders a `span` with `data-slot="sync-status-label"`.

## Related

- [Connection Status](https://vitehub.dev/docs/ui/connection-status) shows the connection of the same editor.
- [Avatar Stack](https://vitehub.dev/docs/ui/avatar-stack) shows who is editing.
- [Collaborative Editor](https://vitehub.dev/docs/ui/blocks/collaborative-editor) combines all collaboration parts with Realtime.

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/ui.md)
- [AI components](https://vitehub.dev/raw/docs/ui/ai-components.md)
- [Blocks](https://vitehub.dev/raw/docs/ui/blocks/chat-app.md)
- [Parts](https://vitehub.dev/raw/docs/ui/message.md)
- [Chat](https://vitehub.dev/raw/docs/ui/chat.md)
- Collaboration
  - [Avatar Stack](https://vitehub.dev/raw/docs/ui/avatar-stack.md)
  - [Connection Status](https://vitehub.dev/raw/docs/ui/connection-status.md)
  - [Sync Status](https://vitehub.dev/raw/docs/ui/sync-status.md) (this page)
  - [Carets](https://vitehub.dev/raw/docs/ui/carets.md)
  - [Comments](https://vitehub.dev/raw/docs/ui/comments.md)
  - [Markdown Editor](https://vitehub.dev/raw/docs/ui/markdown-editor.md)
- [Agent work](https://vitehub.dev/raw/docs/ui/tool-list.md)
- [Utilities](https://vitehub.dev/raw/docs/ui/attachments.md)

Next: [Carets](https://vitehub.dev/raw/docs/ui/carets.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
