-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from melange-re/styling-with-css
Add 'styling with css' chapter
- Loading branch information
Showing
15 changed files
with
556 additions
and
3 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
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,102 @@ | ||
module Item = { | ||
type t = | ||
| Sandwich | ||
| Burger | ||
| Hotdog; | ||
|
||
let toPrice = | ||
fun | ||
| Sandwich => 10. | ||
| Burger => 15. | ||
| Hotdog => 5.; | ||
|
||
let toEmoji = | ||
fun | ||
| Sandwich => {js|🥪|js} | ||
| Burger => {js|🍔|js} | ||
| Hotdog => {js|🌭|js}; | ||
}; | ||
|
||
module Format = { | ||
let currency = _value => React.null; | ||
}; | ||
|
||
// #region order-item | ||
module OrderItem = { | ||
[@react.component] | ||
let make = (~item: Item.t) => | ||
<tr className="item"> | ||
<td className="emoji"> {item |> Item.toEmoji |> React.string} </td> | ||
<td className="price"> {item |> Item.toPrice |> Format.currency} </td> | ||
</tr>; | ||
}; | ||
// #endregion order-item | ||
|
||
type t = array(Item.t); | ||
|
||
// #region order-make | ||
[@react.component] | ||
let make = (~items: t) => { | ||
let total = | ||
items |> Js.Array.reduce((acc, order) => acc +. Item.toPrice(order), 0.); | ||
|
||
<table className="order"> | ||
<tbody> | ||
{items | ||
|> Js.Array.mapi((item, index) => | ||
<OrderItem key={"item-" ++ string_of_int(index)} item /> | ||
) | ||
|> React.array} | ||
<tr className="total"> | ||
<td> {React.string("Total")} </td> | ||
<td> {total |> Format.currency} </td> | ||
</tr> | ||
</tbody> | ||
</table>; | ||
}; | ||
// #endregion order-make | ||
|
||
module OrderItemV2 = { | ||
// #region order-item-css | ||
module OrderItem = { | ||
[@mel.module "./order-item.module.css"] | ||
external css: Js.t({..}) = "default"; | ||
|
||
[@react.component] | ||
let make = (~item: Item.t) => | ||
<tr className=css##item> | ||
<td className=css##emoji> {item |> Item.toEmoji |> React.string} </td> | ||
<td className=css##price> | ||
{item |> Item.toPrice |> Format.currency} | ||
</td> | ||
</tr>; | ||
}; | ||
// #endregion order-item-css | ||
}; | ||
|
||
module OrderV2 = { | ||
// #region order-external | ||
[@mel.module "./order.module.css"] external css: Js.t({..}) = "default"; | ||
|
||
[@react.component] | ||
let make = (~items: t) => { | ||
let total = | ||
items | ||
|> Js.Array.reduce((acc, order) => acc +. Item.toPrice(order), 0.); | ||
|
||
<table className=css##order> | ||
<tbody> | ||
{items | ||
|> Js.Array.mapi((item, index) => | ||
<OrderItem key={"item-" ++ string_of_int(index)} item /> | ||
) | ||
|> React.array} | ||
<tr className=css##total> | ||
<td> {React.string("Total")} </td> | ||
<td> {total |> Format.currency} </td> | ||
</tr> | ||
</tbody> | ||
</table>; | ||
}; | ||
// #endregion order-external | ||
}; |
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,8 @@ | ||
(melange.emit | ||
(target output) | ||
(libraries reason-react) | ||
(preprocess | ||
(pps melange.ppx reason-react-ppx)) | ||
(module_systems es6) | ||
(runtime_deps | ||
(glob_files *.css))) |
Oops, something went wrong.