From fc4d96abf33d95c2585a6d6620388b7ffcf0dff0 Mon Sep 17 00:00:00 2001 From: Sujal Goel Date: Mon, 6 Apr 2026 21:24:24 +0530 Subject: [PATCH] refactor(Configuration): rewrite class component to functional --- src/components/Configuration/components.jsx | 120 +++++++++----------- 1 file changed, 51 insertions(+), 69 deletions(-) diff --git a/src/components/Configuration/components.jsx b/src/components/Configuration/components.jsx index e395168b3b1a..db2abb0fb188 100644 --- a/src/components/Configuration/components.jsx +++ b/src/components/Configuration/components.jsx @@ -1,5 +1,5 @@ import PropTypes from "prop-types"; -import { Component, isValidElement } from "react"; +import { isValidElement, useState } from "react"; import Popover from "react-tiny-popover"; const DEFAULT_CHILDREN_SIZE = 4; @@ -20,8 +20,8 @@ const addLink = (child, i, url) => const Card = ({ body }) => ( // Applied .shadow > .markdown styles: max-height and overflow
- {/* Combined .inline and .shadow pre.inline styles: - display: block, margin: 0, padding: 0 with right-padding override + {/* Combined .inline and .shadow pre.inline styles: + display: block, margin: 0, padding: 0 with right-padding override */}
       {body}
@@ -33,71 +33,53 @@ Card.propTypes = {
   body: PropTypes.node,
 };
 
-export class Details extends Component {
-  static propTypes = {
-    url: PropTypes.string,
-    myChilds: PropTypes.arrayOf(PropTypes.node),
-  };
-
-  constructor(props) {
-    super(props);
-    this.state = {
-      open: false,
-    };
-  }
-
-  clickOutsideHandler = () => {
-    this.setState({ open: false });
-  };
-
-  toggleVisibility = () => {
-    this.setState({ open: !this.state.open });
-  };
-
-  render() {
-    const { myChilds, url } = this.props;
-
-    // Find the index of 
-    const closeDefaultTagIndex = myChilds.findIndex((child) => {
-      if (isValidElement(child)) {
-        return (
-          child.props.className.includes("tag") &&
-          child.props.children.length === DEFAULT_CHILDREN_SIZE
-        );
-      }
-
-      return false;
-    });
-
-    const content = [...myChilds];
-
-    // Summary is the part of the snippet that would be shown in the code snippet,
-    // to get it we need to cut the  enclosing tags
-    const summary = content
-      .splice(2, closeDefaultTagIndex - 3)
-      .map(removeSpaces)
-      .map((child, i) => addLink(child, i, url));
-
-    content.splice(0, DEFAULT_CHILDREN_SIZE); // Remove  information
-
-    const { open } = this.state;
-    return (
-      }
+export function Details({ url, myChilds }) {
+  const [open, setOpen] = useState(false);
+
+  // Find the index of 
+  const closeDefaultTagIndex = myChilds.findIndex((child) => {
+    if (isValidElement(child)) {
+      return (
+        child.props.className.includes("tag") &&
+        child.props.children.length === DEFAULT_CHILDREN_SIZE
+      );
+    }
+
+    return false;
+  });
+
+  const content = [...myChilds];
+
+  // Summary is the part of the snippet that would be shown in the code snippet,
+  // to get it we need to cut the  enclosing tags
+  const summary = content
+    .splice(2, closeDefaultTagIndex - 3)
+    .map(removeSpaces)
+    .map((child, i) => addLink(child, i, url));
+
+  content.splice(0, DEFAULT_CHILDREN_SIZE); // Remove  information
+
+  return (
+     setOpen(false)}
+      // Replaced .shadow with Tailwind equivalents, including the custom rgba box-shadow
+      containerClassName="overflow-visible rounded shadow-[-1px_1px_10px_0_rgba(255,255,255,0.44)]"
+      content={}
+    >
+       setOpen((prev) => !prev)}
       >
-        
-          {summary}
-        
-      
-    );
-  }
+        {summary}
+      
+    
+  );
 }
+
+Details.propTypes = {
+  url: PropTypes.string,
+  myChilds: PropTypes.arrayOf(PropTypes.node),
+};