1
- /* eslint-disable lodash/import-scope */
2
1
import React from 'react' ;
3
2
import { GithubOutlined } from '@ant-design/icons' ;
4
3
import { Descriptions , theme , Tooltip , Typography , type GetProp } from 'antd' ;
5
4
import { createStyles , css } from 'antd-style' ;
6
- import { kebabCase } from 'lodash' ;
5
+ import kebabCase from 'lodash/kebabCase ' ;
7
6
import CopyToClipboard from 'react-copy-to-clipboard' ;
8
7
9
8
import useLocale from '../../../hooks/useLocale' ;
@@ -27,26 +26,41 @@ const useStyle = createStyles(({ token }) => ({
27
26
code : css `
28
27
cursor : pointer;
29
28
position : relative;
30
- display : inline-block;
31
- border-radius : 3px ;
29
+ display : inline-flex;
30
+ align-items : center;
31
+ column-gap : 4px ;
32
+ border-radius : 4px ;
32
33
padding-inline : ${ token . paddingXS } px;
33
34
transition : all ${ token . motionDurationSlow } !important ;
34
-
35
35
& : hover {
36
36
background : ${ token . controlItemBgHover } ;
37
37
}
38
38
` ,
39
+ import : css `
40
+ color : ${ token . magenta8 } ;
41
+ ` ,
42
+ component : css `
43
+ color : ${ token . colorText } ;
44
+ ` ,
45
+ from : css `
46
+ color : ${ token . magenta8 } ;
47
+ ` ,
48
+ antd : css `
49
+ color : ${ token . green8 } ;
50
+ ` ,
51
+ semicolon : css `
52
+ color : ${ token . colorText } ;
53
+ ` ,
39
54
} ) ) ;
40
55
41
56
export interface ComponentMetaProps {
42
57
component : string ;
43
58
source : string | true ;
44
59
}
45
60
46
- const ComponentMeta = ( props : ComponentMetaProps ) => {
61
+ const ComponentMeta : React . FC < ComponentMetaProps > = ( props ) => {
47
62
const { component, source } = props ;
48
63
const { token } = theme . useToken ( ) ;
49
-
50
64
const [ locale ] = useLocale ( locales ) ;
51
65
52
66
const { styles } = useStyle ( ) ;
@@ -83,17 +97,17 @@ const ComponentMeta = (props: ComponentMetaProps) => {
83
97
84
98
// ======================== Render ========================
85
99
const importList = [
86
- < span key = "import" style = { { color : token . magenta8 } } >
100
+ < span key = "import" className = { styles . import } >
87
101
import
88
102
</ span > ,
89
- < span key = "component" style = { { color : token . colorText } } > { ` { ${ component } } ` } </ span > ,
90
- < span key = "from" style = { { color : token . magenta8 } } >
103
+ < span key = "component" className = { styles . component } > { `{ ${ component } }` } </ span > ,
104
+ < span key = "from" className = { styles . from } >
91
105
from
92
106
</ span > ,
93
- < span key = "antd" style = { { color : token . green8 } } >
94
- { `' antd' ` }
107
+ < span key = "antd" className = { styles . antd } >
108
+ { `" antd" ` }
95
109
</ span > ,
96
- < span key = "semicolon" style = { { color : token . colorText } } >
110
+ < span key = "semicolon" className = { styles . semicolon } >
97
111
;
98
112
</ span > ,
99
113
] ;
@@ -104,9 +118,7 @@ const ComponentMeta = (props: ComponentMetaProps) => {
104
118
colon = { false }
105
119
column = { 1 }
106
120
style = { { marginTop : token . margin } }
107
- labelStyle = { {
108
- paddingInlineEnd : token . padding ,
109
- } }
121
+ labelStyle = { { paddingInlineEnd : token . padding } }
110
122
items = {
111
123
[
112
124
{
@@ -118,9 +130,9 @@ const ComponentMeta = (props: ComponentMetaProps) => {
118
130
onOpenChange = { onOpenChange }
119
131
>
120
132
< span >
121
- < CopyToClipboard text = { `import { ${ component } } from ' antd' ;` } onCopy = { onCopy } >
133
+ < CopyToClipboard text = { `import { ${ component } } from " antd" ;` } onCopy = { onCopy } >
122
134
< Typography . Text className = { styles . code } onClick = { onCopy } >
123
- { importList . map ( ( txt , index ) => ( index === 0 ? txt : [ ' ' , txt ] ) ) }
135
+ { importList }
124
136
</ Typography . Text >
125
137
</ CopyToClipboard >
126
138
</ span >
0 commit comments