You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
893 B

  1. import './icon-grid.scss';
  2. import {createElement} from "../../_global/scripts/helpers";
  3. export const extractGlyphClassNames = (scssSource, prefix) => {
  4. const pattern = new RegExp(`\\.(${prefix}-[a-zA-Z0-9_-]+):before`, 'g');
  5. const names = [];
  6. const seen = new Set();
  7. let match;
  8. while ((match = pattern.exec(scssSource)) !== null) {
  9. if (!seen.has(match[1])) {
  10. seen.add(match[1]);
  11. names.push(match[1]);
  12. }
  13. }
  14. return names;
  15. };
  16. export const createIconGrid = ({classNames = [], variant = 'pictograms'} = {}) => {
  17. const grid = createElement('div', ['icon-grid', `icon-grid--${variant}`]);
  18. classNames.forEach((className) => {
  19. const item = createElement('div', ['icon-grid__item'], null, grid);
  20. createElement('span', ['icon-grid__glyph', className], null, item);
  21. createElement('code', ['icon-grid__label'], className, item);
  22. });
  23. return grid;
  24. };