Skip to content

Commit

Permalink
docs: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lessp committed May 2, 2019
1 parent 37cb81e commit 5f68cba
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 4 deletions.
80 changes: 80 additions & 0 deletions examples/App.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module Style = {
let global = ReactDOMRe.Style.make(~fontFamily="sans-serif", ());

let title =
ReactDOMRe.Style.make(
~alignItems="flex-start",
~borderBottom="2px solid hotpink",
~display="flex",
~fontSize="18px",
~fontWeight="700",
~margin="6px 12px",
~marginBottom="24px",
~paddingBottom="6px",
(),
);

let navigation =
ReactDOMRe.Style.make(
~backgroundColor="#f9f9f9",
~borderRight="1px solid #eaeaea",
~bottom="0px",
~display="flex",
~flexDirection="column",
~left="0px",
~listStyleType="none",
~padding="32px 12px",
~position="fixed",
~top="0px",
~width="256px",
(),
);

let link = active =>
ReactDOMRe.Style.make(
~color="black",
~fontWeight={
active ? "700" : "500";
},
~margin="6px 12px",
~textDecoration="none",
(),
);
};

[@react.component]
let make = () => {
let url = ReasonReactRouter.useUrl();

let (example, currentUrl) =
switch (url.path) {
| ["basic"]
| [] => (<Basic />, "basic")
| ["lazyload"] => (<LazyLoad />, "lazyload")
| _ => (
<h1 style={ReactDOMRe.Style.make(~paddingLeft="320px", ())}>
{"Nothing to see here..." |> React.string}
</h1>,
"",
)
};

<div style=Style.global>
<nav style=Style.navigation>
<h1 style=Style.title> {"bs-react-is-visible" |> React.string} </h1>
<a
href="/basic"
title="Basic"
style={Style.link(currentUrl === "basic")}>
{"Basic" |> React.string}
</a>
<a
href="/lazyload"
title="LazyLoad"
style={Style.link(currentUrl === "lazyload")}>
{"Lazy Load" |> React.string}
</a>
</nav>
example
</div>;
};
36 changes: 33 additions & 3 deletions examples/Basic.re
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
module Style = {
let wrapper =
ReactDOMRe.Style.make(
~height="150vh",
~display="flex",
~flexDirection="column",
~alignItems="center",
~transition="background-color 1s ease",
(),
);

let box = visible =>
ReactDOMRe.Style.make(
~alignItems="center",
~backgroundColor={
visible ? "hotpink" : "transparent";
},
~color="white",
~display="flex",
~fontSize="32px",
~height="256px",
~justifyContent="center",
~marginTop="auto",
~transition="background-color 1s ease",
~width="256px",
(),
);
};

[@react.component]
let make = () => {
let (isVisible, ref) = ReactIsVisible.useIsVisible();

<div style={ReactDOMRe.Style.make(~height="200vh", ())}>
<h1 ref>
<div style=Style.wrapper>
<h1> {"Scroll down" |> React.string} </h1>
<div ref style={Style.box(isVisible)}>
{(isVisible ? "I'm visible!" : "I'm not visible!") |> React.string}
</h1>
</div>
</div>;
};
2 changes: 1 addition & 1 deletion examples/Index.re
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ReactDOMRe.renderToElementWithId(<Basic />, "root");
ReactDOMRe.renderToElementWithId(<App />, "root");
55 changes: 55 additions & 0 deletions examples/LazyLoad.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Style = {
let wrapper =
ReactDOMRe.Style.make(
~alignItems="center",
~display="grid",
~fontFamily="sans-serif",
~gridGap="32px",
~justifyContent="center",
(),
);

let box =
ReactDOMRe.Style.make(
~alignItems="center",
~backgroundColor="hotpink",
~color="white",
~display="flex",
~fontSize="32px",
~height="256px",
~justifyContent="center",
(),
);
};

[@react.component]
let make = () => {
let (isVisible, ref) = ReactIsVisible.useIsVisible();
let (items, setItems) = React.useState(() => [|0, 0, 0, 0|]);

React.useEffect1(
() => {
isVisible
? setItems(currentItems =>
currentItems |> Array.append([|0, 0, 0, 0|])
)
: ();

None;
},
[|isVisible|],
);

<div style=Style.wrapper>
{items
|> Array.mapi((i, _item) =>
<div key={string_of_int(i)} style=Style.box>
{string_of_int(i) |> React.string}
</div>
)
|> React.array}
<span ref>
{"When you see this, more items will load" |> React.string}
</span>
</div>;
};

0 comments on commit 5f68cba

Please sign in to comment.