owncast/webroot/js/social.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-08-21 00:29:15 +02:00
import { html } from "https://unpkg.com/htm/preact/index.mjs?module";
import { SOCIAL_PLATFORMS } from './utils/social.js';
import { classNames } from './utils.js';
2020-06-21 09:07:57 +02:00
2020-08-21 00:29:15 +02:00
export default function SocialIcon(props) {
const { platform, url } = props;
const platformInfo = SOCIAL_PLATFORMS[platform.toLowerCase()];
const inList = !!platformInfo;
const imgRow = inList ? platformInfo.imgPos[0] : 0;
const imgCol = inList ? platformInfo.imgPos[1] : 0;
2020-06-21 09:07:57 +02:00
2020-08-21 00:29:15 +02:00
const name = inList ? platformInfo.name : platform;
2020-08-21 00:29:15 +02:00
const style = `--imgRow: -${imgRow}; --imgCol: -${imgCol};`;
const itemClass = classNames({
2020-08-21 00:29:15 +02:00
"user-social-item": true,
"flex": true,
"justify-start": true,
"items-center": true,
"-mr-1": true,
2020-08-21 00:29:15 +02:00
"use-default": !inList,
});
const labelClass = classNames({
2020-08-21 00:29:15 +02:00
"platform-label": true,
"visually-hidden": inList,
"text-indigo-800": true,
"text-xs": true,
"uppercase": true,
"max-w-xs": true,
"inline-block": true,
});
2020-08-21 00:29:15 +02:00
return (
html`
<a class=${itemClass} target="_blank" href=${url}>
<span class="platform-icon rounded-lg bg-no-repeat" style=${style}></span>
2020-08-21 00:29:15 +02:00
<span class=${labelClass}>Find me on ${name}</span>
2020-06-21 10:31:08 +02:00
</a>
2020-08-21 00:29:15 +02:00
`);
}