Dictionary.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { useEffect, useState } from "react";
  2. import { useNavigate } from "react-router-dom";
  3. import { Layout, Affix, Col, Row } from "antd";
  4. import DictSearch from "./DictSearch";
  5. import SearchVocabulary from "./SearchVocabulary";
  6. const { Content } = Layout;
  7. interface IWidget {
  8. word?: string;
  9. compact?: boolean;
  10. onSearch?: Function;
  11. }
  12. const Widget = ({ word, compact = false, onSearch }: IWidget) => {
  13. const navigate = useNavigate();
  14. const [wordSearch, setWordSearch] = useState<string>();
  15. const [container, setContainer] = useState<HTMLDivElement | null>(null);
  16. useEffect(() => {
  17. setWordSearch(word?.toLowerCase());
  18. }, [word]);
  19. return (
  20. <div ref={setContainer}>
  21. <Affix offsetTop={0} target={compact ? () => container : undefined}>
  22. <div
  23. style={{
  24. backgroundColor: "rgba(100,100,100,0.3)",
  25. backdropFilter: "blur(5px)",
  26. }}
  27. >
  28. <Row style={{ paddingTop: "0.5em", paddingBottom: "0.5em" }}>
  29. {compact ? <></> : <Col flex="auto"></Col>}
  30. <Col flex="560px">
  31. <SearchVocabulary
  32. value={word}
  33. onSearch={(value: string, isFactor?: boolean) => {
  34. console.log("onSearch", value);
  35. const word = value.toLowerCase();
  36. setWordSearch(word);
  37. if (typeof onSearch !== "undefined") {
  38. onSearch(value, isFactor);
  39. }
  40. }}
  41. />
  42. </Col>
  43. {compact ? <></> : <Col flex="auto"></Col>}
  44. </Row>
  45. </div>
  46. </Affix>
  47. <Content style={{ minHeight: 700 }}>
  48. <Row>
  49. {compact ? <></> : <Col flex="auto"></Col>}
  50. <Col flex="1260px">
  51. <DictSearch word={wordSearch} compact={compact} />
  52. </Col>
  53. {compact ? <></> : <Col flex="auto"></Col>}
  54. </Row>
  55. </Content>
  56. </div>
  57. );
  58. };
  59. export default Widget;