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.

svg.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import octiconChevronDown from '../../public/img/svg/octicon-chevron-down.svg';
  2. import octiconChevronRight from '../../public/img/svg/octicon-chevron-right.svg';
  3. import octiconGitMerge from '../../public/img/svg/octicon-git-merge.svg';
  4. import octiconGitPullRequest from '../../public/img/svg/octicon-git-pull-request.svg';
  5. import octiconInternalRepo from '../../public/img/svg/octicon-internal-repo.svg';
  6. import octiconIssueClosed from '../../public/img/svg/octicon-issue-closed.svg';
  7. import octiconIssueOpened from '../../public/img/svg/octicon-issue-opened.svg';
  8. import octiconLink from '../../public/img/svg/octicon-link.svg';
  9. import octiconLock from '../../public/img/svg/octicon-lock.svg';
  10. import octiconRepo from '../../public/img/svg/octicon-repo.svg';
  11. import octiconRepoClone from '../../public/img/svg/octicon-repo-clone.svg';
  12. import octiconRepoForked from '../../public/img/svg/octicon-repo-forked.svg';
  13. import octiconRepoTemplate from '../../public/img/svg/octicon-repo-template.svg';
  14. import octiconRepoTemplatePrivate from '../../public/img/svg/octicon-repo-template-private.svg';
  15. export const svgs = {
  16. 'octicon-chevron-down': octiconChevronDown,
  17. 'octicon-chevron-right': octiconChevronRight,
  18. 'octicon-git-merge': octiconGitMerge,
  19. 'octicon-git-pull-request': octiconGitPullRequest,
  20. 'octicon-internal-repo': octiconInternalRepo,
  21. 'octicon-issue-closed': octiconIssueClosed,
  22. 'octicon-issue-opened': octiconIssueOpened,
  23. 'octicon-link': octiconLink,
  24. 'octicon-lock': octiconLock,
  25. 'octicon-repo': octiconRepo,
  26. 'octicon-repo-clone': octiconRepoClone,
  27. 'octicon-repo-forked': octiconRepoForked,
  28. 'octicon-repo-template': octiconRepoTemplate,
  29. 'octicon-repo-template-private': octiconRepoTemplatePrivate,
  30. };
  31. const parser = new DOMParser();
  32. const serializer = new XMLSerializer();
  33. // retrieve a HTML string for given SVG icon name and size in pixels
  34. export function svg(name, size = 16) {
  35. if (name in svgs) {
  36. if (size === 16) return svgs[name];
  37. const document = parser.parseFromString(svgs[name], 'image/svg+xml');
  38. const svgNode = document.firstChild;
  39. svgNode.setAttribute('width', String(size));
  40. svgNode.setAttribute('height', String(size));
  41. return serializer.serializeToString(svgNode);
  42. }
  43. return '';
  44. }