MessageScroller

가장 새 메시지를 계속 보여주는 경계 있는 자동 고정 채팅 로그입니다.

개요

MessageScroller는 채팅 로그의 스크롤 뷰포트예요. 자식을 세로로 쌓고, 독자가 바닥에 있는 동안 콘텐츠가 늘어나면 가장 새 메시지를 계속 보여줘요 — 독자가 히스토리를 읽으려고 위로 스크롤하는 순간 멈추고, 바닥으로 돌아오면 재개해요. style로 높이를 제한하세요.

구조

테마된 스크롤바(comp.messageScroller.*)가 있는 스크롤 뷰포트 안의 세로 flex 스택이에요. 매 업데이트 후 독자가 바닥 근처에 있는지 확인하고, 그렇다면 scrollTop을 가장 새 메시지에 고정해요. Message 행으로 채우세요.

변형 및 상태

시각적 변형은 없어요 — 유일한 동작 토글은 stickToBottom이에요.

State Status Notes
Following (바닥에 있음) Implemented 새 메시지가 자동으로 뷰에 스크롤돼요.
Reading history (위로 스크롤함) Implemented 독자가 바닥으로 돌아올 때까지 자동 스크롤이 멈춰요.
stickToBottom=false Implemented 자동 스크롤을 완전히 옵트아웃해요.
비활성화 Not implemented —
로딩 Not implemented —

사용법

Do

  • style(maxHeight)로 높이를 제한하세요 — 그 경계가 로그를 스크롤되게 만들어요.
  • 아바타, 작성자, 말풍선이 일관되게 유지되도록 Message 행으로 채우세요.
  • 라이브 채팅에서는 수동 스크롤 없이 새 메시지가 나타나도록 stickToBottom을 켜 두세요.

Don't

  • 독자가 히스토리를 읽는 동안 바닥으로 강제로 스크롤하지 마세요 — 멈춤 동작은 의도적이에요.
  • 같은 축에 또 다른 세로 스크롤 영역을 중첩하지 마세요.

접근성

콘텐츠

N/A — 스크롤러는 자체 콘텐츠 모델이 없어요. 안에 넣는 메시지 행을 제한하고 따라가요.

Props API

React@ghds/react

PropTypeDefaultDescription
stickToBottombooleantrue독자가 바닥에 있는 동안 뷰를 가장 새 메시지에 고정해요.
...restHTMLAttributes<HTMLDivElement>—네이티브 <div> 속성이 전달돼요; style로 maxHeight를 설정하세요.

Web Components@ghds/web-components

PropTypeDefaultDescription
stick-to-bottombooleantrue반영되는 속성; 독자가 바닥에 있는 동안 뷰를 가장 새 메시지에 고정해요.
scrollToBottom()() => void—뷰포트를 가장 새 메시지로 점프시키는 메서드.
(기본 슬롯)slot—<gh-message> 행의 세로 스택. 호스트에 max-height를 설정하세요.

React Native@ghds/react-native

PropTypeDefaultDescription
stickToBottombooleantrue독자가 바닥에 있는 동안 뷰를 가장 새 메시지에 고정해요.
childrenReactNode—메시지의 세로 스택.
testIDstring—쿼리용 테스트 핸들.

코드 예시

// React — @ghds/react
import { MessageScroller } from '@ghds/react/message-scroller';
import { Message } from '@ghds/react/message';

<MessageScroller style={{ maxHeight: 320 }}>
  {messages.map((m) => (
    <Message key={m.id} side={m.side}>
      {/* … MessageAvatar / MessageContent / Bubble … */}
    </Message>
  ))}
</MessageScroller>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
  import '@ghds/web-components/message-scroller';
  import '@ghds/web-components/message';
  import '@ghds/web-components/bubble';
  // 명령형 API: scroller.scrollToBottom()을 호출하면 최신 메시지로 이동해요
</script>
<gh-message-scroller style="max-height: 320px;">
  <gh-message side="received">
    <span slot="author">Bo Ram</span>
    <gh-bubble variant="received">Hey — are we still on for tomorrow?</gh-bubble>
  </gh-message>
</gh-message-scroller>
// React Native — @ghds/react-native
import { MessageScroller } from '@ghds/react-native/message-scroller';
import { Message } from '@ghds/react-native/message';

<MessageScroller style={{ maxHeight: 320 }}>
  {messages.map((m) => (
    <Message key={m.id} side={m.side}>{/* … */}</Message>
  ))}
</MessageScroller>;

라이브 데모

React와 Web Components가 아래에서 같은 토큰으로 라이브 렌더돼요 — 헤더에서 다크 모드를 토글하면 둘이 동일하게 반응해요. React Native는 추가 react-native-web 연결(이 사이트에는 설정되지 않음) 없이는 브라우저에서 실행할 수 없어서, 사용법을 코드 샘플로 보여줘요.

React @ghds/react

Web Components @ghds/web-components

Bo Ram 10:00 Hey — are we still on for tomorrow? You 10:01 Yes! See you at 10. Bo Ram 10:02 Should I bring anything? You 10:03 Just the slides, I think. Bo Ram 10:04 Great, I'll print a few copies. You 10:05 Perfect. Coffee on me. Bo Ram 10:06 Deal. See you then! You 10:07 One more thing — which room? Bo Ram 10:08 The one on the third floor. You 10:09 Got it. Thanks!