mirror of
https://github.com/plankanban/planka.git
synced 2025-07-25 16:19:47 +02:00
Add file attachments
This commit is contained in:
parent
87a3cf751a
commit
f743f4ea8b
103 changed files with 1847 additions and 305 deletions
|
@ -0,0 +1,52 @@
|
|||
import React, { useCallback, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import styles from './FilePicker.module.css';
|
||||
|
||||
const FilePicker = React.memo(({ children, accept, onSelect }) => {
|
||||
const field = useRef(null);
|
||||
|
||||
const handleTriggerClick = useCallback(() => {
|
||||
field.current.click();
|
||||
}, []);
|
||||
|
||||
const handleFieldChange = useCallback(
|
||||
({ target }) => {
|
||||
if (target.files[0]) {
|
||||
onSelect(target.files[0]);
|
||||
|
||||
target.value = null; // eslint-disable-line no-param-reassign
|
||||
}
|
||||
},
|
||||
[onSelect],
|
||||
);
|
||||
|
||||
const tigger = React.cloneElement(children, {
|
||||
onClick: handleTriggerClick,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{tigger}
|
||||
<input
|
||||
ref={field}
|
||||
type="file"
|
||||
accept={accept}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
FilePicker.propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
accept: PropTypes.string,
|
||||
onSelect: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
FilePicker.defaultProps = {
|
||||
accept: undefined,
|
||||
};
|
||||
|
||||
export default FilePicker;
|
|
@ -0,0 +1,3 @@
|
|||
.field {
|
||||
display: none;
|
||||
}
|
3
client/src/lib/custom-ui/components/FilePicker/index.js
Normal file
3
client/src/lib/custom-ui/components/FilePicker/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import FilePicker from './FilePicker';
|
||||
|
||||
export default FilePicker;
|
|
@ -1,6 +1,7 @@
|
|||
import Input from './components/Input';
|
||||
import Popup from './components/Popup';
|
||||
import Markdown from './components/Markdown';
|
||||
import FilePicker from './components/FilePicker';
|
||||
import DragScroller from './components/DragScroller';
|
||||
|
||||
export { Input, Popup, Markdown, DragScroller };
|
||||
export { Input, Popup, Markdown, FilePicker, DragScroller };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue