Skip to content

Commit

Permalink
♻️ refactor: refactor dumi docs layout
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Jun 14, 2023
1 parent 755d714 commit 80fa42f
Show file tree
Hide file tree
Showing 39 changed files with 734 additions and 410 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Changelog
description: New updates and improvements to @lobehub/ui
nav:
title: Changelog
order: 999
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export const ApiHeader = memo<ApiTitleProps>(
</div>
)}
<Flexbox gap={mobile ? 16 : 24} style={{ marginTop: 16 }}>
<div style={{ display: 'flex' }}>
<Snippet spotlight>{importStr}</Snippet>
</div>
{componentName && (
<div style={{ display: 'flex' }}>
<Snippet spotlight>{importStr}</Snippet>
</div>
)}
<Divider dashed style={{ margin: '2px 0' }} />
<Flexbox distribution={'space-between'} gap={mobile ? 24 : 0} horizontal={!mobile}>
<Space split={<Divider type={'vertical'} />} wrap>
Expand Down
4 changes: 2 additions & 2 deletions packages/dumi-theme-lobehub/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const Footer = memo<FooterProps>(({ columns, bottom, theme }) => {
const { styles } = useStyles(isEmpty);

return (
<footer className={styles.container}>
<section className={styles.container}>
<RcFooter bottom={bottom} className={styles.footer} columns={columns} theme={theme} />
</footer>
</section>
);
});

Expand Down
10 changes: 6 additions & 4 deletions packages/dumi-theme-lobehub/src/components/Footer/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const useStyles = createStyles(({ css, responsive, token }, isEmpty: bool
}
&-column {
text-align: left;
h2 {
position: relative;
Expand Down Expand Up @@ -110,13 +112,14 @@ export const useStyles = createStyles(({ css, responsive, token }, isEmpty: bool
}
&-bottom {
color: ${token.colorTextDescription};
&-container {
width: 100%;
max-width: 1200px;
max-width: ${token.contentMaxWidth}px;
margin: 0 auto;
padding: 16px 0;
font-size: 16px;
line-height: 32px;
text-align: center;
}
Expand Down Expand Up @@ -144,8 +147,6 @@ export const useStyles = createStyles(({ css, responsive, token }, isEmpty: bool
${responsive.mobile} {
.${prefix} {
text-align: center;
&-container {
padding: 40px 0;
}
Expand All @@ -157,6 +158,7 @@ export const useStyles = createStyles(({ css, responsive, token }, isEmpty: bool
&-column {
display: block;
margin-bottom: 40px;
text-align: center;
&:last-child {
margin-bottom: 0;
Expand Down
97 changes: 97 additions & 0 deletions packages/dumi-theme-lobehub/src/components/Toc/TocMobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { ActionIcon } from '@lobehub/ui';
import { Anchor, AnchorProps, Collapse, ConfigProvider } from 'antd';
import { useTheme } from 'antd-style';
import { PanelTopClose, PanelTopOpen } from 'lucide-react';
import { memo, useMemo } from 'react';
import useControlledState from 'use-merge-value';

import { AnchorItem } from '@/types';

import { useStyles } from './style';

export interface TocMobileProps {
/**
* @title 当前激活的目录项 key 值
*/
activeKey?: string;
getContainer?: AnchorProps['getContainer'];
/**
* @title 目录项列表
*/
items: AnchorItem[];
/**
* @title 目录项切换的回调函数
* @param activeKey - 切换后的目录项 key 值
*/
onChange?: (activeKey: string) => void;
}
const TocMobile = memo<TocMobileProps>(({ items, activeKey, onChange, getContainer }) => {
const [activeLink, setActiveLink] = useControlledState<string>('', {
value: activeKey,
onChange,
});
const { styles } = useStyles();

const theme = useTheme();
const activeAnchor = items.find((item) => item.id === activeLink);

const linkItems = useMemo(
() =>
items.map((item) => ({
href: `#${item.id}`,
title: item.title,
key: item.id,
children: item.children?.map((child) => ({
href: `#${child.id}`,
title: child?.title,
key: child.id,
})),
})),
[items],
);

return (
<ConfigProvider theme={{ token: { fontSize: 12, sizeStep: 3 } }}>
<section className={styles.mobileCtn}>
<Collapse
bordered={false}
className={styles.expand}
expandIcon={({ isActive }) =>
isActive ? (
<ActionIcon
icon={PanelTopClose}
size={{ fontSize: 16, strokeWidth: 1, blockSize: 24, borderRadius: 3 }}
/>
) : (
<ActionIcon
icon={PanelTopOpen}
size={{ fontSize: 16, strokeWidth: 1, blockSize: 24, borderRadius: 3 }}
/>
)
}
expandIconPosition={'end'}
ghost
>
<Collapse.Panel
forceRender
header={!activeAnchor ? 'TOC' : activeAnchor.title}
key={'toc'}
>
<ConfigProvider theme={{ token: { fontSize: 14, sizeStep: 4 } }}>
<Anchor
getContainer={getContainer}
items={linkItems}
onChange={(currentLink) => {
setActiveLink(currentLink.replace('#', ''));
}}
targetOffset={theme.headerHeight + 48}
/>
</ConfigProvider>
</Collapse.Panel>
</Collapse>
</section>
</ConfigProvider>
);
});

export default TocMobile;
78 changes: 15 additions & 63 deletions packages/dumi-theme-lobehub/src/components/Toc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ActionIcon } from '@lobehub/ui';
import { Anchor, Collapse, ConfigProvider } from 'antd';
import { useResponsive, useTheme } from 'antd-style';
import { PanelTopClose, PanelTopOpen } from 'lucide-react';
import { Anchor, AnchorProps } from 'antd';
import { useTheme } from 'antd-style';
import { memo, useMemo } from 'react';
import useControlledState from 'use-merge-value';

import { AnchorItem } from '@/types';

import { useStyles } from './style';

export { default as TocMobile } from './TocMobile';

export interface TocProps {
/**
* @title 当前激活的目录项 key 值
*/
activeKey?: string;
getContainer?: AnchorProps['getContainer'];
/**
* @title 目录项列表
*/
Expand All @@ -24,16 +24,10 @@ export interface TocProps {
*/
onChange?: (activeKey: string) => void;
}
const Toc = memo<TocProps>(({ items, activeKey, onChange }) => {
const [activeLink, setActiveLink] = useControlledState<string>('', {
value: activeKey,
onChange,
});
const { styles } = useStyles();
const { mobile } = useResponsive();
const Toc = memo<TocProps>(({ items, getContainer }) => {
const { styles, cx } = useStyles();

const theme = useTheme();
const activeAnchor = items.find((item) => item.id === activeLink);

const linkItems = useMemo(
() =>
Expand All @@ -51,56 +45,14 @@ const Toc = memo<TocProps>(({ items, activeKey, onChange }) => {
);

return (
(items?.length === 0 ? null : mobile ? (
<ConfigProvider theme={{ token: { fontSize: 12, sizeStep: 3 } }}>
<nav className={styles.mobileCtn}>
<Collapse
bordered={false}
className={styles.expand}
expandIcon={({ isActive }) =>
isActive ? (
<ActionIcon
icon={PanelTopClose}
size={{ fontSize: 16, strokeWidth: 1, blockSize: 24, borderRadius: 3 }}
/>
) : (
<ActionIcon
icon={PanelTopOpen}
size={{ fontSize: 16, strokeWidth: 1, blockSize: 24, borderRadius: 3 }}
/>
)
}
expandIconPosition={'end'}
ghost
>
<Collapse.Panel
forceRender
header={!activeAnchor ? 'TOC' : activeAnchor.title}
key={'toc'}
>
<ConfigProvider theme={{ token: { fontSize: 14, sizeStep: 4 } }}>
<Anchor
items={linkItems}
onChange={(currentLink) => {
setActiveLink(currentLink.replace('#', ''));
}}
targetOffset={theme.headerHeight + 12}
/>
</ConfigProvider>
</Collapse.Panel>
</Collapse>
</nav>
</ConfigProvider>
) : (
<nav className={styles.container}>
<h4>Table of Contents</h4>
<Anchor
className={styles.anchor}
items={linkItems}
targetOffset={theme.headerHeight + 12}
/>
</nav>
)) || null
<section className={cx(styles.container, styles.anchor)}>
<h4>Table of Contents</h4>
<Anchor
getContainer={getContainer}
items={linkItems}
targetOffset={theme.headerHeight + 12}
/>
</section>
);
});

Expand Down
42 changes: 23 additions & 19 deletions packages/dumi-theme-lobehub/src/components/Toc/style.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { createStyles } from 'antd-style';
import { rgba } from 'polished';

export const useStyles = createStyles(({ token, stylish, prefixCls, responsive, cx, css }) => {
export const useStyles = createStyles(({ token, stylish, responsive, cx, css }) => {
const fixHeight = 36;

return {
container: css`
position: fixed;
z-index: 10;
position: sticky;
top: ${token.headerHeight + 64}px;
right: 0;
overflow: auto;
overscroll-behavior: contain;
grid-area: toc;
width: ${token.tocWidth}px;
max-height: 80vh;
margin-inline-end: 24px;
border-radius: 3px;
-webkit-overflow-scrolling: touch;
${responsive.mobile} {
z-index: 300;
top: ${token.headerHeight + 1}px;
position: relative;
left: 0;
width: 100%;
margin-top: 0;
}
Expand All @@ -38,10 +34,6 @@ export const useStyles = createStyles(({ token, stylish, prefixCls, responsive,
}
`,
mobileCtn: css`
position: fixed;
z-index: 200;
top: ${token.headerHeight}px;
width: 100%;
height: ${fixHeight}px;
Expand All @@ -52,22 +44,34 @@ export const useStyles = createStyles(({ token, stylish, prefixCls, responsive,
expand: cx(
stylish.blur,
css`
z-index: 201;
width: 100%;
background-color: ${rgba(token.colorBgLayout, 0.8)};
background-color: ${rgba(token.colorBgLayout, 0.5)};
border-bottom: 1px solid ${token.colorSplit};
border-radius: 0;
box-shadow: ${token.boxShadowSecondary};
.${prefixCls}-collapse-header {
.ant-collapse-content {
overflow: auto;
}
.ant-collapse-header {
z-index: 10;
padding: 8px 16px !important;
&[aria-expanded='true'] {
box-shadow: ${token.boxShadowSecondary};
}
}
`,
),
anchor: css`
${stylish.blur}
`,
anchor: cx(
stylish.blur,
css`
overflow-x: hidden;
overflow-y: auto;
max-height: 60vh !important;
`,
),
};
});
Loading

1 comment on commit 80fa42f

@vercel
Copy link

@vercel vercel bot commented on 80fa42f Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lobe-ui – ./

lobe-ui.vercel.app
lobe-ui-git-master-lobehub.vercel.app
ui.lobehub.com
lobe-ui-lobehub.vercel.app

Please sign in to comment.