exchanges.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org>
  5. */
  6. import * as React from 'react';
  7. import {Button} from 'molstar/lib/mol-plugin-ui/controls/common';
  8. export const DefaultExchanges = [
  9. ['ALA', 'Alanine'],
  10. ['CYS', 'Cysteine'],
  11. ['ASP', 'Aspartic Acid'],
  12. ['GLU', 'Glutamic Acid'],
  13. ['PHE', 'Phenylalanine'],
  14. ['GLY', 'Glycine'],
  15. ['HIS', 'Histidine'],
  16. ['ILE', 'Isoleucine'],
  17. ['LYS', 'Lysine'],
  18. ['LEU', 'Leucine'],
  19. ['MET', 'Methionine'],
  20. ['ASN', 'Asparagine'],
  21. ['PRO', 'Proline'],
  22. ['GLN', 'Glutamine'],
  23. ['ARG', 'Arginine'],
  24. ['SER', 'Serine'],
  25. ['THR', 'Threonine'],
  26. ['VAL', 'Valine'],
  27. ['TRP', 'Tryptophan'],
  28. ['TYR', 'Tyrosine'],
  29. ['A', 'Adenosine'],
  30. ['C', 'Cytidine'],
  31. ['DA', 'Deoxyadenosine'],
  32. ['DC', 'Deoxycytidine'],
  33. ['DG', 'Deoxyguanosine'],
  34. ['G', ',Guanosine'],
  35. ['T', 'Thymidine'],
  36. ['U', 'Uridine']
  37. ];
  38. export class ExchangesControl extends React.PureComponent<{}, { exchanges: Set<string> }> {
  39. state = {
  40. exchanges: new Set<string>()
  41. }
  42. onClickSwatch = (e: React.MouseEvent<HTMLButtonElement>) => {
  43. const tlc = e.currentTarget.getAttribute('data-id')!;
  44. if (this.state.exchanges.has(tlc)) {
  45. this.setState(({ exchanges }) => {
  46. const newExchanges = new Set(exchanges);
  47. newExchanges.delete(tlc);
  48. return {
  49. exchanges: newExchanges
  50. };
  51. });
  52. } else {
  53. this.setState(({ exchanges }) => ({
  54. exchanges: new Set(exchanges).add(tlc)
  55. }));
  56. }
  57. }
  58. swatch() {
  59. // TODO it would be nice to only display relevant exchanges (amino acids for amino acids, nucleotides for nucl)
  60. // TODO update of isSelected style is delayed
  61. return <div className='msp-combined-color-swatch'>
  62. {DefaultExchanges.map(e => {
  63. const isSelected = this.state.exchanges.has(e[0]);
  64. const className = isSelected ? 'msp-control-current' : '';
  65. return <Button key={e[0]} title={e[1]} inline data-id={e[0]} onClick={this.onClickSwatch} style={{ padding: 0, fontSize: '13px' }} className={className}>
  66. {e[0] && isSelected ? <b>{e[0]}</b> : e[0]}
  67. </Button>;
  68. })}
  69. </div>;
  70. }
  71. render() {
  72. return <>
  73. <div className='msp-control-offset'>
  74. {this.swatch()}
  75. </div>
  76. </>;
  77. }
  78. }