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

@agney/react-avatar

v1.1.2

Published

Create Image Avatars with text based fallbacks.

Downloads

182

Readme

React Avatar

All Contributors

Create Image Avatars with text based fallbacks.

Demo Storybook

Features ✨

  1. Ability to render image avatar or text avatar as circle or square.
  2. Ability to render text based fallbacks for images for the time they take to load or error.
  3. Renders text based avatars and backgrounds based on text passed in.
  4. Autoscales text if it doesn't fit the container width.
  5. Automatically determines readable text color depending on background.
  6. Exposes a hook to use/generate gravatar for a user.
  7. Exposes a context so you can configure avatar components across your application.

Install

npm install @agney/react-avatar
# OR
yarn add @agney/react-avatar

Requires React v16.8 or above and Styled Components v4 or above.

Usage

import React from "react";
import { Avatar } from "@agney/react-avatar";

const App = () => {
  return (
    <Avatar
      src="https://gravatar.com/avatar/7c4ff521986b4ff8d29440beec01972d?s=400&d=robohash&r=x"
      text="CM"
    />
  );
}

export default App;

API

| | Description | Default Value | |:-------------: |---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |----------------------------------------------------------------------------------- | | src | Source of image to be displayed | | | text | Text to be displayed as fallback | | | imageAlt | Alt tag for image | '' - decorative | | shape | shape of avatar. options: 'circle' | 'square' | circle | | htmlWidth | width of image element and text fallback. | 100% | | htmlHeight | height of image element and text fallback | same as htmlWidth | | backgrounds | Array of background colors | ['#3c40c6','#ffa801','#485460','#0be881','#f53b57'] | | bgColor | background color for specific text fallback. | picks random from backgrounds, this changes according to text prop passed in. | | textColor | text color for specific text fallback | readable dark or light color depending on background. | | textProcessor | function to process visible text inside the avatar. Original text will be used for hashing so even ones with same initials inside avatar can have different backgrounds. | (text) => text | | className | className on the wrapper. can be used for wrapping with CSS-in-JS frameworks | |

See Storybook for more examples and code snippets.

Context

Package exposes a context in the form of AvatarContext.

import { Avatar, AvatarContext } from '../.';

function App() {
  const contextValue = React.useMemo(() => ({
    backgrounds: ['#000000', '#DD2C00', '#6200EA', '#3F51B5'], // Any props used by Avatar can be used here.
  }), []);
  return (
    <AvatarContext.Provider>
      <div style={{ display: 'flex' }}>
        <Avatar
          htmlWidth='150px'
          text="Fallback"
          backgrounds={['red']}
          textColor='white'
        />
        <Avatar
          htmlWidth='150px'
          text="AJ"
        />
      </div>
    </AvatarContext.Provider>
  )
}

Values on the Context Provider are overridden by any props that are on the individual component. Context Provider is not compulsory for usage of Avatar component. Read more about Context API on docs.

useGravatar hook

Gravatars or Globally Recognized Avatars is a free service that allows you to share profile pictures/avatars across different sites and services. react-avatar exposes a hook that makes it easier for you to request and use these gravatars in your application.

Usage:

import React from "react";
import { Avatar, useGravatar } from "@agney/react-avatar";

const App = () => {
  const url = useGravatar('[email protected]');
  return (
    <Avatar
      src={url}
      text="CM"
    />
  );
}

export default App;

API

| Argument | Description | Default | |--------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |--------- | | email | Email of the person for which gravatar is to be fetched | | | config | configuration object. following fields are part of this object | | | config.size | number representing height & width of image. 1px up to 2048px | 80 | | config.defaultImage | If the image is not available, gravatar defaults to this property. You can provide a custom URL image to default to or one of the alternatives that Gravatar supports. | | | config.forceDefault | Always returns the default image if true | false | | config.rating | Gravatar allows users to self rate their images. If required pass in a higher rating. | g |

For a complete list of available options, view Gravatar docs

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Development

We use yarn v1 for development.

yarn
yarn start

# To run example
cd example
yarn start

# Running storybook
yarn run storybook

Run tests

yarn test

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 Agney Menon [email protected]. This project is MIT licensed.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!