Skip to content

Commit 4ca27df

Browse files
authored
Merge pull request facebook#112 from reasonml-community/new-styles-api-fix-pct-margin-padding
Support % for margin
2 parents e0688cc + a24d32a commit 4ca27df

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

lib/js/src/style.js

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/style.re

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ let encode_pt_pct = (value) =>
1212
| Pct(pct) => Encode.pct(pct)
1313
};
1414

15-
type pt_auto =
15+
type pt_pct_auto =
1616
| Pt(float)
17+
| Pct(float)
1718
| Auto;
1819

19-
let encode_pt_auto = (value) =>
20+
let encode_pt_pct_auto = (value) =>
2021
switch value {
21-
| Pt(value) => Encode.float(value)
22+
| Pt(pt) => Encode.float(pt)
23+
| Pct(pct) => Encode.pct(pct)
2224
| Auto => Encode.string("auto")
2325
};
2426

@@ -221,19 +223,19 @@ let justifyContent = (v) =>
221223
}
222224
);
223225

224-
let margin = (value) => ("margin", encode_pt_auto(value));
226+
let margin = (value) => ("margin", encode_pt_pct_auto(value));
225227

226-
let marginBottom = (value) => ("marginBottom", encode_pt_auto(value));
228+
let marginBottom = (value) => ("marginBottom", encode_pt_pct_auto(value));
227229

228-
let marginHorizontal = (value) => ("marginHorizontal", encode_pt_auto(value));
230+
let marginHorizontal = (value) => ("marginHorizontal", encode_pt_pct_auto(value));
229231

230-
let marginLeft = (value) => ("marginLeft", encode_pt_auto(value));
232+
let marginLeft = (value) => ("marginLeft", encode_pt_pct_auto(value));
231233

232-
let marginRight = (value) => ("marginRight", encode_pt_auto(value));
234+
let marginRight = (value) => ("marginRight", encode_pt_pct_auto(value));
233235

234-
let marginTop = (value) => ("marginTop", encode_pt_auto(value));
236+
let marginTop = (value) => ("marginTop", encode_pt_pct_auto(value));
235237

236-
let marginVertical = (value) => ("marginVertical", encode_pt_auto(value));
238+
let marginVertical = (value) => ("marginVertical", encode_pt_pct_auto(value));
237239

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

src/style.rei

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ type pt_pct =
66
| Pt(float)
77
| Pct(float);
88

9-
type pt_auto =
9+
type pt_pct_auto =
1010
| Pt(float)
11+
| Pct(float)
1112
| Auto;
1213

1314
type pt_pct_animated_interpolated =
@@ -119,19 +120,19 @@ type justifyContent =
119120

120121
let justifyContent: justifyContent => styleElement;
121122

122-
let margin: pt_auto => styleElement;
123+
let margin: pt_pct_auto => styleElement;
123124

124-
let marginBottom: pt_auto => styleElement;
125+
let marginBottom: pt_pct_auto => styleElement;
125126

126-
let marginHorizontal: pt_auto => styleElement;
127+
let marginHorizontal: pt_pct_auto => styleElement;
127128

128-
let marginLeft: pt_auto => styleElement;
129+
let marginLeft: pt_pct_auto => styleElement;
129130

130-
let marginRight: pt_auto => styleElement;
131+
let marginRight: pt_pct_auto => styleElement;
131132

132-
let marginTop: pt_auto => styleElement;
133+
let marginTop: pt_pct_auto => styleElement;
133134

134-
let marginVertical: pt_auto => styleElement;
135+
let marginVertical: pt_pct_auto => styleElement;
135136

136137
let maxHeight: pt_pct => styleElement;
137138

upgrade_scripts/styles_v1_to_v2/styles_v1_to_v2.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Replacements = {
1010
("padding", ["", "Horizontal", "Vertical", "Left", "Right", "Bottom", "Top"])
1111
]);
1212
let pt_pct_animated_interpolated = ["height", "width", "top", "bottom", "left", "right"];
13-
let pt_auto =
13+
let pt_pct_auto =
1414
combine([("margin", ["", "Bottom", "Top", "Right", "Left", "Horizontal", "Vertical"])]);
1515
let variantReplacements = [
1616
("flexStart", "FlexStart"),
@@ -57,7 +57,7 @@ module Replacements = {
5757
("nowrap", "Nowrap")
5858
];
5959
let suffix_pt =
60-
pt_auto @ pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix, prefix));
60+
pt_pct_auto @ pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix, prefix));
6161
let suffix_pct =
6262
pt_pct @ pt_pct_animated_interpolated |> List.map((prefix) => (prefix ++ "Pct", prefix));
6363
let suffix_animated =

0 commit comments

Comments
 (0)