-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding DateTimePicker, EmailTextInput, UrlTextInput, and NumberInput …
…block elements
- Loading branch information
Showing
6 changed files
with
211 additions
and
30 deletions.
There are no files selected for viewing
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,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; } | ||
} |
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,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; } | ||
} |
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,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; | ||
} |
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
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,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; } | ||
} |
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,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; } | ||
} |