BxBaseIconsetLucide.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Basic Lucide iconset representation.
  11. * @see BxDolIconset
  12. */
  13. class BxBaseIconsetLucide extends BxBaseIconset
  14. {
  15. protected $_aMap;
  16. public function __construct ($aObject, $oTemplate)
  17. {
  18. parent::__construct ($aObject, $oTemplate);
  19. $this->_aMap = [
  20. 'ad' => 'circle-star',
  21. 'address-book' => 'contact-round',
  22. 'address-card' => 'id-card',
  23. 'angle-double-left' => 'chevrons-left',
  24. 'angle-double-right' => 'chevrons-right',
  25. 'arrows-alt' => 'move',
  26. 'bars' => 'menu',
  27. 'book-reader' => 'book-open-text',
  28. 'buffer' => 'layers',
  29. 'building' => 'building',
  30. 'bullhorn' => 'megaphone',
  31. 'calendar-alt' => 'calendar-days',
  32. 'calendar-day' => 'calendar-days',
  33. 'calendar-plus' => 'calendar-plus',
  34. 'camera-retro' => 'camera',
  35. 'caret-right' => 'chevron-right',
  36. 'cart-arrow-down' => 'shopping-cart',
  37. 'cart-plus' => 'shopping-cart',
  38. 'cc-stripe' => 'credit-card',
  39. 'certificate' => 'award',
  40. 'chart-pie' => 'pie-chart',
  41. 'check-circle' => 'check-circle',
  42. 'check-double' => 'check-check',
  43. 'clipboard-check' => 'clipboard-check',
  44. 'cog' => 'settings',
  45. 'cogs' => 'settings',
  46. 'comment' => 'message-circle',
  47. 'comment-dots' => 'message-square-dashed',
  48. 'comments' => 'messages-square',
  49. 'desktop' => 'monitor',
  50. 'donate' => 'hand-coins',
  51. 'ellipsis-h' => 'more-horizontal',
  52. 'ellipsis-v' => 'more-vertical',
  53. 'envelope' => 'mail',
  54. 'envelope-open-text' => 'mail-open',
  55. 'exchange-alt' => 'repeat',
  56. 'exclamation-circle' => 'alert-circle',
  57. 'exclamation-triangle' => 'alert-triangle',
  58. 'fa-book' => 'book-text',
  59. 'fa-bookmark' => 'bookmark',
  60. 'fa-certificate' => 'badge',
  61. 'fa-check-circle' => 'circle-check',
  62. 'fa-smile' => 'smile',
  63. 'fa-thumbs-up' => 'thumbs-up',
  64. 'file-alt' => 'file',
  65. 'file-alt' => 'file-text',
  66. 'file-export' => 'file-output',
  67. 'file-invoice' => 'receipt',
  68. 'file-word' => 'file-text',
  69. 'fire' => 'flame',
  70. 'group' => 'users',
  71. 'hand-holding-usd' => 'hand-coins',
  72. 'hashtag' => 'hash',
  73. 'helpcircle' => 'help-circle',
  74. 'house' => 'home',
  75. 'industry' => 'factory',
  76. 'info-circle' => 'info',
  77. 'keyround' => 'key-round',
  78. 'language' => 'languages',
  79. 'lockopen' => 'unlock',
  80. 'mail-bulk' => 'mails',
  81. 'map-marker' => 'map-pin',
  82. 'map-marker-alt' => 'map-pin',
  83. 'money-check-alt' => 'wallet-cards',
  84. 'object-group' => 'layout-dashboard',
  85. 'pencil-alt' => 'pencil-line',
  86. 'pencil-ruler' => 'ruler',
  87. 'photo-video' => 'image-play',
  88. 'plus-circle' => 'plus-circle',
  89. 'qrcode' => 'qr-code',
  90. 'quote-right' => 'quote',
  91. 'remove' => 'x',
  92. 'reply-all' => 'reply-all',
  93. 'search-location' => 'search-check',
  94. 'share-alt' => 'share-2',
  95. 'shield-alt' => 'shield',
  96. 'sign-in-alt' => 'log-in',
  97. 'sign-out-alt' => 'log-out',
  98. 'star-half-o' => 'star-half',
  99. 'swatchbook' => 'swatch-book',
  100. 'sync' => 'refresh-ccw',
  101. 'tachometer-alt' => 'gauge',
  102. 'tasks' => 'check-square',
  103. 'th-large' => 'grid-2x2',
  104. 'thumbtack' => 'pin',
  105. 'times' => 'x',
  106. 'times-circle' => 'x-circle',
  107. 'toolbox' => 'tool-case',
  108. 'trash2' => 'trash-2',
  109. 'unlock-alt' => 'unlock',
  110. 'user' => 'user-round',
  111. 'user-friends' => 'users',
  112. 'user-plus' => 'user-round-plus',
  113. 'user-slash' => 'user-x',
  114. 'user-shield' => 'user-round-search',
  115. 'user-check' => 'user-round-check',
  116. 'user-times' => 'user-x',
  117. 'users' => 'users-round',
  118. 'video-camera' => 'video',
  119. ];
  120. }
  121. public function getPreloaderJs()
  122. {
  123. return 'https://unpkg.com/lucide@latest';
  124. }
  125. public function getIcon($sIcon)
  126. {
  127. $sIcon = trim(preg_replace('/(sys-icon|far|col-\w+)/i', '', $sIcon));
  128. if(isset($this->_aMap[$sIcon]))
  129. $sIcon = $this->_aMap[$sIcon];
  130. return bx_gen_method_name($sIcon, ['_', '-']);
  131. }
  132. public function getCode()
  133. {
  134. $sMap = json_encode($this->_aMap);
  135. $sCode = <<<BLAH
  136. function bx_iconset_init_lucide() {
  137. if(!window.lucide || !lucide.icons)
  138. return;
  139. const aMap = $sMap;
  140. document.querySelectorAll('i.sys-icon').forEach(el => {
  141. if(el.hasAttribute('data-lucide'))
  142. return;
  143. const sName = el.getAttribute('class').replace(/(sys-icon-bigger|sys-icon|fab|far|fas|col-\w+)/gi, '').trim().split(' ').shift();
  144. if(sName)
  145. el.setAttribute('data-lucide', aMap[sName] != undefined ? aMap[sName] : sName);
  146. else
  147. console.warn('Lucide: no icon class found on', el);
  148. });
  149. lucide.createIcons({
  150. attrs: { class: ['sys-icon'] },
  151. nameAttr: 'data-lucide'
  152. });
  153. };
  154. bx_iconset_init_lucide();
  155. if (typeof glOnProcessHtml === 'undefined')
  156. glOnProcessHtml = [];
  157. if (glOnProcessHtml instanceof Array) {
  158. glOnProcessHtml.push(function(e) {
  159. bx_iconset_init_lucide();
  160. });
  161. }
  162. BLAH;
  163. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  164. }
  165. }
  166. /** @} */