quickInputUtils.js 1.2 KB

1234567891011121314151617181920212223242526
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import * as dom from '../../../browser/dom.js';
  6. import { IdGenerator } from '../../../common/idGenerator.js';
  7. import './media/quickInput.css';
  8. const iconPathToClass = {};
  9. const iconClassGenerator = new IdGenerator('quick-input-button-icon-');
  10. export function getIconClass(iconPath) {
  11. if (!iconPath) {
  12. return undefined;
  13. }
  14. let iconClass;
  15. const key = iconPath.dark.toString();
  16. if (iconPathToClass[key]) {
  17. iconClass = iconPathToClass[key];
  18. }
  19. else {
  20. iconClass = iconClassGenerator.nextId();
  21. dom.createCSSRule(`.${iconClass}`, `background-image: ${dom.asCSSUrl(iconPath.light || iconPath.dark)}`);
  22. dom.createCSSRule(`.vs-dark .${iconClass}, .hc-black .${iconClass}`, `background-image: ${dom.asCSSUrl(iconPath.dark)}`);
  23. iconPathToClass[key] = iconClass;
  24. }
  25. return iconClass;
  26. }