@@ -23,6 +23,7 @@ In its basic implementation `useModal` lets you manage multiple modals in page i
2323 - [ Alternative] ( #alternative )
2424 - [ Partial config update] ( #update-current-config-partially )
2525 - [ Decoupled logic] ( #decoupled-logic )
26+ - [ Modal Component] ( #modal-component-coming-soon )
2627- [ API] ( #api )
2728 - [ Properties and methods] ( #properties-and-methods )
2829 - [ Hook configuration / Modal props] ( #hook-configuration--modal-props )
@@ -207,6 +208,145 @@ Here yoy can see an example of `useModal` usage with non-empty initial configura
207208
208209> _Alternative usage: config through hook inital config, modal shown with ` showModal` , rewritten ` buttons` and ` children` Modal props_.
209210
211+ ## Modal Component (coming soon)
212+
213+ At the moment we **don't provide** the ` Modal component` . The hook provides config and functions, you are supposed to adjust your Modal component to them. Soon we will provide an official Modal too. In the meantime you can find below an example of how we implemented the Modal for the examples seen in this doc.
214+
215+ ` ` ` tsx
216+ // Modal.tsx
217+
218+ import { ModalProps } from " react-use-modal" ;
219+ import styles from " ./Modal.module.css" ;
220+
221+ export const Modal = ({
222+ open,
223+ title,
224+ children,
225+ handleClose,
226+ showCloseIcon,
227+ buttons,
228+ }: ModalProps) => {
229+ return open ? (
230+ <>
231+ < div className= {styles .modalBody }>
232+ {showCloseIcon && (
233+ < div className= {styles .close } onClick= {handleClose}>< / div>
234+ )}
235+ < div className= {styles .title }> {title}< / div>
236+ < div className= {styles .message }> {children}< / div>
237+
238+ < ModalActions handleClose= {handleClose} buttons= {buttons} / >
239+ < / div>
240+ < div className= {styles .overlay } onClick= {handleClose}>< / div>
241+ < / >
242+ ) : null ;
243+ };
244+ ` ` `
245+
246+ ` ` ` tsx
247+ // ModalActions.tsx
248+
249+ import { ModalProps } from " react-use-modal" ;
250+ import styles from " ./Modal.module.css" ;
251+
252+ export const ModalActions = ({
253+ buttons,
254+ handleClose,
255+ }: Pick< ModalProps, " buttons" | " handleClose" > ) => (
256+ < div className= {styles .actions }>
257+ {buttons? .map (({ text, disableClose, disabled, onClick, style }, idx ) => {
258+ const handleClick = () => {
259+ ! disabled && onClick? .();
260+ if (! disableClose) handleClose ();
261+ };
262+ return (
263+ < div
264+ key= {idx}
265+ onClick= {handleClick}
266+ className= {styles .btn }
267+ style= {style}
268+ >
269+ {text}
270+ < / div>
271+ );
272+ })}
273+ < / div>
274+ );
275+ ` ` `
276+
277+ <details>
278+ <summary>See CSS Code</summary>
279+
280+ ` ` ` css
281+ /* Modal.module.css */
282+
283+ .overlay {
284+ position: absolute;
285+ z- index: 1 ;
286+ width: 100 % ;
287+ height: 100vh ;
288+ left: 0 ;
289+ top: 0 ;
290+ background- color: rgba (0 , 0 , 0 , 0.6 );
291+ }
292+
293+ .modalBody {
294+ position: absolute;
295+ min- width: 300px ;
296+ max- width: 500px ;
297+ min- height: 100px ;
298+ left: 50 % ;
299+ top: 50 % ;
300+ transform: translate (- 50 % , - 50 % );
301+ background- color: white;
302+ border- radius: 10px ;
303+ z- index: 2 ;
304+ box- shadow: 0px 5px 20px rgba (0 , 0 , 0 , 0.5 );
305+ padding: 15px ;
306+ }
307+
308+ .title {
309+ font- weight: bold;
310+ margin- top: 20px ;
311+ font- size: 22px ;
312+ }
313+
314+ .message {
315+ margin: 20px ;
316+ font- size: 16px ;
317+ }
318+
319+ .close : after {
320+ position: absolute;
321+ right: 20px ;
322+ top: 10px ;
323+ line- height: 1em ;
324+ font- size: 40px ;
325+ display: block;
326+ content: " \00 d7" ;
327+ cursor: pointer;
328+ }
329+
330+ .actions {
331+ display: flex;
332+ justify- content: center;
333+ gap: 10px ;
334+ margin- top: 30px ;
335+ margin- bottom: 10px ;
336+ }
337+
338+ .btn {
339+ padding: 8px ;
340+ border- radius: 6px ;
341+ border: 1px solid grey;
342+ text- align: center;
343+ min- width: 80px ;
344+ cursor: pointer;
345+ }
346+ ` ` `
347+
348+ </details>
349+
210350## API
211351
212352### Properties and methods
0 commit comments