TermShow.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { useEffect, useState } from "react";
  2. import { Layout, Affix, Col, Row } from "antd";
  3. import SearchVocabulary from "../dict/SearchVocabulary";
  4. import TermSearch from "./TermSearch";
  5. const { Content } = Layout;
  6. interface IWidget {
  7. word?: string;
  8. wordId?: string;
  9. compact?: boolean;
  10. hideInput?: boolean;
  11. onSearch?: Function;
  12. onIdChange?: Function;
  13. }
  14. const TermShowWidget = ({
  15. word,
  16. wordId,
  17. compact = false,
  18. hideInput = false,
  19. onSearch,
  20. onIdChange,
  21. }: IWidget) => {
  22. const [_split, setSplit] = useState<string>();
  23. const [wordSearch, setWordSearch] = useState<string>();
  24. const [container, setContainer] = useState<HTMLDivElement | null>(null);
  25. useEffect(() => {
  26. setWordSearch(word?.toLowerCase());
  27. }, [word]);
  28. const dictSearch = (value: string, isFactor?: boolean) => {
  29. console.log("onSearch", value);
  30. const word = value.toLowerCase();
  31. setWordSearch(word);
  32. if (typeof onSearch !== "undefined") {
  33. onSearch(value, isFactor);
  34. }
  35. };
  36. return (
  37. <div ref={setContainer}>
  38. {hideInput ? (
  39. <></>
  40. ) : (
  41. <Affix offsetTop={0} target={compact ? () => container : undefined}>
  42. <div
  43. style={{
  44. backgroundColor: "rgba(100,100,100,0.3)",
  45. backdropFilter: "blur(5px)",
  46. }}
  47. >
  48. <Row style={{ paddingTop: "0.5em", paddingBottom: "0.5em" }}>
  49. {compact ? <></> : <Col flex="auto"></Col>}
  50. <Col flex="560px">
  51. <SearchVocabulary
  52. value={word}
  53. onSearch={dictSearch}
  54. onSplit={(word: string | undefined) => {
  55. console.log("onSplit", word);
  56. setSplit(word);
  57. }}
  58. />
  59. </Col>
  60. {compact ? <></> : <Col flex="auto"></Col>}
  61. </Row>
  62. </div>
  63. </Affix>
  64. )}
  65. <Content style={{ minHeight: 700 }}>
  66. <Row>
  67. {compact ? <></> : <Col flex="auto"></Col>}
  68. <Col flex="1260px">
  69. <TermSearch
  70. word={wordSearch}
  71. wordId={wordId}
  72. compact={compact}
  73. onIdChange={(value: string) => {
  74. console.debug("term onIdChange", value);
  75. if (typeof onIdChange !== "undefined") {
  76. onIdChange(value);
  77. }
  78. }}
  79. />
  80. </Col>
  81. {compact ? <></> : <Col flex="auto"></Col>}
  82. </Row>
  83. </Content>
  84. </div>
  85. );
  86. };
  87. export default TermShowWidget;