|
| 1 | +import React from "react"; |
| 2 | +import styled, { css } from "styled-components"; |
| 3 | + |
| 4 | +import Modal from "react-modal"; |
| 5 | + |
| 6 | +import { Button } from "@kleros/ui-components-library"; |
| 7 | + |
| 8 | +import WarningIcon from "svgs/icons/warning-outline.svg"; |
| 9 | + |
| 10 | +import { landscapeStyle } from "styles/landscapeStyle"; |
| 11 | + |
| 12 | +const StyledModal = styled(Modal)` |
| 13 | + position: absolute; |
| 14 | + top: 50%; |
| 15 | + left: 50%; |
| 16 | + right: auto; |
| 17 | + bottom: auto; |
| 18 | + margin-right: -50%; |
| 19 | + transform: translate(-50%, -50%); |
| 20 | + height: auto; |
| 21 | + max-height: 90vh; |
| 22 | + width: min(90%, 480px); |
| 23 | + border: 1px solid ${({ theme }) => theme.stroke}; |
| 24 | + border-radius: 8px; |
| 25 | + background-color: ${({ theme }) => theme.whiteBackground}; |
| 26 | + padding: 32px; |
| 27 | + box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); |
| 28 | + z-index: 10002; |
| 29 | + overflow-y: auto; |
| 30 | +`; |
| 31 | + |
| 32 | +const Overlay = styled.div` |
| 33 | + position: fixed; |
| 34 | + top: 0; |
| 35 | + left: 0; |
| 36 | + right: 0; |
| 37 | + bottom: 0; |
| 38 | + background-color: rgba(0, 0, 0, 0.5); |
| 39 | + z-index: 10001; |
| 40 | +`; |
| 41 | + |
| 42 | +const Header = styled.div` |
| 43 | + display: flex; |
| 44 | + align-items: center; |
| 45 | + gap: 12px; |
| 46 | + margin-bottom: 16px; |
| 47 | +`; |
| 48 | + |
| 49 | +const StyledWarningIcon = styled(WarningIcon)` |
| 50 | + width: 24px; |
| 51 | + height: 24px; |
| 52 | + fill: ${({ theme }) => theme.warning}; |
| 53 | +`; |
| 54 | + |
| 55 | +const Title = styled.h3` |
| 56 | + color: ${({ theme }) => theme.primaryText}; |
| 57 | + font-size: 18px; |
| 58 | + font-weight: 600; |
| 59 | + margin: 0; |
| 60 | +`; |
| 61 | + |
| 62 | +const Message = styled.p` |
| 63 | + color: ${({ theme }) => theme.primaryText}; |
| 64 | + font-size: 14px; |
| 65 | + line-height: 1.5; |
| 66 | + margin: 0 0 16px 0; |
| 67 | +`; |
| 68 | + |
| 69 | +const UrlContainer = styled.div` |
| 70 | + background-color: ${({ theme }) => theme.lightGrey}; |
| 71 | + border: 1px solid ${({ theme }) => theme.stroke}; |
| 72 | + border-radius: 4px; |
| 73 | + padding: 12px; |
| 74 | + margin: 16px 0; |
| 75 | + word-break: break-all; |
| 76 | +`; |
| 77 | + |
| 78 | +const Url = styled.code` |
| 79 | + color: ${({ theme }) => theme.secondaryText}; |
| 80 | + font-size: 13px; |
| 81 | + font-family: monospace; |
| 82 | +`; |
| 83 | + |
| 84 | +const ButtonContainer = styled.div` |
| 85 | + display: flex; |
| 86 | + gap: 12px; |
| 87 | + justify-content: center; |
| 88 | + flex-wrap: wrap; |
| 89 | + margin-top: 24px; |
| 90 | +
|
| 91 | + ${landscapeStyle( |
| 92 | + () => css` |
| 93 | + justify-content: flex-end; |
| 94 | + ` |
| 95 | + )} |
| 96 | +`; |
| 97 | + |
| 98 | +const CancelButton = styled(Button)` |
| 99 | + background-color: ${({ theme }) => theme.whiteBackground}; |
| 100 | + border: 1px solid ${({ theme }) => theme.stroke}; |
| 101 | +
|
| 102 | + p { |
| 103 | + color: ${({ theme }) => theme.primaryText} !important; |
| 104 | + } |
| 105 | +
|
| 106 | + &:hover { |
| 107 | + background-color: ${({ theme }) => theme.mediumBlue}; |
| 108 | + } |
| 109 | +`; |
| 110 | + |
| 111 | +const ConfirmButton = styled(Button)` |
| 112 | + background-color: ${({ theme }) => theme.warning}; |
| 113 | + color: ${({ theme }) => theme.whiteBackground}; |
| 114 | + border: 1px solid ${({ theme }) => theme.warning}; |
| 115 | +
|
| 116 | + &:hover { |
| 117 | + background-color: ${({ theme }) => theme.warning}BB; |
| 118 | + } |
| 119 | +`; |
| 120 | + |
| 121 | +interface IExternalLinkWarning { |
| 122 | + isOpen: boolean; |
| 123 | + url: string; |
| 124 | + onConfirm: () => void; |
| 125 | + onCancel: () => void; |
| 126 | +} |
| 127 | + |
| 128 | +const ExternalLinkWarning: React.FC<IExternalLinkWarning> = ({ isOpen, url, onConfirm, onCancel }) => { |
| 129 | + return ( |
| 130 | + <StyledModal |
| 131 | + isOpen={isOpen} |
| 132 | + onRequestClose={onCancel} |
| 133 | + overlayElement={(props, contentElement) => <Overlay {...props}>{contentElement}</Overlay>} |
| 134 | + ariaHideApp={false} |
| 135 | + role="dialog" |
| 136 | + aria-labelledby="external-link-title" |
| 137 | + aria-describedby="external-link-description" |
| 138 | + > |
| 139 | + <Header> |
| 140 | + <StyledWarningIcon /> |
| 141 | + <Title id="external-link-title">External Link Warning</Title> |
| 142 | + </Header> |
| 143 | + |
| 144 | + <Message id="external-link-description"> |
| 145 | + You are about to navigate to an external website. Please verify the URL before proceeding to ensure it's |
| 146 | + safe and legitimate. |
| 147 | + </Message> |
| 148 | + |
| 149 | + <UrlContainer> |
| 150 | + <Url>{url}</Url> |
| 151 | + </UrlContainer> |
| 152 | + |
| 153 | + <Message> |
| 154 | + <strong>Safety Tips:</strong> |
| 155 | + <br /> |
| 156 | + • Verify the domain name is correct |
| 157 | + <br /> |
| 158 | + • Check for suspicious characters or typos |
| 159 | + <br />• Only proceed if you trust this destination |
| 160 | + </Message> |
| 161 | + |
| 162 | + <ButtonContainer> |
| 163 | + <CancelButton text="Cancel" onClick={onCancel} /> |
| 164 | + <ConfirmButton text="Continue to External Site" onClick={onConfirm} /> |
| 165 | + </ButtonContainer> |
| 166 | + </StyledModal> |
| 167 | + ); |
| 168 | +}; |
| 169 | + |
| 170 | +export default ExternalLinkWarning; |
0 commit comments