Skip to content

Commit b407ce4

Browse files
authored
feat(forms): allow custom upload hints (#802)
1 parent 9d300f0 commit b407ce4

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

src/bundle/toolbar/custom/ToolbarFilePopup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type ToolbarFilePopupProps = Omit<ToolbarBaseProps<never>, 'editor'> & {
2020

2121
uploadHandler?: FileUploadHandler;
2222
onSuccessUpload?: (result: BatchUploadResult) => void;
23-
} & Pick<FileFormProps, 'onSubmit'>;
23+
} & Pick<FileFormProps, 'onSubmit' | 'uploadHint'>;
2424

2525
export const ToolbarFilePopup: React.FC<ToolbarFilePopupProps> = ({
2626
className,
@@ -32,6 +32,7 @@ export const ToolbarFilePopup: React.FC<ToolbarFilePopupProps> = ({
3232
onClick,
3333
uploadHandler,
3434
onSuccessUpload,
35+
uploadHint,
3536
}) => {
3637
const toaster = useToaster();
3738
const [loading, showLoading, hideLoading] = useBooleanState(false);
@@ -82,6 +83,7 @@ export const ToolbarFilePopup: React.FC<ToolbarFilePopupProps> = ({
8283
onClick?.('addFile');
8384
}}
8485
loading={loading}
86+
uploadHint={uploadHint}
8587
/>
8688
</Popup>
8789
);

src/bundle/toolbar/custom/ToolbarImagePopup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type ToolbarImagePopuProps = Omit<ToolbarBaseProps<never>, 'editor'> & {
1919
onSuccessUpload?: (res: BatchUploadResult) => void;
2020
hide: () => void;
2121
anchorElement: HTMLElement | null;
22-
} & Pick<ImageFormProps, 'onSubmit' | 'imageTitle'>;
22+
} & Pick<ImageFormProps, 'onSubmit' | 'imageTitle' | 'uploadHint'>;
2323

2424
export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
2525
className,
@@ -31,6 +31,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
3131
uploadImages,
3232
onSuccessUpload,
3333
imageTitle,
34+
uploadHint,
3435
}) => {
3536
const toaster = useToaster();
3637
const [loading, showLoading, hideLoading] = useBooleanState(false);
@@ -81,6 +82,7 @@ export const ToolbarImagePopup: React.FC<ToolbarImagePopuProps> = ({
8182
}}
8283
loading={loading}
8384
imageTitle={imageTitle}
85+
uploadHint={uploadHint}
8486
/>
8587
</Popup>
8688
);

src/forms/FileForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type FileFormProps = ClassNameProps & {
3030
onCancel(): void;
3131
onAttach?: (files: File[]) => void;
3232
loading?: boolean;
33+
uploadHint?: string;
3334
};
3435

3536
export const FileForm: React.FC<FileFormProps> = ({
@@ -39,6 +40,7 @@ export const FileForm: React.FC<FileFormProps> = ({
3940
onSubmit,
4041
onAttach,
4142
loading,
43+
uploadHint,
4244
}) => {
4345
const [tabId, setTabId] = useState<string>(() =>
4446
isFunction(onAttach) ? TabId.Attach : TabId.Link,
@@ -75,7 +77,7 @@ export const FileForm: React.FC<FileFormProps> = ({
7577
)}
7678
{tabId === TabId.Attach && onAttach && (
7779
<>
78-
<Form.Layout>{i18n('file_upload_help')}</Form.Layout>
80+
<Form.Layout>{uploadHint ?? i18n('file_upload_help')}</Form.Layout>
7981
<Form.Footer onCancel={onCancel}>
8082
<ButtonAttach
8183
multiple

src/forms/ImageForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type ImageFormProps = ClassNameProps & {
3636
onAttach?: (files: File[]) => void;
3737
loading?: boolean;
3838
imageTitle?: string;
39+
uploadHint?: string;
3940
};
4041

4142
export const ImageForm: React.FC<ImageFormProps> = ({
@@ -46,6 +47,7 @@ export const ImageForm: React.FC<ImageFormProps> = ({
4647
onAttach,
4748
loading,
4849
imageTitle: providedName,
50+
uploadHint,
4951
}) => {
5052
const [tabId, setTabId] = useState<string>(() =>
5153
isFunction(onAttach) ? ImageTabId.Attach : ImageTabId.Link,
@@ -89,7 +91,7 @@ export const ImageForm: React.FC<ImageFormProps> = ({
8991
)}
9092
{tabId === ImageTabId.Attach && onAttach && (
9193
<>
92-
<Form.Layout>{i18n('image_upload_help')}</Form.Layout>
94+
<Form.Layout>{uploadHint ?? i18n('image_upload_help')}</Form.Layout>
9395
<Form.Footer onCancel={onCancel}>
9496
<ButtonAttach
9597
multiple

src/forms/uploadHints.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {renderToStaticMarkup} from 'react-dom/server';
2+
3+
import {FileForm} from './FileForm';
4+
import {ImageForm} from './ImageForm';
5+
6+
describe('upload hints', () => {
7+
const commonImageProps = {
8+
onSubmit: jest.fn(),
9+
onCancel: jest.fn(),
10+
onAttach: () => {},
11+
};
12+
13+
it('ImageForm should display custom upload hint', () => {
14+
const html = renderToStaticMarkup(
15+
<ImageForm {...commonImageProps} uploadHint="custom image hint" />,
16+
);
17+
18+
expect(html).toContain('custom image hint');
19+
});
20+
21+
it('FileForm should display custom upload hint', () => {
22+
const html = renderToStaticMarkup(
23+
<FileForm {...commonImageProps} uploadHint="custom file hint" />,
24+
);
25+
26+
expect(html).toContain('custom file hint');
27+
});
28+
});

0 commit comments

Comments
 (0)