This gist: https://gist.github.com/lucamug/8842415a63935fb5b58e133cfb2566ed
Clone and copy the content of the src folders of these two repos in your project
https://github.com/mdgriffith/elm-ui/tree/2.0
https://github.com/mdgriffith/elm-animator/tree/v2
Get the code from the branches 2.0 for elm-ui, and v2 for elm-animator.
Copy these in your project, for example under
elm-vendored/elm-ui-2/src
elm-vendored/elm-animator-2/src
Add these two folders in the source-directories section of elm.json.
This repository contains all the necessary files:
https://github.com/lucamug/elm-ui-v2-testing/
Deployed at
https://lucamug.github.io/elm-ui-v2-testing/
Also available in Replit for quick testing (use elm reactor as elm-watch seems not working there).
https://replit.com/@lucamug/elm-ui-v2-testing#src/Sliders.elm
elm-json install avh4/elm-color
radians is exposed by 2 of the imports:
Basics.radians
Ui.radians
If you import it like
import Ui exposing (..)
you still need to prefix radians as Ui.radians to avoid the conflict.
- From
import Element exposing (..)toimport Ui exposing (..) - From
import Element.Events as Eventstoimport Ui.Events as Events - From
import Element.Font as Fonttoimport Ui.Font as Font - From
import Element.Input as Inputtoimport Ui.Input as Input
import Element.Background as Backgroundimport Element.Border as Border
import Ui.Prose as Prose(forparagraph)import Color(When color management is needed)import Ui.Shadow as Shadow
- Replace
rgb255withrgb - Convert floating colors to integers multipling by 255 (e.g. 0.8 = 0.8 * 255 = 204)
- Replace
rgb 1 1 1withrgb 255 255 255 - Replace
rgba 1 1 1withrgba 255 255 255
- Replace
Border.widthwithborder - Replace
Border.shadowwithShadow.shadows - Replace the
Shadow.shadowsargument from{ blur = 12, color = rgba 0 0 0 0.15, offset = ( 0, -2 ), size = 0 }to[ { blur = 12, color = rgba 0 0 0 0.15, size = 0, x = 0, y = -2 } ](note the added list and the decomposition ofoffsettoxandy. - Replace
Border.widthEachwithborderWith - Replace
Border.colorwithborderColor - Replace
Border.roundedwithrounded
- Replace
Background.colortobackground.
Note that border set the width, while background set the color. To set the color for a border, use borderColor.
- Replace
moveDown 4tomove <| down 4. Also convert the argument toIntusingroundor removingtoFloat - The same for
moveUp,moveLeft,moveRight - Multiple
movedo not compose in v2, but they were composing in v1. To compose them in v2, call them asmove { x=0, y=0, z=0 } - Note that in v1 move was using CSS
tranformation, while in v2 is using CSStranslation. So if you use CSS transition you need to do something liketransition: translate 150ms ease-out.
- Replace
Input.buttonwithel - Move
Input.buttonamong the attributes, taking the message for theonPressvalue (without theMaybe) - Remove the record
{ label = ..., onPress = ... }with just the content of the label.
Input.button
[ height <| px 20 ]
{ label = el [ centerX, centerY ] <| html "Back"
, onPress = Just UserPressedBackButton
}
el
[ height <| px 20
, Input.button UserPressedBackButton
]
(el [ centerX, centerY ] <| html "Back")
- Most (if not all)
width fillare unnecessary now. - Some new
width shrinkmay became necessary here and there. - Some new
height fillmay became necessary, for example in case ofinFront.
width <| maximum (500) <| fill
widthMax 500
This doesn't have an immediate replacement.
It can be replaced with Ui.Anim.onHover but I haven't look into it yet.
Labels are handled differently in V2. They are created separately and added using the usual row, column approach.
For example:
f =
let
label : { element : Element msg, id : Input.Label }
label =
Input.label "client-id"
[ Font.size 12, width shrink ]
(text "Client ID")
in
row
[ spacing 8 ]
[ label.element
, Input.text [ Font.size 12, padding 5 ]
{ label = label.id
, onChange = UserChangedClientId
, placeholder = Nothing
, text = model.clientId
}
]
wrappedRow seems to be replaceable with
row [ wrap ] ...
- Replace
Font.heavywithFont.weight 900 - Replace
Font.extraBoldwithFont.weight 800 - Replace
Font.boldwithFont.weight 700 - Replace
Font.semiBoldwithFont.weight 600 - Replace
Font.mediumwithFont.weight 500 - Replace
Font.regularwithFont.weight 400 - Replace
Font.lightwithFont.weight 300 - Replace
Font.extraLightwithFont.weight 200 - Replace
Font.hairlinewithFont.weight 100
This became linkNewTab and it is now an attribute, so from
newTabLink (linkAttrsInline ++ attrs)
{ label = Prose.paragraph [] [ text (label ++ " ⬀") ]
, url = url
}
to
el (linkAttrsInline ++ attrs ++ [ linkNewTab url ])
(Prose.paragraph [] [ text (label ++ " ⬀") ])
The same for link. It has the same name bit it is now an attribute, not an element anymore.
fillPortion is now portion.
scrollbars is now scrollable.
Before it was just
{ description : String
, src : String
}
Now is
{ source : String
, description : String
, onLoad : Maybe msg
}
Region.heading 1 is now Ui.Accessibility.h1
- Replace
alphawithopacity - Replace
layoutwithlayout default - Replace
layoutWithwithlayout. Note that the options are different now.
Report issues at https://www.notion.so/25d2ac32de2980ad8f91c175cd1f84d5?v=25d2ac32de2980588787000ce0b324be
elm-ui V2 seem introducing a reduction of assets size (around 5%)
These are some values from a small Elm project:
7,819 lines of Elm code
elm-ui 1.1.8
240,627 bytes minified
63,802 bytes compressed
elm-ui 2.0
215,350 bytes minified
59,495 bytes compressed
-10.5 % minified
-6.8 % compressed
================
10,662 lines of Elm code
elm-ui 1.1.8
517,358 bytes minified
120,421 bytes compressed
elm-ui 2.0
484,203 bytes minified
114,305 bytes compressed
-6.4 %
-5.1 %