Skip to content

Commit e73113f

Browse files
authored
feat(component): replaced -> component (#15084)
1 parent 37b9f24 commit e73113f

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

packages/react/src/components/UIShell/SideNavItems.js renamed to packages/react/src/components/UIShell/SideNavItems.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@ import React from 'react';
1111
import { CARBON_SIDENAV_ITEMS } from './_utils';
1212
import { usePrefix } from '../../internal/usePrefix';
1313

14-
const SideNavItems = ({
14+
interface SideNavItemsProps {
15+
/**
16+
* Provide a single icon as the child to `SideNavIcon` to render in the
17+
* container
18+
*/
19+
children: React.ReactNode;
20+
21+
/**
22+
* Provide an optional class to be applied to the containing node
23+
*/
24+
className?: string;
25+
26+
/**
27+
* Property to indicate if the side nav container is open (or not). Use to
28+
* keep local state and styling in step with the SideNav expansion state.
29+
*/
30+
isSideNavExpanded?: boolean;
31+
}
32+
33+
const SideNavItems: React.FC<SideNavItemsProps> = ({
1534
className: customClassName,
1635
children,
1736
isSideNavExpanded,
@@ -21,13 +40,16 @@ const SideNavItems = ({
2140
const childrenWithExpandedState = React.Children.map(children, (child) => {
2241
if (React.isValidElement(child)) {
2342
// avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
24-
return React.cloneElement(child, {
25-
...(CARBON_SIDENAV_ITEMS.includes(child.type?.displayName)
26-
? {
27-
isSideNavExpanded,
28-
}
29-
: {}),
30-
});
43+
const childType = child.type as React.ComponentType;
44+
if (childType && childType.displayName) {
45+
return React.cloneElement(child, {
46+
...(CARBON_SIDENAV_ITEMS.includes(childType.displayName)
47+
? {
48+
isSideNavExpanded,
49+
}
50+
: {}),
51+
});
52+
}
3153
}
3254
});
3355
return <ul className={className}>{childrenWithExpandedState}</ul>;

0 commit comments

Comments
 (0)