Migrate MessageBodyHighlight to storybook

This commit is contained in:
Sidney Keese 2020-08-20 15:17:43 -07:00 committed by Josh Perez
parent f1d04f4751
commit 2de4a3177a
3 changed files with 64 additions and 42 deletions

View file

@ -1,41 +0,0 @@
Basic replacement
```jsx
<MessageBodyHighlight
text="This is before <<left>>Inside<<right>> This is after."
i18n={util.i18n}
/>
```
With no replacement
```jsx
<MessageBodyHighlight
text="All\nplain\ntext 🔥 http://somewhere.com"
i18n={util.i18n}
/>
```
With two replacements
```jsx
<MessageBodyHighlight
text="Begin <<left>>Inside #1<<right>> This is between the two <<left>>Inside #2<<right>> End."
i18n={util.i18n}
/>
```
With emoji, newlines, and URLs
```jsx
<MessageBodyHighlight
text="http://somewhere.com\n\n🔥 Before -- <<left>>A 🔥 inside<<right>> -- After 🔥"
i18n={util.i18n}
/>
```
No jumbomoji
```jsx
<MessageBodyHighlight text="🔥" i18n={util.i18n} />
```

View file

@ -0,0 +1,63 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { text, withKnobs } from '@storybook/addon-knobs';
// @ts-ignore
import { setup as setupI18n } from '../../js/modules/i18n';
// @ts-ignore
import enMessages from '../../_locales/en/messages.json';
import { MessageBodyHighlight, Props } from './MessageBodyHighlight';
const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/MessageBodyHighlight', module);
story.addDecorator((withKnobs as any)({ escapeHTML: false }));
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
i18n,
text: text('text', overrideProps.text || ''),
});
story.add('Basic', () => {
const props = createProps({
text: 'This is before <<left>>Inside<<right>> This is after.',
});
return <MessageBodyHighlight {...props} />;
});
story.add('No Replacement', () => {
const props = createProps({
text: 'All\nplain\ntext 🔥 http://somewhere.com',
});
return <MessageBodyHighlight {...props} />;
});
story.add('Two Replacements', () => {
const props = createProps({
text:
'Begin <<left>>Inside #1<<right>> This is between the two <<left>>Inside #2<<right>> End.',
});
return <MessageBodyHighlight {...props} />;
});
story.add('Emoji + Newlines + URLs', () => {
const props = createProps({
text:
'\nhttp://somewhere.com\n\n🔥 Before -- <<left>>A 🔥 inside<<right>> -- After 🔥',
});
return <MessageBodyHighlight {...props} />;
});
story.add('No Jumbomoji', () => {
const props = createProps({
text: '🔥',
});
return <MessageBodyHighlight {...props} />;
});

View file

@ -8,7 +8,7 @@ import { SizeClassType } from './emoji/lib';
import { LocalizerType, RenderTextCallbackType } from '../types/Util';
interface Props {
export interface Props {
text: string;
i18n: LocalizerType;
}