Skip to content

Commit

Permalink
Work for surveyjs/survey-creator#4435: implement loading indicator in…
Browse files Browse the repository at this point in the history
… React
  • Loading branch information
dk981234 committed Sep 5, 2023
1 parent 3ebc292 commit 8b52568
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/entries/react-ui-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export { CharacterCounterComponent } from "../react/components/character-counter

export { SurveyLocStringViewer } from "../react/string-viewer";
export { SurveyLocStringEditor } from "../react/string-editor";
export { LoadingIndicatorComponent } from "../react/components/loading-indicator";

//Uncomment to include the "date" question type.
//export {default as SurveyQuestionDate} from "../plugins/react/reactquestiondate";
8 changes: 8 additions & 0 deletions src/react/components/loading-indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";
import { SvgIcon } from "./svg-icon/svg-icon";

export class LoadingIndicatorComponent extends React.Component<any, any> {
render(): JSX.Element | null {
return (<div className="sd-loading-indicator"><SvgIcon iconName="icon-loading" size="auto"></SvgIcon></div>);
}
}
26 changes: 18 additions & 8 deletions src/react/reactquestion_file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SvgIcon } from "./components/svg-icon/svg-icon";
import { SurveyQuestionElementBase } from "./reactquestion_element";
import { ReactQuestionFactory } from "./reactquestion_factory";
import { attachKey2click } from "./reactSurvey";
import { LoadingIndicatorComponent } from "./components/loading-indicator";

export class SurveyQuestionFile extends SurveyQuestionElementBase {
constructor(props: any) {
Expand All @@ -13,6 +14,9 @@ export class SurveyQuestionFile extends SurveyQuestionElementBase {
protected get question(): QuestionFileModel {
return this.questionBase as QuestionFileModel;
}
protected renderLoadingIndicator(): JSX.Element {
return <LoadingIndicatorComponent></LoadingIndicatorComponent>;
}
protected renderElement(): JSX.Element {
var preview = this.renderPreview();
var fileInput: JSX.Element | null = null;
Expand Down Expand Up @@ -79,7 +83,16 @@ export class SurveyQuestionFile extends SurveyQuestionElementBase {
);
}
protected renderFileDecorator(): JSX.Element {
const questionCss = this.question.cssClasses;
const content = this.question.isUploading ? this.renderLoadingIndicator() : this.renderButtons();
return (
<div
className={this.question.getFileDecoratorCss()}
>
{content}
</div>
);
}
protected renderButtons(): JSX.Element {
let noFileChosen: JSX.Element | null = null;
let chooseFile: JSX.Element | null = null;
chooseFile = this.question.isReadOnly ? null : attachKey2click(
Expand All @@ -102,19 +115,16 @@ export class SurveyQuestionFile extends SurveyQuestionElementBase {
);
}
return (
<div
className={this.question.getFileDecoratorCss()}
>
<>
<span className={this.question.cssClasses.dragAreaPlaceholder}>{this.question.renderedPlaceholder}</span>
<div className={this.question.cssClasses.wrapper}>
{chooseFile}
{noFileChosen}
</div>
</div>
);
</>);
}
protected renderClearButton(className: string): JSX.Element | null {
return className ? (
return className && !this.question.isUploading ? (
<button type="button" onClick={this.question.doClean} className={className}>
<span>{this.question.clearButtonCaption}</span>
{(!!this.question.cssClasses.removeButtonIconId) ? <SvgIcon iconName={this.question.cssClasses.removeButtonIconId} size={"auto"} title={this.question.clearButtonCaption}></SvgIcon>: null }
Expand All @@ -140,7 +150,7 @@ export class SurveyQuestionFile extends SurveyQuestionElementBase {
);
}
protected renderPreview(): JSX.Element | null {
if (!this.question.previewValue || !this.question.previewValue.length) return null;
if (!this.question.previewValue || !this.question.previewValue.length || this.question.isUploading) return null;
var previews = this.question.previewValue.map((val, index) => {
if (!val) return null;
return (
Expand Down

0 comments on commit 8b52568

Please sign in to comment.