Skip to content

Commit

Permalink
Adding DateTimePicker, EmailTextInput, UrlTextInput, and NumberInput …
Browse files Browse the repository at this point in the history
…block elements
  • Loading branch information
soxtoby committed Jan 15, 2023
1 parent 4118aa9 commit 22c7ccb
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 30 deletions.
39 changes: 39 additions & 0 deletions SlackNet/Blocks/DateTimePicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace SlackNet.Blocks;

/// <summary>
/// An element which lets users easily select a date from a calendar style UI.
/// </summary>
[SlackType("datetimepicker")]
public class DateTimePicker : ActionElement, IInputBlockElement
{
public DateTimePicker() : base("datetimepicker") { }

/// <summary>
/// The initial date and time that is selected when the element is loaded.
/// </summary>
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime? InitialDateTime { get; set; }

/// <summary>
/// Indicates whether the element will be set to auto focus within the <see cref="ViewInfo"/> object. Only one element can be set to true.
/// </summary>
public bool FocusOnLoad { get; set; }
}

[SlackType("datetimepicker")]
public class DateTimePickerAction : BlockAction
{
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime? SelectedDateTime { get; set; }
}

[SlackType("datetimepicker")]
public class DateTimePickerValue : ElementValue
{
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime? SelectedDateTime { get; set; }
}
18 changes: 18 additions & 0 deletions SlackNet/Blocks/EmailTextInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SlackNet.Blocks;

public class EmailTextInput : TextInput
{
public EmailTextInput() : base("email_text_input") { }
}

[SlackType("email_text_input")]
public class EmailTextInputAction : BlockAction
{
public string Value { get; set; }
}

[SlackType("email_text_input")]
public class EmailTextInputValue : ElementValue
{
public string Value { get; set; }
}
100 changes: 100 additions & 0 deletions SlackNet/Blocks/NumberInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Globalization;
using Newtonsoft.Json;

namespace SlackNet.Blocks;

public class NumberInput : TextInput
{
public NumberInput() : base("number_input") { }

/// <summary>
/// Decimal numbers are allowed if this is set to true.
/// </summary>
public bool IsDecimalAllowed { get; set; }

/// <summary>
/// The minimum value, cannot be greater than <see cref="MaxValue"/>.
/// </summary>
public string MinValue { get; set; }

/// <summary>
/// The maximum value, cannot be less than <see cref="MinValue"/>.
/// </summary>
public string MaxValue { get; set; }

/// <summary>
/// The initial value in the input when it is loaded, as a double.
/// </summary>
[JsonIgnore]
public double? InitialDouble
{
get => double.TryParse(InitialValue, out var value) ? value : null;
set => InitialValue = value?.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// The initial value in the input when it is loaded, as an integer.
/// </summary>
[JsonIgnore]
public int? InitialInteger
{
get => int.TryParse(InitialValue, out var value) ? value : null;
set => InitialValue = value?.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// The minimum value as a double, cannot be greater than <see cref="MaxValue"/>.
/// </summary>
[JsonIgnore]
public double? MinDouble
{
get => double.TryParse(MinValue, out var value) ? value : null;
set => MinValue = value?.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// The minimum value as an integer, cannot be greater than <see cref="MaxValue"/>.
/// </summary>
[JsonIgnore]
public int? MinInteger
{
get => int.TryParse(MinValue, out var value) ? value : null;
set => MinValue = value?.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// The maximum value as a double, cannot be less than <see cref="MinValue"/>.
/// </summary>
[JsonIgnore]
public double? MaxDouble
{
get => double.TryParse(MaxValue, out var value) ? value : null;
set => MaxValue = value?.ToString(CultureInfo.InvariantCulture);
}

/// <summary>
/// The maximum value as an integer, cannot be less than <see cref="MinValue"/>.
/// </summary>
[JsonIgnore]
public int? MaxInteger
{
get => int.TryParse(MaxValue, out var value) ? value : null;
set => MaxValue = value?.ToString(CultureInfo.InvariantCulture);
}
}

[SlackType("number_input")]
public class NumberInputAction : BlockAction
{
public string Value { get; set; }
public double? DoubleValue => double.TryParse(Value, out var value) ? value : null;
public int? IntegerValue => int.TryParse(Value, out var value) ? value : null;
}

[SlackType("number_input")]
public class NumberInputValue : ElementValue
{
public string Value { get; set; }
public double? DoubleValue => double.TryParse(Value, out var value) ? value : null;
public int? IntegerValue => int.TryParse(Value, out var value) ? value : null;
}
31 changes: 1 addition & 30 deletions SlackNet/Blocks/PlainTextInput.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
using SlackNet.Interaction;

namespace SlackNet.Blocks;

public class PlainTextInput : BlockElement, IInputBlockElement
public class PlainTextInput : TextInput
{
public PlainTextInput() : base("plain_text_input") { }

/// <summary>
/// An identifier for the input value when the parent modal is submitted.
/// You can use this when you receive a <see cref="ViewSubmission"/> payload to identify the value of the input element.
/// Should be unique among all other <see cref="IActionElement.ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }

/// <summary>
/// A plain text object that defines the placeholder text shown in the plain-text input.
/// </summary>
public PlainText Placeholder { get; set; }

/// <summary>
/// The initial value in the plain-text input when it is loaded.
/// </summary>
public string InitialValue { get; set; }

/// <summary>
/// Indicates whether the input will be a single line (False) or a larger textarea (True).
/// </summary>
Expand All @@ -37,16 +18,6 @@ public PlainTextInput() : base("plain_text_input") { }
/// The maximum length of input that the user can provide. If the user provides more, they will receive an error.
/// </summary>
public int? MaxLength { get; set; }

/// <summary>
/// A <see cref="DispatchActionConfig"/> that determines when during text input the element returns a <see cref="BlockAction"/> payload.
/// </summary>
public DispatchActionConfig DispatchActionConfig { get; set; }

/// <summary>
/// Indicates whether the element will be set to auto focus within the <see cref="ViewInfo"/> object. Only one element can be set to true.
/// </summary>
public bool FocusOnLoad { get; set; }
}

[SlackType("plain_text_input")]
Expand Down
35 changes: 35 additions & 0 deletions SlackNet/Blocks/TextInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using SlackNet.Interaction;

namespace SlackNet.Blocks;

public abstract class TextInput : BlockElement, IInputBlockElement
{
protected TextInput(string type) : base(type) { }

/// <summary>
/// An identifier for the input value when the parent modal is submitted.
/// You can use this when you receive a <see cref="ViewSubmission"/> payload to identify the value of the input element.
/// Should be unique among all other <see cref="IActionElement.ActionId"/>s used elsewhere by your app.
/// </summary>
public string ActionId { get; set; }

/// <summary>
/// The initial value in the input when it is loaded.
/// </summary>
public string InitialValue { get; set; }

/// <summary>
/// A plain text object that defines the placeholder text shown in the input.
/// </summary>
public PlainText Placeholder { get; set; }

/// <summary>
/// A <see cref="DispatchActionConfig"/> that determines when during text input the element returns a <see cref="BlockAction"/> payload.
/// </summary>
public DispatchActionConfig DispatchActionConfig { get; set; }

/// <summary>
/// Indicates whether the element will be set to auto focus within the <see cref="ViewInfo"/> object. Only one element can be set to true.
/// </summary>
public bool FocusOnLoad { get; set; }
}
18 changes: 18 additions & 0 deletions SlackNet/Blocks/UrlTextInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SlackNet.Blocks;

public class UrlTextInput : TextInput
{
public UrlTextInput() : base("url_text_input") { }
}

[SlackType("url_text_input")]
public class UrlTextInputAction : BlockAction
{
public string Value { get; set; }
}

[SlackType("url_text_input")]
public class UrlTextInputValue : ElementValue
{
public string Value { get; set; }
}

0 comments on commit 22c7ccb

Please sign in to comment.