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

@atlaskit/media-avatar-picker

v25.0.5

Published

A component to select, drag and resize image avatars. It also provides a default list of predefined avatars.

Downloads

1,294

Readme

@atlaskit/media-avatar-picker

Provides a component to select, drag and resize image avatars. It also provides a default list of predefined avatars.

Installation

yarn add @atlaskit/media-avatar-picker

Using the component

Local Image Upload and Cropping

The AvatarPickerDialog allows the user to upload or drop a local image, then pan and zoom to a desired cropped view.

The default zoom level should fit the image within the crop area. Images smaller than the crop area are scaled up.

The component constrains the panning and scaling of the image to ensure that only valid regions are selectable by the user.

Pre-defined Avatars

The component also allows the user to select from pre-defined avatar images. These can be provided to the component via it's avatars property.

Pre-defined avatars are hidden when an image is chosen by the user.

Client-side only

The component is currently designed to pass back a selected image or avatar. It does not use any specific APIs for storage or upload, that is currently the responsibility of the consumer. In other words you will need a solution to store the selected image or avatar.

Limitations

The component currently only accepts image/gif, image/jpeg, and image/png mime types. SVG is not currently not supported.

The component only accepts images up to 10Mib.

Error Handling

The component will handle the following errors on the client:

  • Bad format - if the user uploads an image with a bad format, or drops an invalid mime type, an error will be shown
  • Image size > 10Mib - if the user uploads or drops an image greater than 10Mib in size, an error message will be shown

See the errorMessage property below to set your own custom error message if required.

API

onImagePicked?: (file: File, crop: CropProperties) => void

This property is raised when the user clicks the Save button and there is a selected image. Two arguments are passed, the file:File which is a blob, and the crop settings which is an object containing x:number,y:number, and size:number values, which are all relative to the coordinates of the selected image.

Note Due to limitations on Safari <= 10.0 and IE11, a Blob object will be returned instead of a File. This still allows access to the image byte data to facilitate uploads, essentially minus the filename and date attributes.

The x and y represent the origin of the crop area. The size value is a single value which represents the width and height of the crop area. To get the crop area from the selected image, simply take the clipped rect of (x, y, size, size) from the given image.

onImagePickedDataURI?: (dataURI: string) => void

This property is raised when the user clicks the Save button and there is a selected image. The selected image is provided as a dataURI string.

onAvatarPicked: (avatar: Avatar) => void

This property is raised when the user clicks the Save button and there is a pre-defined avatar selected, and no image selected. An Avatar object with a dataURI property is passed.

onCancel: Function

This property is raised when the user clicks Cancel button.

Note this does not close the dialog. It is up to the consumer to re-render and remove the dialog from the UI.

imageSource?: string

(optional) This property is used to set the selected image so that the component opens up with it visible already.

The value should be a valid dataURI string. If an invalid dataURI is given, the bad format error state will be triggered and a message shown.

avatars: Array<Avatar>

This property is used to provide an array of pre-defined avatars. The Avatar object is a simple type with a single dataURI: string property. For convenience, this type is exported from the @atlassian/media-avatar-picker module along with the AvatarPickerDialog component.

defaultSelectedAvatar?: Avatar

(optional) This property is used along with the avatar property. It allows you to set the currently selected pre-defined avatar. By default, there is no pre-defined avatar selected, even if the avatars property is set.

title?: string

(optional) The title text for the dialog. The default is Upload an avatar.

primaryButtonText?: string

(optional) The primary button text. The default is Save.

errorMessage?: string

(optional) This property allows the consumer to display an error message. This may occur from a call to a service. The string is clipped if greater than 125 charaters (approximately 3 lines within the dialog).

Usage Example

Below is an example of rendering an `AvatarPickerDialog`. The dialog should be wrapped in a `ModalTransition` component so it fades out when closed.

import { AvatarPickerDialog, Avatar } from '@atlaskit/media-avatar-picker';
import { ModalTransition } from '@atlaskit/modal-dialog';

const avatars: Array<Avatar> = [{ dataURI: 'some-data-uri' }];

const App = ({ isOpen }) => (
  <ModalTransition>
    {isOpen && (
      <AvatarPickerDialog
        avatars={avatars}
        onImagePicked={(selectedImage, crop) => {
          console.log(selectedImage.size, crop.x, crop.y, crop.size);
        }}
        onAvatarPicked={selectedAvatar =>
          console.log(selectedAvatar.dataURI)
        }
        onCancel={() => /* we need to close the dialog... */}
      />
    )}
  </ModalTransition>
);