svg.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import 'jest';
  4. // Distributed under the terms of the Modified BSD License.
  5. // including this file in a package allows for the use of import statements
  6. // with svg files. Example: `import xSvg from 'path/xSvg.svg'`
  7. // for use with raw-loader in Webpack.
  8. // The svg will be imported as a raw string
  9. declare module '*.svg' {
  10. const value: string;
  11. export default value;
  12. }
  13. // for use with svg-react-loader in Webpack.
  14. // The svg will be imported as a ReactElement
  15. // declare module '*.svg' {
  16. // import { HTMLAttributes } from 'react';
  17. // const value: React.ComponentType<HTMLAttributes<SVGElement>>;
  18. // export default value;
  19. // }
  20. // as an alternative to importing svgs one at a time, you can do a glob import
  21. // using `context.requires`. This is a Webpack only extension. Implementation:
  22. // import { PathExt } from '@jupyterlab/coreutils';
  23. //
  24. // /**
  25. // * Import all svgs from a directory. The input argument should be
  26. // * of the form `require.context('raw-loader!<path>', true, /\.svg$/)`.
  27. // * <path> should be a string literal path, as this is needed by `require`.
  28. // */
  29. // export function importSvgs(r: any, exclude: string[] = []): IModel[] {
  30. // const excset = new Set(exclude);
  31. //
  32. // return r.keys().reduce((svgs: IModel[], item: string, index: number) => {
  33. // const name = PathExt.stem(item);
  34. // if (!excset.has(name)) {
  35. // svgs.push({ name: name, svg: r(item).default });
  36. // }
  37. // return svgs;
  38. // }, []);
  39. // }
  40. //
  41. // // create the array of default icon models
  42. // let icons: IModel[];
  43. // try {
  44. // // require.context is supplied by Webpack, and doesn't play nice with jest
  45. // icons = importSvgs(
  46. // require.context('raw-loader!../../style/icons', true, /\.svg$/),
  47. // ['bad', 'blank']
  48. // );
  49. // } catch (e) {
  50. // // fallback for jest tests
  51. // icons = [];
  52. // }
  53. // export const defaultIcons: ReadonlyArray<IModel> = icons;