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 1 commit
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: 8 additions & 2 deletions src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
const icon = item.icon;
const iconSize = item.iconSize || ASIDE_HEADER_ICON_SIZE;
const collapsedItem = item.id === COLLAPSE_ITEM_ID;
let highlightedNode = null;

const modifiers: Required<PopupProps>['modifiers'] = React.useMemo(
() => [
Expand Down Expand Up @@ -155,6 +156,12 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
};

const makeNode = ({icon: iconEl, title: titleEl}: MakeItemParams) => {
const iconNode = makeIconNode(iconEl);

if (bringForward) {
highlightedNode = iconNode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function makeNode has become a function with a side effect. I suggest leaving the variable highlightedNode definition in its place, but correcting the logic of its initialization (consider ItemWrapper).

}

const createdNode = (
<React.Fragment>
<div
Expand Down Expand Up @@ -185,7 +192,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
}}
>
<div className={b('icon-place')} ref={highlightedRef}>
{makeIconNode(iconEl)}
{iconNode}
</div>

<div
Expand Down Expand Up @@ -234,7 +241,6 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
node = makeNode(params);
}

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