| 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 |
9x
11x
2x
1x
1x
1x
1x
1x
1x
1x
1x
7x
7x
7x
7x
7x
1x
20x
20x
20x
30x
20x
20x
30x
89x
89x
| import React from 'react';
import PropTypes from 'prop-types';
import { omit } from 'lodash';
import { EventOverlay, Button } from '@collab-ui/react';
/**
* @category communication
* @component coachmark
* @variations collab-ui-react
*/
class Coachmark extends React.Component {
static displayName = 'Coachmark';
state = {
isOpen: this.props.isOpen
};
componentDidMount() {
this.props.isOpen &&
this.delayedShow();
}
componentDidUpdate(prevProps) {
if (prevProps.isOpen !== this.props.isOpen) {
return this.props.isOpen
? this.delayedShow()
: this.delayedHide();
}
}
componentWillUnmount() {
this.hideTimerId && clearTimeout(this.hideTimerId);
this.showTimerId && clearTimeout(this.showTimerId);
}
delayedHide = e => {
const { onClick } = this.props;
Iif (this.showTimerId) {
clearTimeout(this.showTimerId);
this.showTimerId = null;
}
const delay = this.props.hideDelay
? this.props.hideDelay
: this.props.delay;
this.hideTimerId = setTimeout(() => {
this.hideTimerId = null;
this.setState(() => {
onClick && onClick(e);
return { isOpen: false };
});
}, delay);
};
delayedShow = () => {
Iif (this.hideTimerId) {
clearTimeout(this.hideTimerId);
this.hideTimerId = null;
}
const delay = this.props.showDelay
? this.props.showDelay
: this.props.delay;
this.showTimerId = setTimeout(() => {
this.showTimerId = null;
this.setState({ isOpen: true });
}, delay);
};
handleClose = () => {
this.setState({ isOpen: false });
};
render() {
const {
allowClickAway,
buttonChildren,
className,
children,
closeOnClick,
contentNode,
direction,
header,
maxWidth,
onClick,
subheader,
...props
} = this.props;
const otherProps = omit({...props}, ['delay', 'hideDelay', 'isOpen', 'showDelay']);
const anchorWithRef =
children && React.cloneElement(children, {
ref: ele => this.anchorRef = ele
});
const content = (
<div className='cui-coachmark__container'>
{
contentNode
? contentNode
: [
header && <div className='cui-coachmark__header' key='content-0'>{header}</div>,
subheader && <div className='cui-coachmark__subheader' key='content-1'>{subheader}</div>,
onClick && <Button onClick={this.delayedHide} {...otherProps} key='content-2'>{buttonChildren}</Button>
]
}
</div>
);
return (
<div className='cui-coachmark'>
{anchorWithRef}
<EventOverlay
ref={ref => this.overlay = ref}
allowClickAway={allowClickAway}
anchorNode={this.anchorRef}
isOpen={this.state.isOpen}
className={className}
showArrow
direction={direction}
close={this.handleClose}
closeOnClick={closeOnClick}
{...maxWidth && {maxWidth: maxWidth}}
>
{content}
</EventOverlay>
</div>
);
}
}
Coachmark.defaultProps = {
allowClickAway: false,
buttonChildren: null,
children: null,
className: '',
closeOnClick: false,
contentNode: null,
delay: 0,
direction: 'top-center',
header: '',
hideDelay: 0,
isOpen: false,
maxWidth: null,
onClick: null,
showDelay: 0,
subheader: '',
};
Coachmark.propTypes = {
/** @prop Allows user to click outside of element | false */
allowClickAway: PropTypes.bool,
/** @prop Button nodes within Coachmark | null */
buttonChildren: PropTypes.node,
/** @prop Optional css class string | '' */
className: PropTypes.string,
/** @prop Children nodes to render inside Coachmark | null */
children: PropTypes.node.isRequired,
/** @prop Allows Coachmark to be closed by a click from the user | false */
closeOnClick: PropTypes.bool,
/** @prop Node with content that populates the Coachmark | null */
contentNode: PropTypes.node,
/** @prop Sets the time the timer is delayed | 0 */
delay: PropTypes.number,
/** @prop Sets the direction the Coachmark opens up | 'top-center' */
direction: PropTypes.oneOf([
'top-center',
'top-left',
'top-right',
'left-center',
'left-top',
'left-bottom',
'bottom-center',
'bottom-left',
'bottom-right',
'right-center',
'right-top',
'right-bottom'
]),
/** @prop Sets the header node of Coachmark | '' */
header: PropTypes.node,
/** @prop Sets the time delay to hide the Coachmark | 0 */
hideDelay: PropTypes.number,
/** @prop Sets the initial visibility of Coachmark | false */
isOpen: PropTypes.bool,
/** @prop Sets the maximum width of Coachmark | null */
maxWidth: PropTypes.number,
/** @prop Handler to be called when the user clicks the Coachmark | null */
onClick: PropTypes.func,
/** @prop Shows visibility of the delay value | 0 */
showDelay: PropTypes.number,
/** @prop Sets the subheader node of the Coachmark | '' */
subheader: PropTypes.node,
};
export default Coachmark;
/**
* @name Coachmark Default
*
* @category communication
* @component coachmark
* @section default
*
* @js
import {
Avatar,
Button,
Coachmark,
SpaceListItem,
} from '@collab-ui/react';
export default class CoachmarkDefault extends React.Component {
state = {
openFirst: true,
openNext: false,
openLast: false
}
render() {
const {openFirst, openNext, openLast} = this.state;
return (
<div style={{display: 'flex', flexFlow: 'row nowrap', justifyContent: 'space-between'}}>
<Coachmark
isOpen={openFirst}
maxWidth={272}
onClick={() => this.setState({openFirst: false, openNext: true})}
buttonChildren={'Got It'}
header={`Header prop(node)`}
subheader={`Subheader prop(node)`}
direction='bottom-center'
ariaLabel='Open Coachmark 1'
>
<Button ariaLabel='test' onClick={() => this.setState({openFirst: true, openNext: false, openLast: false})}>Coachmark Anchor</Button>
</Coachmark>
<Coachmark
isOpen={openNext}
onClick={() => this.setState({openLast: true, openNext: false})}
buttonChildren={'Click for next Coachmark'}
header={`Header prop(node)`}
direction='top-center'
ariaLabel='Open Coachmark 2'
>
<Button ariaLabel='test' onClick={() => this.setState({openFirst: false, openNext: true, openLast: false})}>2nd Coachmark Anchor</Button>
</Coachmark>
<Coachmark isOpen={openLast}
contentNode={<div>contentNode prop(node)</div>}
direction='bottom-center'
ariaLabel='Open Coachmark 3'
>
<Button ariaLabel='test' onClick={() => this.setState({openFirst: false, openNext: false, openLast: true})}>3rd Coachmark Anchor</Button>
</Coachmark>
</div>
);
}
}
**/
|