signal-desktop/ts/components/conversation/ConversationHeader.stories.tsx

384 lines
9.6 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import type { ComponentProps } from 'react';
2021-11-02 23:01:13 +00:00
import React, { useContext } from 'react';
import { action } from '@storybook/addon-actions';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../../test-both/helpers/getDefaultConversation';
2021-08-06 00:17:05 +00:00
import { getRandomColor } from '../../test-both/helpers/getRandomColor';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2022-11-16 20:18:02 +00:00
import { DurationInSeconds } from '../../util/durations';
2020-09-14 19:51:27 +00:00
import enMessages from '../../../_locales/en/messages.json';
2021-11-02 23:01:13 +00:00
import { StorybookThemeContext } from '../../../.storybook/StorybookThemeContext';
import {
ConversationHeader,
OutgoingCallButtonStyle,
} from './ConversationHeader';
2020-04-06 16:48:58 +00:00
import { gifUrl } from '../../storybook/Fixtures';
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/ConversationHeader',
};
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
type ItemsType = Array<{
title: string;
2022-06-07 00:48:02 +00:00
props: Omit<ComponentProps<typeof ConversationHeader>, 'theme'>;
}>;
2020-10-30 17:52:21 +00:00
const commonProps = {
2021-05-07 22:21:10 +00:00
...getDefaultConversation(),
cannotLeaveBecauseYouAreLastAdmin: false,
2020-10-30 17:52:21 +00:00
showBackButton: false,
outgoingCallButtonStyle: OutgoingCallButtonStyle.Both,
2020-10-30 17:52:21 +00:00
i18n,
setDisappearingMessages: action('setDisappearingMessages'),
destroyMessages: action('destroyMessages'),
leaveGroup: action('leaveGroup'),
2020-06-04 18:16:19 +00:00
onOutgoingAudioCallInConversation: action(
'onOutgoingAudioCallInConversation'
),
onOutgoingVideoCallInConversation: action(
'onOutgoingVideoCallInConversation'
),
onArchive: action('onArchive'),
onMarkUnread: action('onMarkUnread'),
2023-03-20 22:23:53 +00:00
toggleSelectMode: action('toggleSelectMode'),
onMoveToInbox: action('onMoveToInbox'),
pushPanelForConversation: action('pushPanelForConversation'),
popPanelForConversation: action('popPanelForConversation'),
searchInConversation: action('searchInConversation'),
setMuteExpiration: action('onSetMuteNotifications'),
2022-12-07 01:00:02 +00:00
setPinned: action('setPinned'),
2022-07-22 00:44:35 +00:00
viewUserStories: action('viewUserStories'),
};
2022-11-18 00:45:19 +00:00
export function PrivateConvo(): JSX.Element {
2022-06-07 00:48:02 +00:00
const items: ItemsType = [
{
title: 'With name and profile, verified',
props: {
...commonProps,
color: getRandomColor(),
isVerified: true,
avatarPath: gifUrl,
title: 'Someone 🔥 Somewhere',
name: 'Someone 🔥 Somewhere',
phoneNumber: '(202) 555-0001',
type: 'direct',
id: '1',
profileName: '🔥Flames🔥',
acceptedMessageRequest: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'With name, not verified, no avatar',
props: {
...commonProps,
color: getRandomColor(),
isVerified: false,
title: 'Someone 🔥 Somewhere',
name: 'Someone 🔥 Somewhere',
phoneNumber: '(202) 555-0002',
type: 'direct',
id: '2',
acceptedMessageRequest: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'With name, not verified, descenders',
props: {
...commonProps,
color: getRandomColor(),
isVerified: false,
title: 'Joyrey 🔥 Leppey',
name: 'Joyrey 🔥 Leppey',
phoneNumber: '(202) 555-0002',
type: 'direct',
id: '3',
acceptedMessageRequest: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'Profile, no name',
props: {
...commonProps,
color: getRandomColor(),
isVerified: false,
phoneNumber: '(202) 555-0003',
type: 'direct',
id: '4',
title: '🔥Flames🔥',
profileName: '🔥Flames🔥',
acceptedMessageRequest: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'No name, no profile, no color',
props: {
...commonProps,
title: '(202) 555-0011',
phoneNumber: '(202) 555-0011',
type: 'direct',
id: '5',
acceptedMessageRequest: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'With back button',
props: {
...commonProps,
showBackButton: true,
color: getRandomColor(),
phoneNumber: '(202) 555-0004',
title: '(202) 555-0004',
type: 'direct',
id: '6',
acceptedMessageRequest: true,
2021-03-01 20:08:37 +00:00
},
2022-06-07 00:48:02 +00:00
},
{
title: 'Disappearing messages set',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0005',
phoneNumber: '(202) 555-0005',
type: 'direct',
id: '7',
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(10),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
2020-08-27 19:45:08 +00:00
},
2022-06-07 00:48:02 +00:00
},
{
title: 'Disappearing messages + verified',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0005',
phoneNumber: '(202) 555-0005',
type: 'direct',
id: '8',
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(300),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
isVerified: true,
canChangeTimer: true,
},
2022-06-07 00:48:02 +00:00
},
{
title: 'Muting Conversation',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0006',
phoneNumber: '(202) 555-0006',
type: 'direct',
id: '9',
acceptedMessageRequest: true,
muteExpiresAt: new Date('3000-10-18T11:11:11Z').valueOf(),
},
2022-06-07 00:48:02 +00:00
},
{
title: 'SMS-only conversation',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0006',
phoneNumber: '(202) 555-0006',
type: 'direct',
id: '10',
acceptedMessageRequest: true,
isSMSOnly: true,
},
2022-06-07 00:48:02 +00:00
},
];
const theme = useContext(StorybookThemeContext);
return (
<>
{items.map(({ title: subtitle, props }, i) => {
return (
<div key={i}>
{subtitle ? <h3>{subtitle}</h3> : null}
<ConversationHeader {...props} theme={theme} />
</div>
);
})}
</>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
PrivateConvo.story = {
name: '1:1 conversation',
};
2022-11-18 00:45:19 +00:00
export function Group(): JSX.Element {
2022-06-07 00:48:02 +00:00
const items: ItemsType = [
{
title: 'Basic',
props: {
...commonProps,
color: getRandomColor(),
title: 'Typescript support group',
name: 'Typescript support group',
phoneNumber: '',
id: '11',
type: 'group',
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(10),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.JustVideo,
2020-11-20 17:19:28 +00:00
},
2022-06-07 00:48:02 +00:00
},
{
title: 'In a group you left - no disappearing messages',
props: {
...commonProps,
color: getRandomColor(),
title: 'Typescript support group',
name: 'Typescript support group',
phoneNumber: '',
id: '12',
type: 'group',
left: true,
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(10),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.JustVideo,
2021-04-09 16:19:38 +00:00
},
2022-06-07 00:48:02 +00:00
},
{
title: 'In a group with an active group call',
props: {
...commonProps,
color: getRandomColor(),
title: 'Typescript support group',
name: 'Typescript support group',
phoneNumber: '',
id: '13',
type: 'group',
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(10),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.Join,
2020-05-27 21:37:06 +00:00
},
2022-06-07 00:48:02 +00:00
},
{
title: 'In a forever muted group',
props: {
...commonProps,
color: getRandomColor(),
title: 'Way too many messages',
name: 'Way too many messages',
phoneNumber: '',
id: '14',
type: 'group',
2022-11-16 20:18:02 +00:00
expireTimer: DurationInSeconds.fromSeconds(10),
2022-06-07 00:48:02 +00:00
acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.JustVideo,
muteExpiresAt: Infinity,
},
2022-06-07 00:48:02 +00:00
},
];
2022-06-07 00:48:02 +00:00
const theme = useContext(StorybookThemeContext);
2021-11-02 23:01:13 +00:00
2022-06-07 00:48:02 +00:00
return (
<>
{items.map(({ title: subtitle, props }, i) => {
return (
<div key={i}>
{subtitle ? <h3>{subtitle}</h3> : null}
2021-11-02 23:01:13 +00:00
<ConversationHeader {...props} theme={theme} />
</div>
);
2022-06-07 00:48:02 +00:00
})}
</>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
Group.story = {
name: 'In a group',
};
2022-11-18 00:45:19 +00:00
function NoteToSelf() {
2022-06-07 00:48:02 +00:00
const items: ItemsType = [
{
title: 'In chat with yourself',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0007',
phoneNumber: '(202) 555-0007',
id: '15',
type: 'direct',
isMe: true,
acceptedMessageRequest: true,
outgoingCallButtonStyle: OutgoingCallButtonStyle.None,
},
2021-11-02 23:01:13 +00:00
},
2022-06-07 00:48:02 +00:00
];
const theme = useContext(StorybookThemeContext);
return (
<>
{items.map(({ title: subtitle, props }, i) => {
return (
<div key={i}>
{subtitle ? <h3>{subtitle}</h3> : null}
<ConversationHeader {...props} theme={theme} />
</div>
);
})}
</>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
NoteToSelf.story = {
name: 'Note to Self',
};
2022-11-18 00:45:19 +00:00
function Unaccepted() {
2022-06-07 00:48:02 +00:00
const items: ItemsType = [
{
2022-06-07 00:48:02 +00:00
title: '1:1 conversation',
props: {
...commonProps,
color: getRandomColor(),
title: '(202) 555-0007',
phoneNumber: '(202) 555-0007',
id: '16',
type: 'direct',
isMe: false,
acceptedMessageRequest: false,
outgoingCallButtonStyle: OutgoingCallButtonStyle.None,
},
},
];
const theme = useContext(StorybookThemeContext);
return (
<>
{items.map(({ title: subtitle, props }, i) => {
return (
<div key={i}>
{subtitle ? <h3>{subtitle}</h3> : null}
<ConversationHeader {...props} theme={theme} />
</div>
);
})}
</>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
Unaccepted.story = {
name: 'Unaccepted',
};