11import styled from "styled-components" ;
22import { ReactNode , useContext , useMemo , useRef , useState } from "react" ;
33import { Layers } from "../../constants/Layers" ;
4- import { CodeEditorOpenIcon } from "lowcoder-design" ;
4+ import { CodeEditorOpenIcon , CodeEditorPinnedIcon , CodeEditorUnPinnedIcon } from "lowcoder-design" ;
55import { CodeEditorCloseIcon } from "lowcoder-design" ;
66import { DragIcon } from "lowcoder-design" ;
77import Trigger from "rc-trigger" ;
@@ -74,6 +74,11 @@ const OpenButton = styled.div`
7474 }
7575 }
7676` ;
77+ const Buttons = styled . div `
78+ display: flex;
79+ justify-content: space-between;
80+ align-items: center;
81+ `
7782const CloseButton = styled . div `
7883 display: flex;
7984 justify-content: space-between;
@@ -98,6 +103,30 @@ const CloseButton = styled.div`
98103 }
99104 }
100105` ;
106+ const PinButton = styled . div `
107+ width: 32px;
108+ height: 26px;
109+ border: 1px solid #d7d9e0;
110+ border-radius: 4px;
111+ color: #333333;
112+ padding: 2px ;
113+ cursor: pointer;
114+
115+ &:hover {
116+ background: #f5f5f6;
117+
118+ svg g g {
119+ stroke: #222222;
120+ }
121+ }
122+
123+ // fixes the icon when there's no text in the container
124+ svg {
125+ width: 100%;
126+ height: 100%;
127+ fill: currentColor;
128+ }
129+ ` ;
101130
102131export const CodeEditorPanel = ( props : {
103132 editor : ReactNode ;
@@ -106,6 +135,8 @@ export const CodeEditorPanel = (props: {
106135} ) => {
107136 const draggableRef = useRef < HTMLDivElement > ( null ) ;
108137 const [ unDraggable , setUnDraggable ] = useState ( true ) ;
138+ const [ pinned , setPinned ] = useState ( false ) ;
139+
109140 const [ bounds , setBounds ] = useState ( {
110141 left : 0 ,
111142 top : 0 ,
@@ -126,7 +157,8 @@ export const CodeEditorPanel = (props: {
126157 action = { [ "click" ] }
127158 zIndex = { Layers . codeEditorPanel }
128159 popupStyle = { { opacity : 1 , display : visible ? "block" : "none" } }
129- maskClosable = { true }
160+ maskClosable = { ! pinned }
161+ mask = { true }
130162 onPopupVisibleChange = { ( visible ) => setVisible ( visible ) }
131163 afterPopupVisibleChange = { ( visible ) => props . onVisibleChange ( visible ) }
132164 getPopupContainer = { ( node : any ) => node . parentNode . parentNode }
@@ -169,10 +201,15 @@ export const CodeEditorPanel = (props: {
169201 < StyledDragIcon />
170202 { [ compName , ...( props . breadcrumb ?? [ ] ) ] . filter ( ( t ) => ! isEmpty ( t ) ) . join ( " / " ) }
171203 </ TitleWrapper >
172- < CloseButton onClick = { ( ) => setVisible ( false ) } >
173- < CodeEditorCloseIcon />
174- { trans ( "codeEditor.fold" ) }
175- </ CloseButton >
204+ < Buttons >
205+ < PinButton onClick = { ( ) => setPinned ( ! pinned ) } >
206+ { pinned ? < CodeEditorPinnedIcon /> : < CodeEditorUnPinnedIcon /> }
207+ </ PinButton >
208+ < CloseButton onClick = { ( ) => setVisible ( false ) } >
209+ < CodeEditorCloseIcon />
210+ { trans ( "codeEditor.fold" ) }
211+ </ CloseButton >
212+ </ Buttons >
176213 </ HeaderWrapper >
177214
178215 < BodyWrapper > { props . editor } </ BodyWrapper >
0 commit comments