🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@modalor/react

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modalor/react

A modal state manager for React.

1.0.1
latest
Source
npm
Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
 
Created
Source

@modalor/vue

A modal state manager for Vue3.

Install

pnpm add @modalor/vue

Usage

  • Render the Modalor in the root of your app.
<script lang="ts" setup>
import { Modalor } from '@modalor/vue'
</script>

<!-- App.vue -->
<template>
  <!-- ... -->
  <Modalor />
</template>
  • create a modal with your own modal component
// modal.ts
import { create } from '@modalor/vue'
import { h } from 'vue'

interface ModalProps {
  title: string
  // ...
}

// 1. create modal wrapper
export const createModal = create<ModalProps>(({ onCancel, onOk, open, isOkLoading, props: { renderChildren, ...rest } }) => (
  h(YourModalComponent, { onCancel, onOk, open, isOkLoading, ...rest }, renderChildren)
))
  • create a modal with a content component
// modals/userProfile.ts
import { createModal } from './../modal'

// 1.define modal content props
interface ModalContentProps {
  username: string
  // ...
}

// 2. define modal content resolve values
interface ModalContentResolveValues {
  newUsername: string
  // ...
}
// 3. create modal wrapper with modal content props and resolve values
const userProfileModal = createModal<ModalContentProps, ModalContentResolveValues>(props => (
  h(YourModalContentComponent, { ...props })
))
  • use api to show modal
<script setup>
// 1. import your modal
import { userProfileModal } from '@/modals/userProfile'

async function showModal() {
  // 2. show modal
  const [isOk, result] = await userProfileModal.show({
    username: 'John'
  }, {
    title: 'User Profile', // you can override modal props
  })

  // 3. handle result
  if (isOk) {
    console.log(result.newUsername) // will be your resolve values
  }
}
</script>

<template>
  <button @click="showModal">
    Show Modal
  </button>
</template>

Keywords

vue

FAQs

Package last updated on 27 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts