|
| 1 | +# Button Variant & Icon Constructor Parameters Removed - v1.2.15 |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +The `Button` constructor no longer accepts `variant:` or `icon:` named parameters. Variants are now set via fluent extension methods (`.Destructive()`, `.Outline()`, `.Ghost()`, `.Secondary()`, `.Link()`, `.Success()`, `.Warning()`, `.Info()`), and icons are set via the `.Icon()` method. `ButtonVariant.Primary` is the default and no longer needs to be specified. |
| 6 | + |
| 7 | +## What Changed |
| 8 | + |
| 9 | +### Before (v1.2.14 and earlier) |
| 10 | + |
| 11 | +```csharp |
| 12 | +new Button("Delete", variant: ButtonVariant.Destructive) |
| 13 | +new Button("Cancel", _ => Close(), variant: ButtonVariant.Outline) |
| 14 | +new Button("Save", variant: ButtonVariant.Primary) |
| 15 | +new Button(null, icon: Icons.Settings, variant: ButtonVariant.Ghost) |
| 16 | +new Button("Search", icon: Icons.Search, variant: ButtonVariant.Outline) |
| 17 | +``` |
| 18 | + |
| 19 | +### After (v1.2.15+) |
| 20 | + |
| 21 | +```csharp |
| 22 | +new Button("Delete").Destructive() |
| 23 | +new Button("Cancel", _ => Close()).Outline() |
| 24 | +new Button("Save") // Primary is default, no method needed |
| 25 | +new Button().Icon(Icons.Settings).Ghost() |
| 26 | +new Button("Search").Icon(Icons.Search).Outline() |
| 27 | +``` |
| 28 | + |
| 29 | +> **Note:** `ButtonVariant.Primary` is the default variant. Remove `variant: ButtonVariant.Primary` entirely — no replacement method is needed. |
| 30 | +
|
| 31 | +## How to Find Affected Code |
| 32 | + |
| 33 | +Run a `dotnet build`. |
| 34 | + |
| 35 | +Or search for these patterns in the codebase: |
| 36 | + |
| 37 | +### Pattern 1: variant parameter |
| 38 | + |
| 39 | +```regex |
| 40 | +variant:\s*ButtonVariant\. |
| 41 | +``` |
| 42 | + |
| 43 | +### Pattern 2: icon constructor parameter |
| 44 | + |
| 45 | +```regex |
| 46 | +new Button\(.*icon:\s*Icons\. |
| 47 | +``` |
| 48 | + |
| 49 | +## How to Refactor |
| 50 | + |
| 51 | +### Variant Mapping |
| 52 | + |
| 53 | +| Old Constructor Parameter | New Fluent Method | |
| 54 | +|--------------------------|-------------------| |
| 55 | +| `variant: ButtonVariant.Primary` | *(remove — it's the default)* | |
| 56 | +| `variant: ButtonVariant.Secondary` | `.Secondary()` | |
| 57 | +| `variant: ButtonVariant.Destructive` | `.Destructive()` | |
| 58 | +| `variant: ButtonVariant.Outline` | `.Outline()` | |
| 59 | +| `variant: ButtonVariant.Ghost` | `.Ghost()` | |
| 60 | +| `variant: ButtonVariant.Link` | `.Link()` | |
| 61 | +| `variant: ButtonVariant.Success` | `.Success()` | |
| 62 | +| `variant: ButtonVariant.Warning` | `.Warning()` | |
| 63 | +| `variant: ButtonVariant.Info` | `.Info()` | |
| 64 | +| `variant: ButtonVariant.Ai` | `.Ai()` | |
| 65 | + |
| 66 | +### Icon Migration |
| 67 | + |
| 68 | +Replace `icon:` constructor parameter with `.Icon()` method: |
| 69 | + |
| 70 | +**Before:** |
| 71 | + |
| 72 | +```csharp |
| 73 | +new Button("Search", icon: Icons.Search, variant: ButtonVariant.Outline) |
| 74 | +``` |
| 75 | + |
| 76 | +**After:** |
| 77 | + |
| 78 | +```csharp |
| 79 | +new Button("Search").Icon(Icons.Search).Outline() |
| 80 | +``` |
| 81 | + |
| 82 | +### Complex Example |
| 83 | + |
| 84 | +**Before:** |
| 85 | + |
| 86 | +```csharp |
| 87 | +new DialogFooter( |
| 88 | + new Button("Cancel", _ => isOpen.Set(false), variant: ButtonVariant.Outline), |
| 89 | + new Button("Confirm", _ => Submit(), variant: ButtonVariant.Primary) |
| 90 | +) |
| 91 | +``` |
| 92 | + |
| 93 | +**After:** |
| 94 | + |
| 95 | +```csharp |
| 96 | +new DialogFooter( |
| 97 | + new Button("Cancel", _ => isOpen.Set(false)).Outline(), |
| 98 | + new Button("Confirm", _ => Submit()) |
| 99 | +) |
| 100 | +``` |
| 101 | + |
| 102 | +## Key Refactoring Rules |
| 103 | + |
| 104 | +1. Move `variant:` from constructor to fluent method call **after** the constructor |
| 105 | +2. Move `icon:` from constructor to `.Icon()` method call |
| 106 | +3. Remove `variant: ButtonVariant.Primary` entirely (it's the default) |
| 107 | +4. Remove `null` as button text if it was only used to pass `icon:` — use parameterless `new Button()` instead |
| 108 | + |
| 109 | +## Verification |
| 110 | + |
| 111 | +After refactoring, run: |
| 112 | + |
| 113 | +```bash |
| 114 | +dotnet build |
| 115 | +``` |
| 116 | + |
| 117 | +All usages should compile without errors. |
0 commit comments