forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoachmark.stories.tsx
119 lines (115 loc) · 3.32 KB
/
Coachmark.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as React from 'react';
import { Steps, StoryWright } from 'storywright';
import { storiesOf } from '@storybook/react';
import { TestWrapperDecorator } from '../utilities/index';
import { Coachmark, DirectionalHint, TeachingBubbleContent, Fabric } from '@fluentui/react';
import { useId } from '@fluentui/react-hooks';
import { DefaultButton } from '@fluentui/react/lib/Button';
const directionalHints = [
DirectionalHint.topLeftEdge,
DirectionalHint.topCenter,
DirectionalHint.topRightEdge,
DirectionalHint.bottomLeftEdge,
DirectionalHint.bottomCenter,
DirectionalHint.bottomRightEdge,
DirectionalHint.leftTopEdge,
DirectionalHint.leftCenter,
DirectionalHint.leftBottomEdge,
DirectionalHint.rightTopEdge,
DirectionalHint.rightCenter,
DirectionalHint.rightBottomEdge,
];
const CoachmarkUsage = ({
isCollapsed = true,
directionalHint = DirectionalHint.rightTopEdge,
}: {
isCollapsed?: boolean;
directionalHint?: DirectionalHint;
}) => {
const targetId = useId();
return (
<>
<div id={targetId}>
<DefaultButton text="Click me!" />
</div>
<Coachmark
target={`#${targetId}`}
positioningContainerProps={{
directionalHint,
doNotLayer: false,
}}
ariaAlertText="A Coachmark has appeared"
ariaDescribedBy={'coachmark-desc1'}
ariaLabelledBy={'coachmark-label1'}
ariaDescribedByText={'Press enter or alt + C to open the Coachmark notification'}
ariaLabelledByText={'Coachmark notification'}
isCollapsed={isCollapsed}
>
<TeachingBubbleContent
headline="Example Title"
hasCloseButton={true}
closeButtonAriaLabel="Close"
primaryButtonProps={{
text: 'Try it',
}}
secondaryButtonProps={{
text: 'Try it',
}}
ariaDescribedBy={'example-description1'}
ariaLabelledBy={'example-label1'}
>
Welcome to the land of Coachmarks!
</TeachingBubbleContent>
</Coachmark>
</>
);
};
storiesOf('Coachmark', module)
.addDecorator(TestWrapperDecorator)
.addDecorator(story =>
// prettier-ignore
<StoryWright
steps={new Steps()
.snapshot('default', { cropTo: '.ms-PositioningContainer' })
.end()}
>
{story()}
</StoryWright>,
)
.addStory('Collapsed', () => (
<Fabric>
<CoachmarkUsage />
</Fabric>
))
.addStory('Rendering Coachmark attached to a rectangle', () => {
const rectangle = {
left: 50,
right: 150,
top: 50,
bottom: 100,
};
const divStyles: React.CSSProperties = {
background: 'red',
position: 'absolute',
left: rectangle.left,
top: rectangle.top,
width: rectangle.right - rectangle.left,
height: rectangle.bottom - rectangle.top,
};
const positioningContainerProps = { directionalHint: DirectionalHint.topCenter };
return (
<>
<div style={divStyles} />
<Coachmark target={rectangle} positioningContainerProps={positioningContainerProps} />
</>
);
})
.addStory('Positioning', () => {
return (
<div>
{directionalHints.map((directionalHint, index) => (
<CoachmarkUsage isCollapsed={false} directionalHint={directionalHint} key={index} />
))}
</div>
);
});