From f1ce642804397cc72c62524047c00044c1b6e708 Mon Sep 17 00:00:00 2001 From: Michel Jansson Date: Wed, 12 Jul 2023 01:04:31 +0200 Subject: [PATCH] Add Action and Size parameters to widget --- src/BlazorTurnstile/Turnstile.razor | 17 +++++++++++++++++ src/BlazorTurnstile/TurnstileParameters.cs | 6 ++++++ src/BlazorTurnstile/TurnstileSize.cs | 10 ++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/BlazorTurnstile/TurnstileSize.cs diff --git a/src/BlazorTurnstile/Turnstile.razor b/src/BlazorTurnstile/Turnstile.razor index 7d77995..0682d59 100644 --- a/src/BlazorTurnstile/Turnstile.razor +++ b/src/BlazorTurnstile/Turnstile.razor @@ -36,9 +36,24 @@ [Parameter] public EventCallback OnErrorCallback { get; set; } + /// + /// 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 -. + /// + [Parameter] + public string Action { get; set; } = string.Empty; + + /// + /// The widget theme. The default is auto, which respects the user preference. + /// [Parameter] public TurnstileTheme? Theme { get; set; } + /// + /// The widget size. + /// + [Parameter] + public TurnstileSize? Size { get; set; } + /// /// Controls if an input element with the response token is created, defaults to true. /// @@ -66,7 +81,9 @@ await _interop.RenderAsync(_objRef!, _element, new TurnstileParameters(SiteKey) { + Action = Action, Theme = Theme, + Size = Size, ResponseField = ResponseField, ResponseFieldName = ResponseFieldName }); diff --git a/src/BlazorTurnstile/TurnstileParameters.cs b/src/BlazorTurnstile/TurnstileParameters.cs index 6605534..cb36e6e 100644 --- a/src/BlazorTurnstile/TurnstileParameters.cs +++ b/src/BlazorTurnstile/TurnstileParameters.cs @@ -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; } diff --git a/src/BlazorTurnstile/TurnstileSize.cs b/src/BlazorTurnstile/TurnstileSize.cs new file mode 100644 index 0000000..89292a0 --- /dev/null +++ b/src/BlazorTurnstile/TurnstileSize.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace BlazorTurnstile; + +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum TurnstileSize +{ + normal, + compact, +}