Skip to content

Commit

Permalink
hack around elm's lack of support for custom css properties
Browse files Browse the repository at this point in the history
Uses a port to set `--change-stage`.
  • Loading branch information
harrysarson committed Jun 2, 2018
1 parent 83e0e0b commit 50aa864
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions elm-src/Config.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ imageInputId = "file"

nonPrimeImageNumberId : String
nonPrimeImageNumberId = "nonPrimeImageNumberId"

2 changes: 0 additions & 2 deletions elm-src/DisplayPanel.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ view props =
div []
[ div
[ class "display-panel stage-selecting"
, style
[ ( "--show-stage", toString props.stage ) ]
]
( List.map
( div <|
Expand Down
4 changes: 4 additions & 0 deletions elm-src/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ port module Ports exposing ( fileSelected
, prettyPrintState
, setInitialValues
, resizeImageNumber
, setCssProp
)
import Types
import ToNumberConfig.Types
Expand All @@ -29,3 +30,6 @@ port ppState : Types.Model -> Cmd msg
port setInitialValues : ToNumberConfig.Types.Model -> Cmd msg

port resizeImageNumber : String -> Cmd msg

-- selector prop value
port setCssProp : ( String, String, String ) -> Cmd msg
17 changes: 14 additions & 3 deletions elm-src/State.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import Task

import Types
import Config
import Ports exposing (fileSelected, requestNonPrime, prettyPrintState, setInitialValues, resizeImageNumber)
import Ports exposing ( fileSelected
, requestNonPrime
, prettyPrintState
, setInitialValues
, resizeImageNumber
, setCssProp
)

import ToNumberConfig.Types
import ToNumberConfig.State
Expand All @@ -25,6 +31,8 @@ initialState =
{ contents = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
, filename = "sample"
}
, Task.perform Types.ChangeStage <|
Task.succeed 0
]
)

Expand All @@ -36,14 +44,17 @@ update msg model =
Types.ChangeStage change ->
let
newStage = max 0 <| min Config.stageCount model.stage + change
cmd =
setIntialVal =
if change /= 0 && newStage == 2 then
setInitialValues model.toNumberConfig
else
Cmd.none
in
( { model | stage = newStage }
, cmd
, Cmd.batch
[ setIntialVal
, setCssProp ( ".display-panel", "--show-stage", toString newStage )
]
)
Types.ImageSelected ->
( model
Expand Down
6 changes: 6 additions & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
console.log(state);
});

app.ports.setCssProp.subscribe(([selector, prop, value]) => {
for(const $el of document.querySelectorAll(selector)) {
$el.style.setProperty(prop, value);
}
});

/* Automatic text resizing */

function resizeText($node) {
Expand Down

0 comments on commit 50aa864

Please sign in to comment.