From 276dfff2ba5fe7db8d85c2822781565354766fc2 Mon Sep 17 00:00:00 2001 From: Valtteri Karesto Date: Mon, 13 Dec 2021 17:23:09 +0200 Subject: [PATCH] Add link and log components --- components/Link.tsx | 8 +++ components/LogBox.tsx | 108 +++++++++++++++++++++++++++++++++++++++++ components/LogText.tsx | 3 ++ 3 files changed, 119 insertions(+) create mode 100644 components/Link.tsx create mode 100644 components/LogBox.tsx diff --git a/components/Link.tsx b/components/Link.tsx new file mode 100644 index 0000000..7c688d4 --- /dev/null +++ b/components/Link.tsx @@ -0,0 +1,8 @@ +import { styled } from "../stitches.config"; + +const StyledLink = styled("a", { + color: "CurrentColor", + textDecoration: "underline", +}); + +export default StyledLink; diff --git a/components/LogBox.tsx b/components/LogBox.tsx new file mode 100644 index 0000000..493e79e --- /dev/null +++ b/components/LogBox.tsx @@ -0,0 +1,108 @@ +import React, { useRef, useLayoutEffect } from "react"; +import { Notepad, Prohibit } from "phosphor-react"; +import useStayScrolled from "react-stay-scrolled"; +import NextLink from "next/link"; + +import Container from "./Container"; +import Box from "./Box"; +import Flex from "./Flex"; +import LogText from "./LogText"; +import { ILog } from "../state"; +import Text from "./Text"; +import Button from "./Button"; +import Heading from "./Heading"; +import Link from "./Link"; + +interface ILogBox { + title: string; + clearLog?: () => void; + logs: ILog[]; +} + +const LogBox: React.FC = ({ title, clearLog, logs, children }) => { + const logRef = useRef(null); + const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef); + + useLayoutEffect(() => { + stayScrolled(); + }, [stayScrolled, logs]); + + return ( + + + + + {title} + + + {clearLog && ( + + )} + + + + {logs?.map((log, index) => ( + + {/* + {log.type}:{" "} + */} + + {log.message}{" "} + {log.link && ( + + {log.linkText} + + )} + + + ))} + {children} + + + + ); +}; + +export default LogBox; diff --git a/components/LogText.tsx b/components/LogText.tsx index 3a70f1a..e485120 100644 --- a/components/LogText.tsx +++ b/components/LogText.tsx @@ -15,6 +15,9 @@ const Text = styled("span", { error: { color: "$red11", }, + success: { + color: "$green11", + }, }, capitalize: { true: {