All Projects β†’ davesnx β†’ Styled Ppx

davesnx / Styled Ppx

Licence: mit
Typed styled components in Reason, OCaml and ReScript

Programming Languages

ocaml
1615 projects
reason
219 projects
bucklescript
41 projects

Projects that are alternatives of or similar to Styled Ppx

Goober
πŸ₯œ goober, a less than 1KB πŸŽ‰ css-in-js alternative with a familiar API
Stars: ✭ 2,317 (+881.78%)
Mutual labels:  styled-components, css-in-js, emotion
Design System Utils
πŸ‘©β€πŸŽ¨ Access your design tokens with ease
Stars: ✭ 465 (+97.03%)
Mutual labels:  styled-components, css-in-js, emotion
Twin.macro
πŸ¦Ήβ€β™‚οΈ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, stitches and goober) at build time.
Stars: ✭ 5,137 (+2076.69%)
Mutual labels:  styled-components, css-in-js, emotion
React Next Boilerplate
πŸš€ A basis for reducing the configuration of your projects with nextJS, best development practices and popular libraries in the developer community.
Stars: ✭ 129 (-45.34%)
Mutual labels:  styled-components, css-in-js, emotion
Grid
This package has moved and renamed
Stars: ✭ 2,079 (+780.93%)
Mutual labels:  styled-components, css-in-js, emotion
Xstyled
A utility-first CSS-in-JS framework built for React. πŸ’…πŸ‘©β€πŸŽ€βš‘οΈ
Stars: ✭ 1,835 (+677.54%)
Mutual labels:  styled-components, css-in-js, emotion
Filbert Js
A lightweight(~1kb) css-in-js framework
Stars: ✭ 167 (-29.24%)
Mutual labels:  styled-components, css-in-js, emotion
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-77.97%)
Mutual labels:  styled-components, emotion, css-in-js
Horror
😱 React HTML elements with CSS-in-JS
Stars: ✭ 78 (-66.95%)
Mutual labels:  styled-components, css-in-js, emotion
Styled System
β¬’ Style props for rapid UI development
Stars: ✭ 7,126 (+2919.49%)
Mutual labels:  styled-components, css-in-js, emotion
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (+10.17%)
Mutual labels:  vscode-extension, styled-components, css-in-js
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (-57.2%)
Mutual labels:  styled-components, css-in-js, emotion
satchel
The little bag of CSS-in-JS superpowers
Stars: ✭ 14 (-94.07%)
Mutual labels:  styled-components, emotion, css-in-js
Next Dark Mode
πŸŒ‘ Enable dark mode for Next.js apps
Stars: ✭ 133 (-43.64%)
Mutual labels:  styled-components, css-in-js, emotion
Styled-Responsive-Media-Queries
Responsive Media Queries for Emotion styled or styled-components β€” Standard size from Chrome DevTools.
Stars: ✭ 33 (-86.02%)
Mutual labels:  styled-components, emotion, css-in-js
Styled Breakpoints
Simple and powerful tool for creating breakpoints in styled components and emotion. πŸ’…
Stars: ✭ 428 (+81.36%)
Mutual labels:  styled-components, css-in-js, emotion
Styled Tools
Useful interpolated functions for CSS-in-JS
Stars: ✭ 761 (+222.46%)
Mutual labels:  styled-components, css-in-js, emotion
Onno
Responsive style props for building themed design systems
Stars: ✭ 95 (-59.75%)
Mutual labels:  styled-components, css-in-js, emotion
Styled Components Vs Emotion
a short doc comparing the popular CSS-in-JS libraries styled-components and emotion
Stars: ✭ 204 (-13.56%)
Mutual labels:  styled-components, css-in-js, emotion
Scoped Style
A tiny css in js library πŸš€
Stars: ✭ 129 (-45.34%)
Mutual labels:  styled-components, css-in-js

styled-ppx CIComVer

styled-ppx is the ppx that enables CSS-in-Reason. Build on top of emotion, it allows you to style apps quickly, performant and as you always done it.

Allows you to create React Components with Type-safe CSS style definitions that don't rely on a specific DSL and great error messages:

BETA: This ppx is in an early stage ⚠️. Meaning that it doesn't support full functionality as emotion or styled-components. But you can safely use it, as it would respect Compatible Versioning. In case you want to know more, take a look at the ROADMAP, or feel free to chat on Discord: @davesnx#5641

Usage

styled-ppx implements a ppx that transforms [%styled] extensions points into [@react.components] modules with bs-emotion as styles, which does all the CSS-in-JS under the hood thanks to emotion.

This is how you can write components in ReasonML or OCaml with this ppx:

Standard styled component

module StyledComponent = [%styled.div
  {|
  align-items: center;
  display: flex;
  height: 100vh;
  justify-content: center;
  width: 100vw;
|}
];

ReactDOMRe.renderToElementWithId(
  <StyledComponent> {React.string("- Middle -")} </StyledComponent>,
  "app",
);

Dynamic styled component

module Dynamic = [%styled
  (~color, ~background) => {j|
  color: $color;
  background-color: $background;
|j}
];

ReactDOMRe.renderToElementWithId(
  <Dynamic color="#EB5757" background="#516CF0">
    {React.string("Hello!")}
  </Dynamic>,
  "app",
);

Inline css function

ReactDOMRe.renderToElementWithId(
  <span className=[%css "font-size: 32px"]> {React.string("Hello!")} </span>,
  "app",
);

For further detail, take a look in here.

Motivation

I love CSS and I'm coming from the JavaScript world: writing React with styled-components mostly. I found to be one of the best combos for writting scalable frontend applications. When I arrived to Reason wasn't a thing. Even people were asking for it (a few times).

So I took the time to create it with help from @jchavarri πŸ™Œ.

If you want to know more about how it works or what are the benefits I recommend to watch my talk at ReasonSTHLM Meetup

Installation

This package depends on bs-emotion, ReasonReact and BuckleScript, make sure you follow their installations.

With esy on native projects

esy add davesnx/styled-ppx

With npm or yarn on BuckleScript projects

yarn add @davesnx/styled-ppx @ahrefs/bs-emotion
# Or
npm install @davesnx/styled-ppx @ahrefs/bs-emotion

And add the PPX in your bsconfig.json file:

{
  "bs-dependencies": [
    "reason-react",
    "@ahrefs/bs-emotion"
  ],
  "ppx-flags": ["@davesnx/styled-ppx/styled-ppx"]
}

However, if you want to use esy in BuckleScript: Create an esy.json file with the content:

{
  "dependencies": {
    "styled-ppx": "*",
    "ocaml": "~4.6.1000"
  },
  "resolutions": {
    "styled-ppx": "davesnx/styled-ppx"
  }
}

And add the PPX in your bsconfig.json file:

{
  "ppx-flags": ["esy x styled-ppx.exe"]
}

If you want to try out of the box a project, just visit https://github.com/davesnx/try-styled-ppx and follow the instalation process there.

Editor Support

One of the fears of using a ppx is editor support, we belive that having compiling errors and syntax highlight would be an amazing experience. Install the VSCode extension:

VSCode Extension

  • If you are interested on another editor, please fill an issue and we would consider.

Thanks to

Thanks to Javier ChΓ‘varri, for helping me understand all the world of OCaml and his knowledge about ppx's. It has been a great experience. Inspired by @astrada bs-css-ppx and his CSS Parser. Thanks to ahrefs/bs-emotion and emotion.

Contributing

We would love your help improving styled-ppx, there's still a lot to do. The roadmap lives under the Projects in GitHub. Take a look, the tasks are well organized and clear for everybody to pick any!

You need esy, you can install the latest version from npm:

yarn global add [email protected]
# Or
npm install -g [email protected]

NOTE: Make sure esy --version returns at least 0.5.8 for this project to build.

Then run the esy command from this project root to install and build depenencies.

esy

Now you can run your editor within the environment (which also includes merlin):

esy $EDITOR
esy vim

After you make some changes to source code, you can re-run project's build again with the same simple esy command and run the native tests with

esy test

This project uses Dune as a build system, if you add a dependency in your package.json file, don't forget to add it to your dune and dune-project files too.

Running Tests

You can test compiled executable (runs scripts.tests specified in esy.json):

This will run the native unit test.

esy test

This tests only ensures that the output looks exactly as a snapshot, so their mission are to ensure the ppx transforms to a valid OCaml syntax.

If you want to run Bucklescript's integration test instead, you can do:

esy
cd test/bucklescript
yarn install
yarn build
yarn test

This tests are more like an end to end tests, that ensures that emotion have the correct methods for each CSS property.


Happy reasoning!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].