// Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { storiesOf } from '@storybook/react'; import { text, withKnobs } from '@storybook/addon-knobs'; import { setupI18n } from '../../util/setupI18n'; import enMessages from '../../../_locales/en/messages.json'; import type { Props } from './MessageBodyHighlight'; import { MessageBodyHighlight } from './MessageBodyHighlight'; const i18n = setupI18n('en', enMessages); const story = storiesOf('Components/MessageBodyHighlight', module); // Storybook types are incorrect // eslint-disable-next-line @typescript-eslint/no-explicit-any story.addDecorator((withKnobs as any)({ escapeHTML: false })); const createProps = (overrideProps: Partial = {}): Props => ({ bodyRanges: overrideProps.bodyRanges || [], i18n, text: text('text', overrideProps.text || ''), }); story.add('Basic', () => { const props = createProps({ text: 'This is before <>Inside<> This is after.', }); return ; }); story.add('No Replacement', () => { const props = createProps({ text: 'All\nplain\ntext šŸ”„ http://somewhere.com', }); return ; }); story.add('Two Replacements', () => { const props = createProps({ text: 'Begin <>Inside #1<> This is between the two <>Inside #2<> End.', }); return ; }); story.add('Two Replacements with an @mention', () => { const props = createProps({ bodyRanges: [ { length: 1, mentionUuid: '0ca40892-7b1a-11eb-9439-0242ac130002', replacementText: 'Jin Sakai', start: 33, }, ], text: 'Begin <>Inside #1<> \uFFFC This is between the two <>Inside #2<> End.', }); return ; }); story.add('Emoji + Newlines + URLs', () => { const props = createProps({ text: '\nhttp://somewhere.com\n\nšŸ”„ Before -- <>A šŸ”„ inside<> -- After šŸ”„', }); return ; }); story.add('No Jumbomoji', () => { const props = createProps({ text: 'šŸ”„', }); return ; });