forked from LumexUI/lumexui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLumexUser.razor.cs
More file actions
78 lines (64 loc) · 2.09 KB
/
LumexUser.razor.cs
File metadata and controls
78 lines (64 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 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 System.Diagnostics.CodeAnalysis;
using LumexUI.Common;
using LumexUI.Utilities;
using Microsoft.AspNetCore.Components;
namespace LumexUI;
/// <summary>
/// A component that represents user information, such as an avatar, name, and email.
/// </summary>
public partial class LumexUser : LumexComponentBase, ISlotComponent<UserSlots>
{
/// <summary>
/// Gets or sets the content to render when using a custom description element.
/// </summary>
[Parameter] public RenderFragment? DescriptionContent { get; set; }
/// <summary>
/// Gets or sets the content to render for the avatar element.
/// </summary>
[Parameter] public RenderFragment? AvatarContent { get; set; }
/// <summary>
/// Gets or sets the name of the user.
/// </summary>
[Parameter] public string? Name { get; set; }
/// <summary>
/// Gets or sets the description of the user.
/// </summary>
[Parameter] public string? Description { get; set; }
/// <summary>
/// Gets or sets the whether the user is focusable.
/// </summary>
[Parameter] public bool IsFocusable { get; set; }
/// <summary>
/// Gets or sets the CSS class names for the user slots.
/// </summary>
[Parameter] public UserSlots? Classes { get; set; }
private Dictionary<string, ComponentSlot> _slots = [];
/// <inheritdoc/>
protected override void OnParametersSet()
{
var user = Styles.User.Style( TwMerge );
_slots = user( new()
{
[nameof( IsFocusable )] = IsFocusable.ToString(),
} );
}
[ExcludeFromCodeCoverage]
private string? GetStyles( string slot )
{
if( !_slots.TryGetValue( slot, out var styles ) )
{
throw new NotImplementedException();
}
return slot switch
{
nameof( UserSlots.Base ) => styles( Classes?.Base, Class ),
nameof( UserSlots.Wrapper ) => styles( Classes?.Wrapper ),
nameof( UserSlots.Name ) => styles( Classes?.Name ),
nameof( UserSlots.Description ) => styles( Classes?.Description ),
_ => throw new NotImplementedException()
};
}
}