|
| 1 | +# 29. CSS Spacing Variable Convention |
| 2 | + |
| 3 | +**Date:** 2025-02-07 |
| 4 | +**Status:** Accepted |
| 5 | + |
| 6 | +## Context |
| 7 | + |
| 8 | +### Background |
| 9 | + |
| 10 | +Spacing values across the application are currently inconsistent and do not follow a standardised convention. |
| 11 | + |
| 12 | +### Problem |
| 13 | + |
| 14 | +The lack of a consistent spacing convention results in: |
| 15 | + |
| 16 | +- Inconsistencies in user experience and visual design. |
| 17 | +- Increased maintenance overhead when adjusting spacing. |
| 18 | +- Difficulty in making layout changes efficiently. |
| 19 | + |
| 20 | +### Goals |
| 21 | + |
| 22 | +- Standardise spacing values across the Find Case Law front-end. |
| 23 | +- Reduce maintenance effort when updating spacing. |
| 24 | +- Provide a clear convention to enable faster development and modifications. |
| 25 | + |
| 26 | +## Options Considered |
| 27 | + |
| 28 | +1. **Use SCSS functions** – Generate spacing values dynamically based on a base size (e.g., `calc(base-size * 1.5)`). |
| 29 | +2. **Use named size variables** – Define a static set of variables (`xs`, `sm`, `lg`, `xl`) based on relative size. |
| 30 | +3. **Use numerical naming convention** – Define a static set of variables using a numbered scale (`space-1`, `space-2`, etc.). |
| 31 | +4. **Use variables that mimic values** – Define variables where the name directly reflects the value (e.g., `space-1` equals `1rem`). |
| 32 | + |
| 33 | +## Decision |
| 34 | + |
| 35 | +### Solution |
| 36 | + |
| 37 | +Adopt a static set of variables following a numerical naming convention (e.g., `space-1`, `space-2`, etc.). |
| 38 | + |
| 39 | +### Justification |
| 40 | + |
| 41 | +- SCSS functions add unnecessary cognitive complexity, as the output is not immediately clear when reading the SCSS. |
| 42 | +- Named size variables (e.g., `xs`, `sm`, `lg`) lack clear relationships between values, making it harder to determine spacing hierarchy. |
| 43 | +- Variables that mimic their values directly (e.g., `space-1 = 1rem`) create unnecessary maintenance overhead, as renaming would be required if values change. |
| 44 | +- A numerical naming convention provides: |
| 45 | + - **Consistency** – Ensures predictable spacing across the application. |
| 46 | + - **Maintainability** – Values can be adjusted without renaming variables. |
| 47 | + - **Clarity** – Developers can easily compare spacing values in relation to each other. |
| 48 | + |
| 49 | +## Consequences |
| 50 | + |
| 51 | +- **Consistent user experience** – Spacing will be uniform across the website. |
| 52 | +- **Simplified development** – A clear convention reduces ambiguity and speeds up implementation. |
| 53 | +- **Easier maintenance** – Updating spacing values will not require renaming variables. |
0 commit comments