feat(components): introduce Avatar and AvatarGroup components#201
feat(components): introduce Avatar and AvatarGroup components#201desmondinho merged 21 commits intodevfrom
Conversation
WalkthroughThis PR introduces numerous enhancements and new features for the Lumex UI documentation and component library. The NavigationStore is updated to include a new LumexAvatar entry and to adjust statuses for existing components. A comprehensive set of documentation pages, examples, and interactive preview codes have been added for the Avatar component. Additionally, new source components for avatars and avatar groups, along with supporting context, slot, and utility classes, have been implemented. Updates to styling, JavaScript utilities, and extensive tests further reinforce the robustness of these changes. Changes
Sequence Diagram(s)sequenceDiagram
participant G as LumexAvatarGroup
participant C as AvatarGroupContext
participant A as LumexAvatar
G->>C: StartCollecting()
loop For each avatar in group
A->>C: Register()
end
G->>C: StopCollecting()
alt Total avatars ≤ Max
G->>A: Render each avatar
else Total avatars > Max
G->>A: Render first Max avatars
G->>G: Display RemainingCount via CountContent
end
sequenceDiagram
participant A as LumexAvatar
participant JS as IJSRuntime
A->>JS: Call isImageLoaded(img)
alt Image successfully loaded
A->>A: Render image element
else Image not loaded
A->>A: Render fallback content (custom fallback, initials, or default icon)
end
Possibly related PRs
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (20)
src/LumexUI/Common/InitialsResolver.cs (1)
8-8: Minor formatting inconsistency in parameter declarationThere's an extra space after the opening parenthesis in the delegate declaration.
-public delegate string InitialsResolver( string name ); +public delegate string InitialsResolver(string name);docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Radii.razor (1)
1-14: Implementation looks good! Consider using local assets for examplesThe example correctly demonstrates the different radius options available for the LumexAvatar component in a clean, structured layout.
While the usage of pravatar.cc is common for examples, consider using local assets if you want to ensure consistent rendering regardless of external service availability.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Sizes.razor (1)
1-17: LGTM! Good example of avatar size variations.The example clearly demonstrates multiple size options for the LumexAvatar component including:
- Custom sizing with utility classes (w-6 h-6)
- Predefined sizes (Small, Medium, Large)
- Another custom size (w-18 h-18)
All avatars consistently use the Bordered property and the flex layout provides a clear visual comparison.
Consider adding alt text to the avatars for accessibility:
<LumexAvatar Class="w-6 h-6" Bordered="@true" + Alt="Avatar example" Src="https://i.pravatar.cc/150?img=2" />docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupGrid.razor (1)
1-11: Good demonstration of the LumexAvatarGroup grid layout.This example shows the LumexAvatarGroup with:
- Grid layout enabled (
Grid="@true")- Maximum display limit (
Max="7")- Border styling (
Bordered="@true")- Multiple avatar instances (9 total, with 2 being hidden due to the Max setting)
The example effectively demonstrates the component's capabilities.
Consider adding alt text to avatars for accessibility:
<LumexAvatar Src="https://i.pravatar.cc/150?img=2" + Alt="Team member avatar" />docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupMaxCount.razor (1)
1-8: Good demonstration of the max count feature in LumexAvatarGroup.This example clearly shows how to limit the visible avatars in a group using the
Maxproperty. With 6 avatars provided butMax="3", this should display 3 avatars plus a "+3" indicator.Consider adding alt text for improved accessibility:
<LumexAvatar Src="https://i.pravatar.cc/150?img=2" + Alt="Team member avatar" />src/LumexUI/wwwroot/js/utils/dom.js (1)
57-63: Useful utility function for checking image load status.The
isImageLoadedfunction properly checks two critical conditions for successful image loading:
- The image loading process is complete (
img.complete)- The image has valid dimensions (
img.naturalWidth !== 0)This approach correctly handles both network errors and invalid images.
Consider adding JSDoc comments to improve documentation:
+/** + * Checks if an image element has successfully loaded. + * @param {HTMLElement} img - The image element to check + * @returns {boolean} - True if the image is fully loaded with valid dimensions + */ export function isImageLoaded(img) { if (!(img instanceof HTMLElement)) { return false; } return img.complete && img.naturalWidth !== 0; }src/LumexUI/Components/Avatar/AvatarGroupContext.cs (1)
1-35: Well-designed context implementation for AvatarGroupThe context pattern implementation is clean and follows good practices for managing component state:
- Proper encapsulation with private field for tracking collection state
- Clear registration control with StartCollecting/StopCollecting methods
- Efficient implementation of IsWithinMaxLimit using IndexOf to determine visibility
One small improvement suggestion:
Consider using an immutable collection for Items to prevent external modification:
-public List<LumexAvatar> Items { get; } = []; +private readonly List<LumexAvatar> _items = []; +public IReadOnlyList<LumexAvatar> Items => _items;And updating the Register method:
public void Register( LumexAvatar avatar ) { if( !_collecting ) { return; } - Items.Add( avatar ); + _items.Add( avatar ); }Also update StartCollecting method:
public void StartCollecting() { - Items.Clear(); + _items.Clear(); _collecting = true; }src/LumexUI/Components/Avatar/AvatarGroupSlots.cs (1)
16-33: Well-structured slot definition with a minor inconsistencyThe
AvatarGroupSlotsclass follows the pattern used for component slots in LumexUI, with proper XML documentation and appropriate implementation of theISlotinterface.There is a minor inconsistency between the property definitions:
Root(obsolete) is defined with only a getter:public string? Root { get; }Base(the recommended replacement) has both getter and setter:public string? Base { get; set; }Consider making
Rootconsistent withBaseby adding a setter, or clarify why the obsolete property should be read-only.docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Usage.razor (1)
1-8: Add accessibility attributes to avatars with imagesWhile the usage example is clear and demonstrates both image-based and name-based avatars, consider adding accessibility attributes like
Altfor image-based avatars to improve screen reader support.-<LumexAvatar Src="https://i.pravatar.cc/150?img=2" /> +<LumexAvatar Src="https://i.pravatar.cc/150?img=2" Alt="Profile avatar" /> -<LumexAvatar Src="https://i.pravatar.cc/150?img=6" /> +<LumexAvatar Src="https://i.pravatar.cc/150?img=6" Alt="Profile avatar" /> -<LumexAvatar Src="https://i.pravatar.cc/150?img=9" /> +<LumexAvatar Src="https://i.pravatar.cc/150?img=9" Alt="Profile avatar" />src/LumexUI/Components/Avatar/AvatarSlots.cs (1)
18-22: Clarify implementation of obsolete Root propertyThe
Rootproperty is marked as obsolete but has a getter with no setter and returns null by default. Consider either providing a default value or adding a setter for consistency with other properties.[Obsolete( "Deprecated. This will be removed in the future releases. Use the 'Base' slot instead." )] -public string? Root { get; } +public string? Root { get; set; }src/LumexUI/Styles/Avatar.cs (2)
25-37: Confirm the choice of default text color.Including
"text-white"is effective for most background colors, but for lighter backgrounds or future brand theming, it may become illegible. Ensure there's a fallback or updated text color for light backgrounds if required.
85-99: Check size scaling for text.When the avatar is scaled (e.g., large vs. small), consider also scaling the text proportionally. Currently,
"text-tiny","text-small", etc., might be slightly off if the avatar needs a more fluid or responsive approach.tests/LumexUI.Tests/Components/Avatar/AvatarGroupTests.razor (1)
23-57: Impressive approach for testing image loading.Stubbing
JSRuntimeto return true in a sequence covers multiple images well. Consider adding a test scenario with at least one failing image load to confirm fallback rendering in groups.src/LumexUI/Components/Avatar/LumexAvatar.razor (3)
16-35: Optionally integrate lazy-loading for images.If performance is a concern for large image sets, you could consider using native
loading="lazy"attribute or a recommended library approach to minimize resource usage.
44-54: Assess fallback animations or transitions.When fallback content is displayed, you might want transitions or fade-ins. Current setup is straightforward, but adding a small fade might improve user experience.
56-64: Check placeholder length in Name fallback.If a user's name is longer or doesn't conform to a typical two-word pattern, the
Initials(Name)might produce undesired placeholders. Consider bounding logic for or customizing how many initials are extracted.docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupUsage.razor (1)
1-8: Example demonstrates the AvatarGroup component wellThe example shows clearly how to use the
LumexAvatarGroupcomponent with multiple avatar instances and the bordered property.However, consider adding alt text to the images for accessibility:
-<LumexAvatar Src="https://i.pravatar.cc/150?img=2" /> +<LumexAvatar Src="https://i.pravatar.cc/150?img=2" Alt="Avatar 2" />tests/LumexUI.Tests/Components/Avatar/AvatarTests.razor (1)
23-47: Image rendering test could be improvedThe test correctly verifies that an image is rendered when a source URL is provided. However, it would be more robust to also test the failure case.
Consider adding a test that verifies fallback behavior when image loading fails:
[Fact] public void ShouldRenderFallbackWhenImageFailsToLoad() { var jsRuntimeMock = new Mock<IJSRuntime>(); var jsObjectMock = new Mock<IJSObjectReference>(); jsRuntimeMock .Setup(js => js.InvokeAsync<IJSObjectReference>("import", It.IsAny<object[]>())) .ReturnsAsync(jsObjectMock.Object); jsObjectMock .SetupSequence(js => js.InvokeAsync<bool>("isImageLoaded", It.IsAny<object[]>())) .ReturnsAsync(false); Services.AddSingleton(jsRuntimeMock.Object); var cut = Render( @<LumexAvatar Src="https://invalid-url.com" Name="Fallback" /> ); var fallback = cut.FindBySlot("fallback"); var img = cut.FindBySlot("img"); img.GetAttribute("data-loaded").Should().Be("false"); fallback.Should().NotBeNull(); }docs/LumexUI.Docs.Client/Pages/Components/Avatar/Avatar.razor (1)
37-42: Consider adding code examples for fallback optionsWhile the explanation of fallbacks is good, it would be helpful to include inline code examples to demonstrate the syntax.
Consider adding code examples like:
<!-- With name for initials --> <LumexAvatar Name="John Doe" /> <!-- With default icon --> <LumexAvatar /> <!-- With ShowFallback set to false --> <LumexAvatar Src="invalid-url.jpg" ShowFallback="false" />src/LumexUI/Components/Avatar/LumexAvatar.razor.cs (1)
137-141: Avoid unintended override of user-provided Alt text.When
Nameis non-empty, the logic forcibly setsAlt = value, even if the user explicitly provided a differentAlt. Consider making this conditional to preserve custom alt text:if (parameters.TryGetValue<string>(nameof(Name), out var value) && !string.IsNullOrWhiteSpace(value)) { - Alt = value; + if (Alt == "avatar") + { + Alt = value; + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (45)
docs/LumexUI.Docs.Client/Common/Navigation/NavigationStore.cs(2 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Avatar.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Bordered.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Colors.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/CustomFallback.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/CustomStyles.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Fallbacks.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupCustomCount.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupGrid.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupMaxCount.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupUsage.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Radii.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Sizes.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Usage.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Bordered.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Colors.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/CustomFallback.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/CustomStyles.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Fallbacks.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupCustomCount.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupGrid.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupMaxCount.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupUsage.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Radii.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Sizes.razor(1 hunks)docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Usage.razor(1 hunks)docs/LumexUI.Docs/LumexUI.Docs.csproj(1 hunks)src/LumexUI/Common/Enums/Radius.cs(1 hunks)src/LumexUI/Common/InitialsResolver.cs(1 hunks)src/LumexUI/Components/Avatar/AvatarGroupContext.cs(1 hunks)src/LumexUI/Components/Avatar/AvatarGroupSlots.cs(1 hunks)src/LumexUI/Components/Avatar/AvatarSlots.cs(1 hunks)src/LumexUI/Components/Avatar/LumexAvatar.razor(1 hunks)src/LumexUI/Components/Avatar/LumexAvatar.razor.cs(1 hunks)src/LumexUI/Components/Avatar/LumexAvatarGroup.razor(1 hunks)src/LumexUI/Components/Avatar/LumexAvatarGroup.razor.cs(1 hunks)src/LumexUI/Styles/Avatar.cs(1 hunks)src/LumexUI/Styles/Utils.cs(1 hunks)src/LumexUI/Utilities/ElementClass.cs(1 hunks)src/LumexUI/wwwroot/js/utils/dom.js(1 hunks)tests/LumexUI.Tests/Components/Avatar/AvatarGroupTests.razor(1 hunks)tests/LumexUI.Tests/Components/Avatar/AvatarTests.razor(1 hunks)tests/LumexUI.Tests/Extensions/AngleSharpExtensions.cs(1 hunks)tests/LumexUI.Tests/LumexUI.Tests.csproj(2 hunks)tests/LumexUI.Tests/_Imports.razor(1 hunks)
🔇 Additional comments (53)
tests/LumexUI.Tests/_Imports.razor (1)
2-2: Appropriate addition of JSInterop importAdding the Microsoft.JSInterop namespace is appropriate for supporting the new Avatar component which likely uses JS interop for image loading functionality.
src/LumexUI/Common/InitialsResolver.cs (1)
1-8: Well-defined delegate with proper documentationThe InitialsResolver delegate is properly defined with clear XML documentation explaining its purpose, parameters, and return value.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Sizes.razor (1)
1-5: Properly structured preview code for Avatar sizesThe component is correctly set up to display size variations of the Avatar component using the InteractiveWebAssembly render mode.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Bordered.razor (1)
1-5: Properly structured preview code for bordered AvatarsThe component is correctly set up to display bordered variations of the Avatar component using the InteractiveWebAssembly render mode.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Radii.razor (1)
1-5: Implementation looks good!This preview code component correctly uses
InteractiveWebAssemblyrendermode and references the Radii example component. The structure follows the project's documentation pattern for component examples.docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Fallbacks.razor (1)
1-5: Implementation looks good!This preview code component correctly uses
InteractiveWebAssemblyrendermode and references the Fallbacks example component. The structure follows the project's documentation pattern for component examples.docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupGrid.razor (1)
1-5: Implementation looks good!This preview code component correctly uses
InteractiveWebAssemblyrendermode and references the GroupGrid example component. The structure follows the project's documentation pattern for component examples.docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/CustomStyles.razor (1)
1-5: Clean implementation for Avatar custom styles preview.The code correctly implements a preview component for demonstrating custom styles for the Avatar component. The
InteractiveWebAssemblyrender mode is appropriate for interactive components, and the structure follows documentation conventions.docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupMaxCount.razor (1)
1-5: Clean implementation for AvatarGroup max count preview.The preview component properly demonstrates the max count feature of the AvatarGroup component. The implementation follows the established pattern for documentation examples.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupCustomCount.razor (1)
1-5: Clean implementation for AvatarGroup custom count preview.The preview component correctly implements documentation for the custom count feature of the AvatarGroup component. The structure is consistent with other preview components.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/CustomFallback.razor (1)
1-5: Clean implementation for Avatar custom fallback preview.The preview component properly demonstrates how to use custom fallback content with the Avatar component. The implementation adheres to documentation standards for the project.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/GroupUsage.razor (1)
1-5: LGTM: Clean implementation of the avatar group preview codeThe component correctly uses
InteractiveWebAssemblyrender mode and properly references the Group usage example. This is a well-structured code preview component for documentation.docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Bordered.razor (1)
1-8: LGTM: Well-structured avatar example with border stylingThe example provides a good demonstration of bordered avatars with both image and name fallbacks. The layout using flex with appropriate spacing creates a clean presentation.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/CustomStyles.razor (1)
1-9: LGTM: Excellent demonstration of avatar styling customizationThis example effectively demonstrates the slot-based styling approach. The implementation shows how to customize both the base avatar background with a gradient and the icon color.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Colors.razor (1)
1-23: LGTM: Comprehensive color variants demonstrationThe example clearly demonstrates all theme color variants for the avatar component with consistent formatting and structure. The flex layout presents the variations in a user-friendly way.
tests/LumexUI.Tests/LumexUI.Tests.csproj (2)
20-20: Good addition of Moq for unit testing.Adding the Moq library as a package reference is appropriate for testing the new Avatar components. The version used (4.20.72) is a stable release.
33-33: Nice addition of the global using directive.Adding a global Using directive for Moq makes the test code cleaner by eliminating the need for repeated imports in individual test files.
src/LumexUI/Utilities/ElementClass.cs (1)
136-137: Good addition of the implicit string conversion operator.This implicit conversion operator enhances usability by allowing ElementClass instances to be seamlessly used in string contexts without explicit ToString() calls. The implementation follows good practices by delegating to the existing ToString() method.
src/LumexUI/Common/Enums/Radius.cs (1)
30-38: Good addition of the Full radius option.Adding the Full radius option is appropriate for Avatar components which typically support circular shapes. The documentation is clear, and I particularly appreciate the remark indicating that not all components support this radius option.
The trailing comma after Large is also good practice as it makes future enum additions cleaner in source control diffs.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Colors.razor (1)
1-5: Properly structured preview code for Avatar colors.The component is correctly set up with InteractiveWebAssembly rendermode and uses the PreviewCode component to demonstrate color options for the Avatar component. This follows the project's documentation pattern.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/CustomFallback.razor (1)
1-10: Well-structured example demonstrating fallback scenariosThis example effectively showcases three different fallback scenarios for the LumexAvatar component:
- Custom fallback with an animated camera icon
- Default fallback with name
- Disabled fallback with name
The flex layout provides a clean presentation of these variations side by side.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/PreviewCodes/Usage.razor (1)
1-5: Clean implementation of Avatar usage previewThe implementation follows the standard pattern for component documentation with InteractiveWebAssembly rendering mode and proper embedding of the example component.
tests/LumexUI.Tests/Extensions/AngleSharpExtensions.cs (1)
23-32: Good error handling improvement for FindBySlot methodThe updated method now properly handles exceptions when an element with the specified slot cannot be found, consistent with the FindByTestId method above. The return type change to IElement? correctly indicates that the method might return null.
docs/LumexUI.Docs/LumexUI.Docs.csproj (1)
31-31: Good practice to pin Tailwind CSS to a specific versionUpdating from
latestto a specific version (v4.0.9) for the Tailwind CSS CLI download URLs is a good change. Using fixed versions improves build reproducibility and prevents unexpected changes when new versions are released.Also applies to: 35-35
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/GroupCustomCount.razor (1)
1-13: Well-structured example for AvatarGroup with custom count displayThis example effectively demonstrates:
- Limiting the number of displayed avatars with
Max="3"- Custom styling for the overflow count with the
CountContenttemplate- Proper use of the
BorderedpropertyThe example shows good practices for implementing avatar groups with a limit, which is a common UI pattern.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Examples/Fallbacks.razor (1)
1-5: Good demonstration of Avatar fallback behaviorsThis example effectively shows three different fallback scenarios:
- Default fallback for a broken image
- Name-based fallback with initials
- Disabled fallback behavior with
ShowFallback="@false"These examples provide valuable guidance for handling image loading failures in production applications.
src/LumexUI/Components/Avatar/LumexAvatarGroup.razor (2)
1-30: Well-structured component with clear cascading patternThe cascading context pattern is implemented properly, with appropriate start/stop collection methods. The comment explaining why
IsFixedis not set to true is helpful for future maintainers.
32-52: Implement CountContent method for better code completenessThe
Rendermethod referencesCountContent(RemainingCount)but this method and theRemainingCountproperty are not defined in the provided code. These should be defined to ensure the component functions properly.Can you verify that the
CountContentmethod andRemainingCountproperty are defined in a partial class or base class? If not, they should be implemented here to complete the component's functionality.src/LumexUI/Styles/Utils.cs (3)
7-8: Great accessibility improvement with screen reader and motion supportThe refactored
VisuallyHiddenproperty using "sr-only" and the newReduceMotionproperty enhance accessibility for users with screen readers and those who prefer reduced motion.
10-12: Good implementation of disabled state stylingThe new
Disabledutility provides consistent styling for disabled elements with appropriate opacity and pointer-events settings.
14-27: Consistent focus styling implementationThe refactored focus styles maintain the same functionality while using a more consistent instantiation pattern.
src/LumexUI/Components/Avatar/AvatarSlots.cs (1)
11-47: Well-documented slots implementation with appropriate XML documentationThe slots implementation is well-structured with clear XML documentation for each property.
src/LumexUI/Styles/Avatar.cs (3)
14-15: Kudos on the new class introduction!Introducing static classes for styling is a neat approach to ensure clarity and organization within the codebase.
19-24:Details
✅ Verification successful
Validate default variant usage.
The call to create a variant with
twVariants.Create(new VariantConfig() {... })is straightforward, but consider verifying that references toAvatar.Style()indeed consume or override these defaults as expected throughout the rest of the codebase, especially if the styling is extended in other components.
🏁 Script executed:
#!/bin/bash # Description: Search for all Avatar.Style() usages in the codebase to confirm consistent usage and overrides. rg --context 3 "Avatar\.Style\("Length of output: 572
Confirmed: Default Avatar Variant Consumed as Expected
The default variant created in
src/LumexUI/Styles/Avatar.csis being used as intended. Our verification shows that the only consumption—found insrc/LumexUI/Components/Avatar/LumexAvatar.razor.cs—callsStyles.Avatar.Style(TwMerge)and then applies an override (e.g., via passing properties like[nameof(Size)] = Size.ToString()) when computing the component slots. This usage aligns with the expected styling behavior. Please ensure that any future extensions or components consuming this variant follow the same pattern.
185-194:Details
❓ Verification inconclusive
Ensure ring color classes for each variant are tested.
You've defined compound variants to adjust ring colors when the avatar is bordered. Make sure there's a test covering each color scenario, e.g.,
ThemeColor.PrimarywithBordered = true.
🏁 Script executed:
#!/bin/bash # Description: Identify usage of each ring color in tests to ensure coverage. rg --context 3 "ring-primary|ring-secondary|ring-success|ring-warning|ring-danger|ring-info"Length of output: 5118
Ensure Comprehensive Test Coverage for Avatar Ring Variants
The code correctly defines compound variants for applying different ring classes (e.g., ring-primary, ring-secondary, ring-success, ring-warning, ring-danger, and ring-info) when the avatar is bordered. However, based on the grep results, while these classes are referenced in the source and documentation examples, there isn’t clear evidence that dedicated automated tests cover each variant scenario. Please confirm that each variant is tested—especially verifying that setting properties (like
ThemeColor.PrimarywithBordered = true) results in the expected ring color class. If such tests are missing, consider adding them to ensure robust coverage.
- Verify that for every compound variant in
src/LumexUI/Styles/Avatar.cs, an automated test checks the proper application of the corresponding ring class.- Ensure test assertions cover scenarios such as:
ThemeColor.PrimarywithBordered = trueapplies "ring-primary"ThemeColor.SecondarywithBordered = trueapplies "ring-secondary"- …and similarly for the other variants.
tests/LumexUI.Tests/Components/Avatar/AvatarGroupTests.razor (3)
13-21: Well-structured test for rendering check.This test effectively ensures that
LumexAvatarGroupdoesn't throw exceptions upon rendering. Good coverage of basic functionality.
59-76: Validate boundary logic for the remaining count.This is a crucial feature: verifying that when
Maxis exceeded, the last avatar becomes a count indicator. Ensure there's coverage for edge cases (e.g.,Max = 0or negative) if relevant in broader usage.
94-117: Great custom count test.The custom count logic is well-tested for
Max="2". Keep in mind to confirm text content is localized or i18n-friendly if required by your project’s guidelines.src/LumexUI/Components/Avatar/LumexAvatar.razor (2)
6-13: Context registration logic is clear.It’s nice that you handle conditional rendering depending on
_isCounterandContext. This approach helps avoid oversubscribing multiple components to the same context in large lists.
67-73: Good fallback to icon.You gracefully handle the scenario of no
FallbackContentand noNameby showing an icon. Since icons can be updated or localized, ensure an appropriate label or tooltip for accessibility if crucial to your app’s domain.docs/LumexUI.Docs.Client/Common/Navigation/NavigationStore.cs (1)
26-26: Navigation updates look good!The Avatar component has been properly added to both navigation categories with the "New" designation, and the "New" status has been correctly removed from the Dropdown and Tabs components.
Also applies to: 34-34, 44-44, 51-51
tests/LumexUI.Tests/Components/Avatar/AvatarTests.razor (5)
5-11: Constructor setup looks goodThe test constructor correctly sets up the TwMerge service and mocks the JavaScript interop for image loading checks.
13-21: Basic rendering test is appropriateThis test verifies that the component renders without throwing exceptions, which is a good basic test.
49-95: Name and initials tests are comprehensiveThe tests for single-word names, multi-word names, custom initials, and fallback to name when no source is provided are all well-implemented.
97-107: Default icon test is goodThis test correctly verifies that a default icon is rendered when neither a name nor an image source is provided.
109-135: Fallback content tests are well implementedThese tests correctly verify that custom fallback content is rendered when specified and that no fallback is shown when ShowFallback is false.
docs/LumexUI.Docs.Client/Pages/Components/Avatar/Avatar.razor (6)
1-3: Page setup is correctThe page routing and layout are properly configured.
4-6: Documentation structure is well organizedThe composition section at the beginning provides a good overview of the available components.
8-56: Avatar usage documentation is comprehensiveThe documentation covers all key aspects of the Avatar component: basic usage, borders, sizes, radius options, colors, and fallback behaviors.
58-76: Avatar Group documentation is thoroughThe documentation for the AvatarGroup component properly covers its various features including basic usage, max count limitation, custom count display, and grid layout.
78-115: Custom styles documentation is detailed and helpfulThe documentation clearly explains how to apply custom styles using slots and class parameters, which is essential for component customization.
117-181: Code organization is clean and well-structuredThe code section is well-organized with clear definitions of component composition, headings, slots, and API components. The OnInitialized method properly sets up the layout.
src/LumexUI/Components/Avatar/LumexAvatar.razor.cs (1)
248-264: Excellent async disposal for JS module.Using
DisposeAsyncwith a try/catch to handleJSDisconnectedExceptionis a best practice, gracefully avoiding errors if the client disconnects. Nicely done!
* fix(theme): remove extra shade (950) from the color scales for consistency in dark mode (#199) * fix(theme): remove extra key (950) from the color scales for consistency in dark mode * build(docs): explicitly set Tailwind v4.0.9 * feat(components): introduce Avatar and AvatarGroup components (#201) * feat: add baseline implementation * feat: add slots * feat: add basic slots styles * feat: add appearance params, such as `Color`, `Radius`, `Size` * feat: add `Bordered` and `Disabled` params * feat: add compound variants styles * feat: apply slots styles * docs: add baseline examples page * feat: add `data-loaded` attribute on img * feat: add `ShowFallback` parameter * chore: fix compound style variants * chore: set `showFallback` on after first render * feat(utils): add implicit cast to string for the `ElementClass` * feat: add LumexAvatarGroup component * feat: take into account when LumexAvatar is rendered inside the LumexAvatarGroup * feat: add `AvatarClasses` parameter in the avatar group component * docs: add Avatar page * build(docs): explicitly set Tailwind v4.0.9 * test: add tests for LumexAvatar and LumexAvatarGroup components * chore: simplify condition for fallback render * fix(docs): replace usages of `-foreground-950` CSS classes with `-foreground-900` * fix(docs): remove `dark:prose-invert` CSS class until dark theme is properly configured * feat(components): introduce Skeleton component (#202) * feat(skeleton): add baseline implementation of the component * feat(skeleton): add slots and styles * feat(skeleton): add XML summaries * fix(skeleton): return back `after` pseudo CSS classes to prevent flickering on state change * docs(skeleton): add Skeleton page * test(skeleton): add tests * docs(skeleton): fix Loading example button text * fix(navbar): add a check before toggling navbar menu on navigation (#204) * v2.0.0-preview.3
* feat: support Tailwind CSS v4 (#183) * build(deps): bump TailwindMerge.NET from 0.3.0 to 1.0.0 * feat: add new CSS theme file * feat/build: add custom targets file to improve library usability * chore: move `Plugin` folder one level higher; remove `Scripts` folder * feat/build: pack new theme and custom `.targets` files * build(docs): add `Directory.Build.props` and `Directory.Build.targets` * chore(docs): remove tailwind npm deps; use standalone CLI instead * docs: apply `static` on theme * refactor(theme-provider): simplify names of box-shadow css variables * refactor(theme-provider): opacities are percentage to match `color-mix` function syntax * chore(components): apply `static` on theme; fix some vars * refactor(components): drop Tailwind CSS v3 support * feat(theme): add custom transition variables * fix(theme): correct `default` color; add `default-foreground` color * chore(theme): add reference for the custom transitions approach (it's not in docs afaik) * fix: rename `shadow-sm` to `shadow-xs` * fix: rename `rounded-sm` to `rounded-xs` * fix: rename `rounded` to `rounded-sm` * fix: rename `outline-none` to `outline-hidden` * fix: rename `ring-1` to `ring` * fix(button): add base `cursor-pointer` class * docs: remove `children` custom variant in favor of `*` * fix(theme): correct `enter` custom animation * chore(components): cleanup styles * fix(theme): add missing comma separator in custom transition vars * docs: configure typography * refactor(theme): simplify `scrollbar-hide` utility * chore(theme): apply `inline` on theme * refactor: replace `theme` function with CSS vars * fix(components): correct scale/translate transitions * feat(theme): update colors from hex to oklch * docs(installation): update installation guide * feat(theme): add leading CSS vars * chore(docs): fix prose `<code>` tag ticks * refactor(utils): remove hex luminance calculator * docs(customization): update Theme and Colors pages * docs(colors): remove 'common colors are not configurable' callout * fix(checkbox): correct radius styles * fix(data-grid): correct striped styles * fix(input/select): correct label placement out transitions * fix(input/select): correct outlined variant focus styles * fix(input): add cursor-pointer style on the clear button * fix(input/select): correct flat variant focus styles * fix(docs): correct some component examples * build(docs): adjust Tailwind standalone CLI file download for Linux * build(docs): adjust Tailwind standalone CLI file download for Linux * ci(deploy): try add staging env in the ci/cd * ci(build-test): change trigger branch * ci(deploy): update trigger branches * ci(deploy): change env vars usage (test) * ci: add deploy-dev.yml; revert deploy.yml * ci(deploy): test staging * chore(docs): nits * chore(components): tweak styles of some components * chore(docs): tweak some components examples * chore: coderabbit comments * ci: remove deploy-dev.yml * fix(theme): remove extra shade (950) from the color scales for consistency in dark mode (#199) * fix(theme): remove extra key (950) from the color scales for consistency in dark mode * build(docs): explicitly set Tailwind v4.0.9 * feat(components): introduce Avatar and AvatarGroup components (#201) * feat: add baseline implementation * feat: add slots * feat: add basic slots styles * feat: add appearance params, such as `Color`, `Radius`, `Size` * feat: add `Bordered` and `Disabled` params * feat: add compound variants styles * feat: apply slots styles * docs: add baseline examples page * feat: add `data-loaded` attribute on img * feat: add `ShowFallback` parameter * chore: fix compound style variants * chore: set `showFallback` on after first render * feat(utils): add implicit cast to string for the `ElementClass` * feat: add LumexAvatarGroup component * feat: take into account when LumexAvatar is rendered inside the LumexAvatarGroup * feat: add `AvatarClasses` parameter in the avatar group component * docs: add Avatar page * build(docs): explicitly set Tailwind v4.0.9 * test: add tests for LumexAvatar and LumexAvatarGroup components * chore: simplify condition for fallback render * fix(docs): replace usages of `-foreground-950` CSS classes with `-foreground-900` * fix(docs): remove `dark:prose-invert` CSS class until dark theme is properly configured * feat(components): introduce Skeleton component (#202) * feat(skeleton): add baseline implementation of the component * feat(skeleton): add slots and styles * feat(skeleton): add XML summaries * fix(skeleton): return back `after` pseudo CSS classes to prevent flickering on state change * docs(skeleton): add Skeleton page * test(skeleton): add tests * docs(skeleton): fix Loading example button text * fix(navbar): add a check before toggling navbar menu on navigation (#204) * feat(components): introduce Spinner component (#207) * feat(spinner): add baseline implementation * feat(spinner): add variants and styles * feat(spinner): add slots * docs(spinner): add Spinner page * docs: nits * test(spinner): add tests * docs: map static assets * build(docs): remove extra MSBuild target for the Tailwind prod build * docs: revert static assets changes * docs: update static assets usage * Revert "docs: update static assets usage" This reverts commit 94ae9ec. * feat(components): introduce Chip component (#211) * feat(chip): add baseline implementation * feat(chip): add ChipVariant enum * feat(chip): add appearance parameters and styles * feat(chip): add AvatarContent parameter * feat(chip): adjust paddings when chip has start/end content * docs(chip): add Chip page * feat(chip): add XML summaries * test(chip): add tests * chore(components): add missing XML documentation summaries * feat(components): add new Badge component (#222) * feat(badge): initial * feat(badge): add badge slots * feat(badge): add badge baseline implementation * feat(badge): add base visual-related params * feat(badge): add majority of badge styles * feat(badge): add outline around badge * feat(badge): add `Invisible` param to control badge visibility * feat(badge): add `IsOneChar` param to make badge equilateral * feat(badge): decrease badge dimensions if no content provided * refactor(badge): rename `IsOneChar` param to `OneChar` * fix(badge): use correct type for `Variant` param * feat(badge): apply CSS classes directly to the badge slot * fix(badge): ensure correct placement styles * fix(badge): correct `Content` check condition * fix(badge): allow null for content * fix(badge): properly render Content as RenderFragment * docs(badge): add Badge docs page * test(badge): add tests * test(badge): add more tests * fix(badge): ensure `OneChar` param is taken into account * fix(badge): fix one char switch * chore: apply CodeRabbit suggestions * build(deps): bump requests from 2.32.0 to 2.32.4 in /scripts (#219) Bumps [requests](https://github.com/psf/requests) from 2.32.0 to 2.32.4. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](psf/requests@v2.32.0...v2.32.4) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.4 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(components): add Tooltip component (#224) * feat(tooltip): initial * refactor(popover): introduce PopoverWrapper to simplify open state * fix(popover): ensure arrow is positioned correctly * fix(popover): ensure popover closes on trigger click if already opened * fix(popover): position flicker * test(popover/dropdown): adjust tests * refactor(popover): remove LastShown meta from popover service * feat(tooltip): add baseline implementation * feat(tooltip): add common visual-related parameters to pass into popover * feat(tooltip): add OpenDelay and CloseDelay params * docs(tooltip): add Tooltip page * feat(tooltip): pass slots to popover * chore(popover): add full radius styles * test(tooltip): add tests * docs(tooltip): minor tweaks * docs(tooltip): typo * feat(components): add Alert component (#225) * feat(alert): add baseline implementation * feat(alert): add styles (may be not complete) * feat(alert): complete styles * feat(button): add full radius styles * feat(alert): apply styles * feat(alert): add close button handler * chore(alert): complete XML docs summaries * chore(docs): adjust background colors for preview and toolbar * chore(components): darken text color for warning flat variant * chore(alert): styling tweaks * feat(docs): add Alert page * chore(alert): add missing close-button slot attribute * chore(alert): ensure TitleContent takes precedence over Title * docs(alert): add callout regarding Title and TitleContent parameters usage * test(alert): add tests * fix(theme): add tw custom CSS class-based dark mode variant (#226) * refactor(theme): replace C# theme config with a new CSS-first approach (#229) * feat(theme): add light and dark theme CSS files * refactor(components): cleanup theme provider * refactor(theme): remove Theme directory * test(theme): remove Theme directory * docs(theme): remove theme config * fix(alert): correct RenderFragment parameters usage * chore(theme): correct theme variables * docs(customization): replace Customization section with Theming * test(theme-provider): remove all tests * feat(theme): introduce a mechanism to toggle light/dark modes (#230) * feat(theme): introduce Theme service to manage and persist theme settings (JS) * feat(theme): introduce Theme service to manage and persist theme settings * docs(*): rename ComponentStatus enum to PageStatus * docs(theming): add Dark Mode page * chore(docs): component rename * feat(button): add new `IconOnly` parameter * docs(button): add demo for `IconOnly` parameter * refactor(*): remove all bundled Google Material Icons and related code (#232) * build: add new shared icons project * feat(icons): add base icon component * feat(icons): add dynamic icon component * feat(icons): add some icons * build(deps): reference icons in components * refactor(accordion): use new icon components * docs(components): use new icons in Callout components * docs(*): use new icons * refactor(icons): add "Icon" suffix; add more icons * docs(*): use new icons * test(*): fix tests * refactor(components): remove `LumexIcon` component * docs(datagrid): formatting * refactor(icons): remove all Google Material Icons * refactor(icons): remove script for downloading/updating icons * feat(components): add dark mode support (#234) * feat(alert): add dark mode support * feat(button): add dark mode support * feat(chip): add dark mode support * feat(datagrid): add dark mode support * feat(textbox/numbox): add dark mode support * feat(listbox): add dark mode support * feat(menu): add dark mode support * feat(select): add dark mode support * feat(tabs): add dark mode support * fix(theme): ensure default values are of correct shade in dark mode * feat(theme): add `color-scheme` in light theme * fix(icons): use better icons for alert component * docs: add dark mode support + theme toggle (#235) * docs: add dark mode support * docs: add missing border for the preview component * docs: remove extra border in the preview code component * chore(badge): improve flat variant contrast in light theme * chore(tabs): remove `EditorRequired` attribute from `Id` param * docs: add null check and theme class cleanup to prevent issues * docs: remove IPopoverService injection from theme toggle component * chore(components): remove unused / redundant types * fix(data-grid): correct outside click handler creation * feat(popover): enable position autoUpdate * refactor(popover): make use of popover trigger component instead of service * feat(dropdown): introduce dropdown trigger component instead of relying on popover service * docs(dark-mode): update theme toggle dropdown example * docs: add Home page with library usage examples (#241) * feat(icons): add more icons * docs: add showcases on home page * chore(components): adjust some styles * docs(overview): update paths * chore(docs): nits * fix(components): add missing popover js parts * chore(docs): nits * fix(popover): use overlay to close instead of custom outside click event * fix(tooltip): remove pressed effect from on trigger hover * chore(showcases): complete column visibility toggling in UserTable example * chore(showcases): adjust legend color in usage chart * test(popover): update tests * chore(docs): coderabbit suggestions * chore(*): migrate to DigitalOcean app platform * fix(*): update custom LumexUI targets to copy theme files before build * chore(*): add missing css files in the pack * v2.0.0-preview.4 * perf(*): optimize fonts in docs app * fix(docs): stylesheets import ordering * perf(docs): optimize docs CSS output * fix(docs): correct linux tailwind executable file name * chore(*): delete update-icons.yml * perf(docs): enable stream rendering on all pages * fix(docs): ensure initial theme is set * docs(overview): update content * docs(installation): update content * docs(design-tokens): update content * docs(customization): update content * docs(dark-mode): update content * docs(accordion): update content * refactor(docs): replace `Callout` with `LumexAlert` * docs(avatar): update content * docs(components): replace `Code` component usages with HTML tag * fix(docs): ensure ThemeSelector sets correct theme value on init * docs(landing): make adaptive * docs(customization): add dark mode for global theme sample * refactor(components): remove deprecated `Root` slot * refactor(utils): remove redundant; update access modifiers * docs(card): update slot names * refactor(docs): make stream rendering global * docs(header): remove active state from links; update stars counter * ci(*): remove deploy.yml * ci: run build-test on PR to main * v2.0.0 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Description
Closes #172
Introducing the new Avatar and AvatarGroup components.
What's been done?
Checklist
Additional Notes
Summary by CodeRabbit
New Features
Documentation
Chores