Module: twind
Exports
tw
function
The This function is responsible for interpreting Twind rules and injecting CSS in the document.
apply
function
The This function generates one style object, combining all Tailwind rules by deep merging rules in order of declaration.
setup
function
The This optional function accepts a configuration object that allows you to change behaviors, themes, and more.
Table of contents
Interfaces
- Apply
- CSSCustomProperties
- CSSProperties
- CSSPseudos
- CSSRules
- CSSRulesThunk
- Configuration
- Context
- CorePlugins
- CounterStyle
- Directive
- DirectiveHandler
- FontFace
- InlineDirective
- Instance
- Mode
- Plugins
- Preflight
- Rule
- Sheet
- SheetConfig
- SheetInit
- TW
- TWCallable
- Theme
- ThemeColorObject
- ThemeConfiguration
- ThemeContainer
- ThemeHelper
- ThemeResolver
- ThemeSectionResolverContext
- TokenGrouping
- Variants
Type aliases
BlendMode
Ƭ BlendMode: normal | multiply | screen | overlay | darken | lighten | color-dodge | color-burn | hard-light | soft-light | difference | exclusion | hue | saturation | color | luminosity
Defined in: src/types/completion.ts:130
BorderStyle
Ƭ BorderStyle: solid | dashed | dotted | double | none
Defined in: src/types/completion.ts:126
CSSAtKeyframes
Ƭ CSSAtKeyframes: Record<string, CSSProperties | (context
: Context) => CSSProperties>
Defined in: src/types/twind.ts:227
CSSAtMedia
Ƭ CSSAtMedia: Record<string, MaybeArray<CSSRules>>
Defined in: src/types/twind.ts:225
CSSAtSupports
Ƭ CSSAtSupports: Record<string, MaybeArray<CSSRules>>
Defined in: src/types/twind.ts:226
CSSRuleValue
Ƭ CSSRuleValue: CSSAtMedia | CSSAtSupports | CSSAtKeyframes | CSSRulesThunk | MaybeArray<CSSProperties | CSSRules | FontFace | string | Falsy | TypescriptCompat>
Defined in: src/types/twind.ts:275
CSSSimplePseudos
Ƭ CSSSimplePseudos: { [K in CSS.SimplePseudos as `&${string & K}`]?: CSSRulesThunk | MaybeArray<CSSRules>}
Pseudo class watch out for ':root' - that could use '*' instead
Defined in: src/types/twind.ts:216
CompletionTokens
Ƭ CompletionTokens: CoreCompletionTokens | UserCompletionTokens
Defined in: src/types/completion.ts:555
CoreCompletionTokens
Ƭ CoreCompletionTokens: `${FromTheme<"screens">}:` | `${"" | "not-"}${SimplePseudoClasses}:` | `${Join<"group", "" | Interpolate<"string">>}-${SimplePseudoClasses}:` | `${SimplePseudoElements}::` | `${CoreVariants}:` | JoinFromObject<CorePlugins>
Defined in: src/types/completion.ts:543
CoreVariants
Ƭ CoreVariants: dark | sticky | motion-reduce | motion-safe | first | last | even | odd | children | siblings | sibling | override
Defined in: src/types/completion.ts:92
Corners
Ƭ Corners: t | r | b | l | tl | tr | bl | br
Defined in: src/types/completion.ts:124
DarkMode
Ƭ DarkMode: media | class | false
Defined in: src/types/twind.ts:82
Edges
Ƭ Edges: x | y | t | r | b | l | tl | tr | tb | bl | br | lr
Defined in: src/types/completion.ts:125
Empty
Ƭ Empty: never | ** | DEFAULT
Defined in: src/types/completion.ts:106
Falsy
Ƭ Falsy: ** | 0 | 0 | false | null | undefined | void
Defined in: src/types/util.ts:1
FromTheme
Ƭ FromTheme<Section>: Interpolate<`theme(${Section})`>
Type parameters:
Name | Type |
---|---|
Section | keyof Theme |
Defined in: src/types/completion.ts:29
GlobalValue
Ƭ GlobalValue: inherit | initial | unset
Defined in: src/types/completion.ts:128
Hasher
Ƭ Hasher: (value
: string) => string
Type declaration:
â–¸ (value
: string): string
Parameters:
Name | Type |
---|---|
value | string |
Returns: string
Defined in: src/types/twind.ts:80
Interpolate
Ƭ Interpolate<Kind>: `{​{${Kind}​}}`
Type parameters:
Name | Type |
---|---|
Kind | InterpolateKind |
Defined in: src/types/completion.ts:27
InterpolateKind
Ƭ InterpolateKind: `theme(${keyof Theme})` | `range(${number},${number},${number})` | string | number | nonzero
Defined in: src/types/completion.ts:18
Join
Ƭ Join<Prefix, Suffix, Separator>: Suffix extends Empty ? Prefix extends Empty ? never : Prefix : Prefix extends Empty ? Suffix : Prefix extends Suffix ? never : Suffix extends `-${infer S}` ? `-${Prefix}${Separator}${S}` : `${Prefix}${Separator}${Suffix}`
Type parameters:
Name | Type | Default |
---|---|---|
Prefix | string | never | - |
Suffix | string | never | - |
Separator | string | - |
Defined in: src/types/completion.ts:108
JoinFromObject
Ƭ JoinFromObject<T, Separator>: { [P in keyof T]: Join<ToString<P>, ToString<T[P]>, Separator>}[keyof T]
Type parameters:
Name | Type | Default |
---|---|---|
T | - | - |
Separator | string | - |
Defined in: src/types/completion.ts:529
MaybeArray
Ƭ MaybeArray<T>: T | readonly T[]
Type parameters:
Name |
---|
T |
Defined in: src/types/util.ts:3
MaybeObjInterpolationGeneric
Ƭ MaybeObjInterpolationGeneric<T>: T[] | [TemplateStringsArray, ...T[]]
Type parameters:
Name |
---|
T |
Defined in: src/types/twind.ts:7
MaybeThunk
Ƭ MaybeThunk<T>: T | (context
: Context) => T
Type parameters:
Name |
---|
T |
Defined in: src/types/twind.ts:39
MaybeTokenInterpolation
Ƭ MaybeTokenInterpolation: MaybeObjInterpolationGeneric<Token>
Defined in: src/types/twind.ts:8
Negatable
Ƭ Negatable<Value>: Value | `-${Value}`
Type parameters:
Name | Type |
---|---|
Value | string |
Defined in: src/types/completion.ts:37
NonEmptyString
Ƭ NonEmptyString: Interpolate<string>
Defined in: src/types/completion.ts:30
Plugin
Ƭ Plugin: string | CSSRules | DirectiveHandler
Defined in: src/types/twind.ts:154
Prefixer
Ƭ Prefixer: (property
: string, value
: string, important?
: boolean) => string
Type declaration:
â–¸ (property
: string, value
: string, important?
: boolean): string
Parameters:
Name | Type |
---|---|
property | string |
value | string |
important? | boolean |
Returns: string
Defined in: src/types/twind.ts:78
Range
Ƭ Range<From, To, Step>: Interpolate<`range(${From},${To},${Step})`>
Type parameters:
Name | Type | Default |
---|---|---|
From | number | - |
To | number | - |
Step | number | 1 |
Defined in: src/types/completion.ts:31
ReportInfo
Ƭ ReportInfo: { id
: LATE_SETUP_CALL } | { id
: UNKNOWN_DIRECTIVE ; rule
: string } | { id
: UNKNOWN_THEME_VALUE ; key
: string | undefined } | { css
: string ; error
: Error ; id
: INJECT_CSS_ERROR }
Defined in: src/types/twind.ts:129
SheetInitCallback
Ƭ SheetInitCallback<T>: (value?
: T) => T
Type parameters:
Name | Default |
---|---|
T | unknown |
Type declaration:
â–¸ (value?
: T): T
Parameters:
Name | Type |
---|---|
value? | T |
Returns: T
Defined in: src/types/twind.ts:69
SimplePseudoClasses
Ƭ SimplePseudoClasses: active | any-link | autofill | checked | default | disabled | empty | enabled | first-child | first-of-type | focus | focus-visible | focus-within | future | hover | in-range | indeterminate | invalid | last-child | last-of-type | link | local-link | only-child | only-of-type | optional | out-of-range | past | paused | placeholder-shown | playing | read-only | read-write | required | target | target-within | user-invalid | valid | visited
Defined in: src/types/completion.ts:39
SimplePseudoElements
Ƭ SimplePseudoElements: after | before | cue | cue-region | file-selector-button | first-letter | first-line | marker | placeholder | selection | target-text
Defined in: src/types/completion.ts:79
ThemeColor
Ƭ ThemeColor: string | ThemeColorObject
Defined in: src/types/theme.ts:100
ThemeFontSize
Ƭ ThemeFontSize: string | [size: string, lineHeight: string] | [size: string, options: object]
Defined in: src/types/theme.ts:102
ThemeOutline
Ƭ ThemeOutline: [outline: string, offset: string] | string[]
Defined in: src/types/theme.ts:107
ThemeScreen
Ƭ ThemeScreen: MaybeArray<ThemeScreenValue>
Defined in: src/types/theme.ts:93
ThemeScreenValue
Ƭ ThemeScreenValue: string | { raw
: string } | { max?
: string ; min
: string } | { max
: string ; min?
: string }
Defined in: src/types/theme.ts:87
ThemeSection
Ƭ ThemeSection<T>: ThemeSectionRecord<T> | ThemeSectionResolver<T>
Type parameters:
Name | Default |
---|---|
T | string |
Defined in: src/types/theme.ts:79
ThemeSectionRecord
Ƭ ThemeSectionRecord<T>: Record<string, T | undefined>
Type parameters:
Name | Default |
---|---|
T | string |
Defined in: src/types/theme.ts:72
ThemeSectionResolver
Ƭ ThemeSectionResolver<T>: (theme
: ThemeResolver, context
: ThemeSectionResolverContext) => ThemeSectionRecord<T>
Type parameters:
Name | Default |
---|---|
T | string |
Type declaration:
â–¸ (theme
: ThemeResolver, context
: ThemeSectionResolverContext): ThemeSectionRecord<T>
Parameters:
Name | Type |
---|---|
theme | ThemeResolver |
context | ThemeSectionResolverContext |
Returns: ThemeSectionRecord<T>
Defined in: src/types/theme.ts:74
ThemeSectionType
Ƭ ThemeSectionType<T>: T extends ThemeSection<infer R> ? Unwrap<R> : Exclude<T, ThemeSectionResolver<T>>
Type parameters:
Name |
---|
T |
Defined in: src/types/theme.ts:55
ToString
Ƭ ToString<T>: T extends string ? T : T extends number ? `${T}` : never
Type parameters:
Name |
---|
T |
Defined in: src/types/completion.ts:527
Token
Ƭ Token: Token[] | TokenGrouping | InlineDirective | string | Falsy | TypescriptCompat
Defined in: src/types/twind.ts:209
TypescriptCompat
Ƭ TypescriptCompat: boolean | number
Defined in: src/types/twind.ts:207
Unwrap
Ƭ Unwrap<T>: T extends string[] ? string : T extends Record<string, infer R> ? R : T
Type parameters:
Name |
---|
T |
Defined in: src/types/theme.ts:53
UserCompletionTokens
Ƭ UserCompletionTokens: { [K in keyof Variants]: `${ToString<K>}:`}[keyof Variants] | JoinFromObject<Plugins>
Defined in: src/types/completion.ts:551
Variables
silent
• Const
silent: Mode
Defined in: src/twind/modes.ts:24
strict
• Const
strict: Mode
Defined in: src/twind/modes.ts:20
tw
• tw: TW
warn
• Const
warn: Mode
Defined in: src/twind/modes.ts:18
Functions
apply
â–¸ Const
apply(strings
: TemplateStringsArray, ...interpolations
: Token[]): Directive<CSSRules>
Parameters:
Name | Type |
---|---|
strings | TemplateStringsArray |
...interpolations | Token[] |
Defined in: src/twind/apply.ts:15
â–¸ Const
apply(...tokens
: Token[]): Directive<CSSRules>
Parameters:
Name | Type |
---|---|
...tokens | Token[] |
Defined in: src/twind/apply.ts:15
autoprefix
â–¸ Const
autoprefix(property
: string, value
: string, important?
: boolean): string
Parameters:
Name | Type |
---|---|
property | string |
value | string |
important? | boolean |
Returns: string
Defined in: src/twind/prefix.ts:8
create
â–¸ Const
create(config?
: Configuration): Instance
Parameters:
Name | Type |
---|---|
config? | Configuration |
Returns: Instance
Defined in: src/twind/instance.ts:5
cssomSheet
â–¸ Const
cssomSheet(options?
: SheetConfig<CSSStyleSheet>): Sheet<CSSStyleSheet>
Creates an sheet which inserts style rules through the CSS Object Model.
Parameters:
Name | Type | Default value |
---|---|---|
options | SheetConfig<CSSStyleSheet> | {} |
Returns: Sheet<CSSStyleSheet>
Defined in: src/twind/sheets.ts:10
directive
â–¸ Const
directive<Data, T>(factory
: (data
: Data, context
: Context) => MaybeThunk<T>, data
: Data): Directive<T>
Returns an optimized and cached function for use with tw
.
tw
caches rules based on the function identity. This helper caches the function based on the data.
Type parameters:
Name |
---|
Data |
T |
Parameters:
Name | Type | Description |
---|---|---|
factory | (data : Data, context : Context) => MaybeThunk<T> | to use when the directive is invoked |
data | Data | to use |
Returns: Directive<T>
Defined in: src/twind/directive.ts:38
expandGroups
â–¸ Const
expandGroups(classNames
: string): string
Parameters:
Name | Type |
---|---|
classNames | string |
Returns: string
Defined in: src/twind/expand.ts:4
hash
â–¸ Const
hash(value
: string): string
Parameters:
Name | Type |
---|---|
value | string |
Returns: string
Defined in: src/internal/util.ts:120
mode
â–¸ Const
mode(report
: (message
: string) => void): Mode
Parameters:
Name | Type |
---|---|
report | (message : string) => void |
Returns: Mode
Defined in: src/twind/modes.ts:5
noprefix
â–¸ Const
noprefix(property
: string, value
: string, important?
: boolean): string
Parameters:
Name | Type |
---|---|
property | string |
value | string |
important? | boolean |
Returns: string
Defined in: src/twind/prefix.ts:5
setup
â–¸ setup(options?
: Configuration): void
Parameters:
Name | Type |
---|---|
options? | Configuration |
Returns: void
Defined in: src/types/twind.ts:36
theme
â–¸ Const
theme<Section>(section
: Section): function
Type parameters:
Name | Type |
---|---|
Section | colors | spacing | durations | screens | animation | backdropBlur | backdropBrightness | backdropContrast | backdropGrayscale | backdropHueRotate | backdropInvert | backdropOpacity | backdropSaturate | backdropSepia | backgroundColor | backgroundImage | backgroundOpacity | backgroundPosition | backgroundSize | blur | borderColor | borderOpacity | borderRadius | borderWidth | boxShadow | brightness | container | contrast | cursor | divideColor | divideOpacity | divideWidth | dropShadow | fill | flex | flexGrow | flexShrink | fontFamily | fontSize | fontWeight | gap | gradientColorStops | grayscale | gridAutoColumns | gridAutoRows | gridColumn | gridColumnEnd | gridColumnStart | gridRow | gridRowEnd | gridRowStart | gridTemplateColumns | gridTemplateRows | height | hueRotate | inset | invert | keyframes | letterSpacing | lineHeight | listStyleType | margin | maxHeight | maxWidth | minHeight | minWidth | objectPosition | opacity | order | outline | padding | placeholderColor | placeholderOpacity | ringColor | ringOffsetColor | ringOffsetWidth | ringOpacity | ringWidth | rotate | saturate | scale | sepia | skew | space | stroke | strokeWidth | textColor | textOpacity | transformOrigin | transitionDelay | transitionDuration | transitionProperty | transitionTimingFunction | translate | width | zIndex |
Parameters:
Name | Type |
---|---|
section | Section |
Returns: (context
: Context) => Record<string, ThemeSectionType<Theme[Section]>>
Defined in: src/twind/theme.ts:90
â–¸ Const
theme<Section>(keypath
: `${Section}.${string}`): function
Type parameters:
Name | Type |
---|---|
Section | colors | spacing | durations | screens | animation | backdropBlur | backdropBrightness | backdropContrast | backdropGrayscale | backdropHueRotate | backdropInvert | backdropOpacity | backdropSaturate | backdropSepia | backgroundColor | backgroundImage | backgroundOpacity | backgroundPosition | backgroundSize | blur | borderColor | borderOpacity | borderRadius | borderWidth | boxShadow | brightness | container | contrast | cursor | divideColor | divideOpacity | divideWidth | dropShadow | fill | flex | flexGrow | flexShrink | fontFamily | fontSize | fontWeight | gap | gradientColorStops | grayscale | gridAutoColumns | gridAutoRows | gridColumn | gridColumnEnd | gridColumnStart | gridRow | gridRowEnd | gridRowStart | gridTemplateColumns | gridTemplateRows | height | hueRotate | inset | invert | keyframes | letterSpacing | lineHeight | listStyleType | margin | maxHeight | maxWidth | minHeight | minWidth | objectPosition | opacity | order | outline | padding | placeholderColor | placeholderOpacity | ringColor | ringOffsetColor | ringOffsetWidth | ringOpacity | ringWidth | rotate | saturate | scale | sepia | skew | space | stroke | strokeWidth | textColor | textOpacity | transformOrigin | transitionDelay | transitionDuration | transitionProperty | transitionTimingFunction | translate | width | zIndex |
Parameters:
Name | Type |
---|---|
keypath | `${Section}.${string}` |
Returns: (context
: Context) => undefined | ThemeSectionType<Theme[Section]>
Defined in: src/twind/theme.ts:90
â–¸ Const
theme<Section>(keypath
: `${Section}.${string}`, defaultValue
: NonNullable<ThemeSectionType<Theme[Section]>>): function
Type parameters:
Name | Type |
---|---|
Section | colors | spacing | durations | screens | animation | backdropBlur | backdropBrightness | backdropContrast | backdropGrayscale | backdropHueRotate | backdropInvert | backdropOpacity | backdropSaturate | backdropSepia | backgroundColor | backgroundImage | backgroundOpacity | backgroundPosition | backgroundSize | blur | borderColor | borderOpacity | borderRadius | borderWidth | boxShadow | brightness | container | contrast | cursor | divideColor | divideOpacity | divideWidth | dropShadow | fill | flex | flexGrow | flexShrink | fontFamily | fontSize | fontWeight | gap | gradientColorStops | grayscale | gridAutoColumns | gridAutoRows | gridColumn | gridColumnEnd | gridColumnStart | gridRow | gridRowEnd | gridRowStart | gridTemplateColumns | gridTemplateRows | height | hueRotate | inset | invert | keyframes | letterSpacing | lineHeight | listStyleType | margin | maxHeight | maxWidth | minHeight | minWidth | objectPosition | opacity | order | outline | padding | placeholderColor | placeholderOpacity | ringColor | ringOffsetColor | ringOffsetWidth | ringOpacity | ringWidth | rotate | saturate | scale | sepia | skew | space | stroke | strokeWidth | textColor | textOpacity | transformOrigin | transitionDelay | transitionDuration | transitionProperty | transitionTimingFunction | translate | width | zIndex |
Parameters:
Name | Type |
---|---|
keypath | `${Section}.${string}` |
defaultValue | NonNullable<ThemeSectionType<Theme[Section]>> |
Returns: (context
: Context) => NonNullable<ThemeSectionType<Theme[Section]>>
Defined in: src/twind/theme.ts:90
â–¸ Const
theme<Section>(section
: Section, key
: string | string[]): function
Type parameters:
Name | Type |
---|---|
Section | colors | spacing | durations | screens | animation | backdropBlur | backdropBrightness | backdropContrast | backdropGrayscale | backdropHueRotate | backdropInvert | backdropOpacity | backdropSaturate | backdropSepia | backgroundColor | backgroundImage | backgroundOpacity | backgroundPosition | backgroundSize | blur | borderColor | borderOpacity | borderRadius | borderWidth | boxShadow | brightness | container | contrast | cursor | divideColor | divideOpacity | divideWidth | dropShadow | fill | flex | flexGrow | flexShrink | fontFamily | fontSize | fontWeight | gap | gradientColorStops | grayscale | gridAutoColumns | gridAutoRows | gridColumn | gridColumnEnd | gridColumnStart | gridRow | gridRowEnd | gridRowStart | gridTemplateColumns | gridTemplateRows | height | hueRotate | inset | invert | keyframes | letterSpacing | lineHeight | listStyleType | margin | maxHeight | maxWidth | minHeight | minWidth | objectPosition | opacity | order | outline | padding | placeholderColor | placeholderOpacity | ringColor | ringOffsetColor | ringOffsetWidth | ringOpacity | ringWidth | rotate | saturate | scale | sepia | skew | space | stroke | strokeWidth | textColor | textOpacity | transformOrigin | transitionDelay | transitionDuration | transitionProperty | transitionTimingFunction | translate | width | zIndex |
Parameters:
Name | Type |
---|---|
section | Section |
key | string | string[] |
Returns: (context
: Context) => undefined | ThemeSectionType<Theme[Section]>
Defined in: src/twind/theme.ts:90
â–¸ Const
theme<Section>(section
: Section, key
: string | string[], defaultValue
: NonNullable<ThemeSectionType<Theme[Section]>>): function
Type parameters:
Name | Type |
---|---|
Section | colors | spacing | durations | screens | animation | backdropBlur | backdropBrightness | backdropContrast | backdropGrayscale | backdropHueRotate | backdropInvert | backdropOpacity | backdropSaturate | backdropSepia | backgroundColor | backgroundImage | backgroundOpacity | backgroundPosition | backgroundSize | blur | borderColor | borderOpacity | borderRadius | borderWidth | boxShadow | brightness | container | contrast | cursor | divideColor | divideOpacity | divideWidth | dropShadow | fill | flex | flexGrow | flexShrink | fontFamily | fontSize | fontWeight | gap | gradientColorStops | grayscale | gridAutoColumns | gridAutoRows | gridColumn | gridColumnEnd | gridColumnStart | gridRow | gridRowEnd | gridRowStart | gridTemplateColumns | gridTemplateRows | height | hueRotate | inset | invert | keyframes | letterSpacing | lineHeight | listStyleType | margin | maxHeight | maxWidth | minHeight | minWidth | objectPosition | opacity | order | outline | padding | placeholderColor | placeholderOpacity | ringColor | ringOffsetColor | ringOffsetWidth | ringOpacity | ringWidth | rotate | saturate | scale | sepia | skew | space | stroke | strokeWidth | textColor | textOpacity | transformOrigin | transitionDelay | transitionDuration | transitionProperty | transitionTimingFunction | translate | width | zIndex |
Parameters:
Name | Type |
---|---|
section | Section |
key | string | string[] |
defaultValue | NonNullable<ThemeSectionType<Theme[Section]>> |
Returns: (context
: Context) => NonNullable<ThemeSectionType<Theme[Section]>>
Defined in: src/twind/theme.ts:90
voidSheet
â–¸ Const
voidSheet(): Sheet<null>
An sheet placeholder which performs no operations. Useful for avoiding errors in a non-browser environment.
Returns: Sheet<null>
Defined in: src/twind/sheets.ts:25