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

78 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-01-27 22:12:26 +00:00
// Copyright 2021-2022 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-08-21 22:03:25 +00:00
import * as React from 'react';
2021-11-01 18:43:02 +00:00
import { text } from '@storybook/addon-knobs';
2020-08-21 22:03:25 +00:00
import { action } from '@storybook/addon-actions';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-08-21 22:03:25 +00:00
import enMessages from '../../_locales/en/messages.json';
import type { PropsType } from './MainHeader';
import { MainHeader } from './MainHeader';
import { ThemeType } from '../types/Util';
2020-08-21 22:03:25 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/MainHeader',
};
2020-08-21 22:03:25 +00:00
const requiredText = (name: string, value: string | undefined) =>
text(name, value || '');
const optionalText = (name: string, value: string | undefined) =>
text(name, value || '') || undefined;
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
2022-03-04 21:14:52 +00:00
areStoriesEnabled: false,
theme: ThemeType.light,
2020-08-21 22:03:25 +00:00
phoneNumber: optionalText('phoneNumber', overrideProps.phoneNumber),
title: requiredText('title', overrideProps.title),
name: optionalText('name', overrideProps.name),
avatarPath: optionalText('avatarPath', overrideProps.avatarPath),
hasPendingUpdate: Boolean(overrideProps.hasPendingUpdate),
2020-08-21 22:03:25 +00:00
i18n,
startUpdate: action('startUpdate'),
2020-08-21 22:03:25 +00:00
showArchivedConversations: action('showArchivedConversations'),
startComposing: action('startComposing'),
2021-07-19 19:26:06 +00:00
toggleProfileEditor: action('toggleProfileEditor'),
2022-03-04 21:14:52 +00:00
toggleStoriesView: action('toggleStoriesView'),
2020-08-21 22:03:25 +00:00
});
2022-06-07 00:48:02 +00:00
export const Basic = (): JSX.Element => {
2020-08-21 22:03:25 +00:00
const props = createProps({});
return <MainHeader {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-21 22:03:25 +00:00
2022-06-07 00:48:02 +00:00
export const Name = (): JSX.Element => {
2020-08-21 22:03:25 +00:00
const props = createProps({
name: 'John Smith',
title: 'John Smith',
});
return <MainHeader {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-21 22:03:25 +00:00
2022-06-07 00:48:02 +00:00
export const PhoneNumber = (): JSX.Element => {
2020-08-21 22:03:25 +00:00
const props = createProps({
name: 'John Smith',
phoneNumber: '+15553004000',
});
return <MainHeader {...props} />;
2022-06-07 00:48:02 +00:00
};
2020-08-21 22:03:25 +00:00
2022-06-07 00:48:02 +00:00
export const UpdateAvailable = (): JSX.Element => {
const props = createProps({ hasPendingUpdate: true });
return <MainHeader {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-03-04 21:14:52 +00:00
2022-06-07 00:48:02 +00:00
export const Stories = (): JSX.Element => (
2022-03-04 21:14:52 +00:00
<MainHeader {...createProps({})} areStoriesEnabled />
2022-06-07 00:48:02 +00:00
);