Skip to content

Commit

Permalink
adjust docs to mergeConfigs usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Aug 20, 2023
1 parent 8c86919 commit 1e6346b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,22 @@ But don't merge configs like that. Use [`mergeConfigs`](#mergeconfigs) instead.
function mergeConfigs(baseConfig: Config, configExtension: Partial<Config>): Config
```

Helper function to merge multiple config objects. Objects are merged, arrays are concatenated, scalar values are overridden and `undefined` does nothing. The function assumes that both parameters are tailwind-merge config objects and shouldn't be used as a generic merge function.
Helper function to merge multiple tailwind-merge configs. Properties with the value `undefined` are skipped.

```ts
const customTwMerge = createTailwindMerge(getDefaultConfig, (config) =>
mergeConfigs(config, {
classGroups: {
// ↓ Adding new class group
mySpecialClassGroup: [{ special: ['1', '2'] }],
override: {
classGroups: {
// ↓ Overriding existing class group
shadow: [{ shadow: ['100', '200', '300', '400', '500'] }],
},
}
extend: {
// ↓ Adding value to existing class group
animate: ['animate-magic'],
animate: ['animate-shimmer'],
// ↓ Adding new class group
prose: [{ prose: ['', validators.isTshirtSize] }],
},
}),
)
Expand Down
6 changes: 4 additions & 2 deletions docs/writing-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { mergeConfigs, validators, Config } from 'tailwind-merge'

export function withMagic(config: Config): Config {
return mergeConfigs(config, {
classGroups: {
'magic.my-group': [{ magic: [validators.isLength, 'wow'] }],
extend: {
classGroups: {
'magic.my-group': [{ magic: [validators.isLength, 'wow'] }],
},
},
})
}
Expand Down

0 comments on commit 1e6346b

Please sign in to comment.