Add drag layer

This commit is contained in:
MrKBear 2022-04-24 20:16:03 +08:00
parent 4c014a7200
commit 4137362501
2 changed files with 84 additions and 29 deletions

View File

@ -5,34 +5,51 @@ div.load-file-layer-root {
z-index: 1000; z-index: 1000;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; box-sizing: border-box;
align-content: center; padding: 20px;
justify-content: center;
align-items: center;
flex-wrap: wrap;
div { div.load-file-layer {
user-select: none;
text-align: center;
width: 100%; width: 100%;
} height: 100%;
display: flex;
align-content: center;
justify-content: center;
align-items: center;
flex-wrap: wrap;
border-radius: 3px;
div.drag-icon { div {
font-weight: 200; pointer-events: none;
font-size: 2.8em; user-select: none;
} text-align: center;
width: 100%;
}
div.drag-title { div.drag-icon {
margin-top: 5px; font-weight: 200;
margin-bottom: 5px; font-size: 2.8em;
font-size: 1.5em; }
div.drag-title {
margin-top: 5px;
margin-bottom: 5px;
font-size: 1.5em;
}
} }
} }
div.load-file-layer-root.light { div.load-file-layer-root.light {
background-color: rgba($color: #FFFFFF, $alpha: .75); background-color: rgba($color: #FFFFFF, $alpha: .6);
div.load-file-layer {
border: 2px dashed $lt-font-color-normal-light;
}
} }
div.load-file-layer-root.dark { div.load-file-layer-root.dark {
background-color: rgba($color: #000000, $alpha: .75); background-color: rgba($color: #000000, $alpha: .6);
div.load-file-layer {
border: 2px dashed $lt-font-color-normal-dark;
}
} }

View File

@ -4,27 +4,65 @@ import { Icon } from "@fluentui/react";
import { Component, ReactNode } from "react"; import { Component, ReactNode } from "react";
import "./LoadFile.scss"; import "./LoadFile.scss";
class LoadFile extends Component { interface ILoadFileState {
show: boolean;
}
class LoadFile extends Component<{}, ILoadFileState> {
public state: Readonly<ILoadFileState> = {
show: false
};
private renderMask() { private renderMask() {
return <Theme return <Theme
className="load-file-layer-root" className="load-file-layer-root"
fontLevel={FontLevel.normal} fontLevel={FontLevel.normal}
onDragEnter={this.handleWindowsDragOnFiles}
onDragLeave={this.handleWindowsDragOffFiles}
> >
<div className="drag-icon"> <div className="load-file-layer">
<Icon iconName="KnowledgeArticle"/> <div className="drag-icon">
</div> <Icon iconName="KnowledgeArticle"/>
<div className="drag-title"> </div>
<Localization i18nKey="Info.Hint.Load.File.Title"/> <div className="drag-title">
</div> <Localization i18nKey="Info.Hint.Load.File.Title"/>
<div className="drag-intro"> </div>
<Localization i18nKey="Info.Hint.Load.File.Intro"/> <div className="drag-intro">
<Localization i18nKey="Info.Hint.Load.File.Intro"/>
</div>
</div> </div>
</Theme>; </Theme>;
} }
private offDragTimer: NodeJS.Timeout | undefined;
private handleWindowsDragOnFiles = () => {
clearTimeout(this.offDragTimer as number | undefined);
this.setState({
show: true
});
}
private handleWindowsDragOffFiles = () => {
clearTimeout(this.offDragTimer as number | undefined);
this.offDragTimer = setTimeout(() => {
this.setState({
show: false
});
});
}
public componentDidMount() {
window.addEventListener("dragenter", this.handleWindowsDragOnFiles);
}
public componentWillUnmount() {
window.removeEventListener("dragenter", this.handleWindowsDragOnFiles);
}
public render(): ReactNode { public render(): ReactNode {
return <></>; return this.state.show ? this.renderMask() : null;
} }
} }