signal-desktop/ts/components/conversation/Linkify.stories.tsx

104 lines
2.5 KiB
TypeScript
Raw Normal View History

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 type { Props } from './Linkify';
import { Linkify } from './Linkify';
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/Linkify',
};
2020-08-23 19:32:24 +00:00
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
renderNonLink: overrideProps.renderNonLink,
text: text('text', overrideProps.text || ''),
});
2022-06-07 00:48:02 +00:00
export const OnlyLink = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
text: 'https://www.signal.org',
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export const LinksWithText = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
2021-11-11 22:43:05 +00:00
text: 'you should see this: https://www.signal.org - it is good. Also: https://placekitten.com!',
2020-08-23 19:32:24 +00:00
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
LinksWithText.story = {
name: 'Links with Text',
};
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export const LinksWithEmojiWithoutSpace = (): JSX.Element => {
const props = createProps({
text: '👍https://www.signal.org😎',
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
LinksWithEmojiWithoutSpace.story = {
name: 'Links with Emoji without space',
};
2022-06-07 00:48:02 +00:00
export const LinksWithEmojiAndText = (): JSX.Element => {
2021-07-27 23:39:57 +00:00
const props = createProps({
2021-11-11 22:43:05 +00:00
text: 'https://example.com ⚠️ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ https://example.com',
2021-07-27 23:39:57 +00:00
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
2021-07-27 23:39:57 +00:00
2022-06-07 00:48:02 +00:00
LinksWithEmojiAndText.story = {
name: 'Links with Emoji and Text',
};
export const NoLink = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
text: 'I am fond of cats',
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export const BlockedProtocols = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
2021-11-11 22:43:05 +00:00
text: 'smailto:someone@somewhere.com - ftp://something.com - //local/share - \\localshare',
2020-08-23 19:32:24 +00:00
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export const MissingProtocols = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
2021-11-11 22:43:05 +00:00
text: '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} />;
2022-06-07 00:48:02 +00:00
};
MissingProtocols.story = {
name: 'Missing protocols',
};
2020-08-23 19:32:24 +00:00
2022-06-07 00:48:02 +00:00
export const CustomTextRender = (): JSX.Element => {
2020-08-23 19:32:24 +00:00
const props = createProps({
2021-11-11 22:43:05 +00:00
text: 'you should see this: https://www.signal.org - it is good. Also: https://placekitten.com!',
2020-08-23 19:32:24 +00:00
renderNonLink: ({ text: theText, key }) => (
<div key={key} style={{ backgroundColor: 'aquamarine' }}>
{theText}
</div>
),
});
return <Linkify {...props} />;
2022-06-07 00:48:02 +00:00
};