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

Nuxt UI - Responsive Model/Drawer #3772

Closed
QaahirStewart opened this issue Apr 1, 2025 · 3 comments
Closed

Nuxt UI - Responsive Model/Drawer #3772

QaahirStewart opened this issue Apr 1, 2025 · 3 comments
Labels
enhancement New feature or request triage v3 #1289

Comments

@QaahirStewart
Copy link

Description

Hey guys, can we implement a responsive model with Nuxt UI.

Similar to the: Maybe fix the repeated content of the Dialog and Drawer.
https://www.shadcn-vue.com/docs/components/drawer.html

Additional context

No response

@QaahirStewart QaahirStewart added enhancement New feature or request triage v3 #1289 labels Apr 1, 2025
Copy link
Member

You can already do this similar to the example of shadcn/vue:

<script lang="ts" setup>
import { createReusableTemplate, useMediaQuery } from '@vueuse/core'

const [UseTemplate, GridForm] = createReusableTemplate()
const isDesktop = useMediaQuery('(min-width: 768px)')

const open = ref(false)

const state = reactive({
  email: undefined,
  username: undefined
})

const title = 'Edit profile'
const description = 'Make changes to your profile here. Click save when you\'re done.'
</script>

<template>
  <UseTemplate>
    <UForm :state="state" class="space-y-4">
      <UFormField label="Email" name="email">
        <UInput v-model="state.email" placeholder="[email protected]" />
      </UFormField>
      <UFormField label="Username" name="username">
        <UInput v-model="state.username" placeholder="@shadcn" />
      </UFormField>

      <UButton label="Save changes" type="submit" />
    </UForm>
  </UseTemplate>

  <UModal v-if="isDesktop" v-model:open="open" :title="title" :description="description">
    <UButton label="Edit profile" color="neutral" variant="outline" />

    <template #body>
      <GridForm />
    </template>
  </UModal>

  <UDrawer v-else v-model:open="open" :title="title" :description="description">
    <UButton label="Edit profile" color="neutral" variant="outline" />

    <template #body>
      <GridForm />
    </template>
  </UDrawer>
</template>

@zAlweNy26
Copy link
Contributor

@benjamincanac can it be managed with the useOverlay composable without any further addition?

Copy link
Member

Yes of course, you can create two overlays and call the one you want. Something like:

<script setup lang="ts">
const isDesktop = useMediaQuery('(min-width: 768px)')

const modal = overlay.create(MyModal)
const drawer = overlay.create(MyDrawer)

function onButtonClick() {
  if (isDesktop) {
    modal.open()
  } else {
    drawer.open()
  }
}
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage v3 #1289
Projects
None yet
Development

No branches or pull requests

3 participants