Skip to content

Commit f35d147

Browse files
✨ feat: Add new features to Highlighter and CodeBlock components
- Import and use additional components in the Highlighter component - Add "copyButtonSize" prop to customize the size of the copy button - Use Tag component instead of div element for displaying the language - Modify style file for Highlighter component to adjust z-index and color properties - Add "copyButtonSize" prop to CodeBlock component with specific values These changes enhance the functionality and appearance of the Highlighter and CodeBlock components.
1 parent 755d807 commit f35d147

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/Highlighter/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { memo } from 'react';
22

3-
import CopyButton from '@/CopyButton';
3+
import CopyButton, { type CopyButtonProps } from '@/CopyButton';
44
import Spotlight from '@/Spotlight';
5+
import Tag from '@/Tag';
56
import { DivProps } from '@/types';
67

78
import SyntaxHighlighter from './SyntaxHighlighter';
@@ -12,6 +13,7 @@ export interface HighlighterProps extends DivProps {
1213
* @description The code content to be highlighted
1314
*/
1415
children: string;
16+
copyButtonSize?: CopyButtonProps['size'];
1517
/**
1618
* @description Whether to show the copy button
1719
* @default true
@@ -40,6 +42,7 @@ export interface HighlighterProps extends DivProps {
4042

4143
export const Highlighter = memo<HighlighterProps>(
4244
({
45+
copyButtonSize = 'site',
4346
children,
4447
language,
4548
className,
@@ -56,8 +59,15 @@ export const Highlighter = memo<HighlighterProps>(
5659
return (
5760
<div className={container} data-code-type="highlighter" style={style} {...props}>
5861
{spotlight && <Spotlight size={240} />}
59-
{copyable && <CopyButton className={styles.button} content={children} placement="left" />}
60-
{showLanguage && language && <div className={styles.lang}>{language.toLowerCase()}</div>}
62+
{copyable && (
63+
<CopyButton
64+
className={styles.button}
65+
content={children}
66+
placement="left"
67+
size={copyButtonSize}
68+
/>
69+
)}
70+
{showLanguage && language && <Tag className={styles.lang}>{language.toLowerCase()}</Tag>}
6171
<SyntaxHighlighter language={language?.toLowerCase()}>{children.trim()}</SyntaxHighlighter>
6272
</div>
6373
);

src/Highlighter/style.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createStyles } from 'antd-style';
22

33
export const useStyles = createStyles(
4-
({ token, css, cx, prefixCls }, type: 'ghost' | 'block' | 'pure') => {
4+
({ token, css, cx, prefixCls, stylish }, type: 'ghost' | 'block' | 'pure') => {
55
const prefix = `${prefixCls}-highlighter`;
66
const buttonHoverCls = `${prefix}-hover-btn`;
77
const langHoverCls = `${prefix}-hover-lang`;
@@ -20,7 +20,7 @@ export const useStyles = createStyles(
2020
buttonHoverCls,
2121
css`
2222
position: absolute;
23-
z-index: 51;
23+
z-index: 2;
2424
top: ${type === 'pure' ? 0 : '8px'};
2525
right: ${type === 'pure' ? 0 : '8px'};
2626
@@ -64,13 +64,15 @@ export const useStyles = createStyles(
6464
),
6565
lang: cx(
6666
langHoverCls,
67+
stylish.blur,
6768
css`
6869
position: absolute;
69-
z-index: 50;
70-
right: 8px;
70+
z-index: 2;
71+
right: 0;
7172
bottom: 8px;
7273
73-
color: ${token.colorTextPlaceholder};
74+
font-family: ${token.fontFamilyCode};
75+
color: ${token.colorTextSecondary};
7476
7577
opacity: 0;
7678

src/Markdown/CodeBlock.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Code = memo((properties: any) => {
2626
return (
2727
<Highlighter
2828
className={styles}
29+
copyButtonSize={{ blockSize: 28, fontSize: 16 }}
2930
language={className?.replace('language-', '') || 'markdown'}
3031
type="block"
3132
>

0 commit comments

Comments
 (0)