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

97 lines
2.6 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
2020-10-15 19:53:21 +00:00
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { CallingParticipantsList, PropsType } from './CallingParticipantsList';
2020-11-17 15:07:53 +00:00
import { Colors } from '../types/Colors';
import { GroupCallRemoteParticipantType } from '../types/Calling';
2020-10-15 19:53:21 +00:00
import { setup as setupI18n } from '../../js/modules/i18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2020-11-17 15:07:53 +00:00
function createParticipant(
participantProps: Partial<GroupCallRemoteParticipantType>
): GroupCallRemoteParticipantType {
const randomColor = Math.floor(Math.random() * Colors.length - 1);
return {
avatarPath: participantProps.avatarPath,
color: Colors[randomColor],
demuxId: 2,
2020-11-17 15:07:53 +00:00
hasRemoteAudio: Boolean(participantProps.hasRemoteAudio),
hasRemoteVideo: Boolean(participantProps.hasRemoteVideo),
isSelf: Boolean(participantProps.isSelf),
2020-11-20 19:39:50 +00:00
name: participantProps.name,
2020-11-17 15:07:53 +00:00
profileName: participantProps.title,
title: String(participantProps.title),
videoAspectRatio: 1.3,
2020-11-17 15:07:53 +00:00
};
}
2020-10-15 19:53:21 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
i18n,
onClose: action('on-close'),
2020-11-17 15:07:53 +00:00
participants: overrideProps.participants || [],
2020-10-15 19:53:21 +00:00
});
const story = storiesOf('Components/CallingParticipantsList', module);
2020-11-17 15:07:53 +00:00
story.add('No one', () => {
2020-10-15 19:53:21 +00:00
const props = createProps();
return <CallingParticipantsList {...props} />;
});
2020-11-17 15:07:53 +00:00
story.add('Solo Call', () => {
const props = createProps({
participants: [
createParticipant({
title: 'Bardock',
}),
],
});
return <CallingParticipantsList {...props} />;
});
2020-10-15 19:53:21 +00:00
story.add('Many Participants', () => {
const props = createProps({
participants: [
2020-11-17 15:07:53 +00:00
createParticipant({
isSelf: true,
2020-10-15 19:53:21 +00:00
title: 'Son Goku',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
hasRemoteVideo: true,
2020-11-20 19:39:50 +00:00
name: 'Rage Trunks',
2020-10-15 19:53:21 +00:00
title: 'Rage Trunks',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
2020-10-15 19:53:21 +00:00
title: 'Prince Vegeta',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
hasRemoteAudio: true,
hasRemoteVideo: true,
2020-11-20 19:39:50 +00:00
name: 'Goku Black',
2020-10-15 19:53:21 +00:00
title: 'Goku Black',
2020-11-17 15:07:53 +00:00
}),
createParticipant({
2020-10-15 19:53:21 +00:00
title: 'Supreme Kai Zamasu',
2020-11-17 15:07:53 +00:00
}),
2020-10-15 19:53:21 +00:00
],
});
return <CallingParticipantsList {...props} />;
});
2020-11-20 17:19:53 +00:00
story.add('Overflow', () => {
const props = createProps({
participants: Array(50)
.fill(null)
.map(() => createParticipant({ title: 'Kirby' })),
});
return <CallingParticipantsList {...props} />;
});