ChatConnectionState

Feedback & Status

전송 연결 상태를 알리는 배너.

Usage

소켓·SSE 연결이 끊기거나 재연결될 때 상태 배너로 알릴 때 사용한다.

import

import

import { ChatConnectionState } from '@mildang/design-system/unofficial/Chat';

예제를 복사해 쓸 때 필요한 준비

@mildang/styled-system 은 이 저장소에서 Panda 가 생성하는 산출물이다. 저장소 안에서는 turbo run ship 이후 쓸 수 있고, 패키지 소비자는 자기 Panda 산출물이나 다른 레이아웃 수단으로 바꿔야 한다.

API Reference

ChatConnectionState Props

Prop

Type

Default

phase
필수

"online" | "dropped" | "reconnecting" | "resumed"

지정 안 함

attempt

number

지정 안 함

labels

Partial<ChatConnectionStateLabels>

지정 안 함

onRetry

() => void

지정 안 함

resumedTokens

number

지정 안 함

같은 패밀리

@mildang/design-system/unofficial/Chat 에서 같이 내보내는 컴포넌트다.

예제

연결 끊김

import type { ComponentProps } from 'react';
import { ChatConnectionState } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatConnectionState>;
const DEFAULT_ARGS: Props = { phase: 'dropped', onRetry: () => {} };
export default function ConnectionStateDroppedExample(props: Partial<Props> = {}) { return <ChatConnectionState {...DEFAULT_ARGS} {...props} />; }

재연결 중

import type { ComponentProps } from 'react';
import { ChatConnectionState } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatConnectionState>;
const DEFAULT_ARGS: Props = { phase: 'reconnecting', attempt: 3 };
export default function ConnectionStateReconnectingExample(props: Partial<Props> = {}) { return <ChatConnectionState {...DEFAULT_ARGS} {...props} />; }

재개됨

import type { ComponentProps } from 'react';
import { ChatConnectionState } from '@mildang/design-system/unofficial/Chat';
type Props = ComponentProps<typeof ChatConnectionState>;
const DEFAULT_ARGS: Props = { phase: 'resumed', resumedTokens: 1284 };
export default function ConnectionStateResumedExample(props: Partial<Props> = {}) { return <ChatConnectionState {...DEFAULT_ARGS} {...props} />; }

정상 연결

phase가 online이면 아무것도 렌더하지 않는 원본 동작을 보여주는 예시다.

import { css } from '@mildang/styled-system/css';
import { ChatConnectionState } from '@mildang/design-system/unofficial/Chat';

const ConnectionStateOnlineExample = () => (
    <div className={css({ display: 'flex', flexDirection: 'column', gap: '16' })}>
      <div
        className={css({
          borderWidth: '1px',
          borderStyle: 'dashed',
          borderColor: 'neutral.border.base',
          borderRadius: 'lg',
          padding: '12',
          textStyle: 'chat-small-text-R',
          color: 'neutral.text.lowest',
        })}
      >
        phase=&quot;online&quot; → 렌더 없음
        <ChatConnectionState phase="online" />
      </div>

      <ChatConnectionState
        phase="reconnecting"
        attempt={2}
        labels={{
          reconnecting: 'Reconnecting',
          attempt: (attempt) => `attempt ${attempt}`,
        }}
      />
    </div>
  );

export default ConnectionStateOnlineExample;