Migrate AvatarPopup to Storybook
This commit is contained in:
parent
c8e8291da4
commit
cebe72ece7
2 changed files with 82 additions and 48 deletions
|
@ -1,48 +0,0 @@
|
|||
### With avatar
|
||||
|
||||
```jsx
|
||||
<util.ConversationContext theme={util.theme}>
|
||||
<AvatarPopup
|
||||
color="pink"
|
||||
profileName="John Smith"
|
||||
phoneNumber="(800) 555-0001"
|
||||
avatarPath={util.gifObjectUrl}
|
||||
conversationType="direct"
|
||||
onViewPreferences={(...args) => console.log('onViewPreferences', args)}
|
||||
onViewArchive={(...args) => console.log('onViewArchive', args)}
|
||||
i18n={util.i18n}
|
||||
/>
|
||||
</util.ConversationContext>
|
||||
```
|
||||
|
||||
### With no avatar
|
||||
|
||||
```jsx
|
||||
<util.ConversationContext theme={util.theme}>
|
||||
<AvatarPopup
|
||||
color="green"
|
||||
profileName="John Smith"
|
||||
phoneNumber="(800) 555-0001"
|
||||
conversationType="direct"
|
||||
onViewPreferences={(...args) => console.log('onViewPreferences', args)}
|
||||
onViewArchive={(...args) => console.log('onViewArchive', args)}
|
||||
i18n={util.i18n}
|
||||
/>
|
||||
</util.ConversationContext>
|
||||
```
|
||||
|
||||
### With empty profileName
|
||||
|
||||
```jsx
|
||||
<util.ConversationContext theme={util.theme}>
|
||||
<AvatarPopup
|
||||
color="green"
|
||||
profileName={null}
|
||||
phoneNumber="(800) 555-0001"
|
||||
conversationType="direct"
|
||||
onViewPreferences={(...args) => console.log('onViewPreferences', args)}
|
||||
onViewArchive={(...args) => console.log('onViewArchive', args)}
|
||||
i18n={util.i18n}
|
||||
/>
|
||||
</util.ConversationContext>
|
||||
```
|
82
ts/components/AvatarPopup.stories.tsx
Normal file
82
ts/components/AvatarPopup.stories.tsx
Normal file
|
@ -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<string, ColorType> = Colors.reduce(
|
||||
(m, color) => ({
|
||||
...m,
|
||||
[color]: color,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
|
||||
const conversationTypeMap: Record<string, Props['conversationType']> = {
|
||||
direct: 'direct',
|
||||
group: 'group',
|
||||
};
|
||||
|
||||
const createProps = (overrideProps: Partial<Props> = {}): 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 <AvatarPopup {...props} />;
|
||||
});
|
||||
|
||||
stories.add('Title', () => {
|
||||
const props = createProps({
|
||||
title: 'My Great Title',
|
||||
});
|
||||
|
||||
return <AvatarPopup {...props} />;
|
||||
});
|
||||
|
||||
stories.add('Profile Name', () => {
|
||||
const props = createProps({
|
||||
profileName: 'Sam Neill',
|
||||
});
|
||||
|
||||
return <AvatarPopup {...props} />;
|
||||
});
|
||||
|
||||
stories.add('Phone Number', () => {
|
||||
const props = createProps({
|
||||
profileName: 'Sam Neill',
|
||||
phoneNumber: '(555) 867-5309',
|
||||
});
|
||||
|
||||
return <AvatarPopup {...props} />;
|
||||
});
|
Loading…
Add table
Reference in a new issue