1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add horizontal scrolling to NamespaceSelect (#2276)

This commit is contained in:
Sebastian Malton 2021-03-12 08:45:32 -05:00 committed by GitHub
parent 51715b6a8c
commit 6508871209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 6 deletions

View File

@ -4,6 +4,23 @@
} }
} }
.GradientValueContainer {
width: 8px;
height: var(--font-size);
position: absolute;
z-index: 20;
&.front {
left: 0px;
background: linear-gradient(to right, var(--contentColor) 0px, transparent);
}
&.back {
right: 0px;
background: linear-gradient(to left, var(--contentColor) 0px, transparent);
}
}
.NamespaceSelect { .NamespaceSelect {
@include namespaceSelectCommon; @include namespaceSelectCommon;
@ -11,12 +28,19 @@
&__placeholder { &__placeholder {
width: 100%; width: 100%;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; overflow: scroll;
overflow: hidden; margin-left: -8px;
padding-left: 8px;
margin-right: -8px;
padding-right: 8px;
&::-webkit-scrollbar {
display: none;
}
} }
} }
} }
.NamespaceSelectMenu { .NamespaceSelectMenu {
@include namespaceSelectCommon; @include namespaceSelectCommon;
} }

View File

@ -8,6 +8,7 @@ import { cssNames } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { namespaceStore } from "./namespace.store"; import { namespaceStore } from "./namespace.store";
import { kubeWatchApi } from "../../api/kube-watch-api"; import { kubeWatchApi } from "../../api/kube-watch-api";
import { components, ValueContainerProps } from "react-select";
interface Props extends SelectProps { interface Props extends SelectProps {
showIcons?: boolean; showIcons?: boolean;
@ -21,6 +22,16 @@ const defaultProps: Partial<Props> = {
showClusterOption: false, showClusterOption: false,
}; };
function GradientValueContainer<T>({children, ...rest}: ValueContainerProps<T>) {
return (
<components.ValueContainer {...rest}>
<div className="GradientValueContainer front" />
{children}
<div className="GradientValueContainer back" />
</components.ValueContainer>
);
}
@observer @observer
export class NamespaceSelect extends React.Component<Props> { export class NamespaceSelect extends React.Component<Props> {
static defaultProps = defaultProps as object; static defaultProps = defaultProps as object;
@ -64,7 +75,9 @@ export class NamespaceSelect extends React.Component<Props> {
}; };
render() { render() {
const { className, showIcons, customizeOptions, ...selectProps } = this.props; const { className, showIcons, customizeOptions, components = {}, ...selectProps } = this.props;
components.ValueContainer ??= GradientValueContainer;
return ( return (
<Select <Select
@ -72,6 +85,7 @@ export class NamespaceSelect extends React.Component<Props> {
menuClass="NamespaceSelectMenu" menuClass="NamespaceSelectMenu"
formatOptionLabel={this.formatOptionLabel} formatOptionLabel={this.formatOptionLabel}
options={this.options} options={this.options}
components={components}
{...selectProps} {...selectProps}
/> />
); );

View File

@ -103,6 +103,7 @@ export class Select extends React.Component<SelectProps> {
value, options, components = {}, ...props value, options, components = {}, ...props
} = this.props; } = this.props;
const themeClass = `theme-${this.theme}`; const themeClass = `theme-${this.theme}`;
const WrappedMenu = components.Menu ?? Menu;
const selectProps: Partial<SelectProps> = { const selectProps: Partial<SelectProps> = {
...props, ...props,
@ -116,9 +117,9 @@ export class Select extends React.Component<SelectProps> {
components: { components: {
...components, ...components,
Menu: props => ( Menu: props => (
<Menu <WrappedMenu
{...props} {...props}
className={cssNames(menuClass, themeClass)} className={cssNames(menuClass, themeClass, props.className)}
/> />
), ),
} }