-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
311 additions
and
144 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
77 changes: 77 additions & 0 deletions
77
packages/picasso-rich-text-editor/src/RichTextEditor/story/ImageUpload.example.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,77 @@ | ||
import React, { useState } from 'react' | ||
import { Container, Radio } from '@toptal/picasso' | ||
import type { UploadedImage } from '@toptal/picasso-rich-text-editor' | ||
import { ImagePlugin, RichTextEditor } from '@toptal/picasso-rich-text-editor' | ||
|
||
import type { RichTextEditorChangeHandler } from '../types' | ||
|
||
// Imitate file upload function that sets image URL | ||
const onUploadSucceeded = (uploadedImage: UploadedImage) => | ||
new Promise<UploadedImage>(resolve => { | ||
setTimeout(() => { | ||
const fileUrl = `./jacqueline/128x128.jpg?originalFileName=${encodeURIComponent( | ||
uploadedImage.file.name | ||
)}` | ||
|
||
resolve({ ...uploadedImage, url: fileUrl }) | ||
}, 2000) | ||
}) | ||
|
||
// Imitate failure during upload | ||
const onUploadFailed = () => | ||
new Promise<UploadedImage>((resolve, reject) => { | ||
setTimeout(() => { | ||
reject('Upload failed') | ||
}, 2000) | ||
}) | ||
|
||
const Example = () => { | ||
const [value, setValue] = useState<string | undefined>() | ||
const [useSuccessfulUpload, setUseSuccessfullUpload] = useState('true') | ||
|
||
const handleChange: RichTextEditorChangeHandler = newValue => | ||
setValue(newValue) | ||
|
||
return ( | ||
<> | ||
<Container bottom='medium'> | ||
<Radio.Group | ||
name='onUploadCase' | ||
onChange={(event: React.ChangeEvent<{ value: string }>) => { | ||
setUseSuccessfullUpload(event.target.value) | ||
}} | ||
value={useSuccessfulUpload} | ||
> | ||
<Radio label='Imitate successful upload' value='true' /> | ||
<Radio label='Imitate failing upload' value='false' /> | ||
</Radio.Group> | ||
</Container> | ||
<RichTextEditor | ||
id='editor' | ||
onChange={handleChange} | ||
placeholder='Write some cool rich text' | ||
plugins={[ | ||
<ImagePlugin | ||
onUpload={ | ||
useSuccessfulUpload === 'true' | ||
? onUploadSucceeded | ||
: onUploadFailed | ||
} | ||
/>, | ||
]} | ||
/> | ||
<Container | ||
padded='small' | ||
top='large' | ||
style={{ | ||
fontFamily: "Consolas, 'Courier New', monospace", | ||
background: 'lightyellow', | ||
}} | ||
> | ||
{value} | ||
</Container> | ||
</> | ||
) | ||
} | ||
|
||
export default Example |
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
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
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
133 changes: 0 additions & 133 deletions
133
packages/picasso-rich-text-editor/src/plugins/ImagePlugin/ImagePluginModal.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...plugins/ImagePlugin/ImagePluginButton.tsx → ...s/ImagePluginButton/ImagePluginButton.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
1 change: 1 addition & 0 deletions
1
...es/picasso-rich-text-editor/src/plugins/ImagePlugin/components/ImagePluginButton/index.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 @@ | ||
export { default as ImagePluginButton } from './ImagePluginButton' |
Oops, something went wrong.