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>
    )
}

效果

相关推荐
智绘前端2 天前
GitHub 登录功能开发 SOP
人工智能·typescript·github·reactjs
GISer_Jing10 天前
AI驱动营销:业务技术栈实战(From AIGC,待总结)
前端·人工智能·aigc·reactjs
我即将远走丶或许也能高飞10 天前
reduxjs/toolkit 的学习使用
前端·javascript·学习·reactjs
GISer_Jing12 天前
2026前端技术潜在主流前沿方向
前端·人工智能·reactjs
可问春风_ren14 天前
前端文件上传详细解析
前端·ecmascript·reactjs·js
DEMO派18 天前
CSS优先级规则以及如何提升优先级方案详解
前端·javascript·css·vue.js·reactjs·html5·angular.js
我的golang之路果然有问题21 天前
实习中遇到的 CORS 同源策略自己的理解分析
前端·javascript·vue·reactjs·同源策略·cors
Sun_小杰杰哇24 天前
Dayjs常用操作使用
开发语言·前端·javascript·typescript·vue·reactjs·anti-design-vue
web小白成长日记1 个月前
前端三个月速成,是否靠谱?
前端·react.js·前端框架·html·reactjs·webkit·scss
前端不太难2 个月前
RN 与原生通信时出现性能瓶颈(Bridge 卡顿)怎么办?
前端·前端框架·reactjs