nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
3.79k stars 463 forks source link

Programmatic modal #285

Closed ldiellyoungl closed 7 months ago

ldiellyoungl commented 1 year ago

Programmatic modal usage like accept dialog (yes/no)

benjamincanac commented 1 year ago

This could be nice indeed, there is something we could do with https://vueuse.org/core/createTemplatePromise/, I'll look into it!

acidjazz commented 1 year ago

requested a similar feature confirmations

AbdallahAlhaddad commented 1 year ago

Hi @benjamincanac

I think we could replace HeadlessUI Dialog with vue-final-modal

Added benefits in addition to providing a Styleless component

What do you think?

benjamincanac commented 1 year ago

I'd rather implement the useModal composable ourself and add a <UModals /> container like we do for notifications.

rizhenkov commented 1 year ago

Vue-final-modal is also a good option, but I agree with @benjamincanac: his option may be more customizable and may offer better availability for people with limited accessibility.

noook commented 7 months ago

I'm interested in contributing to this, following @benjamincanac 's recommendation.

I'd have a few questions regarding the implementation, and what I have in mind:

I believe OP expects an API like this (types are fictives, I don't know the exact ones but interested to know them):

interface UseModalControls {
  // Optional modal component param would allow chaining Modals
  reveal: (modalComponent?: Component) => Promise<void>
  hide: () => Promise<void>
  isOpen: Ref<boolean>
}

function useModal<T extends Component>(modalComponent: T, props: ComponentProps<T>, modalLifeCycleOptions?: ModalLifeCycleOptions): UseModalControls {}

// modalLifeCycleOptions -> onReveal, onClose ...

Dealing with this composable across multiple components means that we need to persist the state of the current configured modal (selected component, open/close state...). -> Should we use inject/provide (with createInjectionState() or createSharedComposable() for example) to provide the state at the root level when installing the module, and inject in the composable so it is aware of the current state ?