@falcondev-oss/nuxt-layers-base 0.31.2 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -145,7 +145,7 @@ const columns = useTableColumns<typeof data>(
145
145
  ]"
146
146
  :user-menu="{
147
147
  name: 'Benjamin Canac',
148
- avatar: { src: 'https://github.com/benjamincanac.png' },
148
+ // avatar: { src: 'https://github.com/benjamincanac.png' },
149
149
  items: [
150
150
  {
151
151
  icon: 'lucide:log-out',
@@ -259,7 +259,7 @@ const columns = useTableColumns<typeof data>(
259
259
  class="flex flex-col gap-4"
260
260
  >
261
261
  {{ form.data }}
262
- <UField v-slot="{ bind, field }" :field="form.fields.text.$use()">
262
+ <UField v-slot="{ bind, field }" :field="form.fields.text.$use()" error-inline>
263
263
  {{ field.schema }}
264
264
  <UInput class="w-full" v-bind="bind" />
265
265
  </UField>
@@ -43,8 +43,8 @@ const config = useRuntimeConfig()
43
43
  collapsible
44
44
  :ui="{
45
45
  ...sidebar?.ui,
46
- header: [sidebar?.ui?.header ?? '', 'border-b border-default'].join(' ').trim(),
47
- footer: [sidebar?.ui?.footer ?? '', 'border-t border-default'].join(' ').trim(),
46
+ header: [sidebar?.ui?.header, 'border-b border-default'],
47
+ footer: [sidebar?.ui?.footer, 'border-t border-default'],
48
48
  }"
49
49
  >
50
50
  <template
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts" generic="T">
2
2
  import type { FormField } from '@falcondev-oss/form-core'
3
3
  import type { FormFieldProps, FormFieldSlots } from '@nuxt/ui'
4
+ import { createReusableTemplate } from '@vueuse/core'
4
5
  import { useForwardProps } from 'reka-ui'
5
6
  import * as R from 'remeda'
6
7
 
@@ -17,6 +18,8 @@ type InputProps<T> = {
17
18
  const props = defineProps<
18
19
  FormFieldProps & {
19
20
  field: FormField<T>
21
+ errorInline?: boolean
22
+ errorPreferPlaceholder?: boolean
20
23
  }
21
24
  >()
22
25
 
@@ -60,7 +63,7 @@ const formFieldProps = computed<FormFieldProps>(() => {
60
63
  const bind = computed(() => {
61
64
  const field = forwardedProps.value.field
62
65
 
63
- const placeholder = (field.errors && field.errors.join('\n')) || field.schema.default?.toString()
66
+ const placeholder = (field.errors && field.errors[0]) || field.schema.default?.toString()
64
67
 
65
68
  return {
66
69
  'modelValue': field.value,
@@ -83,6 +86,12 @@ const model = computed({
83
86
  })
84
87
 
85
88
  const model_ = { model }
89
+
90
+ const [DefineErrorTemplate, ErrorTemplate] = createReusableTemplate({
91
+ props: {
92
+ errors: Array as PropType<string[]>,
93
+ },
94
+ })
86
95
  </script>
87
96
 
88
97
  <template>
@@ -90,15 +99,43 @@ const model_ = { model }
90
99
  v-bind="formFieldProps"
91
100
  :ui="{
92
101
  ...formFieldProps.ui,
93
- hint: [formFieldProps.ui?.hint ?? '', isOverMaxLength ? 'text-error' : ''].join(' ').trim(),
102
+ hint: [formFieldProps.ui?.hint, isOverMaxLength ? 'text-error' : ''],
103
+ error: [formFieldProps.ui?.error, 'mt-1!'],
94
104
  }"
95
105
  :error="!!field.errors"
96
106
  :class="props.class"
97
107
  >
98
- <template #hint="{ hint }">
108
+ <DefineErrorTemplate v-slot="{ errors }">
109
+ <p v-if="errors.length === 1">
110
+ {{ errors.join('\n') }}
111
+ </p>
112
+
113
+ <ul v-else>
114
+ <li v-for="(error, index) in errors" :key="error + index" class="list-inside">
115
+ {{ error }}
116
+ </li>
117
+ </ul>
118
+ </DefineErrorTemplate>
119
+
120
+ <template
121
+ v-if="
122
+ field.errors &&
123
+ errorInline &&
124
+ (errorPreferPlaceholder ? String(field.value).length > 0 : true)
125
+ "
126
+ #error
127
+ >
128
+ <ErrorTemplate :errors="field.errors" />
129
+
130
+ <template v-if="typeof error === 'string'">
131
+ {{ error }}
132
+ </template>
133
+ </template>
134
+
135
+ <template v-else #hint="{ hint }">
99
136
  <span class="flex items-center gap-1.5">
100
137
  <UPopover
101
- v-if="!!field.errors"
138
+ v-if="!!field.errors && (errorPreferPlaceholder ? String(field.value).length > 0 : true)"
102
139
  mode="hover"
103
140
  :open-delay="0"
104
141
  :ui="{
@@ -108,15 +145,7 @@ const model_ = { model }
108
145
  <UIcon name="lucide:circle-alert" class="text-error" />
109
146
  <template #content>
110
147
  <div class="text-(--ui-color-neutral-800) max-w-sm text-xs">
111
- <p v-if="field.errors.length === 1">
112
- {{ field.errors.join('\n') }}
113
- </p>
114
-
115
- <ul v-else>
116
- <li v-for="(error, index) in field.errors" :key="error + index" class="list-inside">
117
- {{ error }}
118
- </li>
119
- </ul>
148
+ <ErrorTemplate :errors="field.errors" />
120
149
  </div>
121
150
  </template>
122
151
  </UPopover>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@falcondev-oss/nuxt-layers-base",
3
3
  "type": "module",
4
- "version": "0.31.2",
4
+ "version": "0.32.0",
5
5
  "description": "Nuxt layer with lots of useful helpers and @nuxt/ui components",
6
6
  "license": "MIT",
7
7
  "repository": "github:falcondev-oss/nuxt-layers",