Skip to content

Commit

Permalink
Merge pull request facebook#112 from reasonml-community/new-styles-ap…
Browse files Browse the repository at this point in the history
…i-fix-pct-margin-padding

Support % for margin
  • Loading branch information
wokalski authored Dec 12, 2017
2 parents e0688cc + a24d32a commit 4ca27df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
24 changes: 13 additions & 11 deletions lib/js/src/style.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/style.re
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ let encode_pt_pct = (value) =>
| Pct(pct) => Encode.pct(pct)
};

type pt_auto =
type pt_pct_auto =
| Pt(float)
| Pct(float)
| Auto;

let encode_pt_auto = (value) =>
let encode_pt_pct_auto = (value) =>
switch value {
| Pt(value) => Encode.float(value)
| Pt(pt) => Encode.float(pt)
| Pct(pct) => Encode.pct(pct)
| Auto => Encode.string("auto")
};

Expand Down Expand Up @@ -221,19 +223,19 @@ let justifyContent = (v) =>
}
);

let margin = (value) => ("margin", encode_pt_auto(value));
let margin = (value) => ("margin", encode_pt_pct_auto(value));

let marginBottom = (value) => ("marginBottom", encode_pt_auto(value));
let marginBottom = (value) => ("marginBottom", encode_pt_pct_auto(value));

let marginHorizontal = (value) => ("marginHorizontal", encode_pt_auto(value));
let marginHorizontal = (value) => ("marginHorizontal", encode_pt_pct_auto(value));

let marginLeft = (value) => ("marginLeft", encode_pt_auto(value));
let marginLeft = (value) => ("marginLeft", encode_pt_pct_auto(value));

let marginRight = (value) => ("marginRight", encode_pt_auto(value));
let marginRight = (value) => ("marginRight", encode_pt_pct_auto(value));

let marginTop = (value) => ("marginTop", encode_pt_auto(value));
let marginTop = (value) => ("marginTop", encode_pt_pct_auto(value));

let marginVertical = (value) => ("marginVertical", encode_pt_auto(value));
let marginVertical = (value) => ("marginVertical", encode_pt_pct_auto(value));

let maxHeight = (value) => ("maxHeight", encode_pt_pct(value));

Expand Down
17 changes: 9 additions & 8 deletions src/style.rei
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ type pt_pct =
| Pt(float)
| Pct(float);

type pt_auto =
type pt_pct_auto =
| Pt(float)
| Pct(float)
| Auto;

type pt_pct_animated_interpolated =
Expand Down Expand Up @@ -119,19 +120,19 @@ type justifyContent =

let justifyContent: justifyContent => styleElement;

let margin: pt_auto => styleElement;
let margin: pt_pct_auto => styleElement;

let marginBottom: pt_auto => styleElement;
let marginBottom: pt_pct_auto => styleElement;

let marginHorizontal: pt_auto => styleElement;
let marginHorizontal: pt_pct_auto => styleElement;

let marginLeft: pt_auto => styleElement;
let marginLeft: pt_pct_auto => styleElement;

let marginRight: pt_auto => styleElement;
let marginRight: pt_pct_auto => styleElement;

let marginTop: pt_auto => styleElement;
let marginTop: pt_pct_auto => styleElement;

let marginVertical: pt_auto => styleElement;
let marginVertical: pt_pct_auto => styleElement;

let maxHeight: pt_pct => styleElement;

Expand Down
4 changes: 2 additions & 2 deletions upgrade_scripts/styles_v1_to_v2/styles_v1_to_v2.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Replacements = {
("padding", ["", "Horizontal", "Vertical", "Left", "Right", "Bottom", "Top"])
]);
let pt_pct_animated_interpolated = ["height", "width", "top", "bottom", "left", "right"];
let pt_auto =
let pt_pct_auto =
combine([("margin", ["", "Bottom", "Top", "Right", "Left", "Horizontal", "Vertical"])]);
let variantReplacements = [
("flexStart", "FlexStart"),
Expand Down Expand Up @@ -57,7 +57,7 @@ module Replacements = {
("nowrap", "Nowrap")
];
let suffix_pt =
pt_auto @ pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix, prefix));
pt_pct_auto @ pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix, prefix));
let suffix_pct =
pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix ++ "Pct", prefix));
let suffix_animated =
Expand Down

0 comments on commit 4ca27df

Please sign in to comment.