![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@iconify-icon/react
Advanced tools
Iconify Icon web component is a wrapper for iconify-icon
package, which provides React component and typings.
For more information about Iconify project visit https://iconify.design/.
For documentation visit Iconify Icon web component documentation.
If you are using NPM:
npm install --save-dev @iconify-icon/react
If you are using Yarn:
yarn add --dev @iconify-icon/react
Install @iconify-icon/react
and import Icon
from it:
import { Icon } from '@iconify-icon/react';
Then use Icon
component with icon name or data as "icon" parameter:
<Icon icon="mdi-light:home" />
Component will automatically retrieve data for "mdi-light:home" from Iconify API and render it. There are over 150,000 icons available on Iconify API from various free and open source icon sets, including all the most popular icon sets.
Retrieving icon data from Iconify API requires visitor to be online. What if you want to use component offline or on local network?
If you want to use icon component without relying on public Iconify API, there are several options:
See offline use documentation or Iconify API documentation.
Icon name is a string. Few examples:
@api-provider:icon-set-prefix:icon-name
mdi-light:home
(in this example API provider is empty, so it is skipped)It has 3 parts, separated by ":":
See icon names documentation for more detailed explanation.
Instead of icon name, you can pass icon data to component:
import { Icon } from '@iconify-icon/react';
import home from '@iconify-icons/mdi-light/home';
function renderHomeIcon() {
return <Icon icon={home} />;
}
See icon packages documentation for more details.
Example above might 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.
To switch to CommonJS package, replace this line in example above:
import home from '@iconify-icons/mdi-light/home';
with
import home from '@iconify/icons-mdi-light/home';
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}
.
For more details, see icon packages documentation.
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.
The icon component has the following optional properties:
inline
. Adds vertical-align: -0.125em
to style to render it below text baseline, so it fits nicely in text.width
and height
. Icon dimensions. The default values are "1em" for both. See "Dimensions" section below.color
. Icon colour. This is the same as setting colour in style. See "Icon colour" section below.flip
. Flip icon horizontally and/or vertically. See "Transformations" section below.rotate
. Rotate icon by 90, 180 or 270 degrees. See "Transformations" section below.In addition to the properties mentioned above, the icon component accepts any other properties and events.
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.
There are several ways to change icon dimensions:
font-size
in style (or fontSize
if you are using inline style).width
and/or height
property.height="none"
to remove dimensions from SVG and using CSS to resize icon.Values for width
and height
can be numbers or strings.
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.
You can use numbers for width
and height
.
<Icon icon={homeIcon} height={24} />
<Icon icon="mdi-light:home" width={16} height={16} />
Number values are treated as pixels. That means in examples above, values are identical to "24px" and "16px".
If you use strings without units, they are treated the same as numbers in an example above.
<Icon icon={homeIcon} height="24" />
<Icon icon="mdi-light:home" width="16" height={'16'} />
You can use units in width and height values:
<Icon icon="mdi-light:home" height="2em" />
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. Use height="none"
and control dimensions with CSS instead (see below).
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.
<Icon icon="mdi-light:home" height="auto" />
If you want to control icon dimensions with CSS, do the following:
height
attribute to none
or unset
, which will remove attribute from rendered SVG.width
and height
for iconify-icon.<Icon icon="mdi-light:home" height="none" style={{width: '40px'; height: '40px'}} />
This allows easily changing width and height separately in CSS instead of relying on font-size. In some use cases you might need to add display: block;
to CSS.
There are two types of icons: icons that do not have a palette and icons that do have a palette.
Icons that do have a palette, such as emojis, cannot be customised. Setting colour to such icons will not change anything.
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 need to change text color.
Examples:
<Icon icon="eva:alert-triangle-fill" style={{color: 'red'}} />
<Icon icon="eva:alert-triangle-fill" style={{color: '#f00'}} />
Using stylesheet:
<Icon icon="eva:alert-triangle-fill" className="red-icon" />
.red-icon {
color: red;
}
You can rotate and flip the icon.
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.
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.
Rotating 16x24 icon by 90 degrees results in:
See icon transformations documentation for more details.
You can flip an icon horizontally and/or vertically by setting flip
property.
Examples:
Flip an icon horizontally:
<Icon icon="eva:alert-triangle-fill" flip="horizontal" />
Flip an icon vertically:
<Icon icon="eva:alert-triangle-fill" flip="vertical" />
Flip an icon horizontally and vertically (the same as 180 degrees rotation):
<Icon icon="eva:alert-triangle-fill" flip="horizontal,vertical" />
An icon can be rotated by 90, 180 and 270 degrees. Only contents of the icon are rotated.
To rotate an icon, use rotate
property. Value can be a string (degrees or percentages) or a number.
Number values are 1 for 90 degrees, 2 for 180 degrees, 3 for 270 degrees.
Examples of 90 degrees rotation:
<Icon icon="eva:alert-triangle-fill" rotate={1} />
<Icon icon="eva:alert-triangle-fill" rotate="90deg" />
<Icon icon="eva:alert-triangle-fill" rotate="25%" />
For extended documentation visit Iconify Icon web component documentation.
React component is released with MIT license.
© 2022 Vjacheslav Trushkin / Iconify OÜ
See Iconify icon sets page for list of icon sets and their licenses.
FAQs
React wrapper for Iconify Icon web component
The npm package @iconify-icon/react receives a total of 0 weekly downloads. As such, @iconify-icon/react popularity was classified as not popular.
We found that @iconify-icon/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.