Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable jsx-a11y/no-static-element-interactions */ import { css } from '@emotion/react'; import { color } from '@uniquegood/realworld-studio-design'; import React from 'react'; interface ModalData { title: string; content: string; onConfirm: () => void; } export function useModal() { const [isOpen, setIsOpen] = React.useState(false); const [data, setData] = React.useState<ModalData>(); const onCloseRef = React.useRef(() => { setIsOpen(false); }); const openModalWithAwait = React.useCallback( (data: ModalData) => new Promise((resolve) => { onCloseRef.current = () => { setIsOpen(false); resolve(true); }; setData(data); setIsOpen(true); }), [setData, setIsOpen] ); const modalProps = React.useMemo( () => ({ ...data, isOpen, onClose: onCloseRef.current }), [data, isOpen, setIsOpen] ); return { props: modalProps, openModalWithAwait }; } interface ModalProps { isOpen: boolean; onClose: () => void; onConfirm: () => void; title: string; content: string; } export function Modal({ isOpen, onClose, onConfirm, title, content }: ModalProps) { return isOpen ? ( <div css={modalWrapper}> <div css={backDrop} onClick={onClose}> <div css={modalBody} onClick={(e) => e.stopPropagation()}> <div css={textContainer}> <div css={titleStyle}>{title}</div> <div css={contentStyle}>{content}</div> </div> <div css={buttonContainer}> <button type="button" css={buttonDefault} onClick={onClose}> 취소 </button> <button type="button" css={buttonPrimary} onClick={onConfirm}> 확인 </button> </div> </div> </div> </div> ) : null; } const modalWrapper = css` position: absolute; display: flex; justify-content: center; align-items: center; padding: 0 8px; `; const backDrop = css` position: fixed; display: flex; justify-content: center; align-items: center; top: 0; right: 0; bottom: 0; left: 0; padding: 0 16px; background: rgba(0, 0, 0, 0.4); z-index: 100; `; const modalBody = css` max-width: min(327px, 90%); width: 100%; display: flex; flex-direction: column; gap: 24px; padding: 24px; background: #ffffff; border-radius: 24px; box-shadow: 0 10px 130px 0 rgba(0, 0, 0, 0.15), 0 4px 20px 0 rgba(0, 0, 0, 0.15); `; const textContainer = css` display: flex; flex-direction: column; gap: 16px; `; const titleStyle = css` color: #000; text-align: center; font-family: Noto Sans KR sans-serif; font-size: 21px; font-style: normal; font-weight: 700; line-height: 28px; `; const contentStyle = css` color: #000; text-align: center; font-family: Noto Sans KR sans-serif; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px; `; const buttonContainer = css` display: flex; gap: 8px; `; const button = css` width: 100%; border: none; margin: 0; border-radius: 30px; padding: 12px 16px; font-family: Noto Sans KR sans-serif; font-size: 16px; font-style: normal; font-weight: 500; line-height: 24px; `; const buttonDefault = css` ${button}; background: #ededed; color: black; `; const buttonPrimary = css` ${button}; background: ${color.palette_primary_purple_100}; color: white; `; |