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

86 lines
2.2 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 type { Meta } from '@storybook/react';
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',
} satisfies Meta<Props>;
2020-08-23 19:32:24 +00:00
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
renderNonLink: overrideProps.renderNonLink,
text: overrideProps.text || '',
2020-08-23 19:32:24 +00:00
});
2022-11-18 00:45:19 +00:00
export function OnlyLink(): JSX.Element {
2020-08-23 19:32:24 +00:00
const props = createProps({
text: 'https://www.signal.org',
});
return <Linkify {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-23 19:32:24 +00:00
2022-11-18 00:45:19 +00:00
export function 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-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function LinksWithEmojiWithoutSpace(): JSX.Element {
const props = createProps({
text: '👍https://www.signal.org😎',
});
return <Linkify {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function 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-11-18 00:45:19 +00:00
}
2021-07-27 23:39:57 +00:00
2022-11-18 00:45:19 +00:00
export function NoLink(): JSX.Element {
2020-08-23 19:32:24 +00:00
const props = createProps({
text: 'I am fond of cats',
});
return <Linkify {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-23 19:32:24 +00:00
2022-11-18 00:45:19 +00:00
export function 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-11-18 00:45:19 +00:00
}
2020-08-23 19:32:24 +00:00
2022-11-18 00:45:19 +00:00
export function 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-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function 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-11-18 00:45:19 +00:00
}