|
| 1 | +module ShapesReactHooks.Main where |
| 2 | + |
| 3 | +import Prelude |
| 4 | +import Data.Maybe (Maybe(..)) |
| 5 | +import Effect (Effect) |
| 6 | +import Effect.Exception (throw) |
| 7 | +import React.Basic.DOM (render, text) |
| 8 | +import React.Basic.DOM.SVG as R |
| 9 | +import React.Basic.Hooks (Component, component) |
| 10 | +import Web.HTML (window) |
| 11 | +import Web.HTML.HTMLDocument (body) |
| 12 | +import Web.HTML.HTMLElement (toElement) |
| 13 | +import Web.HTML.Window (document) |
| 14 | + |
| 15 | +main :: Effect Unit |
| 16 | +main = do |
| 17 | + body <- body =<< document =<< window |
| 18 | + case body of |
| 19 | + Nothing -> throw "Could not find body." |
| 20 | + Just b -> do |
| 21 | + shapesComponent <- mkShapesComponent |
| 22 | + render (shapesComponent unit) (toElement b) |
| 23 | + |
| 24 | +mkShapesComponent :: Component Unit |
| 25 | +mkShapesComponent = do |
| 26 | + component "ShapesComponent" \_ -> React.do |
| 27 | + pure |
| 28 | + $ R.svg |
| 29 | + { viewBox: "0 0 400 400" |
| 30 | + , width: "400" |
| 31 | + , height: "400" |
| 32 | + , children: |
| 33 | + [ R.circle |
| 34 | + { cx: "50" |
| 35 | + , cy: "50" |
| 36 | + , r: "40" |
| 37 | + , fill: "red" |
| 38 | + , stroke: "black" |
| 39 | + , strokeWidth: "3" |
| 40 | + } |
| 41 | + , R.rect |
| 42 | + { x: "100" |
| 43 | + , y: "10" |
| 44 | + , width: "40" |
| 45 | + , height: "40" |
| 46 | + , fill: "green" |
| 47 | + , stroke: "black" |
| 48 | + , strokeWidth: "2" |
| 49 | + } |
| 50 | + , R.line |
| 51 | + { x1: "20" |
| 52 | + , y1: "200" |
| 53 | + , x2: "200" |
| 54 | + , y2: "20" |
| 55 | + , stroke: "blue" |
| 56 | + , strokeWidth: "10" |
| 57 | + , strokeLinecap: "round" |
| 58 | + } |
| 59 | + , R.polyline |
| 60 | + { points: "200,40 240,40 240,80 280,80 280,120 320,120 320,160" |
| 61 | + , fill: "none" |
| 62 | + , stroke: "red" |
| 63 | + , strokeWidth: "4" |
| 64 | + , strokeDasharray: "20,2" |
| 65 | + } |
| 66 | + , R.text |
| 67 | + { x: "130" |
| 68 | + , y: "130" |
| 69 | + , fill: "black" |
| 70 | + , textAnchor: "middle" |
| 71 | + , dominantBaseline: "central" |
| 72 | + , transform: "rotate(-45 130,130)" |
| 73 | + , children: |
| 74 | + [ text "Welcome to Shapes Club" |
| 75 | + ] |
| 76 | + } |
| 77 | + ] |
| 78 | + } |
0 commit comments