svg.d.ts 1.9 KB

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