-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Upload a picture into a document (see #153).
Co-Authored-By: Martin Gandon <[email protected]>
- Loading branch information
Showing
6 changed files
with
129 additions
and
7 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
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,51 @@ | ||
import '../styles/PassageMarginMenu.css'; | ||
|
||
import { Dropdown } from 'react-bootstrap'; | ||
import {forwardRef, useRef} from 'react'; | ||
import { ThreeDotsVertical } from 'react-bootstrap-icons'; | ||
|
||
function PassageMarginMenu ({ id, backend, handleImageUrl }) { | ||
const fileInputRef = useRef(null); | ||
|
||
const handleClick = () => { | ||
fileInputRef.current.click(); | ||
}; | ||
|
||
const handleFileChange = (event) => { | ||
const file = event.target.files[0]; | ||
if (file) backend.putAttachment(id, file, (response) => { | ||
handleImageUrl(`![<IMAGE DESCRIPTION>](${response.url})`); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Dropdown title="Block actions..."> | ||
<Dropdown.Toggle as={BlockMenuButton}/> | ||
<Dropdown.Menu id="block-actions"> | ||
<Dropdown.Item onClick={handleClick}>Add an image</Dropdown.Item> | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
<input | ||
id="image-input" | ||
type="file" | ||
ref={fileInputRef} | ||
style={{ display: 'none' }} | ||
onChange={handleFileChange} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
const BlockMenuButton = forwardRef(({ children, onClick }, ref) => ( | ||
<ThreeDotsVertical | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
onClick(e); | ||
}} | ||
ref={ref} class="editable-button"> | ||
{children} | ||
</ThreeDotsVertical> | ||
)); | ||
|
||
export default PassageMarginMenu; |
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
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,18 @@ | ||
.editable-button { | ||
visibility: hidden; | ||
margin-top: 0.25rem; | ||
color: crimson; | ||
} | ||
|
||
.editable:hover .editable-button { | ||
visibility: visible; | ||
cursor: pointer; | ||
} | ||
|
||
#block-actions .dropdown-item:hover { | ||
background-color: lightgray; | ||
} | ||
|
||
#block-actions .dropdown-item:active { | ||
color: black; | ||
} |