Coder Social home page Coder Social logo

core's Introduction

@phosphor-icons/core

This repository hosts the raw SVGs and catalog data – including tags, categories, and release versions – of all icons in the Phosphor Icons family. It serves as the basis for our fuzzy-search on our website and other tools, and as a dev dependency in the build process in some of our framework-specific libraries. You may find this package is useful to you in implementing a port of Phosphor to your preferred framework, or as a source of truth for our current SVG assets.

NPM GitHub stars GitHub forks GitHub watchers Follow on GitHub

Installation

pnpm add @phosphor-icons/core
#^ or whatever package manager you use

Assets

This package exposes all icons as SVG assets, grouped by weight, under the /assets directory (i.e. /assets/<weight>/<kebab-name>-<weight>.svg), and also aliased so that /assets can be omitted from the path in projects that support import maps. These files can be used as needed for custom implementations or ports. Your framework and build tooling may require custom type declarations to recognize and transform "*.svg" files into modules.

Note for Vite users: As of Vite 4.0.4 (current at the time of writing), a bug in one of its dependencies prevents wildcard exports from being resolved. This will be fixed in Vite 4.1.

Example

import ghostDuotone from "@phosphor-icons/core/duotone/ghost-duotone.svg";

Using SVGR (includes create-react-app projects):

import { ReactComponent as GhostDuotone } from "@phosphor-icons/core/duotone/ghost-duotone.svg";

Catalog

This package exposes a named export icons, which is an array of IconEntry objects represententing each icon, its name in both kebab-case and PascalCase, the catergories and tags associated with it, as well as the version it was published in and the most recent version it was updated in.

It also includes an optional alias field, which if present, contains deprecated names for the icon for backwards-compatibility purposes, and a codepoint field, which is a stable decimal representation of its Unicode code point in font implementations such as @phosphor-icons/web and @phosphor-icons/flutter.

interface IconEntry {
  name: string; // "cloud-lightning"
  pascal_name: string; // "CloudLightning"
  alias?: {
    name: string;
    pascal_name: string;
  };
  codepoint: number;
  categories: readonly IconCategory[]; // ["weather"]
  tags: readonly string[]; // ["*updated*", "meteorology", "cloudy", "overcast", "stormy", "thunderstorm"]
  published_in: number; // 1.0
  updated_in: number; // 1.4
}

Note: Duotone icons rely on overlaying two glyphs (a background and foreground layer), and thus use 2 codepoints. All codepoint bases are even numbers, so the codepoints associated with duotone icons are codepoint and codepoint + 1. The codepoint feature is not yet stabilized, and should only be relied upon in versions >=2.1.0.

An additional type export, PhosphorIcon, represents the literal type of the icons list. You can use it to extract narrowed types such as valid icon names, which can be useful for constraining parameter types in ports:

type IconName = PhosphorIcon["name"];
/* type IconName = "function" | "address-book" | "air-traffic-control" | "buildings" | "airplane" |
 *                 "airplane-in-flight" | "airplane-landing" | "airplane-takeoff" | "airplane-tilt" |
 *                 "airplay" | ... 1237 more ... | "youtube-logo"
 */

Our Related Projects

Community Projects

If you've made a port of Phosphor and you want to see it here, just open a PR here!

License

MIT © Phosphor Icons

core's People

Contributors

lxchurbakov avatar maful avatar maxichrome avatar minenwerfer avatar reatlat avatar rektdeckard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

core's Issues

Apple, Google, Discord logos look different than the official logos

While trying to add some logos in a project, I noticed that the Apple, Google and Discord logos look wildly different than the original ones. Is this intentional? The curves, weight, shapes do not match the ones provided by these brands. All of these icons have official SVG brand assets provided for free, wouldn't it be a better idea to use those and add the Phosphor specific features on top of them instead of redrawing all?
(Please ignore the color differences, I just couldn't find a black google logo)

Untitled

set stroke or fill to currentColor

it would be great if the svgs contain stroke=currentColor on the correct places to be able to use css properties to set the color of the icons.

[Feature request] Generate SVG sprites as a build step

(Not sure if this is the right place for feature requests. Feel free to move it somewhere more appropriate)

Motivation

Performance (load times, rendering, memory)

This is a visualization of our current production app bundle (no worries! it's split into multiple chunks in case anyone gets dizzy). There's quite a bit going on. The biggest chunk of node_modules/ is @phosphor-icons which takes up ~300kb of JS, notably (the orange slice). This stems from us using @phosphor-icons/react.
Bildschirmfoto 2023-07-24 um 18 29 48

Instead it would be beneficial if all of this could move over here, into the assets/ part of the app, as a static *.svg asset that can be cached by browsers and does not clutter JS bundles more than necessary.
Bildschirmfoto 2023-07-24 um 18 30 11

As Jason Miller points out correctly

Please don't import SVGs as JSX. It's the most expensive form of sprite sheet: costs a minimum of 3x more than other techniques, and hurts both runtime (rendering) performance and memory usage.

Developer experience

Technically, this is possible today by downloading and using the individual *.svg files instead of relying on @phosphor-icons/react. This comes with a significant decline in developer experience though, some of which is described nicely in The "best" way to manage icons in React.js

  1. SVGs rendered as <img /> cannot be styled using CSS
  2. Without preloading as a <link rel="preload" />, SVGs rendered as <img /> introduce request waterfalls for the initial load. Adding an appropriate preload tag for each icon gets tiring
  3. All of @phosphor-icons/react's benefits such as easily importing any of the icons or changing the icon's weight via nothing more than a prop change becomes way more tedious

The blog's proposed solution is to render SVGs as a sprite

<!-- sprite.svg -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <symbol viewBox="0 0 24 24" id="icon-1">
      <!-- svg content here -->
    </symbol>
    <symbol viewBox="0 0 24 24" id="icon-2">
       <!-- svg content here -->
    </symbol>
  </defs>
</svg>

and reference them in a component (taking React as an example)

function Icon({ id, ...props }) {
  return (
    <svg {...props}>
      <use href={`/sprite.svg#${id}`} />
    </svg>
  );
}

This solves both the performance problems as well as 1. (can be styled with CSS) and 2. (only need to preload one file) but still requires manual work to update the SVG sprite by hand each time a new icon is added / the weight is changed / phosphor receives an update where icons are improved/changed.
This can be improved partially by using remix-cli which provides a way to create an SVG sprite by pointing it at a folder containing individual *.svg files. But most of the above still holds true.

Proposed solution

Putting together all of the above, it would be ideal to have a solution that

  • creates an SVG sprite containing all the actually used phosphor-icons
  • is as convenient to use as @phosphor-icons/react with (partial?) support of all its features

For this to work, I propose new packages @phosphor-icons/react-sprite and @phosphor-icons/vue-sprite that both offer a <PhosphorIcon /> much like the <Icon /> component above, offering an interface including all the IconProps & { name: "address-book" | "air-traffic-control" | ... }.

On top of that, there'll need to be a build process much like the one of TailwindCSS:
Read the contents of *.[jsx, tsx, vue| files, find all <PhosphorIcon />s and evaluate their props. Based on that, generate a sprite.svg that can be imported in one place.
Unfortunately this comes with a rather major caveat I believe: Just as the tailwind build process, this requires to only put static strings as props since otherwise this cannot be statically analyzed without going through the immense pain of somehow evaluating dynamic code. One alternative I can think of is to offer named components <AddressBookThin />, <AddressBookLight /> and the likes that under the hood all resolve to the same <PhosphorIcon /> for the sole purpose of being able to statically analyze the code for the build process. This still feels kinda meh but all things considered might still be worth it considering the upsides. There may be other ideas I haven't thought of of course.

I understand that this is a passion project built in your guys' free time and something like this isn't done quickly. Just wanted to share some ideas! :)

Module not found

I'm trying to import SVGs in a Next project with @svgr/webpack loader setup.

import CubeTransparent from '@phosphor-icons/core/regular/cube-transparent.svg';

For some reason I get the following error:

Module not found: 
Package path ./regular/cube-transparent.svg is not exported from package /node_modules/@phosphor-icons/core
(see exports field in /node_modules/@phosphor-icons/core/package.json)

Not exactly sure what is going wrong as I do see the exports in the package.json. No issue when trying to import local SVGs 🤔

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.