react-icons/ai#AiFillCloseCircle JavaScript Examples
The following examples show how to use
react-icons/ai#AiFillCloseCircle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModalProvider.js From plataforma-sabia with MIT License | 5 votes |
ModalProvider = ({ children }) => {
const [state, dispatch] = useReducer(modalReducer, INITIAL_STATE);
const ModalComponent = getModalComponent(state.modal);
const closeModal = useCallback(() => dispatch({ type: 'CLOSE_MODAL' }), []);
useEffect(() => {
const handleKeyUp = ({ key }) => {
if (key === 'Escape') closeModal();
};
if (ModalComponent && document) {
document.body.classList.add('modal-open');
window.addEventListener('keyup', handleKeyUp);
}
return () => {
if (document) {
document.body.classList.remove('modal-open');
window.removeEventListener('keyup', handleKeyUp);
}
};
}, [ModalComponent, closeModal]);
const openModal = useCallback(
(name, props = {}, modalProps = INITIAL_STATE.modalProps) =>
dispatch({ type: 'OPEN_MODAL', payload: { name, props, modalProps } }),
[],
);
const getModalWrapper = () => {
if (!ModalComponent) return null;
const { modalProps } = state;
if (modalProps.customModal) {
return React.createElement(ModalComponent, { closeModal, ...state.props });
}
return (
<Modal data-testid="modal">
{!modalProps.hideCloseModalIcon && (
<ModalCloseIcon aria-label="Close modal" onClick={() => closeModal()}>
<AiFillCloseCircle color={state.props?.closerColor} />
</ModalCloseIcon>
)}
{React.createElement(ModalComponent, { ...state.props, closeModal })}
</Modal>
);
};
const ModalWrapper = getModalWrapper(state.modalProps);
const handleOverlayClick = useCallback(
(e) => {
if (e.target === e.currentTarget) closeModal();
},
[closeModal],
);
return (
<ModalContext.Provider value={{ state, openModal, closeModal }}>
{ModalWrapper && (
<ModalOverlay
onClick={state.modalProps.overlayClick ? handleOverlayClick : () => {}}
>
{ModalWrapper}
</ModalOverlay>
)}
{children}
</ModalContext.Provider>
);
}
Example #2
Source File: DragDrop.jsx From doc2pen with Creative Commons Zero v1.0 Universal | 4 votes |
function DragDrop(props) {
const {
files,
setFiles,
setInput,
setOutput,
input,
outputOptions,
setOutputOptions,
} = props;
const onDrop = useCallback(
acceptedFiles => {
const newFile = acceptedFiles.map(file => {
const fileType = file.type.split("/")[1];
acceptedFiles.length > 1 || files.length > 0
? setInput("Mix")
: setInput(fileType);
const index = outputOptions.indexOf(fileType);
if (index > -1 && fileType !== "pdf") {
const outputOptionsTemp = outputOptions;
outputOptionsTemp.splice(index, 1);
setOutputOptions(outputOptionsTemp);
}
if (fileType === "pdf") setOutputOptions(["pdf"]);
return Object.assign(file, {
preview: URL.createObjectURL(file),
});
});
setFiles(prevState => [...prevState, ...newFile]);
},
[setFiles, setInput, outputOptions, setOutputOptions],
);
const { getRootProps, getInputProps, isDragActive } = useDropzone({
accept: "image/*, application/pdf",
onDrop,
});
const deleteImage = path => {
setFiles(prevState => prevState.filter(file => file.path !== path));
if (input !== "Mix") {
setInput("Input");
setOutput("Output");
setOutputOptions(["png", "jpg", "webp", "jpeg", "pdf"]);
}
};
return (
<section className={styles.container}>
{files.length !== 0 && (
<div className={styles.container_image}>
{files.map(file => (
<div key={file.path} className={`${styles.image} ${styles.scroll}`}>
<img src={file.preview} alt="doc2pen" />
<span onClick={() => deleteImage(file.path)}>
<AiFillCloseCircle size={24} />
</span>
</div>
))}
</div>
)}
<div
{...getRootProps({ className: "dropzone" })}
className={styles.container_upload}
>
<input {...getInputProps()} />
{isDragActive ? (
<p>Drop the files here ...</p>
) : (
<p><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcToxjkIyrVIMesRK1InjzUOSvXHZqSbnunTKw&usqp=CAU" width={60} height={60}></img>
<p><span style={{ display:"block" ,fontWeight:"700", marginTop:"1rem"}}></span><strong>Drag file(s) here to upload.</strong></p>
<span style={{color:"#6a6b76"}} >
Alternatively, you can select a file by <br/> <span style={{color:"blue",}}><strong>clicking here</strong></span>
</span>
</p>
)}
</div>
</section>
);
}