Skip to content

Commit 9e910f5

Browse files
committed
task - updated Ds.onIntersect with __exit and __threshold modifiers #19
1 parent e81d978 commit 9e910f5

File tree

9 files changed

+35
-10
lines changed

9 files changed

+35
-10
lines changed

examples/ClickAndSwap/ClickAndSwap.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Compile Include="ClickAndSwap.fs" />
77
</ItemGroup>
88
<ItemGroup>
9-
<PackageReference Include="Falco" Version="5.0.0" />
9+
<PackageReference Include="Falco" Version="5.1.0" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\..\src\Falco.Datastar\Falco.Datastar.fsproj" />

examples/ClickToEdit/ClickToEdit.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Falco" Version="5.0.0" />
12+
<PackageReference Include="Falco" Version="5.1.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

examples/ClickToLoad/ClickToLoad.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>net9.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="Falco" Version="5.0.0" />
6+
<PackageReference Include="Falco" Version="5.1.0" />
77
</ItemGroup>
88
<ItemGroup>
99
<ProjectReference Include="..\..\src\Falco.Datastar\Falco.Datastar.fsproj" />

examples/InputForm/InputForm.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Compile Include="InputForm.fs" />
77
</ItemGroup>
88
<ItemGroup>
9-
<PackageReference Include="Falco" Version="5.0.0" />
9+
<PackageReference Include="Falco" Version="5.1.0" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\..\src\Falco.Datastar\Falco.Datastar.fsproj" />

examples/Signals/Signals.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Falco" Version="5.0.0" />
16+
<PackageReference Include="Falco" Version="5.1.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

src/Falco.Datastar/Ds.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,19 @@ type Ds =
313313
/// https://data-star.dev/reference/attributes#data-on-intersect
314314
/// </summary>
315315
/// <param name="expression">Expression to run when element is intersected</param>
316-
/// <param name="visibility">Sets it to trigger only if the element is half or fully viewed</param>
316+
/// <param name="visibility">Sets it to trigger only if the element is exited, or half or fully viewed</param>
317317
/// <param name="onlyOnce">Only triggers the event once</param>
318318
/// <param name="delayMs">The time to wait before executing the expression in milliseconds; default = 0</param>
319-
/// <param name="debounce"></param>
320-
/// <param name="throttle"></param>
319+
/// <param name="debounce">Debounce the event listener</param>
320+
/// <param name="throttle">Throttle the event listener</param>
321321
/// <param name="viewTransition">Wrap expression in document.startViewTransition(); default = false</param>
322+
/// <param name="threshold">Triggers when the element is visible by a certain percentage (0-100)</param>
322323
/// <returns>Attribute</returns>
323-
static member onIntersect (expression, ?visibility, ?onlyOnce, ?delayMs:int, ?debounce:Debounce, ?throttle:Throttle, ?viewTransition:bool) =
324+
static member onIntersect (expression, ?visibility, ?onlyOnce, ?delayMs:int, ?debounce:Debounce, ?throttle:Throttle, ?viewTransition:bool, ?threshold:int) =
324325
DsAttr.start "on-intersect"
325326
|> (fun dsAttr ->
326327
match visibility with
328+
| Some vis when vis = IntersectsVisibility.Exit -> DsAttr.addModifierName "exit" dsAttr
327329
| Some vis when vis = IntersectsVisibility.Full -> DsAttr.addModifierName "full" dsAttr
328330
| Some vis when vis = IntersectsVisibility.Half -> DsAttr.addModifierName "half" dsAttr
329331
| _ -> dsAttr
@@ -333,6 +335,7 @@ type Ds =
333335
|> DsAttr.addModifierOption (delayMs |> Option.toValueOption |> ValueOption.map DsAttrModifier.DelayMs)
334336
|> DsAttr.addModifierOption (debounce |> Option.toValueOption |> ValueOption.map DsAttrModifier.Debounce)
335337
|> DsAttr.addModifierOption (throttle |> Option.toValueOption |> ValueOption.map DsAttrModifier.Throttle)
338+
|> DsAttr.addModifierOption (threshold |> Option.toValueOption |> ValueOption.map (fun vv -> DsAttrModifier.Threshold (Math.Clamp(vv, 0, 100))))
336339
|> DsAttr.addValue expression
337340
|> DsAttr.create
338341

src/Falco.Datastar/Falco.Datastar.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<ItemGroup>
4040
<PackageReference Include="Falco" Version="5.1.0" />
4141
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.*" PrivateAssets="All" />
42-
<PackageReference Include="StarFederation.Datastar.FSharp" Version="1.1.3" />
42+
<PackageReference Include="StarFederation.Datastar.FSharp" Version="1.2.0" />
4343
<PackageReference Update="FSharp.Core" Version="6.0.0"/>
4444
</ItemGroup>
4545

src/Falco.Datastar/Types.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module Selector =
7070
let sel = Selector.create
7171

7272
type IntersectsVisibility =
73+
/// Triggers on exit
74+
| Exit
7375
/// Triggers when half of the element is visible
7476
| Half
7577
/// Triggers when the full element is visible
@@ -306,6 +308,10 @@ type DsAttrModifier =
306308
if debounce.NoTrailing then "notrailing"
307309
] }
308310

311+
static member inline Threshold (threshold:int) =
312+
{ Name = "threshold"
313+
Tags = [ $"{threshold}" ] }
314+
309315
static member inline OnEventModifier (onEventModifier:OnEventModifier) =
310316
match onEventModifier with
311317
| Once -> { Name = "once"; Tags = [] }

test/Falco.Datastar.Tests/DsTests.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@ module DsTests =
6060
let filterFiles : SignalsFilter = { IncludePattern = ValueSome "files$"; ExcludePattern = ValueSome "^files" }
6161
renderAttr (Ds.jsonSignalsOptions (filterFiles, terse = true))
6262
|> should equal """<div data-json-signals__terse="{ include: /files$/,exclude: /^files/ }"></div>"""
63+
64+
[<Fact>]
65+
let ``Ds.onIntersect No Options`` () =
66+
renderAttr (Ds.onIntersect "@get('/hello')")
67+
|> should equal """<div data-on-intersect="@get('/hello')"></div>"""
68+
69+
[<Fact>]
70+
let ``Ds.onIntersect Threshold`` () =
71+
renderAttr (Ds.onIntersect ("@get('/hello')", threshold=50))
72+
|> should equal """<div data-on-intersect__threshold.50="@get('/hello')"></div>"""
73+
74+
[<Fact>]
75+
let ``Ds.style`` () =
76+
renderAttr (Ds.style ("display", "$hiding && 'none'"))
77+
|> should equal """<div data-style:display="$hiding && 'none'"></div>"""
78+

0 commit comments

Comments
 (0)