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'
89
910type Props = {
10- snippet : SnippetType ;
11- language : string ;
12- handleCloseModal : ( ) => void ;
13- } ;
11+ snippet : SnippetType
12+ language : string
13+ handleCloseModal : ( ) => void
14+ }
1415
1516const SnippetModal : React . FC < Props > = ( {
1617 snippet,
1718 language,
1819 handleCloseModal,
1920} ) => {
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 )
2224
2325 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 >
2830 < Button isIcon = { true } onClick = { handleCloseModal } >
2931 < CloseIcon />
3032 </ Button >
@@ -35,27 +37,27 @@ const SnippetModal: React.FC<Props> = ({
3537 { snippet . description }
3638 </ p >
3739 < p >
38- Contributed by{ " " }
40+ Contributed by{ ' ' }
3941 < a
4042 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'
4446 >
4547 @{ snippet . author }
4648 </ a >
4749 </ p >
48- < ul role = " list" className = " modal__tags" >
50+ < ul role = ' list' className = ' modal__tags' >
4951 { snippet . tags . map ( ( tag ) => (
50- < li key = { tag } className = " modal__tag" >
52+ < li key = { tag } className = ' modal__tag' >
5153 { tag }
5254 </ li >
5355 ) ) }
5456 </ ul >
5557 </ div >
5658 </ div > ,
5759 modalRoot
58- ) ;
59- } ;
60+ )
61+ }
6062
61- export default SnippetModal ;
63+ export default SnippetModal
0 commit comments