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

108 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-05-28 16:15:17 +00:00
// Copyright 2021 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';
import { storiesOf } from '@storybook/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';
2021-11-01 18:43:02 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
import { ThemeType } from '../types/Util';
2020-08-21 22:03:25 +00:00
const i18n = setupI18n('en', enMessages);
const story = storiesOf('Components/MainHeader', module);
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 => ({
searchTerm: requiredText('searchTerm', overrideProps.searchTerm),
2021-11-01 18:43:02 +00:00
searchConversation: overrideProps.searchConversation,
selectedConversation: undefined,
2020-08-21 22:03:25 +00:00
startSearchCounter: 0,
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,
2020-08-21 22:03:25 +00:00
updateSearchTerm: action('updateSearchTerm'),
clearConversationSearch: action('clearConversationSearch'),
clearSearch: action('clearSearch'),
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'),
2020-08-21 22:03:25 +00:00
});
story.add('Basic', () => {
const props = createProps({});
return <MainHeader {...props} />;
});
story.add('Name', () => {
const props = createProps({
name: 'John Smith',
title: 'John Smith',
});
return <MainHeader {...props} />;
});
story.add('Phone Number', () => {
const props = createProps({
name: 'John Smith',
phoneNumber: '+15553004000',
});
return <MainHeader {...props} />;
});
story.add('Search Term', () => {
const props = createProps({
name: 'John Smith',
searchTerm: 'Hewwo?',
title: 'John Smith',
});
return <MainHeader {...props} />;
});
story.add('Searching Conversation', () => {
const props = createProps({
name: 'John Smith',
2021-11-01 18:43:02 +00:00
searchConversation: getDefaultConversation(),
2020-08-21 22:03:25 +00:00
});
return <MainHeader {...props} />;
});
story.add('Searching Conversation with Term', () => {
const props = createProps({
name: 'John Smith',
searchTerm: 'address',
2021-11-01 18:43:02 +00:00
searchConversation: getDefaultConversation(),
2020-08-21 22:03:25 +00:00
});
return <MainHeader {...props} />;
});
story.add('Update Available', () => {
const props = createProps({ hasPendingUpdate: true });
return <MainHeader {...props} />;
});