Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClassValidator type to package exports #348

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading