1
0

hint.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from "react";
  2. import { IconArrowRight } from "@douyinfe/semi-icons";
  3. import cls from 'classnames';
  4. import { cssClasses } from '@douyinfe/semi-foundation/chat/constants';
  5. const { PREFIX_HINT } = cssClasses;
  6. interface HintProps {
  7. className?: string;
  8. style?: React.CSSProperties;
  9. value?: string[];
  10. onHintClick?: (item: string) => void;
  11. renderHintBox?: (props: {content: string; index: number; onHintClick: () => void}) => React.ReactNode
  12. }
  13. const Hint = React.memo((props: HintProps) => {
  14. const { value, onHintClick, renderHintBox, className, style } = props;
  15. return (
  16. <section
  17. className={cls(`${PREFIX_HINT}s`, {
  18. [className]: !!className,
  19. })}
  20. style={style}
  21. >
  22. {value.map((item, index) => {
  23. if (renderHintBox) {
  24. return renderHintBox({
  25. content: item,
  26. index: index,
  27. onHintClick: () => {
  28. onHintClick?.(item);
  29. }
  30. });
  31. }
  32. return (
  33. <div
  34. className={`${PREFIX_HINT}-item`}
  35. key={index}
  36. onClick={() => {
  37. onHintClick?.(item);
  38. }}
  39. >
  40. <div className={`${PREFIX_HINT}-content`}>
  41. {item}
  42. </div>
  43. <IconArrowRight className={`${PREFIX_HINT}-icon`}/>
  44. </div>
  45. );
  46. })}
  47. </section>
  48. );
  49. });
  50. export default Hint;