Skip to content

Commit f892ea3

Browse files
committed
feat: create theme property and document it
1 parent 3113134 commit f892ea3

File tree

9 files changed

+45
-17
lines changed

9 files changed

+45
-17
lines changed

docs/app/components/examples/Fields.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const schema = z.object({
1717
},
1818
} }),
1919
style: z.boolean()
20-
.meta({ autoForm: { floatRight: true } }),
20+
.meta({ theme: { floatRight: true } }),
2121
})
2222
</script>
2323

docs/app/components/examples/RealWorld.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const schema = z.object({
3535
marketing_consent: z.boolean()
3636
.meta({
3737
title: 'Do you want to receive information about future Hack4Krak events?',
38-
autoForm: { floatRight: true },
38+
theme: { floatRight: true },
3939
}),
4040
referral_source: z
4141
.array(z.enum(REFERRAL_SOURCES))

docs/content/2.customization/1.config.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,21 @@ Consult the [Submit Button](./submit_button) documentation for more information.
103103
props?: Record<string, any>
104104
}
105105
```
106+
107+
### `theme`
108+
109+
This option allows you to customize default form themes.
110+
111+
::warning
112+
This feature is in development!
113+
::
114+
115+
```ts-type
116+
{
117+
/**
118+
* Apply `w-full` class to all input components by default.
119+
* @default true
120+
*/
121+
wFull?: boolean
122+
}
123+
```

docs/content/2.customization/2.fields.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,13 @@ You can customize the appearance of form fields:
6666

6767
```ts-type
6868
/** Auto-form specific configuration */
69-
autoForm?: {
69+
theme?: {
7070
/** Float the input box to the right of the label */
7171
floatRight?: boolean
72+
wFull?: boolean
7273
}
7374
```
7475

75-
::caution
76-
This feature is experimental and may be reworked or removed in future releases.
77-
::
78-
7976
## Example
8077

8178
::component-preview{name="Fields"}

playground/app/components/MyForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const schema = z.object({
4343
.default(true)
4444
.meta({
4545
title: 'Boolean Input with floatRight',
46-
autoForm: { floatRight: true },
46+
theme: { floatRight: true },
4747
}),
4848
multiple_input: z
4949
.array(z.enum(ENUM_MULTIPLE))

playground/tests/e2e/basic.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('test very basic form', async ({ page }) => {
2222
await page.getByRole('combobox', { name: 'Multiple Enum Input' }).click()
2323
await page.getByRole('option', { name: 'E' }).click()
2424
await page.getByRole('option', { name: 'A' }).click()
25-
await page.locator('html').click()
26-
await page.getByRole('button', { name: 'Send' }).click()
27-
await expect(page.getByRole('button', { name: 'Send' })).toBeEnabled()
25+
await page.mouse.click(0, 0)
26+
await page.getByRole('button', { name: 'My custom send button' }).click()
27+
await expect(page.getByRole('button', { name: 'My custom send button' })).toBeEnabled()
2828
})

src/runtime/components/AutoForm.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const isButtonDisabled = computed(() => !props.schema.safeParse(state).success)
3737
3838
const defaults: Partial<AutoFormConfig> = {
3939
components: COMPONENTS_MAP,
40+
theme: {
41+
wFull: true,
42+
},
4043
}
4144
4245
const appConfig = computed<AutoFormConfig>(() => {
@@ -50,6 +53,9 @@ const fields = Object.entries(shape).map(([key, zodType]: [string, any]) => {
5053
5154
const meta = typeof zodType.meta === 'function' ? zodType.meta() || {} : {}
5255
56+
const defaultProps = {
57+
class: appConfig.value?.theme?.wFull ? 'w-full' : '',
58+
}
5359
return {
5460
key,
5561
formField: {
@@ -58,7 +64,7 @@ const fields = Object.entries(shape).map(([key, zodType]: [string, any]) => {
5864
...parseMeta(meta, key),
5965
},
6066
component: meta?.input?.component ?? result.component,
61-
props: defu(meta?.input?.props, result.componentProps ?? {}),
67+
props: defu(defaultProps, meta?.input?.props, result.componentProps ?? {}),
6268
}
6369
}).filter((field): field is NonNullable<typeof field> => field != null)
6470
@@ -75,7 +81,7 @@ function parseMeta(meta: any, key: string) {
7581
description: meta.description,
7682
hint: meta.hint,
7783
help: meta.help,
78-
class: meta.autoForm?.floatRight ? 'flex items-center justify-between text-left' : '',
84+
class: meta.theme?.floatRight ? 'flex items-center justify-between text-left' : '',
7985
}
8086
}
8187

src/runtime/types/index.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ export interface AutoFormConfig {
1818
props?: ButtonProps
1919
} | false
2020

21+
/**
22+
* Customize default form styles
23+
*/
2124
theme?: {
2225
/**
23-
* Use floating labels for form fields
24-
* @see https://ui.nuxt.com/components/form-field#description
26+
* Apply `w-full` class to all input components by default.
2527
* @default true
2628
*/
27-
floatingLabels?: boolean
29+
wFull?: boolean
2830
}
2931

3032
/**

src/runtime/types/zod.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ declare module 'zod' {
66
/** Global configuration added by `nuxt-auto-form` Nuxt module */
77
interface GlobalMeta {
88
/** Auto-form specific configuration */
9-
autoForm?: {
9+
theme?: {
1010
/** Float the input box to the right of the label */
1111
floatRight?: boolean
12+
/**
13+
* Apply `w-full` class to all input components by default.
14+
* @default true
15+
*/
16+
wFull?: boolean
1217
}
1318

1419
/**

0 commit comments

Comments
 (0)