This repository provides an F# WebSharper binding for the Popover API, enabling WebSharper applications to show and hide HTML popovers using the native browser API.
The repository consists of two main projects:
-
Binding Project:
- Contains the F# WebSharper binding for the Popover API.
-
Sample Project:
- Demonstrates how to use the Popover API with WebSharper syntax.
- Includes a GitHub Pages demo: View Demo
To use this package in your WebSharper project, add the NuGet package:
dotnet add package WebSharper.Popover- .NET SDK installed on your machine.
-
Clone the repository:
git clone https://github.com/dotnet-websharper/Popover.git cd Popover -
Build the Binding Project:
dotnet build WebSharper.Popover/WebSharper.Popover.fsproj
-
Build and Run the Sample Project:
cd WebSharper.Popover.Sample dotnet build dotnet run
Below is an example of how to use the Popover API in a WebSharper project:
namespace WebSharper.Popover.Sample
open WebSharper
open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Client
open WebSharper.UI.Templating
open WebSharper.Popover
[<JavaScript>]
module Client =
// The templates are loaded from the DOM, so you just can edit index.html
// and refresh your browser, no need to recompile unless you add or remove holes.
type IndexTemplate = Template<"wwwroot/index.html", ClientLoad.FromDocument>
// Reference the popover element
let myPopover = JS.Document.GetElementById("myPopover")
let popover = myPopover |> As<HTMLElement>
[<SPAEntryPoint>]
let Main () =
IndexTemplate.Main()
// Show button click triggers showPopover on the target element
.ShowBtn(fun _ ->
popover.ShowPopover() |> ignore
)
// Hide button click triggers hidePopover on the target element
.HideBtn(fun _ ->
popover.HidePopover() |> ignore
)
.Doc()
|> Doc.RunById "main"This example demonstrates how to programmatically control the visibility of a native popover element using WebSharper and the Popover API.
- The Popover API is supported in most modern browsers. Check the compatibility table on MDN for more details.