-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing a condensed version of JSR link
- Loading branch information
Showing
10 changed files
with
364 additions
and
172 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,32 @@ | ||
import { PackageDetailsResult } from "../../hooks/use-jsr-client.ts"; | ||
|
||
export function CircleScore({ details }: { details: PackageDetailsResult }) { | ||
return ( | ||
<> | ||
<h3 class="text-2xl flex justify-center"> | ||
<img src="/assets/images/jsr-logo.svg" alt="JSR Logo" class="mr-2" /> | ||
Score | ||
</h3> | ||
<div | ||
class={`h-32 w-32 justify-center aspect-square rounded-full p-1.5 ${getScoreBgColorClass( | ||
details.score, | ||
)}`} | ||
style="background-image: conic-gradient(transparent, transparent 100%, #e7e8e8 100%)" | ||
> | ||
<span class="rounded-full w-full h-full bg-white flex justify-center items-center text-center text-3xl font-bold"> | ||
{details.score}% | ||
</span> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
/** @src https://github.com/jsr-io/jsr/blob/34603e996f56eb38e811619f8aebc6e5c4ad9fa7/frontend/utils/score_ring_color.ts */ | ||
export function getScoreBgColorClass(score: number): string { | ||
if (score >= 90) { | ||
return "bg-green-500"; | ||
} else if (score >= 60) { | ||
return "bg-yellow-500"; | ||
} | ||
return "bg-red-500"; | ||
} |
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,4 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" stroke="currentColor" fill="none" | ||
viewBox="0 0 24 24"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path> | ||
</svg> |
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,38 @@ | ||
// @ts-nocheck Property 'svg' does not exist on type 'JSX.IntrinsicElements'. | ||
|
||
export function Check() { | ||
return ( | ||
<svg | ||
class="h-6 stroke-green-500 stroke-2 -mt-px" | ||
aria-hidden="true" | ||
viewBox="0 0 24 24" | ||
stroke-width="2" | ||
stroke="currentColor" | ||
fill="none" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
> | ||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> | ||
<path d="M5 12l5 5l10 -10"></path> | ||
</svg> | ||
); | ||
} | ||
|
||
export function Cross() { | ||
return ( | ||
<svg | ||
class="h-6 stroke-red-500 stroke-2 -mt-px" | ||
aria-hidden="true" | ||
stroke="currentColor" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M6 18L18 6M6 6l12 12" | ||
></path> | ||
</svg> | ||
); | ||
} |
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,128 @@ | ||
import { Package, usePackage } from "../hooks/use-package.tsx"; | ||
import { | ||
PackageDetailsResult, | ||
type PackageScoreResult, | ||
} from "../hooks/use-jsr-client.ts"; | ||
import { Check, Cross } from "./package/icons.tsx"; | ||
|
||
export function ScoreCard() { | ||
return function* () { | ||
const pkg = yield* usePackage(); | ||
const [details, score] = yield* pkg.jsrPackageDetails(); | ||
|
||
return ( | ||
<div class="flex flex-col items-center space-y-5 w-full border-2 border-cyan-100 rounded-lg p-8"> | ||
{details.success && details.data ? ( | ||
<> | ||
<a class="flex text-lg space-x-2 font-semibold" href={`${pkg.jsr}`}> | ||
<span>Available on</span> | ||
<img | ||
src="/assets/images/jsr-logo.svg" | ||
alt="JSR Logo" | ||
class="mr-2" | ||
/> | ||
</a> | ||
<div class="flex flex-col md:flex-row gap-2 md:gap-8 items-between"> | ||
<div class="flex flex-row md:flex-col items-center md:items-end gap-2 md:gap-1.5 text-sm font-bold"> | ||
<div aria-hidden="true">Works with</div> | ||
<div class="min-w-content font-semibold select-none"> | ||
<div class="flex items-center *:mx-0.5 flex-row-reverse"></div> | ||
</div> | ||
</div> | ||
<a class="flex flex-row md:flex-col items-baseline md:items-end gap-2 md:gap-1.5 text-sm font-bold" | ||
href={`${new URL('./score/', pkg.jsr)}`} | ||
> | ||
<div>JSR Score</div> | ||
<div | ||
class={`!leading-none md:text-xl ${getScoreTextColorClass(details.data.score)}`} | ||
> | ||
{details.data.score}% | ||
</div> | ||
</a> | ||
</div> | ||
{score.success && score.data ? ( | ||
<ScoreDescription score={score.data} pkg={pkg} /> | ||
) : ( | ||
<></> | ||
)} | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
function ScoreDescription({ | ||
score, | ||
pkg, | ||
}: { | ||
score: PackageScoreResult; | ||
pkg: Package; | ||
}) { | ||
const { | ||
percentageDocumentedSymbols: _percentageDocumentedSymbols, | ||
total: _total, | ||
...flags | ||
} = score; | ||
|
||
const SCORE_MAP = { | ||
hasReadme: "Has a readme or module doc", | ||
hasReadmeExamples: "Has examples in the readme or module doc", | ||
allEntrypointsDocs: "Has module docs in all entrypoints", | ||
allFastCheck: ( | ||
<> | ||
No{" "} | ||
<a class="underline" href="https://jsr.io/docs/about-slow-types"> | ||
slow types | ||
</a>{" "} | ||
are used | ||
</> | ||
), | ||
hasProvenance: "Has provenance", | ||
hasDescription: ( | ||
<> | ||
Has a{" "} | ||
<a | ||
class="underline" | ||
href={`${new URL("./settings#description", pkg.jsr)}`} | ||
> | ||
description | ||
</a> | ||
</> | ||
), | ||
atLeastOneRuntimeCompatible: "At least one runtime is marked as compatible", | ||
multipleRuntimesCompatible: | ||
"At least two runtimes are marked as compatible", | ||
}; | ||
|
||
return ( | ||
<details> | ||
<summary class="text-gray-500 text-sm"> | ||
The JSR score is a measure of the overall quality of a package, expand | ||
for more detail. | ||
</summary> | ||
<ul class="flex flex-col divide-y-1 w-full pt-5 px-2"> | ||
<> | ||
{Object.entries(flags).map(([key, value]) => ( | ||
<li class="grid grid-cols-[auto_1fr_auto] gap-x-3 py-3 first:pt-0 items-start"> | ||
{value ? <Check /> : <Cross />} | ||
<span>{SCORE_MAP[key as keyof typeof flags]}</span> | ||
</li> | ||
))} | ||
</> | ||
</ul> | ||
</details> | ||
); | ||
} | ||
|
||
/** @src https://github.com/jsr-io/jsr/blob/34603e996f56eb38e811619f8aebc6e5c4ad9fa7/frontend/utils/score_ring_color.ts */ | ||
export function getScoreTextColorClass(score: number): string { | ||
if (score >= 90) { | ||
return "text-green-600"; | ||
} else if (score >= 60) { | ||
return "text-yellow-700"; | ||
} | ||
return "text-red-500"; | ||
} |
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
Oops, something went wrong.