-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from duyet/chore/update
feat: add /common-errors, colored-badge-format
- Loading branch information
Showing
7 changed files
with
200 additions
and
15 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
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
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,43 @@ | ||
import { cn } from '@/lib/utils' | ||
|
||
interface ColoredBadgeFormatProps { | ||
value: any | ||
className?: string | ||
} | ||
|
||
export function ColoredBadgeFormat({ | ||
value, | ||
className, | ||
}: ColoredBadgeFormatProps) { | ||
const colors = [ | ||
'bg-green-100 text-green-800', | ||
'bg-yellow-100 text-yellow-800', | ||
'bg-blue-100 text-blue-800', | ||
'bg-indigo-100 text-indigo-800', | ||
'bg-purple-100 text-purple-800', | ||
'bg-pink-100 text-pink-800', | ||
] | ||
|
||
// Picked consistently based on the value | ||
const pickedColor = | ||
colors[ | ||
Math.abs( | ||
value | ||
.toString() | ||
.split('') | ||
.reduce((acc: number, char: string) => acc + char.charCodeAt(0), 0) | ||
) % colors.length | ||
] | ||
|
||
return ( | ||
<span | ||
className={cn( | ||
'inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium', | ||
pickedColor, | ||
className | ||
)} | ||
> | ||
{value} | ||
</span> | ||
) | ||
} |
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