forked from chinchang/web-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.jsx
42 lines (35 loc) · 987 Bytes
/
common.jsx
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
import { h, Component } from 'preact';
import { trackEvent } from '../analytics';
class Clickable extends Component {
handleClick(e) {
const el = e.currentTarget;
trackEvent(
el.getAttribute('data-event-category'),
el.getAttribute('data-event-action')
);
this.props.onClick(e);
}
render() {
/* eslint-disable no-unused-vars */
const { onClick, Tag, ...props } = this.props;
/* eslint-enable no-unused-vars */
return <Tag onClick={this.handleClick.bind(this)} {...props} />;
}
}
export function A(props) {
return <Clickable Tag={'a'} {...props} />;
}
export function Button(props) {
return <Clickable Tag={'button'} {...props} />;
}
export function AutoFocusInput(props) {
return (
<input ref={el => el && setTimeout(() => el.focus(), 100)} {...props} />
);
}
export function Divider(props) {
return <div class={`divider ${props.vertical ? 'divider--vertical' : ''}`} />;
}
export function BetaTag() {
return <span class="beta-tag">Beta</span>;
}