BxBaseIconsetLucide.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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-down' => 'chevrons-down',
  24. 'angle-double-left' => 'chevrons-left',
  25. 'angle-double-right' => 'chevrons-right',
  26. 'arrows-alt' => 'move',
  27. 'bars' => 'menu',
  28. 'book-reader' => 'book-open-text',
  29. 'buffer' => 'layers',
  30. 'building' => 'building',
  31. 'bullhorn' => 'megaphone',
  32. 'calendar-alt' => 'calendar-days',
  33. 'calendar-day' => 'calendar-days',
  34. 'calendar-plus' => 'calendar-plus',
  35. 'camera-retro' => 'camera',
  36. 'caret-right' => 'chevron-right',
  37. 'cart-arrow-down' => 'shopping-cart',
  38. 'cart-plus' => 'shopping-cart',
  39. 'cc-stripe' => 'credit-card',
  40. 'certificate' => 'award',
  41. 'chart-pie' => 'pie-chart',
  42. 'check-circle' => 'check-circle',
  43. 'check-double' => 'check-check',
  44. 'clipboard-check' => 'clipboard-check',
  45. 'cog' => 'settings',
  46. 'cogs' => 'settings',
  47. 'comment' => 'message-circle',
  48. 'comment-dots' => 'message-square-dashed',
  49. 'comments' => 'messages-square',
  50. 'desktop' => 'monitor',
  51. 'donate' => 'hand-coins',
  52. 'ellipsis-h' => 'more-horizontal',
  53. 'ellipsis-v' => 'more-vertical',
  54. 'envelope' => 'mail',
  55. 'envelope-open-text' => 'mail-open',
  56. 'exchange-alt' => 'repeat',
  57. 'exclamation-circle' => 'alert-circle',
  58. 'exclamation-triangle' => 'alert-triangle',
  59. 'fa-book' => 'book-text',
  60. 'fa-bookmark' => 'bookmark',
  61. 'fa-certificate' => 'badge',
  62. 'fa-check-circle' => 'circle-check',
  63. 'fa-grip-horizontal' => 'layout-grid',
  64. 'fa-smile' => 'smile',
  65. 'fa-thumbs-up' => 'thumbs-up',
  66. 'facebook-square' => 'log-in', //TODO: Brand icon. Update later.
  67. 'file-alt' => 'file',
  68. 'file-alt' => 'file-text',
  69. 'file-import' => 'file-input',
  70. 'file-export' => 'file-output',
  71. 'file-invoice' => 'receipt',
  72. 'file-word' => 'file-text',
  73. 'fire' => 'flame',
  74. 'group' => 'users',
  75. 'google' => 'log-in', //TODO: Brand icon. Update later.
  76. 'hand-holding-usd' => 'hand-coins',
  77. 'hashtag' => 'hash',
  78. 'helpcircle' => 'help-circle',
  79. 'house' => 'home',
  80. 'industry' => 'factory',
  81. 'info-circle' => 'info',
  82. 'keyround' => 'key-round',
  83. 'language' => 'languages',
  84. 'list-alt' => 'list',
  85. 'linkedin-in' => 'log-in', //TODO: Brand icon. Update later.
  86. 'lockopen' => 'unlock',
  87. 'mail-bulk' => 'mails',
  88. 'map-marker' => 'map-pin',
  89. 'map-marker-alt' => 'map-pin',
  90. 'money-check-alt' => 'wallet-cards',
  91. 'object-group' => 'layout-dashboard',
  92. 'pencil-alt' => 'pencil-line',
  93. 'pencil-ruler' => 'ruler',
  94. 'photo-video' => 'image-play',
  95. 'plus-circle' => 'plus-circle',
  96. 'qrcode' => 'qr-code',
  97. 'question' => 'circle-question-mark',
  98. 'question-circle' => 'circle-question-mark',
  99. 'quote-right' => 'quote',
  100. 'remove' => 'x',
  101. 'reply-all' => 'reply-all',
  102. 'search-location' => 'search-check',
  103. 'share-alt' => 'share-2',
  104. 'shield-alt' => 'shield',
  105. 'sign-in-alt' => 'log-in',
  106. 'sign-out-alt' => 'log-out',
  107. 'star-half-o' => 'star-half',
  108. 'stopwatch' => 'timer',
  109. 'swatchbook' => 'swatch-book',
  110. 'sync' => 'refresh-ccw',
  111. 'sync-alt' => 'refresh-ccw',
  112. 'tachometer-alt' => 'gauge',
  113. 'tasks' => 'check-square',
  114. 'th-large' => 'grid-2x2',
  115. 'thumbtack' => 'pin',
  116. 'times' => 'x',
  117. 'times-circle' => 'x-circle',
  118. 'toolbox' => 'tool-case',
  119. 'trash2' => 'trash-2',
  120. 'twitter' => 'log-in', //TODO: Brand icon. Update later.
  121. 'unlock-alt' => 'unlock',
  122. 'user' => 'user-round',
  123. 'user-friends' => 'users',
  124. 'user-plus' => 'user-round-plus',
  125. 'user-secret' => 'user-key',
  126. 'user-slash' => 'user-x',
  127. 'user-shield' => 'user-round-search',
  128. 'user-check' => 'user-round-check',
  129. 'user-times' => 'user-x',
  130. 'users' => 'users-round',
  131. 'video-camera' => 'video',
  132. 'at' => 'at-sign',
  133. 'backspace' => 'delete',
  134. 'trash-alt' => 'trash',
  135. 'magic' => 'wand-sparkles',
  136. ];
  137. }
  138. public function getPreloaderJs()
  139. {
  140. return 'https://unpkg.com/lucide@latest';
  141. }
  142. public function getIcon($sIcon)
  143. {
  144. $sIcon = trim(preg_replace('/(sys-icon|far|col-\w+)/i', '', $sIcon));
  145. if(isset($this->_aMap[$sIcon]))
  146. $sIcon = $this->_aMap[$sIcon];
  147. return bx_gen_method_name($sIcon, ['_', '-']);
  148. }
  149. public function getCode()
  150. {
  151. $sMap = json_encode($this->_aMap);
  152. $sCode = <<<BLAH
  153. function bx_iconset_init_lucide() {
  154. if(!window.lucide || !lucide.icons)
  155. return;
  156. const aMap = $sMap;
  157. document.querySelectorAll('i.sys-icon').forEach(el => {
  158. if(el.hasAttribute('data-lucide'))
  159. return;
  160. const sName = el.getAttribute('class').replace(/(sys-icon-bigger|sys-icon|fab|far|fas|col-\w+)/gi, '').trim().split(' ').shift();
  161. if(sName)
  162. el.setAttribute('data-lucide', aMap[sName] != undefined ? aMap[sName] : sName);
  163. else
  164. console.warn('Lucide: no icon class found on', el);
  165. });
  166. lucide.createIcons({
  167. attrs: { class: ['sys-icon'] },
  168. nameAttr: 'data-lucide'
  169. });
  170. };
  171. bx_iconset_init_lucide();
  172. if (typeof glOnProcessHtml === 'undefined')
  173. glOnProcessHtml = [];
  174. if (glOnProcessHtml instanceof Array) {
  175. glOnProcessHtml.push(function(e) {
  176. bx_iconset_init_lucide();
  177. });
  178. }
  179. BLAH;
  180. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  181. }
  182. }
  183. /** @} */