props
API reference for the `props` function
The css.props()
function returns styleObject
as hashedClassName
together while filtering out falsy values like undefined
, false
, or null
. It is useful when conditionally combining styles.
Prohibit intermediate code
Props compilation is performed by strictly deleting all intermediate code except import
css.create()
css.props()
.
For example, if you define and use a global variable like the following, a reference error will occur because the variable will be deleted during the compilation phase.
If you want to define a variable and use intermediate code, you can assign a value directly or via an import statement.
or
or
Therefore, keyframes()
etc. cannot be defined in the same file scope as props and must be saved as files and used via import.
Extract
The following is extracted at compile time and executed as ts code. (Vue and Svelte also execute as ts.)
Usage Patterns
Conditional styles
Only truthy values are preserved.
With ternary
Return value
Returns a single hashes string of space-separated styleObject, ignoring falsy inputs:
See Also
Good to know
Since falsy values are filtered out, you can use logical and, ternary
operators, etc. in argument expressions.
Nested ternary operators are not supported as this would require complex parsing.