Skip to content

Commit

Permalink
drill prop if item should be expanded or not
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Oct 25, 2024
1 parent 38c59d3 commit 0809702
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 19 deletions.
14 changes: 11 additions & 3 deletions packages/libs/kode-ui/src/components/SideBar/SideBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import React from 'react';

import type { ISideBar } from './SideBar';
import { SideBar } from './SideBar';
import { SideBarHeader } from './components/SideBarFooter';
import { SideBarFooter } from './components/SideBarFooter';
import { SideBarHeader } from './components/SideBarHeader';
import { SideBarItem } from './components/SideBarItem';
import { SideBarNavigation } from './components/SideBarNavigation';

const sampleNetworkItems: string[] = ['Mainnet', 'Testnet'];

Expand Down Expand Up @@ -34,10 +36,16 @@ export const Primary: IStory = {
args: {},
render: () => {
return (
<SideBar>
<SideBar isExpanded={true}>
<SideBarHeader>
<SideBarItem label="item 1" />
<SideBarItem label="headeritem 1" />
</SideBarHeader>
<SideBarNavigation>
<SideBarItem label="nav item 1" />
</SideBarNavigation>
<SideBarFooter>
<SideBarItem label="footer item 1" />
</SideBarFooter>
</SideBar>
);
},
Expand Down
15 changes: 12 additions & 3 deletions packages/libs/kode-ui/src/components/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import type { FC, PropsWithChildren } from 'react';
import React from 'react';

export interface ISideBar extends PropsWithChildren {}
export interface ISideBar extends PropsWithChildren {
isExpanded?: boolean;
}

export const SideBar: FC<ISideBar> = ({ children }) => {
return <aside>{children}</aside>;
export const SideBar: FC<ISideBar> = ({ children, isExpanded = false }) => {
return (
<aside>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return null;
return React.cloneElement(child, { ...child.props, isExpanded });
})}
</aside>
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import type { FC, PropsWithChildren } from 'react';
import React from 'react';

export interface ISideBarHeader extends PropsWithChildren {}
export interface ISideBarFooter extends PropsWithChildren {
isExpanded?: boolean;
}

export const SideBarHeader: FC<ISideBarHeader> = ({ children }) => {
export const SideBarFooter: FC<ISideBarFooter> = ({
children,
isExpanded = false,
}) => {
return (
<header>
<ul>{children}</ul>
</header>
<footer>
<ul>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return null;
return React.cloneElement(child, { ...child.props, isExpanded });
})}
</ul>
</footer>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import type { FC, PropsWithChildren } from 'react';
import React from 'react';

export interface ISideBarFooter extends PropsWithChildren {}
export interface ISideBarHeader extends PropsWithChildren {
isExpanded?: boolean;
}

export const SideBarFooter: FC<ISideBarFooter> = ({ children }) => {
return <ul>{children}</ul>;
export const SideBarHeader: FC<ISideBarHeader> = ({
children,
isExpanded = false,
}) => {
return (
<header>
<ul>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return null;
return React.cloneElement(child, { ...child.props, isExpanded });
})}
</ul>
</header>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { Text } from './../../Typography';

export interface ISideBarItem {
label: string;
isExpanded?: boolean;
}

export const SideBarItem: FC<ISideBarItem> = ({ label }) => {
export const SideBarItem: FC<ISideBarItem> = ({
label,
isExpanded = false,
}) => {
return (
<li>
<Text>{label}</Text>
<Text>
{label} {isExpanded.toString()}
</Text>
</li>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import type { FC, PropsWithChildren } from 'react';
import React from 'react';

export interface ISideBarNavigation extends PropsWithChildren {}
export interface ISideBarNavigation extends PropsWithChildren {
isExpanded?: boolean;
}

export const SideBarNavigation: FC<ISideBarNavigation> = ({ children }) => {
return <ul>{children}</ul>;
export const SideBarNavigation: FC<ISideBarNavigation> = ({
children,
isExpanded = false,
}) => {
return (
<nav>
<ul>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return null;
return React.cloneElement(child, { ...child.props, isExpanded });
})}
</ul>
</nav>
);
};

0 comments on commit 0809702

Please sign in to comment.