Skip to content

Commit

Permalink
Convert project to reason-react v0.7.0 and JSX 3 syntax
Browse files Browse the repository at this point in the history
- Simplify components
- Switch to Parcel
- Switch to bs-css for styling
  • Loading branch information
wyze committed Apr 22, 2019
1 parent fb3331f commit 5a44d15
Show file tree
Hide file tree
Showing 64 changed files with 5,809 additions and 5,859 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
node_modules

# Build
src/**/*.js
.cache
dist
lib
.bsb.lock
.merlin
**/*.bs.js

# Logs
*.log
Expand Down
39 changes: 13 additions & 26 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
{
"name": "reason-calculator",
"reason": {
"react-jsx": 2
"react-jsx": 3
},
"bs-dependencies": [
"reason-react",
"reductive"
],
"bs-dependencies": ["bs-css", "reason-react"],
"bs-dev-dependencies": [
"bs-jest",
"bs-react-test-renderer"
],
"bsc-flags": [
"-bs-super-errors"
"@glennsl/bs-jest",
"bs-jest-dom",
"bs-react-testing-library"
],
"js-post-build": {
"cmd": "./scripts/copy.js"
},
"refmt": 3,
"sources": [
{
"dir": "src",
Expand All @@ -30,18 +21,14 @@
"type": "dev"
}
]
},
{
"dir": "reductive",
"subdirs": [
{
"dir": "__tests__",
"type": "dev"
}
]
},
"styles"
}
]
}
]
],
"package-specs": {
"module": "es6",
"in-source": true
},
"suffix": ".bs.js",
"refmt": 3
}
54 changes: 25 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@
},
"license": "MIT",
"scripts": {
"build": "npm-run-all build:*",
"build": "run-s build:*",
"build:bsb": "bsb -make-world",
"build:webpack": "webpack -p",
"clean": "npm-run-all clean:*",
"build:parcel": "parcel build public/index.html",
"clean": "run-p clean:*",
"clean:bsb": "bsb -clean-world",
"clean:project": "rimraf dist lib .merlin 'src/**/*.js'",
"deploy": "surge dist reason-calculator.surge.sh",
"dev": "npm-run-all --parallel dev:*",
"dev:bsb": "npm run build:bsb -- -w",
"dev:webpack": "webpack-dev-server -w",
"jest": "jest",
"np": "np --no-publish --yolo",
"prebuild": "npm run clean",
"predeploy": "npm-run-all build np",
"test": "npm-run-all build:bsb jest",
"version": "write-changelog"
"clean:parcel": "rimraf dist lib .merlin",
"pretest": "bsb -make-world",
"start": "run-p start:*",
"start:bsb": "bsb -make-world -w",
"start:parcel": "parcel public/index.html",
"test": "yarn jest"
},
"dependencies": {
"bs-css": "^8.0.4",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"reason-react": "^0.7.0"
},
"devDependencies": {
"bs-jest": "^0.2.0",
"bs-platform": "^2.0.0",
"bs-react-test-renderer": "^1.0.1",
"glamor": "^2.20.40",
"np": "^2.16.1",
"npm-run-all": "^4.1.2",
"react": "^15.6.2",
"reason-react": "^0.2.4",
"reductive": "^0.1.0",
"rimraf": "^2.6.2",
"surge": "^0.19.0",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4",
"webpack-html-plugin": "^0.1.1",
"write-changelog": "^1.1.0"
"@glennsl/bs-jest": "^0.4.8",
"@wyze/changelog": "^1.0.0",
"@wyze/github-release": "^1.0.0",
"bs-jest-dom": "^2.0.0",
"bs-platform": "^5.0.3",
"bs-react-testing-library": "^0.4.0",
"bsb-js": "^1.1.7",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.3",
"rimraf": "^2.6.3"
},
"jest": {
"roots": [
Expand Down
4 changes: 2 additions & 2 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Calculator in Reason</title>
</head>
<body>
<div class="root"></div>
<script src="bundle.js"></script>
<div id="root"></div>
<script src="../src/index.re"></script>
</body>
</html>
14 changes: 0 additions & 14 deletions scripts/copy.js

This file was deleted.

101 changes: 80 additions & 21 deletions src/components/App.re
Original file line number Diff line number Diff line change
@@ -1,25 +1,84 @@
let component = ReasonReact.statelessComponent("App");
module Styles = {
open Css;

let className: string =
Styles.make(
~alignItems="center",
~display="flex",
~flexDirection="column",
()
) |> Styles.className;
let buttons =
style([
display(`flex),
selector(
"&:last-of-type",
[
selector(
"& :first-of-type",
[
flexBasis(pct(50.)),
paddingLeft(em(0.9)),
textAlign(`left),
],
),
],
),
]);

let make = (~state as { Store.operations }, ~dispatch, _children) => {
let output = Operation.getInput(operations);
let calculator =
style([
background(hex("838383")),
borderRadius(px(5)),
overflow(hidden),
width(em(14.)),
]);

{
...component,
render: _self =>
<main className>
<Hero />
<Calculator>
<Display output />
<Buttons dispatch />
</Calculator>
</main>
};
let container =
style([alignItems(`center), display(`flex), flexDirection(`column)]);

let display =
style([
alignItems(center),
color(hex("fafafa")),
display(`flex),
fontSize(em(1.5)),
height(em(2.5)),
justifyContent(flexEnd),
padding2(~v=zero, ~h=em(1.)),
]);
};

[@react.component]
let make = () => {
let display = Store.useDisplay();

<div className=Styles.container>
<Hero />
<div className=Styles.calculator>
<div className=Styles.display> display->React.string </div>
<div className=Styles.buttons>
<Button action=Clear text="C" />
<Button action=PosNeg text={js|+/\u2212|js} />
<Button action=Percent text="%" />
<Button action=Divide text={js|\u00f7|js} />
</div>
<div className=Styles.buttons>
<Button action="7"->Input text="7" />
<Button action="8"->Input text="8" />
<Button action="9"->Input text="9" />
<Button action=Multiply text={js|\u00d7|js} />
</div>
<div className=Styles.buttons>
<Button action="4"->Input text="4" />
<Button action="5"->Input text="5" />
<Button action="6"->Input text="6" />
<Button action=Subtract text={js|\u2212|js} />
</div>
<div className=Styles.buttons>
<Button action="1"->Input text="1" />
<Button action="2"->Input text="2" />
<Button action="3"->Input text="3" />
<Button action=Add text="+" />
</div>
<div className=Styles.buttons>
<Button action="0"->Input text="0" />
<Button action="."->Input text="." />
<Button action=Equals text="=" />
</div>
</div>
</div>;
};
60 changes: 60 additions & 0 deletions src/components/Button.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Styles = {
open Css;

let container =
merge([
style([
borderWidth(zero),
borderRadius(zero),
color(hex("fafafa")),
cursor(`pointer),
display(inlineBlock),
flexBasis(pct(25.)),
fontSize(em(1.5)),
lineHeight(`abs(2.)),
outlineStyle(none),
transitions([
transition(
~duration=300,
~timingFunction=easeOut,
"background-color",
),
transition(~duration=300, ~timingFunction=easeOut, "color"),
]),
hover([backgroundColor(hex("fafafa"))]),
]),
]);

let variant = colorCode =>
style([
backgroundColor(hex(colorCode)),
hover([color(hex(colorCode))]),
]);

let blue = variant("6d71ff");
let green = variant("3bf3a9");
let orange = variant("ff8754");
};

[@react.component]
let make = (~action: Store.action, ~text) => {
let color =
switch (action) {
| Clear
| Percent
| PosNeg => Styles.green
| Add
| Divide
| Equals
| Multiply
| Subtract => Styles.orange
| _ => Styles.blue
};

let addOperation = Store.useAddOperation();
let onClick = React.useCallback(_ => addOperation(action));

<button className={Css.merge([Styles.container, color])} onClick>
text->React.string
</button>;
};
10 changes: 0 additions & 10 deletions src/components/ButtonGroup.re

This file was deleted.

37 changes: 0 additions & 37 deletions src/components/Buttons.re

This file was deleted.

16 changes: 0 additions & 16 deletions src/components/Calculator.re

This file was deleted.

Loading

0 comments on commit 5a44d15

Please sign in to comment.