Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logo click callback #380

Merged
merged 1 commit into from
Jan 4, 2024
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
8 changes: 7 additions & 1 deletion src/components/SideMenu/SideMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ let items = [
];

export const _SideMenu = {
render: () => <SideMenu conf={conf} items={items} />,
render: () => (
<SideMenu
conf={conf}
items={items}
onClickLogo={() => alert('logo clicked')}
/>
),
};
25 changes: 17 additions & 8 deletions src/components/SideMenu/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ISideMenuConfProps extends ComponentPropsWithoutRef<'div'> {
interface ISideMenuProps extends ComponentPropsWithoutRef<'div'> {
items?: ISideMenuItemProps[];
conf: ISideMenuConfProps;
onClickLogo?: () => void;
}

interface IShortItemProps extends ComponentPropsWithoutRef<'div'> {
Expand Down Expand Up @@ -76,12 +77,17 @@ export function LongItem(props: ILongItemProps) {
}

function ShortMenu(props: ISideMenuProps) {
const { items, conf } = props;
const { items, conf, onClickLogo } = props;
const { logo } = conf;

return (
<div className="flex flex-col items-center w-20 h-full overflow-hidden bg-secondary">
<div className="flex items-center justify-center mt-3">{logo}</div>
<div
className="flex items-center justify-center mt-3 hover:cursor-pointer"
onClick={onClickLogo}
>
{logo}
</div>
<div className="flex flex-col items-center mt-3">
{items
?.filter((item) => !item.footer)
Expand All @@ -101,12 +107,15 @@ function ShortMenu(props: ISideMenuProps) {
}

function LongMenu(props: ISideMenuProps) {
const { items, conf } = props;
const { items, conf, onClickLogo } = props;
const { logo, title } = conf;

return (
<div className="flex flex-col items-center w-64 h-full overflow-hidden bg-secondary">
<div className="flex w-full items-center px-5 mt-3">
<div
className="flex w-full items-center px-5 mt-3 hover:cursor-pointer"
onClick={onClickLogo}
>
{logo}
<span className="w-full ml-3 text-center text-f-primary mas-menu-active">
{title}
Expand All @@ -133,15 +142,15 @@ function LongMenu(props: ISideMenuProps) {
}

export function SideMenu(props: ISideMenuProps) {
const { items, conf } = props;
const { items, conf, onClickLogo } = props;
const { fullMode } = conf;

const [hover, setHover] = useState(true);

const fullModeClass = fullMode ? 'fixed top-0 left-0 right-0' : '';
const hoverClass = hover ? 'w-20' : 'w-64';

function handleOnMouseOver(e: any) {
function handleOnMouseOver(e: React.MouseEvent) {
e.preventDefault();
setHover(!hover);
}
Expand All @@ -154,9 +163,9 @@ export function SideMenu(props: ISideMenuProps) {
onMouseLeave={hover ? undefined : handleOnMouseOver}
>
{hover ? (
<ShortMenu items={items} conf={conf} />
<ShortMenu items={items} conf={conf} onClickLogo={onClickLogo} />
) : (
<LongMenu items={items} conf={conf} />
<LongMenu items={items} conf={conf} onClickLogo={onClickLogo} />
)}
</div>
);
Expand Down
Loading