This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
206 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Code Snippet Examples | ||
|
||
## Line highlighting | ||
|
||
```reason{3,6-11} | ||
[@react.component] | ||
let make = () => { | ||
let (counter, setCounter) = React.useState(() => 0); | ||
<div | ||
style={ReactDOMStyle.make( | ||
~padding="1em", | ||
~display="flex", | ||
~gridGap="1em", | ||
(), | ||
)}> | ||
<button onClick={_evt => setCounter(v => v - 1)}> | ||
{React.string("-")} | ||
</button> | ||
<span> {counter |> Int.to_string |> React.string} </span> | ||
<button onClick={_evt => setCounter(v => v + 1)}> | ||
{React.string("+")} | ||
</button> | ||
</div>; | ||
}; | ||
``` | ||
|
||
## Import from file | ||
|
||
<<< @/src/CelsiusConverter.re | ||
|
||
## Import region from file | ||
|
||
Just the sandwich region and nothing else | ||
|
||
<<< @/src/Order.re#sandwich |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let getValueFromEvent = (evt): string => ReactEvent.Form.target(evt)##value; | ||
|
||
let convert = celsius => 9.0 /. 5.0 *. celsius +. 32.0; | ||
|
||
[@react.component] | ||
let make = () => { | ||
let (celsius, setCelsius) = React.useState(() => ""); | ||
|
||
<div> | ||
<input | ||
value=celsius | ||
onChange={evt => { | ||
let newCelsius = getValueFromEvent(evt); | ||
setCelsius(_ => newCelsius); | ||
}} | ||
/> | ||
{React.string({js|°C = |js})} | ||
{( | ||
String.trim(celsius) == "" | ||
? {js|? °F|js} | ||
: ( | ||
switch (celsius |> float_of_string_opt |> Option.map(convert)) { | ||
| None => "error" | ||
| Some(fahrenheit) when fahrenheit < (-128.6) => {js|Unreasonably cold🥶|js} | ||
| Some(fahrenheit) when fahrenheit > 212.0 => {js|Unreasonably hot🥵|js} | ||
| Some(fahrenheit) => | ||
Js.Float.toFixedWithPrecision(fahrenheit, ~digits=2) | ||
++ {js| °F|js} | ||
} | ||
) | ||
) | ||
|> React.string} | ||
</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
[%%mel.raw {|import "./order.css"|}]; | ||
|
||
let sprintf = Printf.sprintf; | ||
|
||
// #region sandwich | ||
module Sandwich = { | ||
type t = | ||
| Portabello | ||
| Ham | ||
| Unicorn; | ||
|
||
let toPrice = | ||
fun | ||
| Portabello => 9. | ||
| Ham => 10. | ||
| Unicorn => 88.8; | ||
|
||
let toEmoji = t => | ||
sprintf( | ||
"%s(%s)", | ||
{js|🥪|js}, | ||
switch (t) { | ||
| Portabello => {js|🍄|js} | ||
| Ham => {js|🐷|js} | ||
| Unicorn => {js|🦄|js} | ||
}, | ||
); | ||
}; | ||
// #endregion sandwich | ||
|
||
module Burger = { | ||
type t = { | ||
tomatoes: bool, | ||
lettuce: bool, | ||
bacon: int, | ||
onions: int, | ||
cheese: int, | ||
}; | ||
|
||
let toEmoji = ({lettuce, tomatoes, bacon, onions, cheese}) => { | ||
let multiple = (str, n) => | ||
switch (n) { | ||
| 0 => "" | ||
| 1 => str | ||
| n => Printf.sprintf("%s%s%d", str, {js|×|js}, n) | ||
}; | ||
|
||
sprintf( | ||
"%s{%s}", | ||
{js|🍔|js}, | ||
[| | ||
lettuce ? {js|🥬|js} : "", | ||
tomatoes ? {js|🍅|js} : "", | ||
multiple({js|🥓|js}, bacon), | ||
multiple({js|🧅|js}, onions), | ||
multiple({js|🧀|js}, cheese), | ||
|] | ||
|> Js.Array.filter(str => str != "") | ||
|> Js.Array.joinWith(", "), | ||
); | ||
}; | ||
|
||
let toPrice = ({bacon, onions, cheese, _}) => | ||
15. | ||
+. float_of_int(bacon) | ||
*. 0.5 | ||
+. float_of_int(onions) | ||
*. 0.2 | ||
+. float_of_int(cheese) | ||
*. 0.1; | ||
}; | ||
|
||
type t = | ||
| Hotdog | ||
| Sandwich(Sandwich.t) | ||
| Burger(Burger.t); | ||
|
||
let toPrice = | ||
fun | ||
| Hotdog => 5. | ||
| Sandwich(s) => Sandwich.toPrice(s) | ||
| Burger(b) => Burger.toPrice(b); | ||
|
||
let toEmoji = | ||
fun | ||
| Hotdog => {js|🌭|js} | ||
| Sandwich(s) => Sandwich.toEmoji(s) | ||
| Burger(b) => Burger.toEmoji(b); | ||
|
||
[@react.component] | ||
let make = (~order: t) => | ||
<tr className="order"> | ||
<td className="emoji"> {order |> toEmoji |> React.string} </td> | ||
<td className="price"> {order |> toPrice |> Format.currency} </td> | ||
</tr>; |