2023-11-14 15:10:00 +00:00
|
|
|
import type { PopupProps } from '../_shared/Popup'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-05-17 04:04:38 +00:00
|
|
|
import { createEffect, createSignal } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
|
|
|
import { Popup } from '../_shared/Popup'
|
2024-01-05 19:31:28 +00:00
|
|
|
import { ShareLinks } from '../_shared/ShareLinks'
|
2022-10-25 15:36:32 +00:00
|
|
|
|
2023-01-30 10:39:36 +00:00
|
|
|
type SharePopupProps = {
|
|
|
|
title: string
|
2024-01-05 19:31:28 +00:00
|
|
|
shareUrl: string
|
2023-01-30 10:39:36 +00:00
|
|
|
imageUrl: string
|
|
|
|
description: string
|
2023-12-29 11:07:48 +00:00
|
|
|
onVisibilityChange?: (value: boolean) => void
|
2023-01-30 10:39:36 +00:00
|
|
|
} & Omit<PopupProps, 'children'>
|
2022-10-25 15:36:32 +00:00
|
|
|
|
2023-01-31 13:58:28 +00:00
|
|
|
export const getShareUrl = (params: { pathname?: string } = {}) => {
|
|
|
|
if (typeof location === 'undefined') return ''
|
|
|
|
const pathname = params.pathname ?? location.pathname
|
|
|
|
return location.origin + pathname
|
|
|
|
}
|
|
|
|
|
2022-10-25 15:36:32 +00:00
|
|
|
export const SharePopup = (props: SharePopupProps) => {
|
2023-05-17 04:04:38 +00:00
|
|
|
const [isVisible, setIsVisible] = createSignal(false)
|
|
|
|
createEffect(() => {
|
2023-12-29 11:07:48 +00:00
|
|
|
if (props.onVisibilityChange) {
|
|
|
|
props.onVisibilityChange(isVisible())
|
2023-05-17 04:04:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-25 15:36:32 +00:00
|
|
|
return (
|
2023-05-17 04:04:38 +00:00
|
|
|
<Popup {...props} variant="bordered" onVisibilityChange={(value) => setIsVisible(value)}>
|
2024-01-05 19:31:28 +00:00
|
|
|
<ShareLinks
|
|
|
|
variant="inPopup"
|
|
|
|
title={props.title}
|
|
|
|
shareUrl={props.shareUrl}
|
|
|
|
imageUrl={props.imageUrl}
|
|
|
|
description={props.description}
|
|
|
|
/>
|
2022-10-25 15:36:32 +00:00
|
|
|
</Popup>
|
|
|
|
)
|
|
|
|
}
|