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:
parent
af7220c29f
commit
a69264e2cd
@ -1,16 +1,20 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -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}
|
||||||
<FilePicker
|
showErrors={false}
|
||||||
accept="image/*"
|
showTooltip={false}
|
||||||
labelText="Browse for new icon..."
|
|
||||||
onOverSizeLimit={OverSizeLimitStyle.FILTER}
|
|
||||||
handler={this.onIconPick}
|
|
||||||
/>
|
/>
|
||||||
{this.getClearButton()}
|
{"Browse for new icon..."}
|
||||||
</div>
|
</>
|
||||||
</>;
|
);
|
||||||
}
|
return (
|
||||||
|
<>
|
||||||
getIconRight(): React.ReactNode {
|
<SubTitle title="Cluster Icon" />
|
||||||
switch (this.status) {
|
<p>Define cluster icon. By default automatically generated.</p>
|
||||||
case GeneralInputStatus.CLEAN:
|
<div className="file-loader">
|
||||||
return null;
|
<FilePicker
|
||||||
case GeneralInputStatus.ERROR:
|
accept="image/*"
|
||||||
return <Icon size="16px" material="error" title={this.errorText}></Icon>
|
label={label}
|
||||||
}
|
onOverSizeLimit={OverSizeLimitStyle.FILTER}
|
||||||
|
handler={this.onIconPick}
|
||||||
|
/>
|
||||||
|
{this.getClearButton()}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,14 +1,11 @@
|
|||||||
.FilePicker {
|
.FilePicker {
|
||||||
input[type="file"] {
|
input[type="file"] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-flex;
|
||||||
border: medium solid;
|
cursor: pointer;
|
||||||
padding: 10px;
|
color: var(--blue);
|
||||||
border-radius: 5px;
|
}
|
||||||
cursor: pointer;
|
|
||||||
margin: 5px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -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"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user