-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add quiz widget to sanity portabletext #94
add quiz widget to sanity portabletext #94
- Loading branch information
Showing
9 changed files
with
102 additions
and
2 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,36 @@ | ||
"use client"; | ||
import { useState } from "react"; | ||
import { BiMinus, BiPlus } from "react-icons/bi"; | ||
|
||
export default function Accordion({ | ||
id, | ||
question, | ||
answer, | ||
}: { | ||
id: string; | ||
question: string; | ||
answer: string; | ||
}) { | ||
const [active, setActive] = useState<string | null>(null); | ||
|
||
return ( | ||
<div | ||
className={`grid gap-y-2 border-b dark:border-zinc-800 border-zinc-200 my-4 duration-200 ${active === id ? "grid-rows-full pb-4" : "grid-rows-fit pb-0"}`} | ||
> | ||
<div | ||
className={`flex items-center justify-between gap-x-2 cursor-pointer selection:bg-transparent`} | ||
onClick={() => setActive(active === id ? null : id)} | ||
> | ||
<h3 className="text-lg mb-1 dark:text-white text-zinc-700"> | ||
{question} | ||
</h3> | ||
<button className="p-1 rounded-full text-sm cursor-[inherit] duration-100 dark:bg-primary-bg bg-secondary-bg"> | ||
{active === id ? <BiMinus /> : <BiPlus />} | ||
</button> | ||
</div> | ||
<p className="dark:text-zinc-400 text-zinc-600 overflow-hidden"> | ||
{answer} | ||
</p> | ||
</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 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,13 @@ | ||
import { QuizValueProps } from "@/types"; | ||
import Accordion from "./Accordion"; | ||
|
||
export default function Quiz({ value }: { value: QuizValueProps }) { | ||
return ( | ||
<Accordion | ||
key={value._key} | ||
id={value._key} | ||
question={value.question} | ||
answer={value.answer} | ||
/> | ||
); | ||
} |
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,35 @@ | ||
import { defineField, defineType } from "sanity"; | ||
import { BiCommand } from "react-icons/bi"; | ||
|
||
export default defineType({ | ||
name: "quiz", | ||
title: "Quiz", | ||
type: "object", | ||
icon: BiCommand, | ||
fields: [ | ||
defineField({ | ||
name: "question", | ||
title: "Question", | ||
type: "string", | ||
}), | ||
defineField({ | ||
name: "answer", | ||
title: "Answer", | ||
type: "text", | ||
rows: 4, | ||
description: "What is the answer to the question?", | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
question: "question", | ||
answer: "answer", | ||
}, | ||
prepare({ question, answer }) { | ||
return { | ||
title: !question ? "No Question" : question, | ||
subtitle: !answer ? "No answer" : answer, | ||
}; | ||
}, | ||
}, | ||
}); |
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