Files
commafeed/commafeed-client/src/components/content/ShareButtons.tsx

63 lines
2.1 KiB
TypeScript
Raw Normal View History

import { ActionIcon, Box, SimpleGrid } from "@mantine/core"
2022-08-19 12:41:33 +02:00
import { Constants } from "app/constants"
import { useAppSelector } from "app/store"
2023-12-28 19:54:51 +01:00
import { type SharingSettings } from "app/types"
import { type IconType } from "react-icons"
import { tss } from "tss"
2022-08-19 12:41:33 +02:00
type Color = `#${string}`
const useStyles = tss
.withParams<{
color: Color
}>()
2023-12-29 23:09:30 +01:00
.create(({ theme, colorScheme, color }) => ({
socialIcon: {
color,
2023-12-29 23:09:30 +01:00
backgroundColor: colorScheme === "dark" ? theme.colors.gray[2] : "white",
borderRadius: "50%",
},
}))
2022-08-19 12:41:33 +02:00
function ShareButton({ url, icon, color }: { url: string; icon: IconType; color: Color }) {
const { classes } = useStyles({
color,
})
2022-08-19 12:41:33 +02:00
const onClick = (e: React.MouseEvent) => {
e.preventDefault()
window.open(url, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=800,height=600")
}
return (
2023-12-29 23:09:30 +01:00
<ActionIcon variant="transparent">
2022-08-19 12:41:33 +02:00
<a href={url} target="_blank" rel="noreferrer" onClick={onClick}>
2022-10-29 08:38:31 +02:00
<Box p={6} className={classes.socialIcon}>
2022-08-19 12:41:33 +02:00
{icon({ size: 18 })}
</Box>
</a>
</ActionIcon>
)
}
export function ShareButtons(props: { url: string; description: string }) {
const sharingSettings = useAppSelector(state => state.user.settings?.sharingSettings)
const url = encodeURIComponent(props.url)
const desc = encodeURIComponent(props.description)
return (
<SimpleGrid cols={4}>
{(Object.keys(Constants.sharing) as Array<keyof SharingSettings>)
2023-12-29 23:09:30 +01:00
.filter(site => sharingSettings?.[site])
2022-08-19 12:41:33 +02:00
.map(site => (
<ShareButton
key={site}
icon={Constants.sharing[site].icon}
color={Constants.sharing[site].color}
url={Constants.sharing[site].url(url, desc)}
/>
))}
</SimpleGrid>
)
}