2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-23 19:32:24 +00:00
|
|
|
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} />;
|
|
|
|
});
|
|
|
|
|
2021-06-30 17:00:02 +00:00
|
|
|
story.add('Links with Emoji without space', () => {
|
|
|
|
const props = createProps({
|
|
|
|
text: '👍https://www.signal.org😎',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Linkify {...props} />;
|
|
|
|
});
|
|
|
|
|
2021-07-27 23:39:57 +00:00
|
|
|
story.add('Links with Emoji and Text', () => {
|
|
|
|
const props = createProps({
|
|
|
|
text:
|
|
|
|
'https://example.com ⚠️ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ https://example.com',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Linkify {...props} />;
|
|
|
|
});
|
|
|
|
|
2020-08-23 19:32:24 +00:00
|
|
|
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} />;
|
|
|
|
});
|
|
|
|
|
2021-09-17 15:14:42 +00:00
|
|
|
story.add('Missing protocols', () => {
|
2020-08-23 19:32:24 +00:00
|
|
|
const props = createProps({
|
2021-09-17 15:14:42 +00:00
|
|
|
text:
|
2021-09-17 16:28:26 +00:00
|
|
|
'I love example.com. I also love кц.рф. I also love مثال.تونس. But I do not love test.example.',
|
2020-08-23 19:32:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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} />;
|
|
|
|
});
|