Skip to content
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

add elm0.19.1-parcel example #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions example-elm0.19.1-parcel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.cache
dist
18 changes: 18 additions & 0 deletions example-elm0.19.1-parcel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Example using React, Elm, and Parcel bundler

[Parcel](https://parceljs.org/) is a blazing fast, zero configiguration web
application bundler. It has [built in support](https://parceljs.org/elm.html)
for components written in Elm.

## Build Instructions

Run the following commands:

```bash
git clone https://github.com/evancz/react-elm-components.git
cd react-elm-components/example-elm0.19.1-parcel
npm install
npm run start
```

Open http://localhost:1234/
24 changes: 24 additions & 0 deletions example-elm0.19.1-parcel/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/time": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
15 changes: 15 additions & 0 deletions example-elm0.19.1-parcel/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>React + Elm</title>
<link href="styles.css" rel="stylesheet" />
</head>

<body>
<div id="time"></div>
<script src="index.jsx"></script>
</body>

</html>
18 changes: 18 additions & 0 deletions example-elm0.19.1-parcel/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import ReactDOM from "react-dom";
import EmojiPicker from "emojione-picker";
import Elm from "react-elm-components";
import Time from "./src/Main.elm";

class ReactTimeExample extends React.Component {
render() {
return (
<div className="time-container">
<h2>The current time is:</h2>
<Elm src={Time.Elm.Main} />
</div>
);
}
}

ReactDOM.render(<ReactTimeExample />, document.getElementById("time"));
19 changes: 19 additions & 0 deletions example-elm0.19.1-parcel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"scripts": {
"buildelm": "elm make --output=Time.js src/Main.elm",
"start": "parcel ./index.html",
"build": "rm -rf dist && parcel build --public-url / ./index.html",
"watch": "parcel watch --public-url / ./index.html"
},
"dependencies": {
"emojione-picker": "^2.2.2",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-elm-components": "^1.1.0"
},
"devDependencies": {
"elm-hot": "^1.1.3",
"node-elm-compiler": "^5.0.4",
"parcel-bundler": "^1.12.4"
}
}
97 changes: 97 additions & 0 deletions example-elm0.19.1-parcel/src/Main.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module Main exposing (Model, Msg(..), init, main, subscriptions, timeToString, update, view)

import Browser
import Html exposing (..)
import Task
import Time



-- MAIN


main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}



-- MODEL


type alias Model =
{ zone : Time.Zone
, time : Time.Posix
}


init : () -> ( Model, Cmd Msg )
init _ =
( Model Time.utc (Time.millisToPosix 0)
, Task.perform AdjustTimeZone Time.here
)



-- UPDATE


type Msg
= Tick Time.Posix
| AdjustTimeZone Time.Zone


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Tick newTime ->
( { model | time = newTime }
, Cmd.none
)

AdjustTimeZone newZone ->
( { model | zone = newZone }
, Cmd.none
)



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
Time.every 1000 Tick



-- VIEW


view : Model -> Html Msg
view model =
let
hour =
timeToString (Time.toHour model.zone model.time)

minute =
timeToString (Time.toMinute model.zone model.time)

second =
timeToString (Time.toSecond model.zone model.time)
in
case Time.posixToMillis model.time of
0 ->
h1 [] []

time ->
h1 [] [ text (hour ++ ":" ++ minute ++ ":" ++ second) ]


timeToString : Int -> String
timeToString int =
String.padLeft 2 '0' (String.fromInt int)
25 changes: 25 additions & 0 deletions example-elm0.19.1-parcel/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
body {
margin: 0;
background-color: #5a6378;
}

.time-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.time-container h1 {
margin: 0;
font-size: 10vh;
color: white;
}

.time-container h2 {
margin: 0;
font-style: italic;
font-size: 3vh;
font-weight: 200;
color: white;
}