11import React , { useState , useRef , useContext } from "react" ;
2- import PropTypes from "prop-types" ;
32import copy from "copy-to-clipboard" ;
43import { MDXProvider } from "@mdx-js/react" ;
54import { Clipboard } from "react-feather" ;
@@ -15,7 +14,7 @@ function makeKeywordsClickable(children) {
1514
1615 KEYWORDS_REGEX . lastIndex = 0 ;
1716
18- return children . reduce ( ( arr , child ) => {
17+ return children . reduce ( ( arr : any [ ] , child ) => {
1918 if ( typeof child !== "string" ) {
2019 arr . push ( child ) ;
2120 return arr ;
@@ -55,20 +54,22 @@ function Selector({ keyword, group, ...props }) {
5554 sharedSelection ,
5655 setSharedSelection ,
5756 ] = codeContext . sharedKeywordSelection ;
58- const spanRef = useRef ( ) ;
59- const [ menuRef , setMenuRef ] = useRefWithCallback ( menuNode => {
60- if ( menuNode ) {
61- for ( const node of menuNode . childNodes ) {
62- if ( node . getAttribute ( "data-active" ) === "1" ) {
63- node . parentNode . scrollTop =
64- node . offsetTop -
65- node . parentNode . getBoundingClientRect ( ) . height / 2 +
66- node . getBoundingClientRect ( ) . height / 2 ;
67- break ;
57+ const spanRef = useRef < HTMLSpanElement > ( ) ;
58+ const [ menuRef , setMenuRef ] = useRefWithCallback < HTMLSpanElement > (
59+ menuNode => {
60+ if ( menuNode ) {
61+ for ( const node of menuNode . childNodes as any ) {
62+ if ( node . getAttribute ( "data-active" ) === "1" ) {
63+ node . parentNode . scrollTop =
64+ node . offsetTop -
65+ node . parentNode . getBoundingClientRect ( ) . height / 2 +
66+ node . getBoundingClientRect ( ) . height / 2 ;
67+ break ;
68+ }
6869 }
6970 }
7071 }
71- } ) ;
72+ ) ;
7273
7374 useOnClickOutside ( menuRef , ( ) => {
7475 if ( isOpen ) {
@@ -87,7 +88,9 @@ function Selector({ keyword, group, ...props }) {
8788
8889 // this is not super clean but since we can depend on the span
8990 // rendering before the menu this works.
90- const style = { } ;
91+ const style : {
92+ [ key : string ] : any ;
93+ } = { } ;
9194 if ( spanRef . current ) {
9295 const rect = spanRef . current . getBoundingClientRect ( ) ;
9396 style . left = spanRef . current . offsetLeft - 10 + "px" ;
@@ -140,7 +143,7 @@ function Selector({ keyword, group, ...props }) {
140143 ) ;
141144}
142145
143- function CodeWrapper ( props ) {
146+ function CodeWrapper ( props ) : JSX . Element {
144147 let { children, class : className , ...rest } = props ;
145148 if ( children ) {
146149 children = makeKeywordsClickable ( children ) ;
@@ -152,7 +155,7 @@ function CodeWrapper(props) {
152155 ) ;
153156}
154157
155- function SpanWrapper ( props ) {
158+ function SpanWrapper ( props ) : JSX . Element {
156159 let { children, class : className , ...rest } = props ;
157160 if ( children ) {
158161 children = makeKeywordsClickable ( children ) ;
@@ -164,7 +167,12 @@ function SpanWrapper(props) {
164167 ) ;
165168}
166169
167- function CodeBlock ( { filename, children } ) {
170+ type Props = {
171+ filename ?: string ;
172+ children : JSX . Element ;
173+ } ;
174+
175+ export default ( { filename, children } : Props ) : JSX . Element => {
168176 const [ showCopied , setShowCopied ] = useState ( false ) ;
169177 const codeRef = useRef ( null ) ;
170178
@@ -197,12 +205,4 @@ function CodeBlock({ filename, children }) {
197205 </ div >
198206 </ div >
199207 ) ;
200- }
201-
202- CodeBlock . propTypes = {
203- language : PropTypes . string ,
204- filename : PropTypes . string ,
205- title : PropTypes . string ,
206208} ;
207-
208- export default CodeBlock ;
0 commit comments