|
| 1 | +@namespace MudExtensions |
| 2 | +@using System.Text |
| 3 | +@using MudExtensions.Enums |
| 4 | +@using MudExtensions.Utilities |
| 5 | +@inherits MudComponentBase |
| 6 | + |
| 7 | +@code{ |
| 8 | + |
| 9 | + /// <summary> |
| 10 | + /// Supports id and class selection. Use "#idName" for id selectors (ex. <Component id="idName" />) or ".idName" for class selectors (ex. <Component Class="idName" />). Leave it null or empty to effect all scrollbars. |
| 11 | + /// </summary> |
| 12 | + [Parameter] |
| 13 | + [Category(CategoryTypes.Item.Behavior)] |
| 14 | + public string Selector { get; set; } |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// If true, selected colors applies even the input does not have focus. Default is false. |
| 18 | + /// </summary> |
| 19 | + [Parameter] |
| 20 | + [Category(CategoryTypes.Item.Behavior)] |
| 21 | + public bool Always { get; set; } |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// The base color that affects text, label and borders. Can be overrided with other color parameters. Supports hex values "#ffffff", valid keywords "blue" and CSS variables "var(--mud-palette-primary)" |
| 25 | + /// </summary> |
| 26 | + [Parameter] |
| 27 | + [Category(CategoryTypes.Item.Appearance)] |
| 28 | + public string BaseColor { get; set; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// The text color. Supports hex values "#ffffff", valid keywords "blue" and CSS variables "var(--mud-palette-primary)" |
| 32 | + /// </summary> |
| 33 | + [Parameter] |
| 34 | + [Category(CategoryTypes.Item.Appearance)] |
| 35 | + public string TextColor { get; set; } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// The label text color. Supports hex values "#ffffff", valid keywords "blue" and CSS variables "var(--mud-palette-primary)" |
| 39 | + /// </summary> |
| 40 | + [Parameter] |
| 41 | + [Category(CategoryTypes.Item.Appearance)] |
| 42 | + public string LabelColor { get; set; } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// The label background color. Supports hex values "#ffffff", valid keywords "blue" and CSS variables "var(--mud-palette-primary)" |
| 46 | + /// </summary> |
| 47 | + [Parameter] |
| 48 | + [Category(CategoryTypes.Item.Appearance)] |
| 49 | + public string LabelBackgroundColor { get; set; } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// The border color. Supports hex values "#ffffff", valid keywords "blue" and CSS variables "var(--mud-palette-primary)" |
| 53 | + /// </summary> |
| 54 | + [Parameter] |
| 55 | + [Category(CategoryTypes.Item.Appearance)] |
| 56 | + public string BorderColor { get; set; } |
| 57 | + |
| 58 | +} |
| 59 | + |
| 60 | +<style> |
| 61 | + @if (!string.IsNullOrEmpty(BaseColor)) |
| 62 | + { |
| 63 | + @($"{Selector} .mud-input-root {{ color: {BaseColor} !important; }}") |
| 64 | +
|
| 65 | + @if (Always) |
| 66 | + { |
| 67 | + @($"{Selector} .mud-input-underline:after, {Selector} .mud-input-underline:before {{ border-color: {BaseColor} !important; }}") |
| 68 | + @($"{Selector} .mud-input-outlined-border {{ border-color: {BaseColor} !important; }}") |
| 69 | + @($"{Selector} .mud-input-underline:hover:before {{ opacity: 0.6; }}") |
| 70 | +
|
| 71 | + @($"{Selector} .mud-input-label {{ color: {BaseColor} !important; }}") |
| 72 | + @($"{Selector}:focus-within .mud-input-label {{ color: {BaseColor} !important; font-weight: 900 }}") |
| 73 | + } |
| 74 | + else |
| 75 | + { |
| 76 | + @($"{Selector} .mud-input-underline:after {{ border-color: {BaseColor} !important; }}") |
| 77 | + @($"{Selector} .mud-input-outlined:focus-within .mud-input-outlined-border {{ border-color: {BaseColor} !important; }}") |
| 78 | +
|
| 79 | + @($"{Selector}:focus-within .mud-input-label {{ color: {BaseColor} !important; }}") |
| 80 | + } |
| 81 | + } |
| 82 | +
|
| 83 | + @if (!string.IsNullOrEmpty(TextColor)) |
| 84 | + { |
| 85 | + @($"{Selector} .mud-input-root {{ color: {TextColor} !important; }}") |
| 86 | + } |
| 87 | +
|
| 88 | + @if (!string.IsNullOrEmpty(LabelColor)) |
| 89 | + { |
| 90 | + if (Always) |
| 91 | + { |
| 92 | + @($"{Selector} .mud-input-label {{ color: {LabelColor} !important; }}") |
| 93 | + @($"{Selector}:focus-within .mud-input-label {{ color: {LabelColor} !important; font-weight: 900 }}") |
| 94 | + } |
| 95 | + else |
| 96 | + { |
| 97 | + @($"{Selector}:focus-within .mud-input-label {{ color: {LabelColor} !important; }}") |
| 98 | + } |
| 99 | + } |
| 100 | +
|
| 101 | + @if (!string.IsNullOrEmpty(LabelBackgroundColor)) |
| 102 | + { |
| 103 | + @($"{Selector} .mud-input-label {{ background-color: {LabelBackgroundColor} !important; }}") |
| 104 | + } |
| 105 | +
|
| 106 | + @if (!string.IsNullOrEmpty(BorderColor)) |
| 107 | + { |
| 108 | + if (Always) |
| 109 | + { |
| 110 | + @($"{Selector} .mud-input-underline:after, {Selector} .mud-input-underline:before {{ border-color: {BorderColor} !important; }}") |
| 111 | + @($"{Selector} .mud-input-outlined-border {{ border-color: {BorderColor} !important; }}") |
| 112 | + @($"{Selector} .mud-input-underline:hover:before {{ opacity: 0.6; }}") |
| 113 | + } |
| 114 | + else |
| 115 | + { |
| 116 | + <MudRender>@(Selector) .mud-input-underline:after { |
| 117 | + @($"border-color: {BorderColor} !important;"); |
| 118 | + }</MudRender> |
| 119 | +
|
| 120 | + <MudRender>@(Selector) .mud-input-outlined:focus-within .mud-input-outlined-border { |
| 121 | + @($"border-color: {BorderColor} !important;"); |
| 122 | + }</MudRender> |
| 123 | + } |
| 124 | + } |
| 125 | +</style> |
0 commit comments