• 简体中文
  • ActivityLine

    单行文字,切换时交叉淡入淡出。

    正在搜索网页
    import { useEffect, useState } from 'react';
    import { ActivityLine } from '@aora-bot/react';
    
    const lines = ['正在搜索网页', '正在阅读结果', '正在写摘要', '完成'];
    
    export default function Demo() {
      const [i, setI] = useState(0);
      useEffect(() => {
        const id = setInterval(() => setI((n) => (n + 1) % lines.length), 1600);
        return () => clearInterval(id);
      }, []);
    
      return (
        <div className="site-demo site-demo--center">
          <ActivityLine text={lines[i]} />
        </div>
      );
    }

    为什么不直接换文字

    过渡期间,淡出和淡入的两行文字都在 DOM 中,叠放在同一个网格单元里。因此在整个淡入淡出过程中,整行的高度始终等于两者中较高的一行,宽度则按内容所需。

    如果直接替换文字,活动行会因为字数变化而每隔几秒抖动一下。单行时不太明显,多行同时变化时就很显眼。

    API

    属性类型默认值说明
    text*string—Current line. Changing it slides the old line out and the new one in.
    classNamestring——
    durationMsnumber220Transition duration in milliseconds.
    styleCSSProperties—Merged over the duration custom property the transition reads.

    接下来