This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor badges to component (#4479)
* fix: refactor badges to component * fix: refactored search to use new badge component * feat: profile use badge component * fix: remove comment
- Loading branch information
1 parent
7e07999
commit 9fb02a0
Showing
6 changed files
with
84 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Link from "./Link"; | ||
|
||
export default function Badge({ | ||
title, | ||
content, | ||
path, | ||
position, | ||
className, | ||
badgeClassName, | ||
children, | ||
display = true, | ||
onClick, | ||
}) { | ||
let css = ""; | ||
const cssTopRight = "top-0 right-0 bottom-auto left-auto"; | ||
const cssTopLeft = "top-0 left-0 bottom-auto right-auto"; | ||
const cssBottomRight = "bottom-0 right-0 top-auto left-auto"; | ||
const cssBottomLeft = "bottom-0 left-0 top-auto right-auto"; | ||
switch (position) { | ||
case "top-right": | ||
css = cssTopRight; | ||
break; | ||
case "top-left": | ||
css = cssTopLeft; | ||
break; | ||
case "bottom-right": | ||
css = cssBottomRight; | ||
break; | ||
case "bottom-left": | ||
css = cssBottomLeft; | ||
break; | ||
default: | ||
css = cssTopRight; | ||
} | ||
|
||
const badge = ( | ||
<div | ||
title={title} | ||
className={`absolute inline-block translate-x-2/4 -translate-y-1/2 rotate-0 skew-x-0 skew-y-0 scale-x-100 scale-y-100 py-1 px-1.5 text-xs leading-none text-center whitespace-nowrap align-baseline font-bold bg-orange-600 text-black rounded-full z-10 ${css} ${badgeClassName}`} | ||
onClick={() => (onClick ? onClick() : null)} | ||
> | ||
{content} | ||
</div> | ||
); | ||
|
||
let clickable; | ||
if (path) { | ||
clickable = <Link href={path}>{badge}</Link>; | ||
} | ||
|
||
return ( | ||
<div className={`inline-flex relative ${className ? className : "w-fit"}`}> | ||
{children} | ||
{display && (clickable ? clickable : badge)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters