mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add button to expand and view whole badge contents
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
25be6401e2
commit
21db4e39fb
@ -233,6 +233,7 @@
|
|||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"mac-ca": "^1.0.4",
|
"mac-ca": "^1.0.4",
|
||||||
"marked": "^1.1.0",
|
"marked": "^1.1.0",
|
||||||
|
"material-design-icons-iconfont": "^6.1.0",
|
||||||
"md5-file": "^5.0.0",
|
"md5-file": "^5.0.0",
|
||||||
"mobx": "^5.15.5",
|
"mobx": "^5.15.5",
|
||||||
"mobx-observable-history": "^1.0.3",
|
"mobx-observable-history": "^1.0.3",
|
||||||
|
|||||||
@ -6,10 +6,32 @@
|
|||||||
padding: .2em .4em;
|
padding: .2em .4em;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
overflow: hidden;
|
position: relative;
|
||||||
text-overflow: ellipsis;
|
|
||||||
|
>.children {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
&.small {
|
&.small {
|
||||||
font-size: $font-size-small;
|
font-size: $font-size-small;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
&.expanded {
|
||||||
|
overflow: unset;
|
||||||
|
text-overflow: unset;
|
||||||
|
white-space: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .expansionIcon {
|
||||||
|
transform: scaleX(-1);
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
right: -10px;
|
||||||
|
bottom: -10px;
|
||||||
|
color: $textColorAccent;
|
||||||
|
background-color: $halfGray;
|
||||||
|
border-radius: 50%;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -3,6 +3,10 @@ import "./badge.scss"
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { cssNames } from "../../utils/cssNames";
|
import { cssNames } from "../../utils/cssNames";
|
||||||
import { TooltipDecoratorProps, withTooltip } from "../tooltip";
|
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<any>, TooltipDecoratorProps {
|
export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorProps {
|
||||||
small?: boolean;
|
small?: boolean;
|
||||||
@ -10,14 +14,48 @@ export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorP
|
|||||||
}
|
}
|
||||||
|
|
||||||
@withTooltip
|
@withTooltip
|
||||||
|
@observer
|
||||||
export class Badge extends React.Component<BadgeProps> {
|
export class Badge extends React.Component<BadgeProps> {
|
||||||
|
private elem: HTMLElement;
|
||||||
|
|
||||||
|
@observable isExpanded = false
|
||||||
|
@observable canBeExpanded = false
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.canBeExpanded = this.elem.offsetWidth < this.elem.scrollWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind()
|
||||||
|
onClick() {
|
||||||
|
if (this.canBeExpanded) {
|
||||||
|
this.isExpanded = !this.isExpanded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderExpansionIcon() {
|
||||||
|
if (!this.canBeExpanded) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isExpanded) {
|
||||||
|
return <Icon className="expansionIcon" size={20} material="close_fullscreen" onClick={this.onClick} />
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Icon className="expansionIcon" size={20} material="open_in_full" onClick={this.onClick} />
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, label, small, children, ...elemProps } = this.props;
|
const { className, label, small, children, ...elemProps } = this.props;
|
||||||
return <>
|
const classNames = cssNames("Badge", className, { small, expanded: this.isExpanded })
|
||||||
<span className={cssNames("Badge", { small }, className)} {...elemProps}>
|
|
||||||
{label}
|
return (
|
||||||
{children}
|
<div className={classNames} {...elemProps}>
|
||||||
</span>
|
{this.renderExpansionIcon()}
|
||||||
</>
|
<div className="children" ref={ref => (this.elem = ref)}>
|
||||||
|
{label}
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
|
$material-design-icons-font-directory-path: '~material-design-icons-iconfont/dist/fonts/';
|
||||||
|
|
||||||
// Custom fonts
|
// Custom fonts
|
||||||
|
@import "~material-design-icons-iconfont/src/material-design-icons";
|
||||||
@import "~typeface-roboto/index.css";
|
@import "~typeface-roboto/index.css";
|
||||||
|
|
||||||
// Material Design Icons, used primarily in icon.tsx
|
// Material Design Icons, used primarily in icon.tsx
|
||||||
@ -17,4 +20,4 @@
|
|||||||
font-family: 'RobotoMono';
|
font-family: 'RobotoMono';
|
||||||
src: local('RobotoMono'),
|
src: local('RobotoMono'),
|
||||||
url('fonts/roboto-mono-nerd.ttf') format('truetype');
|
url('fonts/roboto-mono-nerd.ttf') format('truetype');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,4 +132,4 @@
|
|||||||
@extend .active;
|
@extend .active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { TooltipDecoratorProps, withTooltip } from "../tooltip";
|
|||||||
import isNumber from "lodash/isNumber"
|
import isNumber from "lodash/isNumber"
|
||||||
|
|
||||||
export interface IconProps extends React.HTMLAttributes<any>, TooltipDecoratorProps {
|
export interface IconProps extends React.HTMLAttributes<any>, TooltipDecoratorProps {
|
||||||
material?: string; // material-icon, see available names at https://material.io/icons/
|
material?: string; // material-icon, see available names at https://jossef.github.io/material-design-icons-iconfont/
|
||||||
svg?: string; // svg-filename without extension in current folder
|
svg?: string; // svg-filename without extension in current folder
|
||||||
link?: LocationDescriptor; // render icon as NavLink from react-router-dom
|
link?: LocationDescriptor; // render icon as NavLink from react-router-dom
|
||||||
href?: string; // render icon as hyperlink
|
href?: string; // render icon as hyperlink
|
||||||
@ -32,7 +32,7 @@ export class Icon extends React.PureComponent<IconProps> {
|
|||||||
|
|
||||||
get isInteractive() {
|
get isInteractive() {
|
||||||
const { interactive, onClick, href, link } = this.props;
|
const { interactive, onClick, href, link } = this.props;
|
||||||
return interactive || !!(onClick || href || link);
|
return !!(interactive || onClick || href || link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
@ -87,7 +87,7 @@ export class Icon extends React.PureComponent<IconProps> {
|
|||||||
|
|
||||||
// render as inline svg-icon
|
// render as inline svg-icon
|
||||||
if (svg) {
|
if (svg) {
|
||||||
const svgIconText = require("!!raw-loader!./" + svg + ".svg").default;
|
const svgIconText = require(`!!raw-loader!./${svg}.svg`).default;
|
||||||
iconContent = <span className="icon" dangerouslySetInnerHTML={{ __html: svgIconText }}/>;
|
iconContent = <span className="icon" dangerouslySetInnerHTML={{ __html: svgIconText }}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9476,6 +9476,11 @@ matcher@^3.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
escape-string-regexp "^4.0.0"
|
escape-string-regexp "^4.0.0"
|
||||||
|
|
||||||
|
material-design-icons-iconfont@^6.1.0:
|
||||||
|
version "6.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/material-design-icons-iconfont/-/material-design-icons-iconfont-6.1.0.tgz#ffad21a71f2000336fd410cbeba36ddbf301f0f2"
|
||||||
|
integrity sha512-wRJtOo1v1ch+gN8PRsj0IGJznk+kQ8mz13ds/nuhLI+Qyf/931ZlRpd92oq0IRPpZIb+bhX8pRjzIVdcPDKmiQ==
|
||||||
|
|
||||||
md5-file@^5.0.0:
|
md5-file@^5.0.0:
|
||||||
version "5.0.0"
|
version "5.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/md5-file/-/md5-file-5.0.0.tgz#e519f631feca9c39e7f9ea1780b63c4745012e20"
|
resolved "https://registry.yarnpkg.com/md5-file/-/md5-file-5.0.0.tgz#e519f631feca9c39e7f9ea1780b63c4745012e20"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user