npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pmwcs/badge

v1.1.0

Published

PMWCS badge component

Downloads

4

Readme

Badges (PMWCS Addon)

Badges are small status descriptors for UI elements. A badge consists of a small circle, typically containing a number or other short set of characters, that appears in proximity to another object.

  • Module @pmwcs/badge
  • Import styles:
    • Using CSS Loader
      • import '@pmwcs/badge/styles';
    • Or include stylesheets
      • '@pmwcs/badge/badge.css'
<Badge align="inline" />
<>
  <Badge align="inline" label={20} />
  <Badge align="inline" label="99+" />
  <Badge align="inline" label="New" />
</>
<>
  <Badge theme={['primaryBg', 'onPrimary']} align="inline" />
  <Badge style={{ background: 'hotpink' }} align="inline" />
  <Badge
    theme={['secondaryBg', 'onSecondary']}
    align="inline"
    label="Theme"
  />
</>

Usage with other components

The badge component has been designed to play well with the majority of components in PMWCS. You can place it inside of any component that accepts children and its default position will be absolute to the top end corner.

Because passing a Badge as a child doesn't always work (for things like overflow: hidden elements), you can use the BadgeAnchor component. This is really just a div with position: relative and some other sensible layout properties set on it, so you can use this or your own CSS to achieve the same result. Additionally, exact positioning is highly dependent on your design and shape of your components. Badges provide an inset property that allows you to adjust the positioning of the Badge as necessary.

<>
  <BadgeAnchor>
    <Button raised label="Button" />
    <Badge />
  </BadgeAnchor>

  <BadgeAnchor>
    <Button
      raised
      label="Button"
      theme={['secondaryBg', 'onSecondary']}
    />
    <Badge style={{ background: 'hotpink' }} label="Hello" />
  </BadgeAnchor>
</>
<BadgeAnchor>
  <IconButton icon="notifications" />
  <Badge inset="0.75rem" />
</BadgeAnchor>
<>
  <BadgeAnchor>
    <Avatar
      src="images/avatars/ironman.png"
      size="large"
      name="Tony Stark"
    />
    <Badge inset="5px" />
  </BadgeAnchor>

  <BadgeAnchor>
    <Avatar
      src="images/avatars/blackwidow.png"
      size="large"
      name="Natalia Alianovna Romanova"
      square
    />
    <Badge />
  </BadgeAnchor>
</>

Alignment

Badges can be aligned to the start, end, or use inline alignment. They are also RTL aware. They default to align end.

<>
  <BadgeAnchor>
    <Button raised label="Align Start" />
    <Badge align="start" />
  </BadgeAnchor>

  <BadgeAnchor>
    <Button raised label="Align End" />
    <Badge align="end" />
  </BadgeAnchor>
</>

Transitions

You can transition between the standalone indicator and a badge with content. The badge will consider any label other than null or undefined as valid content.

function Example() {
  const [label, setLabel] = React.useState(undefined);

  React.useEffect(() => {
    const timeout = setTimeout(() => {
      switch (label) {
        case '99+':
          setLabel(undefined);
          break;
        case '':
          setLabel('99+');
          break;
        case undefined:
          setLabel('');
          break;
      }
    }, 1800);

    return () => clearTimeout(timeout);
  }, [label]);

  return (
    <BadgeAnchor>
      <Button raised label="Button" />
      <Badge label={label} exited={label === undefined} />
    </BadgeAnchor>
  );
}

Badge

A Badge component for indicating alerts or counts.

Props

| Name | Type | Description | |------|------|-------------| | align | "end" \| "start" \| "inline" | How to align the badge. | | exited | undefined \| false \| true | Animates the badge out of view. When this class is removed, the badge will return to view. | | inset | string \| number | A value to inset the badge alignment by, useful for positioning the badge on different shaped components. | | label | React.ReactNode \| number | A label or count for the badge. |

BadgeAnchor

An anchor component for badges.