introduce This article is based on The reason is that the developer gave me a Actually, I don’t think it’s very small (orz) full screen You must have seen the The picture above shows the effect of LeetCode in full screen, omitting the menu and other It seems that there
As shown in the picture above, The use of full screen As for full screen, it seems that it is more necessary when you want Install react-full-screen // yarn add react-full-screen npm install react-full-screen --save Install this library using yarn or npm. The official website provides some demos, the link is here. Write a simple component Here is the code directly. There is not much import React, { useState } from "react"; import ReactDOM from "react-dom"; import "antd/dist/antd.css"; import "./index.css"; import { FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons"; import { Tooltip, Card, Col, Row } from "antd"; import { FullScreen, useFullScreenHandle } from "react-full-screen"; const App = () => { // Define the full variable to be compatible with full screen and non-full screen styles. For example, the height of full is 200 and the height of non-full is 100 const [full, setFull] = useState(false); // Create a fullScreen handle const handle = useFullScreenHandle(); return ( <div style={{ background: "#ececec", height: 500 }}> <Row gutter={[8, 8]}> <Col span={8}> <Card style={{ height: 500 }}>Left card</Card> </Col> <Col span={16}> <FullScreen handle={handle} onChange={setFull} style={{ background: "#ffffff" }} > <Card style={{ height: 500 }}> <div> <Tooltip title="Full Screen"> <FullscreenOutlined style={{ fontSize: 16 }} onClick={() => { // Click to set full to true, then call the enter method of handle to enter full screen mode setFull(true); handle.enter(); }} /> </Tooltip> <Tooltip title="Exit full screen"> <FullscreenExitOutlined style={{ fontSize: 16, marginLeft: 16 }} // Exit fullscreen mode and set full to false onClick={() => { setFull(false); handle.exit(); }} /> </Tooltip> </div> <div>Assume this is an editor</div> </Card> </FullScreen> </Col> </Row> </div> ); }; ReactDOM.render(<App />, document.getElementById("container")); This is what it looks like. In this way, we have achieved the effect of only enlarging Problems This is far from enough, there are still some details to be
Defeat them one by oneBackground color The library we use will wrap a global So we can write the following css in the global/component style: .fullscreen.fullscreen-enabled { background: #fff; padding: 24px; } You can see that this style has highWe have previously set the full variable, so we modify the code to determine the height based on full. You can see that Extensions If you think this is the end, you are In the antd component, modal/drawer/message, etc. are all DOM elements generated in the body, so In But Modal Modal can be solved like this. First, we set a Note that this id must be in the FullScreen component. Then we add the following parameters to Modal.info and Modal components: Note: The modal here is not included in my demo, it belongs to the extension part. Writing a modal component is not complicated, you can try it yourself. Modal.info API Modal.info({ title: 'cud request parameters', width: 800, // Note the addition of getContainer: document.getElementById('full_screen') }) messagePass the getContainer method through message.config: I haven’t found a good solution here. It’s quite troublesome to configure message.info every time. If This is the end of this article about React's full-screen component implementation. For more relevant React component full-screen content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: SQL Server Comment Shortcut Key Operation
>>: Detailed explanation of persistent storage of redis under docker
Preface This article introduces how to use the ne...
<br />Previous article: Seven Principles of ...
There is a simple CSS method to realize the pop-u...
Simply pull the image, create a container and run...
Effect: <!doctype html> <html> <he...
Preface The optional chaining operator (?.) allow...
Introduction react-i18next is a powerful internat...
Definition and Usage The display property specifi...
An application of CSS animation, with the same co...
When the database concurrently adds, deletes, and...
Table of contents Preface Installation and Usage ...
Database application is an indispensable part of ...
introduction In recent years, the call for TypeSc...
Today I found that a program inserted an incorrec...
ant-design-vue customizes the use of Ali iconfont...