Skip to content

Commit 2d508c8

Browse files
showerbeehsinghbisht-sfdc
authored andcommitted
@W-21965936@ Add applying and validating SLDS skills to afv-library (#187)
* feat: add SLDS applying and auditing quality skills Two new skills for SLDS v2 compliance: - applying-slds: guides artifact selection, styling hooks, utilities, icons - auditing-slds-quality: scored quality audit with linter + static analysis Made-with: Cursor * refactor: rename auditing-slds-quality skill to validating-slds Renames the skill directory and updates all references in applying-slds/SKILL.md and applying-slds/checklists.md. Made-with: Cursor * fix: improve accuracy and add manual review gate across SLDS skills Correct hook families, badge modifiers, and severity levels; add a manual review gate to validating-slds so automated grades alone cannot declare production readiness; make analyze-quality.cjs portable with explicit --hooks-index flag; remove dead parseYaml code; add version field to all three skill frontmatters. Made-with: Cursor * chore: retrigger CI Made-with: Cursor * fix: quote YAML descriptions and improve color hook disambiguation - Quote description frontmatter in all three skills for valid YAML (inner double quotes now escaped) - Strengthen Step 4 directive: MUST read color-hooks guide before choosing a hook — linter suggestions are unranked - Add surface vs surface-container disambiguation table - Add accent hook context table and state progression - Add standalone-component exception for surface classification - Add modal background example to examples.md - Remove redundant brand-button example (covered by new context table) Made-with: Cursor
1 parent 73db45c commit 2d508c8

158 files changed

Lines changed: 92555 additions & 18 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

skills/applying-slds/SKILL.md

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
---
2+
name: applying-slds
3+
version: "1.0.0"
4+
description: "Apply SLDS-compliant UI using the correct blueprints, styling hooks, utility classes, and icons. Use when building any UI that needs SLDS, choosing between Lightning Base Components and SLDS Blueprints, applying styling hooks for theming, using utility classes for layout and spacing, or selecting icons. Triggers include \"build a modal\", \"create a form\", \"data table\", \"SLDS styling\", \"style with hooks\", \"add an icon\"."
5+
---
6+
7+
# Applying SLDS
8+
9+
The **Salesforce Lightning Design System (SLDS)** is a CSS framework with thousands of artifacts. This skill teaches agents how to find and correctly use them.
10+
11+
> **Version:** This skill targets **SLDS v2**. Legacy `--lwc-*` tokens and `slds-*--modifier` syntax are deprecated.
12+
>
13+
> **Audit scope:** The companion `validating-slds` skill analyzer only scans `.css`, `.html`, and `.js` files. Use it directly for LWC and similar HTML/CSS/JS components; treat it as a partial signal for JSX/TSX or other framework-specific template formats and supplement with manual review.
14+
15+
## What is SLDS?
16+
17+
| Artifact | Count | Description |
18+
|----------|-------|-------------|
19+
| **Lightning Base Components** | ~70 | Pre-built LWC components (LWC only) |
20+
| **SLDS Blueprints** | 85 | CSS/HTML patterns for any framework |
21+
| **Styling Hooks** | 523 | CSS custom properties (`--slds-g-*`) for theming |
22+
| **Utility Classes** | 1,147 | Rapid styling classes for spacing, layout, visibility |
23+
| **Icons** | 1,732 | SVG icons across 5 categories |
24+
25+
---
26+
27+
## Scope
28+
29+
**This skill covers:**
30+
- Which blueprint to use for a given UI pattern
31+
- How to style with hooks (color, spacing, typography, shadows, borders)
32+
- Which utility classes to use for layout, spacing, visibility
33+
- Which icon to use and from which category
34+
- SLDS naming conventions, class structure, hook syntax
35+
36+
**This skill includes basic accessibility reminders** (icon alt text, focus outlines, color-not-sole-indicator) in the validation checklists. Full WCAG compliance requires a dedicated accessibility review.
37+
38+
**This skill does NOT cover (use companion skills):**
39+
- **Design decisions** -- visual hierarchy, composition, interaction patterns
40+
- **LWC mechanics** -- component structure, @wire, @api, lifecycle, events (not yet available)
41+
- **Full accessibility** -- WCAG conformance, ARIA patterns, keyboard navigation, focus management, contrast ratios (not yet available)
42+
43+
---
44+
45+
## Component Selection Hierarchy
46+
47+
Always follow this order:
48+
49+
```
50+
1. Lightning Base Components (LWC only) ← Check first
51+
2. SLDS Blueprints (any framework) ← Use exact SLDS classes
52+
3. Custom with Styling Hooks ← Use var(--slds-g-*)
53+
4. Custom CSS (last resort) ← Still use hooks for values
54+
```
55+
56+
If building in LWC, check for an LBC first: [Lightning Component Library](https://developer.salesforce.com/docs/component-library/overview/components)
57+
58+
If no LBC exists (or not using LWC), select an SLDS Blueprint. See [references/component-selection.md](references/component-selection.md).
59+
60+
---
61+
62+
## Core Rules
63+
64+
### Do
65+
66+
- Follow the selection hierarchy: LBC > Blueprint > Hooks > Custom CSS
67+
- Use `var(--slds-g-*, fallback)` for all themeable values
68+
- Create custom classes (`my-*`, `c-*`) instead of overriding `.slds-*`
69+
- **Verify every hook, class, and utility exists before using it** — run the search scripts; never assume an artifact exists based on naming patterns (see [Verify Before You Use](#verify-before-you-use))
70+
- Pair surface colors with on-surface colors for text
71+
- Provide `alternative-text` on every `<lightning-icon>`
72+
73+
### Don't
74+
75+
- Hard-code colors, spacing, or typography values
76+
- Override `.slds-*` classes directly
77+
- Use deprecated `--lwc-*` tokens as primary values
78+
- Use `--slds-s-*` (shared) hooks -- they are private/internal
79+
- Reassign hook values -- only reference them with `var()`
80+
- Use color alone to convey meaning
81+
- Invent hook names by interpolating patterns from other families (see Naming Traps below)
82+
83+
---
84+
85+
## Hook Naming Traps
86+
87+
SLDS hook families do NOT all follow the same naming pattern. Agents frequently invent hooks that don't exist by assuming `{prefix}-{number}` works universally. **Always verify a hook exists** via the bundled `search-hooks.cjs` script or `metadata/hooks-index.json` before using it.
88+
89+
### Trap 1: Font size hooks are NOT numbered
90+
91+
| Wrong (does not exist) | Correct | Notes |
92+
|------------------------|---------|-------|
93+
| `--slds-g-font-size-3` | `--slds-g-font-scale-1` | Font sizes use `font-scale-*`, not `font-size-*` |
94+
| `--slds-g-font-size-4` | `--slds-g-font-scale-2` | Only `--slds-g-font-size-base` exists (base size) |
95+
| `--slds-g-font-size-8` | `--slds-g-font-scale-6` | Scale goes: neg-4 through 10 |
96+
97+
**Rule:** For font sizes, use `--slds-g-font-size-base` (the one base size) or `--slds-g-font-scale-*` (the numbered scale). Never `--slds-g-font-size-N`.
98+
99+
### Trap 2: Color hooks always require a number
100+
101+
| Wrong (does not exist) | Correct | Notes |
102+
|------------------------|---------|-------|
103+
| `--slds-g-color-on-surface` | `--slds-g-color-on-surface-2` | All color hooks need a number |
104+
| `--slds-g-color-on-accent` | `--slds-g-color-on-accent-1` | Pick 1/2/3 by emphasis level |
105+
| `--slds-g-color-surface` | `--slds-g-color-surface-1` | No unnumbered base form |
106+
107+
**Rule:** Every `--slds-g-color-*` hook ends in a number. Pick by emphasis: `-1` (low), `-2` (medium), `-3` (high).
108+
109+
### Trap 3: Not all values have hook equivalents
110+
111+
Some CSS values (e.g., `min-width: 7rem` for label alignment) have no SLDS hook. This is acceptable:
112+
113+
```css
114+
.c-field-label {
115+
/* No SLDS hook exists for this width; intentional custom value */
116+
min-width: 7rem;
117+
}
118+
```
119+
120+
**Rule:** When no hook exists, use the value directly with a comment explaining it's intentional. Prefer SLDS grid utilities (`slds-size_*`) as alternatives to hardcoded widths where possible.
121+
122+
---
123+
124+
## Verify Before You Use
125+
126+
> **Rule:** Never include an SLDS hook, utility class, blueprint class, or icon in generated code without first confirming it exists in the metadata. Guessing based on naming patterns is the primary source of invented artifacts.
127+
128+
Run the appropriate search command **before** emitting any SLDS artifact:
129+
130+
| Artifact | Verification command | Source of truth |
131+
|----------|---------------------|-----------------|
132+
| Styling hook (`--slds-g-*`) | `node scripts/search-hooks.cjs --prefix "<hook-name>"` | `metadata/hooks-index.json` |
133+
| Utility class (`slds-*`) | `node scripts/search-utilities.cjs --search "<class-name>"` | `metadata/utilities-index.json` |
134+
| Blueprint / CSS class | `node scripts/search-blueprints.cjs --search "<pattern>"` then read the YAML | `metadata/blueprints/components/*.yaml` |
135+
| Icon | `node scripts/search-icons.cjs --query "<description>"` | `metadata/icon-metadata.json` |
136+
137+
If the search returns no match: **do not use the artifact.** Find an alternative from the search results or build custom with verified hooks.
138+
139+
---
140+
141+
## Naming Conventions
142+
143+
Use a consistent prefix for custom classes to avoid collision with SLDS:
144+
145+
| Pattern | Use Case | Example |
146+
|---------|----------|---------|
147+
| `my-*` | General custom styling | `my-card-header` |
148+
| `c-*` | LWC component-specific | `c-accountList-row` |
149+
| `[namespace]-*` | Package/app namespace | `acme-dashboard-widget` |
150+
151+
**Avoid:** generic names (`container`, `wrapper`), SLDS-like names (`custom-slds-button`), BEM on SLDS classes (`slds-card__custom-header`).
152+
153+
Custom hook namespacing:
154+
```css
155+
:root {
156+
--my-app-primary: var(--slds-g-color-accent-1);
157+
--my-app-card-padding: var(--slds-g-spacing-4);
158+
}
159+
```
160+
161+
---
162+
163+
## Knowledge Map
164+
165+
This skill bundles comprehensive SLDS knowledge. Read files as needed -- don't read everything upfront.
166+
167+
### Decision Guides (start here for each task)
168+
169+
| File | Read when |
170+
|------|-----------|
171+
| [references/component-selection.md](references/component-selection.md) | Choosing a component or blueprint |
172+
| [references/styling-decision-guide.md](references/styling-decision-guide.md) | Applying colors, spacing, typography, shadows |
173+
| [references/icons-decision-guide.md](references/icons-decision-guide.md) | Selecting or implementing an icon |
174+
| [references/utilities-quick-ref.md](references/utilities-quick-ref.md) | Using utility classes for layout/spacing |
175+
176+
### Search Scripts (find specific artifacts)
177+
178+
| Script | What it searches | Example |
179+
|--------|-----------------|---------|
180+
| `scripts/search-blueprints.cjs` | 85 blueprint YAMLs | `--search "dialog"` |
181+
| `scripts/search-hooks.cjs` | 523 styling hooks | `--prefix "--slds-g-color-accent-"` |
182+
| `scripts/search-icons.cjs` | 1,732 icons with synonyms | `--query "save button"` |
183+
| `scripts/search-utilities.cjs` | 1,147 utility classes | `--category "grid"` |
184+
185+
### Deep-Dive Guidance (read for detailed rules)
186+
187+
| Folder | Content | Index |
188+
|--------|---------|-------|
189+
| `guidance/overviews/` | Foundational concepts (color, spacing, typography, etc.) | [guidance/README.md](guidance/README.md) |
190+
| `guidance/styling-hooks/` | Hook categories with detailed usage | [guidance/README.md](guidance/README.md) |
191+
| `guidance/utilities/` | 27 utility class categories | [guidance/README.md](guidance/README.md) |
192+
| `guidance/slds-development-guide.md` | Full SLDS development guide | -- |
193+
194+
### Raw Metadata (structured data for lookup)
195+
196+
> **Do not read metadata JSON files directly** — they are too large for agent context (hooks-index.json is 6,000+ lines; icon-metadata.json is 38,000+ lines). Use the search scripts above to query them.
197+
198+
| File | Content | Lines |
199+
|------|---------|-------|
200+
| `metadata/blueprints/components/*.yaml` | 85 blueprint specs (classes, variants, a11y, HTML) | ~50-200 each |
201+
| `metadata/hooks-index.json` | 523 hooks with values and CSS properties | ~6,300 |
202+
| `metadata/icon-metadata.json` | 1,732 icons with synonyms for search | ~38,500 |
203+
| `metadata/utilities-index.json` | 1,147 utility classes with CSS rules | ~6,900 |
204+
205+
---
206+
207+
## Authoring Workflow
208+
209+
### Phase 1: Understand the Need
210+
211+
Identify:
212+
- What UI pattern is needed? (form, table, modal, card, etc.)
213+
- What framework? (LWC, React, Vue, Angular, vanilla)
214+
- What data will it display?
215+
- What states does it need? (loading, empty, error, success)
216+
217+
### Phase 2: Select the Artifact
218+
219+
1. **If LWC**: Check the [Lightning Component Library](https://developer.salesforce.com/docs/component-library/overview/components) for an LBC
220+
2. **Search blueprints**: `node scripts/search-blueprints.cjs --search "<pattern>"`
221+
3. **Read the blueprint YAML**: `metadata/blueprints/components/<name>.yaml` for exact classes, modifiers, states, and accessibility requirements
222+
4. **No match?** Build custom with hooks (see Phase 3)
223+
224+
Details: [references/component-selection.md](references/component-selection.md)
225+
226+
### Phase 3: Apply Styling
227+
228+
1. **Read**: [references/styling-decision-guide.md](references/styling-decision-guide.md)
229+
2. **Colors**: Classify role (surface, accent, feedback, border) then pick hook
230+
3. **Spacing**: Use utility classes (`slds-p-*`, `slds-m-*`) or hooks (`--slds-g-spacing-*`)
231+
4. **Layout**: Use grid utilities (`slds-grid`, `slds-col`, `slds-size_*`)
232+
5. **Custom CSS**: Use `var(--slds-g-*, fallback)`, custom class prefixes only
233+
234+
### Phase 4: Add Icons
235+
236+
1. **Read**: [references/icons-decision-guide.md](references/icons-decision-guide.md)
237+
2. **Search**: `node scripts/search-icons.cjs --query "<description>"`
238+
3. **In LWC**: Use `<lightning-icon>` with `alternative-text`
239+
4. **In non-LWC**: Use SVG with `slds-icon` classes and `slds-assistive-text`
240+
241+
### Phase 5: Validate (Mandatory — Do Not Skip)
242+
243+
**Step 1: Run the SLDS linter.** This is required. Zero violations is the target.
244+
245+
```bash
246+
npx @salesforce-ux/slds-linter@latest lint <component-path>
247+
```
248+
249+
The linter catches hardcoded values, class overrides, and deprecated tokens. **Fix all violations before proceeding.** Do not rationalize violations as acceptable.
250+
251+
**Step 2: Verify no invented hooks.** Confirm every `--slds-g-*` hook in the output exists in `metadata/hooks-index.json`. Cross-reference against the T051 check in [checklists.md](checklists.md).
252+
253+
**Step 3: Run through [checklists.md](checklists.md)** for the checks the linter cannot automate:
254+
- All `var(--slds-g-*)` have fallback values (T002)
255+
- Surface/accent/feedback color hooks are properly paired (T010–T013)
256+
- Spacing uses hooks or utility classes — no magic `px` values (T020–T021)
257+
- Font sizes use `--slds-g-font-scale-*`, not `--slds-g-font-size-N` (T031)
258+
- All icons have accessibility text (A004)
259+
- Custom classes use `my-*` or `c-*` prefix (Q010)
260+
261+
**Step 4 (optional): Run the full quality audit** using the `validating-slds` skill for a scored report before code review or deployment. Use it directly for LWC / HTML-CSS-JS components; for JSX/TSX outputs, treat the result as partial coverage only. Target a B grade (≥80) or higher before marking work complete.
262+
263+
---
264+
265+
## Quick Reference
266+
267+
### Common Hook Patterns
268+
269+
```css
270+
/* Surface + text pairing (always use numbered variants) */
271+
background: var(--slds-g-color-surface-1, #ffffff);
272+
color: var(--slds-g-color-on-surface-2, #181818);
273+
274+
/* Standard padding */
275+
padding: var(--slds-g-spacing-4, 1rem);
276+
277+
/* Card-like container */
278+
border-radius: var(--slds-g-radius-border-2, 0.25rem);
279+
box-shadow: var(--slds-g-shadow-1, 0 2px 4px rgba(0,0,0,0.1));
280+
281+
/* Accent for primary actions */
282+
background: var(--slds-g-color-accent-1, #0176d3);
283+
color: var(--slds-g-color-on-accent-1, #ffffff);
284+
285+
/* Typography -- use font-scale-*, NOT font-size-* (only font-size-base exists) */
286+
font-size: var(--slds-g-font-scale-2, 0.875rem);
287+
```
288+
289+
### Common Utility Patterns
290+
291+
```html
292+
<!-- Responsive grid -->
293+
<div class="slds-grid slds-wrap slds-gutters">
294+
<div class="slds-col slds-size_1-of-1 slds-medium-size_1-of-2">...</div>
295+
</div>
296+
297+
<!-- Spacing -->
298+
<div class="slds-p-around_medium slds-m-bottom_small">...</div>
299+
300+
<!-- Truncation -->
301+
<p class="slds-truncate" title="Full text here">Full text here</p>
302+
```
303+
304+
---
305+
306+
## Examples
307+
308+
See [examples.md](examples.md) for worked examples demonstrating the full workflow from intent to SLDS artifact selection.
309+
310+
## Validation
311+
312+
See [checklists.md](checklists.md) for validation checklists aligned with the validating-slds skill.
313+
314+
## Resources
315+
316+
| Resource | URL |
317+
|----------|-----|
318+
| SLDS Website | https://www.lightningdesignsystem.com/ |
319+
| Lightning Component Library | https://developer.salesforce.com/docs/component-library/overview/components |
320+
| SLDS Linter | https://developer.salesforce.com/docs/platform/slds-linter/guide |
321+
| Styling Hooks Reference | https://www.lightningdesignsystem.com/2e1ef8501/p/591960-global-styling-hooks |

0 commit comments

Comments
 (0)