Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example with custom handler #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/react-uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^14.1.1",
"@uploadcare/uc-blocks": "^0.4.0",
"@uploadcare/uc-blocks": "^0.6.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.1",
Expand Down
60 changes: 36 additions & 24 deletions examples/react-uploader/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,56 @@ import st from "./App.module.css";
LR.registerBlocks(LR);

function App() {
let dataOutputRef = useRef();
const [files, setFiles] = useState([]);
const outputRef = useRef();
const handleUploaderEvent = useCallback((e) => {
const { data } = e.detail;
setFiles(data);
console.log('event', e);
}, []);

useEffect(() => {
let el = dataOutputRef.current;
el.addEventListener("data-output", handleUploaderEvent);
let el = outputRef.current;
el.addEventListener("lr-data-output", handleUploaderEvent);
return () => {
el.removeEventListener("data-output", handleUploaderEvent);
el.removeEventListener("lr-data-output", handleUploaderEvent);
};
}, [handleUploaderEvent]);

const classNames = ["lr-wgt-common", st.uploaderCfg].join(" ");
const classNames = ["lr-wgt-common", st.uploaderCfg, st.wrapper].join(" ");
const onClick = () => {
console.log('open modal', outputRef)
outputRef.current.initFlow()
}
const ctxName = 'my-context'

// 1) BUG - needed force ctx-name to each element
// 2) BUG - modal opened, but uploads not working, also tab-list not clickable
return (
<div className={st.wrapper}>
<lr-file-uploader-regular class={classNames}></lr-file-uploader-regular>
<div className={classNames}>
<button className={st.button} onClick={onClick}>upload</button>
<lr-modal ctx-name={ctxName}>
<lr-activity-icon slot='heading' />
<lr-activity-caption slot='heading' />
<lr-start-from ctx-name={ctxName}>
<lr-source-list />
<lr-drop-area />
</lr-start-from>
<lr-upload-list ctx-name={ctxName} />
<lr-camera-source ctx-name={ctxName} />
<lr-url-source ctx-name={ctxName} />
<lr-external-source ctx-name={ctxName} />
<lr-upload-details ctx-name={ctxName} />
<lr-confirmation-dialog ctx-name={ctxName} />
<lr-cloud-image-editor ctx-name={ctxName} />
</lr-modal>

<lr-message-box ctx-name={ctxName} />
<lr-progress-bar ctx-name={ctxName} />

<lr-data-output
ref={dataOutputRef}
fire-event
ref={outputRef}
use-event
class={classNames}
onEvent={handleUploaderEvent}
ctx-name={ctxName}
></lr-data-output>

<div className={st.output}>
{files.map((file) => (
<img
key={file.uuid}
src={`https://ucarecdn.com/${file.uuid}/-/preview/-/scale_crop/400x400/`}
width="200"
alt="Preview"
/>
))}
</div>
</div>
);
}
Expand Down
8 changes: 8 additions & 0 deletions examples/react-uploader/src/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@
--cfg-source-list: "local, url, camera, dropbox, gdrive";
--cfg-max-files: 10;
}
.button {
width: 200px;
height: 50px;
padding: 10px;
background: gold;
border-radius: 10px;
cursor: pointer;
}