-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs(web-react): Add FileUploader demo #DS-896
FileUploader demo in web-react is now same as demo in web and web-twig
- Loading branch information
1 parent
4f64672
commit 29fd57a
Showing
25 changed files
with
773 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { Tag } from '../src/components'; | ||
|
||
interface DocsSectionProps { | ||
children: ReactNode; | ||
tag?: string; | ||
title: string; | ||
} | ||
|
||
const DocsSection = ({ children, title }: DocsSectionProps) => ( | ||
const DocsSection = ({ children, title, tag }: DocsSectionProps) => ( | ||
<section className="docs-Section"> | ||
<h2 className="docs-Heading">{title}</h2> | ||
<h2 className="docs-Heading"> | ||
{title} | ||
{tag && ( | ||
<Tag color="warning" isSubtle> | ||
{tag} | ||
</Tag> | ||
)} | ||
</h2> | ||
{children} | ||
</section> | ||
); | ||
|
||
DocsSection.defaultProps = { | ||
tag: '', | ||
}; | ||
|
||
export default DocsSection; |
25 changes: 25 additions & 0 deletions
25
packages/web-react/src/components/FileUploader/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { base64ToByteArray, image2Base64Preview } from '../utils'; | ||
|
||
const base64 = 'SGVsbG8gd29ybGQ='; | ||
const blob = new Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); | ||
|
||
describe('image2Base64Preview', () => { | ||
it('should convert image file to base64 string', () => { | ||
const file = new File([blob], 'image.jpg', { | ||
type: 'image/jpeg', | ||
}); | ||
|
||
image2Base64Preview(file, 100, (base64Preview) => { | ||
expect(base64Preview).toBeDefined(); | ||
expect(base64Preview).toBe(base64); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('base64ToByteArray', () => { | ||
it('should convert a base64 string to a byte array', () => { | ||
const result = base64ToByteArray(base64); | ||
|
||
expect(result).toEqual(blob); | ||
}); | ||
}); |
55 changes: 0 additions & 55 deletions
55
packages/web-react/src/components/FileUploader/demo/FileUploaderAccept.tsx
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
packages/web-react/src/components/FileUploader/demo/FileUploaderAttachment.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { DEMO_ATTACHMENT_BASE64_IMAGE } from './constants'; | ||
import { base64ToByteArray } from '../utils'; | ||
import { FileUploaderAttachment as FileUploaderAttachmentComponent, useFileQueue } from '..'; | ||
|
||
const FileUploaderAttachment = () => { | ||
const { onDismiss } = useFileQueue(); | ||
|
||
const byteArray = base64ToByteArray(DEMO_ATTACHMENT_BASE64_IMAGE); | ||
|
||
// ⚠️ VISUAL EXAMPLE ONLY, DO NOT COPY-PASTE | ||
return ( | ||
<div className="FileUploader"> | ||
<div className="FileUploaderList"> | ||
<FileUploaderAttachmentComponent | ||
name="test" | ||
file={new File([''], 'Document.pdf', { type: 'image/png', lastModified: 123456789 })} | ||
id="1" | ||
label="Document.pdf" | ||
onDismiss={onDismiss} | ||
/> | ||
<FileUploaderAttachmentComponent | ||
hasImagePreview | ||
name="test" | ||
file={new File([byteArray], 'test1.png', { type: 'image/png', lastModified: 123456789 })} | ||
id="2" | ||
label="Image with a long name.jpg" | ||
onDismiss={onDismiss} | ||
onEdit={() => { | ||
alert('Edit'); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FileUploaderAttachment; |
49 changes: 49 additions & 0 deletions
49
...ges/web-react/src/components/FileUploader/demo/FileUploaderAttachmentWithCustomAction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { SpiritFileUploaderAttachmentProps } from '../../../types'; | ||
import { FileUploader, FileUploaderAttachment, FileUploaderInput, FileUploaderList, useFileQueue } from '..'; | ||
|
||
const FileUploaderAttachmentWithCustomAction = () => { | ||
const { fileQueue, addToQueue, clearQueue, onDismiss, findInQueue, updateQueue } = useFileQueue(); | ||
|
||
const attachmentComponent = ({ id, ...props }: SpiritFileUploaderAttachmentProps) => ( | ||
<FileUploaderAttachment | ||
key={id} | ||
id={id} | ||
onEdit={() => { | ||
alert('Custom action clicked'); | ||
}} | ||
{...props} | ||
/> | ||
); | ||
|
||
return ( | ||
<FileUploader | ||
addToQueue={addToQueue} | ||
clearQueue={clearQueue} | ||
fileQueue={fileQueue} | ||
findInQueue={findInQueue} | ||
id="fileUploaderAttachmentWithCustomAction" | ||
onDismiss={onDismiss} | ||
updateQueue={updateQueue} | ||
> | ||
<FileUploaderInput | ||
helperText="Max size of each file is 10 MB" | ||
id="fileUploaderAttachmentWithCustomActionInput" | ||
label="Label" | ||
labelText="or drag and drop here" | ||
linkText="Upload your file(s)" | ||
name="attachments" | ||
/* eslint-disable-next-line no-console */ | ||
onError={(error) => console.error('My error log', error)} | ||
/> | ||
<FileUploaderList | ||
attachmentComponent={attachmentComponent} | ||
id="fileUploaderAttachmentWithCustomActionAttachment" | ||
inputName="attachments" | ||
label="Attachments" | ||
/> | ||
</FileUploader> | ||
); | ||
}; | ||
|
||
export default FileUploaderAttachmentWithCustomAction; |
50 changes: 50 additions & 0 deletions
50
...ges/web-react/src/components/FileUploader/demo/FileUploaderAttachmentWithImagePreview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { SpiritFileUploaderAttachmentProps } from '../../../types'; | ||
import { FileUploader, FileUploaderAttachment, FileUploaderInput, FileUploaderList, useFileQueue } from '..'; | ||
|
||
const FileUploaderAttachmentWithImagePreview = () => { | ||
const { fileQueue, addToQueue, clearQueue, onDismiss, findInQueue, updateQueue } = useFileQueue(); | ||
|
||
const attachmentComponent = ({ id, ...props }: SpiritFileUploaderAttachmentProps) => ( | ||
<FileUploaderAttachment | ||
key={id} | ||
id={id} | ||
onEdit={() => { | ||
alert('edit'); | ||
}} | ||
{...props} | ||
/> | ||
); | ||
|
||
return ( | ||
<FileUploader | ||
addToQueue={addToQueue} | ||
clearQueue={clearQueue} | ||
fileQueue={fileQueue} | ||
findInQueue={findInQueue} | ||
id="fileUploaderAttachmentWithImagePreview" | ||
onDismiss={onDismiss} | ||
updateQueue={updateQueue} | ||
> | ||
<FileUploaderInput | ||
helperText="Max size of each file is 10 MB" | ||
id="fileUploaderAttachmentWithImagePreviewInput" | ||
label="Label" | ||
labelText="or drag and drop here" | ||
linkText="Upload your file(s)" | ||
name="attachments" | ||
/* eslint-disable-next-line no-console */ | ||
onError={(error) => console.error('My error log', error)} | ||
/> | ||
<FileUploaderList | ||
attachmentComponent={attachmentComponent} | ||
id="fileUploaderAttachmentWithImagePreviewAttachment" | ||
inputName="attachments" | ||
label="Attachments" | ||
hasImagePreview | ||
/> | ||
</FileUploader> | ||
); | ||
}; | ||
|
||
export default FileUploaderAttachmentWithImagePreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/web-react/src/components/FileUploader/demo/FileUploaderDraggingNotAvailable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useEffect } from 'react'; | ||
import { SpiritFileUploaderAttachmentProps } from '../../../types'; | ||
import { FileUploader, FileUploaderAttachment, FileUploaderInput, FileUploaderList, useFileQueue } from '..'; | ||
|
||
const FileUploaderDraggingNotAvailable = () => { | ||
const { fileQueue, addToQueue, clearQueue, onDismiss, findInQueue, updateQueue } = useFileQueue(); | ||
|
||
const attachmentComponent = ({ id, ...props }: SpiritFileUploaderAttachmentProps) => ( | ||
<FileUploaderAttachment key={id} id={id} {...props} /> | ||
); | ||
|
||
useEffect(() => { | ||
const element = document.getElementById('fileUploaderDraggingNotAvailable')?.querySelector('.has-drag-and-drop'); | ||
element?.classList.remove('has-drag-and-drop'); | ||
}, []); | ||
|
||
// ⚠️ VISUAL EXAMPLE ONLY, DO NOT COPY-PASTE | ||
return ( | ||
<FileUploader | ||
addToQueue={addToQueue} | ||
clearQueue={clearQueue} | ||
fileQueue={fileQueue} | ||
findInQueue={findInQueue} | ||
id="fileUploaderDraggingNotAvailable" | ||
onDismiss={onDismiss} | ||
updateQueue={updateQueue} | ||
> | ||
<FileUploaderInput | ||
helperText="Max file size is 10 MB" | ||
id="fileUploaderDraggingNotAvailableInput" | ||
label="Label" | ||
labelText="or drag and drop here" | ||
linkText="Upload your file" | ||
name="attachments" | ||
/* eslint-disable-next-line no-console */ | ||
onError={(error) => console.error('My error log', error)} | ||
/> | ||
<FileUploaderList | ||
attachmentComponent={attachmentComponent} | ||
id="fileUploaderDraggingNotAvailableAttachment" | ||
inputName="attachments" | ||
label="Attachments" | ||
/> | ||
</FileUploader> | ||
); | ||
}; | ||
|
||
export default FileUploaderDraggingNotAvailable; |
Oops, something went wrong.