2021-04-23 20:50:17 +00:00
|
|
|
import React from 'react';
|
2021-04-24 11:49:37 +00:00
|
|
|
import type { IconifyJSON } from '@iconify/types';
|
|
|
|
|
|
|
|
// Core
|
2021-05-13 12:46:50 +00:00
|
|
|
import { IconifyIconName, stringToIcon } from '@iconify/core/lib/icon/name';
|
2021-04-23 20:50:17 +00:00
|
|
|
import type {
|
2021-04-24 11:49:37 +00:00
|
|
|
IconifyIconSize,
|
2021-04-23 20:50:17 +00:00
|
|
|
IconifyHorizontalIconAlignment,
|
|
|
|
IconifyVerticalIconAlignment,
|
|
|
|
} from '@iconify/core/lib/customisations';
|
2021-04-24 11:49:37 +00:00
|
|
|
import {
|
|
|
|
IconifyStorageFunctions,
|
|
|
|
storageFunctions,
|
|
|
|
getIconData,
|
|
|
|
allowSimpleNames,
|
|
|
|
} from '@iconify/core/lib/storage/functions';
|
|
|
|
import {
|
|
|
|
IconifyBuilderFunctions,
|
|
|
|
builderFunctions,
|
|
|
|
} from '@iconify/core/lib/builder/functions';
|
2021-05-11 20:27:13 +00:00
|
|
|
import type { IconifyIconBuildResult } from '@iconify/core/lib/builder';
|
2021-04-24 11:49:37 +00:00
|
|
|
import { fullIcon, IconifyIcon } from '@iconify/core/lib/icon';
|
|
|
|
|
|
|
|
// Modules
|
|
|
|
import { coreModules } from '@iconify/core/lib/modules';
|
|
|
|
|
|
|
|
// API
|
|
|
|
import { API, IconifyAPIInternalStorage } from '@iconify/core/lib/api/';
|
|
|
|
import {
|
|
|
|
IconifyAPIFunctions,
|
|
|
|
IconifyAPIInternalFunctions,
|
|
|
|
APIFunctions,
|
|
|
|
APIInternalFunctions,
|
|
|
|
} from '@iconify/core/lib/api/functions';
|
|
|
|
import {
|
|
|
|
setAPIModule,
|
|
|
|
IconifyAPIModule,
|
|
|
|
IconifyAPISendQuery,
|
|
|
|
IconifyAPIPrepareQuery,
|
|
|
|
GetIconifyAPIModule,
|
|
|
|
} from '@iconify/core/lib/api/modules';
|
|
|
|
import { getAPIModule as getJSONPAPIModule } from '@iconify/core/lib/api/modules/jsonp';
|
|
|
|
import {
|
|
|
|
getAPIModule as getFetchAPIModule,
|
|
|
|
setFetch,
|
|
|
|
} from '@iconify/core/lib/api/modules/fetch';
|
|
|
|
import {
|
|
|
|
setAPIConfig,
|
|
|
|
PartialIconifyAPIConfig,
|
|
|
|
IconifyAPIConfig,
|
|
|
|
getAPIConfig,
|
|
|
|
GetAPIConfig,
|
|
|
|
} from '@iconify/core/lib/api/config';
|
|
|
|
import type {
|
|
|
|
IconifyIconLoaderCallback,
|
|
|
|
IconifyIconLoaderAbort,
|
|
|
|
} from '@iconify/core/lib/interfaces/loader';
|
|
|
|
|
|
|
|
// Cache
|
|
|
|
import { storeCache, loadCache } from '@iconify/core/lib/browser-storage';
|
|
|
|
import { toggleBrowserCache } from '@iconify/core/lib/browser-storage/functions';
|
|
|
|
import type {
|
|
|
|
IconifyBrowserCacheType,
|
|
|
|
IconifyBrowserCacheFunctions,
|
|
|
|
} from '@iconify/core/lib/browser-storage/functions';
|
|
|
|
|
|
|
|
// Properties
|
2021-04-23 20:50:17 +00:00
|
|
|
import type {
|
2021-05-11 20:27:13 +00:00
|
|
|
RawIconCustomisations,
|
|
|
|
IconifyIconOnLoad,
|
2021-04-23 20:50:17 +00:00
|
|
|
IconifyIconCustomisations,
|
|
|
|
IconifyIconProps,
|
|
|
|
IconProps,
|
|
|
|
IconRef,
|
|
|
|
} from './props';
|
2021-04-24 11:49:37 +00:00
|
|
|
|
|
|
|
// Render SVG
|
2021-04-23 20:50:17 +00:00
|
|
|
import { render } from './render';
|
2021-04-27 16:21:35 +00:00
|
|
|
import { merge } from '@iconify/core/lib/misc/merge';
|
2021-04-23 20:50:17 +00:00
|
|
|
|
|
|
|
/**
|
2021-04-24 11:49:37 +00:00
|
|
|
* Export required types
|
2021-04-23 20:50:17 +00:00
|
|
|
*/
|
2021-04-24 11:49:37 +00:00
|
|
|
// Function sets
|
|
|
|
export {
|
|
|
|
IconifyStorageFunctions,
|
|
|
|
IconifyBuilderFunctions,
|
|
|
|
IconifyBrowserCacheFunctions,
|
|
|
|
IconifyAPIFunctions,
|
|
|
|
IconifyAPIInternalFunctions,
|
|
|
|
};
|
2021-04-23 20:50:17 +00:00
|
|
|
|
2021-04-24 11:49:37 +00:00
|
|
|
// JSON stuff
|
|
|
|
export { IconifyIcon, IconifyJSON, IconifyIconName };
|
|
|
|
|
2021-05-11 20:27:13 +00:00
|
|
|
// Customisations and icon props
|
2021-04-23 20:50:17 +00:00
|
|
|
export {
|
2021-04-24 11:49:37 +00:00
|
|
|
IconifyIconCustomisations,
|
|
|
|
IconifyIconSize,
|
2021-04-23 20:50:17 +00:00
|
|
|
IconifyHorizontalIconAlignment,
|
|
|
|
IconifyVerticalIconAlignment,
|
2021-04-24 11:49:37 +00:00
|
|
|
IconifyIconProps,
|
|
|
|
IconProps,
|
2021-05-11 20:27:13 +00:00
|
|
|
IconifyIconOnLoad,
|
2021-04-23 20:50:17 +00:00
|
|
|
};
|
|
|
|
|
2021-04-24 11:49:37 +00:00
|
|
|
// API
|
|
|
|
export {
|
|
|
|
IconifyAPIConfig,
|
|
|
|
IconifyIconLoaderCallback,
|
|
|
|
IconifyIconLoaderAbort,
|
|
|
|
IconifyAPIInternalStorage,
|
|
|
|
IconifyAPIModule,
|
|
|
|
GetAPIConfig,
|
|
|
|
IconifyAPIPrepareQuery,
|
|
|
|
IconifyAPISendQuery,
|
2021-05-01 20:39:56 +00:00
|
|
|
PartialIconifyAPIConfig,
|
2021-04-24 11:49:37 +00:00
|
|
|
};
|
|
|
|
|
2021-05-11 20:27:13 +00:00
|
|
|
// Builder functions
|
|
|
|
export { RawIconCustomisations, IconifyIconBuildResult };
|
|
|
|
|
2021-04-24 11:49:37 +00:00
|
|
|
/* Browser cache */
|
|
|
|
export { IconifyBrowserCacheType };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable and disable browser cache
|
|
|
|
*/
|
|
|
|
export const enableCache = (storage: IconifyBrowserCacheType) =>
|
|
|
|
toggleBrowserCache(storage, true);
|
|
|
|
|
|
|
|
export const disableCache = (storage: IconifyBrowserCacheType) =>
|
|
|
|
toggleBrowserCache(storage, false);
|
|
|
|
|
|
|
|
/* Storage functions */
|
|
|
|
/**
|
|
|
|
* Check if icon exists
|
|
|
|
*/
|
|
|
|
export const iconExists = storageFunctions.iconExists;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get icon data
|
|
|
|
*/
|
|
|
|
export const getIcon = storageFunctions.getIcon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List available icons
|
|
|
|
*/
|
|
|
|
export const listIcons = storageFunctions.listIcons;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add one icon
|
|
|
|
*/
|
|
|
|
export const addIcon = storageFunctions.addIcon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add icon set
|
|
|
|
*/
|
|
|
|
export const addCollection = storageFunctions.addCollection;
|
|
|
|
|
|
|
|
/* Builder functions */
|
|
|
|
/**
|
|
|
|
* Calculate icon size
|
|
|
|
*/
|
|
|
|
export const calculateSize = builderFunctions.calculateSize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace unique ids in content
|
|
|
|
*/
|
|
|
|
export const replaceIDs = builderFunctions.replaceIDs;
|
|
|
|
|
2021-05-11 20:27:13 +00:00
|
|
|
/**
|
|
|
|
* Build SVG
|
|
|
|
*/
|
|
|
|
export const buildIcon = builderFunctions.buildIcon;
|
|
|
|
|
2021-04-24 11:49:37 +00:00
|
|
|
/* API functions */
|
|
|
|
/**
|
|
|
|
* Load icons
|
|
|
|
*/
|
|
|
|
export const loadIcons = APIFunctions.loadIcons;
|
|
|
|
|
2021-04-23 20:50:17 +00:00
|
|
|
/**
|
2021-04-24 11:49:37 +00:00
|
|
|
* Add API provider
|
|
|
|
*/
|
|
|
|
export const addAPIProvider = APIFunctions.addAPIProvider;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export internal functions that can be used by third party implementations
|
|
|
|
*/
|
|
|
|
export const _api = APIInternalFunctions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise stuff
|
|
|
|
*/
|
|
|
|
// Enable short names
|
|
|
|
allowSimpleNames(true);
|
|
|
|
|
|
|
|
// Set API
|
|
|
|
coreModules.api = API;
|
|
|
|
|
2021-04-26 18:43:20 +00:00
|
|
|
// Use Fetch API by default
|
|
|
|
let getAPIModule: GetIconifyAPIModule = getFetchAPIModule;
|
2021-04-24 11:49:37 +00:00
|
|
|
try {
|
2021-04-26 18:43:20 +00:00
|
|
|
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
|
|
|
// If window and document exist, attempt to load whatever module is available, otherwise use Fetch API
|
|
|
|
getAPIModule =
|
|
|
|
typeof fetch === 'function' && typeof Promise === 'function'
|
|
|
|
? getFetchAPIModule
|
|
|
|
: getJSONPAPIModule;
|
|
|
|
}
|
2021-04-24 11:49:37 +00:00
|
|
|
} catch (err) {
|
2021-04-26 18:43:20 +00:00
|
|
|
//
|
2021-04-24 11:49:37 +00:00
|
|
|
}
|
|
|
|
setAPIModule('', getAPIModule(getAPIConfig));
|
|
|
|
|
|
|
|
/**
|
2021-04-26 18:43:20 +00:00
|
|
|
* Function to enable node-fetch for getting icons on server side
|
2021-04-24 11:49:37 +00:00
|
|
|
*/
|
2021-05-07 18:19:48 +00:00
|
|
|
_api.setFetch = (nodeFetch: typeof fetch) => {
|
2021-04-24 11:49:37 +00:00
|
|
|
setFetch(nodeFetch);
|
|
|
|
if (getAPIModule !== getFetchAPIModule) {
|
|
|
|
getAPIModule = getFetchAPIModule;
|
|
|
|
setAPIModule('', getAPIModule(getAPIConfig));
|
|
|
|
}
|
2021-05-07 18:19:48 +00:00
|
|
|
};
|
2021-04-24 11:49:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Browser stuff
|
|
|
|
*/
|
|
|
|
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
|
|
|
// Set cache and load existing cache
|
|
|
|
coreModules.cache = storeCache;
|
|
|
|
loadCache();
|
|
|
|
|
|
|
|
const _window = window;
|
|
|
|
|
|
|
|
// Load icons from global "IconifyPreload"
|
|
|
|
interface WindowWithIconifyPreload {
|
|
|
|
IconifyPreload: IconifyJSON[] | IconifyJSON;
|
|
|
|
}
|
|
|
|
if (
|
2021-05-11 20:27:13 +00:00
|
|
|
(_window as unknown as WindowWithIconifyPreload).IconifyPreload !==
|
2021-04-24 11:49:37 +00:00
|
|
|
void 0
|
|
|
|
) {
|
2021-05-11 20:27:13 +00:00
|
|
|
const preload = (_window as unknown as WindowWithIconifyPreload)
|
2021-04-24 11:49:37 +00:00
|
|
|
.IconifyPreload;
|
|
|
|
const err = 'Invalid IconifyPreload syntax.';
|
|
|
|
if (typeof preload === 'object' && preload !== null) {
|
|
|
|
(preload instanceof Array ? preload : [preload]).forEach((item) => {
|
|
|
|
try {
|
|
|
|
if (
|
|
|
|
// Check if item is an object and not null/array
|
|
|
|
typeof item !== 'object' ||
|
|
|
|
item === null ||
|
|
|
|
item instanceof Array ||
|
|
|
|
// Check for 'icons' and 'prefix'
|
|
|
|
typeof item.icons !== 'object' ||
|
|
|
|
typeof item.prefix !== 'string' ||
|
|
|
|
// Add icon set
|
|
|
|
!addCollection(item)
|
|
|
|
) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set API from global "IconifyProviders"
|
|
|
|
interface WindowWithIconifyProviders {
|
|
|
|
IconifyProviders: Record<string, PartialIconifyAPIConfig>;
|
|
|
|
}
|
|
|
|
if (
|
2021-05-11 20:27:13 +00:00
|
|
|
(_window as unknown as WindowWithIconifyProviders).IconifyProviders !==
|
|
|
|
void 0
|
2021-04-24 11:49:37 +00:00
|
|
|
) {
|
2021-05-11 20:27:13 +00:00
|
|
|
const providers = (_window as unknown as WindowWithIconifyProviders)
|
2021-04-24 11:49:37 +00:00
|
|
|
.IconifyProviders;
|
|
|
|
if (typeof providers === 'object' && providers !== null) {
|
|
|
|
for (let key in providers) {
|
|
|
|
const err = 'IconifyProviders[' + key + '] is invalid.';
|
|
|
|
try {
|
|
|
|
const value = providers[key];
|
|
|
|
if (
|
|
|
|
typeof value !== 'object' ||
|
|
|
|
!value ||
|
|
|
|
value.resources === void 0
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!setAPIConfig(key, value)) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component
|
2021-04-23 20:50:17 +00:00
|
|
|
*/
|
2021-04-27 16:21:35 +00:00
|
|
|
interface InternalIconProps extends IconProps {
|
|
|
|
_ref?: IconRef;
|
|
|
|
_inline: boolean;
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:46:50 +00:00
|
|
|
interface IconComponentData {
|
|
|
|
data: Required<IconifyIcon>;
|
|
|
|
classes?: string[];
|
|
|
|
}
|
2021-04-27 16:21:35 +00:00
|
|
|
|
|
|
|
interface IconComponentState {
|
2021-05-13 12:46:50 +00:00
|
|
|
icon: IconComponentData | null;
|
2021-04-27 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ComponentAbortData {
|
|
|
|
name: string;
|
|
|
|
abort: IconifyIconLoaderAbort;
|
|
|
|
}
|
|
|
|
|
|
|
|
class IconComponent extends React.Component<
|
|
|
|
InternalIconProps,
|
|
|
|
IconComponentState
|
|
|
|
> {
|
|
|
|
protected _icon: string;
|
|
|
|
protected _loading: ComponentAbortData | null;
|
|
|
|
|
|
|
|
constructor(props: InternalIconProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
// Render placeholder before component is mounted
|
2021-05-13 12:46:50 +00:00
|
|
|
icon: null,
|
2021-04-27 16:21:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abort loading icon
|
|
|
|
*/
|
|
|
|
_abortLoading() {
|
|
|
|
if (this._loading) {
|
|
|
|
this._loading.abort();
|
|
|
|
this._loading = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update state
|
|
|
|
*/
|
2021-05-13 12:46:50 +00:00
|
|
|
_setData(icon: IconComponentData | null) {
|
|
|
|
if (this.state.icon !== icon) {
|
2021-04-27 16:21:35 +00:00
|
|
|
this.setState({
|
2021-05-13 12:46:50 +00:00
|
|
|
icon,
|
2021-04-27 16:21:35 +00:00
|
|
|
});
|
|
|
|
}
|
2021-04-23 20:50:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 16:21:35 +00:00
|
|
|
/**
|
|
|
|
* Check if icon should be loaded
|
|
|
|
*/
|
|
|
|
_checkIcon(changed: boolean) {
|
|
|
|
const state = this.state;
|
|
|
|
const icon = this.props.icon;
|
|
|
|
|
|
|
|
// Icon is an object
|
2021-05-01 20:39:56 +00:00
|
|
|
if (
|
|
|
|
typeof icon === 'object' &&
|
|
|
|
icon !== null &&
|
|
|
|
typeof icon.body === 'string'
|
|
|
|
) {
|
2021-04-27 16:21:35 +00:00
|
|
|
// Stop loading
|
|
|
|
this._icon = '';
|
|
|
|
this._abortLoading();
|
|
|
|
|
2021-05-13 12:46:50 +00:00
|
|
|
if (changed || state.icon === null) {
|
2021-04-27 16:21:35 +00:00
|
|
|
// Set data if it was changed
|
2021-05-13 12:46:50 +00:00
|
|
|
this._setData({
|
|
|
|
data: fullIcon(icon),
|
|
|
|
});
|
2021-04-27 16:21:35 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid icon?
|
2021-05-13 12:46:50 +00:00
|
|
|
let iconName: IconifyIconName | null;
|
|
|
|
if (
|
|
|
|
typeof icon !== 'string' ||
|
|
|
|
(iconName = stringToIcon(icon, false, true)) === null
|
|
|
|
) {
|
2021-04-27 16:21:35 +00:00
|
|
|
this._abortLoading();
|
|
|
|
this._setData(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load icon
|
2021-05-13 12:46:50 +00:00
|
|
|
const data = getIconData(iconName);
|
2021-04-27 16:21:35 +00:00
|
|
|
if (data === null) {
|
|
|
|
// Icon needs to be loaded
|
|
|
|
if (!this._loading || this._loading.name !== icon) {
|
|
|
|
// New icon to load
|
|
|
|
this._abortLoading();
|
|
|
|
this._icon = '';
|
|
|
|
this._setData(null);
|
|
|
|
this._loading = {
|
|
|
|
name: icon,
|
|
|
|
abort: API.loadIcons(
|
2021-05-13 12:46:50 +00:00
|
|
|
[iconName],
|
2021-04-27 16:21:35 +00:00
|
|
|
this._checkIcon.bind(this, false)
|
|
|
|
),
|
|
|
|
};
|
2021-04-24 11:49:37 +00:00
|
|
|
}
|
2021-04-27 16:21:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Icon data is available
|
2021-05-13 12:46:50 +00:00
|
|
|
if (this._icon !== icon || state.icon === null) {
|
2021-04-27 16:21:35 +00:00
|
|
|
// New icon or icon has been loaded
|
|
|
|
this._abortLoading();
|
|
|
|
this._icon = icon;
|
2021-05-13 12:46:50 +00:00
|
|
|
|
|
|
|
// Add classes
|
|
|
|
const classes: string[] = ['iconify'];
|
|
|
|
if (iconName.prefix !== '') {
|
|
|
|
classes.push('iconify--' + iconName.prefix);
|
|
|
|
}
|
|
|
|
if (iconName.provider !== '') {
|
|
|
|
classes.push('iconify--' + iconName.provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set data
|
|
|
|
this._setData({
|
|
|
|
data,
|
|
|
|
classes,
|
|
|
|
});
|
2021-05-11 20:27:13 +00:00
|
|
|
if (this.props.onLoad) {
|
|
|
|
this.props.onLoad(icon);
|
|
|
|
}
|
2021-04-27 16:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component mounted
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
this._checkIcon(false);
|
|
|
|
}
|
2021-04-24 11:49:37 +00:00
|
|
|
|
2021-04-27 16:21:35 +00:00
|
|
|
/**
|
|
|
|
* Component updated
|
|
|
|
*/
|
|
|
|
componentDidUpdate(oldProps) {
|
|
|
|
if (oldProps.icon !== this.props.icon) {
|
|
|
|
this._checkIcon(true);
|
2021-04-24 11:49:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:21:35 +00:00
|
|
|
/**
|
|
|
|
* Abort loading
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
this._abortLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const props = this.props;
|
2021-05-13 12:46:50 +00:00
|
|
|
const icon = this.state.icon;
|
2021-04-27 16:21:35 +00:00
|
|
|
|
2021-05-13 12:46:50 +00:00
|
|
|
if (icon === null) {
|
2021-04-27 16:21:35 +00:00
|
|
|
// Render placeholder
|
|
|
|
return props.children
|
|
|
|
? (props.children as JSX.Element)
|
|
|
|
: React.createElement('span', {});
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:46:50 +00:00
|
|
|
// Add classes
|
|
|
|
let newProps = props;
|
|
|
|
if (icon.classes) {
|
|
|
|
newProps = merge(props, {
|
|
|
|
className:
|
|
|
|
(typeof props.className === 'string'
|
|
|
|
? props.className + ' '
|
|
|
|
: '') + icon.classes.join(' '),
|
|
|
|
} as typeof props);
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:21:35 +00:00
|
|
|
// Render icon
|
2021-05-13 12:46:50 +00:00
|
|
|
return render(icon.data, newProps, props._inline, props._ref);
|
2021-04-27 16:21:35 +00:00
|
|
|
}
|
2021-04-23 20:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type for exported components
|
|
|
|
*/
|
|
|
|
export type Component = (props: IconProps) => JSX.Element;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Block icon
|
|
|
|
*
|
|
|
|
* @param props - Component properties
|
|
|
|
*/
|
|
|
|
export const Icon: Component = React.forwardRef(
|
2021-04-27 16:21:35 +00:00
|
|
|
(props: IconProps, ref?: IconRef) => {
|
|
|
|
const newProps = merge(props as Partial<InternalIconProps>, {
|
|
|
|
_ref: ref,
|
|
|
|
_inline: false,
|
|
|
|
}) as InternalIconProps;
|
|
|
|
return React.createElement(IconComponent, newProps);
|
|
|
|
}
|
2021-04-23 20:50:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inline icon (has negative verticalAlign that makes it behave like icon font)
|
|
|
|
*
|
|
|
|
* @param props - Component properties
|
|
|
|
*/
|
|
|
|
export const InlineIcon: Component = React.forwardRef(
|
2021-04-27 16:21:35 +00:00
|
|
|
(props: IconProps, ref?: IconRef) => {
|
|
|
|
const newProps = merge(props as Partial<InternalIconProps>, {
|
|
|
|
_ref: ref,
|
|
|
|
_inline: true,
|
|
|
|
}) as InternalIconProps;
|
|
|
|
return React.createElement(IconComponent, newProps);
|
|
|
|
}
|
2021-04-23 20:50:17 +00:00
|
|
|
);
|