Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add grid repeat for track lengths #100 #101

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions example/test.re
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,29 @@ let tests =
)
/>
</div>
<div className=Css.(style([display(`grid), gridAutoFlow(`row)]))>
<div className=Css.(style([background(purple)]))>
{text("grid auto direction row")}
</div>
<div className=Css.(style([background(green)]))>
{text("grid auto direction row")}
</div>
</div>
<div
className=Css.(
style([
display(`grid),
gridAutoFlow(`row)
gridTemplateColumns([100->px, `repeat((`num(2), 60->px))]),
])
)>
<div className=Css.(style([background(purple)]))>
{text("grid auto direction row")}
{text("Grid track repeat")}
</div>
<div className=Css.(style([background(green)]))>
{text("grid auto direction row")}
{text("two times")}
</div>
<div className=Css.(style([background(red)]))>
{text("three times")}
</div>
</div>
</Section>
Expand Down
54 changes: 46 additions & 8 deletions src/Css.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ include Css_Colors;
module Emotion = {
type css = string;
[@bs.module "emotion"] external _make: Js.Json.t => css = "css";
[@bs.module "emotion"]
external injectGlobal: Js.Json.t => unit = "";
[@bs.module "emotion"] external injectGlobal: Js.Json.t => unit = "";
[@bs.module "emotion"]
external rawInjectGlobal: string => unit = "injectGlobal";
[@bs.module "emotion"]
Expand Down Expand Up @@ -291,9 +290,12 @@ type selector = [ | `selector(string, list(rule))];
let empty = [];

let merge = List.concat;
let global = (selector, rules: list(rule)) => {
Emotion.injectGlobal([(selector, Emotion.makeDict(rules))]->Js.Dict.fromList->Js.Json.object_);
}
let global = (selector, rules: list(rule)) =>
Emotion.injectGlobal(
[(selector, Emotion.makeDict(rules))]
->Js.Dict.fromList
->Js.Json.object_,
);

let insertRule = raw => Emotion.rawInjectGlobal(raw);

Expand Down Expand Up @@ -391,8 +393,6 @@ type length = [
| `zero
];

type gridLength = [ length | `fr(float) | `minContent | `maxContent];

let string_of_length_cascading =
fun
| `calc(`add, a, b) =>
Expand Down Expand Up @@ -812,8 +812,46 @@ let gridAutoDirectionToJs =
let gridAutoFlow = direction =>
d("gridAutoFlow", gridAutoDirectionToJs(direction));

type repeatValue = [ | `autoFill | `autoFit | `num(int)];
let repeatValueToJs =
fun
| `autoFill => "auto-fill"
| `autoFit => "auto-fit"
| `num(x) => x->string_of_int;

type trackLength = [ length | `fr(float) | `minContent | `maxContent];
type gridLength = [ trackLength | `repeat(repeatValue, trackLength)];

let gridLengthToJs =
fun
| `auto => "auto"
| `calc(`add, a, b) =>
"calc(" ++ string_of_length(a) ++ " + " ++ string_of_length(b) ++ ")"
| `calc(`sub, a, b) =>
"calc(" ++ string_of_length(a) ++ " - " ++ string_of_length(b) ++ ")"
| `ch(x) => string_of_float(x) ++ "ch"
| `cm(x) => string_of_float(x) ++ "cm"
| `em(x) => string_of_float(x) ++ "em"
| `ex(x) => string_of_float(x) ++ "ex"
| `mm(x) => string_of_float(x) ++ "mm"
| `percent(x) => string_of_float(x) ++ "%"
| `pt(x) => string_of_int(x) ++ "pt"
| `px(x) => string_of_int(x) ++ "px"
| `pxFloat(x) => string_of_float(x) ++ "px"
| `rem(x) => string_of_float(x) ++ "rem"
| `vh(x) => string_of_float(x) ++ "vh"
| `vmax(x) => string_of_float(x) ++ "vmax"
| `vmin(x) => string_of_float(x) ++ "vmin"
| `vw(x) => string_of_float(x) ++ "vw"
| `fr(x) => string_of_float(x) ++ "fr"
| `zero => "0"
| `minContent => "min-content"
| `maxContent => "max-content"
| `repeat(n, x) =>
"repeat(" ++ n->repeatValueToJs ++ ", " ++ string_of_dimension(x) ++ ")";

let string_of_dimensions = dimensions =>
dimensions |> List.map(string_of_dimension) |> String.concat(" ");
dimensions |> List.map(gridLengthToJs) |> String.concat(" ");

let gridTemplateColumns = dimensions =>
d("gridTemplateColumns", string_of_dimensions(dimensions));
Expand Down
36 changes: 17 additions & 19 deletions src/Css.rei
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ type length = [
| `zero
];

type gridLength = [ length | `fr(float) | `minContent | `maxContent];
type repeatValue = [ | `autoFill | `autoFit | `num(int)];
type trackLength = [ length | `fr(float) | `minContent | `maxContent];
type gridLength = [ trackLength | `repeat(repeatValue, trackLength)];

let ch: float => [> | `ch(float)];
let cm: float => [> | `cm(float)];
Expand Down Expand Up @@ -463,14 +465,17 @@ let order: int => rule;
let gridTemplateColumns: list([ gridLength | `auto]) => rule;
let gridTemplateRows: list([ gridLength | `auto]) => rule;
let gridAutoRows: [ length | `auto] => rule;
let gridAutoFlow: [
| `column
| `row
| `columnDense
| `rowDense
| `inherit_
| `initial
| `unset ] => rule;
let gridAutoFlow:
[
| `column
| `row
| `columnDense
| `rowDense
| `inherit_
| `initial
| `unset
] =>
rule;
let gridColumn: (int, int) => rule;
let gridRow: (int, int) => rule;
let gridColumnStart: int => rule;
Expand Down Expand Up @@ -534,14 +539,7 @@ let alignItems:
[ | `stretch | `flexStart | `center | `flexEnd | `baseline] => rule;
let alignSelf:
[ | `stretch | `flexStart | `center | `flexEnd | `baseline | `auto] => rule;
let justifySelf:
[
| `flexStart
| `center
| `flexEnd
| `stretch
] =>
rule;
let justifySelf: [ | `flexStart | `center | `flexEnd | `stretch] => rule;
let justifyContent:
[
| `flexStart
Expand All @@ -565,7 +563,7 @@ let overflowY: [ | `hidden | `visible | `scroll | `auto] => rule;
let zIndex: int => rule;
let contentRule: string => rule;

let columnCount: [ | `auto | `count(int) | cascading ] => rule;
let columnCount: [ | `auto | `count(int) | cascading] => rule;

/**
* Style
Expand Down Expand Up @@ -622,7 +620,7 @@ let boxShadow:
let boxShadows: list([ | `shadow(string)]) => rule;

let background: [ color | `url(string) | gradient | `none] => rule;
let backgrounds : list([ | color | `url(string) | gradient | `none] ) => rule;
let backgrounds: list([ color | `url(string) | gradient | `none]) => rule;
let backgroundColor: [ color] => rule;
let backgroundImage: [ | `url(string) | gradient | `none] => rule;
let backgroundAttachment: [ | `scroll | `fixed | `local] => rule;
Expand Down