Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.36 KB | None | 0 0
  1. diff --git a/example/test.re b/example/test.re
  2. index b657ce1..b6fa6c8 100644
  3. --- a/example/test.re
  4. +++ b/example/test.re
  5. @@ -54,17 +54,20 @@ let rowLayout = Css.[display(flexBox), flexDirection(row), flexWrap(wrap)];
  6.  let mergedStyles = {
  7.    open Css;
  8.  
  9. -  let buttonStyles = [
  10. -    padding(px(5)),
  11. -    media("(min-width: 768px)", [padding(px(10))]),
  12. -  ];
  13. +  let paddingStyle = style([padding(px(5))]);
  14. +  let fontStyle = style([fontSize(px(14))]);
  15. +
  16. +  let buttonStyles = [media("(min-width: 768px)", [padding(px(10))])];
  17.  
  18.    let typographyStyles = [
  19. -    fontSize(px(14)),
  20.      media("(min-width: 768px)", [fontSize(px(16))]),
  21.    ];
  22.  
  23. -  style(merge([buttonStyles, typographyStyles]));
  24. +  mergeStyles([
  25. +    paddingStyle,
  26. +    fontStyle,
  27. +    styleList([buttonStyles, typographyStyles]),
  28. +  ]);
  29.  };
  30.  
  31.  let section =
  32. @@ -1146,6 +1149,7 @@ let tests =
  33.      <Section name="insertRule, the ultimate escape hatch">
  34.        <div className="raw-css" />
  35.      </Section>
  36. -    <Section name="merging styles"> <button className=mergedStyles >
  37. -    {text("Merged")} </button> </Section>
  38. -  </div>;
  39. +    <Section name="merging styles">
  40. +      <button className=mergedStyles> {text("Merged")} </button>
  41. +    </Section>
  42. +  </div>;
  43. \ No newline at end of file
  44. diff --git a/src/Css.re b/src/Css.re
  45. index b8a40f6..c47a45b 100644
  46. --- a/src/Css.re
  47. +++ b/src/Css.re
  48. @@ -3,14 +3,15 @@ include Css_Colors;
  49.  module Emotion = {
  50.    type css = string;
  51.    [@bs.module "emotion"] external _make: Js.Json.t => css = "css";
  52. +  [@bs.module "emotion"] external _makeArray: array(Js.Json.t) => css = "css";
  53.    [@bs.module "emotion"] external injectGlobal: Js.Json.t => unit = "";
  54.    [@bs.module "emotion"]
  55.    external rawInjectGlobal: string => unit = "injectGlobal";
  56.    [@bs.module "emotion"]
  57.    external makeKeyFrames: Js.Dict.t(Js.Json.t) => string = "keyframes";
  58. -  [@bs.module "emotion"] [@bs.splice]
  59. -  external merge: array(css) => css = "cx";
  60. -  let merge: list(css) => css = classes => classes->Array.of_list->merge;
  61. +  [@bs.module "emotion"] external cx: array(css) => css = "cx";
  62. +  let merge: list(css) => css = classes => classes->Array.of_list->cx;
  63. +
  64.    let rec makeDict = ruleset => {
  65.      let toJs = rule =>
  66.        switch (rule) {
  67. @@ -59,6 +60,9 @@ module Emotion = {
  68.    };
  69.  
  70.    let make = rules => rules |> makeDict |> _make;
  71. +
  72. +  let makeList = rulelist =>
  73. +    rulelist |> List.map(makeDict) |> Array.of_list |> _makeArray;
  74.  };
  75.  
  76.  let join = (separator, strings) => {
  77. @@ -321,6 +325,8 @@ type selector = [ | `selector(string, list(rule))];
  78.  let empty = [];
  79.  
  80.  let merge = List.concat;
  81. +let mergeStyles = Emotion.merge;
  82. +
  83.  let global = (selector, rules: list(rule)) =>
  84.    Emotion.injectGlobal(
  85.      [(selector, Emotion.makeDict(rules))]
  86. @@ -340,6 +346,7 @@ let keyframes = frames => {
  87.  };
  88.  
  89.  let style = rules => rules |> Emotion.make;
  90. +let styleList = Emotion.makeList;
  91.  
  92.  let d = (property, value) => `declaration((property, value));
  93.  
  94. diff --git a/src/Css.rei b/src/Css.rei
  95. index 252bc46..a92b74d 100644
  96. --- a/src/Css.rei
  97. +++ b/src/Css.rei
  98. @@ -8,7 +8,9 @@ type rule = [
  99.  
  100.  let empty: list(rule);
  101.  let merge: list(list(rule)) => list(rule);
  102. +let mergeStyles: list(string) => string;
  103.  let style: list(rule) => string;
  104. +let styleList: list(list(rule)) => string;
  105.  
  106.  let global: (string, list(rule)) => unit;
  107.  let insertRule: string => unit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement