Skip to content

Commit

Permalink
#1 - Update binding to version 11.7 and convert to be npm based (#2)
Browse files Browse the repository at this point in the history
* #1  Initial update to WS7 (beta)
- Uses npm package instead of concrete cdn link
- Upgrade to SweetAlert2 (https://sweetalert2.github.io/), version 11.7+

* Moved helper pattern into its own sub-module

* meta/info changes

* typo fix in paket template + removed AssemblyTitle/Desc attributes
  • Loading branch information
GyGerg authored and Jooseppi12 committed Nov 23, 2023
1 parent e5b81a3 commit b19f08d
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 151 deletions.
77 changes: 43 additions & 34 deletions WebSharper.SweetAlert Sample Page/Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,73 +24,82 @@ open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Html
open WebSharper.UI.Client
open WebSharper.UI.Notation
open WebSharper.UI.Templating
open WebSharper.SweetAlert

[<JavaScript>]
module Client =
module Helpers =
let (|IsConfirmed|IsDenied|IsDismissed|) (res: SweetAlertResult<'T>) =
if res.IsConfirmed then IsConfirmed(res.Value)
else if res.IsDismissed then IsDismissed(res.Dismiss)
else if res.IsDenied then IsDenied
else failwith "SweetAlert JS failure: Result not set as confirmed, dimissed or denied"

open Helpers

[<SPAEntryPoint>]
let Main () =
let Alert0=
SweetAlert.Box(
let Alert0 () =
Swal.Fire<unit>(SweetAlertOptions(
TitleText = "Information",
Text = "It works!",
Type = "info",
Icon = SweetAlertIcon.Info,
AllowOutsideClick = true,
ShowCancelButton = true
)
let Alert1 =
SweetAlert.Box(
))
let Alert1 () =
Swal.Fire<unit>(SweetAlertOptions(
TitleText = "Click",
Text = "You have clicked on the button!",
Type = "success",
Icon = SweetAlertIcon.Success,
ConfirmButtonText = "Cool",
ConfirmButtonColor = "#000000"
)

let Alert2 =
SweetAlert.Box(
))
let InputAlert () =
Swal.Fire<string>(SweetAlertOptions(
TitleText = "Input",
Text = "Hello! Please say something",
Type = "info",
Input = "text"
)
SweetAlert.SetDefaults Alert0
SweetAlert.ShowBox Alert0 |> ignore
Icon = SweetAlertIcon.Info,
Input = SweetAlertInput.Text
))

Alert0() |> ignore
let btn1 =
Doc.Button "Click me!" [] (fun () ->
SweetAlert.ShowBox Alert1 |> ignore
Alert1() |> ignore
)
let rResult = Var.Create ""


let btn2 =

Doc.Button "Input" [] (fun () ->
// (SweetAlert.ShowBox Alert2).Then(fun r ->
// let Alert = Box(Text = "You have wrote: "+string(r), TitleText = "Result")
// Console.Log r
// SweetAlert.ShowBox(Alert)|>ignore) |> ignore

SweetAlert.ShowBox(Alert2).Then(fun x -> rResult := x)|> ignore
// SweetAlert.Close()
// SweetAlert.ShowBox(Alert2).State() |> Console.Log
// SweetAlert.ShowBox(Alert2).Then (fun result -> Console.Log result) |> ignore
// SweetAlert.Then(SweetAlert(Alert2)) |> Console.Log

// rValue.Value <- SweetAlert.Then(SweetAlert.ShowBox(Alert2))
// SweetAlert.GetInput |> Console.Log
promise {
let! result = InputAlert()
Console.Log result

return!
match result with
| IsConfirmed v ->
rResult.Set v
("Result", $"You have wrote: {v}")
| IsDismissed reason ->
("Dismissed", $"Dismissed with reason: {reason}")
| IsDenied ->
("Denied", "Dialog denied.")
|> Swal.Fire
} |> ignore
()

)

Doc.Concat[
btn1
br[][]
br [] []
btn2
h2[][text "The last input was: "]
p[][textView rResult.View]
h2 [] [text "The last input was: "]
p [] [textView rResult.View]
]
|> Doc.RunById "main"

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
<ItemGroup>
<Compile Include="Client.fs" />
</ItemGroup>
<ItemGroup>
<!--<ItemGroup>
<ProjectReference Include="../WebSharper.SweetAlert/WebSharper.SweetAlert.fsproj" />
</ItemGroup>
</ItemGroup>-->
<ItemGroup>
<Reference Include="WebSharper.SweetAlert">
<HintPath>..\WebSharper.SweetAlert\bin\Debug\netstandard2.0\WebSharper.SweetAlert.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="..\paket-files\wsbuild\github.com\dotnet-websharper\build-script\WebSharper.Fake.targets" Condition="Exists('..\paket-files\wsbuild\github.com\dotnet-websharper\build-script\WebSharper.Fake.targets')" />
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
6 changes: 3 additions & 3 deletions WebSharper.SweetAlert Sample Page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<title>WebSharper.SweetAlert_Sample_Page</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="Content/WebSharper.SweetAlert_Sample_Page.css" />
<link rel="stylesheet" type="text/css" href="./Content/WebSharper.SweetAlert%20Sample%20Page.css" />
<style>
/* Don't show the not-yet-loaded templates */
[ws-template], [ws-children-template] { display: none; }
</style>
<script type="text/javascript" src="Content/WebSharper.SweetAlert_Sample_Page.head.js"></script>
<script type="module" src="./Content/WebSharper.SweetAlert%20Sample%20Page.head.js"></script>
</head>
<body>
<h1>WebSharper.SweetAlert sample page</h1>
<div id="main">
</div>
<script type="text/javascript" src="Content/WebSharper.SweetAlert_Sample_Page.min.js"></script>
<script type="module" src="./Content/WebSharper.SweetAlert%20Sample%20Page.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions WebSharper.SweetAlert Sample Page/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions WebSharper.SweetAlert Sample Page/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "websharper.sweetalert-sample-page",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sweetalert2": "^11.7.27"
}
}
Loading

0 comments on commit b19f08d

Please sign in to comment.