From cebe72ece7f914aab636dc60ed5171190bae58ad Mon Sep 17 00:00:00 2001 From: Chris Svenningsen Date: Mon, 17 Aug 2020 11:57:17 -0700 Subject: [PATCH] Migrate AvatarPopup to Storybook --- ts/components/AvatarPopup.md | 48 ---------------- ts/components/AvatarPopup.stories.tsx | 82 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 48 deletions(-) delete mode 100644 ts/components/AvatarPopup.md create mode 100644 ts/components/AvatarPopup.stories.tsx diff --git a/ts/components/AvatarPopup.md b/ts/components/AvatarPopup.md deleted file mode 100644 index 72d9c962314..00000000000 --- a/ts/components/AvatarPopup.md +++ /dev/null @@ -1,48 +0,0 @@ -### With avatar - -```jsx - - console.log('onViewPreferences', args)} - onViewArchive={(...args) => console.log('onViewArchive', args)} - i18n={util.i18n} - /> - -``` - -### With no avatar - -```jsx - - console.log('onViewPreferences', args)} - onViewArchive={(...args) => console.log('onViewArchive', args)} - i18n={util.i18n} - /> - -``` - -### With empty profileName - -```jsx - - console.log('onViewPreferences', args)} - onViewArchive={(...args) => console.log('onViewArchive', args)} - i18n={util.i18n} - /> - -``` diff --git a/ts/components/AvatarPopup.stories.tsx b/ts/components/AvatarPopup.stories.tsx new file mode 100644 index 00000000000..586423c00c5 --- /dev/null +++ b/ts/components/AvatarPopup.stories.tsx @@ -0,0 +1,82 @@ +import * as React from 'react'; + +import { storiesOf } from '@storybook/react'; +import { action } from '@storybook/addon-actions'; +import { AvatarPopup, Props } from './AvatarPopup'; +import { Colors, ColorType } from '../types/Colors'; +import { boolean, select, text } from '@storybook/addon-knobs'; + +// @ts-ignore +import { setup as setupI18n } from '../../js/modules/i18n'; + +// @ts-ignore +import enMessages from '../../_locales/en/messages.json'; + +const i18n = setupI18n('en', enMessages); + +const colorMap: Record = Colors.reduce( + (m, color) => ({ + ...m, + [color]: color, + }), + {} +); + +const conversationTypeMap: Record = { + direct: 'direct', + group: 'group', +}; + +const createProps = (overrideProps: Partial = {}): Props => ({ + avatarPath: text('avatarPath', overrideProps.avatarPath || ''), + color: select('color', colorMap, overrideProps.color || 'blue'), + conversationType: select( + 'conversationType', + conversationTypeMap, + overrideProps.conversationType || 'direct' + ), + i18n, + name: text('name', overrideProps.name || ''), + noteToSelf: boolean('noteToSelf', overrideProps.noteToSelf || false), + onClick: action('onClick'), + onViewArchive: action('onViewArchive'), + onViewPreferences: action('onViewPreferences'), + phoneNumber: text('phoneNumber', overrideProps.phoneNumber || ''), + profileName: text('profileName', overrideProps.profileName || ''), + size: 80, + style: {}, + title: text('title', overrideProps.title || ''), +}); + +const stories = storiesOf('Components/Avatar Popup', module); + +stories.add('Avatar Only', () => { + const props = createProps(); + + return ; +}); + +stories.add('Title', () => { + const props = createProps({ + title: 'My Great Title', + }); + + return ; +}); + +stories.add('Profile Name', () => { + const props = createProps({ + profileName: 'Sam Neill', + }); + + return ; +}); + +stories.add('Phone Number', () => { + const props = createProps({ + profileName: 'Sam Neill', + phoneNumber: '(555) 867-5309', + }); + + return ; +});