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

@readyplayerme/react-avatar-creator

v0.5.0

Published

Ready Player Me - React Avatar Creator

Downloads

3,120

Readme

Ready Player Me - React Avatar Creator

Ready Player Me - React Avatar Creator is a set of components and helper methods to help implementing the Ready Player Me Avatar Creator into React projects.

Codesandbox example for loading the Avatar Creator: https://codesandbox.io/p/sandbox/ready-player-me-react-avatar-creator-qxkqjf

Codesandbox example for loading the Avatar Creator and visualizing the avatar with the Visage package: https://codesandbox.io/p/sandbox/ready-player-me-visage-example-l4m2k2

Installation

Ready Player Me React Avatar Creator is available as a npm package.

npm i @readyplayerme/react-avatar-creator

Usage

import { AvatarCreator } from '@readyplayerme/react-avatar-creator';

export default function App() {
  return <AvatarCreator subdomain="demo" style={{ width: '100%', height: '100vh', border: 'none' }} />;
}

https://user-images.githubusercontent.com/3163281/235168912-a9dacd91-af3a-4b35-81c3-b025e12e333a.mp4


Components

AvatarCreator

AvatarCreator component helps you load Ready Player Me in an iframe where you can edit your avatar and receive your avatar URL as a post message once your avatar is exported.

Parameters

subdomain [required]: string

className [optional]: string

  • The css classes to apply to the iframe.

style [optional]: CSSProperties

  • The css styles to apply to the iframe.

config [optional]: AvatarCreatorConfig

onAvatarExported [optional]: (event: AvatarExportedEvent) => void

  • Callback function that is called when avatar is exported.

onUserSet [optional]: (event: UserSetEvent) => void

  • Callback function that is called when user id is set.

onAssetUnlocked [optional]: (event: AssetUnlockedEvent) => void

  • Callback function that is called when an asset is unlocked.

onUserAuthorized [optional]: (event: UserAuthorizedEvent) => void

  • Callback function that is called when the user is authorized.

Example

import { AvatarCreator, AvatarCreatorConfig, AvatarExportedEvent, UserSetEvent } from '@readyplayerme/react-avatar-creator';

const config: AvatarCreatorConfig = {
  clearCache: true,
  bodyType: 'fullbody',
  quickStart: false,
  language: 'en',
};

const style = { width: '100%', height: '100vh', border: 'none' };

export default function App() {
  const handleOnUserSet = (event: UserSetEvent) => {
    console.log(`User ID is: ${event.data.id}`);
  };

  const handleOnAvatarExported = (event: AvatarExportedEvent) => {
    console.log(`Avatar URL is: ${event.data.url}`);
  };

  return (
    <>
      <AvatarCreator subdomain="demo" config={config} style={style} onUserSet={handleOnUserSet} onAvatarExported={handleOnAvatarExported} />
    </>
  );
}

AvatarCreatorRaw

AvatarCreatorRaw is a lower level component that gives you everything found in the avatar creator, but without explicit callbacks for each event, so you can have the ability to create your own custom logic around these events, if you choose to do so.

Parameters

subdomain [required]: string

className [optional]: string

  • The css classes to apply to the iframe.

style [optional]: CSSProperties

  • The css styles to apply to the iframe.

config [optional]: AvatarCreatorConfig

onEventReceived [required]: (event: IFrameEvent) => void

  • Callback function that is called whenever an AvatarCreatorEvent is published

Example

import { AvatarCreatorConfig, AvatarCreatorEvent, AvatarCreatorRaw } from '@readyplayerme/react-avatar-creator';

const config: AvatarCreatorConfig = {
  clearCache: true,
  bodyType: 'fullbody',
  quickStart: false,
  language: 'en',
};

const style = { width: '100%', height: '100vh', border: 'none' };

export default function App() {
  const handleCustomEvent = (event: AvatarCreatorEvent) => {
    console.log(`Received custom event`, event);
  };

  return (
    <>
      <AvatarCreatorRaw subdomain="demo" config={config} style={style} onEventReceived={handleCustomEvent} />
    </>
  );
}

Using AvatarCreator with Visage

If you would like to use Visage, with its full capability to edit camera and light properties of the scene and more, you can use AvatarCreator component and Visage components together.

import { Avatar } from '@readyplayerme/visage';
import { AvatarCreator, AvatarCreatorConfig } from '@readyplayerme/react-avatar-creator';
import { useState } from 'react';

const subdomain = 'demo';

const config: AvatarCreatorConfig = {
  clearCache: true,
  bodyType: 'fullbody',
  quickStart: false,
  language: 'en',
};

const style = { width: '100%', height: '100vh', border: 'none' };

export const YourCustomComponent = () => {
  const [url, setUrl] = useState<string>();

  if (!url) {
    return <AvatarCreator subdomain={subdomain} config={config} style={style} onAvatarExported={(event) => setUrl(event.data.url)} />;
  }
  return <Avatar style={style} modelSrc={url} cameraInitialDistance={10} />;
};