2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-20 22:09:46 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { text } from '@storybook/addon-knobs';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props } from './Intl';
|
|
|
|
import { Intl } from './Intl';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2020-08-20 22:09:46 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
const story = storiesOf('Components/Intl', module);
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
|
|
|
i18n,
|
|
|
|
id: text('id', overrideProps.id || 'deleteAndRestart'),
|
|
|
|
components: overrideProps.components,
|
|
|
|
renderText: overrideProps.renderText,
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('No Replacements', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'deleteAndRestart',
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Single String Replacement', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'leftTheGroup',
|
|
|
|
components: ['Theodora'],
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Single Tag Replacement', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'leftTheGroup',
|
2020-09-12 00:46:52 +00:00
|
|
|
components: [
|
|
|
|
<button type="button" key="a-button">
|
|
|
|
Theodora
|
|
|
|
</button>,
|
|
|
|
],
|
2020-08-20 22:09:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Multiple String Replacement', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'changedRightAfterVerify',
|
|
|
|
components: {
|
|
|
|
name1: 'Fred',
|
|
|
|
name2: 'The Fredster',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Multiple Tag Replacement', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'changedRightAfterVerify',
|
|
|
|
components: {
|
|
|
|
name1: <b>Fred</b>,
|
|
|
|
name2: <b>The Fredster</b>,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Custom Render', () => {
|
|
|
|
const props = createProps({
|
|
|
|
id: 'deleteAndRestart',
|
|
|
|
renderText: ({ text: theText, key }) => (
|
|
|
|
<div style={{ backgroundColor: 'purple', color: 'orange' }} key={key}>
|
|
|
|
{theText}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Intl {...props} />;
|
|
|
|
});
|