Skip to content

Commit 83643a2

Browse files
committed
feature: Add unstyled and fully configurable component
1 parent 3300d45 commit 83643a2

File tree

6 files changed

+88
-30
lines changed

6 files changed

+88
-30
lines changed

playground/app.vue

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
<template>
22
<div>
3-
<ListmonkForm />
3+
<ListmonkForm>
4+
<ListmonkInputGroup
5+
id="input-email"
6+
label="E-mail"
7+
>
8+
<template #default="inputProps">
9+
<ListmonkInput
10+
:id="inputProps.id"
11+
field="email"
12+
type="email"
13+
required
14+
/>
15+
</template>
16+
</ListmonkInputGroup>
17+
18+
<ListmonkInputGroup
19+
id="input-name"
20+
label="Name"
21+
>
22+
<template #default="inputProps">
23+
<ListmonkInput
24+
:id="inputProps.id"
25+
field="name"
26+
/>
27+
</template>
28+
</ListmonkInputGroup>
29+
30+
<ListmonkButton title="Send" />
31+
</ListmonkForm>
432
</div>
533
</template>
6-
7-
<script setup lang="ts">
8-
</script>

src/module.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath } from 'node:url'
2-
import { defineNuxtModule, createResolver, addComponent, addServerHandler, addImportsDir } from '@nuxt/kit'
2+
import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addComponentsDir } from '@nuxt/kit'
33
import { defu } from 'defu'
44
import type { NuxtModule } from 'nuxt/schema'
55

@@ -43,10 +43,9 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
4343

4444
addImportsDir(resolve(runtimeDir, 'composables'))
4545

46-
addComponent({
47-
filePath: resolve(runtimeDir, 'components/ListmonkForm.vue'),
48-
name: 'ListmonkForm',
46+
addComponentsDir({
4947
global: true,
48+
path: resolve(runtimeDir, 'components'),
5049
})
5150

5251
addServerHandler({
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup lang="ts">
2+
defineProps<{
3+
type?: string
4+
title: string
5+
}>()
6+
</script>
7+
8+
<template>
9+
<button
10+
:type="type || 'submit'"
11+
>
12+
{{ title }}
13+
</button>
14+
</template>

src/runtime/components/ListmonkForm.vue

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const emit = defineEmits(['subscribed'])
44
const email = ref('')
55
const name = ref('')
66
7+
provide('email', email)
8+
provide('name', name)
9+
710
async function submit() {
811
const subscriber = {
912
email: email.value,
@@ -17,27 +20,9 @@ async function submit() {
1720
</script>
1821

1922
<template>
20-
<form @submit.prevent="submit">
21-
<div>
22-
<input
23-
v-model="email"
24-
type="email"
25-
name="email"
26-
placeholder="E-mail"
27-
>
28-
</div>
29-
30-
<div>
31-
<input
32-
v-model="name"
33-
type="text"
34-
name="name"
35-
placeholder="Nome"
36-
>
37-
</div>
38-
39-
<button type="submit">
40-
Enviar
41-
</button>
23+
<form
24+
@submit.prevent="submit"
25+
>
26+
<slot />
4227
</form>
4328
</template>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
field: 'email' | 'name'
4+
id?: string
5+
required?: boolean
6+
type?: string
7+
placeholder?: string
8+
}>()
9+
10+
const field = inject(props.field)
11+
</script>
12+
13+
<template>
14+
<input
15+
:id="id || ''"
16+
v-model="field"
17+
:type="type || 'text'"
18+
:required="required || false"
19+
:placeholder="placeholder || ''"
20+
>
21+
</template>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup lang="ts">
2+
defineProps<{
3+
id: string
4+
label: string
5+
}>()
6+
</script>
7+
8+
<template>
9+
<div>
10+
<label :for="id">{{ label }}</label>
11+
12+
<slot :id="id" />
13+
</div>
14+
</template>

0 commit comments

Comments
 (0)