Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@_nu/react-avatar

nu-system57MIT0.5.1TypeScript support: included

react avatar

react-component, ui, no-ui, nu-system, react, react-ui, avatar

readme

@_nu/react-avatar

npm package npm downloads jsdelivr github
npm package npm downloads jsdelivr github

安装

$ npm install @_nu/react-avatar

二次封装

/* @/components/Avatar/index.js */
import React from 'react';
import { Container, Img, Skeleton } from '@_nu/react-avatar';
import 'sacss';
import './index.css';

const Avatar = ({
  className = '',
  src,
  size,
  placeholder,
  children = null,
}) => {
  return (
    <Container size={size} className={className}>
      <Skeleton />
      <Img src={src} size={size} placeholder={placeholder} />
      {children}
    </Container>
  );
};

export default Avatar;

使用

import React from 'react';
import Avatar from "./components/Avatar";
import imgAvatar from '../avatar.jpg';

const AvatarDefault = ({ className = null }) => (
  <svg
    viewBox="0 0 1024 1024"
    xmlns="http://www.w3.org/2000/svg"
    className={className}
  >
    <path d="M512 64a448 448 0 1 0 448 448A448 448 0 0 0 512 64zm0 160a144 144 0 1 1-144 144 143.68 143.68 0 0 1 144-144zm256 573.44a381.76 381.76 0 0 1-512 0v-18.56A166.4 166.4 0 0 1 416 608h192a166.72 166.72 0 0 1 160 169.92v19.52z" />
  </svg>
);

const Page=()=>{
    return (
     <div>
      <Avatar alt="hello" size={24} src={imgAvatar} />
      <Avatar alt="hello" size={32} src={imgAvatar} />
      <Avatar alt="hello" size={40} src={imgAvatar} />
      <Avatar alt="hello" size={40} src="123" placeholder={AvatarDefault} />
      <Avatar alt="hello" src={imgAvatar} />
      <Avatar alt="hello" placeholder={AvatarDefault} />
    </div>
    );
};

export default Page;

接口

属性 类型 默认值 作用
Component node i 容器组件
children node - 子元素
className string - class
src string - 图片地址
alt string.isRequired - 图片描述
size string | number '40' Avatar 尺寸
placeholder node | string - 图片加载失败
  • size:size={null} 表示头像会撑满整个容器
  • placeholder: string 表示图片加载失败用这个作为占位图,

更多

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.5.1 (2021-05-31)

Bug Fixes

0.5.0 (2021-03-01)

Features

  • react-avatar: 升级 sacss (847aae4)

0.4.4 (2021-02-09)

Note: Version bump only for package @_nu/react-avatar

0.4.3 (2020-12-16)

Bug Fixes

  • 修改 超出隐藏逻辑 (8e48cdd)

0.4.2 (2020-12-16)

Bug Fixes

0.4.1 (2020-12-16)

Bug Fixes

0.4.0 (2020-12-16)

Features

  • avatar 修改为 atom 形势 (da6bbed)

0.3.3 (2020-08-18)

Bug Fixes

0.3.2 (2020-08-18)

Bug Fixes

  • 将 css 注入到 react 中 (a3e4d6a)

0.3.1 (2020-07-03)

Bug Fixes

  • avatar placeholder 添加 aria-hidden (31dfb04)

0.3.0 (2020-07-03)

Bug Fixes

Features