Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/option-label/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { OptionLabel } from "./option-label";
export type { OptionLabelProps } from "./types";
20 changes: 20 additions & 0 deletions src/option-label/option-label.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import { StoryFn } from "@storybook/react";
import { OptionLabel, OptionLabelProps } from ".";

const story = {
title: "components/OptionLabel",
component: OptionLabel,
};

const Template: StoryFn<OptionLabelProps> = (args) => {
return <OptionLabel {...args} />;
};

export const Default = Template.bind({});
Default.args = {
// default props go here
questionText: "What is the capital of France?",
};

export default story;
14 changes: 14 additions & 0 deletions src/option-label/option-label.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { render, screen } from "@testing-library/react";

import { OptionLabel } from ".";

describe("<OptionLabel />", () => {
it("should render correctly", () => {
const questionText = "What is the capital of France?";
render(<OptionLabel questionText={questionText} />);

const questionElement = screen.getByText(questionText);
expect(questionElement).toBeInTheDocument();
});
});
20 changes: 20 additions & 0 deletions src/option-label/option-label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";

import { OptionLabelProps } from "./types";
import { PrismFormatted } from "../prism-formatted";

export const OptionLabel = (props: OptionLabelProps) => {
const removeParagraphTags = (text: string) => {
// Remove <p> and </p> tags from the text
return text.replace(/<\/?p>/g, "");
};

return (
<PrismFormatted
text={removeParagraphTags(props.questionText)}
useSpan
noAria
getCodeBlockAriaLabel={() => ""}
/>
);
};
3 changes: 3 additions & 0 deletions src/option-label/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface OptionLabelProps {
questionText: string;
}
2 changes: 2 additions & 0 deletions src/question-label/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { QuestionLabel } from "./question-label";
export type { QuestionLabelProps } from "./types";
20 changes: 20 additions & 0 deletions src/question-label/question-label.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import { StoryFn } from "@storybook/react";
import { QuestionLabel, QuestionLabelProps } from ".";

const story = {
title: "components/QuestionLabel",
component: QuestionLabel,
};

const Template: StoryFn<QuestionLabelProps> = (args) => {
return <QuestionLabel {...args} />;
};

export const Default = Template.bind({});
Default.args = {
// default props go here
question: "What is the capital of France?",
};

export default story;
14 changes: 14 additions & 0 deletions src/question-label/question-label.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { render, screen } from "@testing-library/react";

import { QuestionLabel } from ".";

describe("<QuestionLabel />", () => {
it("should render correctly", () => {
const questionText = "What is the capital of France?";
render(<QuestionLabel question={questionText} />);

const questionElement = screen.getByText(questionText);
expect(questionElement).toBeInTheDocument();
});
});
10 changes: 10 additions & 0 deletions src/question-label/question-label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";

import { QuestionLabelProps } from "./types";
import { PrismFormatted } from "../prism-formatted";

export const QuestionLabel = (props: QuestionLabelProps) => {
return (
<PrismFormatted text={props.question} getCodeBlockAriaLabel={() => ""} />
);
};
3 changes: 3 additions & 0 deletions src/question-label/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface QuestionLabelProps {
question: string;
}
9 changes: 8 additions & 1 deletion src/quiz-question/quiz-question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RadioGroup } from "@headlessui/react";

import type { QuizQuestionAnswer, QuizQuestionProps } from "./types";
import { Answer } from "./answer";
import { QuestionLabel } from "../question-label";
import { OptionLabel } from "../option-label";

const QuestionText = ({
question,
Expand Down Expand Up @@ -32,7 +34,7 @@ const QuestionText = ({
* but instead, it provides a `selectedAnswer` and an `onChange` props,
* giving the parent component full control over the selection handling logic.
*/
export const QuizQuestion = <AnswerT extends number | string>({
const QuizQuestion = <AnswerT extends number | string>({
question,
answers,
required,
Expand Down Expand Up @@ -82,3 +84,8 @@ export const QuizQuestion = <AnswerT extends number | string>({
</RadioGroup>
);
};

QuizQuestion.QuestionLabel = QuestionLabel;
QuizQuestion.OptionLabel = OptionLabel;

export { QuizQuestion };
9 changes: 8 additions & 1 deletion src/quiz/quiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React from "react";

import { QuizQuestion } from "../quiz-question";
import { type QuizProps } from "./types";
import { QuestionLabel } from "../question-label";
import { OptionLabel } from "../option-label";

export const Quiz = <AnswerT extends number | string>({
const Quiz = <AnswerT extends number | string>({
questions,
disabled,
required,
Expand All @@ -23,3 +25,8 @@ export const Quiz = <AnswerT extends number | string>({
</ul>
);
};

Quiz.QuestionLabel = QuestionLabel;
Quiz.OptionLabel = OptionLabel;

export { Quiz };