Skip to content

Commit 1359942

Browse files
✨ feat(apiheader): add configuration for component API header
This commit introduces a new configuration option to the `dumi` config file for the component API header. The added configuration allows matching routes, defining source and documentation URLs, and specifying the package name. Additionally, the commit also updates the `ApiHeader` component to use customized icons from the `lobehub/ui` library instead of `ant-design/icons`.
1 parent 144c125 commit 1359942

File tree

12 files changed

+63
-49
lines changed

12 files changed

+63
-49
lines changed

.dumirc.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineConfig } from 'dumi';
2-
import { homepage } from './package.json';
2+
import { homepage, name } from './package.json';
33

44
const isProd = process.env.NODE_ENV === 'production';
55
const isWin = process.platform === 'win32';
@@ -12,6 +12,15 @@ const themeConfig = {
1212
socialLinks: {
1313
github: homepage,
1414
},
15+
apiHeader: {
16+
// 组件库包名,可以从 package.json 中引入名称
17+
pkg: name,
18+
// 匹配路由,默认为 /api 或 /components
19+
match: ['/components'],
20+
// github 会匹配 themeConfig.github 字段
21+
sourceUrl: `{github}/tree/master/src/{atomId}/index.tsx`,
22+
docUrl: `{github}/tree/master/src/{atomId}/index.md`,
23+
},
1524
};
1625

1726
export default defineConfig({
@@ -37,7 +46,7 @@ export default defineConfig({
3746
: {
3847
exclude: ['@dqbd/tiktoken'],
3948
},
40-
chainWebpack(config) {
49+
chainWebpack(config: any) {
4150
config.set('experiments', {
4251
...config.get('experiments'),
4352
asyncWebAssembly: true,

packages/dumi-theme-lobehub/src/components/ApiHeader/index.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { EditOutlined, GithubFilled } from '@ant-design/icons';
1+
import { ApiHeaderProps } from '@/index';
2+
import { Icon, Snippet } from '@lobehub/ui';
23
import { Divider, Space, Typography } from 'antd';
34
import { useResponsive } from 'antd-style';
5+
import { Edit3, Github } from 'lucide-react';
46
import { FC, ReactNode, memo } from 'react';
57
import { Flexbox } from 'react-layout-kit';
6-
7-
import { Snippet } from '@lobehub/ui';
8-
9-
import { ApiHeaderProps } from '@/index';
108
import { useStyles } from './style';
119

1210
/**
@@ -63,13 +61,13 @@ export const ApiHeader: FC<ApiTitleProps> = memo(
6361

6462
const items = [
6563
sourceUrl && {
66-
icon: <GithubFilled />,
67-
children: '查看源码',
64+
icon: <Icon icon={Github} size={{ fontSize: 15 }} />,
65+
children: 'Source',
6866
url: sourceUrl,
6967
},
7068
docUrl && {
71-
icon: <EditOutlined />,
72-
children: '编辑文档',
69+
icon: <Icon icon={Edit3} size={{ fontSize: 15 }} />,
70+
children: 'Edit',
7371
url: docUrl,
7472
},
7573
].filter((i) => i) as ServiceItem[];

packages/dumi-theme-lobehub/src/slots/ContentFooter/Linker.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { ArrowLeftOutlined, ArrowRightOutlined } from '@ant-design/icons';
1+
import { Icon } from '@lobehub/ui';
22
import { Link } from 'dumi';
3+
import { ArrowLeft, ArrowRight } from 'lucide-react';
34
import type { FC } from 'react';
4-
55
import { memo, useMemo } from 'react';
6-
76
import { Flexbox } from 'react-layout-kit';
87
import { useStyles } from './Linker.style';
98

@@ -20,13 +19,15 @@ const Linker: FC<LinkerProps> = ({ title, link, type }) => {
2019
case 'prev':
2120
return (
2221
<>
23-
<ArrowLeftOutlined /> Previous
22+
<Icon icon={ArrowLeft} size={{ fontSize: 14 }} />
23+
<span style={{ lineHeight: '14px' }}>Previous</span>
2424
</>
2525
);
2626
case 'next':
2727
return (
2828
<>
29-
Next <ArrowRightOutlined />
29+
<span style={{ lineHeight: '14px' }}>Next</span>
30+
<Icon icon={ArrowRight} size={{ fontSize: 14 }} />
3031
</>
3132
);
3233
}

packages/dumi-theme-lobehub/src/slots/Sidebar/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const Sidebar: FC = () => {
2323
placement="left"
2424
className={styles.sidebar}
2525
expand={expand}
26-
classNames={{ content: styles.sidebarContent }}
2726
onExpandChange={setExpand}
2827
>
2928
<div className={styles.sidebarInner}>

packages/dumi-theme-lobehub/src/slots/Sidebar/style.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,47 @@ export const useStyles = createStyles(({ css, token }) => ({
44
sidebar: css`
55
margin-top: ${token.headerHeight}px;
66
`,
7-
sidebarContent: css`
8-
&.draggable-panel-fixed {
9-
overflow-y: scroll;
10-
}
11-
`,
127
sidebarInner: css`
8+
overflow: auto;
9+
width: 100%;
10+
height: 100%;
1311
padding: 16px;
1412
dl {
1513
margin: 0;
1614
padding: 0;
1715
line-height: 1;
1816
1917
> dt {
18+
overflow: hidden;
19+
2020
margin: 8px 0;
21-
color: ${token.colorText};
21+
2222
font-weight: 500;
23-
white-space: nowrap;
24-
overflow: hidden;
23+
color: ${token.colorText};
2524
text-overflow: ellipsis;
2625
text-transform: uppercase;
26+
white-space: nowrap;
2727
}
2828
2929
> dd {
3030
margin: 0;
3131
padding: 2px 0;
3232
3333
> a {
34-
padding: 6px 12px;
35-
border-radius: 6px;
34+
overflow: hidden;
3635
display: block;
36+
37+
padding: 6px 12px;
38+
3739
font-size: ${token.fontSize}px;
3840
line-height: ${token.lineHeight};
41+
color: ${token.colorTextSecondary};
3942
text-decoration: none;
40-
41-
white-space: nowrap;
42-
overflow: hidden;
4343
text-overflow: ellipsis;
44+
white-space: nowrap;
45+
46+
border-radius: 6px;
4447
45-
color: ${token.colorTextSecondary};
4648
transition: color 600ms ${token.motionEaseOut},
4749
background-color 100ms ${token.motionEaseOut};
4850
&:hover {

src/DraggablePanel/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const useStyle = createStyles(({ token }, prefix: string) => {
1717
&:hover,
1818
&:active {
1919
&::before {
20-
background: ${token.colorPrimary};
20+
background: ${token.colorPrimary} !important;
2121
}
2222
}
2323
`;

src/StroyBook/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export const StroyBook = memo<StroyBookProps>(
3131
placement={mobile ? 'bottom' : 'right'}
3232
minWidth={280}
3333
>
34-
<LevaPanel fill store={levaStore} titleBar={false} flat />{' '}
34+
<div className={styles.leva}>
35+
<LevaPanel fill store={levaStore} titleBar={false} flat />{' '}
36+
</div>
3537
</DraggablePanel>
3638
</div>
3739
);

src/StroyBook/style.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const useStyles = createStyles(
2828
`}
2929
`,
3030
right: css`
31+
background: ${token.colorBgLayout};
32+
`,
33+
leva: css`
3134
--leva-sizes-controlWidth: 66%;
3235
--leva-colors-elevation1: ${token.colorFillSecondary};
3336
--leva-colors-elevation2: transparent;
@@ -43,8 +46,11 @@ export const useStyles = createStyles(
4346
--leva-shadows-level2: unset;
4447
--leva-fonts-mono: ${token.fontFamilyCode};
4548
49+
overflow: auto;
50+
width: 100%;
51+
height: 100%;
4652
padding: 6px 0;
47-
background: ${token.colorBgLayout};
53+
4854
> div {
4955
background: transparent;
5056
> div {

src/styles/algorithms/generateColorPalette.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export const generateColorNeutralPalette = ({
3434
appearance: 'light' | 'dark';
3535
}): Partial<AliasToken> => {
3636
return {
37-
colorText: scale[`${appearance}A`][12],
38-
colorTextSecondary: scale[`${appearance}A`][10],
39-
colorTextTertiary: scale[`${appearance}A`][8],
40-
colorTextQuaternary: scale[`${appearance}A`][6],
37+
colorText: scale[appearance][12],
38+
colorTextSecondary: scale[appearance][10],
39+
colorTextTertiary: scale[appearance][8],
40+
colorTextQuaternary: scale[appearance][6],
4141
colorBorder: scale[appearance][4],
4242
colorBorderSecondary: scale[appearance][3],
4343
colorFill: scale[`${appearance}A`][3],

src/styles/algorithms/generateCustomStylish.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,14 @@ export const generateCustomStylish: GetCustomStylish<LobeCustomStylish> = ({
144144
max-width: 100%;
145145
}
146146
147-
code,
148-
pre * {
149-
font-size: ${token.fontSizeSM}px;
150-
}
151-
152147
pre {
153148
border-radius: ${token.borderRadius}px;
154149
}
155150
156151
> :not([data-code-type='highlighter']) code {
157152
padding: 2px 6px;
158153
154+
font-size: ${token.fontSizeSM}px;
159155
color: ${isDarkMode ? token.cyan9A : token.cyan10A};
160156
161157
background: ${isDarkMode ? token.cyan1A : token.cyan3A};

0 commit comments

Comments
 (0)