Search code examples
f#elmish

How do i apply both hard-coded and method classes in Elmish?


I am formatting a web application made using F# and the SAFE stack. I am using a variable to determine a CSS class to change the formatting of a tag, but I also need two hard-coded CSS classes, and I am unsure how to have both.

I have this:

let statusTag (state:Appointment.State) =
    span [ Class (state.ToString()) ] [ str (sprintf "%A" state) ]

And i need it to work more like this:

let statusTag (state:Appointment.State) =
    span [ Class "status text" + (state.ToString()) ] [ str (sprintf "%A" state) ]

But i dont know how to do this in F#

Any help would be appreciated


Solution

  • The only thing that seems wrong with your attempt is that you need extra parentheses around the expression that constructs the string with the names of the classes (on the other hand, you do not need it around the state.ToString() call). The following should do the trick:

    let statusTag (state:Appointment.State) =
        span [ Class("status text" + state.ToString()) ] [ str (sprintf "%A" state) ]