Skip to content
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
27 changes: 14 additions & 13 deletions src/components/ui/Collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const Collapsible = ({ children, ...props }: CollapsibleProps) => {
// Collapsible Content
const collapsibleContent = props.collapsibleContent;

const DisabledContent = () => {
return <>{children && children}
{collapsibleContent && collapsibleContent}</>
}
Comment on lines +47 to +50
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

Refactor DisabledContent to follow React best practices

The component definition inside the render method can cause performance issues and should be moved outside. Also, the implementation can be simplified.

Apply these changes:

-  const DisabledContent = () => {
-    return <>{children && children}
-         {collapsibleContent && collapsibleContent}</>
-  }
+type DisabledContentProps = {
+  children?: React.ReactNode;
+  collapsibleContent?: React.ReactNode;
+};
+
+const DisabledContent: React.FC<DisabledContentProps> = ({
+  children,
+  collapsibleContent
+}) => (
+  <>
+    {children}
+    {collapsibleContent}
+  </>
+);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const DisabledContent = () => {
return <>{children && children}
{collapsibleContent && collapsibleContent}</>
}
type DisabledContentProps = {
children?: React.ReactNode;
collapsibleContent?: React.ReactNode;
};
const DisabledContent: React.FC<DisabledContentProps> = ({
children,
collapsibleContent
}) => (
<>
{children}
{collapsibleContent}
</>
);

return (
<CollapsibleComponent.Root
open={props.open ?? open}
Expand All @@ -52,25 +56,22 @@ const Collapsible = ({ children, ...props }: CollapsibleProps) => {
>
<CollapsibleComponent.Header title={title}>
{/* Button */}

<CollapsibleComponent.Trigger asChild>
{props.trigger && props.trigger}
</CollapsibleComponent.Trigger>


<CollapsibleComponent.Trigger asChild>
{props.trigger && props.trigger}
</CollapsibleComponent.Trigger>
</CollapsibleComponent.Header>

{/* Conditonal Loop */}
{disabled ? (
// loops through all the items with no toggle
<>{children && children}
{collapsibleContent && collapsibleContent}</>
) : (
{/* Conditional Loop */}
{disabled
? <DisabledContent />
: (
<>
{/* Default Content */}
{children && children}
{/* Collapsable Content */}
{/* Collapsable Content */}
<CollapsibleComponent.Content>
{collapsibleContent && collapsibleContent}
{collapsibleContent && collapsibleContent}
</CollapsibleComponent.Content>
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion styles/themes/components/collapsible.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
padding: 10px;
border: 1px solid var(--rad-ui-color-gray-1000);
border-radius: 5px;
width: "full";
width: 100%;
color: black;
background: var(--rad-ui-color-accent-200);

Expand Down
Loading