1.17.0 • Published 2 years ago

@s-ui/react-molecule-avatar v1.17.0

Weekly downloads
222
License
MIT
Repository
-
Last release
2 years ago

MoleculeAvatar 👤

The Avatar component is the representation of a user.

Installation

$ npm install @s-ui/react-molecule-avatar

Usage

Basic usage

Import package and use the component

import MoleculeAvatar from '@s-ui/react-molecule-avatar'

return <MoleculeAvatar />

Import the styles (Sass)

@import '~@s-ui/theme/lib/index';
// @import 'your theme';
@import '~@s-ui/react-molecule-avatar/lib/index';

Fallbacks

Icon

If no name or src is set, a default icon will be displayed by default, it can be customized using fallbackIcon prop

import MoleculeAvatar from '@s-ui/react-molecule-avatar'

const FallbackIconStory = () => (
  <>
    <MoleculeAvatar />
    <MoleculeAvatar fallbackIcon={<Icon />} />
  </>
)

Name

If name is set but src is not the initials of the name will be used to generate a accessible background color

import MoleculeAvatar from '@s-ui/react-molecule-avatar'

const FallbackNameStory = () => (
  <>
    <MoleculeAvatar name="Jon Snow" />
  </>
)

Size

Modify the size of the avatar with size prop. Choose between xsmall, small, medium, large, xlarge and xxlarge

import MoleculeAvatar, {AVATAR_SIZES} from '@s-ui/react-molecule-avatar'

const SizeStory = () => (
  <>
    <MoleculeAvatar size={USER_AVATAR_SIZES.XSMALL} />
    <MoleculeAvatar size={USER_AVATAR_SIZES.SMALL} />
    <MoleculeAvatar size={USER_AVATAR_SIZES.MEDIUM} />
    <MoleculeAvatar size={USER_AVATAR_SIZES.LARGE} />
    <MoleculeAvatar size={USER_AVATAR_SIZES.XLARGE} />
    <MoleculeAvatar size={USER_AVATAR_SIZES.XXLARGE} />
  </>
)

Image

If src is set an image will be displayed, if it fails one of the fallbacks will be used instead.

import MoleculeAvatar from '@s-ui/react-molecule-avatar'

const ImageStory = () => (
  <>
    <MoleculeAvatar name="Jon Snow" src="https://www.images/jon_snow.png" />
  </>
)

Badge

Use MoleculeAvatar.Badge component to display a status badge.

import MoleculeAvatar from '@s-ui/react-molecule-avatar'

const BadgeStory = () => (
  <>
    <MoleculeAvatar name="Jon Snow">
      <MoleculeAvatar.Badge />
    </MoleculeAvatar>
  </>
)

Find full description and more examples in the demo page.

1.15.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago