Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/fields/file-upload/file-upload.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { FileUpload as DSFileUpload, FileItemProps } from "@lifesg/react-design-system/file-upload";
import { FileItemProps, FileUpload as DSFileUpload } from "@lifesg/react-design-system/file-upload";
import xor from "lodash/xor";
import { Suspense, lazy, useCallback, useContext, useEffect, useRef, useState } from "react";
import { useFormContext } from "react-hook-form";
import * as Yup from "yup";
import { IGenericFieldProps } from "..";
import { FileHelper } from "../../../utils";
import { useFieldEvent, useValidationConfig } from "../../../utils/hooks";
import { IYupValidationRule } from "../../frontend-engine";
Expand All @@ -18,6 +17,7 @@ import {
IFileUploadValue,
TFileUploadErrorObject,
} from "./types";
import { IGenericFieldProps } from "../types";

// lazy load to fix next.js SSR errors
const FileUploadManager = lazy(() => import("./file-upload-manager"));
Expand All @@ -40,6 +40,7 @@ export const FileUploadInner = (props: IGenericFieldProps<IFileUploadSchema>) =>
uploadOnAddingFile,
validation,
warning: schemaWarning,
customLabels,
...otherSchema
},
warning,
Expand Down Expand Up @@ -338,6 +339,7 @@ export const FileUploadInner = (props: IGenericFieldProps<IFileUploadSchema>) =>
onDelete={handleDelete}
title={renderHtmlText(label)}
warning={renderHtmlText(warning || schemaWarning)}
customLabels={customLabels}
/>
</>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/fields/file-upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IFileUploadSchema<V = undefined>
className?: string | undefined;
description?: string | undefined;
label: string;
customLabels?: TFileUploadCustomLabels | undefined;
hideThumbnail?: boolean | undefined;
uploadOnAddingFile: {
type: TUploadType;
Expand Down Expand Up @@ -86,6 +87,9 @@ export type TUploadErrorDetail = {
errorData: unknown;
};

// Custom labels type for FileUpload
export type TFileUploadCustomLabels = FileUploadProps extends { customLabels?: infer T } ? T : never;

// =============================================================================
// EVENTS (fired from FEE)
// =============================================================================
Expand Down
8 changes: 8 additions & 0 deletions src/stories/3-fields/file-upload/file-upload.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const meta: Meta = {
},
},
},
customLabels: {
description: "Specify custom label text for some elements",
table: {
type: {
summary: "{ uploadButtonLabel?: string }",
},
},
},
capture: {
description:
"Whether to allow image to be taken by device and which camera to do so. Based on HTML capture attribute, for more info, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#capture",
Expand Down