|
| 1 | +--- |
| 2 | +name: design-system-usage |
| 3 | +description: Rules and patterns for using DIPS.Mobile.UI design tokens, styles, and Layout effect in C# code. Apply when building UI components or views. |
| 4 | +--- |
| 5 | + |
| 6 | +# Design System Usage |
| 7 | + |
| 8 | +When building UI elements in C# code, always use the DIPS design system instead of hardcoded values. |
| 9 | + |
| 10 | +## Trigger Phrases |
| 11 | + |
| 12 | +- Building a new component or view in C# |
| 13 | +- Creating UI elements with colors, sizes, fonts, or corner radius |
| 14 | +- Refactoring hardcoded values to design tokens |
| 15 | +- "Use design tokens" / "Use design system" |
| 16 | + |
| 17 | +## Rules |
| 18 | + |
| 19 | +### 1. Colors — Never Hardcode |
| 20 | + |
| 21 | +```csharp |
| 22 | +using DIPS.Mobile.UI.Resources.Colors; |
| 23 | +using Colors = DIPS.Mobile.UI.Resources.Colors.Colors; |
| 24 | + |
| 25 | +// ✅ Correct — use semantic color tokens from ColorName enum |
| 26 | +label.TextColor = Colors.GetColor(ColorName.color_text_default); |
| 27 | +grid.BackgroundColor = Colors.GetColor(ColorName.color_surface_backdrop); |
| 28 | + |
| 29 | +// ❌ Wrong — hardcoded hex or Color values |
| 30 | +label.TextColor = Color.FromArgb("#FFFFFF"); |
| 31 | +grid.BackgroundColor = Color.FromArgb("#DD1A1A2E"); |
| 32 | +``` |
| 33 | + |
| 34 | +**Always verify** the color name exists in `src/library/DIPS.Mobile.UI/Resources/Colors/ColorName.cs` before using it. |
| 35 | + |
| 36 | +Common color token categories: |
| 37 | +| Purpose | Token pattern | |
| 38 | +|---------|--------------| |
| 39 | +| Page/card backgrounds | `color_surface_*`, `color_background_default` | |
| 40 | +| Text | `color_text_default`, `color_text_subtle`, `color_text_on_button`, `color_text_danger` | |
| 41 | +| Buttons | `color_fill_button`, `color_fill_button_danger`, `color_fill_success` | |
| 42 | +| Icons | `color_icon_default`, `color_icon_danger`, `color_icon_success` | |
| 43 | +| Borders | `color_border_default`, `color_border_subtle` | |
| 44 | +| Overlays | `color_surface_backdrop` | |
| 45 | +| Disabled | `color_surface_disabled`, `color_text_disabled`, `color_fill_disabled` | |
| 46 | + |
| 47 | +### 2. Sizes — Never Hardcode Dimensions |
| 48 | + |
| 49 | +```csharp |
| 50 | +using DIPS.Mobile.UI.Resources.Sizes; |
| 51 | + |
| 52 | +// ✅ Correct — use size tokens from SizeName enum |
| 53 | +Margin = new Thickness(Sizes.GetSize(SizeName.content_margin_small)); // 8 |
| 54 | +WidthRequest = Sizes.GetSize(SizeName.size_8); // 32 |
| 55 | +CornerRadius = (int)Sizes.GetSize(SizeName.radius_large); // 16 |
| 56 | +
|
| 57 | +// ❌ Wrong — magic numbers |
| 58 | +Margin = new Thickness(8); |
| 59 | +WidthRequest = 32; |
| 60 | +CornerRadius = 16; |
| 61 | +``` |
| 62 | + |
| 63 | +Key size token groups: |
| 64 | +| Purpose | Tokens | Values | |
| 65 | +|---------|--------|--------| |
| 66 | +| Base sizes | `size_1` to `size_25` | 4px increments (4–100) | |
| 67 | +| Small fractions | `size_half` | 2 | |
| 68 | +| Content padding/margins | `content_margin_xsmall` to `content_margin_xlarge` | 4, 8, 12, 20, 28 | |
| 69 | +| Page margins | `page_margin_xsmall` to `page_margin_xlarge` | 12, 16, 24, 32 | |
| 70 | +| Corner radius | `radius_xsmall` to `radius_xlarge` | 4, 8, 12, 16, 32 | |
| 71 | +| Strokes | `stroke_small` to `stroke_xlarge` | 0.5, 1, 2, 5 | |
| 72 | + |
| 73 | +### 3. Label Styles — Never Set FontSize/FontFamily Manually |
| 74 | + |
| 75 | +```csharp |
| 76 | +using DIPS.Mobile.UI.Resources.Styles; |
| 77 | +using DIPS.Mobile.UI.Resources.Styles.Label; |
| 78 | + |
| 79 | +// ✅ Correct — use label styles |
| 80 | +label.Style = Styles.GetLabelStyle(LabelStyle.UI200); |
| 81 | + |
| 82 | +// ❌ Wrong — manual font properties |
| 83 | +label.FontSize = 14; |
| 84 | +label.FontFamily = "UI"; |
| 85 | +``` |
| 86 | + |
| 87 | +Available label styles: |
| 88 | +| Style | Font Family | Font Size | |
| 89 | +|-------|-------------|-----------| |
| 90 | +| `UI100` | UI | 12 | |
| 91 | +| `UI200` | UI | 14 | |
| 92 | +| `UI300` | UI | 16 | |
| 93 | +| `UI400` | UI | 18 | |
| 94 | +| `Body100` | Body | 12 | |
| 95 | +| `Body200` | Body | 14 | |
| 96 | +| `Body300` | Body | 16 | |
| 97 | +| `Body400` | Body | 18 | |
| 98 | +| `SectionHeader` | UI | 18 | |
| 99 | +| `Header500`–`Header1000` | Header | 20–64 | |
| 100 | + |
| 101 | +**Never** set `WidthRequest`/`HeightRequest` on labels — let them size naturally. |
| 102 | + |
| 103 | +### 4. Button Styles |
| 104 | + |
| 105 | +```csharp |
| 106 | +using DIPS.Mobile.UI.Resources.Styles; |
| 107 | +using DIPS.Mobile.UI.Resources.Styles.Button; |
| 108 | + |
| 109 | +// ✅ Standard buttons |
| 110 | +button.Style = Styles.GetButtonStyle(ButtonStyle.DefaultSmall); |
| 111 | + |
| 112 | +// ✅ Close/dismiss buttons |
| 113 | +closeButton.Style = Styles.GetButtonStyle(ButtonStyle.CloseIconSmall); |
| 114 | +``` |
| 115 | + |
| 116 | +Available: `DefaultLarge/Small`, `CallToActionLarge/Small`, `GhostLarge/Small`, `CloseIconSmall`, `DefaultIconSmall/Large`, `GhostIconSmall/Large`, `CallToActionIconSmall/Large`, `DefaultFloatingIconLarge/Large`. |
| 117 | + |
| 118 | +### 5. Corner Radius — Use Layout Effect, Not Border |
| 119 | + |
| 120 | +```csharp |
| 121 | +using LayoutEffect = DIPS.Mobile.UI.Effects.Layout.Layout; |
| 122 | + |
| 123 | +// ✅ Correct — Layout effect with radius token |
| 124 | +var container = new Grid { BackgroundColor = Colors.GetColor(ColorName.color_surface_default) }; |
| 125 | +LayoutEffect.SetCornerRadius(container, new CornerRadius(Sizes.GetSize(SizeName.radius_large))); |
| 126 | + |
| 127 | +// ❌ Wrong — Border wrapper with StrokeShape |
| 128 | +var border = new Border |
| 129 | +{ |
| 130 | + StrokeShape = new RoundRectangle { CornerRadius = 16 }, |
| 131 | + Content = container |
| 132 | +}; |
| 133 | +``` |
| 134 | + |
| 135 | +**Important**: Inside classes extending `VisualElement` (e.g., `Grid`, `ContentView`), `Layout` resolves to the `VisualElement.Layout(Rect)` method. Use a `using` alias: |
| 136 | + |
| 137 | +```csharp |
| 138 | +using LayoutEffect = DIPS.Mobile.UI.Effects.Layout.Layout; |
| 139 | + |
| 140 | +// Then use: |
| 141 | +LayoutEffect.SetCornerRadius(view, new CornerRadius(Sizes.GetSize(SizeName.radius_medium))); |
| 142 | +``` |
| 143 | + |
| 144 | +### 6. Font Families |
| 145 | + |
| 146 | +Only three valid font families: `"Body"`, `"UI"`, `"Header"`. |
| 147 | + |
| 148 | +**Never** use `"monospace"` or system fonts. |
| 149 | + |
| 150 | +Prefer label styles over manual `FontFamily` assignment. Manual `FontFamily` is acceptable on `Button` when no matching `ButtonStyle` exists. |
| 151 | + |
| 152 | +## Verification Checklist |
| 153 | + |
| 154 | +Before finishing, verify: |
| 155 | +- [ ] No hardcoded hex colors — all use `Colors.GetColor(ColorName.*)` |
| 156 | +- [ ] No hardcoded pixel values for spacing/sizing — all use `Sizes.GetSize(SizeName.*)` |
| 157 | +- [ ] No manual `FontSize`/`FontFamily` on labels — all use `Styles.GetLabelStyle()` |
| 158 | +- [ ] No `Border` used purely for corner radius — use `LayoutEffect.SetCornerRadius()` |
| 159 | +- [ ] No `Shadow` on views — it causes platform-specific issues (Android elevation shadows) |
| 160 | +- [ ] Color/size names verified against `ColorName.cs` / `SizeName.cs` |
0 commit comments