npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-quizlet-flashcard

v3.0.0

Published

Simple quizlet like flashcard

Downloads

525

Readme

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 | | :--------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------: | | | |

Installation

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.

Basic Usage

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>
  );
}

Available Props for <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 |

Available props for <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 } |

Possible keys for each object in cards array

| Key | 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 |

Examples

Basic Flashcard:

import { Flashcard } from "react-quizlet-flashcard";

function App() {
  return (
    <div className="storyContainer">
      <Flashcard frontHTML="<h1>Front</h1>" backHTML={<h1>Back</h1>} />
    </div>
  );
}

Manual flip using ref:

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>
  );
}

Custom Styles for front and back content

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>
  );
}

Card flip callback

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>
  );
}

Custom Card Size

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>
  );
}

Basic FlashcardArray:

import { FlashcardArray } from "react-quizlet-flashcard";

function App() {
  const cards = [...]
  return (
    <div className="storyContainer">
      <FlashcardArray cards={cards} />
    </div>
  );
}

Cards with custom controls(Using forwardRef prop):

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>
  );
}

Custom styles for all cards in the array:

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>
  );
}

Custom style for each card:

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>
  );
}

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

Give a ⭐️ if this project helped you!

To-Do:

  • [x] Write the component with typescript.
  • [ ] Write Unit tests.
  • [x] More finer control.
  • [x] Write the styles with Sass