mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
Fix renderHTML, renderSVG and renderIcon functions in SVG framework
This commit is contained in:
parent
f5729b7d00
commit
02ccf58817
@ -81,6 +81,11 @@ describe('Testing Iconify object', () => {
|
||||
inline: true,
|
||||
});
|
||||
expect(html2).to.be.equal(html);
|
||||
|
||||
// Make sure inline attribute was applied
|
||||
expect(html2.indexOf('vertical-align: -0.125em;') === -1).to.be.equal(
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it('Rendering icons without API', (done) => {
|
||||
|
@ -21,13 +21,13 @@ Iconify SVG framework is designed to be as easy to use as possible.
|
||||
Add this line to your page to load Iconify SVG framework (you can add it to `<head>` section of the page or before `</body>`):
|
||||
|
||||
```html
|
||||
<script src="https://code.iconify.design/2/2.0.3/iconify.min.js"></script>
|
||||
<script src="https://code.iconify.design/2/2.0.4/iconify.min.js"></script>
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/@iconify/iconify@2.0.3/dist/iconify.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@iconify/iconify@2.0.4/dist/iconify.min.js"></script>
|
||||
```
|
||||
|
||||
or, if you are building a project with something like WebPack or Rollup, you can include the script by installing `@iconify/iconify` as a dependency and importing it in your project:
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "@iconify/iconify",
|
||||
"description": "Unified SVG framework with over 70,000 icons to choose from",
|
||||
"author": "Vjacheslav Trushkin <cyberalien@gmail.com> (https://iconify.design)",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.4",
|
||||
"license": "(Apache-2.0 OR GPL-2.0)",
|
||||
"main": "./dist/iconify.min.js",
|
||||
"types": "./dist/iconify.d.ts",
|
||||
|
@ -34,7 +34,7 @@ import { findRootNode, addBodyNode } from './modules/root';
|
||||
*/
|
||||
function buildIcon(
|
||||
name: string,
|
||||
customisations: IconifyIconCustomisations
|
||||
customisations?: IconifyIconCustomisations
|
||||
): IconifyIconBuildResult | null {
|
||||
// Get icon data
|
||||
const iconData = getIconData(name);
|
||||
@ -43,7 +43,10 @@ function buildIcon(
|
||||
}
|
||||
|
||||
// Clean up customisations
|
||||
const changes = mergeCustomisations(defaults, customisations);
|
||||
const changes = mergeCustomisations(
|
||||
defaults,
|
||||
typeof customisations === 'object' ? customisations : {}
|
||||
);
|
||||
|
||||
// Get data
|
||||
return iconToSVG(iconData, changes);
|
||||
@ -54,8 +57,8 @@ function buildIcon(
|
||||
*/
|
||||
function generateIcon(
|
||||
name: string,
|
||||
customisations: IconifyIconCustomisations,
|
||||
returnString: boolean
|
||||
customisations?: IconifyIconCustomisations,
|
||||
returnString?: boolean
|
||||
): SVGElement | string | null {
|
||||
// Get icon data
|
||||
const iconData = getIconData(name);
|
||||
@ -67,7 +70,10 @@ function generateIcon(
|
||||
const iconName = stringToIcon(name);
|
||||
|
||||
// Clean up customisations
|
||||
const changes = mergeCustomisations(defaults, customisations);
|
||||
const changes = mergeCustomisations(
|
||||
defaults,
|
||||
typeof customisations === 'object' ? customisations : {}
|
||||
);
|
||||
|
||||
// Get data
|
||||
return renderIcon(
|
||||
@ -96,12 +102,12 @@ export interface IconifyCommonFunctions {
|
||||
*/
|
||||
renderSVG: (
|
||||
name: string,
|
||||
customisations: IconifyIconCustomisations
|
||||
customisations?: IconifyIconCustomisations
|
||||
) => SVGElement | null;
|
||||
|
||||
renderHTML: (
|
||||
name: string,
|
||||
customisations: IconifyIconCustomisations
|
||||
customisations?: IconifyIconCustomisations
|
||||
) => string | null;
|
||||
|
||||
/**
|
||||
@ -109,7 +115,7 @@ export interface IconifyCommonFunctions {
|
||||
*/
|
||||
renderIcon: (
|
||||
name: string,
|
||||
customisations: IconifyIconCustomisations
|
||||
customisations?: IconifyIconCustomisations
|
||||
) => IconifyIconBuildResult | null;
|
||||
|
||||
/* Scanner */
|
||||
@ -148,11 +154,11 @@ export const commonFunctions: IconifyCommonFunctions = {
|
||||
getVersion: () => '__iconify_version__',
|
||||
|
||||
// Render SVG
|
||||
renderSVG: (name: string, customisations: IconifyIconCustomisations) => {
|
||||
renderSVG: (name: string, customisations?: IconifyIconCustomisations) => {
|
||||
return generateIcon(name, customisations, false) as SVGElement | null;
|
||||
},
|
||||
|
||||
renderHTML: (name: string, customisations: IconifyIconCustomisations) => {
|
||||
renderHTML: (name: string, customisations?: IconifyIconCustomisations) => {
|
||||
return generateIcon(name, customisations, true) as string | null;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user