2018-02-20 09:30:36 +00:00
|
|
|
/* @flow */
|
|
|
|
'use strict';
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
children: React.Node,
|
|
|
|
className: string,
|
|
|
|
isDisabled: boolean,
|
|
|
|
isFocused: boolean,
|
|
|
|
isSelected: boolean,
|
|
|
|
onFocus: Function,
|
|
|
|
onSelect: Function,
|
|
|
|
option: any,
|
|
|
|
}
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
export default class CoinSelectOption extends React.Component<Props> {
|
|
|
|
constructor(props: Props) {
|
2018-02-20 09:30:36 +00:00
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
handleMouseDown(event: MouseEvent) {
|
2018-02-20 09:30:36 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
this.props.onSelect(this.props.option, event);
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
handleMouseEnter(event: MouseEvent) {
|
2018-02-20 09:30:36 +00:00
|
|
|
this.props.onFocus(this.props.option, event);
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
handleMouseMove(event: MouseEvent) {
|
2018-02-20 09:30:36 +00:00
|
|
|
if (this.props.isFocused) return;
|
|
|
|
this.props.onFocus(this.props.option, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const css = `${this.props.className} ${this.props.option.value}`;
|
|
|
|
return (
|
|
|
|
<div className={ css }
|
|
|
|
onMouseDown={ this.handleMouseDown.bind(this) }
|
|
|
|
onMouseEnter={ this.handleMouseEnter.bind(this) }
|
|
|
|
onMouseMove={ this.handleMouseMove.bind(this) }
|
|
|
|
title={ this.props.option.label }>
|
|
|
|
<span>{ this.props.children }</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-04-16 21:19:50 +00:00
|
|
|
}
|