2021-08-06 00:17:05 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { chunk } from 'lodash';
|
|
|
|
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType } from './AvatarPreview';
|
|
|
|
import { AvatarPreview } from './AvatarPreview';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { AvatarColors } from '../types/Colors';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2021-08-06 00:17:05 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const TEST_IMAGE = new Uint8Array(
|
|
|
|
chunk(
|
|
|
|
'89504e470d0a1a0a0000000d4948445200000008000000080103000000fec12cc800000006504c5445ff00ff00ff000c82e9800000001849444154085b633061a8638863a867f8c720c760c12000001a4302f4d81dd9870000000049454e44ae426082',
|
|
|
|
2
|
|
|
|
).map(bytePair => parseInt(bytePair.join(''), 16))
|
2021-09-24 00:49:05 +00:00
|
|
|
);
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
|
|
|
avatarColor: overrideProps.avatarColor,
|
|
|
|
avatarPath: overrideProps.avatarPath,
|
|
|
|
avatarValue: overrideProps.avatarValue,
|
|
|
|
conversationTitle: overrideProps.conversationTitle,
|
|
|
|
i18n,
|
|
|
|
isEditable: Boolean(overrideProps.isEditable),
|
|
|
|
isGroup: Boolean(overrideProps.isGroup),
|
|
|
|
onAvatarLoaded: action('onAvatarLoaded'),
|
|
|
|
onClear: action('onClear'),
|
|
|
|
onClick: action('onClick'),
|
|
|
|
style: overrideProps.style,
|
|
|
|
});
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/AvatarPreview',
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function NoStatePersonal(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({
|
|
|
|
avatarColor: AvatarColors[0],
|
|
|
|
conversationTitle: 'Just Testing',
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
NoStatePersonal.story = {
|
|
|
|
name: 'No state (personal)',
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function NoStateGroup(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({
|
|
|
|
avatarColor: AvatarColors[1],
|
|
|
|
isGroup: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
NoStateGroup.story = {
|
|
|
|
name: 'No state (group)',
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function NoStateGroupUploadMe(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({
|
|
|
|
avatarColor: AvatarColors[1],
|
|
|
|
isEditable: true,
|
|
|
|
isGroup: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
NoStateGroupUploadMe.story = {
|
|
|
|
name: 'No state (group) + upload me',
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Value(): JSX.Element {
|
|
|
|
return <AvatarPreview {...createProps({ avatarValue: TEST_IMAGE })} />;
|
|
|
|
}
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
Value.story = {
|
|
|
|
name: 'value',
|
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Path(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({ avatarPath: '/fixtures/kitten-3-64-64.jpg' })}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
Path.story = {
|
|
|
|
name: 'path',
|
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function ValuePath(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({
|
|
|
|
avatarPath: '/fixtures/kitten-3-64-64.jpg',
|
|
|
|
avatarValue: TEST_IMAGE,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
ValuePath.story = {
|
|
|
|
name: 'value & path',
|
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Style(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<AvatarPreview
|
|
|
|
{...createProps({
|
|
|
|
avatarValue: TEST_IMAGE,
|
|
|
|
style: { height: 100, width: 100 },
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
Style.story = {
|
|
|
|
name: 'style',
|
|
|
|
};
|