You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.0 KiB

package react.product;
import react.ReactDOM;
import react.ReactComponent;
import react.ReactMacro.jsx;
import Common;
import utils.HttpUtil;
/**
* A Product selector
* @author fbarbut
*/
class ProductSelect extends react.ReactComponentOfPropsAndState<{onSelect:ProductInfo->Void,products:Array<ProductInfo>},{selected:Int}>
{
public function new(props)
{
super(props);
state = { selected : null };
}
override public function render(){
var products = props.products.map(function(info){
//var selector = info.id==state.selected ? jsx(''):jsx('<div className="clickable"><$Product productInfo=$info /></div>');
return jsx('<div key=${info.id} className="col-md-6" onClick=${onClick.bind(info.id)}>
<div className="clickable"><$Product productInfo=$info /></div>
</div>');
});
return jsx('<div className="productSelect">${products}</div>');
}
function onClick(i:Int){
this.setState(cast {selected:i});
if(props.onSelect!=null){
var p = Lambda.find(props.products,function(x) return x.id==i);
props.onSelect(p);
}
}
}