Skip to content

Commit

Permalink
feat(component): replaced -> component (carbon-design-system#15084)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirajsah authored and danoro96 committed Jan 18, 2024
1 parent df2b17b commit 6149490
Showing 1 changed file with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ import React from 'react';
import { CARBON_SIDENAV_ITEMS } from './_utils';
import { usePrefix } from '../../internal/usePrefix';

const SideNavItems = ({
interface SideNavItemsProps {
/**
* Provide a single icon as the child to `SideNavIcon` to render in the
* container
*/
children: React.ReactNode;

/**
* Provide an optional class to be applied to the containing node
*/
className?: string;

/**
* Property to indicate if the side nav container is open (or not). Use to
* keep local state and styling in step with the SideNav expansion state.
*/
isSideNavExpanded?: boolean;
}

const SideNavItems: React.FC<SideNavItemsProps> = ({
className: customClassName,
children,
isSideNavExpanded,
Expand All @@ -21,13 +40,16 @@ const SideNavItems = ({
const childrenWithExpandedState = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
// avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
return React.cloneElement(child, {
...(CARBON_SIDENAV_ITEMS.includes(child.type?.displayName)
? {
isSideNavExpanded,
}
: {}),
});
const childType = child.type as React.ComponentType;
if (childType && childType.displayName) {
return React.cloneElement(child, {
...(CARBON_SIDENAV_ITEMS.includes(childType.displayName)
? {
isSideNavExpanded,
}
: {}),
});
}
}
});
return <ul className={className}>{childrenWithExpandedState}</ul>;
Expand Down

0 comments on commit 6149490

Please sign in to comment.