@canonical/code-standards 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/workflows/ci.yml +40 -0
- package/biome.json +6 -0
- package/bun.lock +200 -0
- package/data/code.ttl +208 -167
- package/data/css.ttl +110 -91
- package/data/icons.ttl +186 -150
- package/data/packaging.ttl +428 -170
- package/data/react.ttl +306 -244
- package/data/rust.ttl +563 -467
- package/data/storybook.ttl +108 -90
- package/data/styling.ttl +40 -40
- package/data/tsdoc.ttl +111 -86
- package/data/turtle.ttl +89 -68
- package/definitions/CodeStandard.ttl +28 -20
- package/docs/code.md +37 -327
- package/docs/css.md +24 -20
- package/docs/icons.md +41 -42
- package/docs/index.md +2 -1
- package/docs/packaging.md +643 -0
- package/docs/react.md +58 -59
- package/docs/rust.md +92 -158
- package/docs/storybook.md +18 -20
- package/docs/styling.md +8 -8
- package/docs/tsdoc.md +16 -16
- package/docs/turtle.md +15 -15
- package/package.json +16 -2
- package/skills/add-standard/SKILL.md +83 -47
- package/src/scripts/generate-docs.ts +95 -13
- package/src/scripts/index.ts +4 -2
- package/tsconfig.json +8 -0
package/data/css.ttl
CHANGED
|
@@ -15,33 +15,36 @@ cs:CSSSelectorNamespace a cs:CodeStandard ;
|
|
|
15
15
|
cs:name "css/selectors/namespace" ;
|
|
16
16
|
cs:hasCategory cs:CSSCategory ;
|
|
17
17
|
cs:description "All component selectors must be prefixed with the `.ds` namespace (e.g., `.ds.button`)." ;
|
|
18
|
-
cs:
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
cs:do [
|
|
19
|
+
cs:description "Prefix all component selectors with `.ds`." ;
|
|
20
|
+
cs:language "css" ;
|
|
21
|
+
cs:code """
|
|
21
22
|
/* Component root with namespace */
|
|
22
23
|
.ds.button {
|
|
23
24
|
/* Base styles */
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cs:
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
"""
|
|
27
|
+
] ;
|
|
28
|
+
cs:dont [
|
|
29
|
+
cs:description "Omit the `.ds` namespace from component selectors." ;
|
|
30
|
+
cs:language "css" ;
|
|
31
|
+
cs:code """
|
|
30
32
|
/* Bad: Missing .ds namespace */
|
|
31
33
|
.button {
|
|
32
34
|
/* styles */
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
"""
|
|
37
|
+
] .
|
|
36
38
|
|
|
37
39
|
# CSS Component Encapsulation Standard
|
|
38
40
|
cs:CSSComponentEncapsulation a cs:CodeStandard ;
|
|
39
41
|
cs:name "css/component/encapsulation" ;
|
|
40
42
|
cs:hasCategory cs:CSSCategory ;
|
|
41
43
|
cs:description "Component styles must be encapsulated using the component's root class as a boundary. All internal element styles must be scoped to the component's namespace." ;
|
|
42
|
-
cs:
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
cs:do [
|
|
45
|
+
cs:description "Scope internal element styles using the component's namespace." ;
|
|
46
|
+
cs:language "css" ;
|
|
47
|
+
cs:code """
|
|
45
48
|
.ds.button {
|
|
46
49
|
/* Component root styles */
|
|
47
50
|
|
|
@@ -50,42 +53,45 @@ cs:CSSComponentEncapsulation a cs:CodeStandard ;
|
|
|
50
53
|
margin-right: var(--button-icon-spacing);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
cs:
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
"""
|
|
57
|
+
] ;
|
|
58
|
+
cs:dont [
|
|
59
|
+
cs:description "Don't style internal elements without the component namespace." ;
|
|
60
|
+
cs:language "css" ;
|
|
61
|
+
cs:code """
|
|
58
62
|
/* Bad: Internal element not scoped to component */
|
|
59
63
|
.icon {
|
|
60
64
|
margin-right: var(--button-icon-spacing);
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
"""
|
|
67
|
+
] .
|
|
64
68
|
|
|
65
69
|
# CSS State Handling Standard
|
|
66
70
|
cs:CSSStateHandling a cs:CodeStandard ;
|
|
67
71
|
cs:name "css/component/states" ;
|
|
68
72
|
cs:hasCategory cs:CSSCategory ;
|
|
69
73
|
cs:description "Component states must be handled using attribute selectors for native states and class modifiers for custom states." ;
|
|
70
|
-
cs:
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
cs:do [
|
|
75
|
+
cs:description "Use attribute selectors for native element states." ;
|
|
76
|
+
cs:language "css" ;
|
|
77
|
+
cs:code """
|
|
73
78
|
.ds.button {
|
|
74
79
|
&[disabled] {
|
|
75
80
|
opacity: var(--button-disabled-opacity);
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
cs:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
"""
|
|
84
|
+
] ;
|
|
85
|
+
cs:dont [
|
|
86
|
+
cs:description "Use class modifiers for native states." ;
|
|
87
|
+
cs:language "css" ;
|
|
88
|
+
cs:code """
|
|
83
89
|
/* Bad: Using class for native state */
|
|
84
90
|
.ds.button.disabled {
|
|
85
91
|
opacity: var(--button-disabled-opacity);
|
|
86
92
|
}
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
"""
|
|
94
|
+
] .
|
|
89
95
|
|
|
90
96
|
# CSS Specificity Management Standard
|
|
91
97
|
cs:CSSSpecificityManagement a cs:CodeStandard ;
|
|
@@ -95,111 +101,123 @@ cs:CSSSpecificityManagement a cs:CodeStandard ;
|
|
|
95
101
|
- Component root must use namespace + component name (.ds.button)
|
|
96
102
|
- Single modifier class for variants (.ds.button.primary)
|
|
97
103
|
- Single attribute for states (.ds.button[disabled])""" ;
|
|
98
|
-
cs:
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
cs:do [
|
|
105
|
+
cs:description "Use a single modifier class for component variants." ;
|
|
106
|
+
cs:language "css" ;
|
|
107
|
+
cs:code """
|
|
101
108
|
.ds.button.primary {
|
|
102
109
|
/* Variant: root + modifier (3 classes) */
|
|
103
110
|
background: var(--button-primary-background);
|
|
104
111
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
cs:
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
"""
|
|
113
|
+
] ;
|
|
114
|
+
cs:dont [
|
|
115
|
+
cs:description "Combine multiple modifiers or mix states with variants." ;
|
|
116
|
+
cs:language "css" ;
|
|
117
|
+
cs:code """
|
|
110
118
|
/* Bad: Mixing variant with state */
|
|
111
119
|
.ds.button.primary[disabled].large {
|
|
112
120
|
/* Too specific: root + 2 modifiers + state */
|
|
113
121
|
}
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
"""
|
|
123
|
+
] .
|
|
116
124
|
|
|
117
125
|
# CSS Selector Semantics Standard
|
|
118
126
|
cs:CSSSelectorSemantics a cs:CodeStandard ;
|
|
119
127
|
cs:name "css/selectors/semantics" ;
|
|
120
128
|
cs:hasCategory cs:CSSCategory ;
|
|
121
129
|
cs:description "CSS class names must describe the purpose or state of an element, not its appearance." ;
|
|
122
|
-
cs:
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
cs:do [
|
|
131
|
+
cs:description "Use semantic modifier classes to represent component variations." ;
|
|
132
|
+
cs:language "css" ;
|
|
133
|
+
cs:code """
|
|
125
134
|
/* Semantic modifier for a primary button */
|
|
126
135
|
.ds.button.primary {
|
|
127
136
|
--modifier-color: var(--color-primary);
|
|
128
137
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
cs:
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
"""
|
|
139
|
+
] ;
|
|
140
|
+
cs:dont [
|
|
141
|
+
cs:description "Use non-semantic or presentational class names." ;
|
|
142
|
+
cs:language "css" ;
|
|
143
|
+
cs:code """
|
|
134
144
|
/* Bad: 'big' describes appearance, not purpose */
|
|
135
145
|
.ds.button.big {
|
|
136
146
|
padding: 1rem;
|
|
137
147
|
}
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
"""
|
|
149
|
+
] .
|
|
140
150
|
|
|
141
151
|
# Theme Activation Standard
|
|
142
152
|
cs:ThemeActivation a cs:CodeStandard ;
|
|
143
153
|
cs:name "css/themes/activation" ;
|
|
144
154
|
cs:hasCategory cs:CSSCategory ;
|
|
145
155
|
cs:description """Theme tokens must be activated through CSS classes on container elements. See styling/themes/definition for theme token structure.""" ;
|
|
146
|
-
cs:
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
cs:do [
|
|
157
|
+
cs:description "Define semantic tokens within theme classes." ;
|
|
158
|
+
cs:language "css" ;
|
|
159
|
+
cs:code """
|
|
149
160
|
.canonical {
|
|
150
161
|
--spacing-vertical-medium: var(--spacing-unit-2x);
|
|
151
162
|
--color-background: var(--color-neutral-100);
|
|
152
163
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
cs:
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
"""
|
|
165
|
+
] ;
|
|
166
|
+
cs:dont [
|
|
167
|
+
cs:description "Hardcode theme names in component styles." ;
|
|
168
|
+
cs:language "css" ;
|
|
169
|
+
cs:code """
|
|
158
170
|
/* Bad: Component locked to specific theme */
|
|
159
171
|
.ds.button {
|
|
160
172
|
padding: var(--canonical-spacing-vertical-medium);
|
|
161
173
|
}
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
"""
|
|
175
|
+
] .
|
|
164
176
|
|
|
165
177
|
# CSS Property Values Standard
|
|
166
178
|
cs:CSSPropertyValues a cs:CodeStandard ;
|
|
167
179
|
cs:name "css/properties/values" ;
|
|
168
180
|
cs:hasCategory cs:CSSCategory ;
|
|
169
181
|
cs:description """CSS properties must use design tokens for design decisions (see styling/tokens/creation) and raw values for properties that are independent from design decisions, or "unthemable".""" ;
|
|
170
|
-
cs:
|
|
171
|
-
|
|
172
|
-
|
|
182
|
+
cs:do [
|
|
183
|
+
cs:description "Use design tokens for design decisions." ;
|
|
184
|
+
cs:language "css" ;
|
|
185
|
+
cs:code """
|
|
173
186
|
.ds.button {
|
|
174
187
|
/* Design decision uses token */
|
|
175
188
|
background: var(--button-background);
|
|
176
189
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
190
|
+
"""
|
|
191
|
+
] ;
|
|
192
|
+
cs:do [
|
|
193
|
+
cs:description "Use raw values for unthemable properties (independent of design decisions)." ;
|
|
194
|
+
cs:language "css" ;
|
|
195
|
+
cs:code """
|
|
180
196
|
.ds.skip-link {
|
|
181
197
|
visibility: hidden;
|
|
182
198
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
cs:
|
|
186
|
-
|
|
187
|
-
|
|
199
|
+
"""
|
|
200
|
+
] ;
|
|
201
|
+
cs:dont [
|
|
202
|
+
cs:description "Use raw values for design decisions." ;
|
|
203
|
+
cs:language "css" ;
|
|
204
|
+
cs:code """
|
|
188
205
|
.ds.button {
|
|
189
206
|
/* Bad: Design decision using raw value */
|
|
190
207
|
background: #0066CC;
|
|
191
208
|
}
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
"""
|
|
210
|
+
] .
|
|
194
211
|
|
|
195
212
|
# Child Element Naming Standard
|
|
196
213
|
cs:CSSChildElementNaming a cs:CodeStandard ;
|
|
197
214
|
cs:name "css/selectors/child-elements" ;
|
|
198
215
|
cs:hasCategory cs:CSSCategory ;
|
|
199
216
|
cs:description """Child elements within components must use simple, role-based class names (e.g., `.header`, `.content`, `.icon`) scoped by the parent selector, NOT verbose prefixed names that repeat the component name.""" ;
|
|
200
|
-
cs:
|
|
201
|
-
|
|
202
|
-
|
|
217
|
+
cs:do [
|
|
218
|
+
cs:description "Use simple role-based class names scoped by the parent." ;
|
|
219
|
+
cs:language "css" ;
|
|
220
|
+
cs:code """
|
|
203
221
|
.ds.accordion-item {
|
|
204
222
|
& > .header {
|
|
205
223
|
/* Header styles */
|
|
@@ -227,11 +245,12 @@ cs:CSSChildElementNaming a cs:CodeStandard ;
|
|
|
227
245
|
/* Separator styles */
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
cs:
|
|
233
|
-
|
|
234
|
-
|
|
248
|
+
"""
|
|
249
|
+
] ;
|
|
250
|
+
cs:dont [
|
|
251
|
+
cs:description "Use verbose prefixed class names that repeat the component name." ;
|
|
252
|
+
cs:language "css" ;
|
|
253
|
+
cs:code """
|
|
235
254
|
/* Bad: Redundant component prefix in child class names */
|
|
236
255
|
.ds.accordion-item .accordion-item-header {
|
|
237
256
|
/* 'accordion-item-' prefix is redundant */
|
|
@@ -244,22 +263,22 @@ cs:CSSChildElementNaming a cs:CodeStandard ;
|
|
|
244
263
|
.ds.timeline-event .timeline-event-marker {
|
|
245
264
|
/* Verbose and BEM-like */
|
|
246
265
|
}
|
|
247
|
-
|
|
248
|
-
|
|
266
|
+
"""
|
|
267
|
+
] .
|
|
249
268
|
|
|
250
269
|
# Component Naming Convention for CSS
|
|
251
270
|
cs:CSSComponentNamingConvention a cs:CodeStandard ;
|
|
252
271
|
cs:name "css/selectors/naming-convention" ;
|
|
253
272
|
cs:hasCategory cs:CSSCategory ;
|
|
254
273
|
cs:description "Component CSS class names must be the kebab-case version of the component's PascalCase name." ;
|
|
255
|
-
cs:
|
|
256
|
-
|
|
274
|
+
cs:do [
|
|
275
|
+
cs:description """Convert PascalCase component names to kebab-case for CSS classes:
|
|
257
276
|
- `MyComponent` -> `.ds.my-component`
|
|
258
277
|
- `UserProfile` -> `.ds.user-profile`
|
|
259
|
-
- `Button` -> `.ds.button`
|
|
260
|
-
|
|
261
|
-
cs:
|
|
262
|
-
|
|
278
|
+
- `Button` -> `.ds.button`"""
|
|
279
|
+
] ;
|
|
280
|
+
cs:dont [
|
|
281
|
+
cs:description """Use PascalCase or other formats in CSS class names:
|
|
263
282
|
- `.ds.MyComponent` (Bad: Not kebab-case)
|
|
264
|
-
- `.ds.user_profile` (Bad: Not kebab-case)
|
|
265
|
-
|
|
283
|
+
- `.ds.user_profile` (Bad: Not kebab-case)"""
|
|
284
|
+
] .
|