-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat(components): Add basic textarea component #129
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
trucidare
wants to merge
8
commits into
LumexUI:main
Choose a base branch
from
trucidare:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b86b31
feat(components): Add basic textarea component
trucidare 81d6baf
fix(components): Remove shadow from base textarea component
trucidare bdc240d
fix(codereview): Fix naming to TextArea + ReadOnly
trucidare f523dbf
fix(codereview): Use correct snippet in read only sample
trucidare 1f1a2e6
fix(codereview): Add event test + correct usage of samples
trucidare 0f95603
fix(codereview): Rename heading + section
trucidare 16c0302
Merge branch 'LumexUI:main' into main
trucidare 0993141
fix(codereview): Remove Folder include for text area component
trucidare 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
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
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
19 changes: 19 additions & 0 deletions
19
docs/LumexUI.Docs.Client/Pages/Components/Textarea/Examples/Controlled.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,19 @@ | ||
<div class="w-full flex flex-col flex-wrap gap-4 md:flex-nowrap"> | ||
<LumexTextarea Placeholder="Enter your email" ValueChanged="@OnValueChanged" /> | ||
<div class="flex flex-col items-center text-sm"> | ||
<span>Changed Value:</span> | ||
<span>@_newValue</span> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
|
||
private string _value = string.Empty; | ||
private string _newValue = string.Empty; | ||
|
||
private void OnValueChanged( string value ) | ||
{ | ||
_newValue = value; | ||
StateHasChanged(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Textarea/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 @@ | ||
<div class="w-full flex flex-wrap gap-4 md:flex-nowrap"> | ||
<LumexTextarea Disabled /> | ||
<LumexTextarea Disabled Placeholder="Enter your email" /> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
docs/LumexUI.Docs.Client/Pages/Components/Textarea/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,3 @@ | ||
<div class="w-full flex flex-wrap gap-4 md:flex-nowrap"> | ||
<LumexTextarea Readonly Value="Lorem ipsum..." /> | ||
</div> |
4 changes: 4 additions & 0 deletions
4
docs/LumexUI.Docs.Client/Pages/Components/Textarea/Examples/Usage.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 @@ | ||
<div class="w-full flex flex-wrap gap-4 md:flex-nowrap"> | ||
<LumexTextarea Value="LumexUI Textarea sample text..." /> | ||
<LumexTextarea Placeholder="Enter your email" /> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
docs/LumexUI.Docs.Client/Pages/Components/Textarea/PreviewCodes/Controlled.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 @@ | ||
@rendermode InteractiveWebAssembly | ||
|
||
<PreviewCode Code="@new(name: null, snippet: "Textarea.Code.Usage")"> | ||
<LumexUI.Docs.Client.Pages.Components.Textarea.Examples.Controlled /> | ||
</PreviewCode> |
5 changes: 5 additions & 0 deletions
5
docs/LumexUI.Docs.Client/Pages/Components/Textarea/PreviewCodes/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,5 @@ | ||
@rendermode InteractiveWebAssembly | ||
|
||
<PreviewCode Code="@new(name: null, snippet: "Textarea.Code.Usage")"> | ||
<LumexUI.Docs.Client.Pages.Components.Textarea.Examples.Disabled /> | ||
</PreviewCode> |
5 changes: 5 additions & 0 deletions
5
docs/LumexUI.Docs.Client/Pages/Components/Textarea/PreviewCodes/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,5 @@ | ||
@rendermode InteractiveWebAssembly | ||
|
||
<PreviewCode Code="@new(name: null, snippet: "Textarea.Code.Usage")"> | ||
<LumexUI.Docs.Client.Pages.Components.Textarea.Examples.Readonly /> | ||
</PreviewCode> |
5 changes: 5 additions & 0 deletions
5
docs/LumexUI.Docs.Client/Pages/Components/Textarea/PreviewCodes/Usage.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 @@ | ||
@rendermode InteractiveWebAssembly | ||
|
||
<PreviewCode Code="@new(name: null, snippet: "Textarea.Code.Usage")"> | ||
<LumexUI.Docs.Client.Pages.Components.Textarea.Examples.Usage /> | ||
</PreviewCode> |
63 changes: 63 additions & 0 deletions
63
docs/LumexUI.Docs.Client/Pages/Components/Textarea/Textarea.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,63 @@ | ||
@page "/docs/components/textarea" | ||
@layout DocsContentLayout | ||
|
||
@using LumexUI.Docs.Client.Pages.Components.Textarea.PreviewCodes | ||
|
||
<DocsSection Title="Usage"> | ||
<p>The textarea component provides a simple way to input and edit multiline text data.</p> | ||
<Usage /> | ||
|
||
<DocsSection Title="Disabled"> | ||
<p> | ||
You can disable a textarea to prevent user interaction. | ||
A disabled textarea is faded and does not respond to user clicks. | ||
</p> | ||
|
||
<Disabled /> | ||
</DocsSection> | ||
|
||
<DocsSection Title="Readonly"> | ||
<p> | ||
You can make a textareas value read only to prevent Changes. | ||
</p> | ||
|
||
<Readonly /> | ||
</DocsSection> | ||
|
||
<DocsSection Title="Controlled"> | ||
<p> | ||
It is possible to get an event after changing the value. If you set the Intermediate | ||
flag, the event will be called on every input. Otherwise the event will be called after | ||
leaving the textarea. | ||
</p> | ||
|
||
<Controlled /> | ||
</DocsSection> | ||
</DocsSection> | ||
|
||
@code { | ||
[CascadingParameter] private DocsContentLayout Layout { get; set; } = default!; | ||
|
||
private readonly Heading[] _headings = | ||
[ | ||
new("Usage", [ | ||
new("Disabled"), | ||
new("Readonly"), | ||
new("Controlled"), | ||
]), | ||
new("Custom Styles"), | ||
new("API") | ||
]; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Layout.Initialize( | ||
title: "Textarea", | ||
category: "Components", | ||
description: "Textarea allows users to input multiline text data.", | ||
headings: _headings, | ||
linksProps: new ComponentLinksProps( "Textarea", isServer: false ) | ||
); | ||
} | ||
|
||
} |
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,16 @@ | ||
@namespace LumexUI | ||
@inherits LumexComponentBase | ||
|
||
<textarea | ||
class="@RootClass" | ||
style="@RootStyle" | ||
disabled="@Disabled" | ||
readonly="@Readonly" | ||
placeholder="@Placeholder" | ||
required="@Required" | ||
data-disabled="@Disabled.ToAttributeValue()" | ||
@bind="Value" | ||
@bind:event="@(Behavior == InputBehavior.OnInput ? "oninput" : "onchange")" | ||
@bind:after="OnValueChanged" | ||
@attributes="@AdditionalAttributes" > | ||
</textarea> |
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,71 @@ | ||
using LumexUI.Common; | ||
using LumexUI.Styles; | ||
|
||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace LumexUI; | ||
|
||
public partial class LumexTextarea : LumexComponentBase | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether the textarea is disabled. | ||
/// </summary> | ||
[Parameter] public bool Disabled { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the textareas value is readonly. | ||
/// </summary> | ||
[Parameter] public bool Readonly { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the textareas value is required. | ||
/// </summary> | ||
[Parameter] public bool Required { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating wether the ValueChanged event will be fired on input or change. | ||
/// </summary> | ||
[Parameter] public InputBehavior Behavior { get; set; } = InputBehavior.OnChange; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the textarea has full width. | ||
/// </summary> | ||
[Parameter] public bool FullWidth { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the text value. | ||
/// </summary> | ||
[Parameter] public string? Value { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the placeholder to show if the value is empty. | ||
/// </summary> | ||
[Parameter] public string? Placeholder { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets Value changed event. | ||
/// </summary> | ||
[Parameter] public Action<string?>? ValueChanged { get; set; } | ||
|
||
/// <summary> | ||
/// Get the merged style of this instance. | ||
/// </summary> | ||
private protected override string? RootClass => | ||
TwMerge.Merge( Textarea.GetStyles( this ) ); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LumexTextarea"/>. | ||
/// </summary> | ||
public LumexTextarea() | ||
{ | ||
As = "textarea"; | ||
} | ||
|
||
/// <summary> | ||
/// Event wrapper function. | ||
/// </summary> | ||
private void OnValueChanged() | ||
{ | ||
ValueChanged?.Invoke( Value ); | ||
} | ||
} |
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,51 @@ | ||
// Copyright (c) LumexUI 2024 | ||
// LumexUI licenses this file to you under the MIT license | ||
// See the license here https://github.com/LumexUI/lumexui/blob/main/LICENSE | ||
|
||
using LumexUI.Utilities; | ||
|
||
namespace LumexUI.Styles; | ||
|
||
internal class Textarea | ||
{ | ||
private readonly static string _base = ElementClass.Empty() | ||
.Add( "flex" ) | ||
.Add( "min-h-[60px]" ) | ||
.Add( "rounded-medium" ) | ||
.Add( "border" ) | ||
.Add( "border-input" ) | ||
.Add( "bg-default-100" ) | ||
.Add( "px-3" ) | ||
.Add( "py-2" ) | ||
.Add( "text-sm" ) | ||
.Add( "shadow-sm" ) | ||
.Add( "text-default-600" ) | ||
.Add( "placeholder:text-muted-foreground" ) | ||
.ToString(); | ||
|
||
private readonly static string _focus = ElementClass.Empty() | ||
.Add( "focus-visible:outline-none" ) | ||
.Add( "focus-visible:ring-0" ) | ||
.ToString(); | ||
|
||
private readonly static string _disabled = ElementClass.Empty() | ||
.Add( "opacity-disabled" ) | ||
.Add( "opacity-50" ) | ||
.Add( "cursor-not-allowed" ) | ||
.Add( "pointer-events-none" ) | ||
.ToString(); | ||
|
||
private readonly static string _fullWidth = ElementClass.Empty() | ||
.Add( "w-full" ) | ||
.ToString(); | ||
|
||
public static string GetStyles( LumexTextarea textarea ) | ||
{ | ||
return ElementClass.Empty() | ||
.Add( _base ) | ||
.Add( _focus ) | ||
.Add( _disabled, when: textarea.Disabled ) | ||
.Add( _fullWidth, when: textarea.FullWidth ) | ||
.ToString(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
tests/LumexUI.Tests/Components/Textarea/TextareaTests.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,77 @@ | ||
@namespace LumexUI.Tests.Components | ||
@inherits TestContext | ||
@using LumexUI.Common | ||
@using TailwindMerge | ||
@using Microsoft.Extensions.DependencyInjection | ||
|
||
@code { | ||
public TextareaTests() | ||
{ | ||
Services.AddSingleton<TwMerge>(); | ||
var module = JSInterop.SetupModule( "./_content/LumexUI/js/components/input.js" ); | ||
module.Setup<string>( "input.getValidationMessage", _ => true ); | ||
} | ||
|
||
[Fact] | ||
public void ShouldRenderCorrectly() | ||
{ | ||
var action = () => Render(@<LumexTextarea Placeholder="Test" />); | ||
|
||
action.Should().NotThrow(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldRenderWithPlaceholder() | ||
{ | ||
var cut = Render(@<LumexTextarea Placeholder="Test" />); | ||
|
||
var input = cut.Find( "textarea" ); | ||
|
||
input.HasAttribute( "placeholder" ).Should().BeTrue(); | ||
input.GetAttribute( "placeholder" ).Should().Be( "Test" ); | ||
} | ||
|
||
[Fact] | ||
public void ShouldRenderWithPlaceholderButShowsValue() | ||
{ | ||
var cut = Render(@<LumexTextarea Placeholder="Test" Value="Hello World!" />); | ||
|
||
var input = cut.Find( "textarea" ); | ||
|
||
input.HasAttribute( "placeholder" ).Should().BeTrue(); | ||
input.GetAttribute( "placeholder" ).Should().Be( "Test" ); | ||
input.HasAttribute( "value" ).Should().BeTrue(); | ||
input.GetAttribute( "value" ).Should().Be( "Hello World!" ); | ||
} | ||
|
||
[Fact] | ||
public void ShouldRenderReadonly() | ||
{ | ||
var cut = Render(@<LumexTextarea Placeholder="Test" Value="Hello World!" Readonly />); | ||
|
||
var input = cut.Find( "textarea" ); | ||
|
||
input.HasAttribute( "readonly" ).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldRenderDisabled() | ||
{ | ||
var cut = Render(@<LumexTextarea Placeholder="Test" Value="Hello World!" Disabled />); | ||
|
||
var input = cut.Find( "textarea" ); | ||
|
||
input.HasAttribute( "disabled" ).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ShouldChangeValueOnInput() | ||
{ | ||
var cut = Render<LumexTextarea>( @<LumexTextarea Value="Test" Behavior="@InputBehavior.OnInput" />); | ||
|
||
var input = cut.Find( "textarea" ); | ||
|
||
input.Input( "test 2" ); | ||
cut.Instance.Value.Should().Be( "test 2" ); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per styles, follow the NextUI's one. They share a single
input.ts
for the input and textarea styles. We already have the same in theInputField.cs
, however the styles for a textarea component are not there yet.Actually, this task is not so easy at first glance.