diff --git a/src/components/Tag.tsx b/src/components/Tag.tsx index 4d0ae3665..3d2666746 100644 --- a/src/components/Tag.tsx +++ b/src/components/Tag.tsx @@ -1,36 +1,51 @@ +import { colors } from "../styles/colors" import styled from "@emotion/styled" import { useRouter } from "next/router" import React from "react" +const colorArray = [ + colors.light.red4, + colors.light.amber4, + colors.light.green4, + colors.light.blue4, + colors.light.indigo4, + colors.light.purple4, + colors.light.pink4, +] + type Props = { children: string } +const hashStringToColor = (str: string, colorsArray: string[]) => { + let hash = 0 + for (let i = 0; i < str.length; i++) { + hash = str.charCodeAt(i) + ((hash << 5) - hash) + } + const index = Math.abs(hash) % colorsArray.length + + return colorsArray[index] +} + const Tag: React.FC = ({ children }) => { const router = useRouter() const handleClick = (value: string) => { router.push(`/?tag=${value}`) } - return ( - handleClick(children)}> - {children} - - ) + + const StyledTag = styled.div` + background-color: ${hashStringToColor(children, colorArray)}; + color: ${colors.light.gray10}; + padding: 0.25rem 0.5rem; + border-radius: 50px; + font-size: 0.75rem; + line-height: 1rem; + font-weight: 400; + cursor: pointer; + ` + + return handleClick(children)}>{children} } export default Tag - -const StyledWrapper = styled.div` - padding-top: 0.25rem; - padding-bottom: 0.25rem; - padding-left: 0.5rem; - padding-right: 0.5rem; - border-radius: 50px; - font-size: 0.75rem; - line-height: 1rem; - font-weight: 400; - color: ${({ theme }) => theme.colors.gray10}; - background-color: ${({ theme }) => theme.colors.gray5}; - cursor: pointer; -` diff --git a/src/routes/Detail/PostDetail/PostHeader.tsx b/src/routes/Detail/PostDetail/PostHeader.tsx index 85485f4c9..3e7cfe31a 100644 --- a/src/routes/Detail/PostDetail/PostHeader.tsx +++ b/src/routes/Detail/PostDetail/PostHeader.tsx @@ -42,9 +42,10 @@ const PostHeader: React.FC = ({ data }) => {
{data.tags && (
- {data.tags.map((tag: string) => ( - {tag} - ))} + {data.tags && + data.tags.map((tag: string, idx: number) => ( + {tag} + ))}
)}
diff --git a/src/routes/Feed/PostList/PostCard.tsx b/src/routes/Feed/PostList/PostCard.tsx index 7673e161c..6fd66309c 100644 --- a/src/routes/Feed/PostList/PostCard.tsx +++ b/src/routes/Feed/PostList/PostCard.tsx @@ -32,7 +32,11 @@ const PostCard: React.FC = ({ data }) => { /> )} -
+

{data.title}

diff --git a/src/styles/colors.ts b/src/styles/colors.ts index 4dfbce217..6f5156917 100644 --- a/src/styles/colors.ts +++ b/src/styles/colors.ts @@ -9,6 +9,14 @@ import { greenDark, indigo, indigoDark, + amber, + amberDark, + grayA, + grayDarkA, + purple, + purpleDark, + pink, + pinkDark, } from "@radix-ui/colors" export type Colors = typeof colors.light & typeof colors.dark @@ -20,6 +28,10 @@ export const colors = { ...blue, ...red, ...green, + ...amber, + ...grayA, + ...purple, + ...pink, }, dark: { ...indigoDark, @@ -27,5 +39,9 @@ export const colors = { ...blueDark, ...redDark, ...greenDark, + ...amberDark, + ...grayDarkA, + ...purpleDark, + ...pinkDark, }, }