Gathering detailed insights and metrics for phosphor-react-sc
Gathering detailed insights and metrics for phosphor-react-sc
A flexible icon family for React Server Components
npm install phosphor-react-sc
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.83%)
JavaScript (0.14%)
CSS (0.02%)
HTML (0.01%)
Total Downloads
8,217
Last Day
24
Last Week
150
Last Month
378
Last Year
4,569
6 Stars
166 Commits
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
phosphor-react-sc@1.0.0
Unpacked Size
12.56 MB
Size
2.51 MB
File Count
2,507
NPM Version
9.5.1
Node Version
18.16.1
Publised On
18 Jul 2023
Cumulative downloads
Total Downloads
Last day
-14.3%
24
Compared to previous day
Last week
27.1%
150
Compared to previous week
Last month
7.1%
378
Compared to previous month
Last year
25.2%
4,569
Compared to previous year
Phosphor is a flexible icon family for interfaces, diagrams, presentations — whatever, really. Explore all our icons at phosphoricons.com.
Supports React Server Components: This is a fork of @phosphor-icons/react. The only change is that the icons no longer use useContext
in order to support React Server Components.
1yarn add phosphor-react-sc
or
1npm install --save phosphor-react-sc
Simply import the icons you need, and add them anywhere in your render method. Phosphor supports tree-shaking, so your bundle only includes code for the icons you use.
1import { Horse, Heart, Cube } from "phosphor-react-sc"; 2 3const App = () => { 4 return ( 5 <main> 6 <Horse /> 7 <Heart color="#AE2983" weight="fill" size={32} /> 8 <Cube color="teal" weight="duotone" /> 9 </main> 10 ); 11};
Icon components accept all props that you can pass to a normal SVG element, including inline style
objects, onClick
handlers, and more. The main way of styling them will usually be with the following props:
string
– Icon stroke/fill color. Can be any CSS color string, including hex
, rgb
, rgba
, hsl
, hsla
, named colors, or the special currentColor
variable.number | string
– Icon height & width. As with standard React elements, this can be a number, or a string with units in px
, %
, em
, rem
, pt
, cm
, mm
, in
."thin" | "light" | "regular" | "bold" | "fill" | "duotone"
– Icon weight/style. Can also be used, for example, to "toggle" an icon's state: a rating component could use Stars with weight="regular"
to denote an empty star, and weight="fill"
to denote a filled star.boolean
– Flip the icon horizontally. Can be useful in RTL languages where normal icon orientation is not appropriate.string
– Add accessible alt text to an icon.Components can accept arbitrary SVG elements as children, so long as they are valid children of the <svg>
element. This can be used to modify an icon with background layers or shapes, filters, animations and more. The children will be placed below the normal icon contents.
The following will cause the Cube icon to rotate and pulse:
1const RotatingCube = () => { 2 return ( 3 <Cube color="darkorchid" weight="duotone"> 4 <animate 5 attributeName="opacity" 6 values="0;1;0" 7 dur="4s" 8 repeatCount="indefinite" 9 ></animate> 10 <animateTransform 11 attributeName="transform" 12 attributeType="XML" 13 type="rotate" 14 dur="5s" 15 from="0 0 0" 16 to="360 0 0" 17 repeatCount="indefinite" 18 ></animateTransform> 19 </Cube> 20 ); 21};
Note: The coordinate space of slotted elements is relative to the contents of the icon
viewBox
, which is a 256x256 square. Only valid SVG elements will be rendered.
You may wish to import all icons at once for use in your project, though depending on your bundler this could prevent tree-shaking and make your app's bundle larger.
1import * as Icon from "phosphor-react-sc"; 2 3<Icon.Smiley /> 4<Icon.Folder weight="thin" /> 5<Icon.BatteryHalf size="24px" />
It is possible to extend Phosphor with your own custom icons and taking advantage of the styling. To create a custom icon, first design your icons on a 256x256 pixel grid, and export them as SVG. For best results, flatten the icon so that you only export assets with path
elements. Strip any fill
or stroke
attributes, as these will be inherited from the wrapper.
Next, create a new React forwardRef
component, importing the IconBase
component, as well as the Icon
and IconWeight
types from this library. Define a Map<IconWeight, ReactElement>
that maps each icon weight to the contents of each SVG asset, effectively removing the wrapping <svg>
element from each. Name your component, and render an <IconBase />
, passing all props and the ref, as well as the weights
you defined earlier, as JSX props:
1import { forwardRef, ReactElement } from "react"; 2import { Icon, IconBase, IconWeight } from "phosphor-react-sc"; 3 4const weights = new Map<IconWeight, ReactElement>([ 5 ["thin", <path d="..." />], 6 ["light", <path d="..." />], 7 ["regular", <path d="..." />], 8 ["bold", <path d="..." />], 9 ["fill", <path d="..." />], 10 [ 11 "duotone", 12 <> 13 <path d="..." opacity="0.2" /> 14 <path d="..." /> 15 </>, 16 ], 17]); 18 19const CustomIcon: Icon = forwardRef((props, ref) => ( 20 <IconBase ref={ref} {...props} weights={weights} /> 21)); 22 23CustomIcon.displayName = "CustomIcon"; 24 25export default CustomIcon;
NOTE: If you have multiple child elements, wrap them in a
Fragment
. Typically ourduotone
icons have multiple elements, with the background layer at 20% opacity.
If you've made a port of Phosphor and you want to see it here, just open a PR here!
MIT © Phosphor Icons
No vulnerabilities found.
No security vulnerabilities found.