docs: add site alert

This commit is contained in:
wwsun
2023-08-25 16:53:22 +08:00
parent c792a0785c
commit 55603e473a
2 changed files with 33 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import React, { useState } from 'react';
export interface AlertProps {
type?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info';
closeable?: boolean;
children: React.ReactNode;
}
export function Alert({ type = 'primary', closeable, children }: AlertProps) {
const [visible, setVisible] = useState(true);
if (!visible) {
return <div className="alert" role="alert" />;
}
return (
<div className={`alert alert--${type}`} role="alert">
{closeable && (
<button
aria-label="Close"
className="clean-btn close"
type="button"
onClick={() => setVisible(false)}
>
<span aria-hidden="true">&times;</span>
</button>
)}
{children}
</div>
);
}
+4
View File
@@ -6,12 +6,16 @@ import Layout from '@theme/Layout';
import HomepageFeatures from '@site/src/components/HomepageFeatures';
import styles from './index.module.css';
import { Alert } from '../components/alert';
function HomepageHeader() {
const { siteConfig } = useDocusaurusContext();
return (
<header className={clsx('hero', styles.heroBanner)}>
<div className="container">
<div className="margin-bottom--lg">
<Alert type="info">🏗 </Alert>
</div>
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div className={styles.buttons}>