UNPKG

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