Skip to content

Commit b14da0c

Browse files
authored
Merge pull request #3 from marklearst/feat/examples-docs
docs(examples): enhance Figma export and DTCG compliant example pages
2 parents 4dc275e + 385c849 commit b14da0c

File tree

2 files changed

+430
-11
lines changed

2 files changed

+430
-11
lines changed

docs/examples/dtcg-compliant.md

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
---
2+
title: DTCG Compliant Example
3+
---
4+
5+
# DTCG Compliant Example
6+
7+
A complete DTCG 2025.10 compliant variable file demonstrating primitive types, composite types, references, modes, and group extension.
8+
9+
- Raw file: [dtcg-compliant.json](dtcg-compliant.json)
10+
11+
This file can be used as a starting point for new projects or as a reference for Variable Contract compliance. See [DTCG Alignment](/contract/dtcg-alignment) for compliance details.
12+
13+
## File overview
14+
15+
The example file includes:
16+
17+
- Primitive types: color, dimension, fontFamily, fontWeight, duration, cubicBezier
18+
- Composite types: border, transition, shadow, gradient, typography
19+
- References using curly brace syntax
20+
- Modes for light/dark theme variants
21+
- Group extension using `$ref`
22+
- Component layer demonstrating variable hierarchy
23+
24+
## Primitive types
25+
26+
Basic types with single values. See [Types](/contract/types) for complete reference.
27+
28+
```json
29+
{
30+
"color": {
31+
"base": {
32+
"primary": {
33+
"$type": "color",
34+
"$value": "#0066cc"
35+
}
36+
}
37+
},
38+
"spacing": {
39+
"base": {
40+
"medium": {
41+
"$type": "dimension",
42+
"$value": "16px"
43+
}
44+
}
45+
},
46+
"font": {
47+
"family": {
48+
"primary": {
49+
"$type": "fontFamily",
50+
"$value": "Roboto"
51+
}
52+
},
53+
"weight": {
54+
"bold": {
55+
"$type": "fontWeight",
56+
"$value": 700
57+
}
58+
}
59+
},
60+
"duration": {
61+
"fast": {
62+
"$type": "duration",
63+
"$value": "200ms"
64+
}
65+
},
66+
"easing": {
67+
"default": {
68+
"$type": "cubicBezier",
69+
"$value": [0.25, 0.1, 0.25, 1]
70+
}
71+
}
72+
}
73+
```
74+
75+
## Composite types
76+
77+
Structured types combining multiple values. See [Composite Types](/contract/composite-types) for complete reference.
78+
79+
```json
80+
{
81+
"border": {
82+
"default": {
83+
"$type": "border",
84+
"$value": {
85+
"width": { "value": 1, "unit": "px" },
86+
"color": "#e0e0e0",
87+
"style": "solid"
88+
}
89+
}
90+
},
91+
"shadow": {
92+
"small": {
93+
"$type": "shadow",
94+
"$value": {
95+
"color": "rgba(0, 0, 0, 0.1)",
96+
"offsetX": { "value": 0, "unit": "px" },
97+
"offsetY": { "value": 2, "unit": "px" },
98+
"blur": { "value": 4, "unit": "px" },
99+
"spread": { "value": 0, "unit": "px" }
100+
}
101+
}
102+
},
103+
"typography": {
104+
"heading": {
105+
"$type": "typography",
106+
"$value": {
107+
"fontFamily": "{font.family.primary}",
108+
"fontSize": "{font.size.lg}",
109+
"fontWeight": "{font.weight.bold}",
110+
"letterSpacing": { "value": 0, "unit": "px" },
111+
"lineHeight": 1.5
112+
}
113+
}
114+
}
115+
}
116+
```
117+
118+
## References
119+
120+
Variables can reference other variables using curly brace syntax. See [References](/contract/references) for resolution rules.
121+
122+
```json
123+
{
124+
"spacing": {
125+
"semantic": {
126+
"component": {
127+
"gap": {
128+
"md": {
129+
"$type": "dimension",
130+
"$value": "{spacing.base.medium}"
131+
}
132+
}
133+
}
134+
}
135+
},
136+
"transition": {
137+
"default": {
138+
"$type": "transition",
139+
"$value": {
140+
"duration": "{duration.fast}",
141+
"delay": "0ms",
142+
"timingFunction": "{easing.default}"
143+
}
144+
}
145+
}
146+
}
147+
```
148+
149+
## Modes
150+
151+
Mode objects define variants for different contexts (light/dark, mobile/desktop). See [Modes](/contract/modes) for structure rules.
152+
153+
```json
154+
{
155+
"color": {
156+
"semantic": {
157+
"text": {
158+
"primary": {
159+
"$type": "color",
160+
"$value": {
161+
"light": "{color.base.gray.900}",
162+
"dark": "{color.base.gray.100}"
163+
}
164+
}
165+
},
166+
"surface": {
167+
"default": {
168+
"$type": "color",
169+
"$value": {
170+
"light": "#ffffff",
171+
"dark": "#000000"
172+
}
173+
}
174+
}
175+
}
176+
}
177+
}
178+
```
179+
180+
Mode values can be literals or references. References resolve per-mode at build time.
181+
182+
## Group extension
183+
184+
Groups can extend other groups using `$ref`. See [Groups](/contract/groups) for extension rules.
185+
186+
```json
187+
{
188+
"color": {
189+
"semantic": {
190+
"$ref": "#/color/base",
191+
"text": {
192+
"primary": {
193+
"$type": "color",
194+
"$value": {
195+
"light": "{color.base.gray.900}",
196+
"dark": "{color.base.gray.100}"
197+
}
198+
}
199+
}
200+
}
201+
}
202+
}
203+
```
204+
205+
The `$ref` property imports all variables from the referenced group. Local definitions override inherited ones.
206+
207+
## Component layer
208+
209+
Component variables reference semantic variables, creating a consumption layer for UI components.
210+
211+
```json
212+
{
213+
"component": {
214+
"button": {
215+
"color": {
216+
"background": {
217+
"default": {
218+
"$type": "color",
219+
"$value": {
220+
"light": "{color.semantic.surface.default}",
221+
"dark": "{color.semantic.surface.default}"
222+
}
223+
}
224+
},
225+
"text": {
226+
"default": {
227+
"$type": "color",
228+
"$value": {
229+
"light": "{color.semantic.text.primary}",
230+
"dark": "{color.semantic.text.primary}"
231+
}
232+
}
233+
}
234+
},
235+
"border": {
236+
"default": {
237+
"$type": "border",
238+
"$value": "{border.default}"
239+
}
240+
}
241+
}
242+
}
243+
}
244+
```
245+
246+
This pattern creates a clear hierarchy: base → semantic → component.
247+
248+
## Failure modes
249+
250+
Invalid DTCG format causes build failures and runtime errors:
251+
252+
- **Missing `$type`**: Validators reject the variable. Build tools cannot determine output format.
253+
- **Invalid `$value` for type**: Schema validation fails. A `color` type with value `16px` is rejected.
254+
- **Broken references**: References to non-existent paths (`{does.not.exist}`) cause build failures or produce undefined CSS custom properties.
255+
- **Inconsistent mode keys**: If one variable uses `light`/`dark` and another uses `day`/`night`, mode resolution fails. All variables in a file MUST use the same mode keys.
256+
- **Circular references**: `{a}` references `{b}` which references `{a}`. Build tools detect this and fail.
257+
258+
## Out of scope
259+
260+
This example demonstrates format compliance, not:
261+
262+
- **Platform output**: CSS, SCSS, or JavaScript output. See [Adapter Pipeline](/examples/adapter-pipeline) for transformation examples.
263+
- **Tool-specific input**: Figma or Tokens Studio export formats. See [Figma Export](/examples/figma-export) for tool output.
264+
- **Multi-brand architecture**: Brand overrides and theme composition. See [Multi-brand Architecture](/patterns/multi-brand-architecture).
265+
- **Naming conventions**: Category prefixes and path structure rules. See [Naming](/contract/naming).
266+
267+
## Validation
268+
269+
Validate DTCG compliance using the JSON schema:
270+
271+
```bash
272+
npx ajv validate -s schema/v1.json -d examples/dtcg-compliant.json
273+
```
274+
275+
See [Validation](/governance/validation) for CI integration patterns.

0 commit comments

Comments
 (0)