当前位置: 首页 > article >正文

挑战用React封装100个组件【003】

项目地址
https://github.com/hismeyy/react-component-100

组件描述
组件适用于展示个人信息

样式展示

在这里插入图片描述

前置依赖

今天我们的这个挑战需要用用到了 react-icons 依赖,因此,我们需要先安装它。

# 使用 npm
npm install react-icons

# 或者使用 yarn
yarn add react-icons

使用的话,大家可以看这个网站。大家进去可以找需要的图标。具体使用里面有介绍,非常简单。
react-icons 图标
好了,下面我们展示代码。

代码展示

InfoCard.tsx
import './InfoCard.css'
import { BsFillCheckCircleFill } from "react-icons/bs";
import { BsPersonHearts } from "react-icons/bs";
import { BsTrophyFill } from "react-icons/bs";
import { FaStar } from 'react-icons/fa';

interface InfoCardProps {
    title?: string;
    avatarUrl?: string;
    name?: string;
    job?: string;
    progress?: number;
    likes?: number;
    checks?: number;
    trophies?: number;
}

const defaultProps: InfoCardProps = {
    title: "个人中心",
    avatarUrl: "https://images.unsplash.com/photo-1633332755192-727a05c4013d?w=500&h=500&q=80",
    name: "MaxCosmos",
    job: "React 开发工程师",
    progress: 85,
    likes: 128,
    checks: 46,
    trophies: 15
}

const InfoCard = (props: InfoCardProps) => {
    const {
        title,
        avatarUrl,
        name,
        job,
        progress = defaultProps.progress,
        likes,
        checks,
        trophies
    } = { ...defaultProps, ...props };

    const circumference = 2 * Math.PI * 60;
    const strokeDashoffset = circumference - ((progress || 0) / 100) * circumference;

    return (
        <div className='info-card'>
            <div className='info-title'>
                <h6>{title}</h6>
            </div>
            <div className='info-avatar'>
                <div className='tip-logo'>
                    <FaStar />
                </div>

                <svg className='avatar-bg' width="130" height="130" viewBox="0 0 130 130" xmlns="http://www.w3.org/2000/svg">
                    <circle cx="65" cy="65" r="60" stroke="#E0E1E6" stroke-width="5" fill="none" />
                    <circle cx="65" cy="65" r="60" stroke="#FA7D73" stroke-width="5" fill="none"
                        stroke-dasharray={circumference} stroke-dashoffset={strokeDashoffset} stroke-linecap="round" />
                </svg>

                <div className='avatar'>
                    <img src={avatarUrl} alt={name} />
                </div>
            </div>
            <div className="info">
                <p className='info-name'>{name}</p>
                <p className='info-job'>{job}</p>
            </div>

            <div className='info-other'>
                <div><BsPersonHearts style={{ color: '#FF451C' }} />&nbsp;&nbsp;{likes}</div>
                <div><BsFillCheckCircleFill style={{ color: '#FF451C' }} />&nbsp;&nbsp;{checks}</div>
                <div><BsTrophyFill style={{ color: '#FF451C' }} />&nbsp;&nbsp;{trophies}</div>
            </div>
        </div>
    )
}

export default InfoCard
InfoCard.css
.info-card {
    box-sizing: border-box;
    width: 320px;
    height: 400px;
    border-radius: 25px;
    background-color: #FFFFFF;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    overflow: hidden;
    font-family: "Microsoft YaHei", SimSun, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

.info-card .info-title {
    width: 100%;
    display: flex;
    justify-content: left;
}

.info-card .info-title h6{
    all: unset;
    font-weight: bold;
    letter-spacing: 2px;
}

.info-card .info-avatar{
    margin-top: 20px;
    background-color: #FFFFFF;
    width: 130px;
    height: 130px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position:relative;
    
}

.info-card .info-avatar .tip-logo{
    position: absolute;
    width: 25px;
    height: 25px;
    bottom: 10px;
    right: 10px;
    border-radius: 50%;
    background-color: black;
    z-index: 5;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #FFFFFF;
    font-size: 14px;
}

.info-card .info-avatar .avatar-bg{
    position: absolute;
    top: 0;
    left: 0;
    transform: rotate(-90deg);
}


.info-card .info-avatar .avatar{
    width: 90px;
    height: 90px;
    border-radius: 100%;
}



.info-card .info-avatar .avatar img{
    all: unset;
    width: 100%;
    height: 100%;
    background-color: #FA7D73;
    border-radius: 100%;
    overflow: hidden;
}

.info-card .info {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center
}

.info-card .info .info-name{
    all: unset;
    font-weight: bold;
    font-size: 20px;
}

.info-card .info .info-job{
    all: unset;
    font-size: 14px;
    color: #B3B3B3;
    margin-top: 10px;
    font-weight: bold;
}

.info-card .info-other{
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-top: 40px;
}

.info-card .info-other div{
    width: 70px;
    height: 35px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 17.5px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    font-weight: bold;
}

使用

App.tsx
import './App.css'
import InfoCard from './components/card/infoCard03/InfoCard'

function App() {
  return (
    <>
      <InfoCard />
    </>
  )
}

export default App

http://www.kler.cn/a/416943.html

相关文章:

  • 分层耦合 - IOC详解
  • 【JVM详解五】JVM性能调优
  • 从零开始:使用Jenkins实现高效自动化部署
  • 原生鸿蒙版小艺APP接入DeepSeek-R1,为HarmonyOS应用开发注入新活力
  • Spring Boot 线程池自定义拒绝策略:解决任务堆积与丢失问题
  • python卷积神经网络人脸识别示例实现详解
  • ElasticSearch7.x入门教程之全文搜索(七)
  • 深入理解 GitHub 高级应用:从分支管理到自动化工作流
  • 【大数据学习 | Spark调优篇】Spark之JVM调优
  • iOS开发之修改已有项目的项目名和类名前缀
  • Shell脚本小练习
  • GitLab: You cannot create a branch with a SHA-1 or SHA-256 branch name
  • java基础概念43:Lambda表达式
  • [Ubuntu] linux之Ubuntu18.04的下载及在虚拟机中详细安装过程(附有下载链接)
  • 计算机基础 原码反码补码问题
  • 大数据新视界 -- 大数据大厂之 Hive 数据质量监控:实时监测异常数据(下)(18/ 30)
  • 暴雨发布首款兆芯KX-7000信创笔记本
  • Android 12系统源码_RRO机制(一)Runtime Resource Overlay机制实践
  • RFID资产管理系统的应用与未来发展
  • 初学git报错处理 | 从IDEA远程拉取、创建分支中“clone failed”“couldn‘t checkout”
  • otter 高可用策略
  • 聚云科技×亚马逊云科技:打通生成式AI落地最后一公里
  • javaScript数据类型存储
  • 基于Java Springboot个人记账之财来财往微信小程序
  • django开发中html继承模板样式
  • Vue程序调试和排错技巧