1
- import React from 'react' ;
2
- import { Col , ConfigProvider , Flex , Row , Tag , theme , Typography } from 'antd' ;
1
+ import { Col , ConfigProvider , Flex , Row , Tag , Typography , theme } from 'antd' ;
3
2
import { createStyles , css } from 'antd-style' ;
4
3
import classnames from 'classnames' ;
4
+ import React from 'react' ;
5
5
6
6
const MARK_BORDER_SIZE = 2 ;
7
7
8
- const useStyle = createStyles (
9
- ( { token } , markPos : [ number , number , number , number ] ) => ( {
10
- container : css `
11
- position : relative;
12
- ` ,
13
- colWrap : css `
14
- border-right : 1px solid ${ token . colorBorderSecondary } ;
15
- display : flex;
16
- justify-content : center;
17
- align-items : center;
18
- padding : ${ token . paddingMD } px;
19
- overflow : hidden;
20
- ` ,
21
- listWrap : css `
22
- display : flex;
23
- flex-direction : column;
24
- list-style : none;
25
- margin : 0 ;
26
- padding : 0 ;
27
- overflow : hidden;
28
- ` ,
29
- listItem : css `
30
- cursor : pointer;
31
- padding : ${ token . paddingSM } px;
32
- transition : background-color ${ token . motionDurationFast } ease;
33
- & : hover {
34
- background-color : ${ token . controlItemBgHover } ;
35
- }
36
- & : not (: first-of-type ) {
37
- border-top : 1px solid ${ token . colorBorderSecondary } ;
38
- }
39
- ` ,
40
- marker : css `
41
- position : absolute;
42
- border : ${ MARK_BORDER_SIZE } px solid ${ token . colorWarning } ;
43
- box-sizing : border-box;
44
- z-index : 999999 ;
45
- box-shadow : 0 0 0 1px # fff ;
46
- pointer-events : none;
47
- left : ${ markPos [ 0 ] - MARK_BORDER_SIZE } px;
48
- top : ${ markPos [ 1 ] - MARK_BORDER_SIZE } px;
49
- width : ${ markPos [ 2 ] + MARK_BORDER_SIZE * 2 } px;
50
- height : ${ markPos [ 3 ] + MARK_BORDER_SIZE * 2 } px;
51
- ` ,
52
- markerActive : css `
53
- opacity : 1 ;
54
- ` ,
55
- markerNotActive : css `
56
- opacity : 0 ;
57
- ` ,
58
- markerMotion : css `
59
- transition :
60
- opacity ${ token . motionDurationSlow } ease,
61
- all ${ token . motionDurationSlow } ease;
62
- ` ,
63
- markerNotMotion : css `
64
- transition : opacity ${ token . motionDurationSlow } ease;
65
- ` ,
66
- } ) ,
67
- ) ;
8
+ const useStyle = createStyles ( ( { token } , markPos : [ number , number , number , number ] ) => ( {
9
+ container : css `
10
+ position : relative;
11
+ ` ,
12
+ colWrap : css `
13
+ border-right : 1px solid ${ token . colorBorderSecondary } ;
14
+ display : flex;
15
+ justify-content : center;
16
+ align-items : center;
17
+ padding : ${ token . paddingMD } px;
18
+ overflow : hidden;
19
+ ` ,
20
+ listWrap : css `
21
+ display : flex;
22
+ flex-direction : column;
23
+ list-style : none;
24
+ margin : 0 ;
25
+ padding : 0 ;
26
+ overflow : hidden;
27
+ ` ,
28
+ listItem : css `
29
+ cursor : pointer;
30
+ padding : ${ token . paddingSM } px;
31
+ transition : background-color ${ token . motionDurationFast } ease;
32
+ & : hover {
33
+ background-color : ${ token . controlItemBgHover } ;
34
+ }
35
+ & : not (: first-of-type ) {
36
+ border-top : 1px solid ${ token . colorBorderSecondary } ;
37
+ }
38
+ ` ,
39
+ marker : css `
40
+ position : absolute;
41
+ border : ${ MARK_BORDER_SIZE } px solid ${ token . colorWarning } ;
42
+ box-sizing : border-box;
43
+ z-index : 999999 ;
44
+ box-shadow : 0 0 0 1px # fff ;
45
+ pointer-events : none;
46
+ inset-inline-start : ${ markPos [ 0 ] - MARK_BORDER_SIZE } px;
47
+ top : ${ markPos [ 1 ] - MARK_BORDER_SIZE } px;
48
+ width : ${ markPos [ 2 ] + MARK_BORDER_SIZE * 2 } px;
49
+ height : ${ markPos [ 3 ] + MARK_BORDER_SIZE * 2 } px;
50
+ ` ,
51
+ markerActive : css `
52
+ opacity : 1 ;
53
+ ` ,
54
+ markerNotActive : css `
55
+ opacity : 0 ;
56
+ ` ,
57
+ markerMotion : css `
58
+ transition :
59
+ opacity ${ token . motionDurationSlow } ease,
60
+ all ${ token . motionDurationSlow } ease;
61
+ ` ,
62
+ markerNotMotion : css `
63
+ transition : opacity ${ token . motionDurationSlow } ease;
64
+ ` ,
65
+ } ) ) ;
68
66
69
67
export interface SemanticPreviewProps {
70
68
semantics : { name : string ; desc : string ; version ?: string } [ ] ;
@@ -103,18 +101,14 @@ const SemanticPreview: React.FC<SemanticPreviewProps> = (props) => {
103
101
104
102
const [ positionMotion , setPositionMotion ] = React . useState < boolean > ( false ) ;
105
103
const [ hoverSemantic , setHoverSemantic ] = React . useState < string | null > ( null ) ;
106
- const [ markPos , setMarkPos ] = React . useState <
107
- [ number , number , number , number ]
108
- > ( [ 0 , 0 , 0 , 0 ] ) ;
104
+ const [ markPos , setMarkPos ] = React . useState < [ number , number , number , number ] > ( [ 0 , 0 , 0 , 0 ] ) ;
109
105
110
106
const { styles } = useStyle ( markPos ) ;
111
107
112
108
React . useEffect ( ( ) => {
113
109
if ( hoverSemantic ) {
114
110
const targetClassName = getMarkClassName ( hoverSemantic ) ;
115
- const targetElement = containerRef . current ?. querySelector < HTMLElement > (
116
- `.${ targetClassName } ` ,
117
- ) ;
111
+ const targetElement = containerRef . current ?. querySelector < HTMLElement > ( `.${ targetClassName } ` ) ;
118
112
const containerRect = containerRef . current ?. getBoundingClientRect ( ) ;
119
113
const targetRect = targetElement ?. getBoundingClientRect ( ) ;
120
114
setMarkPos ( [
@@ -143,9 +137,7 @@ const SemanticPreview: React.FC<SemanticPreviewProps> = (props) => {
143
137
< div className = { classnames ( styles . container ) } ref = { containerRef } >
144
138
< Row style = { { minHeight : height } } >
145
139
< Col span = { 16 } className = { classnames ( styles . colWrap ) } >
146
- < ConfigProvider theme = { { token : { motion : false } } } >
147
- { cloneNode }
148
- </ ConfigProvider >
140
+ < ConfigProvider theme = { { token : { motion : false } } } > { cloneNode } </ ConfigProvider >
149
141
</ Col >
150
142
< Col span = { 8 } >
151
143
< ul className = { classnames ( styles . listWrap ) } >
@@ -161,13 +153,9 @@ const SemanticPreview: React.FC<SemanticPreviewProps> = (props) => {
161
153
< Typography . Title level = { 5 } style = { { margin : 0 } } >
162
154
{ semantic . name }
163
155
</ Typography . Title >
164
- { semantic . version && (
165
- < Tag color = "blue" > { semantic . version } </ Tag >
166
- ) }
156
+ { semantic . version && < Tag color = "blue" > { semantic . version } </ Tag > }
167
157
</ Flex >
168
- < Typography . Paragraph
169
- style = { { margin : 0 , fontSize : token . fontSizeSM } }
170
- >
158
+ < Typography . Paragraph style = { { margin : 0 , fontSize : token . fontSizeSM } } >
171
159
{ semantic . desc }
172
160
</ Typography . Paragraph >
173
161
</ Flex >
0 commit comments