Giter VIP home page Giter VIP logo

Comments (6)

wayne-shih avatar wayne-shih commented on May 6, 2024 1

alternatively, another way of thinking of this is the .notdef (aka. tofu) glyph in fonts...
https://docs.microsoft.com/en-us/typography/opentype/spec/recom#glyph-0-the-notdef-glyph
which is what normally gets displayed when a glyph requested isn't in the font

visually could be something like this:
image

pro of this would be if phosphor gets converted into (web) icon fonts as .notdef is a required glyph (although sometimes left blank visually, so it looks like a space)

from homepage.

rektdeckard avatar rektdeckard commented on May 6, 2024 1

This is the way. Phosphor already has an icon font implementation, and we currently use a blank space for .notdef, but this is much better and solves both problems.

from homepage.

rektdeckard avatar rektdeckard commented on May 6, 2024

Interesting idea. Personally I would spring for something simple like:

<svg xmlns="http://www.w3.org/2000/svg" height={size} width={size}></svg>

But I could see the need for a library solution for cases where you wanted to make use of Context or composition. Will definitely consider adding it. In the mean time, you can make your own, since we give you all the icon dependencies as public exports:

import React, { forwardRef, memo, useContext } from "react";
import { IconProps, IconContext } from "phosphor-react";

const EmptyIcon = memo(
  forwardRef<SVGSVGElement, IconProps>((props, ref) => {
    const { color, size, weight, mirrored, children, ...restProps } = props;
    const {
      color: contextColor,
      size: contextSize,
      weight: contextWeight,
      mirrored: contextMirrored,
      ...restContext
    } = useContext(IconContext);

    return (
      <svg
        ref={ref}
        xmlns="http://www.w3.org/2000/svg"
        width={size ?? contextSize}
        height={size ?? contextSize}
        fill={color ?? contextColor}
        viewBox="0 0 256 256"
        transform={mirrored || contextMirrored ? "scale(-1, 1)" : undefined}
        {...restContext}
        {...restProps}
      >
        {children}
        <rect width="256" height="256" fill="none" />
      </svg>
    );
  })
);

export default EmptyIcon;

Here I included the Context and seemingly irrelevant props in the case you would want to do something conditionally with them, but you could leave them out.

from homepage.

rektdeckard avatar rektdeckard commented on May 6, 2024

A more minimal example that's still context and ref-aware:

import React, { forwardRef, memo, useContext } from "react";
import { IconProps, IconContext } from "phosphor-react";

const EmptyIcon = memo(
  forwardRef<SVGSVGElement, IconProps>(({ size }, ref) => {
    const { size: contextSize } = useContext(IconContext);

    return (
      <svg
        ref={ref}
        xmlns="http://www.w3.org/2000/svg"
        width={size ?? contextSize}
        height={size ?? contextSize}
        fill="none"
      />
    );
  })
);

export default EmptyIcon;

from homepage.

rektdeckard avatar rektdeckard commented on May 6, 2024

I just realized I thought this issue was on the phosphor-react library, and the example reflects that. But I guess the point still stands, it's an interesting idea but I'm not totally warm to including it yet.

from homepage.

rektdeckard avatar rektdeckard commented on May 6, 2024

placeholder icon added in 1.2.0!

from homepage.

Related Issues (20)

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.