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

fix(CompositeBar/Item): support itemWrapper icon for highlighted node #148

Merged
merged 4 commits into from
Nov 14, 2023
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
19 changes: 16 additions & 3 deletions src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import React, {FC, useState} from 'react';

import {RadioButton, Radio, Modal, Button, eventBroker, EventBrokerData} from '@gravity-ui/uikit';
import {Gear, Magnifier} from '@gravity-ui/icons';
import {
Button,
EventBrokerData,
Radio,
RadioButton,
Modal,
Icon,
eventBroker,
} from '@gravity-ui/uikit';
import {Bug, Gear, Magnifier} from '@gravity-ui/icons';

import {AsideHeader, FooterItem} from '../..';
import {cn} from '../../utils/cn';
import {menuItemsShowcase, text as placeholderText} from './moc';
import {MenuItem, OpenModalSubscriber} from '../../types';
import {ASIDE_HEADER_ICON_SIZE} from '../../constants';

import logoIcon from '../../../../.storybook/assets/logo.svg';

Expand Down Expand Up @@ -50,7 +59,7 @@
const openModalCount = data?.meta?.layers?.filter(
({type}) => type === 'modal',
).length;
callback(openModalCount !== 0);

Check warning on line 62 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Expected return with your callback function
}
});
};
Expand Down Expand Up @@ -129,7 +138,7 @@
compact={compact}
multipleTooltip={multipleTooltip}
openModalSubscriber={openModalSubscriber}
renderFooter={({compact, asideRef}) => (

Check warning on line 141 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'compact' is already declared in the upper scope
<React.Fragment>
<FooterItem
compact={compact}
Expand Down Expand Up @@ -172,14 +181,18 @@
<FooterItem
item={{
id: 'project-settings',
icon: Gear,
title: 'Settings with panel',
tooltipText: (
<div>
<b>Settings with panel</b>
</div>
),
current: visiblePanel === Panel.ProjectSettings,
itemWrapper: (params, makeItem) =>
makeItem({
...params,
icon: <Icon data={Bug} size={ASIDE_HEADER_ICON_SIZE} />,
}),
onItemClick: () => {
setVisiblePanel(
visiblePanel === Panel.ProjectSettings
Expand Down
10 changes: 9 additions & 1 deletion src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,25 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
const iconNode = icon ? <Icon data={icon} size={iconSize} className={b('icon')} /> : null;
const titleNode = renderItemTitle(item);
const params = {icon: iconNode, title: titleNode};
let highlightedNode = null;
let node;

const opts = {compact: Boolean(compact), collapsed: false, item, ref};

if (typeof item.itemWrapper === 'function') {
node = item.itemWrapper(params, makeNode, opts) as React.ReactElement;
highlightedNode =
bringForward &&
(item.itemWrapper(
params,
({icon: iconEl}) => makeIconNode(iconEl),
opts,
) as React.ReactElement);
} else {
node = makeNode(params);
highlightedNode = bringForward && makeIconNode(iconNode);
}

const highlightedNode = makeIconNode(iconNode);
return (
<>
{bringForward && (
Expand Down
Loading