Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping the same modal #16

Closed
dragonfire1119 opened this issue Jan 10, 2022 · 6 comments
Closed

Overlapping the same modal #16

dragonfire1119 opened this issue Jan 10, 2022 · 6 comments

Comments

@dragonfire1119
Copy link

I was wondering if there was a way to overlap the same modal over each other? I don't see a way to give the same modal a unique id?

Like a group stack of modals that you can close one by one or all at once.

ExampleModal > ExampleModal > ExampleModal

Thanks for this awesome lib!

@youf-olivier
Copy link

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

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

@dragonfire1119
Copy link
Author

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.

@Yedidyar
Copy link
Contributor

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

@dragonfire1119
Copy link
Author

@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.

@supnate supnate closed this as completed Oct 1, 2023
@HiChen404
Copy link

you can code like this:

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

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

@IVLIU
Copy link

IVLIU commented Jan 29, 2024

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants