Skip to content

Commit

Permalink
Add Action and Size parameters to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelJansson committed Jul 11, 2023
1 parent 9e477dc commit f1ce642
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/BlazorTurnstile/Turnstile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@
[Parameter]
public EventCallback<string> OnErrorCallback { get; set; }

/// <summary>
/// A customer value that can be used to differentiate widgets under the same sitekey in analytics and which is returned upon validation. This can only contain up to 32 alphanumeric characters including _ and -.
/// </summary>
[Parameter]
public string Action { get; set; } = string.Empty;

/// <summary>
/// The widget theme. The default is auto, which respects the user preference.
/// </summary>
[Parameter]
public TurnstileTheme? Theme { get; set; }

/// <summary>
/// The widget size.
/// </summary>
[Parameter]
public TurnstileSize? Size { get; set; }

/// <summary>
/// Controls if an input element with the response token is created, defaults to true.
/// </summary>
Expand Down Expand Up @@ -66,7 +81,9 @@

await _interop.RenderAsync(_objRef!, _element, new TurnstileParameters(SiteKey)
{
Action = Action,
Theme = Theme,
Size = Size,
ResponseField = ResponseField,
ResponseFieldName = ResponseFieldName
});
Expand Down
6 changes: 6 additions & 0 deletions src/BlazorTurnstile/TurnstileParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ namespace BlazorTurnstile;

internal record TurnstileParameters(string sitekey)
{
[JsonPropertyName("action")]
public string Action { get; set; } = string.Empty;

[JsonPropertyName("theme")]
public TurnstileTheme? Theme { get; set; }

[JsonPropertyName("size")]
public TurnstileSize? Size { get; set; }

[JsonPropertyName("response-field")]
public bool? ResponseField { get; set; }

Expand Down
10 changes: 10 additions & 0 deletions src/BlazorTurnstile/TurnstileSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Text.Json.Serialization;

namespace BlazorTurnstile;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TurnstileSize
{
normal,
compact,
}

0 comments on commit f1ce642

Please sign in to comment.