
Product
Rubygems Ecosystem Support Now Generally Available
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
@react-pakistan/flashcard-component
Advanced tools
A simple and responsive quizlet-like flashcard component with a few additional options.
Front and back card accepts html strings and JSX elements!
react-quizlet-flashcard | Quizlet's flashcard component |
---|---|
![]() | ![]() |
yarn add react-quizlet-flashcard
npm i react-quizlet-flashcard
NOTE: All basic card styles like padding, border radius, font, font size and flex alignment for card content has been removed from V3.0.0 to make it more customizable. You can add your own styles to the card using various style props in both <Flashcard />
and <FlashcardArray />
components or by defining the styles in cards
array as mentioned below.
import { FlashcardArray } from "react-quizlet-flashcard";
function App() {
const cards = [
{
id: 1,
front: "What is the capital of <u>Alaska</u>?",
back: "Juneau",
frontChild: <div>Hello there</div>,
backChild: <p>This is a back child</p>,
},
{
id: 2,
front: "What is the capital of California?",
back: "Sacramento",
},
{
id: 3,
front: "What is the capital of New York?",
back: "Albany",
},
{
id: 4,
front: "What is the capital of Florida?",
back: "Tallahassee",
},
{
id: 5,
front: "What is the capital of Texas?",
back: "Austin",
},
{
id: 6,
front: "What is the capital of New Mexico?",
back: "Santa Fe",
},
{
id: 7,
front: "What is the capital of Arizona?",
back: "Phoenix",
},
];
return (
<div>
<FlashcardArray cards={cards} />
</div>
);
}
<FlashcardArray />
Prop | Type | default |
---|---|---|
*cards | array | None |
controls | boolean | true |
forwardRef | Obj | () => {} |
showCount | boolean | true |
frontCardStyle | React.CSSProperties | {} |
frontContentStyle | React.CSSProperties | {} |
backCardStyle | React.CSSProperties | {} |
backContentStyle | React.CSSProperties | {} |
FlashcardArrayStyle | React.CSSProperties | {} |
onCardChange | func | (id: any, index: number) => {} |
onCardFlip | func | (id: any, index: number, state: boolean) => {} |
currentCardFlipRef | React.MutableRefObject | None |
cycle | boolean | false |
<Flashcard />
Prop | Type | default |
---|---|---|
*frontHTML | string | JSX.Element | None |
frontCardStyle | React.CSSProperties | None |
frontContentStyle | React.CSSProperties | None |
backHTML | string | JSX.Element | None |
backCardStyle | React.CSSProperties | None |
backContentStyle | React.CSSProperties | None |
className | string | "" |
height | string | None |
width | string | None |
borderRadius | string | 1rem |
style | React.CSSProperties | None |
onCardFlip | (state: boolean) => void | None |
manualFlipRef | React.MutableRefObject | { current: null } |
cards
arrayKey | Type |
---|---|
*id | number |
*frontHTML | string | JSX.Element |
*backHTML | string | JSX.Element |
frontCardStyle | React.CSSProperties |
frontContentStyle | React.CSSProperties |
backCardStyle | React.CSSProperties |
backContentStyle | React.CSSProperties |
className | string |
height | string |
width | string |
borderRadius | string |
style | React.CSSProperties |
import { Flashcard } from "react-quizlet-flashcard";
function App() {
return (
<div className="storyContainer">
<Flashcard frontHTML="<h1>Front</h1>" backHTML={<h1>Back</h1>} />
</div>
);
}
You can use this when you want to add buttons or other intractable elements to flip the card content.
import { Flashcard } from "react-quizlet-flashcard";
import { useRef } from "react";
function App() {
const flipRef = useRef();
return (
<div className="storyContainer">
<Flashcard
frontHTML="<h1>Front</h1>"
backHTML={<h1>Back</h1>}
manualFlipRef={flipRef}
/>
<button onClick={() => flipRef.current()}>Flip</button>
</div>
);
}
import { Flashcard } from "react-quizlet-flashcard";
function App() {
return (
<div className="storyContainer">
<Flashcard
frontHTML={
<>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span>7</span>
<span>8</span>
<span>9</span>
</>
}
backHTML={<h1>Back</h1>}
backContentStyle={{
backgroundColor: "red",
color: "white",
padding: "10px",
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
frontContentStyle={{
backgroundColor: "turquoise",
color: "white",
display: "grid",
gridTemplateColumns: "repeat(3, 1fr)",
gridTemplateRows: "repeat(3, 1fr)",
fontSize: "2rem",
}}
/>
</div>
);
}
import { Flashcard } from "react-quizlet-flashcard";
function App() {
return (
<div className="storyContainer">
<Flashcard
frontHTML="<h1>Check console</h1>"
backHTML={<h1>Back</h1>}
onCardFlip={(state) => {
if (state) console.log("Card is flipped");
else console.log("Card is not flipped");
}}
/>
</div>
);
}
import { Flashcard } from "react-quizlet-flashcard";
function App() {
return (
<div className="storyContainer">
<Flashcard
frontHTML="<h1>Front</h1>"
backHTML={<h1>Back</h1>}
style={{ width: "300px", height: "300px" }}
/>
</div>
);
}
import { FlashcardArray } from "react-quizlet-flashcard";
function App() {
const cards = [...]
return (
<div className="storyContainer">
<FlashcardArray cards={cards} />
</div>
);
}
import { FlashcardArray } from "react-quizlet-flashcard";
import { useRef } from "react";
function App() {
const controlRef = useRef({}); // {} should definitely be passed to useRef for it to work
const currentCardFlipRef = useRef(); // nothing should be passed to useRef for it to work
const [currentCard, setCurrentCard] = useState(1);
return (
<div className="storyContainer">
<FlashcardArray
cards={deck.cards}
controls={false}
showCount={false}
forwardRef={controlRef}
currentCardFlipRef={currentCardFlipRef}
onCardChange={(id, index) => {
setCurrentCard(index);
}}
/>
<p>
{currentCard} / {deck.cards.length}
</p>
<button onClick={() => controlRef.current.prevCard()}>Prev</button>
<button onClick={() => controlRef.current.resetArray()}>Reset</button>
<button onClick={() => controlRef.current.nextCard()}>Next</button>
<button onClick={() => currentCardFlipRef.current()}>Flip</button>
</div>
);
}
import { FlashcardArray } from "react-quizlet-flashcard";
function App() {
cards = [...]
return (
<div className="storyContainer">
<FlashcardArray
cards={cards}
frontContentStyle={{
backgroundColor: "lightgoldenrodyellow",
color: "black",
}}
backContentStyle={{
backgroundColor: "turquoise",
}}
/>
</div>
);
}
You can set style for each card through the card object. Refer to prop list of Card object above. Instead, you can also pass another react component with custom style into cards.
import { FlashcardArray } from "react-quizlet-flashcard";
function App() {
return (
<div className="storyContainer">
<FlashcardArray
cards={[
{
id: 1,
frontHTML: (
<>
<span style={{ backgroundColor: "lawngreen" }}>Option 1</span>
<span style={{ backgroundColor: "lawngreen" }}>Option 2</span>
<span style={{ backgroundColor: "lawngreen" }}>Option 3</span>
</>
),
backHTML: "Juneau",
options: ["Juneau", "Anchorage", "Fairbanks"],
frontContentStyle: {
backgroundColor: "lightgoldenrodyellow",
color: "black",
display: "grid",
gridTemplateColumns: "1fr 1fr 1fr",
gridTemplateRows: "1fr",
gap: "10px",
padding: "10px",
},
},
{
id: 2,
frontHTML: (
<>
<span style={{ backgroundColor: "pink" }}>Option 1</span>
<span style={{ backgroundColor: "pink" }}>Option 2</span>
<span style={{ backgroundColor: "pink" }}>Option 3</span>
</>
),
backHTML: "Sacramento",
options: ["Sacramento", "Los Angeles", "San Francisco"],
frontContentStyle: {
backgroundColor: "lightgoldenrodyellow",
color: "black",
display: "grid",
gridTemplateColumns: "1fr",
gridTemplateRows: "1fr 1fr 1fr",
gap: "10px",
padding: "10px",
},
},
]}
/>
</div>
);
}
Contributions, issues and feature requests are welcome! Feel free to check issues page.
Give a ⭐️ if this project helped you!
FAQs
React Pakistan Flashcard Component
The npm package @react-pakistan/flashcard-component receives a total of 8 weekly downloads. As such, @react-pakistan/flashcard-component popularity was classified as not popular.
We found that @react-pakistan/flashcard-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
Research
The Socket Research Team investigates a malicious npm package that appears to be an Advcash integration but triggers a reverse shell during payment success, targeting servers handling transactions.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.