webapp/src/components/Article/SharePopup.tsx

42 lines
1.1 KiB
TypeScript
Raw Normal View History

import type { PopupProps } from '../_shared/Popup'
2023-02-17 09:21:02 +00:00
import { createEffect, createSignal } from 'solid-js'
import { Popup } from '../_shared/Popup'
import { ShareLinks } from '../_shared/ShareLinks'
2022-10-25 15:36:32 +00:00
type SharePopupProps = {
title: string
shareUrl: string
imageUrl: string
description: string
onVisibilityChange?: (value: boolean) => void
} & 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) => {
const [isVisible, setIsVisible] = createSignal(false)
createEffect(() => {
if (props.onVisibilityChange) {
props.onVisibilityChange(isVisible())
}
})
2022-10-25 15:36:32 +00:00
return (
<Popup {...props} variant="bordered" onVisibilityChange={(value) => setIsVisible(value)}>
<ShareLinks
variant="inPopup"
title={props.title}
shareUrl={props.shareUrl}
imageUrl={props.imageUrl}
description={props.description}
/>
2022-10-25 15:36:32 +00:00
</Popup>
)
}