-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update event modifiers to use
HTMLModifier
.
- Loading branch information
JPToroDev
committed
Jan 18, 2025
1 parent
3e0fbcc
commit 592fc7b
Showing
4 changed files
with
138 additions
and
35 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Sources/Ignite/Actions/Event Modifiers/ClickModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// ClickModifier.swift | ||
// Ignite | ||
// https://www.github.com/twostraws/Ignite | ||
// See LICENSE for license information. | ||
// | ||
|
||
/// A modifier that adds a click event handler to an HTML element. | ||
struct ClickModifier: HTMLModifier { | ||
let actions: [Action] | ||
|
||
func body(content: some HTML) -> any HTML { | ||
content.addEvent(name: "onclick", actions: actions) | ||
} | ||
} | ||
|
||
public extension HTML { | ||
/// Adds an "onclick" JavaScript event to this element. | ||
/// - Parameter actions: A closure that returns the actions to execute when clicked. | ||
/// - Returns: A modified HTML element with the click event handler attached. | ||
func onClick(@ActionBuilder actions: () -> [Action]) -> some HTML { | ||
modifier(ClickModifier(actions: actions())) | ||
} | ||
} | ||
|
||
public extension InlineHTML { | ||
/// Adds an "onclick" JavaScript event to this inline element. | ||
/// - Parameter actions: A closure that returns the actions to execute when clicked. | ||
/// - Returns: A modified inline HTML element with the click event handler attached. | ||
func onClick(@ActionBuilder actions: () -> [Action]) -> some InlineHTML { | ||
modifier(ClickModifier(actions: actions())) | ||
} | ||
} | ||
|
||
public extension BlockHTML { | ||
/// Adds an "onclick" JavaScript event to this block element. | ||
/// - Parameter actions: A closure that returns the actions to execute when clicked. | ||
/// - Returns: A modified block HTML element with the click event handler attached. | ||
func onClick(@ActionBuilder actions: () -> [Action]) -> some BlockHTML { | ||
modifier(ClickModifier(actions: actions())) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Sources/Ignite/Actions/Event Modifiers/DoubleClickModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// DoubleClickModifier.swift | ||
// Ignite | ||
// https://www.github.com/twostraws/Ignite | ||
// See LICENSE for license information. | ||
// | ||
|
||
/// A modifier that adds a double click event handler to an HTML element. | ||
struct DoubleClickModifier: HTMLModifier { | ||
let actions: [Action] | ||
|
||
func body(content: some HTML) -> any HTML { | ||
content.addEvent(name: "ondblclick", actions: actions) | ||
} | ||
} | ||
|
||
public extension HTML { | ||
/// Adds an "ondblclick" JavaScript event to this element. | ||
/// - Parameter actions: A closure that returns the actions to execute when double-clicked. | ||
/// - Returns: A modified HTML element with the double click event handler attached. | ||
func onDoubleClick(@ActionBuilder actions: () -> [Action]) -> some HTML { | ||
modifier(DoubleClickModifier(actions: actions())) | ||
} | ||
} | ||
|
||
public extension InlineHTML { | ||
/// Adds an "ondblclick" JavaScript event to this inline element. | ||
/// - Parameter actions: A closure that returns the actions to execute when double-clicked. | ||
/// - Returns: A modified inline HTML element with the double click event handler attached. | ||
func onDoubleClick(@ActionBuilder actions: () -> [Action]) -> some InlineHTML { | ||
modifier(DoubleClickModifier(actions: actions())) | ||
} | ||
} | ||
|
||
public extension BlockHTML { | ||
/// Adds an "ondblclick" JavaScript event to this block element. | ||
/// - Parameter actions: A closure that returns the actions to execute when double-clicked. | ||
/// - Returns: A modified block HTML element with the double click event handler attached. | ||
func onDoubleClick(@ActionBuilder actions: () -> [Action]) -> some BlockHTML { | ||
modifier(DoubleClickModifier(actions: actions())) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Sources/Ignite/Actions/Event Modifiers/HoverModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// EventModifiers.swift | ||
// Ignite | ||
// https://www.github.com/twostraws/Ignite | ||
// See LICENSE for license information. | ||
// | ||
|
||
/// A modifier that adds hover event handlers to an HTML element. | ||
struct HoverModifier: HTMLModifier { | ||
let hoverActions: [Action] | ||
let unhoverActions: [Action] | ||
|
||
func body(content: some HTML) -> any HTML { | ||
content | ||
.addEvent(name: "onmouseover", actions: hoverActions) | ||
.addEvent(name: "onmouseout", actions: unhoverActions) | ||
} | ||
} | ||
|
||
public extension HTML { | ||
/// Adds "onmouseover" and "onmouseout" JavaScript events to this element. | ||
/// - Parameter actions: A closure that takes a Boolean indicating hover state and returns actions to execute. | ||
/// - Returns: A modified HTML element with the hover event handlers attached. | ||
func onHover(@ActionBuilder actions: (_ isHovering: Bool) -> [Action]) -> some HTML { | ||
modifier(HoverModifier( | ||
hoverActions: actions(true), | ||
unhoverActions: actions(false) | ||
)) | ||
} | ||
} | ||
|
||
public extension InlineHTML { | ||
/// Adds "onmouseover" and "onmouseout" JavaScript events to this inline element. | ||
/// - Parameter actions: A closure that takes a Boolean indicating hover state and returns actions to execute. | ||
/// - Returns: A modified inline HTML element with the hover event handlers attached. | ||
func onHover(@ActionBuilder actions: (_ isHovering: Bool) -> [Action]) -> some InlineHTML { | ||
modifier(HoverModifier( | ||
hoverActions: actions(true), | ||
unhoverActions: actions(false) | ||
)) | ||
} | ||
} | ||
|
||
public extension BlockHTML { | ||
/// Adds "onmouseover" and "onmouseout" JavaScript events to this block element. | ||
/// - Parameter actions: A closure that takes a Boolean indicating hover state and returns actions to execute. | ||
/// - Returns: A modified block HTML element with the hover event handlers attached. | ||
func onHover(@ActionBuilder actions: (_ isHovering: Bool) -> [Action]) -> some BlockHTML { | ||
modifier(HoverModifier( | ||
hoverActions: actions(true), | ||
unhoverActions: actions(false) | ||
)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.