Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Commit a88aa28

Browse files
committed
add flowtype and update index's title
1 parent c6b9cc8 commit a88aa28

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

examples/linkify-example/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
99

10-
<title>@djsp/hashtag-example</title>
10+
<title>@djsp/linkify-example</title>
1111
</head>
1212

1313
<body>
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
// @flow
2+
13
import React, { Component } from 'react'
2-
import linkifyIt from 'linkify-it';
3-
import tlds from 'tlds';
4+
import { Plugin } from '@djsp/core'
5+
import linkStrategy from './linkStrategy'
6+
import linkifyIt from 'linkify-it'
7+
import tlds from 'tlds'
8+
import type { DraftDecoratorComponentProps } from 'draft-js'
9+
10+
const linkify = linkifyIt()
11+
linkify.tlds(tlds)
412

5-
const linkify = linkifyIt();
6-
linkify.tlds(tlds);
13+
type Props = DraftDecoratorComponentProps & {
14+
target?: string,
15+
rel?: string,
16+
}
717

8-
export default class Hashtag extends Component {
18+
class LinkComponent extends Component<Props> {
919
render() {
1020
const {
1121
decoratedText, // eslint-disable-line no-unused-vars
@@ -18,17 +28,30 @@ export default class Hashtag extends Component {
1828
...otherProps
1929
} = this.props // eslint-disable-line no-use-before-define
2030

21-
const links = linkify.match(decoratedText);
22-
const href = links && links[0] ? links[0].url : '';
31+
const links = linkify.match(decoratedText)
32+
const href = links && links[0] ? links[0].url : ''
2333

2434
const props = {
2535
...otherProps,
2636
href,
2737
target,
2838
rel,
2939
className: 'link',
30-
};
40+
}
3141

32-
return <a {...props} />
42+
return <a {...props} /> // eslint-disable-line jsx-a11y/anchor-has-content
3343
}
3444
}
45+
46+
export default function Link() {
47+
return (
48+
<Plugin
49+
decorators={[
50+
{
51+
strategy: linkStrategy,
52+
component: LinkComponent,
53+
},
54+
]}
55+
/>
56+
)
57+
}

examples/linkify-example/src/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { Component } from 'react'
22
import ReactDOM from 'react-dom'
33

44
import { EditorState, convertFromRaw } from 'draft-js'
5-
import { EditorContainer, Editor, Plugin } from '@djsp/core'
6-
import linkStrategy from './linkStrategy'
5+
import { EditorContainer, Editor } from '@djsp/core'
76
import Link from './Link'
87
import './styles.css'
98

@@ -30,14 +29,7 @@ class App extends Component {
3029
editorState={this.state.editorState}
3130
onChange={this.onChange}>
3231
<Editor />
33-
<Plugin
34-
decorators={[
35-
{
36-
strategy: linkStrategy,
37-
component: Link,
38-
},
39-
]}
40-
/>
32+
<Link />
4133
</EditorContainer>
4234
</div>
4335
)
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// @flow
22

3-
import linkifyIt from 'linkify-it';
4-
import tlds from 'tlds';
3+
import { ContentBlock } from 'draft-js'
4+
import linkifyIt from 'linkify-it'
5+
import tlds from 'tlds'
56

6-
const linkify = linkifyIt();
7-
linkify.tlds(tlds);
7+
const linkify = linkifyIt()
8+
linkify.tlds(tlds)
89

910
// Gets all the links in the text, and returns them via the callback
10-
const linkStrategy = (contentBlock: Object, callback: Function) => {
11-
const links = linkify.match(contentBlock.get('text'));
11+
const linkStrategy = (contentBlock: ContentBlock, callback: Function): void => {
12+
const links = linkify.match(contentBlock.get('text'))
1213
if (typeof links !== 'undefined' && links !== null) {
1314
for (let i = 0; i < links.length; i += 1) {
14-
callback(links[i].index, links[i].lastIndex);
15+
callback(links[i].index, links[i].lastIndex)
1516
}
1617
}
17-
};
18+
}
1819

19-
export default linkStrategy;
20+
export default linkStrategy

0 commit comments

Comments
 (0)