Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the style of the checkboxes for multi-selection #1244

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Spectre.Console/Prompts/List/ListPromptConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ internal sealed class ListPromptConstants
public const string InstructionsMarkup = "[grey](Press <space> to select, <enter> to accept)[/]";
public const string MoreChoicesMarkup = "[grey](Move up and down to reveal more choices)[/]";
public const string SearchPlaceholderMarkup = "[grey](Type to search)[/]";

public static string GetSelectedCheckbox(bool isGroup, SelectionMode mode, Style? style = null)
{
if (style != null)
{
return "[[" + $"[{style.ToMarkup()}]X[/]" + "]]";
}

return isGroup && mode == SelectionMode.Leaf
? GroupSelectedCheckbox : SelectedCheckbox;
}
}
3 changes: 1 addition & 2 deletions src/Spectre.Console/Prompts/MultiSelectionPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ IRenderable IListPromptStrategy<T>.Render(IAnsiConsole console, bool scrollable,
}

var checkbox = item.Node.IsSelected
? (item.Node.IsGroup && Mode == SelectionMode.Leaf
? ListPromptConstants.GroupSelectedCheckbox : ListPromptConstants.SelectedCheckbox)
? ListPromptConstants.GetSelectedCheckbox(item.Node.IsGroup, Mode, HighlightStyle)
: ListPromptConstants.Checkbox;

grid.AddRow(new Markup(indent + prompt + " " + checkbox + " " + text, style));
Expand Down
2 changes: 1 addition & 1 deletion src/Spectre.Console/Widgets/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected override IRenderable Build()
while (currentDay <= daysInMonth)
{
if (weekdays[currentDay - 1] == weekday)
{
{
var todayEvent = _calendarEvents.LastOrDefault(e => e.Month == Month && e.Day == currentDay);
if (todayEvent != null)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Spectre.Console/Widgets/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@ public sealed class CalendarEvent
/// <summary>
/// Gets the custom highlight style of the calendar event.
/// </summary>
public Style? CustomHighlightStyle { get; }
public Style? CustomHighlightStyle { get; }

/// <summary>
/// Initializes a new instance of the <see cref="CalendarEvent"/> class.
/// </summary>
/// <param name="year">The year of the calendar event.</param>
/// <param name="month">The month of the calendar event.</param>
/// <param name="day">The day of the calendar event.</param>
/// <param name="day">The day of the calendar event.</param>
/// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param>
public CalendarEvent(int year, int month, int day, Style? customHighlightStyle = null)
: this(string.Empty, year, month, day, customHighlightStyle)
{
}
}

/// <summary>
/// Initializes a new instance of the <see cref="CalendarEvent"/> class.
/// </summary>
/// <param name="description">The calendar event description.</param>
/// <param name="year">The year of the calendar event.</param>
/// <param name="month">The month of the calendar event.</param>
/// <param name="day">The day of the calendar event.</param>
/// <param name="day">The day of the calendar event.</param>
/// <param name="customHighlightStyle">The custom highlight style of the calendar event.</param>
public CalendarEvent(string description, int year, int month, int day, Style? customHighlightStyle = null)
{
Description = description ?? string.Empty;
Year = year;
Month = month;
Day = day;
Day = day;
CustomHighlightStyle = customHighlightStyle;
}
}