styl() Function
The styl() function is an alternative to the styleName prop that returns props to spread onto a component.
When to Use
Use styl() instead of styleName when you need to:
- Pass inline
stylealongside class-based styles - Pass part styles (like
titleStyle,iconStyle) to child components - Spread props onto a component that doesn't support
styleNamedirectly
Signature
Parameters:
styleName- Class names to apply (same syntax as thestyleNameprop)inlineStyles- Optional object withstyleand/or part styles
Returns: An object with style and any part style props, ready to spread.
Basic Usage
This is equivalent to:
With Array/Object Syntax
The first argument supports the same syntax as styleName:
With Inline Styles
Pass a second argument to include inline styles:
The inline style is merged with the class-based styles, with inline styles taking priority.
With Part Styles
When using components that expose parts, pass part styles in the second argument:
The part styles from both class selectors (.card:part(title)) and inline (titleStyle) are merged together.
Combining with Props
A common pattern is combining styl() with other props:
Style Arrays
Both style and part styles support arrays:
Comparison with styleName
Use styleName for simple cases. Use styl() when you need to combine class-based styles with inline styles or part styles in a single expression.