Switch
With label
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open type Html
open type Svg
open type Datastar
let basicSwitch =
Switch.create "productUpdates" "Product updates"
|> Switch.renderWith help text
Receive one email with the week's activity.
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open type Html
open type Svg
open type Datastar
let switchWithHelp =
Switch.create "weeklySummary" "Weekly summary"
|> Switch.withDescription "Receive one email with the week's activity."
|> Switch.withChecked
|> Switch.renderSetting with submission
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open type Html
open type Svg
open type Datastar
let private choiceSubmitButton id (label:string) =
Button.create label
|> Button.withVariant ButtonVariant.Primary
|> Button.asSubmit
|> Button.withAttributes [ _id id ]
|> Button.render
let private choiceResult id result =
output {
_id id
_role "status"
_class "block min-h-5 text-sm text-[var(--fve-muted-text)]"
defaultArg result "Submit this ordinary form to see the server-owned result."
}
let switchFormRegion enabled validation result =
let config =
Switch.create "postingNotifications" "Posting notifications"
|> Switch.withId "components-posting-notifications"
|> Switch.withDescription "Notify account owners after entries post."
|> (if enabled then Switch.withChecked else id)
|> (match validation with Some message -> Switch.withValidation message | None -> id)
div {
_id "components-switch-form-region"
_class "grid max-w-sm gap-3"
form {
_dataOn ("submit", "@post('/components/choices/switch')")
_class "grid gap-3"
config |> Switch.render
choiceSubmitButton "components-switch-submit" "Save notifications"
}
choiceResult "components-switch-result" result
}
let postingNotifications = switchFormRegion true None NonePending
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open type Html
open type Svg
open type Datastar
let pendingNotifications =
Switch.create "postingNotifications" "Saving notifications"
|> Switch.withId "components-pending-notifications"
|> Switch.withChecked
|> Switch.pending
|> Switch.renderValidation error
Notification preferences could not be saved.
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open type Html
open type Svg
open type Datastar
let invalidNotifications =
Switch.create "postingNotifications" "Notification service"
|> Switch.withId "components-invalid-notifications"
|> Switch.withValidation "Notification preferences could not be saved."
|> Switch.render