Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Tag coloring #81

Open
i99dev opened this issue Jan 24, 2023 · 3 comments
Open

feat:Tag coloring #81

i99dev opened this issue Jan 24, 2023 · 3 comments

Comments

@i99dev
Copy link
Contributor

i99dev commented Jan 24, 2023

before:
image
after:
image

@morethanmin
Copy link
Owner

It is very cool! can you tell me what color you used?

@i99dev
Copy link
Contributor Author

i99dev commented Jan 29, 2023

import { useRouter } from "next/router"
import React from "react"

type Props = {
  children: string
  tag_id: number
}

const Tag: React.FC<Props> = ({ children, tag_id }) => {
  const router = useRouter()
  const handleClick = (value: string) => {
    router.push(`/?tag=${value}`)
  }

  let arrayOfColors = [
    "bg-red-200",
    "bg-yellow-200",
    "bg-green-200",
    "bg-blue-200",
    "bg-indigo-200",
    "bg-purple-200",
    "bg-pink-200",
  ]

  return (
    <div
      onClick={() => handleClick(children)}
      className={`text-xs text-gray-800 font-normal rounded-full ${
        arrayOfColors[tag_id % arrayOfColors.length]
      } px-2 py-1 cursor-pointer`}
    >
      {children}
    </div>
  )
}

export default Tag

update : Tag.tsx

and next i pass props id on two file

PostCard.tsx

line 74

<Tag tag_id={idx}>{tag}</Tag>

PostHeader.tsx

after line 45

{data.tags.map((tag: string) => (
                  <Tag key={tag}>{tag}</Tag>
                ))}

will be

        {data.tags.map((tag: string, idx:number) => (
                  <Tag key={idx} tag_id={idx}>{tag}</Tag>
                ))}

and that's it 🎨👨‍💼🤖 :😎

i99dev added a commit to i99dev/morethan-log that referenced this issue Jan 29, 2023
@i99dev i99dev mentioned this issue Jan 29, 2023
2 tasks
@i99dev
Copy link
Contributor Author

i99dev commented Jan 29, 2023

i create new pull request for the tag

@uiw6unoh uiw6unoh mentioned this issue Apr 26, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants