-
-
Notifications
You must be signed in to change notification settings - Fork 26
feat(components): add Datebox component #250
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
152d7d8
feat(component): added date picker
sikelio 93f8c9d
fix: applied date input requested changes
sikelio 164e38c
fix: renamed dateinput to datenbox
sikelio 61a2d42
chore(*): minor improvements
desmondinho 20abe86
chore(*): coderabbit suggestions
desmondinho 2b34751
chore(*): make datebox always look 'filled' instead of 'focused'
desmondinho 3e600c7
fix(*): ensure values are set during `onchange` event
desmondinho db30b9b
docs(*): minor adjustments
desmondinho f6cf80a
test(*): update tests
desmondinho 0a318d3
docs(*): nits
desmondinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
166 changes: 166 additions & 0 deletions
166
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Datebox.razor
This file contains hidden or 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,166 @@ | ||
| @page "/docs/components/datebox" | ||
| @layout DocsContentLayout | ||
|
|
||
| @using LumexUI.Docs.Client.Pages.Components.Datebox.PreviewCodes | ||
|
|
||
| <DocsSection Title="Types"> | ||
| <p> | ||
| The datebox component is almost identical to the | ||
| <LumexLink Href="/docs/components/textbox">textbox</LumexLink> | ||
| but includes additional features specific to date input. | ||
| </p> | ||
| <p> | ||
| It supports various date types, including | ||
| <code>DateTime</code>, <code>DateTimeOffset</code>, <code>DateOnly</code>, | ||
| <code>TimeOnly</code>. Additionally, their nullable counterparts are also supported. | ||
| </p> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Usage"> | ||
| <Usage /> | ||
|
|
||
| <DocsSection Title="Disabled"> | ||
| <Disabled /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Read-Only"> | ||
| <ReadOnly /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Required"> | ||
| <Required /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Sizes"> | ||
| <Sizes /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Radius"> | ||
| <Radius /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Colors"> | ||
| <Colors /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Variants"> | ||
| <Variants /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Label Placements"> | ||
| <LabelPlacements /> | ||
| </DocsSection> | ||
|
|
||
| <LumexAlert Radius="@LumexUI.Common.Radius.Large" Class="my-6 [&_code]:text-current"> | ||
| <DescriptionContent> | ||
| If the <code>Label</code> parameter is not set, the <code>LabelPlacement</code> | ||
| parameter will default to <code>Outside</code>. | ||
| </DescriptionContent> | ||
| </LumexAlert> | ||
|
|
||
| <DocsSection Title="Clear Button"> | ||
| <ClearButton /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Start & End Content"> | ||
| <StartEndContent /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Description"> | ||
| <Description /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Error Message"> | ||
| <p> | ||
| Display an error message below the datebox to indicate validation issues. | ||
| You can combine the <code>Invalid</code> and <code>ErrorMessage</code> parameters to show an invalid input. | ||
| An error message is shown only when the <code>Invalid</code> parameter is set to <code>true</code>. | ||
| </p> | ||
|
|
||
| <ErrorMessage /> | ||
| </DocsSection> | ||
|
|
||
| <DocsSection Title="Two-way Data Binding"> | ||
| <p> | ||
| Use <code>@@bind-Value</code> directive or <code>Value</code> and <code>ValueChanged</code> | ||
| parameters to manually control datebox value. | ||
| </p> | ||
| <TwoWayDataBinding /> | ||
| </DocsSection> | ||
| </DocsSection> | ||
|
|
||
| <DocsSlotsSection Slots="@_slots"> | ||
| <div> | ||
| <h4 class="font-semibold">Datebox</h4> | ||
|
|
||
| <ul> | ||
| <li> | ||
| <code>Class</code>: The CSS class names to style the datebox wrapper. | ||
| </li> | ||
|
|
||
| <li> | ||
| <code>Classes</code>: The CSS class names to style the datebox slots. | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| <CustomStyles /> | ||
| </DocsSlotsSection> | ||
|
|
||
| <DocsApiSection Components="@_apiComponents" /> | ||
|
|
||
| @code { | ||
| [CascadingParameter] | ||
| private DocsContentLayout Layout { get; set; } = default!; | ||
|
|
||
| private readonly Heading[] _headings = new Heading[] | ||
| { | ||
| new("Types"), | ||
| new("Usage", [ | ||
| new("Disabled"), | ||
| new("Read-Only"), | ||
| new("Required"), | ||
| new("Sizes"), | ||
| new("Radius"), | ||
| new("Colors"), | ||
| new("Variants"), | ||
| new("Label Placements"), | ||
| new("Clear Button"), | ||
| new("Start & End Content"), | ||
| new("Description"), | ||
| new("Error message"), | ||
| new("Two-way Data Binding"), | ||
| ]), | ||
| new("Custom Styles"), | ||
| new("API") | ||
| }; | ||
|
|
||
| private readonly Slot[] _slots = new Slot[] | ||
| { | ||
| new(nameof(InputFieldSlots.Base), "The overall wrapper."), | ||
| new(nameof(InputFieldSlots.Label), "The label element."), | ||
| new(nameof(InputFieldSlots.MainWrapper), "The wrapper of the input wrapper (when the label is outside)."), | ||
| new(nameof(InputFieldSlots.InputWrapper), "The wrapper of the label and the inner wrapper (when the label is inside)."), | ||
| new(nameof(InputFieldSlots.InnerWrapper), "The wrapper of the input, start/end content."), | ||
| new(nameof(InputFieldSlots.Input), "The input element."), | ||
| new(nameof(InputFieldSlots.ClearButton), "The clear button element."), | ||
| new(nameof(InputFieldSlots.HelperWrapper), "The wrapper of a description and an error message."), | ||
| new(nameof(InputFieldSlots.Description), "The description of the input field."), | ||
| new(nameof(InputFieldSlots.ErrorMessage), "The error message of the input field.") | ||
| }; | ||
|
|
||
| private readonly string[] _apiComponents = new string[] | ||
| { | ||
| nameof(LumexDatebox<T>) | ||
| }; | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| Layout.Initialize( | ||
| title: "Datebox", | ||
| category: "Components", | ||
| description: "Datebox allows users to enter and edit date values.", | ||
| headings: _headings, | ||
| linksProps: new ComponentLinksProps("Datebox", isServer: false) | ||
| ); | ||
| } | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/ClearButton.razor
This file contains hidden or 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,5 @@ | ||
| <LumexDatebox Clearable="@true" | ||
| Label="Birth date" | ||
| Variant="@InputVariant.Outlined" | ||
| Value="@DateTime.Today" | ||
| Class="max-w-xs" /> |
27 changes: 27 additions & 0 deletions
27
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/Colors.razor
This file contains hidden or 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,27 @@ | ||
| <div class="w-full grid grid-cols-1 gap-4 md:grid-cols-2"> | ||
| @foreach (ThemeColor color in _colors) | ||
| { | ||
| <div> | ||
| <LumexDatebox TValue="DateTime?" | ||
| Color="@color" | ||
| Label="Birth date" | ||
| Class="max-w-xs" /> | ||
|
|
||
| <small class="text-default-400 mt-1"> | ||
| @color | ||
| </small> | ||
| </div> | ||
| } | ||
| </div> | ||
|
|
||
| @code { | ||
| private ThemeColor[] _colors = [ | ||
| ThemeColor.Default, | ||
| ThemeColor.Primary, | ||
| ThemeColor.Secondary, | ||
| ThemeColor.Success, | ||
| ThemeColor.Warning, | ||
| ThemeColor.Danger, | ||
| ThemeColor.Info | ||
| ]; | ||
| } |
30 changes: 30 additions & 0 deletions
30
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/CustomStyles.razor
This file contains hidden or 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,30 @@ | ||
| <LumexDatebox TValue="DateTime?" | ||
| Label="Birth date" | ||
| Radius="@Radius.Large" | ||
| Clearable="@true" | ||
| Classes="@_classes"> | ||
| <StartContent> | ||
| <CalendarClockIcon Size="18" class="text-secondary-400 shrink-0" /> | ||
| </StartContent> | ||
| </LumexDatebox> | ||
|
|
||
| @code { | ||
| private InputFieldSlots _classes = new() | ||
| { | ||
| Label = "text-default-700", | ||
| InnerWrapper = "bg-transparent", | ||
| InputWrapper = ElementClass.Empty() | ||
| .Add("shadow-xl") | ||
| .Add("bg-default-200/50") | ||
| .Add("backdrop-blur-xl") | ||
| .Add("backdrop-saturate-200") | ||
| .Add("hover:bg-default-200/70") | ||
| .Add("group-data-[focus=true]:bg-default-200/85") | ||
| .ToString(), | ||
| Input = ElementClass.Empty() | ||
| .Add("bg-transparent") | ||
| .Add("text-default-900") | ||
| .Add("placeholder:text-default-500") | ||
| .ToString() | ||
| }; | ||
| } |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/Description.razor
This file contains hidden or 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,4 @@ | ||
| <LumexDatebox TValue="DateTime?" | ||
| Label="Birth date" | ||
| Description="We'll never share your birthday with anyone else." | ||
| Class="max-w-xs" /> |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/Disabled.razor
This file contains hidden or 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,4 @@ | ||
| <LumexDatebox TValue="DateTime?" | ||
| Disabled="true" | ||
| Label="Birth date" | ||
| Class="max-w-xs" /> |
64 changes: 64 additions & 0 deletions
64
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/ErrorMessage.razor
This file contains hidden or 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,64 @@ | ||
| @using FluentValidation | ||
| @using FluentValidation.Results | ||
|
|
||
| <LumexDatebox TValue="DateTime?" | ||
| Variant="@InputVariant.Underlined" | ||
| Label="Birth date" | ||
| Required="@true" | ||
| ErrorMessage="@_userValidator.DateErrorMessage" | ||
desmondinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Invalid="@(!string.IsNullOrEmpty(_userValidator.DateErrorMessage))" | ||
| Color="@(!string.IsNullOrEmpty(_userValidator.DateErrorMessage) ? ThemeColor.Danger : ThemeColor.Success)" | ||
| Value="@_user.Date" | ||
| ValueChanged="@OnDateChange" | ||
| Class="max-w-xs" /> | ||
|
|
||
| @code { | ||
| private User _user = new(); | ||
| private UserValidator _userValidator = new(); | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| _user.Date = DateTime.Today; | ||
| Validate(); | ||
| } | ||
|
|
||
| private void OnDateChange(DateTime? value) | ||
| { | ||
| _user.Date = value; | ||
| Validate(); | ||
| } | ||
|
|
||
| private void Validate() | ||
| { | ||
| ValidationResult result = _userValidator.Validate(_user); | ||
|
|
||
| if (!result.IsValid) | ||
| { | ||
| _userValidator.DateErrorMessage = result.Errors | ||
| .Where(failure => failure.PropertyName == nameof(User.Date)) | ||
| .Select(failure => failure.ErrorMessage) | ||
| .FirstOrDefault(); | ||
| } | ||
| else | ||
| { | ||
| _userValidator.DateErrorMessage = null; | ||
| } | ||
| } | ||
|
|
||
| public class User | ||
| { | ||
| public DateTime? Date { get; set; } | ||
| } | ||
|
|
||
| public class UserValidator : AbstractValidator<User> | ||
| { | ||
| public string? DateErrorMessage { get; set; } | ||
|
|
||
| public UserValidator() | ||
| { | ||
| RuleFor(user => user.Date) | ||
| .NotEmpty() | ||
| .WithMessage("Birth date is required"); | ||
| } | ||
| } | ||
desmondinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
22 changes: 22 additions & 0 deletions
22
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/LabelPlacements.razor
This file contains hidden or 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,22 @@ | ||
| <div class="w-full grid grid-cols-1 gap-4"> | ||
| @foreach (LabelPlacement placement in _labelPlacements) | ||
| { | ||
| <div> | ||
| <LumexDatebox TValue="DateTime?" | ||
| LabelPlacement="@placement" | ||
| Label="Birth date" | ||
| Class="max-w-xs" /> | ||
|
|
||
| <small class="text-default-400 mt-1"> | ||
| @placement | ||
| </small> | ||
| </div> | ||
| } | ||
| </div> | ||
|
|
||
| @code { | ||
| private LabelPlacement[] _labelPlacements = [ | ||
| LabelPlacement.Inside, | ||
| LabelPlacement.Outside | ||
| ]; | ||
| } |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/ReadOnly.razor
This file contains hidden or 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,4 @@ | ||
| <LumexDatebox TValue="DateTime?" | ||
| ReadOnly="@true" | ||
| Label="Bbirth date" | ||
| Class="max-w-xs" /> |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/Required.razor
This file contains hidden or 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,4 @@ | ||
| <LumexDatebox TValue="DateTime?" | ||
| Required="@true" | ||
| Label="Birth date" | ||
| Class="max-w-xs" /> |
21 changes: 21 additions & 0 deletions
21
docs/LumexUI.Docs.Client/Pages/Components/Datebox/Examples/Sizes.razor
This file contains hidden or 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,21 @@ | ||
| <div class="w-full grid grid-cols-1 gap-4"> | ||
| @foreach (Size size in _sizes) | ||
| { | ||
| <div> | ||
| <LumexDatebox TValue="DateTime?" | ||
| Size="@size" | ||
| Label="Birth date" | ||
| Class="max-w-xs" /> | ||
|
|
||
| <small class="text-default-400 mt-1">@size</small> | ||
| </div> | ||
| } | ||
| </div> | ||
|
|
||
| @code { | ||
| private Size[] _sizes = [ | ||
| Size.Small, | ||
| Size.Medium, | ||
| Size.Large | ||
| ]; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.