previewHeader.tsx 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import * as React from "react";
  2. import { IconClose } from "@douyinfe/semi-icons";
  3. import { cssClasses } from "@douyinfe/semi-foundation/image/constants";
  4. import cls from "classnames";
  5. import { HeaderProps } from "./interface";
  6. import { PreviewContext } from "./previewContext";
  7. const prefixCls = `${cssClasses.PREFIX}-preview-header`;
  8. const Header: React.FC<HeaderProps> = ({ onClose, titleStyle, className, renderHeader }) => (
  9. <PreviewContext.Consumer>
  10. {({ currentIndex, titles }) => {
  11. let title;
  12. if (titles && typeof currentIndex === "number") {
  13. title = titles[currentIndex];
  14. }
  15. return (
  16. <section className={cls(prefixCls, className)}>
  17. <section className={`${prefixCls}-title`} style={titleStyle}>{renderHeader ? renderHeader(title) : title}</section>
  18. {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
  19. <section className={`${prefixCls}-close`} onMouseUp={onClose}>
  20. <IconClose />
  21. </section>
  22. </section>
  23. );
  24. }}
  25. </PreviewContext.Consumer>
  26. );
  27. export default Header;