Alert

Offline Alert

An offline bar that watches the connection itself through browser events. There is no "back online" message: the bar disappearing says it.

  • alert
  • offline
  • network
  • status

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/alert-018?lang=en

No connectionYour changes will be saved once the network is back.
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "alert-018" (Offline Alert) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/alert-018.json

Registry item: https://vibeui.ru/r/alert-018.json
Installs to: components/vibeui/alert-018.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
An offline bar that watches the connection itself through browser events. There is no "back online" message: the bar disappearing says it.

A floating offline bar: a blinking dot, a heading, a note and a retry button. The only component in the set that watches state itself, through the online and offline events. While the connection is up it renders nothing at all. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Alert018 } from "@/components/vibeui/alert-018"

<Alert018 onRetry={retryRequest} />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-alert-018-* palette — the bar is deliberately dark and does not follow the page theme
- useSyncExternalStore instead of useState with an effect: it is the sanctioned way to read an external source without extra renders
- the server snapshot of "online": otherwise the markup diverges at hydration
- returning null while online: the bar must not occupy space in the document
- the absence of a "back online" message: the bar disappearing says it, and a success toast would need hiding on a timer
- aria-live="polite": the appearance should be announced without interrupting
- the <style> block inside the component — it holds the palette and the blinking dot

## 6. You may change
- the title and description copy
- onRetry and retryLabel — retrying the last request
- force — show the bar regardless: showcase, screenshots, debugging
- placement through className: usually fixed at the bottom centre

## 7. Rules
- navigator.onLine reports network presence, not that your server is reachable. For that you need your own probe request.
- The component neither queues nor replays requests — onRetry is written by the caller.
- Positioning is not part of the component: it stays inline-flex and the page decides where it sits.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/alert-018.json
https://vibeui.ru/r/alert-018.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-alert-018-*. Состояние читается через useSyncExternalStore с подпиской на события online и offline: это штатный способ читать внешний источник, он не вызывает лишних рендеров и корректно ведёт себя при серверной отрисовке, где снимок всегда «связь есть». Пока связь есть, компонент возвращает null. Проп force показывает полосу принудительно — для витрины и отладки.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useSyncExternalStore } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Alert018Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "title" | "children"
> & {
  title?: string
  description?: string
  retryLabel?: string
  onRetry?: () => void
  /** Показать полосу принудительно: витрина, скриншот, отладка. */
  force?: boolean
}

// Идея компонента: полоса «нет соединения». Она единственная в наборе следит
// за состоянием сама, потому что прокидывать его пропом означало бы повторять
// одну и ту же подписку в каждом проекте. Подписка сделана через
// useSyncExternalStore: это штатный способ читать внешний источник, он не
// вызывает лишних рендеров и корректно ведёт себя при серверной отрисовке.
//
// Компонент показывает только отсутствие связи. Сообщения «связь вернулась»
// здесь нет намеренно: о возврате к норме говорит исчезновение полосы, а
// отдельное уведомление об успехе пришлось бы прятать по таймеру.
const STYLES = `
:where([data-vibeui-block="alert-018"]){
--vibeui-alert-018-fg:oklch(0.97 0.004 265);
--vibeui-alert-018-bg:oklch(0.32 0.016 265);
--vibeui-alert-018-muted:oklch(0.82 0.01 265);
--vibeui-alert-018-radius:9999px;
--vibeui-alert-018-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="alert-018"]{
display:inline-flex;align-items:center;gap:0.625rem;
box-sizing:border-box;
padding:0.5rem 0.9375rem;
border-radius:var(--vibeui-alert-018-radius);
background:var(--vibeui-alert-018-bg);color:var(--vibeui-alert-018-fg);
font-family:var(--vibeui-alert-018-font);font-size:0.8125rem;
box-shadow:0 12px 30px -18px oklch(0.15 0.02 265 / 70%);
}
/* Мигающая точка вместо спиннера: связь не «грузится», она отсутствует. */
[data-vibeui-block="alert-018"] [data-part="dot"]{
flex:none;width:0.4375rem;height:0.4375rem;border-radius:9999px;
background:currentColor;
animation:vibeui-alert-018-blink 1.4s ease-in-out infinite;
}
@keyframes vibeui-alert-018-blink{0%,100%{opacity:1}50%{opacity:.25}}
[data-vibeui-block="alert-018"] [data-part="title"]{font-weight:600}
[data-vibeui-block="alert-018"] [data-part="description"]{color:var(--vibeui-alert-018-muted)}
[data-vibeui-block="alert-018"] [data-part="retry"]{
appearance:none;border:0;background:none;cursor:pointer;padding:0;
color:inherit;font:inherit;font-weight:600;text-decoration:underline;
}
[data-vibeui-block="alert-018"] [data-part="retry"]:focus-visible{outline:2px solid currentColor;outline-offset:3px;border-radius:0.25rem}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="alert-018"] *{animation:none!important;transition:none!important}}
`

function subscribe(callback: () => void) {
  window.addEventListener("online", callback)
  window.addEventListener("offline", callback)

  return () => {
    window.removeEventListener("online", callback)
    window.removeEventListener("offline", callback)
  }
}

/**
 * Полоса отсутствия связи: подписка на события браузера внутри компонента.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Alert018({
  title = "Нет соединения",
  description = "Изменения сохранятся, когда сеть вернётся.",
  retryLabel = "Повторить",
  onRetry,
  force = false,
  className,
  style,
  ...props
}: Alert018Props) {
  // На сервере считаем, что связь есть: полоса появится уже в браузере.
  const online = useSyncExternalStore(
    subscribe,
    () => navigator.onLine,
    () => true,
  )

  if (online && !force) {
    return null
  }

  return (
    <>
      <style href="vibeui-alert-018" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="alert-018"
        role="status"
        aria-live="polite"
        className={className}
        style={style as CSSProperties}
      >
        <span data-part="dot" aria-hidden="true" />
        <span data-part="title">{title}</span>
        {description ? (
          <span data-part="description">{description}</span>
        ) : null}
        {onRetry && retryLabel ? (
          <button data-part="retry" type="button" onClick={onRetry}>
            {retryLabel}
          </button>
        ) : null}
      </div>
    </>
  )
}