docs(input-menu/select-menu/select): add example with full item width (#4419)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
J-Michalek
2025-07-08 12:43:49 +02:00
committed by GitHub
parent c1427a3264
commit 513cca25f6
22 changed files with 197 additions and 10 deletions

View File

@@ -14,8 +14,8 @@ const items = [
v-slot="{ item }" v-slot="{ item }"
orientation="vertical" orientation="vertical"
:items="items" :items="items"
class="w-full max-w-xs mx-auto"
:ui="{ container: 'h-[336px]' }" :ui="{ container: 'h-[336px]' }"
class="w-full max-w-xs mx-auto"
> >
<img :src="item" width="320" height="320" class="rounded-lg"> <img :src="item" width="320" height="320" class="rounded-lg">
</UCarousel> </UCarousel>

View File

@@ -0,0 +1,31 @@
<script setup lang="ts">
const { data: users } = await useFetch('https://jsonplaceholder.typicode.com/users', {
key: 'typicode-users-email',
transform: (data: { id: number, name: string, email: string }[]) => {
return data?.map(user => ({
label: user.name,
value: String(user.id),
email: user.email,
avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` }
}))
},
lazy: true
})
</script>
<template>
<UInputMenu
:items="users"
icon="i-lucide-user"
placeholder="Select user"
:ui="{ content: 'min-w-fit' }"
>
<template #item-label="{ item }">
{{ item.label }}
<span class="text-muted">
{{ item.email }}
</span>
</template>
</UInputMenu>
</template>

View File

@@ -35,6 +35,7 @@ const items = ref([
} }
} }
] satisfies InputMenuItem[]) ] satisfies InputMenuItem[])
const value = ref(items.value[0]) const value = ref(items.value[0])
</script> </script>

View File

@@ -40,9 +40,9 @@ const text = computed(() => {
placeholder="Password" placeholder="Password"
:color="color" :color="color"
:type="show ? 'text' : 'password'" :type="show ? 'text' : 'password'"
:ui="{ trailing: 'pe-1' }"
:aria-invalid="score < 4" :aria-invalid="score < 4"
aria-describedby="password-strength" aria-describedby="password-strength"
:ui="{ trailing: 'pe-1' }"
class="w-full" class="w-full"
> >
<template #trailing> <template #trailing>

View File

@@ -62,13 +62,13 @@ const items = [
<template> <template>
<UNavigationMenu <UNavigationMenu
:items="items" :items="items"
class="w-full justify-center"
:ui="{ :ui="{
viewport: 'sm:w-(--reka-navigation-menu-viewport-width)', viewport: 'sm:w-(--reka-navigation-menu-viewport-width)',
content: 'sm:w-auto', content: 'sm:w-auto',
childList: 'sm:w-96', childList: 'sm:w-96',
childLinkDescription: 'text-balance line-clamp-2' childLinkDescription: 'text-balance line-clamp-2'
}" }"
class="w-full justify-center"
> >
<template #docs-content="{ item }"> <template #docs-content="{ item }">
<ul class="grid gap-2 p-4 lg:w-[500px] lg:grid-cols-[minmax(0,.75fr)_minmax(0,1fr)]"> <ul class="grid gap-2 p-4 lg:w-[500px] lg:grid-cols-[minmax(0,.75fr)_minmax(0,1fr)]">

View File

@@ -0,0 +1,32 @@
<script setup lang="ts">
const { data: users } = await useFetch('https://jsonplaceholder.typicode.com/users', {
key: 'typicode-users-email',
transform: (data: { id: number, name: string, email: string }[]) => {
return data?.map(user => ({
label: user.name,
value: String(user.id),
email: user.email,
avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` }
}))
},
lazy: true
})
</script>
<template>
<USelectMenu
:items="users"
icon="i-lucide-user"
placeholder="Select user"
:ui="{ content: 'min-w-fit' }"
class="w-48"
>
<template #item-label="{ item }">
{{ item.label }}
<span class="text-muted">
{{ item.email }}
</span>
</template>
</USelectMenu>
</template>

View File

@@ -35,6 +35,7 @@ const items = ref([
} }
} }
] satisfies SelectMenuItem[]) ] satisfies SelectMenuItem[])
const value = ref(items.value[0]) const value = ref(items.value[0])
</script> </script>

View File

@@ -24,6 +24,7 @@ const items = ref([
} }
} }
] satisfies SelectMenuItem[]) ] satisfies SelectMenuItem[])
const value = ref(items.value[0]) const value = ref(items.value[0])
</script> </script>

View File

@@ -23,6 +23,7 @@ const items = ref([
icon: 'i-lucide-circle-check' icon: 'i-lucide-circle-check'
} }
] satisfies SelectMenuItem[]) ] satisfies SelectMenuItem[])
const value = ref(items.value[0]) const value = ref(items.value[0])
</script> </script>

View File

@@ -0,0 +1,35 @@
<script setup lang="ts">
const value = ref<string>()
const { data: users } = await useFetch('https://jsonplaceholder.typicode.com/users', {
key: 'typicode-users-email',
transform: (data: { id: number, name: string, email: string }[]) => {
return data?.map(user => ({
label: user.name,
email: user.email,
value: String(user.id),
avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` }
}))
},
lazy: true
})
</script>
<template>
<USelect
v-model="value"
:items="users"
placeholder="Select user"
value-key="value"
:ui="{ content: 'min-w-fit' }"
class="w-48"
>
<template #item-label="{ item }">
{{ item.label }}
<span class="text-muted">
{{ item.email }}
</span>
</template>
</USelect>
</template>

View File

@@ -24,8 +24,8 @@ function getUserAvatar(value: string) {
:loading="status === 'pending'" :loading="status === 'pending'"
icon="i-lucide-user" icon="i-lucide-user"
placeholder="Select user" placeholder="Select user"
class="w-48"
value-key="value" value-key="value"
class="w-48"
> >
<template #leading="{ modelValue, ui }"> <template #leading="{ modelValue, ui }">
<UAvatar <UAvatar

View File

@@ -35,6 +35,7 @@ const items = ref([
} }
} }
] satisfies SelectItem[]) ] satisfies SelectItem[])
const value = ref(items.value[0]?.value) const value = ref(items.value[0]?.value)
const avatar = computed(() => items.value.find(item => item.value === value.value)?.avatar) const avatar = computed(() => items.value.find(item => item.value === value.value)?.avatar)

View File

@@ -23,6 +23,7 @@ const items = ref([
icon: 'i-lucide-circle-check' icon: 'i-lucide-circle-check'
} }
] satisfies SelectItem[]) ] satisfies SelectItem[])
const value = ref(items.value[0]?.value) const value = ref(items.value[0]?.value)
const icon = computed(() => items.value.find(item => item.value === value.value)?.icon) const icon = computed(() => items.value.find(item => item.value === value.value)?.icon)

View File

@@ -26,7 +26,7 @@ const state = reactive({
</script> </script>
<template> <template>
<UTabs :items="items" variant="link" class="gap-4 w-full" :ui="{ trigger: 'grow' }"> <UTabs :items="items" variant="link" :ui="{ trigger: 'grow' }" class="gap-4 w-full">
<template #account="{ item }"> <template #account="{ item }">
<p class="text-muted mb-4"> <p class="text-muted mb-4">
{{ item.description }} {{ item.description }}

View File

@@ -27,8 +27,8 @@ const items: TimelineItem[] = [{
<template> <template>
<UTimeline <UTimeline
:items="items" :items="items"
:ui="{ item: 'even:flex-row-reverse even:-translate-x-[calc(100%-2rem)] even:text-right' }"
:default-value="2" :default-value="2"
:ui="{ item: 'even:flex-row-reverse even:-translate-x-[calc(100%-2rem)] even:text-right' }"
class="translate-x-[calc(50%-1rem)]" class="translate-x-[calc(50%-1rem)]"
/> />
</template> </template>

View File

@@ -42,11 +42,11 @@ const items = [{
<UTimeline <UTimeline
:items="items" :items="items"
size="xs" size="xs"
class="w-96"
:ui="{ :ui="{
date: 'float-end ms-1', date: 'float-end ms-1',
description: 'px-3 py-2 ring ring-default mt-2 rounded-md text-default' description: 'px-3 py-2 ring ring-default mt-2 rounded-md text-default'
}" }"
class="w-96"
> >
<template #title="{ item }"> <template #title="{ item }">
<span>{{ item.username }}</span> <span>{{ item.username }}</span>

View File

@@ -7,12 +7,12 @@ const appConfig = useAppConfig()
<UFormField <UFormField
label="toaster.duration" label="toaster.duration"
size="sm" size="sm"
class="inline-flex ring ring-accented rounded-sm"
:ui="{ :ui="{
wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented', wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented',
label: 'text-muted px-2 py-1.5', label: 'text-muted px-2 py-1.5',
container: 'mt-0' container: 'mt-0'
}" }"
class="inline-flex ring ring-accented rounded-sm"
> >
<UInput <UInput
v-model="appConfig.toaster.duration" v-model="appConfig.toaster.duration"

View File

@@ -7,12 +7,12 @@ const appConfig = useAppConfig()
<UFormField <UFormField
label="toaster.expand" label="toaster.expand"
size="sm" size="sm"
class="inline-flex ring ring-accented rounded-sm"
:ui="{ :ui="{
wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented', wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented',
label: 'text-muted px-2 py-1.5', label: 'text-muted px-2 py-1.5',
container: 'mt-0' container: 'mt-0'
}" }"
class="inline-flex ring ring-accented rounded-sm"
> >
<USelectMenu <USelectMenu
v-model="appConfig.toaster.expand" v-model="appConfig.toaster.expand"

View File

@@ -10,12 +10,12 @@ const appConfig = useAppConfig()
<UFormField <UFormField
label="toaster.position" label="toaster.position"
size="sm" size="sm"
class="inline-flex ring ring-accented rounded-sm"
:ui="{ :ui="{
wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented', wrapper: 'bg-elevated/50 rounded-l-sm flex border-r border-accented',
label: 'text-muted px-2 py-1.5', label: 'text-muted px-2 py-1.5',
container: 'mt-0' container: 'mt-0'
}" }"
class="inline-flex ring ring-accented rounded-sm"
> >
<USelectMenu <USelectMenu
v-model="appConfig.toaster.position" v-model="appConfig.toaster.position"

View File

@@ -757,6 +757,33 @@ name: 'input-menu-filter-fields-example'
--- ---
:: ::
### With full content width
You can expand the content to the full width of its items by using the `ui.content` key.
::component-example
---
name: 'input-menu-content-width-example'
collapse: true
---
::
::tip
You can also change the content width globally in your `app.config.ts`:
```
export default defineAppConfig({
ui: {
inputMenu: {
slots: {
content: 'min-w-fit'
}
}
}
})
```
::
### As a CountryPicker ### As a CountryPicker
This example demonstrates using the InputMenu as a country picker with lazy loading - countries are only fetched when the menu is opened. This example demonstrates using the InputMenu as a country picker with lazy loading - countries are only fetched when the menu is opened.

View File

@@ -790,6 +790,33 @@ name: 'select-menu-filter-fields-example'
--- ---
:: ::
### With full content width
You can expand the content to the full width of its items by using the `ui.content` key.
::component-example
---
name: 'select-menu-content-width-example'
collapse: true
---
::
::tip
You can also change the content width globally in your `app.config.ts`:
```
export default defineAppConfig({
ui: {
selectMenu: {
slots: {
content: 'min-w-fit'
}
}
}
})
```
::
### As a CountryPicker ### As a CountryPicker
This example demonstrates using the SelectMenu as a country picker with lazy loading - countries are only fetched when the menu is opened. This example demonstrates using the SelectMenu as a country picker with lazy loading - countries are only fetched when the menu is opened.
@@ -801,6 +828,8 @@ name: 'select-menu-countries-example'
--- ---
:: ::
## API ## API
### Props ### Props

View File

@@ -695,6 +695,33 @@ collapse: true
--- ---
:: ::
### With full content width
You can expand the content to the full width of its items by using the `ui.content` key.
::component-example
---
name: 'select-content-width-example'
collapse: true
---
::
::tip
You can also change the content width globally in your `app.config.ts`:
```
export default defineAppConfig({
ui: {
select: {
slots: {
content: 'min-w-fit'
}
}
}
})
```
::
## API ## API
### Props ### Props