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

feat(AsideHeader): add ui-kit button in aside-header #315

Open
wants to merge 3 commits into
base: v3
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion src/components/CompositeBar/Item/Item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

$block: '.#{variables.$ns}composite-bar-item';

// rewrite default button styles

.g-list__item-content .g-button.g-button_pin_round-round.g-button {
border-radius: var(--gn-composite-bar-item-action-size);
}

#{$block} {
$class: &;
--gn-composite-bar-item-action-size: 36px;
Expand Down Expand Up @@ -158,7 +164,7 @@ $block: '.#{variables.$ns}composite-bar-item';
box-shadow:
0px 0px 0px 1px rgba(0, 0, 0, 0.03),
0px 5px 6px rgba(0, 0, 0, 0.12);
border-radius: var(--gn-composite-bar-item-action-size);

transition:
transform 0.1s ease-out,
background-color 0.15s linear;
Expand All @@ -184,6 +190,14 @@ $block: '.#{variables.$ns}composite-bar-item';
& #{$class}__title {
margin-right: 16px;
}

&::before {
content: none;
}

&::after {
content: none;
}
}

&__icon-tooltip_item-type_action {
Expand Down
134 changes: 87 additions & 47 deletions src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React from 'react';

import {ActionTooltip, Icon, List, Popup, PopupPlacement, PopupProps} from '@gravity-ui/uikit';
import {
ActionTooltip,
Button,
Icon,
List,
Popup,
PopupPlacement,
PopupProps,
} from '@gravity-ui/uikit';

import {useAsideHeaderContext} from '../../AsideHeader/AsideHeaderContext';
import {ASIDE_HEADER_ICON_SIZE} from '../../constants';
Expand Down Expand Up @@ -158,48 +166,77 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
};

const makeNode = ({icon: iconEl, title: titleEl}: MakeItemParams) => {
const createdNode = (
<React.Fragment>
const handleMouseEnter = () => {
if (!compact) {
onMouseEnter?.();
}
};

const handleMouseLeave = () => {
if (!compact) {
onMouseLeave?.();
}
};

const handleClick = (
event: React.MouseEvent<
HTMLAnchorElement | HTMLButtonElement | HTMLDivElement,
MouseEvent
>,
) => {
const target = event.currentTarget;
if (collapsedItem) {
/**
* If we call onItemClick for collapsedItem then:
* - User get unexpected item in onItemClick callback
* - onClosePanel calls twice for each popuped item, as result it will prevent opening of panelItems
*/
toggleOpen(!open);
} else if (target instanceof HTMLDivElement) {
onItemClick?.(item, false, event as React.MouseEvent<HTMLDivElement, MouseEvent>);
}
};

const renderActionButton = () => (
<Button
onClick={handleClick}
className={b({type, current, compact}, className)}
ref={ref}
data-qa={item.qa}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
{makeIconNode(iconEl)}
{!compact && titleEl}
</Button>
);

const renderDivContainer = () => (
<div
className={b({type, compact}, className)}
ref={ref}
data-qa={item.qa}
onClick={handleClick}
onClickCapture={onItemClickCapture}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className={b('icon-place')} ref={highlightedRef}>
{makeIconNode(iconEl)}
</div>
<div
className={b({type, current, compact}, className)}
ref={ref}
data-qa={item.qa}
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (collapsedItem) {
/**
* If we call onItemClick for collapsedItem then:
* - User get unexpected item in onItemClick callback
* - onClosePanel calls twice for each popuped item, as result it will prevent opening of panelItems
*/
toggleOpen(!open);
} else {
onItemClick?.(item, false, event);
}
}}
onClickCapture={onItemClickCapture}
onMouseEnter={() => {
if (!compact) {
onMouseEnter?.();
}
}}
onMouseLeave={() => {
if (!compact) {
onMouseLeave?.();
}
}}
className={b('title')}
title={typeof item.title === 'string' ? item.title : undefined}
>
<div className={b('icon-place')} ref={highlightedRef}>
{makeIconNode(iconEl)}
</div>

<div
className={b('title')}
title={typeof item.title === 'string' ? item.title : undefined}
>
{titleEl}
</div>
{titleEl}
</div>
{renderPopupContent && Boolean(anchorRef?.current) && (
</div>
);

const createdNode = (
<React.Fragment>
{type === 'action' ? renderActionButton() : renderDivContainer()}
{renderPopupContent && anchorRef?.current && (
<Popup
contentClassName={b('popup', popupContentClassName)}
open={popupVisible}
Expand All @@ -216,18 +253,21 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
</React.Fragment>
);

return item.link ? (
<a href={item.link} className={b('link')}>
{createdNode}
</a>
) : (
createdNode
);
if (item.link) {
return (
<a href={item.link} className={b('link')}>
{createdNode}
</a>
);
}

return createdNode;
};

const iconNode = icon ? (
<Icon qa={iconQa} data={icon} size={iconSize} className={b('icon')} />
) : null;

const titleNode = renderItemTitle(item);
const params = {icon: iconNode, title: titleNode};
let highlightedNode = null;
Expand Down
Loading