UniprotRowMarkComponent.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2021 RCSB PDB and contributors, licensed under MIT, See LICENSE file for more info.
  3. * @author Joan Segura Mora <joan.segura@rcsb.org>
  4. */
  5. import React from "react";
  6. import classes from '../../../../../styles/UniprotPfvStyle.module.scss';
  7. import {Property} from "csstype";
  8. import {asyncScheduler} from "rxjs";
  9. interface UniprotRowMarkInterface {
  10. isGlowing:boolean;
  11. clickCallback?:()=>void;
  12. hoverCallback?:()=>void;
  13. }
  14. interface UniprotRowMarkState {
  15. visibility: Property.Visibility | undefined;
  16. borderLeftColor: Property.BorderLeftColor | undefined;
  17. }
  18. export class UniprotRowMarkComponent extends React.Component <UniprotRowMarkInterface,UniprotRowMarkState> {
  19. private readonly HOVER_COLOR: string = "#666";
  20. private readonly ACTIVE_COLOR: string = "#ccc";
  21. readonly state: UniprotRowMarkState = {
  22. visibility: undefined,
  23. borderLeftColor: undefined
  24. }
  25. public render(): JSX.Element {
  26. return (
  27. <>
  28. <div onClick={this.click.bind(this)} onMouseOver={this.hover.bind(this)} style={{visibility: this.state.visibility, cursor:"pointer", display:"inline-block", width:6, height:6, marginBottom: 4, marginRight:5}} >
  29. <div className={classes.uniprotRowMark} style={{borderLeftColor: this.props.isGlowing ? this.HOVER_COLOR : (this.state.borderLeftColor)}}/>
  30. </div>
  31. </>
  32. );
  33. }
  34. private click(): void {
  35. this.setState({visibility: this.state.visibility === "visible" ? undefined : "visible", borderLeftColor: this.state.visibility === "visible" ? undefined : this.ACTIVE_COLOR});
  36. asyncScheduler.schedule(()=>this.props.clickCallback?.());
  37. }
  38. private hover(): void {
  39. this.props.hoverCallback?.();
  40. }
  41. }