The main server, and probably only repository in this org.
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.

60 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, {useState} from "react";
  2. import {Badge, ButtonDropdown, Col, DropdownItem, DropdownMenu, DropdownToggle, ListGroupItem, Row} from "reactstrap";
  3. import ColorModal from "./Modals/ColorModal";
  4. import {changeColor} from "../Helpers/lights";
  5. import LightPropertiesModal from "./Modals/LightPropertiesModal";
  6. function Light({id, groupId, name, on, color, brightness}) {
  7. const [modal, setModal] = useState(false);
  8. const [dropDown, setDropDown] = useState(false);
  9. const [propModal, setPropModal] = useState(false);
  10. return (
  11. <ListGroupItem>
  12. <Row>
  13. <Col xs={7}>
  14. <ButtonDropdown isOpen={dropDown} toggle={() => setDropDown(!dropDown)}>
  15. <DropdownToggle size="sm" caret outline color="secondary">
  16. {name}
  17. </DropdownToggle>
  18. <DropdownMenu>
  19. <DropdownItem onClick={() => setPropModal(true)}>Egenskaper</DropdownItem>
  20. <DropdownItem>Glem</DropdownItem>
  21. </DropdownMenu>
  22. </ButtonDropdown>
  23. </Col>
  24. <Col xs={3}>
  25. {on && (
  26. <Badge style={{backgroundColor: `#${color}`}} onClick={() => setModal(true)}>
  27. {color.toUpperCase()}
  28. </Badge>
  29. )}
  30. </Col>
  31. <Col xs={2}>
  32. <Badge style={{backgroundColor: `gray(${brightness})`}} onClick={() => setModal(true)}>
  33. {on ? brightness : "Av"}
  34. </Badge>
  35. </Col>
  36. </Row>
  37. {modal && (
  38. <ColorModal cValue={color}
  39. bValue={brightness}
  40. pValue={on}
  41. onConfirm={(newColor, newBrightness, newPower) => {
  42. changeColor(id, newColor, newBrightness, newPower);
  43. setModal(false);
  44. }}
  45. onCancel={() => setModal(false)}
  46. />
  47. )}
  48. {propModal && (
  49. <LightPropertiesModal id={id}
  50. gValue={groupId}
  51. nValue={name}
  52. onClose={() => setPropModal(false)}/>
  53. )}
  54. </ListGroupItem>
  55. );
  56. }
  57. export default Light;