Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
feat: Linkify component (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadenlemmon authored and kylealwyn committed Aug 2, 2018
1 parent 5cdb6ac commit 30a6371
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Linkify/Linkify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import styled from 'styled-components';

const Container = styled.span`
a {
color: inherit;
text-decoration: underline;
}
`;

const REGEX = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;

const parse = string => string.replace(REGEX, url => `<a target="_blank" href="${url}">${url}</a>`);

const Linkify = props => (
<Container style={props.style || {}} dangerouslySetInnerHTML={{ __html: parse(props.children) }} />
);

export default Linkify;
18 changes: 18 additions & 0 deletions src/Linkify/Linkify.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
menu: Components
name: Linkify
---

import { Playground, PropsTable } from 'docz'
import Linkify from './Linkify'

# Linkify

Automatically parse links contained in a body of text.

## Example
<Playground>
<Linkify>
Checkout http://google.com. Another one that is not that great is http://bing.com.
</Linkify>
</Playground>
3 changes: 3 additions & 0 deletions src/Linkify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Linkify from './Linkify';

export default Linkify;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export Spinner from './Spinner';
export Swtich from './Form/Switch';
export Tabs from './Tabs';
export ThemeProvider from './ThemeProvider';
export Linkify from './Linkify';

0 comments on commit 30a6371

Please sign in to comment.