Skip to content
This repository was archived by the owner on Apr 9, 2023. It is now read-only.

Commit 1788b32

Browse files
ItsWendellbyCedric
authored andcommitted
feature: prototype github mentions support as a component (#56)
1 parent 167a5f3 commit 1788b32

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const MENTIONS_PATTERN = /@([a-z0-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+
};

src/atoms/github-mentions/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './github-mentions';

0 commit comments

Comments
 (0)