|
| 1 | +@namespace MudBlazor.MudScrollbar |
| 2 | +@inherits MudComponentBase |
| 3 | +@using MudBlazor.Extensions |
| 4 | + |
| 5 | +@code{ |
| 6 | + |
| 7 | + /// <summary> |
| 8 | + /// 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. |
| 9 | + /// </summary> |
| 10 | + [Parameter] |
| 11 | + [Category(CategoryTypes.Item.Behavior)] |
| 12 | + public string Selector { get; set; } |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// Firefox ignores the other parameters. It can be only done with this parameter. |
| 16 | + /// </summary> |
| 17 | + [Parameter] |
| 18 | + [Category(CategoryTypes.Item.Appearance)] |
| 19 | + public string FirefoxStyle { get; set; } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Custom thumb styles for scrollbar. Must end with ";" character for each style. Doesn't support by firefox (see FirefoxStyle). |
| 23 | + /// </summary> |
| 24 | + [Parameter] |
| 25 | + [Category(CategoryTypes.Item.Appearance)] |
| 26 | + public string ThumbStyle { get; set; } |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Custom track styles for scrollbar. Must end with ";" character for each style. Doesn't support by firefox (see FirefoxStyle). |
| 30 | + /// </summary> |
| 31 | + [Parameter] |
| 32 | + [Category(CategoryTypes.Item.Appearance)] |
| 33 | + public string TrackStyle { get; set; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Width of both scrollbar thumb and track. Doesn't support by firefox (see FirefoxStyle). |
| 37 | + /// </summary> |
| 38 | + [Parameter] |
| 39 | + [Category(CategoryTypes.Item.Appearance)] |
| 40 | + public int Width { get; set; } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Width of both scrollbar thumb and track on hover. Doesn't support by firefox (see FirefoxStyle). |
| 44 | + /// </summary> |
| 45 | + [Parameter] |
| 46 | + [Category(CategoryTypes.Item.Appearance)] |
| 47 | + public int? HoverWidth { get; set; } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Border radius for scrollbar thumb. Doesn't support by firefox (see FirefoxStyle). |
| 51 | + /// </summary> |
| 52 | + [Parameter] |
| 53 | + [Category(CategoryTypes.Item.Appearance)] |
| 54 | + public int BorderRadius { get; set; } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Border radius for scrollbar thumb. Supports hex values, color names and MudTheme color keywords (ex. "primary", "secondary"). Doesn't support by firefox (see FirefoxStyle). |
| 58 | + /// </summary> |
| 59 | + [Parameter] |
| 60 | + [Category(CategoryTypes.Item.Appearance)] |
| 61 | + public string Color { get; set; } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Border radius for scrollbar thumb on hover. Supports hex values, color names and MudTheme color keywords (ex. "primary", "secondary"). Doesn't support by firefox (see FirefoxStyle). |
| 65 | + /// </summary> |
| 66 | + [Parameter] |
| 67 | + [Category(CategoryTypes.Item.Appearance)] |
| 68 | + public string HoverColor { get; set; } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Border radius for scrollbar track. Supports hex values, color names and MudTheme color keywords (ex. "primary", "secondary"). Doesn't support by firefox (see FirefoxStyle). |
| 72 | + /// </summary> |
| 73 | + [Parameter] |
| 74 | + [Category(CategoryTypes.Item.Appearance)] |
| 75 | + public string TrackColor { get; set; } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Hide the scrollbar with securing scroll functionality. Also supported by firefox. |
| 79 | + /// </summary> |
| 80 | + [Parameter] |
| 81 | + [Category(CategoryTypes.Item.Appearance)] |
| 82 | + public bool Hide { get; set; } |
| 83 | + |
| 84 | + protected bool IsThemeColor(string color) |
| 85 | + { |
| 86 | + foreach (Color val in Enum.GetValues(typeof(Color))) |
| 87 | + { |
| 88 | + if (val.ToDescriptionString() == color) |
| 89 | + { |
| 90 | + return true; |
| 91 | + } |
| 92 | + } |
| 93 | + return false; |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +<style> |
| 98 | + @(Selector) { |
| 99 | + @if (Hide) |
| 100 | + { |
| 101 | + <MudRender>scrollbar-width: none;</MudRender> |
| 102 | + } |
| 103 | + @(FirefoxStyle) |
| 104 | + } |
| 105 | +
|
| 106 | + @(Selector)::-webkit-scrollbar { |
| 107 | + width: @(Width)px; |
| 108 | + @if (Hide) |
| 109 | + { |
| 110 | + <MudRender>display: none;</MudRender> |
| 111 | + } |
| 112 | + @(Style) |
| 113 | + } |
| 114 | +
|
| 115 | + @(Selector):hover::-webkit-scrollbar { |
| 116 | + @if (HoverWidth != null) |
| 117 | + { |
| 118 | + <MudRender>width: @(HoverWidth)px;</MudRender> |
| 119 | + } |
| 120 | + |
| 121 | + } |
| 122 | +
|
| 123 | + @(Selector)::-webkit-scrollbar-thumb { |
| 124 | + @if (IsThemeColor(Color)) |
| 125 | + { |
| 126 | + <MudRender>background-color: var(--mud-palette-@(Color));</MudRender> |
| 127 | + } |
| 128 | + else |
| 129 | + { |
| 130 | + <MudRender>background-color: @(Color);</MudRender> |
| 131 | + } |
| 132 | + border-radius: @(BorderRadius)px; |
| 133 | + @(ThumbStyle) |
| 134 | + } |
| 135 | +
|
| 136 | + @(Selector)::-webkit-scrollbar-thumb:hover { |
| 137 | + @if (IsThemeColor(HoverColor)) |
| 138 | + { |
| 139 | + <MudRender>background-color: var(--mud-palette-@(HoverColor));</MudRender> |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + <MudRender>background-color: @(HoverColor);</MudRender> |
| 144 | + } |
| 145 | + width: @(HoverWidth)px; |
| 146 | + } |
| 147 | +
|
| 148 | + @(Selector)::-webkit-scrollbar-track { |
| 149 | + @if (IsThemeColor(TrackColor)) |
| 150 | + { |
| 151 | + <MudRender>background-color: var(--mud-palette-@(TrackColor));</MudRender> |
| 152 | + } |
| 153 | + else |
| 154 | + { |
| 155 | + <MudRender>background-color: @(TrackColor);</MudRender> |
| 156 | + } |
| 157 | + @(TrackStyle) |
| 158 | + } |
| 159 | +</style> |
0 commit comments