Migrate Linkify to Storybook
This commit is contained in:
parent
d27a15a3eb
commit
15e817c3e2
3 changed files with 70 additions and 45 deletions
|
@ -1,44 +0,0 @@
|
||||||
### All link
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="https://somewhere.com" />
|
|
||||||
```
|
|
||||||
|
|
||||||
### Starting and ending with link
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="https://somewhere.com Yes? No? https://anotherlink.com" />
|
|
||||||
```
|
|
||||||
|
|
||||||
### With a link in the middle
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="Before. https://somewhere.com After." />
|
|
||||||
```
|
|
||||||
|
|
||||||
### No link
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="Plain text" />
|
|
||||||
```
|
|
||||||
|
|
||||||
### Should not render as link
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="smailto:someone@somewhere.com - ftp://something.com - //local/share - \\local\share" />
|
|
||||||
```
|
|
||||||
|
|
||||||
### Should render as link
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<Linkify text="github.com - https://blah.com" />
|
|
||||||
```
|
|
||||||
|
|
||||||
### Providing custom non-link render function
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
const renderNonLink = ({ text, key }) => (
|
|
||||||
<span key={key}>This is my custom non-link content!</span>
|
|
||||||
);
|
|
||||||
<Linkify text="Before github.com After" renderNonLink={renderNonLink} />;
|
|
||||||
```
|
|
69
ts/components/conversation/Linkify.stories.tsx
Normal file
69
ts/components/conversation/Linkify.stories.tsx
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { text } from '@storybook/addon-knobs';
|
||||||
|
import { storiesOf } from '@storybook/react';
|
||||||
|
|
||||||
|
import { Linkify, Props } from './Linkify';
|
||||||
|
|
||||||
|
const story = storiesOf('Components/Conversation/Linkify', module);
|
||||||
|
|
||||||
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
||||||
|
renderNonLink: overrideProps.renderNonLink,
|
||||||
|
text: text('text', overrideProps.text || ''),
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('Only Link', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text: 'https://www.signal.org',
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('Links with Text', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text:
|
||||||
|
'you should see this: https://www.signal.org - it is good. Also: https://placekitten.com!',
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('No Link', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text: 'I am fond of cats',
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('Blocked Protocols', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text:
|
||||||
|
'smailto:someone@somewhere.com - ftp://something.com - //local/share - \\localshare',
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('Missing Protocol', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text: 'github.com is a place for things',
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
|
story.add('Custom Text Render', () => {
|
||||||
|
const props = createProps({
|
||||||
|
text:
|
||||||
|
'you should see this: https://www.signal.org - it is good. Also: https://placekitten.com!',
|
||||||
|
renderNonLink: ({ text: theText, key }) => (
|
||||||
|
<div key={key} style={{ backgroundColor: 'aquamarine' }}>
|
||||||
|
{theText}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Linkify {...props} />;
|
||||||
|
});
|
|
@ -7,7 +7,7 @@ import { isLinkSneaky } from '../../../js/modules/link_previews';
|
||||||
|
|
||||||
const linkify = LinkifyIt();
|
const linkify = LinkifyIt();
|
||||||
|
|
||||||
interface Props {
|
export interface Props {
|
||||||
text: string;
|
text: string;
|
||||||
/** Allows you to customize now non-links are rendered. Simplest is just a <span>. */
|
/** Allows you to customize now non-links are rendered. Simplest is just a <span>. */
|
||||||
renderNonLink?: RenderTextCallbackType;
|
renderNonLink?: RenderTextCallbackType;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue