Skip to content

Instantly share code, notes, and snippets.

@keyurparalkar
Created March 4, 2024 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyurparalkar/3c33b27c6ad2f0403226201145e3001c to your computer and use it in GitHub Desktop.
Save keyurparalkar/3c33b27c6ad2f0403226201145e3001c to your computer and use it in GitHub Desktop.
Customized details component
const CustomDetails = (props: CustomDetailsProps) => {
const { icons, name, renderTree } = props;
const [isOpen, setIsOpen] = useState(false);
const hasIcons = icons && icons.length > 0;
const handleDrawerOpen = (
e: React.SyntheticEvent<HTMLDetailsElement, ToggleEvent>,
) => {
// This stops event bubbling;
e.stopPropagation();
setIsOpen(e.nativeEvent.newState === "open" ? true : false);
};
return (
<StyledDetails onToggle={handleDrawerOpen} hasIcons={hasIcons}>
<summary className={hasIcons ? "custom-icons" : undefined}>
{hasIcons && (isOpen ? icons[1] : icons[0])}
<span>{name}</span>
</summary>
{renderTree}
</StyledDetails>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment