Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions types/vite-plugin-react-svg/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Type definitions for vite-plugin-react-svg 0.2
// Project: https://github.com/visualfanatic/vite-svg
// Definitions by: Priyanshu Rav <https://github.com/priyanshurav>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.8

import { Plugin } from 'vite';
import { OptimizeOptions } from 'svgo';
import * as React from 'react';

interface Options {
/**
* Default behavior when importing `.svg` files, possible options are: `url` and `component`.
*
* Default value: `url`
*/
defaultExport?: 'url' | 'component';
/** Boolean flag to enable/disable SVGO */
svgo?: boolean;
/** Specify SVGO config */
svgoConfig?: OptimizeOptions;
/** Props to be forwarded on SVG tag, possible options: `start`, `end` or `false` */
expandProps?: 'start' | 'end' | false;
/** Setting this to `true` will forward ref to the root SVG tag */
ref?: boolean;
/** Setting this to `true` will wrap the exported component in `React.memo` */
memo?: boolean;
/**
* Replace an attribute value by another.
* The main usage of this option is to change an icon color to `currentColor` in order to inherit from text color.
*/
replaceAttrValues?: Record<string, unknown>;
/** Add props to the root SVG tag */
svgProps?: React.SVGAttributes<SVGSVGElement>;
/** Add title tag via `title` property */
titleProp?: boolean;
}

declare function reactSvgPlugin(options?: Options): Plugin;

export = reactSvgPlugin;
6 changes: 6 additions & 0 deletions types/vite-plugin-react-svg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"vite": "^2.3.8"
}
}
23 changes: 23 additions & 0 deletions types/vite-plugin-react-svg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"vite-plugin-react-svg-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/vite-plugin-react-svg/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
38 changes: 38 additions & 0 deletions types/vite-plugin-react-svg/vite-plugin-react-svg-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { PluginOption } from 'vite';
import reactSvgPlugin = require('vite-plugin-react-svg');

const testCases: Array<PluginOption | PluginOption[]> = [
reactSvgPlugin({
defaultExport: 'component',
expandProps: 'start',
memo: false,
ref: false,
replaceAttrValues: {
someKey: 42,
anotherKey: 'value',
},
svgProps: {
role: 'alert',
},
svgo: true,
svgoConfig: {
datauri: 'base64',
},
titleProp: true,
}),
reactSvgPlugin({
defaultExport: 'url',
expandProps: 'end',
}),
reactSvgPlugin({
expandProps: false,
}),
reactSvgPlugin({
// $ExpectError
expandProps: true,
}),
reactSvgPlugin({
// $ExpectError
expandProps: 'en',
}),
];