Skip to content

Commit

Permalink
Merge pull request #348 from dcastil/feature/331/add-class-validator-…
Browse files Browse the repository at this point in the history
…type-to-lib-exports

Add `ClassValidator` type to pacakge exports
  • Loading branch information
dcastil authored Nov 18, 2023
2 parents 552d019 + b86b0df commit 9fdc590
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ function myWrappedTwMerge(...args: ClassNameValue[]) {
}
```
## `ClassValidator`
```ts
type ClassValidator = (value: string) => boolean
```
TypeScript type for class validators accepted in class definitions within [`extendTailwindMerge`](#extendtailwindmerge) and [`createTailwindMerge`](#createtailwindmerge).
---
Next: [Writing plugins](./writing-plugins.md)
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ export { fromTheme } from './lib/from-theme'
export { mergeConfigs } from './lib/merge-configs'
export { twJoin, type ClassNameValue } from './lib/tw-join'
export { twMerge } from './lib/tw-merge'
export { type Config, type DefaultClassGroupIds, type DefaultThemeGroupIds } from './lib/types'
export {
type ClassValidator,
type Config,
type DefaultClassGroupIds,
type DefaultThemeGroupIds,
} from './lib/types'
export * as validators from './lib/validators'
3 changes: 3 additions & 0 deletions tests/public-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ClassNameValue,
ClassValidator,
Config,
DefaultClassGroupIds,
DefaultThemeGroupIds,
Expand Down Expand Up @@ -40,12 +41,14 @@ test('has correct export types', () => {
const noRun = () => {
const config: Config<DefaultClassGroupIds, DefaultThemeGroupIds> = getDefaultConfig()
const classNameValue: ClassNameValue = 'some-class'
const classValidator: ClassValidator = (value: string) => false

twMerge(classNameValue, classNameValue, classNameValue)
twJoin(classNameValue, classNameValue, classNameValue)

return {
config,
classValidator,
}
}
})
Expand Down

0 comments on commit 9fdc590

Please sign in to comment.