diff options
Diffstat (limited to 'frontend/components')
| -rw-r--r-- | frontend/components/Marquees/Marquee.module.css | 38 | ||||
| -rw-r--r-- | frontend/components/Marquees/Marquee.tsx | 20 | ||||
| -rw-r--r-- | frontend/components/Marquees/Marquees.tsx | 35 |
3 files changed, 93 insertions, 0 deletions
diff --git a/frontend/components/Marquees/Marquee.module.css b/frontend/components/Marquees/Marquee.module.css new file mode 100644 index 0000000..0fb8ece --- /dev/null +++ b/frontend/components/Marquees/Marquee.module.css @@ -0,0 +1,38 @@ +.marqueeContainer { + height: 100vh; + overflow: hidden; + position: relative; + background: #fefefe; + color: #333; + z-index: 10; +} + +.marquee { + position: absolute; + width: 100%; + height: 50px; + margin: 0; + line-height: 50px; + text-align: center; + transform: translateX(100%); + animation: scroll-left 10s linear infinite; + text-decoration: underline; +} + +@keyframes scroll-left { + 0% { + transform: translateX(100%); + } + 100% { + transform: translateX(-100%); + } +} + +@keyframes scroll-right { + 0% { + transform: translateX(-100%); + } + 100% { + transform: translateX(100%); + } +} diff --git a/frontend/components/Marquees/Marquee.tsx b/frontend/components/Marquees/Marquee.tsx new file mode 100644 index 0000000..4cc41a2 --- /dev/null +++ b/frontend/components/Marquees/Marquee.tsx @@ -0,0 +1,20 @@ +import React, { ReactElement } from "react"; +import styles from "./Marquee.module.css"; + +interface Props { + delayShorthand: string; + topShorthand: string; + url: string; + text: string; + direction: "left" | "right"; +} + +const Marquee = ({ delayShorthand, url, text, topShorthand, direction }: Props): ReactElement => ( + <a className={styles.marquee} href={url} style={{ + animationDelay: delayShorthand, + top: topShorthand, + animationDirection: direction === "left" ? "normal" : "reverse", + }}>{text}</a> +); + +export default Marquee; diff --git a/frontend/components/Marquees/Marquees.tsx b/frontend/components/Marquees/Marquees.tsx new file mode 100644 index 0000000..04747fb --- /dev/null +++ b/frontend/components/Marquees/Marquees.tsx @@ -0,0 +1,35 @@ +import React, { ReactElement } from "react"; +import styles from "./Marquee.module.css"; +import Marquee from "./Marquee"; + +export interface MarqueeLink { + title: string; + url: string; +} + +interface Props { + links: MarqueeLink[] +} + +const getRandomDelayBetween = (start: number, end: number) => `${Math.random() * (end - start) + start}s`; +const getTopFromIndex = (index: number, n: number) => `calc((100% - 50px) * (${index} / ${n - 1}))`; +const getRandomAnimationName = () => Math.random() > 0.5 ? "right" : "left"; + +const Marquees = ({ links }: Props): ReactElement => { + return ( + <div className={styles.marqueeContainer}> + { links.map((link, idx) => ( + <Marquee + key={idx} + url={link.url} + text={link.title} + delayShorthand={getRandomDelayBetween(0, 9)} + topShorthand={getTopFromIndex(idx, links.length)} + direction={getRandomAnimationName()} + /> + ))} + </div> + ); +}; + +export default Marquees; |
