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

FilePicker restyling

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
This commit is contained in:
alexfront 2020-08-06 13:05:02 +03:00
parent af7220c29f
commit a69264e2cd
3 changed files with 45 additions and 44 deletions

View File

@ -1,13 +1,17 @@
import React from "react"; import React from "react";
import { Cluster } from "../../../../main/cluster"; import { Cluster } from "../../../../main/cluster";
import { clusterStore } from "../../../../common/cluster-store"
import { Icon } from "../../icon";
import { FilePicker, OverSizeLimitStyle } from "../../file-picker"; import { FilePicker, OverSizeLimitStyle } from "../../file-picker";
import { autobind } from "../../../utils"; import { autobind } from "../../../utils";
import { Button } from "../../button"; import { Button } from "../../button";
import { GeneralInputStatus } from "./statuses"
import { observable } from "mobx"; import { observable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { SubTitle } from "../../layout/sub-title";
import { ClusterIcon } from "../../cluster-icon";
enum GeneralInputStatus {
CLEAN = "clean",
ERROR = "error",
}
interface Props { interface Props {
cluster: Cluster; cluster: Cluster;
@ -21,7 +25,6 @@ export class ClusterIconSetting extends React.Component<Props> {
@autobind() @autobind()
async onIconPick([file]: File[]) { async onIconPick([file]: File[]) {
const { cluster } = this.props; const { cluster } = this.props;
try { try {
if (file) { if (file) {
const buf = Buffer.from(await file.arrayBuffer()); const buf = Buffer.from(await file.arrayBuffer());
@ -38,35 +41,36 @@ export class ClusterIconSetting extends React.Component<Props> {
} }
getClearButton() { getClearButton() {
const { cluster } = this.props; if (this.props.cluster.preferences.icon) {
return <Button tooltip="Revert back to default icon" accent onClick={() => this.onIconPick([])}>Clear</Button>
if (cluster.preferences.icon) {
return <Button accent onClick={() => this.onIconPick([])}>Clear</Button>
} }
} }
render() { render() {
return <> const label = (
<h4>Cluster Icon</h4> <>
<p>Set cluster icon. By default it is automatically generated. {this.getIconRight()}</p> <ClusterIcon
<div className="center"> cluster={this.props.cluster}
showErrors={false}
showTooltip={false}
/>
{"Browse for new icon..."}
</>
);
return (
<>
<SubTitle title="Cluster Icon" />
<p>Define cluster icon. By default automatically generated.</p>
<div className="file-loader">
<FilePicker <FilePicker
accept="image/*" accept="image/*"
labelText="Browse for new icon..." label={label}
onOverSizeLimit={OverSizeLimitStyle.FILTER} onOverSizeLimit={OverSizeLimitStyle.FILTER}
handler={this.onIconPick} handler={this.onIconPick}
/> />
{this.getClearButton()} {this.getClearButton()}
</div> </div>
</>; </>
} );
getIconRight(): React.ReactNode {
switch (this.status) {
case GeneralInputStatus.CLEAN:
return null;
case GeneralInputStatus.ERROR:
return <Icon size="16px" material="error" title={this.errorText}></Icon>
}
} }
} }

View File

@ -4,11 +4,8 @@
} }
label { label {
display: inline-block; display: inline-flex;
border: medium solid;
padding: 10px;
border-radius: 5px;
cursor: pointer; cursor: pointer;
margin: 5px; color: var(--blue);
} }
} }

View File

@ -43,7 +43,7 @@ export enum OverTotalSizeLimitStyle {
export interface BaseProps { export interface BaseProps {
accept?: string; accept?: string;
labelText: string; label: React.ReactElement;
multiple?: boolean; multiple?: boolean;
// limit is the optional maximum number of files to upload // limit is the optional maximum number of files to upload
@ -175,10 +175,10 @@ export class FilePicker extends React.Component<Props> {
} }
render() { render() {
const { accept, labelText, multiple } = this.props; const { accept, label, multiple } = this.props;
return <div className="FilePicker"> return <div className="FilePicker">
<label htmlFor="file-upload">{labelText} {this.getIconRight()}</label> <label className="flex gaps align-center" htmlFor="file-upload">{label} {this.getIconRight()}</label>
<input <input
id="file-upload" id="file-upload"
name="FilePicker" name="FilePicker"