react基于antd二次封装spin组件

目录

react基于antd二次封装spin组件

组件

js 复制代码
import { Spin } from 'antd';
import propTypes from "prop-types";
import React from 'react';
import styleId from "styled-components";
// 使用 父div必须加 position:'relative'
const SpinCom = (props) => {
  // console.log('props',props);
    return (
        <SpinComWrap>
          <Spin className='spin' tip={props.tip} spinning={props.spinning} />
        </SpinComWrap>
    )
}
// props
SpinCom.propTypes = {
  tip: propTypes.string,
  spinning: propTypes.bool.isRequired,
  size: propTypes.string,
};
SpinCom.defaultProps = {
  tip: 'Loading...', // 默认值
  spinning: false,
  size: 'default'
};
const SpinComWrap = styleId.div`
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  .spin {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
  }
`
export default SpinCom

使用组件

js 复制代码
import { Button } from 'antd';
import React, { useState } from 'react';
import SpinCom from "./SpinCom";
export default function App(props) {
  const [show,setshow] = useState(false)
  const showspain = () => {
    setshow(!show)
  }
    return (
        <div className='content' style={{width:'200px',height: '200px',background: '#ccc',position:'relative'}}>
          <SpinCom spinning={show}></SpinCom>
          app -{show ? 1: 0}
          <Button type="primary" onClick={showspain}>Button</Button>
        </div>
    )
}

效果

相关推荐
大福ya3 天前
AI开源项目改造NextChat(ChatGPT-Next-Web)实现前端SSR改造打造一个初始框架
前端·chatgpt·前端框架·开源·aigc·reactjs·ai编程
宝桥南山21 天前
Microsoft Fabric - 试一下在前端应用中使用 GraphQL API去连接Lakehouse
microsoft·reactjs·azure·fabric·graphql·db
WYiQIU24 天前
高级Web前端开发工程师2025年面试题总结及参考答案【含刷题资源库】
前端·vue.js·面试·职场和发展·前端框架·reactjs·飞书
明仔的阳光午后1 个月前
React 入门 01:快速写一个React的HelloWorld项目
前端·javascript·react.js·前端框架·reactjs·react
逻极1 个月前
Next.js vs Vue.js:2025年全栈战场,谁主沉浮?
开发语言·javascript·vue.js·reactjs
小白64022 个月前
前端梳理体系从常问问题去完善-框架篇(react生态)
前端·css·html·reactjs
解道Jdon2 个月前
IntelliJ IDEA全流程智能支持Java 25新特性
javascript·reactjs
解道Jdon2 个月前
SpringBoot4与Spring7发布:云原生深度进化
javascript·reactjs
GISer_Jing3 个月前
滴滴二面(准备二)
前端·javascript·vue·reactjs
三思而后行,慎承诺3 个月前
requestIdleCallback 和 MessageChannel
javascript·reactjs