1 | import React from 'react';
|
2 | import {storiesOf} from '@storybook/html';
|
3 |
|
4 | import reactDecorator from '../../.storybook/react-decorator';
|
5 | import hubConfig from '../../.storybook/hub-config';
|
6 | import {UserCard, UserCardTooltip, SmartUserCardTooltip} from '../user-card/user-card';
|
7 | import Auth from '../auth/auth';
|
8 | import {createHubUserCardSource} from '../hub-source/hub-source__user';
|
9 |
|
10 | storiesOf('Components|User Card', module).
|
11 | addParameters({
|
12 | notes: 'A component that displays user details.'
|
13 | }).
|
14 | addDecorator(reactDecorator()).
|
15 | add('inline', () => {
|
16 | const user = {
|
17 | login: 'testuser',
|
18 | name: 'Test User',
|
19 | email: 'testuser@mail.com',
|
20 | avatarUrl: `${hubConfig.serverUri}/api/rest/avatar/default?username=Jet%20Brains`,
|
21 | href: `${hubConfig.serverUri}/users/0`
|
22 | };
|
23 |
|
24 | return (
|
25 | <div>
|
26 | <div>Inline user card:</div>
|
27 | <UserCard user={user} data-test="user-card-inline"/>
|
28 |
|
29 | <UserCardTooltip user={user}>
|
30 | <span>Hover this text see card in tooltip mode</span>
|
31 | </UserCardTooltip>
|
32 | </div>
|
33 | );
|
34 | }).
|
35 | add('smart tooltip', () => {
|
36 | const user = {
|
37 | login: 'testuser',
|
38 | name: 'Test User',
|
39 | email: 'testuser@mail.com',
|
40 | avatarUrl: `${hubConfig.serverUri}/api/rest/avatar/default?username=Jet%20Brains`,
|
41 | href: `${hubConfig.serverUri}/users/0`,
|
42 | banned: true,
|
43 | online: false,
|
44 | banReason: 'Bad guy: is accused of stealing potatoes'
|
45 | };
|
46 |
|
47 | async function loadUser() {
|
48 | return new Promise(resolve => setTimeout(resolve, 10000)).
|
49 | then(() => user);
|
50 | }
|
51 |
|
52 | return (
|
53 | <SmartUserCardTooltip userDataSource={loadUser}>
|
54 | <span>Hover this text load user information</span>
|
55 | </SmartUserCardTooltip>
|
56 | );
|
57 | }, {hermione: {skip: true}}).
|
58 | add('hub user card', () => {
|
59 | const auth = new Auth(hubConfig);
|
60 |
|
61 | const waitForAuthAndGetUser = async () => {
|
62 | await auth.init();
|
63 | const userSource = createHubUserCardSource(auth, auth.user.id);
|
64 | return userSource();
|
65 | };
|
66 |
|
67 | return (
|
68 | <SmartUserCardTooltip userDataSource={waitForAuthAndGetUser}>
|
69 | <span>Hover this text load user information</span>
|
70 | </SmartUserCardTooltip>
|
71 | );
|
72 | }, {hermione: {skip: true}});
|