2021-04-27 13:20:17 +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-13 20:53:45 +00:00
|
|
|
import * as React from 'react';
|
2021-04-30 19:40:25 +00:00
|
|
|
import { isBoolean } from 'lodash';
|
2020-08-13 20:53:45 +00:00
|
|
|
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
import { boolean, select, text } from '@storybook/addon-knobs';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
2021-04-27 13:20:17 +00:00
|
|
|
import { Avatar, AvatarBlur, Props } from './Avatar';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2020-08-13 20:53:45 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { AvatarColors, AvatarColorType } from '../types/Colors';
|
2020-08-13 20:53:45 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const story = storiesOf('Components/Avatar', module);
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
const colorMap: Record<string, AvatarColorType> = AvatarColors.reduce(
|
2020-08-13 20:53:45 +00:00
|
|
|
(m, color) => ({
|
|
|
|
...m,
|
|
|
|
[color]: color,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
const conversationTypeMap: Record<string, Props['conversationType']> = {
|
|
|
|
direct: 'direct',
|
|
|
|
group: 'group',
|
|
|
|
};
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
2021-04-30 19:40:25 +00:00
|
|
|
acceptedMessageRequest: isBoolean(overrideProps.acceptedMessageRequest)
|
|
|
|
? overrideProps.acceptedMessageRequest
|
|
|
|
: true,
|
2020-08-13 20:53:45 +00:00
|
|
|
avatarPath: text('avatarPath', overrideProps.avatarPath || ''),
|
2021-04-27 13:20:17 +00:00
|
|
|
blur: overrideProps.blur,
|
2021-08-06 00:17:05 +00:00
|
|
|
color: select('color', colorMap, overrideProps.color || AvatarColors[0]),
|
2020-08-13 20:53:45 +00:00
|
|
|
conversationType: select(
|
|
|
|
'conversationType',
|
|
|
|
conversationTypeMap,
|
|
|
|
overrideProps.conversationType || 'direct'
|
|
|
|
),
|
|
|
|
i18n,
|
2021-05-07 22:21:10 +00:00
|
|
|
isMe: false,
|
2021-01-29 22:16:48 +00:00
|
|
|
loading: boolean('loading', overrideProps.loading || false),
|
2020-08-13 20:53:45 +00:00
|
|
|
name: text('name', overrideProps.name || ''),
|
|
|
|
noteToSelf: boolean('noteToSelf', overrideProps.noteToSelf || false),
|
|
|
|
onClick: action('onClick'),
|
|
|
|
phoneNumber: text('phoneNumber', overrideProps.phoneNumber || ''),
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames: [],
|
2020-08-13 20:53:45 +00:00
|
|
|
size: 80,
|
2021-04-21 16:32:23 +00:00
|
|
|
title: overrideProps.title || '',
|
2020-08-13 20:53:45 +00:00
|
|
|
});
|
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
const sizes: Array<Props['size']> = [112, 96, 80, 52, 32, 28];
|
2020-08-13 20:53:45 +00:00
|
|
|
|
|
|
|
story.add('Avatar', () => {
|
|
|
|
const props = createProps({
|
|
|
|
avatarPath: '/fixtures/giphy-GVNvOUpeYmI7e.gif',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
2021-05-10 17:50:04 +00:00
|
|
|
story.add('Wide image', () => {
|
|
|
|
const props = createProps({
|
|
|
|
avatarPath: '/fixtures/wide.jpg',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
2020-08-13 20:53:45 +00:00
|
|
|
story.add('One-word Name', () => {
|
|
|
|
const props = createProps({
|
2021-04-21 16:32:23 +00:00
|
|
|
title: 'John',
|
2020-08-13 20:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
2021-04-21 16:32:23 +00:00
|
|
|
story.add('Two-word Name', () => {
|
2020-08-13 20:53:45 +00:00
|
|
|
const props = createProps({
|
2021-04-21 16:32:23 +00:00
|
|
|
title: 'John Smith',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Wide initials', () => {
|
|
|
|
const props = createProps({
|
|
|
|
title: 'Walter White',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Three-word name', () => {
|
|
|
|
const props = createProps({
|
|
|
|
title: 'Walter H. White',
|
2020-08-13 20:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Note to Self', () => {
|
|
|
|
const props = createProps({
|
|
|
|
noteToSelf: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Contact Icon', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Group Icon', () => {
|
|
|
|
const props = createProps({
|
|
|
|
conversationType: 'group',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Colors', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
return AvatarColors.map(color => (
|
|
|
|
<Avatar key={color} {...props} color={color} />
|
|
|
|
));
|
2020-08-13 20:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Broken Color', () => {
|
|
|
|
const props = createProps({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: 'nope' as AvatarColorType,
|
2020-08-13 20:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Broken Avatar', () => {
|
|
|
|
const props = createProps({
|
|
|
|
avatarPath: 'badimage.png',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Broken Avatar for Group', () => {
|
|
|
|
const props = createProps({
|
|
|
|
avatarPath: 'badimage.png',
|
|
|
|
conversationType: 'group',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
2021-01-29 22:16:48 +00:00
|
|
|
|
|
|
|
story.add('Loading', () => {
|
|
|
|
const props = createProps({
|
|
|
|
loading: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
2021-04-27 13:20:17 +00:00
|
|
|
|
2021-04-30 19:40:25 +00:00
|
|
|
story.add('Blurred based on props', () => {
|
|
|
|
const props = createProps({
|
|
|
|
acceptedMessageRequest: false,
|
|
|
|
avatarPath: '/fixtures/kitten-3-64-64.jpg',
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Force-blurred', () => {
|
2021-04-27 13:20:17 +00:00
|
|
|
const props = createProps({
|
|
|
|
avatarPath: '/fixtures/kitten-3-64-64.jpg',
|
|
|
|
blur: AvatarBlur.BlurPicture,
|
|
|
|
});
|
|
|
|
|
|
|
|
return sizes.map(size => <Avatar key={size} {...props} size={size} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Blurred with "click to view"', () => {
|
|
|
|
const props = createProps({
|
|
|
|
avatarPath: '/fixtures/kitten-3-64-64.jpg',
|
|
|
|
blur: AvatarBlur.BlurPictureWithClickToView,
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Avatar {...props} size={112} />;
|
|
|
|
});
|