Skip to content

DatePicker: Adds "Today" button #6089

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
The <Code>DatePicker</Code> component now includes a <Code>ShowWeekNumbers</Code> parameter. When enabled, the calendar displays ISO week numbers alongside each row. This can be helpful for planning or referencing by week.
</Paragraph>

<Heading Size="HeadingSize.Is3">
Show "Today" Button on DatePicker
</Heading>

<Paragraph>
The <Code>DatePicker</Code> component now includes a <Code>ShowTodayButton</Code> parameter. When enabled, a "Today" button appears at the bottom of the calendar, allowing users to quickly jump to the current date.
</Paragraph>

<Heading Size="HeadingSize.Is3">
Optimized Chart Plugins
</Heading>
Expand Down
33 changes: 33 additions & 0 deletions Source/Blazorise.Bootstrap5/Styles/_vendors/_flatpickr.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,36 @@ span.flatpickr-weekday {
.flatpickr-monthSelect-month.selected {
background-color: $primary;
}

.flatpickr-today-button {
display: inline-block;
font-weight: 400;
color: #fff;
text-align: center;
vertical-align: middle;
user-select: none;
background-color: $primary;
border: 1px solid $primary;
padding: 0.375rem 0.75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: 0.375rem;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
cursor: pointer;

&:hover {
background-color: darken($primary, 10%);
border-color: darken($primary, 12%);
}

&:focus {
outline: 0;
box-shadow: 0 0 0 0.25rem rgba($primary, 0.5);
}

&:disabled {
opacity: 0.65;
cursor: not-allowed;
}
}
57 changes: 46 additions & 11 deletions Source/Blazorise.Bootstrap5/wwwroot/blazorise.bootstrap5.css
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On flatpickr repo, there is src\style\flatpickr.styl. Maybe we should define the default button and its container styles in there?

Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ hr.divider.divider-text::before {
.b-is-autocomplete.b-is-autocomplete-multipleselection.focus {
color: var(--bs-body-color);
background-color: var(--bs-body-bg);
border-color: #86b7fe;
border-color: rgb(134, 182.5, 254);
outline: 0;
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
Expand Down Expand Up @@ -1627,7 +1627,7 @@ li.list-group-item-action {
}

.form-check.form-switch .form-check-input.form-check-input-xs {
width: calc(0.75rem + (0.5rem / 2));
width: calc(0.75rem + 0.5rem / 2);
height: 0.5rem;
margin-left: -2.5em;
}
Expand All @@ -1637,11 +1637,11 @@ li.list-group-item-action {
padding-left: 0;
}
.form-check.form-switch .form-check-input.form-check-input-xs:checked ~ .form-check-label::after {
transform: translateX(calc(0.75rem - (0.5rem / 2)));
transform: translateX(calc(0.75rem - 0.5rem / 2));
}

.form-check.form-switch .form-check-input.form-check-input-sm {
width: calc(1rem + (0.75rem / 2));
width: calc(1rem + 0.75rem / 2);
height: 0.75rem;
margin-left: -2.5em;
}
Expand All @@ -1651,11 +1651,11 @@ li.list-group-item-action {
padding-left: 0.75rem;
}
.form-check.form-switch .form-check-input.form-check-input-sm:checked ~ .form-check-label::after {
transform: translateX(calc(1rem - (0.75rem / 2)));
transform: translateX(calc(1rem - 0.75rem / 2));
}

.form-check.form-switch .form-check-input.form-check-input-md {
width: calc(2rem + (1.5rem / 2));
width: calc(2rem + 1.5rem / 2);
height: 1.5rem;
margin-left: -2.5em;
}
Expand All @@ -1665,11 +1665,11 @@ li.list-group-item-action {
padding-left: 0.75rem;
}
.form-check.form-switch .form-check-input.form-check-input-md:checked ~ .form-check-label::after {
transform: translateX(calc(2rem - (1.5rem / 2)));
transform: translateX(calc(2rem - 1.5rem / 2));
}

.form-check.form-switch .form-check-input.form-check-input-lg {
width: calc(3rem + (2rem / 2));
width: calc(3rem + 2rem / 2);
height: 2rem;
margin-left: -2.5em;
}
Expand All @@ -1679,11 +1679,11 @@ li.list-group-item-action {
padding-left: 0.75rem;
}
.form-check.form-switch .form-check-input.form-check-input-lg:checked ~ .form-check-label::after {
transform: translateX(calc(3rem - (2rem / 2)));
transform: translateX(calc(3rem - 2rem / 2));
}

.form-check.form-switch .form-check-input.form-check-input-xl {
width: calc(4rem + (2.5rem / 2));
width: calc(4rem + 2.5rem / 2);
height: 2.5rem;
margin-left: -2.5em;
}
Expand All @@ -1693,7 +1693,7 @@ li.list-group-item-action {
padding-left: 0.75rem;
}
.form-check.form-switch .form-check-input.form-check-input-xl:checked ~ .form-check-label::after {
transform: translateX(calc(4rem - (2.5rem / 2)));
transform: translateX(calc(4rem - 2.5rem / 2));
}

table.table tbody tr:not(.table-group).selected {
Expand Down Expand Up @@ -4565,3 +4565,38 @@ span.flatpickr-weekday {
.flatpickr-monthSelect-month.selected {
background-color: #0d6efd;
}

.flatpickr-extra-buttons-container {
display: flex;
justify-content: end;
padding: 10px;
}

.flatpickr-today-button {
display: inline-block;
font-weight: 400;
color: #fff;
text-align: center;
vertical-align: middle;
user-select: none;
background-color: #0d6efd;
border: 1px solid #0d6efd;
padding: 0.375rem 0.75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: 0.375rem;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
cursor: pointer;
}
.flatpickr-today-button:hover {
background-color: rgb(1.762295082, 87.2336065574, 213.237704918);
border-color: rgb(1.6786885246, 83.0950819672, 203.1213114754);
}
.flatpickr-today-button:focus {
outline: 0;
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.5);
}
.flatpickr-today-button:disabled {
opacity: 0.65;
cursor: not-allowed;
}

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion Source/Blazorise/Components/DatePicker/DatePicker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
var disabledChanged = parameters.TryGetValue( nameof( Disabled ), out bool paramDisabled ) && Disabled != paramDisabled;
var readOnlyChanged = parameters.TryGetValue( nameof( ReadOnly ), out bool paramReadOnly ) && ReadOnly != paramReadOnly;
var disabledDatesChanged = parameters.TryGetValue( nameof( DisabledDates ), out IEnumerable<TValue> paramDisabledDates ) && !DisabledDates.AreEqual( paramDisabledDates );
var enabledDatesChanged = parameters.TryGetValue( nameof( EnabledDates ), out IEnumerable<TValue>? paramEnabledDates ) && !EnabledDates.AreEqual( paramEnabledDates );

Check warning on line 53 in Source/Blazorise/Components/DatePicker/DatePicker.razor.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
var disabledDaysChanged = parameters.TryGetValue( nameof( DisabledDays ), out IEnumerable<DayOfWeek> paramDisabledDays ) && !DisabledDays.AreEqual( paramDisabledDays );
var selectionModeChanged = parameters.TryGetValue( nameof( SelectionMode ), out DateInputSelectionMode paramSelectionMode ) && !SelectionMode.IsEqual( paramSelectionMode );
var inlineChanged = parameters.TryGetValue( nameof( Inline ), out bool paramInline ) && Inline != paramInline;
Expand All @@ -58,6 +58,7 @@
var placeholderChanged = parameters.TryGetValue( nameof( Placeholder ), out string paramPlaceholder ) && Placeholder != paramPlaceholder;
var staticPickerChanged = parameters.TryGetValue( nameof( StaticPicker ), out bool paramStaticPicker ) && StaticPicker != paramStaticPicker;
var showWeekNumbersChanged = parameters.TryGetValue( nameof( ShowWeekNumbers ), out bool paramShowWeekNumbers ) && ShowWeekNumbers != paramShowWeekNumbers;
var showTodayButtonChanged = parameters.TryGetValue( nameof( ShowTodayButton ), out bool paramShowTodayButton ) && ShowTodayButton != paramShowTodayButton;

if ( dateChanged || datesChanged )
{
Expand Down Expand Up @@ -89,7 +90,8 @@
|| disableMobileChanged
|| placeholderChanged
|| staticPickerChanged
|| showWeekNumbersChanged )
|| showWeekNumbersChanged
|| showTodayButtonChanged )
{
ExecuteAfterRender( async () => await JSModule.UpdateOptions( ElementRef, ElementId, new DatePickerUpdateJSOptions()
{
Expand All @@ -110,6 +112,7 @@
Placeholder = new JSOptionChange<string>( placeholderChanged, paramPlaceholder ),
StaticPicker = new JSOptionChange<bool>( staticPickerChanged, paramStaticPicker ),
ShowWeekNumbers = new JSOptionChange<bool>( showWeekNumbersChanged, paramShowWeekNumbers ),
ShowTodayButton = new JSOptionChange<bool>( showTodayButtonChanged, paramShowTodayButton ),
} ) );
}
}
Expand Down Expand Up @@ -190,6 +193,7 @@
Placeholder = Placeholder,
StaticPicker = StaticPicker,
ShowWeekNumbers = ShowWeekNumbers,
ShowTodayButton = ShowTodayButton,
ValidationStatus = new
{
SuccessClass = ClassProvider.DatePickerValidation( ValidationStatus.Success ),
Expand Down Expand Up @@ -480,6 +484,7 @@
},
amPM = new[] { Localizer["AM"], Localizer["PM"] },
RangeSeparator = CurrentRangeSeparator,
Today = Localizer["Today"],
};
}

Expand Down Expand Up @@ -669,6 +674,11 @@
/// Determines whether the calendar menu will show week numbers.
/// </summary>
[Parameter] public bool ShowWeekNumbers { get; set; }

/// <summary>
/// Determines whether to show the today button in the calendar menu.
/// </summary>
[Parameter] public bool ShowTodayButton { get; set; }

#endregion
}
10 changes: 10 additions & 0 deletions Source/Blazorise/Modules/JSOptions/DatePickerJSOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public class DatePickerJSOptions
/// Determines whether the calendar menu will show week numbers.
/// </summary>
public bool ShowWeekNumbers { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to show a "Today" button in the date picker calendar.
/// </summary>
public bool ShowTodayButton { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -202,4 +207,9 @@ public class DatePickerUpdateJSOptions
/// Gets or sets the option for updating the show week numbers setting.
/// </summary>
public JSOptionChange<bool> ShowWeekNumbers { get; set; }

/// <summary>
/// Gets or sets the option for showing or hiding the "Today" button.
/// </summary>
public JSOptionChange<bool> ShowTodayButton { get; set; }
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Prosinec",
"AM": "dopo",
"PM": "odpo",
"RangeSeparator": " do "
"RangeSeparator": " do ",
"Today": "Dnes"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "December",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " til "
"RangeSeparator": " til ",
"Today": "I dag"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Dezember",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " bis "
"RangeSeparator": " bis ",
"Today": "Heute"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "December",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " to "
"RangeSeparator": " to ",
"Today": "Today"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Diciembre",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " a "
"RangeSeparator": " a ",
"Today": "Hoy"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "décembre",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " au "
"RangeSeparator": " au ",
"Today": "Aujourd'hui"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Prosinac",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " do "
"RangeSeparator": " do ",
"Today": "Danas"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/is.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Desember",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " til "
"RangeSeparator": " til ",
"Today": "Í dag"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Dicembre",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " al "
"RangeSeparator": " al ",
"Today": "Oggi"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "december",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " t/m "
"RangeSeparator": " t/m ",
"Today": "Vandaag"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Grudzień",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " do "
"RangeSeparator": " do ",
"Today": "Dzisiaj"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Dezembro",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " até "
"RangeSeparator": " até ",
"Today": "Hoje"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "decembrie",
"AM": "AM",
"PM": "PM",
"RangeSeparator": " până la "
"RangeSeparator": " până la ",
"Today": "Astăzi"
}
}
3 changes: 2 additions & 1 deletion Source/Blazorise/Resources/Localization/DatePicker/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"December": "Декабрь",
"AM": "ДП",
"PM": "ПП",
"RangeSeparator": " — "
"RangeSeparator": " — ",
"Today": "Сегодня"
}
}
Loading
Loading