React封裝全屏彈框的方法
本文實例為大家分享了React封裝全屏彈框的具體代碼,供大家參考,具體內(nèi)容如下
web開發(fā)過程中,需要用到彈框的地方很多,有時候,產(chǎn)品經(jīng)理的原型是全屏彈框,而常用的組件庫里封裝的一般都不是全屏的。
如下圖所示:這就是一個全屏彈框。

廢話不多說,直接上代碼:
// ?FullScreen.tsx
import React, { memo, useEffect } from 'react';
import { Spin } from '@/components/antd';
import IconUrl from '@/assets/icon/closeIcon.png';
import './index.scss';
/*
?*全屏表格自適配組件
?*@title 標(biāo)題
?*@visible 是否顯示
?*@handleCancel 取消事件
?*@content 組件內(nèi)容
?*@loadding 狀態(tài)
?*/
function FullScreen({ title, visible, handleCancel, content, loadding = false }: any) {
? const collapsed = localStorage.getItem('collapsed');
? const collapse = collapsed ?? '1';
? useEffect(() => {
? ? return () => {
? ? ? localStorage.removeItem('collapsed');
? ? };
? }, []);
? return (
? ? visible && (
? ? ? ? <div id="commonModal" style={+collapse === 1 ? { left: 210,top:93 } : { left: 100,top:93 }}>
? ? ? ? ? {/*<!-- 頂部 -->*/}
? ? ? ? ? <div className="modalTop">
? ? ? ? ? ? <div className="modal_title">
? ? ? ? ? ? ? <div className="topTitle">{title}</div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <img className="topIcon" onClick={handleCancel} src={IconUrl} alt="" />
? ? ? ? ? </div>
? ? ? ? ? <Spin spinning={loadding} tip="Loading..." size="large" delay={500}>
? ? ? ? ? ? <div className="modalMain">{content}</div>
? ? ? ? ? </Spin>
? ? ? ? </div>
? ? )
? );
}
export default memo(FullScreen);這個是相關(guān)的css樣式 – index.scss
// index.scss
#commonModal {
? position: fixed;
? bottom: 0px;
? right: 0px;
? background: white;
? border-radius: 5px;
? // width: 100%;
? // height: 100%;
? // height: 95vh;
? z-index: 10;
? .modalTop {
? ? width: 100%;
? ? height: 46px;
? ? border-radius: 5px 5px 0 0;
? ? display: flex;
? ? background: white;
? ? justify-content: space-between;
? ? align-items: center;
? ? border-bottom: 1px solid #dbe3e5;
? ? box-sizing: border-box;
? ? padding: 0 20px;
? ? .modal_title {
? ? ? display: flex;
? ? ? align-items: center;
? ? ? .topTitle {
? ? ? ? color: #333545;
? ? ? ? font-weight: bold;
? ? ? ? font-size: 18px;
? ? ? }
? ? }
? ? .topIcon {
? ? ? width: 24px;
? ? ? height: 24px;
? ? ? cursor: pointer;
? ? }
? }
? .modalMain {
? ? height: 100%;
? ? padding-bottom: 30px;
? ? // height: calc(100vh - 80px);
? ? // height: calc(90vh - 120px);
? ? ::-webkit-scrollbar {
? ? ? // height: 8px;
? ? ? // width: 10px;
? ? }
? }
}
// .modal_mask {
// ? position: fixed;
// ? width: 100%;
// ? height: 100%;
// ? left: 0;
// ? top: 0;
// ? // background-color: rgba(0, 0, 0, 0.5);
// ? z-index: 10;
// }在相關(guān)頁面中進(jìn)行使用:
import FullScreen from '@/components/FullScreen/FullScreen';
const test = (props) => {
?? ?return (
?? ??? ?<Fragment>
? ? ? ? ? ? <FullScreen loadding={isLoading} title={'新增'} content={content} visible={visible} handleCancel={handleCancel} />
? ? ? ? </Fragment>
?? ?)
}content 一般是表單元素
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React利用props的children實現(xiàn)插槽功能
React中并沒有vue中的?slot?插槽概念?不過?可以通過props.children?實現(xiàn)類似功能,本文為大家整理了實現(xiàn)的具體方,需要的可以參考一下2023-07-07
React tabIndex使非表單元素支持focus和blur事件
這篇文章主要為大家介紹了React使用tabIndex使非表單元素支持focus和blur事件實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
React.js組件實現(xiàn)拖拽排序組件功能過程解析
這篇文章主要介紹了React.js組件實現(xiàn)拖拽排序組件功能過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-04-04
React Native之ListView實現(xiàn)九宮格效果的示例
本篇文章主要介紹了React Native之ListView實現(xiàn)九宮格效果的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
React實現(xiàn)多標(biāo)簽在有限空間內(nèi)展示
在業(yè)務(wù)中,需要在一個卡片組件中展示多個標(biāo)簽,標(biāo)簽組件高度相同,寬度和出現(xiàn)順序不同,要求標(biāo)簽只能在有限的空間內(nèi)展示,所以本文給大家介紹了React實現(xiàn)多標(biāo)簽在有限空間內(nèi)展示,需要的朋友可以參考下2023-12-12

