Typed styled components for ReScript
styled-ppx is the ppx that brings typed styled components to ReScript, allowing you to create React Components with type-safe style definitions that look like good old CSS.
styled-ppx is built on top of emotion, so you can style your apps in a safe, familiar, and performant way.
module Center = %styled.div(`
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
`)
<Center>
{React.string("Hello from the future!")}
</Center>
module Center = %styled.div(`
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
`)
<Center>
{React.string("Hello from the future!")}
</Center>
Highlights:
- Type-safe CSS.
- Component-based styling.
- Implements utility helpers such as
classname
andcss
. - There's no abstraction over standard CSS - it's neither a new language nor a DSL.
- Supports the power of the underlying language: pattern-matching, composition, labelled arguments, etc.
- Built on top of emotion.
styled-ppx is a ppx. You can learn more about ppxs in Tarides blog: Introduction to OCaml ppx ecosystem. Generally speaking, they are similar to babel plugins. They run before the compilation of your code, and expands styled-ppx notations (e.g., %styled.div
%styled.div
or %cx
%cx
) into valid ReScript code.