signal-desktop/ts/components/Intl.stories.tsx

80 lines
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
2022-06-07 00:48:02 +00:00
import type { Meta, Story } from '@storybook/react';
2020-08-20 22:09:46 +00:00
import * as React from 'react';
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);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Intl',
component: Intl,
} as Meta;
2020-08-20 22:09:46 +00:00
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
i18n,
2022-06-07 00:48:02 +00:00
id: overrideProps.id || '',
2020-08-20 22:09:46 +00:00
components: overrideProps.components,
renderText: overrideProps.renderText,
});
// eslint-disable-next-line max-len
// eslint-disable-next-line react/function-component-definition, local-rules/valid-i18n-keys
2022-06-07 00:48:02 +00:00
const Template: Story<Props> = args => <Intl {...args} />;
2020-08-20 22:09:46 +00:00
2022-06-07 00:48:02 +00:00
export const NoReplacements = Template.bind({});
NoReplacements.args = createProps({
id: 'deleteAndRestart',
2020-08-20 22:09:46 +00:00
});
2022-06-07 00:48:02 +00:00
export const SingleStringReplacement = Template.bind({});
SingleStringReplacement.args = createProps({
id: 'leftTheGroup',
2023-03-27 23:37:39 +00:00
components: { name: 'Theodora' },
2020-08-20 22:09:46 +00:00
});
2022-06-07 00:48:02 +00:00
export const SingleTagReplacement = Template.bind({});
SingleTagReplacement.args = createProps({
id: 'leftTheGroup',
2023-03-27 23:37:39 +00:00
components: {
name: (
<button type="button" key="a-button">
Theodora
</button>
),
},
2020-08-20 22:09:46 +00:00
});
2022-06-07 00:48:02 +00:00
export const MultipleStringReplacement = Template.bind({});
MultipleStringReplacement.args = createProps({
id: 'changedRightAfterVerify',
components: {
name1: 'Fred',
name2: 'The Fredster',
},
2020-08-20 22:09:46 +00:00
});
2022-06-07 00:48:02 +00:00
export const MultipleTagReplacement = Template.bind({});
MultipleTagReplacement.args = createProps({
id: 'changedRightAfterVerify',
components: {
name1: <b>Fred</b>,
name2: <b>The Fredster</b>,
},
2020-08-20 22:09:46 +00:00
});
2022-06-07 00:48:02 +00:00
export const CustomRender = Template.bind({});
CustomRender.args = createProps({
id: 'deleteAndRestart',
renderText: ({ text: theText, key }) => (
<div style={{ backgroundColor: 'purple', color: 'orange' }} key={key}>
{theText}
</div>
),
2020-08-20 22:09:46 +00:00
});