1
- import React from "react" ;
2
- import ReactDOM from "react-dom" ;
3
- import Button from "./Button" ;
4
- import { CloseIcon } from "./Icons" ;
5
- import CodePreview from "./CodePreview" ;
6
- import { SnippetType } from "../types" ;
7
- import slugify from "../utils/slugify" ;
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom'
3
+ import Button from './Button'
4
+ import { CloseIcon } from './Icons'
5
+ import CodePreview from './CodePreview'
6
+ import { SnippetType } from '../types'
7
+ import slugify from '../utils/slugify'
8
+ import useEscapeKey from '../hooks/useEscapeKey'
8
9
9
10
type Props = {
10
- snippet : SnippetType ;
11
- language : string ;
12
- handleCloseModal : ( ) => void ;
13
- } ;
11
+ snippet : SnippetType
12
+ language : string
13
+ handleCloseModal : ( ) => void
14
+ }
14
15
15
16
const SnippetModal : React . FC < Props > = ( {
16
17
snippet,
17
18
language,
18
19
handleCloseModal,
19
20
} ) => {
20
- const modalRoot = document . getElementById ( "modal-root" ) ;
21
- if ( ! modalRoot ) return null ;
21
+ const modalRoot = document . getElementById ( 'modal-root' )
22
+ if ( ! modalRoot ) return null
23
+ useEscapeKey ( handleCloseModal )
22
24
23
25
return ReactDOM . createPortal (
24
- < div className = " modal-overlay" >
25
- < div className = " modal | flow" data-flow-space = "lg" >
26
- < div className = " modal__header" >
27
- < h2 className = " section-title" > { snippet . title } </ h2 >
26
+ < div className = ' modal-overlay' >
27
+ < div className = ' modal | flow' data-flow-space = 'lg' >
28
+ < div className = ' modal__header' >
29
+ < h2 className = ' section-title' > { snippet . title } </ h2 >
28
30
< Button isIcon = { true } onClick = { handleCloseModal } >
29
31
< CloseIcon />
30
32
</ Button >
@@ -35,27 +37,27 @@ const SnippetModal: React.FC<Props> = ({
35
37
{ snippet . description }
36
38
</ p >
37
39
< p >
38
- Contributed by{ " " }
40
+ Contributed by{ ' ' }
39
41
< a
40
42
href = { `https://github.com/${ snippet . author } ` }
41
- target = " _blank"
42
- rel = " noopener noreferrer"
43
- className = " styled-link"
43
+ target = ' _blank'
44
+ rel = ' noopener noreferrer'
45
+ className = ' styled-link'
44
46
>
45
47
@{ snippet . author }
46
48
</ a >
47
49
</ p >
48
- < ul role = " list" className = " modal__tags" >
50
+ < ul role = ' list' className = ' modal__tags' >
49
51
{ snippet . tags . map ( ( tag ) => (
50
- < li key = { tag } className = " modal__tag" >
52
+ < li key = { tag } className = ' modal__tag' >
51
53
{ tag }
52
54
</ li >
53
55
) ) }
54
56
</ ul >
55
57
</ div >
56
58
</ div > ,
57
59
modalRoot
58
- ) ;
59
- } ;
60
+ )
61
+ }
60
62
61
- export default SnippetModal ;
63
+ export default SnippetModal
0 commit comments