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

114 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-05-07 22:21:10 +00:00
// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-17 18:57:17 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import { boolean, select, text } from '@storybook/addon-knobs';
import type { Props } from './AvatarPopup';
import { AvatarPopup } from './AvatarPopup';
import type { AvatarColorType } from '../types/Colors';
import { AvatarColors } from '../types/Colors';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-08-17 18:57:17 +00:00
import enMessages from '../../_locales/en/messages.json';
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
import { getFakeBadge } from '../test-both/helpers/getFakeBadge';
2020-08-17 18:57:17 +00:00
const i18n = setupI18n('en', enMessages);
2021-05-28 16:15:17 +00:00
const colorMap: Record<string, AvatarColorType> = AvatarColors.reduce(
2020-08-17 18:57:17 +00:00
(m, color) => ({
...m,
[color]: color,
}),
{}
);
const conversationTypeMap: Record<string, Props['conversationType']> = {
direct: 'direct',
group: 'group',
};
const useProps = (overrideProps: Partial<Props> = {}): Props => ({
2021-05-07 22:21:10 +00:00
acceptedMessageRequest: true,
2020-08-17 18:57:17 +00:00
avatarPath: text('avatarPath', overrideProps.avatarPath || ''),
badge: overrideProps.badge,
2021-08-06 00:17:05 +00:00
color: select('color', colorMap, overrideProps.color || AvatarColors[0]),
2020-08-17 18:57:17 +00:00
conversationType: select(
'conversationType',
conversationTypeMap,
overrideProps.conversationType || 'direct'
),
hasPendingUpdate: Boolean(overrideProps.hasPendingUpdate),
2020-08-17 18:57:17 +00:00
i18n,
2021-05-07 22:21:10 +00:00
isMe: true,
2020-08-17 18:57:17 +00:00
noteToSelf: boolean('noteToSelf', overrideProps.noteToSelf || false),
2021-07-19 19:26:06 +00:00
onEditProfile: action('onEditProfile'),
2020-08-17 18:57:17 +00:00
onViewArchive: action('onViewArchive'),
onViewPreferences: action('onViewPreferences'),
phoneNumber: text('phoneNumber', overrideProps.phoneNumber || ''),
profileName: text('profileName', overrideProps.profileName || ''),
2021-05-07 22:21:10 +00:00
sharedGroupNames: [],
startUpdate: action('startUpdate'),
2020-08-17 18:57:17 +00:00
style: {},
theme: React.useContext(StorybookThemeContext),
2020-08-17 18:57:17 +00:00
title: text('title', overrideProps.title || ''),
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Avatar Popup',
};
2020-08-17 18:57:17 +00:00
2022-11-18 00:45:19 +00:00
export function AvatarOnly(): JSX.Element {
const props = useProps();
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-11-18 00:45:19 +00:00
export function HasBadge(): JSX.Element {
const props = useProps({
badge: getFakeBadge(),
title: 'Janet Yellen',
});
2020-08-17 18:57:17 +00:00
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
HasBadge.story = {
name: 'Has badge',
};
2020-08-17 18:57:17 +00:00
2022-11-18 00:45:19 +00:00
export function Title(): JSX.Element {
const props = useProps({
2020-08-17 18:57:17 +00:00
title: 'My Great Title',
});
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-17 18:57:17 +00:00
2022-11-18 00:45:19 +00:00
export function ProfileName(): JSX.Element {
const props = useProps({
2020-08-17 18:57:17 +00:00
profileName: 'Sam Neill',
});
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-17 18:57:17 +00:00
2022-11-18 00:45:19 +00:00
export function PhoneNumber(): JSX.Element {
const props = useProps({
2020-08-17 18:57:17 +00:00
profileName: 'Sam Neill',
phoneNumber: '(555) 867-5309',
});
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-11-18 00:45:19 +00:00
export function UpdateAvailable(): JSX.Element {
const props = useProps({
hasPendingUpdate: true,
});
return <AvatarPopup {...props} />;
2022-11-18 00:45:19 +00:00
}