|
| 1 | +@namespace MudExtensions |
| 2 | +@using System.Text |
| 3 | +@using MudExtensions.Enums |
| 4 | +@using MudExtensions.Utilities |
| 5 | +@inherits MudComponentBase |
| 6 | + |
| 7 | +@code { |
| 8 | + /// <summary> |
| 9 | + /// The hex value of primary color. |
| 10 | + /// </summary> |
| 11 | + [Parameter] |
| 12 | + [Category(CategoryTypes.Item.Behavior)] |
| 13 | + public string Primary { get; set; } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// The hex value of secondary color. |
| 17 | + /// </summary> |
| 18 | + [Parameter] |
| 19 | + [Category(CategoryTypes.Item.Behavior)] |
| 20 | + public string Secondary { get; set; } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// The hex value of tertiary color. |
| 24 | + /// </summary> |
| 25 | + [Parameter] |
| 26 | + [Category(CategoryTypes.Item.Behavior)] |
| 27 | + public string Tertiary { get; set; } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// The color shade between 0 (black) and 100 (white). Default is 40 (20 for dark mode). If its on default, the value will change automatically for dark mode. |
| 31 | + /// </summary> |
| 32 | + [Parameter] |
| 33 | + [Category(CategoryTypes.Item.Behavior)] |
| 34 | + public int MainTone { get; set; } = 40; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// The color shade between 0 (black) and 100 (white) for container colors. Default is 90 (30 for dark mode). If its on default, the value will change automatically for dark mode. |
| 38 | + /// </summary> |
| 39 | + [Parameter] |
| 40 | + [Category(CategoryTypes.Item.Behavior)] |
| 41 | + public int ContainerTone { get; set; } = 90; |
| 42 | + |
| 43 | + [Parameter] |
| 44 | + [Category(CategoryTypes.Item.Behavior)] |
| 45 | + public bool DarkMode { get; set; } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// If true, the current CSS variables also be overriden (--mud-palette-primary etc.). Default is false. |
| 49 | + /// </summary> |
| 50 | + [Parameter] |
| 51 | + [Category(CategoryTypes.Item.Behavior)] |
| 52 | + public bool Override { get; set; } |
| 53 | +} |
| 54 | + |
| 55 | +<style> |
| 56 | + :root { |
| 57 | + @for (int i = 10; i < 100; i = i + 10) |
| 58 | + { |
| 59 | + int a = i; |
| 60 | + @($"--mud-primary-{a}: {GetRGBString(Primary, a)};") |
| 61 | + @($"--mud-secondary-{a}: {GetRGBString(Secondary, a)};") |
| 62 | + @($"--mud-tertiary-{a}: {GetRGBString(Tertiary, a)};") |
| 63 | + } |
| 64 | + @($"--mud-primary-{MainTone}: {GetRGBString(Primary, MainTone)};") |
| 65 | + @($"--mud-secondary-{MainTone}: {GetRGBString(Secondary, MainTone)};") |
| 66 | + @($"--mud-tertiary-{MainTone}: {GetRGBString(Tertiary, MainTone)};") |
| 67 | + @($"--mud-primary-{ContainerTone}: {GetRGBString(Primary, ContainerTone)};") |
| 68 | + @($"--mud-secondary-{ContainerTone}: {GetRGBString(Secondary, ContainerTone)};") |
| 69 | + @($"--mud-tertiary-{ContainerTone}: {GetRGBString(Tertiary, ContainerTone)};") |
| 70 | + @($"--mud-primary-{100 - ContainerTone}: {GetRGBString(Primary, 100 - ContainerTone)};") |
| 71 | + @($"--mud-secondary-{100 - ContainerTone}: {GetRGBString(Secondary, 100 - ContainerTone)};") |
| 72 | + @($"--mud-tertiary-{100 - ContainerTone}: {GetRGBString(Tertiary, 100 - ContainerTone)};") |
| 73 | + @($"--mud-primary-99: {GetRGBString(Primary, 99)};") |
| 74 | + @($"--mud-secondary-99: {GetRGBString(Secondary, 99)};") |
| 75 | + @($"--mud-tertiary-99: {GetRGBString(Tertiary, 99)};") |
| 76 | + --mud-primary-0: rgb(0, 0, 0); |
| 77 | + --mud-primary-100: rgb(255, 255, 255); |
| 78 | + --mud-secondary-0: rgb(0, 0, 0); |
| 79 | + --mud-secondary-100: rgb(255, 255, 255); |
| 80 | + --mud-tertiary-0: rgb(0, 0, 0); |
| 81 | + --mud-tertiary-100: rgb(255, 255, 255); |
| 82 | +
|
| 83 | + --mud-m3-primary: var(--mud-primary-@($"{(MainTone == 40 && DarkMode == true ? "80" : MainTone.ToString())}")); |
| 84 | + --mud-m3-onprimary: var(--mud-primary-@(DarkMode ? "20" : "100")); |
| 85 | + --mud-m3-primary-container: var(--mud-primary-@($"{(ContainerTone == 90 && DarkMode == true ? "30" : ContainerTone.ToString())}")); |
| 86 | + --mud-m3-onprimary-container: var(--mud-primary-@($"{(ContainerTone == 90 && DarkMode == true ? "90" : 100 - ContainerTone)}")); |
| 87 | +
|
| 88 | + --mud-m3-secondary: var(--mud-secondary-@($"{(MainTone == 40 && DarkMode == true ? "80" : MainTone.ToString())}")); |
| 89 | + --mud-m3-onsecondary: var(--mud-secondary-@(DarkMode ? "20" : "100")); |
| 90 | + --mud-m3-secondary-container: var(--mud-secondary-@($"{(ContainerTone == 90 && DarkMode == true ? "30" : ContainerTone.ToString())}")); |
| 91 | + --mud-m3-onsecondary-container: var(--mud-secondary-@($"{(ContainerTone == 90 && DarkMode == true ? "90" : 100 - ContainerTone)}")); |
| 92 | +
|
| 93 | + --mud-m3-tertiary: var(--mud-tertiary-@($"{(MainTone == 40 && DarkMode == true ? "80" : MainTone.ToString())}")); |
| 94 | + --mud-m3-ontertiary: var(--mud-tertiary-@(DarkMode ? "20" : "100")); |
| 95 | + --mud-m3-tertiary-container: var(--mud-tertiary-@($"{(ContainerTone == 90 && DarkMode == true ? "30" : ContainerTone.ToString())}")); |
| 96 | + --mud-m3-ontertiary-container: var(--mud-tertiary-@($"{(ContainerTone == 90 && DarkMode == true ? "90" : 100 - ContainerTone)}")); |
| 97 | +
|
| 98 | + @if (Override) |
| 99 | + { |
| 100 | + <MudRender> |
| 101 | + --mud-palette-primary: var(--mud-m3-primary) !important; |
| 102 | + --mud-palette-primary-text: var(--mud-m3-primary-container) !important; |
| 103 | + --mud-palette-secondary: var(--mud-m3-secondary) !important; |
| 104 | + --mud-palette-secondary-text: var(--mud-m3-secondary-container) !important; |
| 105 | + --mud-palette-tertiary: var(--mud-m3-tertiary) !important; |
| 106 | + --mud-palette-tertiary-text: var(--mud-m3-tertiary-container) !important; |
| 107 | + </MudRender> |
| 108 | + } |
| 109 | + } |
| 110 | +
|
| 111 | + .mud-m3-theme-primary { |
| 112 | + color: var(--mud-m3-onprimary); |
| 113 | + background-color: var(--mud-m3-primary); |
| 114 | + } |
| 115 | +
|
| 116 | + .mud-m3-theme-primary-reverse { |
| 117 | + color: var(--mud-m3-primary); |
| 118 | + background-color: var(--mud-m3-onprimary); |
| 119 | + } |
| 120 | +
|
| 121 | + .mud-m3-theme-primary-container { |
| 122 | + color: var(--mud-m3-onprimary-container); |
| 123 | + background-color: var(--mud-m3-primary-container); |
| 124 | + } |
| 125 | +
|
| 126 | + .mud-m3-theme-primary-container-reverse { |
| 127 | + color: var(--mud-m3-primary-container); |
| 128 | + background-color: var(--mud-m3-onprimary-container); |
| 129 | + } |
| 130 | +
|
| 131 | + .mud-m3-theme-secondary { |
| 132 | + color: var(--mud-m3-onsecondary); |
| 133 | + background-color: var(--mud-m3-secondary); |
| 134 | + } |
| 135 | +
|
| 136 | + .mud-m3-theme-secondary-reverse { |
| 137 | + color: var(--mud-m3-secondary); |
| 138 | + background-color: var(--mud-m3-onsecondary); |
| 139 | + } |
| 140 | +
|
| 141 | + .mud-m3-theme-secondary-container { |
| 142 | + color: var(--mud-m3-onsecondary-container); |
| 143 | + background-color: var(--mud-m3-secondary-container); |
| 144 | + } |
| 145 | +
|
| 146 | + .mud-m3-theme-secondary-container-reverse { |
| 147 | + color: var(--mud-m3-secondary-container); |
| 148 | + background-color: var(--mud-m3-onsecondary-container); |
| 149 | + } |
| 150 | +
|
| 151 | + .mud-m3-theme-tertiary { |
| 152 | + color: var(--mud-m3-ontertiary); |
| 153 | + background-color: var(--mud-m3-tertiary); |
| 154 | + } |
| 155 | +
|
| 156 | + .mud-m3-theme-tertiary-reverse { |
| 157 | + color: var(--mud-m3-tertiary); |
| 158 | + background-color: var(--mud-m3-ontertiary); |
| 159 | + } |
| 160 | +
|
| 161 | + .mud-m3-theme-tertiary-container { |
| 162 | + color: var(--mud-m3-ontertiary-container); |
| 163 | + background-color: var(--mud-m3-tertiary-container); |
| 164 | + } |
| 165 | +
|
| 166 | + .mud-m3-theme-tertiary-container-reverse { |
| 167 | + color: var(--mud-m3-tertiary-container); |
| 168 | + background-color: var(--mud-m3-ontertiary-container); |
| 169 | + } |
| 170 | +</style> |
0 commit comments