Code Monkey home page Code Monkey logo

Comments (6)

HiChen404 avatar HiChen404 commented on August 28, 2024 3

you can code like this:

const modal1 = NiceModal.create(SameModal);
const modal2 = NiceModal.create(SameModal);

NiceModal.show(modal1);
NiceModal.show(modal2);

from nice-modal-react.

dragonfire1119 avatar dragonfire1119 commented on August 28, 2024 2

@dragonfire1119 Hi can you please share your solution with it using the library?

I no longer use nice-modal-react because it lacked the features I required, so I created my own solution. I don't have a solution for this library.

from nice-modal-react.

IVLIU avatar IVLIU commented on August 28, 2024 1

You can encapsulate it like this

import NiceModal from '@ebay/nice-modal-react'
import type { FC } from 'react'

export const createNiceModal = <P extends {}>(component: FC<P>) => {
  const Dialog = NiceModal.create<P>(component);
  
  return (modalId: string) => {
    NiceModal.register(modalId, Dialog)

    const create = (props: P = {} as P) => NiceModal.show(modalId, props)

    const hide = () => NiceModal.hide(modalId)

    const remove = () => NiceModal.remove(modalId)

    return {
      create,
      hide,
      remove,
    }
  }
}

use

const modalFactory = createNiceModal(
  () => {
    // modal
    const { visible, remove, resolve } = useModal()
    // form
    const [form] = useForm()
  
    return (
      <Modal title="登录" open={visible} onCancel={remove} onOk={form.submit}>
        <Form form={form} onFinish={resolve}>
          <FormItem name="username" label="用户名">
            <Input placeholder="请输入密码" />
          </FormItem>
          <FormItem name="password" label="密码">
            <Password placeholder="请输入密码" />
          </FormItem>
        </Form>
      </Modal>
    )
  }
)

export const LoginModal = modalFactory('login')

export const registerModal = modalFactory('register')

from nice-modal-react.

youf-olivier avatar youf-olivier commented on August 28, 2024

It's maybe late, but I have the same need.

And you can do this : https://opensource.ebay.com/nice-modal-react/#promise

from nice-modal-react.

dragonfire1119 avatar dragonfire1119 commented on August 28, 2024

It's maybe late, but I have the same need.

And you can do this : https://opensource.ebay.com/nice-modal-react/#promise

Yes, I noticed that, but it didn't work since I needed the user to be able to click and return to the previous modal-like pages. Finally, I created my own solution.

from nice-modal-react.

Yedidyar avatar Yedidyar commented on August 28, 2024

@dragonfire1119 Hi can you please share your solution with it using the library?

from nice-modal-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.