2021-03-03 20:09:58 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { times } from 'lodash';
|
|
|
|
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2021-03-03 20:09:58 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
import { ContactPills } from './ContactPills';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType as ContactPillPropsType } from './ContactPill';
|
|
|
|
import { ContactPill } from './ContactPill';
|
2021-03-03 20:09:58 +00:00
|
|
|
import { gifUrl } from '../storybook/Fixtures';
|
2021-05-07 22:21:10 +00:00
|
|
|
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/Contact Pills',
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
type ContactType = Omit<ContactPillPropsType, 'i18n' | 'onClickRemove'>;
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const contacts: Array<ContactType> = times(50, index =>
|
|
|
|
getDefaultConversation({
|
|
|
|
id: `contact-${index}`,
|
|
|
|
name: `Contact ${index}`,
|
|
|
|
phoneNumber: '(202) 555-0001',
|
|
|
|
profileName: `C${index}`,
|
|
|
|
title: `Contact ${index}`,
|
|
|
|
})
|
|
|
|
);
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
const contactPillProps = (
|
|
|
|
overrideProps?: ContactType
|
|
|
|
): ContactPillPropsType => ({
|
2021-09-03 21:39:46 +00:00
|
|
|
...(overrideProps ??
|
2021-05-07 22:21:10 +00:00
|
|
|
getDefaultConversation({
|
|
|
|
avatarPath: gifUrl,
|
|
|
|
firstName: 'John',
|
|
|
|
id: 'abc123',
|
|
|
|
isMe: false,
|
|
|
|
name: 'John Bon Bon Jovi',
|
|
|
|
phoneNumber: '(202) 555-0001',
|
|
|
|
profileName: 'JohnB',
|
|
|
|
title: 'John Bon Bon Jovi',
|
|
|
|
})),
|
2021-03-03 20:09:58 +00:00
|
|
|
i18n,
|
|
|
|
onClickRemove: action('onClickRemove'),
|
|
|
|
});
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const EmptyList = (): JSX.Element => <ContactPills />;
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
EmptyList.story = {
|
|
|
|
name: 'Empty list',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const OneContact = (): JSX.Element => (
|
2021-03-03 20:09:58 +00:00
|
|
|
<ContactPills>
|
|
|
|
<ContactPill {...contactPillProps()} />
|
|
|
|
</ContactPills>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
OneContact.story = {
|
|
|
|
name: 'One contact',
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const ThreeContacts = (): JSX.Element => (
|
2021-03-03 20:09:58 +00:00
|
|
|
<ContactPills>
|
|
|
|
<ContactPill {...contactPillProps(contacts[0])} />
|
|
|
|
<ContactPill {...contactPillProps(contacts[1])} />
|
|
|
|
<ContactPill {...contactPillProps(contacts[2])} />
|
|
|
|
</ContactPills>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
ThreeContacts.story = {
|
|
|
|
name: 'Three contacts',
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const FourContactsOneWithALongName = (): JSX.Element => (
|
2021-03-03 20:09:58 +00:00
|
|
|
<ContactPills>
|
|
|
|
<ContactPill {...contactPillProps(contacts[0])} />
|
|
|
|
<ContactPill
|
|
|
|
{...contactPillProps({
|
|
|
|
...contacts[1],
|
|
|
|
title:
|
|
|
|
'Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso',
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<ContactPill {...contactPillProps(contacts[2])} />
|
|
|
|
<ContactPill {...contactPillProps(contacts[3])} />
|
|
|
|
</ContactPills>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FourContactsOneWithALongName.story = {
|
|
|
|
name: 'Four contacts, one with a long name',
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const FiftyContacts = (): JSX.Element => (
|
2021-03-03 20:09:58 +00:00
|
|
|
<ContactPills>
|
|
|
|
{contacts.map(contact => (
|
|
|
|
<ContactPill key={contact.id} {...contactPillProps(contact)} />
|
|
|
|
))}
|
|
|
|
</ContactPills>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FiftyContacts.story = {
|
|
|
|
name: 'Fifty contacts',
|
|
|
|
};
|