Skip to content
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

feat: poc for center align and toolbar shadow #37264

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 31 additions & 2 deletions app/client/src/IDE/Structure/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import React from "react";
import React, { useEffect } from "react";
import { Flex } from "@appsmith/ads";

interface ToolbarProps {
children?: React.ReactNode[] | React.ReactNode;
}

const Toolbar = (props: ToolbarProps) => {
useEffect(function detectScrollbar() {
const ele = document.getElementById("uqi-editor-form-content");
const toolbar = document.getElementById("action-toolbar");

const handleScroll = function () {
if (ele && ele.scrollTop > 0) {
toolbar?.style.setProperty(
"box-shadow",
"0 4px 6px rgba(0, 0, 0, 0.1)",
);
} else {
toolbar?.style.setProperty("box-shadow", "none");
}
};

if (ele) {
ele.addEventListener("scroll", handleScroll);
}

return function cleanup() {
ele?.removeEventListener("scroll", handleScroll);
};
}, []);

Comment on lines +9 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using refs instead of direct DOM queries

The current implementation has several areas for improvement:

  1. Replace getElementById with React refs for better reliability and type safety
  2. Extract the shadow value to a constant
  3. Add null checks for better error handling
+ const toolbarRef = useRef<HTMLDivElement>(null);
+ const contentRef = useRef<HTMLDivElement>(null);
+ const TOOLBAR_SHADOW = "0 4px 6px rgba(0, 0, 0, 0.1)";

  useEffect(function detectScrollbar() {
-   const ele = document.getElementById("uqi-editor-form-content");
-   const toolbar = document.getElementById("action-toolbar");
+   const ele = contentRef.current;
+   const toolbar = toolbarRef.current;

    const handleScroll = function () {
-     if (ele && ele.scrollTop > 0) {
-       toolbar?.style.setProperty(
-         "box-shadow",
-         "0 4px 6px rgba(0, 0, 0, 0.1)",
-       );
+     if (ele?.scrollTop > 0 && toolbar) {
+       toolbar.style.setProperty("box-shadow", TOOLBAR_SHADOW);
      } else {
-       toolbar?.style.setProperty("box-shadow", "none");
+       toolbar?.style.setProperty("box-shadow", "none");
      }
    };

Committable suggestion skipped: line range outside the PR's diff.

return (
<Flex
alignItems="center"
borderBottom="1px solid var(--ads-v2-color-border-muted);"
flexDirection="row"
height="32px"
id="action-toolbar"
justifyContent="space-between"
padding="spaces-2"
style={{
transition: "box-shadow 0.3s ease",
position: "sticky",
top: 0,
}}
>
{props.children}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PluginActionForm = () => {
const { plugin } = usePluginActionContext();

return (
<Flex flex="1" overflow="hidden" p="spaces-4" w="100%">
<Flex flex="1" overflow="hidden" p="spaces-4" pt="spaces-0" w="100%">
{plugin.uiComponent === UIComponentTypes.ApiEditorForm && (
<APIEditorForm />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ const UQIEditorForm = () => {
const { data, evaluationState } = useFormData();

return (
<Flex flexDirection="column" overflowY="scroll" w="100%">
<Flex
alignItems="center"
flexDirection="column"
id="uqi-editor-form-content"
overflowY="scroll"
w="100%"
>
<FormRender
editorConfig={editorConfig}
formData={data}
Expand Down
Loading