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

225 lines
5.4 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
2020-08-26 18:06:48 +00:00
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
2020-08-26 18:06:48 +00:00
import { pngUrl } from '../../storybook/Fixtures';
import type { Props } from './Image';
import { CurveType, Image } from './Image';
2020-08-26 18:06:48 +00:00
import { IMAGE_PNG } from '../../types/MIME';
2021-10-27 19:49:58 +00:00
import type { ThemeType } from '../../types/Util';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
2020-08-26 18:06:48 +00:00
import enMessages from '../../../_locales/en/messages.json';
2021-10-27 19:49:58 +00:00
import { StorybookThemeContext } from '../../../.storybook/StorybookThemeContext';
2020-09-14 19:51:27 +00:00
import { fakeAttachment } from '../../test-both/helpers/fakeAttachment';
2020-08-26 18:06:48 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/Image',
} satisfies Meta<Props>;
2020-08-26 18:06:48 +00:00
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
alt: overrideProps.alt || '',
attachment:
overrideProps.attachment ||
fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
url: pngUrl,
}),
blurHash: overrideProps.blurHash || '',
bottomOverlay: overrideProps.bottomOverlay || false,
closeButton: overrideProps.closeButton || false,
curveBottomLeft: overrideProps.curveBottomLeft || CurveType.None,
curveBottomRight: overrideProps.curveBottomRight || CurveType.None,
curveTopLeft: overrideProps.curveTopLeft || CurveType.None,
curveTopRight: overrideProps.curveTopRight || CurveType.None,
darkOverlay: overrideProps.darkOverlay || false,
height: overrideProps.height || 100,
2020-08-26 18:06:48 +00:00
i18n,
noBackground: overrideProps.noBackground || false,
noBorder: overrideProps.noBorder || false,
2020-08-26 18:06:48 +00:00
onClick: action('onClick'),
onClickClose: action('onClickClose'),
onError: action('onError'),
overlayText: overrideProps.overlayText || '',
playIconOverlay: overrideProps.playIconOverlay || false,
tabIndex: overrideProps.tabIndex || 0,
theme: overrideProps.theme || ('light' as ThemeType),
url: 'url' in overrideProps ? overrideProps.url || '' : pngUrl,
width: overrideProps.width || 100,
2020-08-26 18:06:48 +00:00
});
2022-11-18 00:45:19 +00:00
export function UrlWithHeightWidth(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps();
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function Caption(): JSX.Element {
2020-08-26 18:06:48 +00:00
const defaultProps = createProps();
const props = {
...defaultProps,
attachment: {
...defaultProps.attachment,
caption: '<Saxophone Pun>',
},
};
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function PlayIcon(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
playIconOverlay: true,
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function CloseButton(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
closeButton: true,
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function NoBorderOrBackground(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
attachment: fakeAttachment({
2020-08-26 18:06:48 +00:00
contentType: IMAGE_PNG,
fileName: 'sax.png',
url: pngUrl,
}),
2020-08-26 18:06:48 +00:00
noBackground: true,
noBorder: true,
url: pngUrl,
});
return (
<div style={{ backgroundColor: '#999' }}>
<Image {...props} />
</div>
);
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function Pending(): JSX.Element {
2022-06-07 00:48:02 +00:00
const props = createProps({
attachment: fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
url: pngUrl,
pending: true,
}),
});
2020-08-26 18:06:48 +00:00
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function PendingWBlurhash(): JSX.Element {
2022-06-07 00:48:02 +00:00
const props = createProps({
attachment: fakeAttachment({
contentType: IMAGE_PNG,
fileName: 'sax.png',
url: pngUrl,
pending: true,
}),
});
2021-01-29 22:58:28 +00:00
return (
<Image
{...props}
blurHash="LDA,FDBnm+I=p{tkIUI;~UkpELV]"
width={300}
height={400}
/>
);
2022-11-18 00:45:19 +00:00
}
2021-01-29 22:58:28 +00:00
2022-11-18 00:45:19 +00:00
export function CurvedCorners(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
curveBottomLeft: CurveType.Normal,
curveBottomRight: CurveType.Normal,
curveTopLeft: CurveType.Normal,
curveTopRight: CurveType.Normal,
2020-08-26 18:06:48 +00:00
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function SmallCurveTopLeft(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
curveTopLeft: CurveType.Small,
2020-08-26 18:06:48 +00:00
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function SoftCorners(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
curveBottomLeft: CurveType.Tiny,
curveBottomRight: CurveType.Tiny,
curveTopLeft: CurveType.Tiny,
curveTopRight: CurveType.Tiny,
2020-08-26 18:06:48 +00:00
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function BottomOverlay(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
bottomOverlay: true,
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-08-26 18:06:48 +00:00
2022-11-18 00:45:19 +00:00
export function FullOverlayWithText(): JSX.Element {
2020-08-26 18:06:48 +00:00
const props = createProps({
darkOverlay: true,
overlayText: 'Honk!',
});
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function Blurhash(): JSX.Element {
2020-08-26 18:06:48 +00:00
const defaultProps = createProps();
const props = {
...defaultProps,
blurHash: 'thisisafakeblurhashthatwasmadeup',
};
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}
2021-01-29 22:58:28 +00:00
2022-11-18 00:45:19 +00:00
function UndefinedBlurHashWrapper() {
const theme = React.useContext(StorybookThemeContext);
const props = createProps({
blurHash: undefined,
theme,
url: undefined,
});
2022-11-18 00:45:19 +00:00
return <Image {...props} />;
}
2022-11-18 00:45:19 +00:00
export function UndefinedBlurHash(): JSX.Element {
return <UndefinedBlurHashWrapper />;
}
2022-11-18 00:45:19 +00:00
export function MissingImage(): JSX.Element {
2020-08-26 18:06:48 +00:00
const defaultProps = createProps();
const props = {
...defaultProps,
2020-09-14 19:51:27 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020-08-26 18:06:48 +00:00
attachment: undefined as any,
};
return <Image {...props} />;
2022-11-18 00:45:19 +00:00
}