Skip to content

New react docs (messed up branch) #60

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
90893fe
Upgrade to reason-react 9.1
ryyppy Sep 19, 2020
e64dbf3
Add new layout for the React docs, prepare work for more generic Docs…
ryyppy Sep 19, 2020
aee491c
Add first React doc files
ryyppy Sep 19, 2020
c5ea779
Document optional props
ryyppy Sep 19, 2020
1eb51b6
Rename list-and-keys to arrays-and-keys
ryyppy Sep 19, 2020
0ced4e9
Add arrays-and-keys to toc order
ryyppy Sep 19, 2020
0ea486c
Small tweeks to rendering-elements
ryyppy Sep 19, 2020
98e02e9
Improve HighlightJs module
ryyppy Sep 20, 2020
b538e55
Improve arrays-and-keys, components-and-props, introduction and rende…
ryyppy Sep 20, 2020
605c928
Add hooks overview, useState and useEffect docs
ryyppy Sep 20, 2020
fe901b1
Update rendering elemnts, hooks-overview; add hooks-context
ryyppy Sep 22, 2020
b661756
Merge branch 'master' into new-react-docs
ryyppy Sep 25, 2020
6bc71ab
Add refs / forwardRefs / useRef docs
ryyppy Sep 28, 2020
422af5f
Add useReducer docs
ryyppy Sep 29, 2020
9a2af56
Improve hljs line highlighting
ryyppy Sep 30, 2020
320c43d
Remove cruft from rendering-elements
ryyppy Sep 30, 2020
d20ba19
Add custom hooks docs
ryyppy Sep 30, 2020
0a0bf9f
Update extract-tocs script
ryyppy Sep 30, 2020
9e6e19e
Refine JSX / rendering elements / components section. Remove JSX tran…
ryyppy Oct 1, 2020
a8fc03d
Component-and-props: add invalid prop name docs
ryyppy Oct 1, 2020
f990d12
Merge branch 'master' into new-react-docs
ryyppy Nov 1, 2020
ab39c5b
Refine beyond-jsx, components-and-props, rendering-elements
ryyppy Nov 1, 2020
d38e19e
Remove false statement in hooks-effect
ryyppy Nov 1, 2020
5d95a83
Refactor forwardRef doc
ryyppy Nov 1, 2020
0b727e9
Fix link in intro
ryyppy Nov 1, 2020
2700073
Add context doc
ryyppy Nov 1, 2020
b9b7622
Fix links, small refinements
ryyppy Nov 1, 2020
26acb35
Add hljs html syntax
ryyppy Nov 1, 2020
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
15 changes: 13 additions & 2 deletions common/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
let res = require('../plugins/res-syntax-highlightjs');
let bash = require('highlight.js/lib/languages/bash');
let json = require('highlight.js/lib/languages/json');
let html = require('highlight.js/lib/languages/xml');
let ts = require('highlight.js/lib/languages/typescript');
let text = require('highlight.js/lib/languages/plaintext');
let diff = require('highlight.js/lib/languages/diff');
Expand All @@ -30,6 +31,7 @@
hljs.registerLanguage('sh', bash);
hljs.registerLanguage('json', json);
hljs.registerLanguage('text', text);
hljs.registerLanguage('html', html);
hljs.registerLanguage('diff', diff);
|};

Expand Down Expand Up @@ -110,6 +112,10 @@ let default = (props: props): React.element => {
}
| {base: [|"docs", "reason-compiler"|], version: Latest} =>
<ReasonCompilerDocsLayout> content </ReasonCompilerDocsLayout>
| {base: [|"docs", "react"|], version: Latest} =>
<ReactDocsLayout frontmatter={component->frontmatter}>
content
</ReactDocsLayout>
| {base: [|"docs", "gentype"|], version: Latest} =>
<GenTypeDocsLayout> content </GenTypeDocsLayout>
// common routes
Expand All @@ -123,12 +129,17 @@ let default = (props: props): React.element => {
// to keep the frontmatter parsing etc in one place
content
| _ =>
let title =
switch (url) {
| {base: [|"docs"|]} => Some("Overview | ReScript Documentation")
| _ => None
};
<MainLayout>
<Meta />
<Meta ?title />
<div className="flex justify-center">
<div className="max-w-705 w-full"> content </div>
</div>
</MainLayout>
</MainLayout>;
}
};
};
22 changes: 9 additions & 13 deletions common/HighlightJs.re
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ let renderHLJS =
Js.String2.split(highlighted, "\n")
->Belt.Array.mapWithIndex((i, line) =>
if (Js.Array2.find(highlightedLines, lnum => lnum === i + 1) !== None) {
"<span class=\"hljs-line-highlight\">" ++ line ++ "</span>";
let content = line === "" ? "&nbsp;" : line;
"<span class=\"inline-block\">" ++ content ++ "</span>";
} else {
line;
"<span class=\"inline-block text-inherit opacity-50\">"
++ line
++ "</span>";
}
)
->Js.Array2.joinWith("\n");
Expand All @@ -37,15 +40,8 @@ let renderHLJS =

let dark = darkmode ? "dark" : "";

ReactDOMRe.createElementVariadic(
"code",
~props=
ReactDOMRe.objToDOMProps({
"className": "hljs lang-" ++ lang ++ " " ++ dark,
"dangerouslySetInnerHTML": {
"__html": highlighted,
},
}),
[||],
);
<code
className={"hljs lang-" ++ lang ++ " " ++ dark}
dangerouslySetInnerHTML={"__html": highlighted}
/>;
};
2 changes: 1 addition & 1 deletion components/VersionSelect.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let make =
},
);
<select
className="text-14 border border-fire inline-block rounded px-4 py-1 font-semibold "
className="text-14 border border-fire inline-block rounded px-4 py-1 font-semibold "
name="versionSelection"
value=version
onChange>
Expand Down
2 changes: 1 addition & 1 deletion layouts/CommunityLayout.re
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let make = (~components=Markdown.default, ~children) => {

let title = "Community";

<DocsLayout theme=`Reason components categories title ?activeToc breadcrumbs>
<DocsLayout theme=`Reason components metaTitleCategory="ReScript Documentation" categories title ?activeToc breadcrumbs>
children
</DocsLayout>;
};
110 changes: 103 additions & 7 deletions layouts/DocsLayout.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Category = Sidebar.Category;

let makeBreadcrumbsFromPaths =
(~basePath: string, paths: array(string)): list(Url.breadcrumb) => {
Js.log(paths);
let (_, rest) =
Belt.Array.reduce(
paths,
Expand All @@ -21,8 +20,7 @@ let makeBreadcrumbsFromPaths =

let href = baseHref ++ "/" ++ path;

Js.Array2.push(ret, Url.{name: prettyString(path), href})
->ignore;
Js.Array2.push(ret, Url.{name: prettyString(path), href})->ignore;
(href, ret);
},
);
Expand All @@ -42,8 +40,7 @@ let makeBreadcrumbs =

let href = baseHref ++ "/" ++ path;

Js.Array2.push(ret,Url.{name: prettyString(path), href})
->ignore;
Js.Array2.push(ret, Url.{name: prettyString(path), href})->ignore;
(href, ret);
},
);
Expand All @@ -55,6 +52,7 @@ let make =
(
~breadcrumbs: option(list(Url.breadcrumb))=?,
~title: string,
~metaTitleCategory: option(string)=?, // e.g. Introduction | My Meta Title Category
~frontmatter: option(Js.Json.t)=?,
~version: option(string)=?,
~availableVersions: option(array(string))=?,
Expand Down Expand Up @@ -139,7 +137,12 @@ let make =
route
/>;

let metaTitle = title ++ " | ReScript Documentation";
let metaTitle =
switch (metaTitleCategory) {
| Some(titleCategory) =>
titleCategory ++ " | " ++ "ReScript Documentation"
| None => title
};

let metaElement =
switch (frontmatter) {
Expand All @@ -148,7 +151,11 @@ let make =
| Ok(fm) =>
let canonical = Js.Null.toOption(fm.canonical);
let description = Js.Null.toOption(fm.description);
let title = fm.title ++ " | ReScript Language Manual";
let title =
switch (metaTitleCategory) {
| Some(titleCategory) => fm.title ++ " | " ++ titleCategory
| None => title
};
<Meta title ?description ?canonical />;
| Error(_) => React.null
}
Expand All @@ -166,3 +173,92 @@ let make =
children
</SidebarLayout>;
};

module type StaticContent = {
/*let categories: array(SidebarLayout.Sidebar.Category.t);*/
let tocData: SidebarLayout.Toc.raw;
};

module Make = (Content: StaticContent) => {
[@react.component]
let make =
(
~breadcrumbs: option(list(Url.breadcrumb))=?,
~title: string,
~metaTitleCategory: option(string)=?,
~frontmatter: option(Js.Json.t)=?,
~version: option(string)=?,
~availableVersions: option(array(string))=?,
~latestVersionLabel: option(string)=?,
/*~activeToc: option(SidebarLayout.Toc.t)=?,*/
~components: option(Mdx.Components.t)=?,
~theme: option(ColorTheme.t)=?,
~children: React.element,
) => {
let router = Next.Router.useRouter();
let route = router.route;

let activeToc: option(SidebarLayout.Toc.t) =
Belt.Option.(
Js.Dict.get(Content.tocData, route)
->map(data => {
open SidebarLayout.Toc;
let title = data##title;
let entries =
Belt.Array.map(data##headers, header =>
{header: header##name, href: "#" ++ header##href}
);
{title, entries};
})
);

let categories = {
let groups =
Js.Dict.entries(Content.tocData)
->Belt.Array.reduce(
Js.Dict.empty(),
(acc, next) => {
let (_, value) = next;
switch (Js.Nullable.toOption(value##category)) {
| Some(category) =>
switch (acc->Js.Dict.get(category)) {
| None => acc->Js.Dict.set(category, [|next|])
| Some(arr) =>
Js.Array2.push(arr, next)->ignore;
acc->Js.Dict.set(category, arr);
}
| None =>
Js.log2("has NO category", next);
()
};
acc;
},
);
Js.Dict.entries(groups)
->Belt.Array.map(((name, values)) => {
Category.{
name,
items:
Belt.Array.map(values, ((href, value)) => {
{NavItem.name: value##title, href}
}),
}
});
};

make({
"breadcrumbs": breadcrumbs,
"title": title,
"metaTitleCategory": metaTitleCategory,
"frontmatter": frontmatter,
"version": version,
"availableVersions": availableVersions,
"latestVersionLabel": latestVersionLabel,
"activeToc": activeToc,
"categories": categories,
"components": components,
"theme": theme,
"children": children,
});
};
};
1 change: 1 addition & 0 deletions layouts/ManualDocsLayout.re
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module Docs = {
categories
version
title
metaTitleCategory="ReScript Language Manual"
availableVersions=allManualVersions
latestVersionLabel
?frontmatter
Expand Down
1 change: 1 addition & 0 deletions layouts/ManualDocsLayout8_0_0.re
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ module Docs = {
latestVersionLabel=ManualDocsLayout.latestVersionLabel
?frontmatter
title
metaTitleCategory="ReScript Language Manual"
?activeToc
breadcrumbs>
warnBanner
Expand Down
69 changes: 69 additions & 0 deletions layouts/ReactDocsLayout.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module Link = Next.Link;

module NavItem = SidebarLayout.Sidebar.NavItem;
module Category = SidebarLayout.Sidebar.Category;
module Toc = SidebarLayout.Toc;

let overviewNavs = [|
{NavItem.name: "Introduction", href: "/docs/react/latest/introduction"},
|];

module CategoryDocsLayout =
// Structure defined by `scripts/extract-tocs.js`
DocsLayout.Make({
/*let categories = [|Category.{name: "Overview", items: overviewNavs}|];*/
let tocData: SidebarLayout.Toc.raw = [%raw
"require('../index_data/react_latest_toc.json')"
];
});

[@react.component]
let make = (~frontmatter: option(Js.Json.t)=?, ~components=Markdown.default, ~children) => {
let router = Next.Router.useRouter();
let route = router.route;

let url = route->Url.parse;

let version =
switch (url.version) {
| Version(version) => version
| NoVersion => "latest"
| Latest => "latest"
};

let prefix = [
Url.{name: "Docs", href: "/docs/latest"},
Url.{
name: "ReasonReact",
href: "/docs/react/" ++ version ++ "/introduction",
},
];

let breadcrumbs =
Belt.List.concat(
prefix,
DocsLayout.makeBreadcrumbs(
~basePath="/docs/gentype/" ++ version,
route,
),
);

let title = "ReasonReact";

let availableVersions = [|"latest"|];
let latestVersionLabel = "v0.9";
let version = "latest";

<CategoryDocsLayout
theme=`Reason
components
metaTitleCategory="React"
availableVersions
latestVersionLabel
version
title
breadcrumbs
?frontmatter>
children
</CategoryDocsLayout>;
};
14 changes: 13 additions & 1 deletion layouts/SidebarLayout.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ open Util.ReactStuff;
module Link = Next.Link;

module Toc = {
type raw =
Js.Dict.t({
.
"title": string,
"category": Js.Nullable.t(string),
"headers":
array({
.
"name": string,
"href": string,
}),
});

type entry = {
header: string,
href: string,
Expand Down Expand Up @@ -123,7 +136,6 @@ module Sidebar = {
};
};


// subitems: list of functions inside given module (defined by route)
[@react.component]
let make =
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react": "^16.12.0",
"react-dom": "^16.12.0",
"reason-promise": "^1.0.2",
"reason-react": "^0.7.0",
"reason-react": "^0.9.1",
"remark-parse": "^7.0.1",
"remark-slug": "^5.1.2",
"remark-stringify": "^7.0.3",
Expand Down
Loading