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.

40 lines
1.0 KiB

  1. package react.product;
  2. import react.ReactDOM;
  3. import react.ReactComponent;
  4. import react.ReactMacro.jsx;
  5. import Common;
  6. import utils.HttpUtil;
  7. /**
  8. * A Product selector
  9. * @author fbarbut
  10. */
  11. class ProductSelect extends react.ReactComponentOfPropsAndState<{onSelect:ProductInfo->Void,products:Array<ProductInfo>},{selected:Int}>
  12. {
  13. public function new(props)
  14. {
  15. super(props);
  16. state = { selected : null };
  17. }
  18. override public function render(){
  19. var products = props.products.map(function(info){
  20. //var selector = info.id==state.selected ? jsx(''):jsx('<div className="clickable"><$Product productInfo=$info /></div>');
  21. return jsx('<div key=${info.id} className="col-md-6" onClick=${onClick.bind(info.id)}>
  22. <div className="clickable"><$Product productInfo=$info /></div>
  23. </div>');
  24. });
  25. return jsx('<div className="productSelect">${products}</div>');
  26. }
  27. function onClick(i:Int){
  28. this.setState(cast {selected:i});
  29. if(props.onSelect!=null){
  30. var p = Lambda.find(props.products,function(x) return x.id==i);
  31. props.onSelect(p);
  32. }
  33. }
  34. }