Files
old-tellall/web/src/components/IntentItem.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-11-30 17:43:24 +01:00
import React, { Component } from 'react';
2017-12-01 11:03:48 +01:00
import {Button} from 'react-md';
2017-11-30 17:43:24 +01:00
import '../css/Intent.css'
import {INTENT_TITLE_MAX_LENGTH, INTENT_TITLE_TOOLTIP_DELAY} from '../config'
2017-11-30 17:43:24 +01:00
class IntentItem extends Component {
constructor(props){
super(props);
this.state={intent: props.intent, index: props.index, onClick: props.onClick};
}
render() {
let buttonTitle = this.state.intent.intentName;
if (buttonTitle.length > INTENT_TITLE_MAX_LENGTH){
buttonTitle = this.state.intent.intentName.substr(0,INTENT_TITLE_MAX_LENGTH-1) + '. . .';
}
2017-12-01 11:03:48 +01:00
return (
<div>
<Button className={this.props.selectedIndex===this.state.index ? 'IntentItem-selected' : 'IntentItem'}
onClick={()=>{this.state.onClick(this.state.intent,this.state.index)}}
flat
tooltipDelay={INTENT_TITLE_TOOLTIP_DELAY}
2017-12-03 17:38:58 +01:00
tooltipLabel={this.state.intent.intentName.length>INTENT_TITLE_MAX_LENGTH ? this.state.intent.questions[0] : ''}>
{this.state.index+1}. {buttonTitle}
2017-12-01 11:03:48 +01:00
</Button>
<br></br>
</div>
2017-11-30 17:43:24 +01:00
);
}
}
export default IntentItem;