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},{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('
<$Product productInfo=$info />
'); return jsx('
<$Product productInfo=$info />
'); }); return jsx('
${products}
'); } 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); } } }