Skip to content

Commit 3f8ea5d

Browse files
davestewartbenjamincanac
andauthoredJul 9, 2024··
feat(module): improve app config types autocomplete (#1870)
Co-authored-by: Dave Stewart <dev@davestewart.co.uk> Co-authored-by: Benjamin Canac <canacb1@gmail.com>

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed
 

‎docs/content/1.getting-started/3.theming.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ This can also happen when you bind a dynamic color to a component: `<UBadge :col
106106

107107
### `app.config.ts`
108108

109-
You can find the config of each component in the [`ui.config/`](https://github.com/nuxt/ui/tree/dev/src/runtime/ui.config) directory. You can override those classes in your own `app.config.ts`.
109+
You can override component config in your own `app.config.ts`:
110110

111111
```ts [app.config.ts]
112112
export default defineAppConfig({
@@ -118,6 +118,8 @@ export default defineAppConfig({
118118
})
119119
```
120120

121+
The available options for each component should auto-complete, and you can review the defaults for each component using your IDE's function such as `Cmd`+`Click` (these files can be found in [`src/runtime/ui.config/`](https://github.com/nuxt/ui/tree/dev/src/runtime/ui.config)).
122+
121123
Thanks to [tailwind-merge](https://github.com/dcastil/tailwind-merge), the `app.config.ts` is smartly merged with the default config. This means you don't have to rewrite everything.
122124

123125
You can change this behavior by setting `strategy` to `override` in your `app.config.ts`:

‎src/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type UI = {
2121
colors?: string[]
2222
strategy?: Strategy
2323
[key: string]: any
24-
} & DeepPartial<typeof config>
24+
} & DeepPartial<typeof config, string>
2525

2626
declare module 'nuxt/schema' {
2727
interface AppConfigInput {

‎src/runtime/types/utils.d.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
export type Strategy = 'merge' | 'override'
22

3+
export interface TightMap<O = any> {
4+
[key: string]: TightMap | O
5+
}
6+
7+
export type DeepPartial<T, O = any> = {
8+
[P in keyof T]?: T[P] extends object
9+
? DeepPartial<T[P], O>
10+
: T[P];
11+
} & {
12+
[key: string]: O | TightMap<O>
13+
}
14+
315
export type NestedKeyOf<ObjectType extends Record<string, any>> = {
416
[Key in keyof ObjectType]: ObjectType[Key] extends Record<string, any>
517
? NestedKeyOf<ObjectType[Key]>
618
: Key
719
}[keyof ObjectType]
820

9-
export type DeepPartial<T> = Partial<{
10-
[P in keyof T]: DeepPartial<T[P]> | { [key: string]: string | object }
11-
}>
12-
1321
type DeepKey<T, Keys extends string[]> =
1422
Keys extends [infer First, ...infer Rest]
1523
? First extends keyof T

0 commit comments

Comments
 (0)
Please sign in to comment.