PopupMenuItem.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import classNames from 'clsx';
  2. import {
  3. html
  4. } from '../../ui';
  5. /**
  6. * Component that renders a popup menu entry.
  7. *
  8. * @param {string} key
  9. * @param {Object} entry
  10. * @param {boolean} selected
  11. * @param {function} onMouseEnter
  12. * @param {function} onMouseLeave
  13. * @param {function} onAction
  14. */
  15. export default function PopupMenuItem(props) {
  16. const {
  17. entry,
  18. selected,
  19. onMouseEnter,
  20. onMouseLeave,
  21. onAction
  22. } = props;
  23. return html`
  24. <li
  25. class=${ classNames('entry', { selected }) }
  26. data-id=${ entry.id }
  27. title=${ entry.title || entry.label }
  28. onClick=${ onAction }
  29. onMouseEnter=${ onMouseEnter }
  30. onMouseLeave=${ onMouseLeave }
  31. onDragStart=${ (event) => onAction(event, entry, 'dragstart') }
  32. draggable=${ true }
  33. >
  34. <div class="djs-popup-entry-content">
  35. <span
  36. class=${ classNames('djs-popup-entry-name', entry.className) }
  37. >
  38. ${ entry.imageUrl ? html`
  39. <img class="djs-popup-entry-icon" src=${ entry.imageUrl } alt="" />
  40. ` : null }
  41. ${ entry.label ? html`
  42. <span class="djs-popup-label">
  43. ${ entry.label }
  44. </span>
  45. ` : null }
  46. </span>
  47. ${ entry.description && html`
  48. <span
  49. class="djs-popup-entry-description"
  50. title=${ entry.description }
  51. >
  52. ${ entry.description }
  53. </span>
  54. ` }
  55. </div>
  56. ${ entry.documentationRef && html`
  57. <div class="djs-popup-entry-docs">
  58. <a
  59. href="${ entry.documentationRef }"
  60. onClick=${ (event) => event.stopPropagation() }
  61. title="Open element documentation"
  62. target="_blank"
  63. rel="noopener"
  64. >
  65. <svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
  66. <path fill-rule="evenodd" clip-rule="evenodd" d="M10.6368 10.6375V5.91761H11.9995V10.6382C11.9995 10.9973 11.8623 11.3141 11.5878 11.5885C11.3134 11.863 10.9966 12.0002 10.6375 12.0002H1.36266C0.982345 12.0002 0.660159 11.8681 0.396102 11.6041C0.132044 11.34 1.52588e-05 11.0178 1.52588e-05 10.6375V1.36267C1.52588e-05 0.98236 0.132044 0.660173 0.396102 0.396116C0.660159 0.132058 0.982345 2.95639e-05 1.36266 2.95639e-05H5.91624V1.36267H1.36266V10.6375H10.6368ZM12 0H7.2794L7.27873 1.36197H9.68701L3.06507 7.98391L4.01541 8.93425L10.6373 2.31231V4.72059H12V0Z" fill="#818798"/>
  67. </svg>
  68. </a>
  69. </div>
  70. ` }
  71. </li>
  72. `;
  73. }