@iconify-icon/react 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { IconifyIconProperties, IconifyIconHTMLElement } from 'iconify-icon';
3
+ export { GetAPIConfig, IconifyAPIConfig, IconifyAPICustomQueryParams, IconifyAPIFunctions, IconifyAPIInternalFunctions, IconifyAPIModule, IconifyAPIPrepareIconsQuery, IconifyAPIQueryParams, IconifyAPISendQuery, IconifyBrowserCacheFunctions, IconifyBrowserCacheType, IconifyBuilderFunctions, IconifyIcon, IconifyIconAttributes, IconifyIconBuildResult, IconifyIconCustomisations, IconifyIconHTMLElement, IconifyIconLoaderAbort, IconifyIconLoaderCallback, IconifyIconName, IconifyIconProperties, IconifyIconSize, IconifyJSON, IconifyRenderMode, IconifyStorageFunctions, PartialIconifyAPIConfig, _api, addAPIProvider, addCollection, addIcon, buildIcon, calculateSize, disableCache, enableCache, getIcon, iconExists, listIcons, loadIcon, loadIcons, replaceIDs, shareStorage } from 'iconify-icon';
4
+
5
+ /**
6
+ * Properties for React component
7
+ */
8
+ interface IconifyIconProps extends React.HTMLProps<HTMLElement>, IconifyIconProperties {
9
+ rotate?: string | number;
10
+ }
11
+ /**
12
+ * React component
13
+ */
14
+ declare const Icon: React.ForwardRefExoticComponent<Pick<IconifyIconProps, "rotate" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "children" | "list" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "as" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "classID" | "cols" | "colSpan" | "content" | "controls" | "coords" | "crossOrigin" | "dateTime" | "default" | "defer" | "disabled" | "download" | "encType" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "height" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "name" | "nonce" | "noValidate" | "open" | "optimum" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "selected" | "shape" | "size" | "sizes" | "src" | "srcDoc" | "srcLang" | "srcSet" | "start" | "step" | "target" | "type" | "useMap" | "value" | "width" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "icon" | "mode" | "inline" | "flip"> & React.RefAttributes<IconifyIconHTMLElement>>;
15
+
16
+ export { Icon, IconifyIconProps };
@@ -0,0 +1,79 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/iconify.ts
23
+ var iconify_exports = {};
24
+ __export(iconify_exports, {
25
+ Icon: () => Icon,
26
+ _api: () => import_iconify_icon._api,
27
+ addAPIProvider: () => import_iconify_icon.addAPIProvider,
28
+ addCollection: () => import_iconify_icon.addCollection,
29
+ addIcon: () => import_iconify_icon.addIcon,
30
+ buildIcon: () => import_iconify_icon.buildIcon,
31
+ calculateSize: () => import_iconify_icon.calculateSize,
32
+ disableCache: () => import_iconify_icon.disableCache,
33
+ enableCache: () => import_iconify_icon.enableCache,
34
+ getIcon: () => import_iconify_icon.getIcon,
35
+ iconExists: () => import_iconify_icon.iconExists,
36
+ listIcons: () => import_iconify_icon.listIcons,
37
+ loadIcon: () => import_iconify_icon.loadIcon,
38
+ loadIcons: () => import_iconify_icon.loadIcons,
39
+ replaceIDs: () => import_iconify_icon.replaceIDs,
40
+ shareStorage: () => import_iconify_icon.shareStorage
41
+ });
42
+ module.exports = __toCommonJS(iconify_exports);
43
+ var import_react = __toESM(require("react"));
44
+ var import_iconify_icon = require("iconify-icon");
45
+ var Icon = import_react.default.forwardRef((props, ref) => {
46
+ const newProps = {
47
+ ...props,
48
+ ref
49
+ };
50
+ if (typeof props.icon === "object") {
51
+ newProps.icon = JSON.stringify(props.icon);
52
+ }
53
+ if (!props.inline) {
54
+ delete newProps.inline;
55
+ }
56
+ if (props.className) {
57
+ newProps["class"] = props.className;
58
+ }
59
+ return import_react.default.createElement("iconify-icon", newProps);
60
+ });
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ Icon,
64
+ _api,
65
+ addAPIProvider,
66
+ addCollection,
67
+ addIcon,
68
+ buildIcon,
69
+ calculateSize,
70
+ disableCache,
71
+ enableCache,
72
+ getIcon,
73
+ iconExists,
74
+ listIcons,
75
+ loadIcon,
76
+ loadIcons,
77
+ replaceIDs,
78
+ shareStorage
79
+ });
@@ -0,0 +1,53 @@
1
+ // src/iconify.ts
2
+ import React from "react";
3
+ import {
4
+ enableCache,
5
+ disableCache,
6
+ iconExists,
7
+ getIcon,
8
+ listIcons,
9
+ shareStorage,
10
+ addIcon,
11
+ addCollection,
12
+ calculateSize,
13
+ replaceIDs,
14
+ buildIcon,
15
+ loadIcons,
16
+ loadIcon,
17
+ addAPIProvider,
18
+ _api
19
+ } from "iconify-icon";
20
+ var Icon = React.forwardRef((props, ref) => {
21
+ const newProps = {
22
+ ...props,
23
+ ref
24
+ };
25
+ if (typeof props.icon === "object") {
26
+ newProps.icon = JSON.stringify(props.icon);
27
+ }
28
+ if (!props.inline) {
29
+ delete newProps.inline;
30
+ }
31
+ if (props.className) {
32
+ newProps["class"] = props.className;
33
+ }
34
+ return React.createElement("iconify-icon", newProps);
35
+ });
36
+ export {
37
+ Icon,
38
+ _api,
39
+ addAPIProvider,
40
+ addCollection,
41
+ addIcon,
42
+ buildIcon,
43
+ calculateSize,
44
+ disableCache,
45
+ enableCache,
46
+ getIcon,
47
+ iconExists,
48
+ listIcons,
49
+ loadIcon,
50
+ loadIcons,
51
+ replaceIDs,
52
+ shareStorage
53
+ };
package/license.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Vjacheslav Trushkin / Iconify OÜ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@iconify-icon/react",
3
+ "description": "React wrapper for Iconify Icon web component",
4
+ "author": "Vjacheslav Trushkin",
5
+ "version": "0.0.1",
6
+ "license": "MIT",
7
+ "bugs": "https://github.com/iconify/iconify/issues",
8
+ "homepage": "https://iconify.design/",
9
+ "funding": "http://github.com/sponsors/cyberalien",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/iconify/iconify.git",
13
+ "directory": "iconify-icon/react"
14
+ },
15
+ "scripts": {
16
+ "clean": "rimraf lib dist tsconfig.tsbuildinfo",
17
+ "prebuild": "npm run clean",
18
+ "build": "tsup",
19
+ "test": "vitest --config vitest.config.mjs"
20
+ },
21
+ "main": "dist/iconify.js",
22
+ "module": "dist/iconify.mjs",
23
+ "types": "dist/iconify.d.ts",
24
+ "exports": {
25
+ "./*": "./*",
26
+ ".": {
27
+ "import": "./dist/iconify.mjs",
28
+ "types": "./dist/iconify.d.ts",
29
+ "default": "./dist/iconify.js"
30
+ },
31
+ "./lib/iconify": {
32
+ "require": "./dist/iconify.js",
33
+ "import": "./dist/iconify.mjs",
34
+ "types": "./dist/iconify.d.ts"
35
+ }
36
+ },
37
+ "dependencies": {
38
+ "iconify-icon": "^0.0.4"
39
+ },
40
+ "devDependencies": {
41
+ "@types/react": "^17.0.41",
42
+ "@types/react-test-renderer": "^18.0.0",
43
+ "@vitejs/plugin-react": "^1.3.2",
44
+ "jest": "^28.0.0-alpha.7",
45
+ "react": "^18.1.0",
46
+ "react-test-renderer": "^18.1.0",
47
+ "rimraf": "^3.0.2",
48
+ "tsup": "^5.12.7",
49
+ "typescript": "^4.6.2",
50
+ "vitest": "^0.12.6"
51
+ },
52
+ "peerDependencies": {
53
+ "react": ">=16"
54
+ }
55
+ }
package/readme.md ADDED
@@ -0,0 +1,377 @@
1
+ # Iconify for React
2
+
3
+ Iconify for React is not yet another icon component! There are many of them already.
4
+
5
+ What you get with other components:
6
+
7
+ - Limited set of icons.
8
+ - Large bundle size because all icons are bundled.
9
+
10
+ Iconify icon component is nothing like that. Component does not include any icon data, it is not tied to any specific icon set. Instead, all data is retrieved from public API on demand.
11
+
12
+ That means:
13
+
14
+ - One syntax for over 100,000 icons from 100+ icon sets.
15
+ - Renders SVG. Many components simply render icon fonts, which look ugly. Iconify renders pixel perfect SVG.
16
+ - Loads icons on demand. No need to bundle icons, component will automatically load icon data for icons that you use from Iconify API.
17
+
18
+ For more information about Iconify project visit [https://iconify.design/](https://iconify.design/).
19
+
20
+ For extended documentation visit [Iconify for React documentation](https://docs.iconify.design/icon-components/react/).
21
+
22
+ ## Installation
23
+
24
+ If you are using NPM:
25
+
26
+ ```bash
27
+ npm install --save-dev @iconify/react
28
+ ```
29
+
30
+ If you are using Yarn:
31
+
32
+ ```bash
33
+ yarn add --dev @iconify/react
34
+ ```
35
+
36
+ ## Usage with API
37
+
38
+ Install `@iconify/react` and import `Icon` from it:
39
+
40
+ ```typescript
41
+ import { Icon } from '@iconify/react';
42
+ ```
43
+
44
+ Then use `Icon` component with icon name or data as "icon" parameter:
45
+
46
+ ```jsx
47
+ <Icon icon="mdi-light:home" />
48
+ ```
49
+
50
+ Component will automatically retrieve data for "mdi-light:home" from Iconify API and render it. There are over 100,000 icons available on Iconify API from various free and open source icon sets, including all the most popular icon sets.
51
+
52
+ ## Offline Usage
53
+
54
+ Retrieving icon data from Iconify API requires visitor to be online. What if you want to use component offline or on local network?
55
+
56
+ If you want to use icon component without relying on public Iconify API, there are several options:
57
+
58
+ 1. You can import icon data from Iconify Icons packages.
59
+ 2. You can create custom icon bundles (more efficient, but requires more coding).
60
+ 3. You can host your own Iconify API instead of relying on third party service.
61
+
62
+ See [Iconify for React offline use documentation](https://docs.iconify.design/icon-components/react/offline.html) or [Iconify API documentation](https://docs.iconify.design/sources/api/).
63
+
64
+ ## Icon Names
65
+
66
+ Icon name is a string. Few examples:
67
+
68
+ - `@api-provider:icon-set-prefix:icon-name`
69
+ - `mdi-light:home` (in this example API provider is empty, so it is skipped)
70
+
71
+ It has 3 parts, separated by ":":
72
+
73
+ - provider points to API source. Starts with "@", can be empty (empty value is used for public Iconify API).
74
+ - prefix is name of icon set.
75
+ - name is name of icon.
76
+
77
+ See [Iconify for React icon names documentation](https://docs.iconify.design/icon-components/react/icon-name.html) for more detailed explanation.
78
+
79
+ ## Using icon data
80
+
81
+ Instead of icon name, you can pass icon data to component:
82
+
83
+ ```jsx
84
+ import { Icon } from '@iconify/react';
85
+ import home from '@iconify-icons/mdi-light/home';
86
+
87
+ function renderHomeIcon() {
88
+ return <Icon icon={home} />;
89
+ }
90
+ ```
91
+
92
+ See [icon packages documentation](https://docs.iconify.design/sources/npm/) for more details.
93
+
94
+ ### Next.js notice
95
+
96
+ Example above will currently fail with Next.js. This is because Next.js uses outdated packaging software that does not support ES modules. But do not worry, there is a simple solution: switch to CommonJS icon packages.
97
+
98
+ To switch to CommonJS package, replace this line in example above:
99
+
100
+ ```js
101
+ import home from '@iconify-icons/mdi-light/home';
102
+ ```
103
+
104
+ with
105
+
106
+ ```js
107
+ import home from '@iconify/icons-mdi-light/home';
108
+ ```
109
+
110
+ All icons are available as ES modules for modern bundler and as CommonJS modules for outdated bundlers. ES modules use format `@iconify-icons/{prefix}`, CommonJS modules use `@iconify/icons-{prefix}`.
111
+
112
+ For more details, see [icon packages documentation](https://docs.iconify.design/sources/npm/).
113
+
114
+ ## Inline icon
115
+
116
+ Icons have 2 modes: inline and block. Difference between modes is `vertical-align` that is added to inline icons.
117
+
118
+ Inline icons are aligned slightly below baseline, so they look centred compared to text, like glyph fonts.
119
+
120
+ Block icons do not have alignment, like images, which aligns them to baseline by default.
121
+
122
+ Alignment option was added to make icons look like continuation of text, behaving like glyph fonts. This should make migration from glyph fonts easier.
123
+
124
+ ```jsx
125
+ import React from 'react';
126
+ import { Icon, InlineIcon } from '@iconify/react';
127
+
128
+ export function inlineDemo() {
129
+ return (
130
+ <div>
131
+ <p>
132
+ Block:
133
+ <Icon icon="line-md:image-twotone" />
134
+ <Icon icon="mdi:account-box-outline" />
135
+ </p>
136
+ <p>
137
+ Inline:
138
+ <InlineIcon icon="line-md:image-twotone" />
139
+ <InlineIcon icon="mdi:account-box-outline" />
140
+ </p>
141
+ </div>
142
+ );
143
+ }
144
+ ```
145
+
146
+ To toggle between block and inline modes, you can either use `InlineIcon` or use boolean `inline` property:
147
+
148
+ ```jsx
149
+ import React from 'react';
150
+ import { Icon } from '@iconify/react';
151
+
152
+ export function inlineDemo() {
153
+ return (
154
+ <div>
155
+ <p>
156
+ Block:
157
+ <Icon icon="line-md:image-twotone" />
158
+ <Icon icon="mdi:account-box-outline" />
159
+ </p>
160
+ <p>
161
+ Inline:
162
+ <Icon icon="line-md:image-twotone" inline={true} />
163
+ <Icon icon="mdi:account-box-outline" inline={true} />
164
+ </p>
165
+ </div>
166
+ );
167
+ }
168
+ ```
169
+
170
+ Visual example to show the difference between inline and block modes:
171
+
172
+ ![Inline icon](https://iconify.design/assets/images/inline.png)
173
+
174
+ ## Icon component properties
175
+
176
+ `icon` property is mandatory. It tells component what icon to render. The value can be a string containing the icon name or an object containing the icon data.
177
+
178
+ The icon component has the following optional properties:
179
+
180
+ - `inline`. Changes icon behaviour to match icon fonts. See "Inline icon" section above.
181
+ - `width` and `height`. Icon dimensions. The default values are "1em" for both. See "Dimensions" section below.
182
+ - `color`. Icon colour. This is the same as setting colour in style. See "Icon colour" section below.
183
+ - `flip`, `hFlip`, `vFlip`. Flip icon horizontally and/or vertically. See "Transformations" section below.
184
+ - `rotate`. Rotate icon by 90, 180 or 270 degrees. See "Transformations" section below.
185
+ - `align`, `vAlign`, `hAlign`, `slice`. Icon alignment. See "Alignment" section below.
186
+ - `onLoad`. Callback function that is called when icon data has been loaded. See "onLoad" section below.
187
+
188
+ ### Other properties and events
189
+
190
+ In addition to the properties mentioned above, the icon component accepts any other properties and events. All other properties and events will be passed to generated `SVG` element, so you can do stuff like assigning `onClick` event, setting the inline style, add title and so on.
191
+
192
+ ### Dimensions
193
+
194
+ By default, icon height is "1em". With is dynamic, calculated using the icon's width to height ratio. This makes it easy to change icon size by changing `font-size` in the stylesheet, just like icon fonts.
195
+
196
+ There are several ways to change icon dimensions:
197
+
198
+ - Setting `font-size` in style (or `fontSize` if you are using inline style).
199
+ - Setting `width` and/or `height` property.
200
+
201
+ Values for `width` and `height` can be numbers or strings.
202
+
203
+ If you set only one dimension, another dimension will be calculated using the icon's width to height ratio. For example, if the icon size is 16 x 24, you set the height to 48, the width will be set to 32. Calculations work not only with numbers, but also with string values.
204
+
205
+ #### Dimensions as numbers
206
+
207
+ You can use numbers for `width` and `height`.
208
+
209
+ ```jsx
210
+ <Icon icon={homeIcon} height={24} />
211
+ ```
212
+
213
+ ```jsx
214
+ <Icon icon="mdi-light:home" width={16} height={16} />
215
+ ```
216
+
217
+ Number values are treated as pixels. That means in examples above, values are identical to "24px" and "16px".
218
+
219
+ #### Dimensions as strings without units
220
+
221
+ If you use strings without units, they are treated the same as numbers in an example above.
222
+
223
+ ```jsx
224
+ <Icon icon={homeIcon} height="24" />
225
+ ```
226
+
227
+ ```jsx
228
+ <Icon icon="mdi-light:home" width="16" height={'16'} />
229
+ ```
230
+
231
+ #### Dimensions as strings with units
232
+
233
+ You can use units in width and height values:
234
+
235
+ ```jsx
236
+ <Icon icon="mdi-light:home" height="2em" />
237
+ ```
238
+
239
+ Be careful when using `calc`, view port based units or percentages. In SVG element they might not behave the way you expect them to behave and when using such units, you should consider settings both width and height.
240
+
241
+ #### Dimensions as 'auto'
242
+
243
+ Keyword "auto" sets dimensions to the icon's `viewBox` dimensions. For example, for 24 x 24 icon using `height="auto"` sets height to 24 pixels.
244
+
245
+ ```jsx
246
+ <Icon icon="mdi-light:home" height="auto" />
247
+ ```
248
+
249
+ ### Icon colour
250
+
251
+ There are two types of icons: icons that do not have a palette and icons that do have a palette.
252
+
253
+ Icons that do have a palette, such as emojis, cannot be customised. Setting colour to such icons will not change anything.
254
+
255
+ Icons that do not have a palette can be customised. By default, colour is set to "currentColor", which means the icon's colour matches text colour. To change the colour you can:
256
+
257
+ - Set `color` style or use stylesheet to target icon. If you are using the stylesheet, target `svg` element.
258
+ - Add `color` property.
259
+
260
+ Examples:
261
+
262
+ Using `color` property:
263
+
264
+ ```jsx
265
+ <Icon icon="eva:alert-triangle-fill" color="red" />
266
+ <Icon icon="eva:alert-triangle-fill" color="#f00" />
267
+ ```
268
+
269
+ Using inline style:
270
+
271
+ ```jsx
272
+ <Icon icon="eva:alert-triangle-fill" style={{color: 'red'}} />
273
+ <Icon icon="eva:alert-triangle-fill" style={{color: '#f00'}} />
274
+ ```
275
+
276
+ Using stylesheet:
277
+
278
+ ```jsx
279
+ <Icon icon="eva:alert-triangle-fill" className="red-icon" />
280
+ ```
281
+
282
+ ```css
283
+ .red-icon {
284
+ color: red;
285
+ }
286
+ ```
287
+
288
+ ### Transformations
289
+
290
+ You can rotate and flip the icon.
291
+
292
+ This might seem redundant because icon can also be rotated and flipped using CSS transformations. So why do transformation properties exist? Because it is a different type of transformation.
293
+
294
+ - CSS transformations transform the entire icon.
295
+ - Icon transformations transform the contents of the icon.
296
+
297
+ If you have a square icon, this makes no difference. However, if you have an icon that has different width and height values, it makes a huge difference.
298
+
299
+ Rotating 16x24 icon by 90 degrees results in:
300
+
301
+ - CSS transformation keeps 16x24 bounding box, which might cause the icon to overlap text around it.
302
+ - Icon transformation changes bounding box to 24x16, rotating content inside an icon.
303
+
304
+ See [icon transformations documentation](https://docs.iconify.design/icon-components/react/transform.html) for more details.
305
+
306
+ #### Flipping an icon
307
+
308
+ There are several properties available to flip an icon:
309
+
310
+ - `hFlip`: boolean property, flips icon horizontally.
311
+ - `vFlip`: boolean property, flips icon vertically.
312
+ - `flip`: shorthand string property, can flip icon horizontally and/or vertically.
313
+
314
+ Examples:
315
+
316
+ Flip an icon horizontally:
317
+
318
+ ```jsx
319
+ <Icon icon="eva:alert-triangle-fill" hFlip={true} />
320
+ <Icon icon="eva:alert-triangle-fill" flip="horizontal" />
321
+ ```
322
+
323
+ Flip an icon vertically:
324
+
325
+ ```jsx
326
+ <Icon icon="eva:alert-triangle-fill" vFlip={true} />
327
+ <Icon icon="eva:alert-triangle-fill" flip="vertical" />
328
+ ```
329
+
330
+ Flip an icon horizontally and vertically (the same as 180 degrees rotation):
331
+
332
+ ```jsx
333
+ <Icon icon="eva:alert-triangle-fill" hFlip={true} vFlip={true} />
334
+ <Icon icon="eva:alert-triangle-fill" flip="horizontal,vertical" />
335
+ ```
336
+
337
+ #### Rotating an icon
338
+
339
+ An icon can be rotated by 90, 180 and 270 degrees. Only contents of the icon are rotated.
340
+
341
+ To rotate an icon, use `rotate` property. Value can be a string (degrees or percentages) or a number.
342
+
343
+ Number values are 1 for 90 degrees, 2 for 180 degrees, 3 for 270 degrees.
344
+
345
+ Examples of 90 degrees rotation:
346
+
347
+ ```jsx
348
+ <Icon icon="eva:alert-triangle-fill" rotate={1} />
349
+ <Icon icon="eva:alert-triangle-fill" rotate="90deg" />
350
+ <Icon icon="eva:alert-triangle-fill" rotate="25%" />
351
+ ```
352
+
353
+ ### onLoad
354
+
355
+ `onLoad` property is an optional callback function. It is called when icon data has been loaded.
356
+
357
+ It is not an event, such as `onClick` event for links, it is a simple callback function.
358
+
359
+ When `onLoad` is called:
360
+
361
+ - If value of icon property is an object, `onLoad` is not called.
362
+ - If value of icon property is a string and icon data is available, `onLoad` is called on first render.
363
+ - If value of icon property is a string and icon data is not available, `onLoad` is called on first re-render after icon data is retrieved from API.
364
+
365
+ What is the purpose of `onLoad`? To let you know when Icon component renders an icon and when it does not render anything. This allows you to do things like adding class name for parent element, such as "container--with-icon" that modify layout if icon is being displayed.
366
+
367
+ ## Full documentation
368
+
369
+ For extended documentation visit [Iconify for React documentation](https://docs.iconify.design/icon-components/react/).
370
+
371
+ ## License
372
+
373
+ React component is released with MIT license.
374
+
375
+ © 2019 - 2022 Vjacheslav Trushkin / Iconify OÜ
376
+
377
+ See [Iconify icon sets page](https://icon-sets.iconify.design/) for list of collections and their licenses.
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "strict": true,
6
+ "skipLibCheck": true,
7
+ "moduleResolution": "node",
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "importsNotUsedAsValues": "error",
11
+ "resolveJsonModule": true,
12
+ "jsx": "react-jsx"
13
+ }
14
+ }
package/tsup.config.js ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/iconify.ts'],
5
+ format: ['cjs', 'esm'],
6
+ splitting: false,
7
+ sourcemap: false,
8
+ clean: true,
9
+ dts: true,
10
+ target: 'esnext',
11
+ });
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ test: {
7
+ globals: true,
8
+ watch: false,
9
+ include: ['**/tests/*-test.{ts,tsx}'],
10
+ transformMode: {
11
+ web: [/\.[jt]sx$/],
12
+ },
13
+ },
14
+ });