{"_id":"@bikallem/bs-emotion","_rev":"1-8bb615ab1d80984466b6e93cde5c99ea","name":"@bikallem/bs-emotion","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@bikallem/bs-emotion","version":"1.0.1","description":"BuckleScript bindings to Emotion","author":{"name":"Alex Fedoseev","email":"alex.fedoseev@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/ahrefs/bs-emotion.git"},"main":"src/Emotion.re","scripts":{"start":"bsb -clean-world -make-world -w","build":"bsb -clean-world -make-world","test":"exit 0"},"peerDependencies":{"bs-platform":"^7.0.1"},"dependencies":{"@minima.app/re-css":"0.1.0","emotion":"9.2.12"},"devDependencies":{"bs-platform":"7.0.1"},"keywords":["css","css-in-js","react","emotion","reason","reasonml","ocaml","bucklescript"],"bugs":{"url":"https://github.com/ahrefs/bs-emotion/issues"},"homepage":"https://github.com/ahrefs/bs-emotion#readme","_id":"@bikallem/bs-emotion@1.0.1","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-ofishjKSy7gjoa3s2O9VGgn6niDIV86s6Z2JzFJ7hVM3cpyc/UPm2kwjQy+hdDNG26Ipu2nb0yy8dl7uoeVaBg==","shasum":"d44acff678eff461eac590048fd2aad8328fcbeb","tarball":"https://registry.npmjs.org/@bikallem/bs-emotion/-/bs-emotion-1.0.1.tgz","fileCount":7,"unpackedSize":104545,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd/AxnCRA9TVsSAnZWagAAMHkP+wRAiyZXOfGacuhyYD3I\nvq9281mvNJ9kA6PSmOYH6kZJLoiEp0r190GqTWnjOFtYUrWnAepX1ShLbFPQ\nfzZk86ikF63bShws5/19XpVApXxmFnOt9aWihadzbijwyZ1qVbKC+GfYz2w7\nAnplISF3DtB4+92TJNzjeYRMVaV4QsMt/Dn8CWPLmkqCoJTE6ytZ0roNN8Tf\nB/Cn5OhN1W45pMgC9u8MICfDllBcF0bVHB90L3386oqoOrt0cLliZIBh3C2h\nydMwNnePATCpefhApLX4vnv0BoC88gh/Bh5mvgOdTAroRJLhqQl4qkugWFUy\nQh8h1B8IzGlQMKYbbdDKYPHP92dl8nAHuyieVXyQZVJy1N6P1yX4tV6QXhou\nCGZQTMO6g+Hq15QVMNtZRX0SjytIKs5XQ9RUe/2fzyywOwmNPsrEb+FW/lzp\nXYrTIaKI+oOvEEWSM3UmpZIioWYOKdTgue1oQujNpLdAXHvU/XXrlvODz5Jb\n4sSJE7wUzKcNr15Tj3sM1Iz/lQl3HwK26ML/dBL+sFKNAAo1cY7d6ccT9UPy\nNWqBRA5zabhudvUKQ63GZvNR/hv/an3TGTMmnMjraUJAd8rUQD033gQp48ai\nHDW7w0M200E1vHKBzNcGXUhU+6bm9eOM3qmOkvNlwEaFdVVqktwtvdoXKLm+\nfgSa\r\n=YpBO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDKqLKXIh8W2efwKU7r+kWGCTAkMrokfp2NYwhfXBepsAiEAk7wksHw4rhWN1n92O7xZRuqymWi1aonGBk5at5k6DwA="}]},"maintainers":[{"name":"bikallem","email":"gbikal@gmail.com"}],"_npmUser":{"name":"bikallem","email":"gbikal@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bs-emotion_1.0.1_1576799335258_0.2197244192212604"},"_hasShrinkwrap":false}},"time":{"created":"2019-12-19T23:48:55.227Z","1.0.1":"2019-12-19T23:48:55.483Z","modified":"2022-04-04T18:47:50.055Z"},"maintainers":[{"name":"bikallem","email":"gbikal@gmail.com"}],"description":"BuckleScript bindings to Emotion","homepage":"https://github.com/ahrefs/bs-emotion#readme","keywords":["css","css-in-js","react","emotion","reason","reasonml","ocaml","bucklescript"],"repository":{"type":"git","url":"git+https://github.com/ahrefs/bs-emotion.git"},"author":{"name":"Alex Fedoseev","email":"alex.fedoseev@gmail.com"},"bugs":{"url":"https://github.com/ahrefs/bs-emotion/issues"},"license":"MIT","readme":"# bs-emotion\n\n[![Build Status](https://dev.azure.com/igor0048/ahrefs/_apis/build/status/ahrefs.bs-emotion?branchName=master)](https://dev.azure.com/igor0048/ahrefs/_build/latest?definitionId=1&branchName=master)\n\nBuckleScript bindings to [Emotion](https://emotion.sh).\n\n## BuckleScript v7+\n\n`bs-emotion` and `bs-emotion-ppx` are compatible with BuckleScript v7 starting from version 1.0.0.\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/bin/bs-emotion-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 [ ... ]] (* -> \"css-HASHED-button\" *)\n\n(* If you don't use ppx *)\nlet button = css [ ... ] (* -> \"css-HASHED\" *)\n```\n\nAnd here's real-world example:\n> 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 & 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 &|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 = _ => {\n  ...component,\n  render: _ => <div className=Css.container> ... </div>,\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]) /* => \"css-<HASH>-one css-<HASH>-two\" */\nCx.merge([|Css.one, Css.two|]) /* => \"css-<HASH>-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<div className={Cx.merge([|Css.foo, Css.bar|])}>\n  <button className=Css.button />\n</div>\n```\n\n```ocaml\nlet foo = css [ ... ]\nlet bar = css [ ... ]\n\nlet button = css [\n  ...\n\n  select {j|.$foo:hover &|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<div className={Cn.make([Css.foo, Css.bar])} />\n```\n\n##### Caveat #2\n\n```reason\nlet make = (~className, children) => {\n  ...component,\n  render: _ =>\n    <div className={Cn.make([Css.foo, className])}>\n      ...children\n    </div>,\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<div className={Cx.merge([|Css.foo, className|])} />\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","readmeFilename":"README.md"}