탐색

v2.1.0
본문

메시지

대화의 한 차례를 작성자를 가리키는 말풍선으로 표시합니다.

이 페이지의 내용

메시지는 대화의 한 차례에 해당합니다. 받은 메시지는 행의 시작에 살짝 떠 있는 표면으로 표시하고, 보낸 메시지는 기본 버튼과 같은 잉크 색으로 행의 끝에 표시합니다. 말풍선의 모서리는 표면과 같은 모양이며, 작성자를 가리키는 모서리만 둥글기가 작습니다. 어느 댓글에나 답글을 달 수 있는 토론에는 스레드를 사용합니다.

메시지

<ol class="max-w(440) mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">Did the build for the docs site finish?</div>  </li>  <li class="message message-sent">    <div class="message-bubble">Yes, a minute ago. 71 pages, no warnings.</div>  </li>  <li class="message message-sent">    <div class="message-bubble">      I also moved the previews to static pages, so the next build takes about forty seconds on a cold cache.    </div>    <span class="message-meta">Delivered · 14:02</span>  </li>  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">Perfect. Ship it.</div>    <span class="message-meta">Ada · 14:03</span>  </li></ol>
<ol className="max-w(440) mx-auto m(0) p(0)">  <li className="message">    <span className="avatar avatar-sm message-avatar">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="Ada" />    </span>    <div className="message-bubble">Did the build for the docs site finish?</div>  </li>  <li className="message message-sent">    <div className="message-bubble">Yes, a minute ago. 71 pages, no warnings.</div>  </li>  <li className="message message-sent">    <div className="message-bubble">      I also moved the previews to static pages, so the next build takes about forty seconds on a cold cache.    </div>    <span className="message-meta">Delivered · 14:02</span>  </li>  <li className="message">    <span className="avatar avatar-sm message-avatar">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="Ada" />    </span>    <div className="message-bubble">Perfect. Ship it.</div>    <span className="message-meta">Ada · 14:03</span>  </li></ol>
<ol class="max-w(440) mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">Did the build for the docs site finish?</div>  </li>  <li class="message message-sent">    <div class="message-bubble">Yes, a minute ago. 71 pages, no warnings.</div>  </li>  <li class="message message-sent">    <div class="message-bubble">      I also moved the previews to static pages, so the next build takes about forty seconds on a cold cache.    </div>    <span class="message-meta">Delivered · 14:02</span>  </li>  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">Perfect. Ship it.</div>    <span class="message-meta">Ada · 14:03</span>  </li></ol>
<template>  <ol class="max-w(440) mx-auto m(0) p(0)">    <li class="message">      <span class="avatar avatar-sm message-avatar">        <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">      </span>      <div class="message-bubble">Did the build for the docs site finish?</div>    </li>    <li class="message message-sent">      <div class="message-bubble">Yes, a minute ago. 71 pages, no warnings.</div>    </li>    <li class="message message-sent">      <div class="message-bubble">        I also moved the previews to static pages, so the next build takes about forty seconds on a cold cache.      </div>      <span class="message-meta">Delivered · 14:02</span>    </li>    <li class="message">      <span class="avatar avatar-sm message-avatar">        <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">      </span>      <div class="message-bubble">Perfect. Ship it.</div>      <span class="message-meta">Ada · 14:03</span>    </li>  </ol></template>

대화에는 일반 목록 요소를 사용할 수 있습니다. 메시지 순서 자체가 내용의 일부이므로 <ol>을 사용하고, m(0) p(0)으로 목록의 마진과 패딩을 제거합니다. 메시지 간격은 각 메시지에 지정되어 있습니다. 앞 메시지와는 12px 간격을 두되, 두 메시지가 같은 쪽에 있으면 4px로 줄여 작성자가 바뀌는 지점이 드러나게 합니다. 좁은 대화 목록에서는 말풍선이 너비의 대부분을 차지하고, 넓은 목록에서는 읽기 편한 너비를 넘지 않습니다.

#아바타 없는 메시지

두 사람의 대화에서는 말풍선이 놓인 쪽만으로도 누가 말하는지 알 수 있습니다. 아바타를 생략하면 말풍선이 행의 시작에 놓입니다.

아바타 없는 메시지

<ol class="max-w(360) mx-auto m(0) p(0)">  <li class="message">    <div class="message-bubble">Are we still on for Thursday?</div>  </li>  <li class="message">    <div class="message-bubble">I can do any time after two.</div>    <span class="message-meta">09:41</span>  </li>  <li class="message message-sent">    <div class="message-bubble">Thursday at three.</div>    <span class="message-meta">Read · 09:44</span>  </li></ol>
<ol className="max-w(360) mx-auto m(0) p(0)">  <li className="message">    <div className="message-bubble">Are we still on for Thursday?</div>  </li>  <li className="message">    <div className="message-bubble">I can do any time after two.</div>    <span className="message-meta">09:41</span>  </li>  <li className="message message-sent">    <div className="message-bubble">Thursday at three.</div>    <span className="message-meta">Read · 09:44</span>  </li></ol>
<ol class="max-w(360) mx-auto m(0) p(0)">  <li class="message">    <div class="message-bubble">Are we still on for Thursday?</div>  </li>  <li class="message">    <div class="message-bubble">I can do any time after two.</div>    <span class="message-meta">09:41</span>  </li>  <li class="message message-sent">    <div class="message-bubble">Thursday at three.</div>    <span class="message-meta">Read · 09:44</span>  </li></ol>
<template>  <ol class="max-w(360) mx-auto m(0) p(0)">    <li class="message">      <div class="message-bubble">Are we still on for Thursday?</div>    </li>    <li class="message">      <div class="message-bubble">I can do any time after two.</div>      <span class="message-meta">09:41</span>    </li>    <li class="message message-sent">      <div class="message-bubble">Thursday at three.</div>      <span class="message-meta">Read · 09:44</span>    </li>  </ol></template>

#입력 중 표시

message-typing은 말풍선 안에서 점 세 개가 차례로 위로 움직이는 표시입니다. 보조 기술은 점만으로 의미를 알 수 없으므로, 말풍선에 role="status"를 지정하고 시각적으로 숨긴 span에 “Ada 님이 입력 중입니다”와 같은 문구를 넣습니다. 상태 영역은 aria-label이 아니라 그 안의 텍스트를 읽어 주므로 문구는 영역 안에 둡니다.

입력 중 표시

<ol class="max-w(360) mx-auto m(0) p(0)">  <li class="message message-sent">    <div class="message-bubble">Can you send the notes from the review?</div>  </li>  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble" role="status">      <span class="message-typing"></span><span class="sr-only">Ada is typing</span>    </div>  </li></ol>
<ol className="max-w(360) mx-auto m(0) p(0)">  <li className="message message-sent">    <div className="message-bubble">Can you send the notes from the review?</div>  </li>  <li className="message">    <span className="avatar avatar-sm message-avatar">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="Ada" />    </span>    <div className="message-bubble" role="status">      <span className="message-typing"></span><span className="sr-only">Ada is typing</span>    </div>  </li></ol>
<ol class="max-w(360) mx-auto m(0) p(0)">  <li class="message message-sent">    <div class="message-bubble">Can you send the notes from the review?</div>  </li>  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble" role="status">      <span class="message-typing"></span><span class="sr-only">Ada is typing</span>    </div>  </li></ol>
<template>  <ol class="max-w(360) mx-auto m(0) p(0)">    <li class="message message-sent">      <div class="message-bubble">Can you send the notes from the review?</div>    </li>    <li class="message">      <span class="avatar avatar-sm message-avatar">        <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">      </span>      <div class="message-bubble" role="status">        <span class="message-typing"></span><span class="sr-only">Ada is typing</span>      </div>    </li>  </ol></template>

#접근성

  • 대화 목록에는 <ol>을 사용합니다. 새 메시지를 aria-live="polite" 영역에 넣거나 목록 자체에 role="log"를 지정합니다. 그러면 포커스를 옮기지 않고도 새 메시지를 알릴 수 있습니다.
  • 어시스턴트의 답변처럼 도착하면서 작성되는 답변에는 스트리밍하는 동안 aria-busy="true"를 지정합니다. 그러면 라이브 영역이 단어마다 알리지 않고 답변이 완성된 뒤 한 번만 알립니다. 답변이 완료되거나 중지되거나 실패하면 속성을 제거하고, 셋 중 어떤 상태인지 해당 메시지에 밝힙니다.
  • 색상과 배치 방향 외에도 스크린 리더가 작성자를 식별할 수 있도록 각 메시지에 작성자 이름을 넣습니다. message-meta에 이름을 표시하거나 메시지 앞에 화면에서만 숨긴 텍스트로 추가합니다.
  • 메시지에 작성자 이름이 없으면 아바타의 alt에 작성자 이름을 넣습니다. 메시지에 이름이 있으면 해당 값은 비워 둡니다.
  • 동작 줄이기가 활성화되면 입력 중 표시의 점이 움직이지 않습니다. 보낸 말풍선에는 moonstone에서 잉크 색을, obsidian에서 진주색을 사용합니다. 두 테마 모두 텍스트 대비를 온전히 유지합니다.

#클래스

클래스설명
message받은 메시지는 행의 시작 쪽에 배치합니다. 이전 메시지와의 간격은 12px이며, 두 메시지가 같은 쪽에 있으면 4px입니다.
message-sent내가 보낸 메시지는 행의 배치를 반대로 바꾸고 말풍선을 전경색으로 채웁니다.적용할 클래스는 message입니다
message-avatar작성자 아바타를 말풍선 하단에 맞춥니다. 아바타 요소 자체에 적용하며 생략할 수 있습니다.
message-bubble메시지 본문을 담는 말풍선입니다. 작성자 쪽 모서리의 반경을 작게 둡니다.
message-meta말풍선 아래에 표시하는 이름, 시각 또는 수신 확인 표시입니다.
message-typing점 3개가 말풍선 안에서 차례로 위로 움직입니다. 말풍선에는 role="status"를 지정하고, "Ada 님이 입력 중입니다" 같은 문구는 시각적으로 숨긴 span에 적습니다.

#사용자 지정 속성

속성기본값설명
--message-radius1.125rem말풍선 모서리
--message-tail.375rem작성자를 가리키는 모서리

#소스

@master/ui/components/message.css
/* * Message: one turn of a conversation. * A received message is a raised sheet at the start of the row; a sent one is ink at the end, the way a * primary button is ink. A bubble's corners are those of a surface, except the one that points at its * author, which is tight. A bubble takes most of a narrow thread and no more than a comfortable measure of * a wide one. The thread itself is any list: turns keep their own distance from each other. */@layer components.ui {  .message {    --message-radius: 1.125rem;    --message-tail: .375rem;    display: grid;    grid-template-columns: auto minmax(0, 1fr);    align-items: end;    justify-items: start;    gap: .25rem .5rem;    min-width: 0;    /* Sent: the row mirrors, and the bubble is ink. */    &.message-sent {      grid-template-columns: minmax(0, 1fr) auto;      justify-items: end;      .message-bubble {        --surface-color: var(--color-surface-inverse);        @apply --on-ink;        border-end-start-radius: calc(var(--message-radius) * var(--corner-scale));        border-end-end-radius: calc(var(--message-tail) * var(--corner-scale));        @apply --surface-ink;        color: var(--color-text-inverse);        box-shadow:          inset 0 .5px 0 var(--color-ink-highlight),          0 0 0 .5px var(--color-ink-edge),          0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);      }      .message-meta {        text-align: end;      }    }    /*     * The rhythm of a thread belongs to its turns, so any list or column can hold them: a turn stands     * 12px from the one before it, and 4px when both come from the same side.     */    & + & {      margin-block-start: .75rem;    }    &:not(.message-sent) + &:not(.message-sent), &.message-sent + &.message-sent {      margin-block-start: .25rem;    }  }  /* The author's avatar, level with the foot of the bubble. Leave it out and the bubble starts the row. */  .message-avatar {    grid-row: 1;    align-self: end;  }  /* 28px by default, set on the avatar itself, which would otherwise reset it to its own size. A size class on it still wins. */  .message .message-avatar {    --avatar-size: 1.75rem;  }  .message-bubble {    --surface-color: var(--color-surface-raised);    grid-column: 2;    grid-row: 1;    min-width: 0;    max-width: min(34rem, 86%);    margin: 0;    padding: .5rem .75rem;    border-radius: calc(var(--message-radius) * var(--corner-scale));    border-end-start-radius: calc(var(--message-tail) * var(--corner-scale));    corner-shape: var(--corner-shape);    @apply --surface-sheet;    color: var(--color-text-strong);    box-shadow: var(--shadow-raised);    font-size: .875rem;    line-height: 1.5;    overflow-wrap: anywhere;    text-wrap: pretty;  }  .message-sent .message-bubble {    grid-column: 1;  }  /* Without an avatar the bubble takes the first column of a received row. */  .message:not(.message-sent, :has(.message-avatar)) .message-bubble {    grid-column: 1 / -1;  }  .message:not(.message-sent, :has(.message-avatar)) .message-meta {    grid-column: 1 / -1;  }  /* A sent turn with no avatar has no second column to keep: it ends on the thread's edge, as a received one starts on it. */  .message-sent:not(:has(.message-avatar)) .message-bubble, .message-sent:not(:has(.message-avatar)) .message-meta {    grid-column: 1 / -1;  }  /* Under the bubble: a name, a time, a receipt. */  .message-meta {    grid-column: 2;    margin: 0;    padding-inline: .25rem;    color: var(--color-text-muted);    font-size: .6875rem;    line-height: 1.4;    font-variant-numeric: tabular-nums;  }  .message-sent .message-meta {    grid-column: 1;  }  /*   * Typing: three dots that rise in turn, inside a bubble. Say it for assistive technology in words inside the   * bubble ("Mira is typing"), which a status region reads out where it would not read a label. Without motion   * the dots rest.   */  .message-typing {    display: block;    width: 1.75rem;    height: 1.3125rem;    background:      radial-gradient(circle closest-side, currentColor calc(100% - .5px), transparent) 0 50% / 6px 6px no-repeat,      radial-gradient(circle closest-side, currentColor calc(100% - .5px), transparent) 50% 50% / 6px 6px no-repeat,      radial-gradient(circle closest-side, currentColor calc(100% - .5px), transparent) 100% 50% / 6px 6px no-repeat;    opacity: .5;    animation: message-typing 1.2s var(--easing-glide) infinite;    @media (prefers-reduced-motion: reduce) {      animation: none;    }    /* Forced colors drop a gradient: the dots keep theirs, in the text color. */    @media (forced-colors: active) {      forced-color-adjust: none;      color: CanvasText;    }  }  @media (forced-colors: active) {    .message-bubble {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }}@keyframes message-typing {  0%, 60%, 100% {    background-position: 0 50%, 50% 50%, 100% 50%;  }  15% {    background-position: 0 22%, 50% 50%, 100% 50%;  }  30% {    background-position: 0 50%, 50% 22%, 100% 50%;  }  45% {    background-position: 0 50%, 50% 50%, 100% 22%;  }}