BxBaseIconsetLucide.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. 'facebook-square' => 'facebook',
  65. 'file-alt' => 'file',
  66. 'file-alt' => 'file-text',
  67. 'file-export' => 'file-output',
  68. 'file-invoice' => 'receipt',
  69. 'file-word' => 'file-text',
  70. 'fire' => 'flame',
  71. 'group' => 'users',
  72. 'google' => 'log-in', //TODO: Brand icon. Update later.
  73. 'hand-holding-usd' => 'hand-coins',
  74. 'hashtag' => 'hash',
  75. 'helpcircle' => 'help-circle',
  76. 'house' => 'home',
  77. 'industry' => 'factory',
  78. 'info-circle' => 'info',
  79. 'keyround' => 'key-round',
  80. 'language' => 'languages',
  81. 'linkedin-in' => 'linkedin',
  82. 'lockopen' => 'unlock',
  83. 'mail-bulk' => 'mails',
  84. 'map-marker' => 'map-pin',
  85. 'map-marker-alt' => 'map-pin',
  86. 'money-check-alt' => 'wallet-cards',
  87. 'object-group' => 'layout-dashboard',
  88. 'pencil-alt' => 'pencil-line',
  89. 'pencil-ruler' => 'ruler',
  90. 'photo-video' => 'image-play',
  91. 'plus-circle' => 'plus-circle',
  92. 'qrcode' => 'qr-code',
  93. 'quote-right' => 'quote',
  94. 'remove' => 'x',
  95. 'reply-all' => 'reply-all',
  96. 'search-location' => 'search-check',
  97. 'share-alt' => 'share-2',
  98. 'shield-alt' => 'shield',
  99. 'sign-in-alt' => 'log-in',
  100. 'sign-out-alt' => 'log-out',
  101. 'star-half-o' => 'star-half',
  102. 'stopwatch' => 'timer',
  103. 'swatchbook' => 'swatch-book',
  104. 'sync' => 'refresh-ccw',
  105. 'tachometer-alt' => 'gauge',
  106. 'tasks' => 'check-square',
  107. 'th-large' => 'grid-2x2',
  108. 'thumbtack' => 'pin',
  109. 'times' => 'x',
  110. 'times-circle' => 'x-circle',
  111. 'toolbox' => 'tool-case',
  112. 'trash2' => 'trash-2',
  113. 'unlock-alt' => 'unlock',
  114. 'user' => 'user-round',
  115. 'user-friends' => 'users',
  116. 'user-plus' => 'user-round-plus',
  117. 'user-secret' => 'user-key',
  118. 'user-slash' => 'user-x',
  119. 'user-shield' => 'user-round-search',
  120. 'user-check' => 'user-round-check',
  121. 'user-times' => 'user-x',
  122. 'users' => 'users-round',
  123. 'video-camera' => 'video',
  124. ];
  125. }
  126. public function getPreloaderJs()
  127. {
  128. return 'https://unpkg.com/lucide@latest';
  129. }
  130. public function getIcon($sIcon)
  131. {
  132. $sIcon = trim(preg_replace('/(sys-icon|far|col-\w+)/i', '', $sIcon));
  133. if(isset($this->_aMap[$sIcon]))
  134. $sIcon = $this->_aMap[$sIcon];
  135. return bx_gen_method_name($sIcon, ['_', '-']);
  136. }
  137. public function getCode()
  138. {
  139. $sMap = json_encode($this->_aMap);
  140. $sCode = <<<BLAH
  141. function bx_iconset_init_lucide() {
  142. if(!window.lucide || !lucide.icons)
  143. return;
  144. const aMap = $sMap;
  145. document.querySelectorAll('i.sys-icon').forEach(el => {
  146. if(el.hasAttribute('data-lucide'))
  147. return;
  148. const sName = el.getAttribute('class').replace(/(sys-icon-bigger|sys-icon|fab|far|fas|col-\w+)/gi, '').trim().split(' ').shift();
  149. if(sName)
  150. el.setAttribute('data-lucide', aMap[sName] != undefined ? aMap[sName] : sName);
  151. else
  152. console.warn('Lucide: no icon class found on', el);
  153. });
  154. lucide.createIcons({
  155. attrs: { class: ['sys-icon'] },
  156. nameAttr: 'data-lucide'
  157. });
  158. };
  159. bx_iconset_init_lucide();
  160. if (typeof glOnProcessHtml === 'undefined')
  161. glOnProcessHtml = [];
  162. if (glOnProcessHtml instanceof Array) {
  163. glOnProcessHtml.push(function(e) {
  164. bx_iconset_init_lucide();
  165. });
  166. }
  167. BLAH;
  168. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  169. }
  170. }
  171. /** @} */