This repository was archived by the owner on Apr 9, 2023. It is now read-only.
Commit 1788b32 1 parent 167a5f3 commit 1788b32 Copy full SHA for 1788b32
File tree 2 files changed +41
-0
lines changed
src/atoms/github-mentions
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+
4
+ const MENTIONS_PATTERN = / @ ( [ a - z 0 - 9 ] + ) / gi;
5
+
6
+ export default function GithubMentionsAtom ( props ) {
7
+ console . log ( 'PROPS' , props ) ;
8
+ const splitText = props . children . split ( MENTIONS_PATTERN ) ;
9
+ const matches = props . children . match ( MENTIONS_PATTERN ) ;
10
+
11
+ if ( ! splitText ) return props . children ;
12
+
13
+ return (
14
+ < p >
15
+ { splitText . reduce ( ( arr , element ) => {
16
+ if ( ! element ) return arr ;
17
+
18
+ if ( matches . includes ( `@${ element } ` ) ) {
19
+ return [
20
+ ...arr ,
21
+ ( < a href = { `https://github.com/${ element } ` } target = "_blank" rel = "noopener noreferrer" >
22
+ @{ element }
23
+ </ a > ) ,
24
+ ] ;
25
+ }
26
+
27
+ return [ ...arr , element ] ;
28
+ } , [ ] ) }
29
+ </ p >
30
+ ) ;
31
+ }
32
+
33
+ GithubMentionsAtom . propTypes = {
34
+ /** The content that has mentions that needs transformed to GitHub links */
35
+ children : PropTypes . string . isRequired ,
36
+ } ;
37
+
38
+ GithubMentionsAtom . defaultProps = {
39
+ children : '' ,
40
+ } ;
Original file line number Diff line number Diff line change
1
+ export { default } from './github-mentions' ;
You can’t perform that action at this time.
0 commit comments