Skip to content

Commit

Permalink
feat(module): improve app config types autocomplete (nuxt#1870)
Browse files Browse the repository at this point in the history
Co-authored-by: Dave Stewart <[email protected]>
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
3 people authored and binhth-1206 committed Jul 28, 2024
1 parent 7718397 commit f7150c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/content/1.getting-started/3.theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ This can also happen when you bind a dynamic color to a component: `<UBadge :col

### `app.config.ts`

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`.
You can override component config in your own `app.config.ts`:

```ts [app.config.ts]
export default defineAppConfig({
Expand All @@ -118,6 +118,8 @@ export default defineAppConfig({
})
```

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)).

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.

You can change this behavior by setting `strategy` to `override` in your `app.config.ts`:
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type UI = {
colors?: string[]
strategy?: Strategy
[key: string]: any
} & DeepPartial<typeof config>
} & DeepPartial<typeof config, string>

declare module 'nuxt/schema' {
interface AppConfigInput {
Expand Down
16 changes: 12 additions & 4 deletions src/runtime/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
export type Strategy = 'merge' | 'override'

export interface TightMap<O = any> {
[key: string]: TightMap | O
}

export type DeepPartial<T, O = any> = {
[P in keyof T]?: T[P] extends object
? DeepPartial<T[P], O>
: T[P];
} & {
[key: string]: O | TightMap<O>
}

export type NestedKeyOf<ObjectType extends Record<string, any>> = {
[Key in keyof ObjectType]: ObjectType[Key] extends Record<string, any>
? NestedKeyOf<ObjectType[Key]>
: Key
}[keyof ObjectType]

export type DeepPartial<T> = Partial<{
[P in keyof T]: DeepPartial<T[P]> | { [key: string]: string | object }
}>

type DeepKey<T, Keys extends string[]> =
Keys extends [infer First, ...infer Rest]
? First extends keyof T
Expand Down

0 comments on commit f7150c6

Please sign in to comment.