Skip to content

Allow pinning the code editor popup #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/packages/lowcoder-design/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export { ReactComponent as ClickLinkIcon } from "./icon-clickLink.svg";
export { ReactComponent as CloseEyeIcon } from "./icon-closeEye.svg";
export { ReactComponent as CodeEditorCloseIcon } from "./icon-code-editor-close.svg";
export { ReactComponent as CodeEditorOpenIcon } from "./icon-code-editor-open.svg";
export { ReactComponent as CodeEditorPinnedIcon} from "./remix/pushpin-2-fill.svg"
export { ReactComponent as CodeEditorUnPinnedIcon} from "./remix/pushpin-line.svg"
export { ReactComponent as ColorHexIcon } from "./icon-colorHex.svg";
export { ReactComponent as ContainerDragIcon } from "./icon-container-drag.svg";
export { ReactComponent as CopyIcon } from "./icon-copy.svg";
Expand Down
49 changes: 43 additions & 6 deletions client/packages/lowcoder/src/pages/editor/codeEditorPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import { ReactNode, useContext, useMemo, useRef, useState } from "react";
import { Layers } from "../../constants/Layers";
import { CodeEditorOpenIcon } from "lowcoder-design";
import { CodeEditorOpenIcon, CodeEditorPinnedIcon, CodeEditorUnPinnedIcon } from "lowcoder-design";
import { CodeEditorCloseIcon } from "lowcoder-design";
import { DragIcon } from "lowcoder-design";
import Trigger from "rc-trigger";
Expand Down Expand Up @@ -74,6 +74,11 @@ const OpenButton = styled.div`
}
}
`;
const Buttons = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
`
const CloseButton = styled.div`
display: flex;
justify-content: space-between;
Expand All @@ -98,6 +103,30 @@ const CloseButton = styled.div`
}
}
`;
const PinButton = styled.div`
width: 32px;
height: 26px;
border: 1px solid #d7d9e0;
border-radius: 4px;
color: #333333;
padding: 2px ;
cursor: pointer;
&:hover {
background: #f5f5f6;
svg g g {
stroke: #222222;
}
}
// fixes the icon when there's no text in the container
svg {
width: 100%;
height: 100%;
fill: currentColor;
}
`;

export const CodeEditorPanel = (props: {
editor: ReactNode;
Expand All @@ -106,6 +135,8 @@ export const CodeEditorPanel = (props: {
}) => {
const draggableRef = useRef<HTMLDivElement>(null);
const [unDraggable, setUnDraggable] = useState(true);
const [pinned, setPinned] = useState(false);

const [bounds, setBounds] = useState({
left: 0,
top: 0,
Expand All @@ -126,7 +157,8 @@ export const CodeEditorPanel = (props: {
action={["click"]}
zIndex={Layers.codeEditorPanel}
popupStyle={{ opacity: 1, display: visible ? "block" : "none" }}
maskClosable={true}
maskClosable={!pinned}
mask={true}
onPopupVisibleChange={(visible) => setVisible(visible)}
afterPopupVisibleChange={(visible) => props.onVisibleChange(visible)}
getPopupContainer={(node: any) => node.parentNode.parentNode}
Expand Down Expand Up @@ -169,10 +201,15 @@ export const CodeEditorPanel = (props: {
<StyledDragIcon />
{[compName, ...(props.breadcrumb ?? [])].filter((t) => !isEmpty(t)).join(" / ")}
</TitleWrapper>
<CloseButton onClick={() => setVisible(false)}>
<CodeEditorCloseIcon />
{trans("codeEditor.fold")}
</CloseButton>
<Buttons>
<PinButton onClick={() => setPinned(!pinned) }>
{pinned ? <CodeEditorPinnedIcon/> : <CodeEditorUnPinnedIcon/>}
</PinButton>
<CloseButton onClick={() => setVisible(false)}>
<CodeEditorCloseIcon />
{trans("codeEditor.fold")}
</CloseButton>
</Buttons>
</HeaderWrapper>

<BodyWrapper>{props.editor}</BodyWrapper>
Expand Down