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

127 lines
2.9 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-09-16 22:42:48 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import { generateAci } from '../../types/ServiceId';
import type { Props } from './AtMentionify';
import { AtMentionify } from './AtMentionify';
2020-09-16 22:42:48 +00:00
const SERVICE_ID_1 = generateAci();
const SERVICE_ID_2 = generateAci();
const SERVICE_ID_3 = generateAci();
const SERVICE_ID_4 = generateAci();
const SERVICE_ID_5 = generateAci();
const SERVICE_ID_6 = generateAci();
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/AtMentionify',
} satisfies Meta<Props>;
2020-09-16 22:42:48 +00:00
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
mentions: overrideProps.mentions,
direction: overrideProps.direction || 'incoming',
showConversation: action('showConversation'),
text: overrideProps.text || '',
2020-09-16 22:42:48 +00:00
});
2022-11-18 00:45:19 +00:00
export function NoMentions(): JSX.Element {
2020-09-16 22:42:48 +00:00
const props = createProps({
text: 'Hello World',
});
return <AtMentionify {...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 MultipleMentions(): JSX.Element {
const mentions = [
2020-09-16 22:42:48 +00:00
{
start: 4,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_1,
2020-09-16 22:42:48 +00:00
replacementText: 'Professor Farnsworth',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
{
start: 2,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_2,
2020-09-16 22:42:48 +00:00
replacementText: 'Philip J Fry',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
{
start: 0,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_3,
2020-09-16 22:42:48 +00:00
replacementText: 'Yancy Fry',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
];
const props = createProps({
mentions,
2020-09-16 22:42:48 +00:00
direction: 'outgoing',
text: AtMentionify.preprocessMentions('\uFFFC \uFFFC \uFFFC', mentions),
2020-09-16 22:42:48 +00:00
});
return <AtMentionify {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-09-16 22:42:48 +00:00
2022-11-18 00:45:19 +00:00
export function ComplexMentions(): JSX.Element {
const mentions = [
2020-09-16 22:42:48 +00:00
{
start: 80,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_4,
2020-09-16 22:42:48 +00:00
replacementText: 'Cereal Killer',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
{
start: 78,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_5,
2020-09-16 22:42:48 +00:00
replacementText: 'Acid Burn',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
{
start: 4,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_6,
2020-09-16 22:42:48 +00:00
replacementText: 'Zero Cool',
2022-11-10 04:59:36 +00:00
conversationID: 'x',
2020-09-16 22:42:48 +00:00
},
];
const props = createProps({
mentions,
2020-09-16 22:42:48 +00:00
text: AtMentionify.preprocessMentions(
'Hey \uFFFC\nCheck out https://www.signal.org I think you will really like it 😍\n\ncc \uFFFC \uFFFC',
mentions
2020-09-16 22:42:48 +00:00
),
});
return <AtMentionify {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function WithOddCharacter(): JSX.Element {
const mentions = [
{
start: 4,
length: 1,
2023-08-16 20:54:39 +00:00
mentionAci: SERVICE_ID_6,
replacementText: 'Zero Cool',
conversationID: 'x',
},
];
const props = createProps({
mentions,
text: AtMentionify.preprocessMentions(
'Hey \uFFFC - Check out │https://www.signal.org│',
mentions
),
});
return <AtMentionify {...props} />;
}