({
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
beforeOnClick,
children,
className,
disabled,
disabledStyle = { opacity: 0.6 },
forwardedRef,
htmlTitle,
networkLink,
networkName, // deconstructed from ...rest to prevent passing it to the button element
onClick,
onShareWindowClose,
openShareDialogOnClick = true,
opts,
resetButtonStyle = true,
style,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
title, // deconstructed from ...rest to prevent passing it to the button element
type = 'button',
url,
windowHeight = 400,
windowPosition = 'windowCenter',
windowWidth = 550,
...rest
}: Props<LinkOptions>)
| 181 | >; |
| 182 | |
| 183 | export default function ShareButton<LinkOptions extends Record<string, unknown>>({ |
| 184 | 'aria-label': ariaLabel, |
| 185 | 'aria-labelledby': ariaLabelledBy, |
| 186 | beforeOnClick, |
| 187 | children, |
| 188 | className, |
| 189 | disabled, |
| 190 | disabledStyle = { opacity: 0.6 }, |
| 191 | forwardedRef, |
| 192 | htmlTitle, |
| 193 | networkLink, |
| 194 | networkName, // deconstructed from ...rest to prevent passing it to the button element |
| 195 | onClick, |
| 196 | onShareWindowClose, |
| 197 | openShareDialogOnClick = true, |
| 198 | opts, |
| 199 | resetButtonStyle = true, |
| 200 | style, |
| 201 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 202 | title, // deconstructed from ...rest to prevent passing it to the button element |
| 203 | type = 'button', |
| 204 | url, |
| 205 | windowHeight = 400, |
| 206 | windowPosition = 'windowCenter', |
| 207 | windowWidth = 550, |
| 208 | ...rest |
| 209 | }: Props<LinkOptions>) { |
| 210 | const buttonBorderRadius = getButtonBorderRadius(children); |
| 211 | const fallbackAriaLabel = |
| 212 | !ariaLabel && !ariaLabelledBy && !hasTextContent(children) |
| 213 | ? DEFAULT_ARIA_LABELS[networkName as keyof typeof DEFAULT_ARIA_LABELS] |
| 214 | : undefined; |
| 215 | |
| 216 | const handleClick = async (event: React.MouseEvent<HTMLButtonElement>) => { |
| 217 | if (disabled) { |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | const link = networkLink(url, opts); |
| 222 | |
| 223 | event.preventDefault(); |
| 224 | |
| 225 | if (beforeOnClick) { |
| 226 | const returnVal = beforeOnClick(); |
| 227 | |
| 228 | if (isPromise(returnVal)) { |
| 229 | await returnVal; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if (openShareDialogOnClick) { |
| 234 | const windowConfig = { |
| 235 | height: windowHeight, |
| 236 | width: windowWidth, |
| 237 | ...(windowPosition === 'windowCenter' |
| 238 | ? getBoxPositionOnWindowCenter(windowWidth, windowHeight) |
| 239 | : getBoxPositionOnScreenCenter(windowWidth, windowHeight)), |
| 240 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…