Skip to content

Commit

Permalink
fix hover styles SH-204
Browse files Browse the repository at this point in the history
  • Loading branch information
v.trushin committed Oct 29, 2024
1 parent 212f0c0 commit 051f052
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 38 deletions.
66 changes: 31 additions & 35 deletions statshouse-ui/src/components/SelectMertic/SelectMetricRow.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
import React, { memo, useCallback } from 'react';
import React, { memo } from 'react';
import { SelectOptionProps, SelectRowEqual, SelectRowProps } from '../UI/Select';
import { Tooltip } from '../UI';
import { toggleMetricsFavorite, useFavoriteStore } from 'store2/favoriteStore';
import cn from 'classnames';
import { ReactComponent as SVGStar } from 'bootstrap-icons/icons/star.svg';
import { ReactComponent as SVGStarFill } from 'bootstrap-icons/icons/star-fill.svg';
import css from '../UI/style.module.css';
import css from './style.module.css';

export const SelectMetricRow = memo(function _SelectMetricRow<T extends SelectOptionProps>({
export const SelectMetricRow = memo(function SelectMetricRow<T extends SelectOptionProps>({
index,
data: { rows, cursor, onChecked, onHover },
style,
}: SelectRowProps<T>) {
const metricsFavorite = useFavoriteStore((s) => s.metricsFavorite);
const hover = useCallback(
(event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
if (index !== cursor) {
onHover(index);
event.stopPropagation();
}
},
[cursor, index, onHover]
);
const click = useCallback(
(event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
onChecked(index, undefined, true, false);
event.stopPropagation();
},
[index, onChecked]
);
const row = rows[index];
const isFavorite = useFavoriteStore((s) => s.metricsFavorite[row?.value]);
const isCursor = cursor === index;

const toggleFavorite = useCallback(
(event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
toggleMetricsFavorite(rows[index]?.value);
const handleHover = (event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
if (!isCursor) {
onHover(index);
event.stopPropagation();
event.preventDefault();
},
[index, rows]
);
}
};

const handleClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
onChecked(index, undefined, true, false);
event.stopPropagation();
};

const handleToggleFavorite = (event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
toggleMetricsFavorite(row?.value);
event.stopPropagation();
event.preventDefault();
};

return (
<div
style={style}
className={cn(css.selectItem, cursor === index && css.selectCursor, rows[index]?.checked && css.selectChecked)}
onClick={click}
onMouseOver={hover}
className={cn(css.selectItem, isCursor && css.selectCursor, row?.checked && css.selectChecked)}
onClick={handleClick}
onMouseOver={handleHover}
>
<div className="d-flex flex-row">
<Tooltip className="flex-grow-1 text-truncate" title={rows[index]?.value ?? `row ${index}`}>
{rows[index]?.value ?? `row ${index}`}
<Tooltip className="flex-grow-1 text-truncate me-2" title={row?.value ?? `row ${index}`}>
{row?.value ?? `row ${index}`}
</Tooltip>
<Tooltip className="me-2" title={metricsFavorite[rows[index]?.value] ? 'remove favorite' : 'add favorite'}>
<span className="text-primary" onClick={toggleFavorite}>
{metricsFavorite[rows[index]?.value] ? <SVGStarFill /> : <SVGStar />}
<Tooltip className="me-2" title={isFavorite ? 'remove favorite' : 'add favorite'}>
<span className="text-primary" onClick={handleToggleFavorite}>
{isFavorite ? <SVGStarFill /> : <SVGStar className={css.hoverVisible} />}
</span>
</Tooltip>
</div>
Expand Down
33 changes: 33 additions & 0 deletions statshouse-ui/src/components/SelectMertic/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.selectItem {
height: var(--selectItemHeight);
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: center;
padding: 4px 8px;
box-sizing: border-box;
}

.selectChecked {
background-color: var(--selectItemChecked);
}

/*.selectItem:hover,*/
.selectCursor {
background-color: var(--selectItemCursor);
}

/*.selectChecked:hover,*/
.selectCursor.selectChecked {
background-color: var(--selectItemCursorChecked);
}
/** Select component end */

.hoverVisible {
visibility: hidden;
}

.selectItem:hover .hoverVisible,
.selectCursor:hover .hoverVisible {
visibility: visible;
}
3 changes: 0 additions & 3 deletions statshouse-ui/src/components/UI/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@
padding: 4px 8px;
box-sizing: border-box;
}
.selectDisabled {
background-color: var(--selectItemDisabled);
}

.selectChecked {
background-color: var(--selectItemChecked);
Expand Down

0 comments on commit 051f052

Please sign in to comment.