diff --git a/src/renderer/components/badge/badge.scss b/src/renderer/components/badge/badge.scss index 5bba59decb..513b7e5d78 100644 --- a/src/renderer/components/badge/badge.scss +++ b/src/renderer/components/badge/badge.scss @@ -7,31 +7,24 @@ white-space: nowrap; max-width: 100%; position: relative; + cursor: pointer; - >.children { - overflow: hidden; - text-overflow: ellipsis; + &:hover { + background-color: $mainBackground; } &.small { font-size: $font-size-small; } - &.expanded { - overflow: unset; - text-overflow: unset; - white-space: unset; - } + .label-content { + overflow: hidden; + text-overflow: ellipsis; - > .expansionIcon { - transform: scaleX(-1); - position: absolute; - z-index: 1; - right: -6px; - bottom: -6px; - color: $textColorAccent; - background-color: $halfGray; - border-radius: 50%; - padding: 2px; + &.isExpanded { + overflow: unset; + text-overflow: unset; + white-space: normal; + } } } diff --git a/src/renderer/components/badge/badge.tsx b/src/renderer/components/badge/badge.tsx index 3947dd1c24..73d1275293 100644 --- a/src/renderer/components/badge/badge.tsx +++ b/src/renderer/components/badge/badge.tsx @@ -6,55 +6,36 @@ import { TooltipDecoratorProps, withTooltip } from "../tooltip"; import { observer } from "mobx-react"; import { autobind } from "../../utils"; import { observable } from "mobx"; -import { Icon } from "../icon"; export interface BadgeProps extends React.HTMLAttributes, TooltipDecoratorProps { small?: boolean; label?: React.ReactNode; + isExpanded?: boolean; // by default: false (minimized) } @withTooltip @observer export class Badge extends React.Component { - private elem: HTMLElement; - - @observable isExpanded = false - @observable canBeExpanded = false - - componentDidMount() { - this.canBeExpanded = this.elem.offsetWidth < this.elem.scrollWidth - } + @observable isExpanded = false; @autobind() - onClick() { - if (this.canBeExpanded) { - this.isExpanded = !this.isExpanded - } - } - - renderExpansionIcon() { - if (!this.canBeExpanded) { - return null - } - - const material = this.isExpanded ? "close_fullscreen" : "open_in_full" - return + onMouseRelease() { + const textSelected = document.getSelection().toString().trim() !== ""; + if (textSelected) return; + this.isExpanded = this.props.isExpanded /*force to use state from outside*/ ?? !this.isExpanded /*toggle*/; } render() { - const { className, label, small, children, ...elemProps } = this.props; - const classNames = cssNames("Badge", className, { small, expanded: this.isExpanded }) - + const { className, label, small, children, isExpanded, ...elemProps } = this.props; + const classNames = cssNames("Badge", className, { + small: small, + }) + const labelClass = cssNames("label-content", { + isExpanded: this.isExpanded, + }) return ( -
- {this.renderExpansionIcon()} -
(this.elem = ref)}> +
+
{label} {children}