owncast/webroot/js/components/social.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

import { h } from 'https://unpkg.com/preact?module';
import htm from 'https://unpkg.com/htm?module';
const html = htm.bind(h);
2020-08-24 05:06:58 +03:00
import { SOCIAL_PLATFORMS } from '../utils/social.js';
import { classNames } from '../utils/helpers.js';
2020-06-21 10:07:57 +03:00
2020-08-21 01:29:15 +03: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 10:07:57 +03:00
2020-08-21 01:29:15 +03:00
const name = inList ? platformInfo.name : platform;
2020-08-21 01:29:15 +03:00
const style = `--imgRow: -${imgRow}; --imgCol: -${imgCol};`;
const itemClass = classNames({
2020-08-21 01:29:15 +03:00
"user-social-item": true,
"flex": true,
"justify-start": true,
"items-center": true,
"-mr-1": true,
2020-08-21 01:29:15 +03:00
"use-default": !inList,
});
const labelClass = classNames({
2020-08-21 01:29:15 +03: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 01:29:15 +03: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 01:29:15 +03:00
<span class=${labelClass}>Find me on ${name}</span>
2020-06-21 11:31:08 +03:00
</a>
2020-08-21 01:29:15 +03:00
`);
}