{"id":13726643,"url":"https://github.com/ahrefs/bs-emotion","last_synced_at":"2025-10-04T21:30:29.624Z","repository":{"id":33272228,"uuid":"155689515","full_name":"ahrefs/bs-emotion","owner":"ahrefs","description":"BuckleScript bindings to Emotion","archived":true,"fork":false,"pushed_at":"2023-05-02T15:22:55.000Z","size":1071,"stargazers_count":121,"open_issues_count":18,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-25T23:11:20.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Reason","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahrefs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-11-01T09:09:44.000Z","updated_at":"2024-08-12T19:42:55.000Z","dependencies_parsed_at":"2024-01-10T19:10:57.829Z","dependency_job_id":null,"html_url":"https://github.com/ahrefs/bs-emotion","commit_stats":{"total_commits":179,"total_committers":12,"mean_commits":"14.916666666666666","dds":0.5083798882681565,"last_synced_commit":"359524038c8c65e11c3c29d55864d33563b158b6"},"previous_names":["alexfedoseev/bs-emotion"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fbs-emotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fbs-emotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fbs-emotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fbs-emotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahrefs","download_url":"https://codeload.github.com/ahrefs/bs-emotion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219876757,"owners_count":16554786,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:03:15.495Z","updated_at":"2025-10-04T21:30:24.258Z","avatar_url":"https://github.com/ahrefs.png","language":"Reason","funding_links":[],"categories":["Reason"],"sub_categories":[],"readme":"# bs-emotion\n\n\u003e **Warning**\n\u003e This repository is no longer maintained, as we don't use it anymore at Ahrefs. For alternatives, check [styled-ppx](https://github.com/davesnx/styled-ppx/) or [bs-css](https://github.com/giraud/bs-css).\n\n\u003ca href=\"https://github.com/ahrefs/bs-emotion/actions?query=workflow%3A%22Build+bs-emotion%22\"\u003e\u003cimg alt=\"bs-emotion status\" src=\"https://github.com/ahrefs/bs-emotion/workflows/Build%20bs-emotion/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/ahrefs/bs-emotion/actions?query=workflow%3A%22Build+bs-emotion-ppx%22\"\u003e\u003cimg alt=\"bs-emotion-ppx status\" src=\"https://github.com/ahrefs/bs-emotion/workflows/Build%20bs-emotion-ppx/badge.svg\"\u003e\u003c/a\u003e\n\nBuckleScript bindings to [Emotion](https://emotion.sh).\n\n## BuckleScript v8+\n\n`bs-emotion` and `bs-emotion-ppx` are compatible with BuckleScript v7 starting from version 2.0.0.\n\n## Previous versions\n\nUse v1.0.1 if you need compatibility with BuckleScript v7.\n\nIf you need to use them with BuckleScript v5 or below, install the earlier versions:\n- `@ahrefs/bs-emotion` version ^0.1.2\n- `@ahrefs/bs-emotion-ppx` version ^0.0.7\n\n## Installation\nGet the package:\n\n```shell\n# yarn\nyarn add @ahrefs/bs-emotion\n# or npm\nnpm install --save @ahrefs/bs-emotion\n```\n\nThen add it to `bsconfig.json`:\n\n```json\n\"bs-dependencies\": [\n  \"@ahrefs/bs-emotion\"\n]\n```\n\n### `bs-emotion-ppx`\nIf you want to auto-label generated classnames for easier debugging, you can install `bs-emotion-ppx`:\n\n```shell\n# yarn\nyarn add --dev @ahrefs/bs-emotion-ppx\n# or npm\nnpm install --save-dev @ahrefs/bs-emotion-ppx\n```\n\nThen add it to `bsconfig.json`:\n\n```json\n\"ppx-flags\": [\"@ahrefs/bs-emotion-ppx/ppx -as-ppx\"],\n```\n\n## Usage\n### Defining styles\nThere are 2 ways to define a CSS class:\n\n```ocaml\nopen Emotion\n\n(* If you use ppx *)\nlet button = [%css [ ... ]] (* -\u003e \"css-HASHED-button\" *)\n\n(* If you don't use ppx *)\nlet button = css [ ... ] (* -\u003e \"css-HASHED\" *)\n```\n\nAnd here's real-world example:\n\u003e It's in OCaml syntax, but you can use Reason too.\n\n```ocaml\n(* ComponentStyles.ml *)\n\nopen Emotion\n\nlet container = [%css [\n  display `flex;\n  flexFlow `column `nowrap;\n  alignItems `center;\n]]\n\nlet shape = [%css [\n  display `flex;\n  flexFlow `row `nowrap;\n  alignItems `center;\n  justifyContent `center;\n  transitionProperty \"border-radius\";\n  transitionDuration (`ms 100);\n  transitionTimingFunction `easeInOut;\n  width (`px 200);\n  height (`px 200);\n  borderRadius (`px 6);\n  backgroundColor (`hex \"29d\");\n\n  (* :hover selector, same as `select \":hover\" [ ... ]` *)\n  hover [\n    borderRadius (`pct 50.);\n    important (cursor `grab);\n  ];\n]]\n\n(* Dynamic styling *)\n(* NOTE: ppx supports functions with max 2 arguments *)\nlet text ~size = [%css [\n  color (`hex \"fff\");\n  fontSize (`px size);\n  fontWeight 700;\n\n  (* Transition takes property, duration, timing-function \u0026 delay *)\n  transition \"font-size\" (`ms 100) `easeInOut `zero;\n\n  (* You can define multiple transitions by packing them into list of tuples *)\n  transitions [\n    (\"font-size\", `ms 100, `easeInOut, `ms 0);\n  ];\n\n  (* Complex selector that uses .container class defined above *)\n  (* Rendered as: `.container:hover .text {...}` *)\n  select {j|.$container:hover \u0026|j} [\n    fontSize Calc.(((`px size) + (`pct 150.)) * (`n 1.5));\n  ];\n\n  (* @media quiery with nested selectors *)\n  media \"(max-width: 900px)\" [\n    color (`hex \"ff69b4\");\n\n    select \":hover\" [\n      color (`hex \"fff\");\n    ];\n  ];\n]]\n\n(* Define keyframes *)\nlet bounce = keyframes [\n  (0,   [ transform (`translateY `zero); ]);\n  (50,  [ transform (`translateY (`px (-20))); ]);\n  (100, [ transform (`translateY `zero); ]);\n]\n\nlet animated = [%css [\n  (* Use generated animation name *)\n  animationName bounce;\n  animationDuration (`ms 300);\n  animationIterationCount (`i 7);\n]]\n\n(* Compose things *)\nlet smallText = [%css [\n  fontSize (`em 0.8);\n]]\n\nlet note = css ~extend: smallText [\n  label \"note\";\n\n  marginTop (`px 10);\n]\n```\n\n### Applying styles\n```reason\n/* Component.re */\n\nmodule Css = ComponentStyles;\n\nlet component = ReasonReact.statelessComponent(__MODULE__);\n\nlet make = _ =\u003e {\n  ...component,\n  render: _ =\u003e \u003cdiv className=Css.container\u003e ... \u003c/div\u003e,\n};\n```\n\n### Composing classnames\n\n#### Cx\nThis package provides `Cx.merge` function which is a binding to Emotion's [`cx`](https://emotion.sh/docs/cx). It merges 2 Emotion's CSS classes into single unique class. See the [Caveats](#caveats) section for details.\n\n#### Cn\nAlso, there is [`re-classnames`](https://github.com/alexfedoseev/re-classnames). You can use it to combine classnames together. It's not aware of Emotion and simply operates on strings.\n\n#### Caveats\nFirst, let's talk about the difference between `Cn.make` and `Cx.merge`:\n\n```reason\nCn.make([Css.one, Css.two]) /* =\u003e \"css-\u003cHASH\u003e-one css-\u003cHASH\u003e-two\" */\nCx.merge([|Css.one, Css.two|]) /* =\u003e \"css-\u003cHASH\u003e-one-two\" */\n```\n\nIf the former simply concatenates two classname strings into a single string (and as a result 2 CSS classes are applied) then the latter merges 2 Emotion classes into single unique class and applies it to a node (as a result 1 unique CSS class is applied).\n\n##### Caveat #1\n\n```reason\n\u003cdiv className={Cx.merge([|Css.foo, Css.bar|])}\u003e\n  \u003cbutton className=Css.button /\u003e\n\u003c/div\u003e\n```\n\n```ocaml\nlet foo = css [ ... ]\nlet bar = css [ ... ]\n\nlet button = css [\n  ...\n\n  select {j|.$foo:hover \u0026|j} [\n    (*\n      It won't work due to `.foo` class is being merged w/ `.bar`\n      into single unique classname inside component\n    *)\n  ]\n]\n```\n\nTo make this css work you can use `Cn.make`, e.g:\n\n```reason\n\u003cdiv className={Cn.make([Css.foo, Css.bar])} /\u003e\n```\n\n##### Caveat #2\n\n```reason\nlet make = (~className, children) =\u003e {\n  ...component,\n  render: _ =\u003e\n    \u003cdiv className={Cn.make([Css.foo, className])}\u003e\n      ...children\n    \u003c/div\u003e,\n};\n```\n\nOftentimes, UI abstractions accept `className` prop to extend or override default CSS of abstraction. Since position of classname on application site doesn't guarantee precedence of `className` prop (in CSS, precedence is determined by position of classname on definition site), it's not safe to use `Cn.make` here. In this case, use `Cx.merge` since `Emotion` determines precedence on application site and guarantees that last classname has precedence over the preceding classes.\n\n```reason\n\u003cdiv className={Cx.merge([|Css.foo, className|])} /\u003e\n```\n\n## Contributing\n\nSee [`CONTRIBUTING.md`](./CONTRIBUTING.md).\n\n## Thanks\n- [`glennsl/bs-typed-css-core`](https://github.com/glennsl/bs-typed-css-core) and [`SentiaAnalytics/bs-css`](https://github.com/SentiaAnalytics/bs-css) for examples and inspiration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fbs-emotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahrefs%2Fbs-emotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fbs-emotion/lists"}