Skip to content

Commit 5df1e33

Browse files
committed
Migrate components/ to rescript
1 parent 4843648 commit 5df1e33

28 files changed

+1801
-2218
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
open Util.ReactStuff;
2-
open Ansi;
1+
// This file was automatically converted to ReScript from 'AnsiPre.re'
2+
// Check the output and make sure to delete the original file
3+
open Util.ReactStuff
4+
open Ansi
35

46
type colorTarget =
57
| Fg
6-
| Bg;
8+
| Bg
79

8-
let mapColor = (~target: colorTarget, c: Color.t): string => {
10+
let mapColor = (~target: colorTarget, c: Color.t): string =>
911
switch (target, c) {
1012
| (Fg, Black) => "text-black"
1113
| (Fg, Red) => "text-fire"
@@ -23,35 +25,30 @@ let mapColor = (~target: colorTarget, c: Color.t): string => {
2325
| (Bg, Magenta) => "bg-berry"
2426
| (Bg, Cyan) => "bg-dark-code-2"
2527
| (Bg, White) => "bg-snow-dark"
26-
};
27-
};
28+
}
2829

2930
let renderSgrString = (~key: string, sgrStr: SgrString.t): React.element => {
30-
let {SgrString.content, params} = sgrStr;
31+
let {SgrString.content: content, params} = sgrStr
3132

32-
let className =
33-
Belt.Array.reduce(params, "", (acc, p) => {
34-
switch (p) {
35-
| Sgr.Bold => acc ++ " bold"
36-
| Fg(c) => acc ++ " " ++ mapColor(~target=Fg, c)
37-
| Bg(c) => acc ++ " " ++ mapColor(~target=Bg, c)
38-
| _ => acc
39-
}
40-
});
33+
let className = Belt.Array.reduce(params, "", (acc, p) =>
34+
switch p {
35+
| Sgr.Bold => acc ++ " bold"
36+
| Fg(c) => acc ++ (" " ++ mapColor(~target=Fg, c))
37+
| Bg(c) => acc ++ (" " ++ mapColor(~target=Bg, c))
38+
| _ => acc
39+
}
40+
)
4141

42-
<span key className> content->s </span>;
43-
};
42+
<span key className> {content->s} </span>
43+
}
4444

45-
[@react.component]
45+
@react.component
4646
let make = (~className=?, ~children: string) => {
47-
let spans =
48-
Ansi.parse(children)
49-
->SgrString.fromTokens
50-
->Belt.Array.mapWithIndex((i, str) => {
51-
let key = Belt.Int.toString(i);
52-
renderSgrString(~key, str);
53-
});
47+
let spans = Ansi.parse(children)->SgrString.fromTokens->Belt.Array.mapWithIndex((i, str) => {
48+
let key = Belt.Int.toString(i)
49+
renderSgrString(~key, str)
50+
})
5451

5552
// Note: pre is essential here, otherwise whitespace and newlines are not respected
56-
<pre ?className> spans->ate </pre>;
57-
};
53+
<pre ?className> {spans->ate} </pre>
54+
}

components/ApiIntro.re

-4
This file was deleted.

components/ApiIntro.res

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@react.component
2+
let make = (~children) => <div className="my-10"> children </div>

components/ApiMarkdown.re

-59
This file was deleted.

components/ApiMarkdown.res

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This file was automatically converted to ReScript from 'ApiMarkdown.re'
2+
// Check the output and make sure to delete the original file
3+
open Util.ReactStuff
4+
5+
/*
6+
This module is intended for the ODOC like documentation layout.
7+
It hides the h2 tags and does
8+
*/
9+
open Markdown
10+
11+
module InvisibleAnchor = {
12+
@react.component
13+
let make = (~id: string) => {
14+
let style = ReactDOMRe.Style.make(~position="absolute", ~top="-1rem", ())
15+
<span className="relative" ariaHidden=true> <a id style /> </span>
16+
}
17+
}
18+
19+
module H1 = {
20+
@react.component
21+
let make = (~children) =>
22+
<h1 className="text-6xl leading-1 mb-2 font-sans font-medium text-night-dark"> children </h1>
23+
}
24+
25+
module H2 = {
26+
// We will currently hide the headline, to keep the structure,
27+
// but having an Elm like documentation
28+
@react.component
29+
let make = (~id, ~children) => <>
30+
<div className="border-b border-gray-10 mb-10 mt-20" /> <Markdown.H2 id> children </Markdown.H2>
31+
</>
32+
}
33+
34+
let default = Mdx.Components.t(
35+
~intro=Intro.make,
36+
~p=P.make,
37+
~li=Li.make,
38+
~h1=H1.make,
39+
~h2=H2.make,
40+
~h3=H3.make,
41+
~h4=H4.make,
42+
~h5=H5.make,
43+
~ul=Ul.make,
44+
~ol=Ol.make,
45+
~a=A.make,
46+
~thead=Thead.make,
47+
~th=Th.make,
48+
~td=Td.make,
49+
~pre=Pre.make,
50+
~inlineCode=InlineCode.make,
51+
~code=Code.make,
52+
(),
53+
)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
open Util.ReactStuff;
1+
open Util.ReactStuff
22

3-
[@react.component]
4-
let make = (~children) => {
3+
@react.component
4+
let make = (~children) =>
55
<button
66
className="transition-colors duration-200 inline-block text-base text-fire hover:text-white hover:bg-fire rounded border border-fire-80 px-5 py-2">
77
children
8-
</button>;
9-
};
8+
</button>

components/CodeExample.re

-129
This file was deleted.

0 commit comments

Comments
 (0)