DictList.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Affix, Anchor, Button, Col, Popover, Row } from "antd";
  2. import { UnorderedListOutlined } from "@ant-design/icons";
  3. const { Link } = Anchor;
  4. export interface IAnchorData {
  5. href: string;
  6. title: string;
  7. children?: IAnchorData[];
  8. }
  9. interface IWidgetDictList {
  10. data: IAnchorData[];
  11. }
  12. const DictListWidget = (prop: IWidgetDictList) => {
  13. const GetLink = (anchors: IAnchorData[]) => {
  14. return anchors.map((it, id) => {
  15. return (
  16. <Link key={id} href={it.href} title={it.title}>
  17. {it.children ? GetLink(it.children) : ""}
  18. </Link>
  19. );
  20. });
  21. };
  22. const dictNav = <Anchor offsetTop={50}>{GetLink(prop.data)}</Anchor>;
  23. return (
  24. <Row>
  25. <Col xs={0} sm={24}>
  26. {dictNav}
  27. </Col>
  28. <Col xs={24} sm={0}>
  29. <Affix offsetTop={50}>
  30. <Popover
  31. placement="bottomRight"
  32. arrowPointAtCenter
  33. content={dictNav}
  34. trigger="click"
  35. >
  36. <Button
  37. type="primary"
  38. shape="circle"
  39. icon={<UnorderedListOutlined />}
  40. />
  41. </Popover>
  42. </Affix>
  43. </Col>
  44. </Row>
  45. );
  46. };
  47. export default DictListWidget;