import React from 'react'; import { useStaticQuery, graphql, Link } from 'gatsby'; import { Icon, Modal } from 'antd'; import GitHubButton from 'react-github-button'; import gh from 'parse-github-url'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import 'video-react/dist/video-react.css'; import { Player } from 'video-react'; import styles from './Banner.module.less'; import Notification, { NotificationProps } from './Notification'; type BannerButtonShape = 'round' | 'square'; interface BannerButton { text: string; link: string; style?: React.CSSProperties; type?: string; shape?: BannerButtonShape; } interface BannerProps { coverImage?: React.ReactNode; title: string; description: string; notifications?: NotificationProps[]; style?: React.CSSProperties; className?: string; video?: string; showGithubStars?: boolean; buttons?: BannerButton[]; onCloseVideo?: () => void; onPlayVideo?: () => void; } const backLeftBottom = 'https://gw.alipayobjects.com/zos/basement_prod/441d5eaf-e623-47cd-b9b9-2a581d9ce1e3.svg'; const Banner: React.FC = ({ coverImage, title, description, notifications, style = {}, className, video, showGithubStars = true, buttons = [], onCloseVideo, onPlayVideo, }) => { const { t } = useTranslation(); const query = graphql` query SiteBannerQuery { site { siteMetadata { githubUrl } } } `; const { site } = useStaticQuery(query); const { githubUrl } = site.siteMetadata; const notificationsNode = (notifications || []) .slice(0, 10) .map((notification, i) => ( )); const showVideo = () => { if (onPlayVideo) { onPlayVideo(); } Modal.info({ title: 'This is a notification message', className: styles.videoModal, onCancel: onCloseVideo, content: , width: '70%', }); }; const renderButtons = buttons.map((button: BannerButton, i) => { const ButtonLink = button.link.startsWith('http') || button.link.startsWith('#') ? 'a' : Link; const buttonProps = {} as any; if (button.link.startsWith('http')) { buttonProps.target = '_blank'; buttonProps.rel = 'noopener noreferrer'; } if (ButtonLink === 'a') { buttonProps.href = button.link; } else { buttonProps.to = button.link; } const { shape = 'round' } = button; return ( {button.text} ); }); if (video) { renderButtons.push(

{t('知源・致远')}

, ); } if (showGithubStars) { const githubObj = gh(githubUrl); if (githubObj && githubObj.owner && githubObj.name) { renderButtons.push(
, ); } } return (
{title}

{description}

{renderButtons}
{notificationsNode}
{coverImage}
back
); }; export default Banner;