generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
218 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,96 @@ | ||
import { EditOutlined, GithubFilled } from '@ant-design/icons'; | ||
import { Typography } from 'antd'; | ||
import { Divider, Space, Typography } from 'antd'; | ||
import { useResponsive } from 'antd-style'; | ||
import { FC, memo } from 'react'; | ||
import { FC, memo, ReactNode } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import Code from '../CodeSnippet'; | ||
import NpmFilled from './NpmFilled'; | ||
|
||
import { useSiteStore } from '../../store/useSiteStore'; | ||
import { Label, useStyles } from './style'; | ||
|
||
interface ApiTitleProps { | ||
title: string; | ||
componentName: string; | ||
description?: string; | ||
pkg: string; | ||
sourceUrl?: string; | ||
docsUrl?: string; | ||
} | ||
|
||
export const ApiHeader: FC<ApiTitleProps> = memo(({ title, description }) => { | ||
const { styles } = useStyles(); | ||
const { mobile } = useResponsive(); | ||
interface Item { | ||
label: string; | ||
icon: ReactNode; | ||
children: string; | ||
url: string; | ||
} | ||
|
||
const REPO_BASE = useSiteStore((s) => s.siteData.themeConfig.repoUrl); | ||
export const ApiHeader: FC<ApiTitleProps> = memo( | ||
({ title, componentName, description, pkg, sourceUrl, docsUrl }) => { | ||
const { styles } = useStyles(); | ||
const { mobile } = useResponsive(); | ||
|
||
const items = [ | ||
{ | ||
label: '源码', | ||
icon: <GithubFilled />, | ||
children: '查看源码', | ||
url: `${REPO_BASE}/tree/master/src/${title}`, | ||
}, | ||
{ | ||
label: '文档', | ||
icon: <EditOutlined />, | ||
children: '编辑文档', | ||
url: `${REPO_BASE}/tree/master/docs/api/${title}`, | ||
}, | ||
{ | ||
label: '产物', | ||
icon: <NpmFilled />, | ||
children: 'antd-style', | ||
url: 'https://www.npmjs.com/package/antd-style?activeTab=explore', | ||
}, | ||
]; | ||
const items = [ | ||
sourceUrl && { | ||
label: '源码', | ||
icon: <GithubFilled />, | ||
children: '查看源码', | ||
url: sourceUrl, | ||
}, | ||
docsUrl && { | ||
label: '文档', | ||
icon: <EditOutlined />, | ||
children: '编辑文档', | ||
url: docsUrl, | ||
}, | ||
{ | ||
label: '产物', | ||
icon: <NpmFilled />, | ||
children: pkg, | ||
url: `https://www.npmjs.com/package/${pkg}?activeTab=explore`, | ||
}, | ||
].filter((i) => i) as Item[]; | ||
|
||
return ( | ||
<Flexbox> | ||
<Typography.Title className={styles.title}>{title}</Typography.Title> | ||
{description && ( | ||
<div> | ||
<Typography.Text type={'secondary'} className={styles.desc}> | ||
{description} | ||
</Typography.Text> | ||
</div> | ||
)} | ||
<Flexbox style={{ marginTop: 24 }} gap={mobile ? 16 : 12}> | ||
<Flexbox horizontal={!mobile} gap={mobile ? 12 : 0}> | ||
<Label type={'secondary'}>引入方法</Label> | ||
<Code>{`import { ${title} } from "antd-style";`}</Code> | ||
</Flexbox> | ||
{items.map((item) => ( | ||
<Flexbox horizontal key={item.label}> | ||
<Label type={'secondary'}>{item.label}</Label> | ||
{ | ||
<a href={item.url} target={'_blank'} rel="noreferrer"> | ||
<Flexbox horizontal align={'center'} gap={8} className={styles.text}> | ||
<>{item.icon}</> | ||
<>{item.children}</> | ||
</Flexbox> | ||
</a> | ||
} | ||
return ( | ||
<Flexbox> | ||
<Typography.Title className={styles.title}>{title}</Typography.Title> | ||
{description && ( | ||
<div> | ||
<Typography.Text type={'secondary'} className={styles.desc}> | ||
{description} | ||
</Typography.Text> | ||
</div> | ||
)} | ||
<Flexbox style={{ marginTop: 24 }} gap={mobile ? 16 : 24}> | ||
<Flexbox horizontal={!mobile} gap={mobile ? 12 : 0}> | ||
<Label type={'secondary'} style={{ display: 'flex', alignItems: 'center' }}> | ||
引入方法 | ||
</Label> | ||
<Code>{`import { ${componentName} } from "${pkg}";`}</Code> | ||
</Flexbox> | ||
))} | ||
<Divider dashed style={{ margin: '2px 0' }} /> | ||
<Space | ||
direction={mobile ? 'vertical' : 'horizontal'} | ||
split={mobile ? undefined : <Divider type={'vertical'} />} | ||
size={24} | ||
className={styles.meta} | ||
> | ||
{items.map((item) => ( | ||
<Space size={24} key={item.label}> | ||
<Label type={'secondary'}>{item.label}</Label> | ||
{ | ||
<a href={item.url} target={'_blank'} rel="noreferrer"> | ||
<Flexbox horizontal align={'center'} gap={8} className={styles.text}> | ||
<>{item.icon}</> | ||
<>{item.children}</> | ||
</Flexbox> | ||
</a> | ||
} | ||
</Space> | ||
))} | ||
</Space> | ||
</Flexbox> | ||
</Flexbox> | ||
</Flexbox> | ||
); | ||
}); | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export { default as DumiSiteProvider } from './components/DumiSiteProvider'; | ||
export { default as Features } from './components/Features'; | ||
export { default as Footer } from './components/Footer'; | ||
export { default as Hero } from './components/Hero'; | ||
export { Highlighter } from './components/Highlighter'; | ||
export { default as DumiSiteProvider } from './components/SiteProvider'; | ||
export { default as Toc } from './components/Toc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.