(props: ThreadProps<T>)
| 282 | * A Thread shows a conversation within a Chat. |
| 283 | */ |
| 284 | export function Thread<T extends object>(props: ThreadProps<T>) { |
| 285 | let { |
| 286 | items, |
| 287 | children, |
| 288 | styles, |
| 289 | scrollEndThreshold = 100, |
| 290 | 'aria-label': ariaLabel, |
| 291 | 'aria-labelledby': ariaLabelledby |
| 292 | } = props; |
| 293 | |
| 294 | let {setIsNearBottom, setScrollElement, promptFieldSize} = useContext(InternalChatContext); |
| 295 | let isNearBottomRef = useRef(true); |
| 296 | let gridListRef = useRef<HTMLDivElement | null>(null); |
| 297 | let callbackRef = useCallback( |
| 298 | (el: HTMLDivElement | null) => { |
| 299 | gridListRef.current = el; |
| 300 | setScrollElement(el); |
| 301 | }, |
| 302 | [setScrollElement] |
| 303 | ); |
| 304 | |
| 305 | let handleScroll = useCallback(() => { |
| 306 | let el = gridListRef.current; |
| 307 | if (!el) { |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | let nearBottom = el.scrollTop >= el.scrollHeight - el.clientHeight - scrollEndThreshold; |
| 312 | isNearBottomRef.current = nearBottom; |
| 313 | setIsNearBottom(nearBottom); |
| 314 | }, [setIsNearBottom, scrollEndThreshold]); |
| 315 | |
| 316 | return ( |
| 317 | <div |
| 318 | className={mergeStyles( |
| 319 | style({ |
| 320 | position: 'relative', |
| 321 | flexGrow: 1, |
| 322 | overflow: 'hidden', |
| 323 | display: 'flex', |
| 324 | flexDirection: 'column', |
| 325 | minWidth: 0 |
| 326 | }), |
| 327 | styles |
| 328 | )}> |
| 329 | <div |
| 330 | className={style({ |
| 331 | position: 'absolute', |
| 332 | bottom: 16, |
| 333 | left: '50%', |
| 334 | transform: 'translateX(-50%)', |
| 335 | zIndex: 1 |
| 336 | })}> |
| 337 | <ThreadScrollButton> |
| 338 | <ActionButton slot="scroll"> |
| 339 | <ChevronDown /> |
| 340 | </ActionButton> |
| 341 | </ThreadScrollButton> |
nothing calls this directly
no test coverage detected