DEV Community

Cover image for How to Create Modals on PrimeReact
CodePlusDev
CodePlusDev

Posted on

2

How to Create Modals on PrimeReact

IzyModals is a Wizard library that creats React Modals using PrimeReact component. I will show you how to create a modal using izymodals in this post.

GET STARTED: INSTALLATION

npm i izymodals
# or
yarn add izymodals
Enter fullscreen mode Exit fullscreen mode

LINKS

CodePlusDev
NPMJS
YARNPKG

CodeSandbox Live Examples

Example configs for creating TabModal

import { TabModal } from "izymodals";

const steps = [
    {
      label: "Step 1",
      content: Container,
      params: {
        children: <PromptExample buttonLabel="Step 1 Button: Do you like it?" />
      }
    },
    {
      label: "Step 2",
      content: Container,
      params: {
        children: (
          <PromptExample buttonLabel="Step 2: Do you recommend it to your friend?" />
        )
      }
    }
  ];

return (
    <TabModal status steps={steps}>
      {({ tabList, tabPanels }) => {
        return (
          <div className="col-12 flex">
            <div className="col-2">
              <div className="card">
                <div className="flex align-items-center flex-column ">
                  {tabList}
                </div>
              </div>
            </div>
            <div className="col-10">
              <div className="flex flex-column">{tabPanels}</div>
            </div>
          </div>
        );
      }}
    </TabModal>
  );
Enter fullscreen mode Exit fullscreen mode

"tabPanels" and "tabList" variables are placeholders for PrimeReact Tabs component. "tabList" replaces with tab menu, tabPanels replaces with tab contents. TabModal component's child must start with a arrow function such as the example. So, do not forget to import TabModal component.

Prompt Modal Example File

import { useState } from "react";
import { PromptModal } from "izymodals";

const PropmtExample = (props) => {
  const [status, setStatus] = useState(false);

  return (
    <div>
      <PromptModal
        status
        labelYes="yes"
        labelNo="no"
        onYes={() => setStatus("yes")}
        onNo={() => setStatus("no")}
        {...props}
      >
        Test {status}
      </PromptModal>
    </div>
  );
};

export default PropmtExample;
Enter fullscreen mode Exit fullscreen mode

Support me for my Open Source Projects
https://github.com/uuur86
https://github.com/sponsors/uuur86

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay