2020-10-05 04:43:31 +03:00
|
|
|
import { h } from '/js/web_modules/preact.js';
|
|
|
|
import htm from '/js/web_modules/htm.js';
|
2020-08-24 07:41:02 +03:00
|
|
|
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-06-30 12:36:10 +03:00
|
|
|
|
2020-08-21 01:29:15 +03:00
|
|
|
const style = `--imgRow: -${imgRow}; --imgCol: -${imgCol};`;
|
2020-08-22 09:44:10 +03:00
|
|
|
const itemClass = classNames({
|
2020-08-21 01:29:15 +03:00
|
|
|
"user-social-item": true,
|
|
|
|
"flex": true,
|
2020-08-22 09:44:10 +03:00
|
|
|
"justify-start": true,
|
|
|
|
"items-center": true,
|
|
|
|
"-mr-1": true,
|
2020-08-21 01:29:15 +03:00
|
|
|
"use-default": !inList,
|
2020-08-22 09:44:10 +03:00
|
|
|
});
|
|
|
|
const labelClass = classNames({
|
2020-08-21 01:29:15 +03:00
|
|
|
"platform-label": true,
|
|
|
|
"visually-hidden": inList,
|
|
|
|
"text-indigo-800": true,
|
2020-08-22 09:44:10 +03:00
|
|
|
"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}>
|
2020-08-22 09:44:10 +03:00
|
|
|
<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
|
|
|
`);
|
|
|
|
}
|