WbwReal.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Tooltip } from "antd";
  2. import { Typography } from "antd";
  3. import Lookup from "../../dict/Lookup";
  4. import type { IWbw, TWbwDisplayMode } from "./WbwWord";
  5. const { Text } = Typography;
  6. interface IWidget {
  7. data: IWbw;
  8. display?: TWbwDisplayMode;
  9. }
  10. const WbwFactorsWidget = ({ data, display }: IWidget) => {
  11. if (
  12. typeof data.real?.value === "string" &&
  13. data.real.value.trim().length > 0
  14. ) {
  15. let wordReal: React.ReactNode = <></>;
  16. if (display === "block") {
  17. //block 模式下 限制宽度
  18. const shortString = data.real.value.slice(
  19. 0,
  20. data.word.value.length * 1.3 + 3
  21. );
  22. if (shortString === data.real.value) {
  23. wordReal = <span>{shortString}</span>;
  24. } else {
  25. wordReal = (
  26. <Tooltip title={data.real.value}>{`${shortString}…`}</Tooltip>
  27. );
  28. }
  29. } else {
  30. wordReal = (
  31. <>
  32. {data.real.value.split(" ").map((item, index) => (
  33. <Lookup search={item} key={index}>
  34. <Text type="secondary">{item} </Text>
  35. </Lookup>
  36. ))}
  37. </>
  38. );
  39. }
  40. return (
  41. <div className="wbw_word_item">
  42. <Text type="secondary">{wordReal}</Text>
  43. </div>
  44. );
  45. } else {
  46. //标点符号
  47. return <></>;
  48. }
  49. };
  50. export default WbwFactorsWidget;