From b8cc7e81075b29def5338bbec6f31d0127958ad6 Mon Sep 17 00:00:00 2001 From: Sidney Keese Date: Fri, 21 Aug 2020 15:03:25 -0700 Subject: [PATCH] Migrate MainHeader to Storybook --- ts/components/MainHeader.md | 100 ------------------------ ts/components/MainHeader.stories.tsx | 110 +++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 100 deletions(-) delete mode 100644 ts/components/MainHeader.md create mode 100644 ts/components/MainHeader.stories.tsx diff --git a/ts/components/MainHeader.md b/ts/components/MainHeader.md deleted file mode 100644 index 80032a17d3..0000000000 --- a/ts/components/MainHeader.md +++ /dev/null @@ -1,100 +0,0 @@ -Note that this component is controlled, so the text in the search box will only update -if the parent of this component feeds the updated `searchTerm` back. - -#### With image - -```jsx - - console.log('search', text)} - updateSearchTerm={text => console.log('updateSearchTerm', text)} - clearSearch={() => console.log('clearSearch')} - i18n={util.i18n} - /> - -``` - -#### Just name - -```jsx - - console.log('search', text)} - updateSearchTerm={text => console.log('updateSearchTerm', text)} - clearSearch={() => console.log('clearSearch')} - i18n={util.i18n} - /> - -``` - -#### Just phone number - -```jsx - - console.log('search', text)} - updateSearchTerm={text => console.log('updateSearchTerm', text)} - clearSearch={() => console.log('clearSearch')} - i18n={util.i18n} - /> - -``` - -#### Starting with a search term - -```jsx - - console.log('search', text)} - updateSearchTerm={text => console.log('updateSearchTerm', text)} - clearSearch={() => console.log('clearSearch')} - i18n={util.i18n} - /> - -``` - -#### Searching within conversation - -```jsx - - console.log('search', args)} - updateSearchTerm={(...args) => console.log('updateSearchTerm', args)} - clearSearch={(...args) => console.log('clearSearch', args)} - i18n={util.i18n} - /> - -``` - -#### Searching within conversation, with search term - -```jsx - - console.log('search', args)} - updateSearchTerm={(...args) => console.log('updateSearchTerm', args)} - clearSearch={(...args) => console.log('clearSearch', args)} - i18n={util.i18n} - /> - -``` diff --git a/ts/components/MainHeader.stories.tsx b/ts/components/MainHeader.stories.tsx new file mode 100644 index 0000000000..f1b57afc98 --- /dev/null +++ b/ts/components/MainHeader.stories.tsx @@ -0,0 +1,110 @@ +import * as React from 'react'; +import { storiesOf } from '@storybook/react'; +import { text, withKnobs } from '@storybook/addon-knobs'; +import { action } from '@storybook/addon-actions'; + +// @ts-ignore +import { setup as setupI18n } from '../../js/modules/i18n'; +// @ts-ignore +import enMessages from '../../_locales/en/messages.json'; + +import { MainHeader, PropsType } from './MainHeader'; + +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; + +story.addDecorator((withKnobs as any)({ escapeHTML: false })); + +const createProps = (overrideProps: Partial = {}): PropsType => ({ + searchTerm: requiredText('searchTerm', overrideProps.searchTerm), + searchConversationName: optionalText( + 'searchConversationName', + overrideProps.searchConversationName + ), + searchConversationId: optionalText( + 'searchConversationId', + overrideProps.searchConversationId + ), + startSearchCounter: 0, + + ourConversationId: '', + ourUuid: '', + ourNumber: '', + regionCode: '', + + phoneNumber: optionalText('phoneNumber', overrideProps.phoneNumber), + title: requiredText('title', overrideProps.title), + name: optionalText('name', overrideProps.name), + avatarPath: optionalText('avatarPath', overrideProps.avatarPath), + + i18n, + updateSearchTerm: action('updateSearchTerm'), + searchMessages: action('searchMessages'), + searchDiscussions: action('searchDiscussions'), + + clearConversationSearch: action('clearConversationSearch'), + clearSearch: action('clearSearch'), + + showArchivedConversations: action('showArchivedConversations'), +}); + +story.add('Basic', () => { + const props = createProps({}); + + return ; +}); + +story.add('Name', () => { + const props = createProps({ + name: 'John Smith', + title: 'John Smith', + }); + + return ; +}); + +story.add('Phone Number', () => { + const props = createProps({ + name: 'John Smith', + phoneNumber: '+15553004000', + }); + + return ; +}); + +story.add('Search Term', () => { + const props = createProps({ + name: 'John Smith', + searchTerm: 'Hewwo?', + title: 'John Smith', + }); + + return ; +}); + +story.add('Searching Conversation', () => { + const props = createProps({ + name: 'John Smith', + searchConversationId: 'group-id-1', + searchConversationName: 'Everyone', + }); + + return ; +}); + +story.add('Searching Conversation with Term', () => { + const props = createProps({ + name: 'John Smith', + searchTerm: 'address', + searchConversationId: 'group-id-1', + searchConversationName: 'Everyone', + }); + + return ; +});