import React, { Fragment } from 'react'; import styled, { css } from 'styled-components'; import * as tokens from '@tokens'; import { mq } from '@tokensDir/media-query'; import { dim } from '@dim'; import { NavigationObjectProps, NavigationObjectLink, LinkProps } from './interface'; import Title from './title'; import { Anchor, Body } from '../Typography'; const LinkSection = styled.div` grid-column: span 6; margin-bottom: ${dim(2)}; a { color: ${tokens.colorBlack}; display: block; margin-bottom: ${dim(0.5)}; text-decoration: none; &:hover { color: ${tokens.colorPink}; } } `; const LinkTitle = styled(Title)` padding-bottom: ${dim(1.5)}; `; const FooterLinks = styled.div` ${(props: { type: string }) => props.type === 'social' ? css` display: flex; ` : css` display: grid; grid-template-columns: 1fr 1fr; `} &.social-section { display: flex; justify-content: space-between; ${mq.md` column-count: auto; justify-content: normal; `} } `; const FooterLink = styled(Body)` ${(props: any) => props.type === 'social' ? css` margin: ${dim(1)} ${dim(4)} 0 0; ` : css` margin: ${dim(1)} 0; `} `; const FooterAnchor = styled(Anchor)` font-weight: ${tokens.fontWeightNormal}; margin-bottom: 0 !important; `; const isSocialLink = (url: string) => { const socialLinksRegEx = new RegExp(/twitter|facebook|instagram|youtube|vimeo/, 'g'); const stringResult = url.match(socialLinksRegEx); const imageSrc = stringResult ? `images/${stringResult[0]}.svg` : ''; return { valid: stringResult, src: imageSrc }; }; const Links: React.FC = ({ navigation = [] }) => ( {navigation.map((n: NavigationObjectLink, i: number) => ( {n.text} {n.links && n.links.map((l: LinkProps) => ( {isSocialLink(l.url).valid ? ( ) : ( l.title )} ))} ))} ); export default Links;