-
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.
- Loading branch information
Showing
17 changed files
with
173 additions
and
38 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,5 @@ | ||
--- | ||
"namesake": minor | ||
--- | ||
|
||
Display readability score alongside quest content editor |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { ReadingScore } from "./ReadingScore"; | ||
|
||
const meta = { | ||
component: ReadingScore, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
} satisfies Meta<typeof ReadingScore>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
text: "Playing games has always been thought to be important to the development of well-balanced and creative children; however, what part, if any, they should play in the lives of adults has never been researched that deeply. I believe that playing games is every bit as important for adults as for children. Not only is taking time out to play games with our children and other adults valuable to building interpersonal relationships but is also a wonderful way to release built up tension.", | ||
}, | ||
}; |
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 { | ||
RiEmotionHappyFill, | ||
RiEmotionNormalFill, | ||
RiEmotionUnhappyFill, | ||
} from "@remixicon/react"; | ||
import rs from "text-readability"; | ||
import { Badge } from "../Badge"; | ||
|
||
/** | ||
* A badge that displays a grade-level readability score of a given text. | ||
*/ | ||
export interface ReadingScoreProps { | ||
/** | ||
* The text to calculate the readability score for. | ||
*/ | ||
text: string; | ||
/** | ||
* The minimum length of the text to calculate the score. | ||
* @default 280 | ||
*/ | ||
minLength?: number; | ||
} | ||
|
||
export const ReadingScore = ({ text, minLength = 280 }: ReadingScoreProps) => { | ||
if (!text || text.length < minLength) return null; | ||
|
||
const score = rs.daleChallReadabilityScore(text); | ||
|
||
if (!score) return null; | ||
|
||
const variant = score >= 8 ? "danger" : score >= 6 ? "warning" : "success"; | ||
const icon = | ||
score >= 8 | ||
? RiEmotionUnhappyFill | ||
: score >= 6 | ||
? RiEmotionNormalFill | ||
: RiEmotionHappyFill; | ||
|
||
const readingLevel = (score: number) => { | ||
if (score >= 9) return "College"; | ||
if (score >= 8) return "11th–12th grade"; | ||
if (score >= 7) return "9th–10th grade"; | ||
if (score >= 6) return "7th–8th grade"; | ||
if (score >= 5) return "5th–6th grade"; | ||
if (score > 0) return "4th grade or lower"; | ||
return "Unknown"; | ||
}; | ||
|
||
return ( | ||
<Badge icon={icon} variant={variant}> | ||
<span> | ||
<span>{readingLevel(score)} </span> | ||
<span className="opacity-60">reading level</span> | ||
</span> | ||
</Badge> | ||
); | ||
}; |
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 @@ | ||
export * from "./ReadingScore"; |
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
Oops, something went wrong.