@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.
@@ -15,9 +15,10 @@ cs:DocumentationSource a cs:CodeStandard ;
15
15
  cs:name "storybook/documentation/source" ;
16
16
  cs:hasCategory cs:StorybookCategory ;
17
17
  cs:description "Component documentation must primarily come from TSDoc comments on the component signature and props. Storybook docs overrides should only be used when the documentation needs to differ between code and Storybook contexts." ;
18
- cs:dos """
19
- (Do) Use TSDoc comments for primary documentation.
20
- ```typescript
18
+ cs:do [
19
+ cs:description "Use TSDoc comments for primary documentation." ;
20
+ cs:language "typescript" ;
21
+ cs:code """
21
22
 
22
23
  // ContextualMenu/types.ts
23
24
  export interface ContextualMenuProps extends HTMLAttributes<HTMLDivElement> {
@@ -38,11 +39,12 @@ const ContextualMenu = ({
38
39
  }: ContextualMenuProps): ReactElement => {
39
40
  // ...
40
41
  };
41
- ```
42
- """ ;
43
- cs:donts """
44
- (Don't) Add documentation in Storybook parameters when TSDoc is sufficient.
45
- ```typescript
42
+ """
43
+ ] ;
44
+ cs:dont [
45
+ cs:description "Add documentation in Storybook parameters when TSDoc is sufficient." ;
46
+ cs:language "typescript" ;
47
+ cs:code """
46
48
  export const Default: Story = {
47
49
  parameters: {
48
50
  docs: {
@@ -52,17 +54,18 @@ export const Default: Story = {
52
54
  }
53
55
  }
54
56
  };
55
- ```
56
- """ .
57
+ """
58
+ ] .
57
59
 
58
60
  # Story Visibility Standard
59
61
  cs:StoryVisibility a cs:CodeStandard ;
60
62
  cs:name "storybook/story/visibility" ;
61
63
  cs:hasCategory cs:StorybookCategory ;
62
64
  cs:description "Stories that exist solely for testing or visual coverage but don't represent valid usage patterns must be hidden from documentation and the sidebar using tags." ;
63
- cs:dos """
64
- (Do) Hide test-only stories that don't represent valid usage.
65
- ```typescript
65
+ cs:do [
66
+ cs:description "Hide test-only stories that don't represent valid usage." ;
67
+ cs:language "typescript" ;
68
+ cs:code """
66
69
  export const FocusedState: Story = {
67
70
  args: {
68
71
  isOpen: true,
@@ -74,11 +77,12 @@ export const FocusedState: Story = {
74
77
  element.focus();
75
78
  }
76
79
  };
77
- ```
78
- """ ;
79
- cs:donts """
80
- (Don't) Show implementation details or test states in documentation.
81
- ```typescript
80
+ """
81
+ ] ;
82
+ cs:dont [
83
+ cs:description "Show implementation details or test states in documentation." ;
84
+ cs:language "typescript" ;
85
+ cs:code """
82
86
  export const InternalTestState: Story = {
83
87
  args: {
84
88
  _internalProp: true, // Bad: Exposing internal state
@@ -90,8 +94,8 @@ export const InternalTestState: Story = {
90
94
  }
91
95
  }
92
96
  };
93
- ```
94
- """ .
97
+ """
98
+ ] .
95
99
 
96
100
  # Story Format Standard
97
101
  cs:StoryFormat a cs:CodeStandard ;
@@ -101,9 +105,10 @@ cs:StoryFormat a cs:CodeStandard ;
101
105
  1. CSF3 (object-based) format must be used for standard component variations where args define the component state.
102
106
  2. Function-based format must be used when the story needs to directly control component rendering or wrap the component with custom elements.
103
107
  3. Template-based format must be used when multiple stories share the same logic but differ in their args, and the template differs from the component markup.""" ;
104
- cs:dos """
105
- (Do) Use the format that matches your specific use case.
106
- ```typescript
108
+ cs:do [
109
+ cs:description "Use the format that matches your specific use case." ;
110
+ cs:language "typescript" ;
111
+ cs:code """
107
112
  // CSF3: For standard component variations through args
108
113
  type Story = StoryObj<typeof meta>;
109
114
 
@@ -137,11 +142,12 @@ const Template: StoryFn<typeof Component> = (args) => (
137
142
 
138
143
  export const Primary = Template.bind({});
139
144
  Primary.args = { variant: "primary" };
140
- ```
141
- """ ;
142
- cs:donts """
143
- (Don't) Use a format that doesn't match your use case.
144
- ```typescript
145
+ """
146
+ ] ;
147
+ cs:dont [
148
+ cs:description "Use a format that doesn't match your use case." ;
149
+ cs:language "typescript" ;
150
+ cs:code """
145
151
  // Bad: Using function format for simple args variation
146
152
  export const SimpleButton = () => (
147
153
  <Component variant="primary" disabled={false}>
@@ -158,17 +164,18 @@ export const First: Story = {
158
164
  </div>
159
165
  )]
160
166
  };
161
- ```
162
- """ .
167
+ """
168
+ ] .
163
169
 
164
170
  # Story Decorator Standard
165
171
  cs:StoryDecorator a cs:CodeStandard ;
166
172
  cs:name "storybook/story/decorator" ;
167
173
  cs:hasCategory cs:StorybookCategory ;
168
174
  cs:description "Decorators must be used to wrap stories in common context providers or layout elements. Decorators should generally be defined in `storybook/decorators.tsx` and be imported as `decorators` in the storybook file. Decorators may be defined inline in story files in limited circumstances when it would be difficult to globally define a semantic decorator (e.g., a decorator that provides mock data specific to that component)." ;
169
- cs:dos """
170
- (Do) Use decorators for static context or layout wrapping.
171
- ```typescript
175
+ cs:do [
176
+ cs:description "Use decorators for static context or layout wrapping." ;
177
+ cs:language "typescript" ;
178
+ cs:code """
172
179
 
173
180
  // storybook/decorators.tsx
174
181
 
@@ -200,28 +207,30 @@ const meta = {
200
207
  } satisfies Meta<typeof Component>;
201
208
 
202
209
  export default meta;
203
- ```
204
- """ ;
205
- cs:donts """
206
- (Don't) Use function-based stories for static wrapping that could be done with decorators.
207
- ```typescript
210
+ """
211
+ ] ;
212
+ cs:dont [
213
+ cs:description "Use function-based stories for static wrapping that could be done with decorators." ;
214
+ cs:language "typescript" ;
215
+ cs:code """
208
216
  // Bad: Using function-based story for static wrapping
209
217
  export const WithTheme = (args: ComponentProps) => (
210
218
  <ThemeProvider theme="dark">
211
219
  <Component {...args} />
212
220
  </ThemeProvider>
213
221
  );
214
- ```
215
- """ .
222
+ """
223
+ ] .
216
224
 
217
225
  # Story Import Standard
218
226
  cs:StoryImport a cs:CodeStandard ;
219
227
  cs:name "storybook/story/import" ;
220
228
  cs:hasCategory cs:StorybookCategory ;
221
229
  cs:description "Stories must import their component as 'Component' to maintain a consistent, generic reference that is decoupled from the specific component name." ;
222
- cs:dos """
223
- (Do) Import the component generically as 'Component'.
224
- ```typescript
230
+ cs:do [
231
+ cs:description "Import the component generically as 'Component'." ;
232
+ cs:language "typescript" ;
233
+ cs:code """
225
234
  import Component from "./SkipLink.js";
226
235
 
227
236
  const meta = {
@@ -234,28 +243,30 @@ export const Default: Story = {
234
243
  children: "Skip to main content"
235
244
  }
236
245
  };
237
- ```
238
- """ ;
239
- cs:donts """
240
- (Don't) Import the component using its specific name.
241
- ```typescript
246
+ """
247
+ ] ;
248
+ cs:dont [
249
+ cs:description "Import the component using its specific name." ;
250
+ cs:language "typescript" ;
251
+ cs:code """
242
252
  import SkipLink from "./SkipLink.js";
243
253
 
244
254
  const meta = {
245
255
  title: "SkipLink",
246
256
  component: SkipLink, // Bad: Using specific component name
247
257
  } satisfies Meta<typeof SkipLink>;
248
- ```
249
- """ .
258
+ """
259
+ ] .
250
260
 
251
261
  # Story Organization Standard
252
262
  cs:StoryOrganization a cs:CodeStandard ;
253
263
  cs:name "storybook/story/organization" ;
254
264
  cs:hasCategory cs:StorybookCategory ;
255
265
  cs:description "Stories must be organized into logical groups that demonstrate related features and variations. Each story should focus on a specific use case or feature, with clear naming that indicates what aspect of the component it demonstrates." ;
256
- cs:dos """
257
- (Do) Group related features with clear, descriptive names.
258
- ```typescript
266
+ cs:do [
267
+ cs:description "Group related features with clear, descriptive names." ;
268
+ cs:language "typescript" ;
269
+ cs:code """
259
270
  // Basic usage
260
271
  export const Default: Story = {
261
272
  args: {
@@ -279,11 +290,12 @@ export const CustomText: Story = {
279
290
  children: "Jump to content"
280
291
  }
281
292
  };
282
- ```
283
- """ ;
284
- cs:donts """
285
- (Don't) Use unclear names or mix unrelated features in a single story.
286
- ```typescript
293
+ """
294
+ ] ;
295
+ cs:dont [
296
+ cs:description "Use unclear names or mix unrelated features in a single story." ;
297
+ cs:language "typescript" ;
298
+ cs:code """
287
299
  // Bad: Unclear what this story demonstrates
288
300
  export const Variant1: Story = {
289
301
  args: {
@@ -294,17 +306,18 @@ export const Variant1: Story = {
294
306
  style: { color: "red" }
295
307
  }
296
308
  };
297
- ```
298
- """ .
309
+ """
310
+ ] .
299
311
 
300
312
  # Story Testing Standard
301
313
  cs:StoryTesting a cs:CodeStandard ;
302
314
  cs:name "storybook/story/testing" ;
303
315
  cs:hasCategory cs:StorybookCategory ;
304
316
  cs:description "Stories that test component behavior must use the `play` function to simulate user interactions and verify expected outcomes." ;
305
- cs:dos """
306
- (Do) Use play functions to test interactive behavior.
307
- ```typescript
317
+ cs:do [
318
+ cs:description "Use play functions to test interactive behavior." ;
319
+ cs:language "typescript" ;
320
+ cs:code """
308
321
  export const InteractionTest: Story = {
309
322
  args: {
310
323
  children: "Click Me",
@@ -316,28 +329,30 @@ export const InteractionTest: Story = {
316
329
  await expect(args.onClick).toHaveBeenCalled();
317
330
  }
318
331
  };
319
- ```
320
- """ ;
321
- cs:donts """
322
- (Don't) Test implementation details or internal state.
323
- ```typescript
332
+ """
333
+ ] ;
334
+ cs:dont [
335
+ cs:description "Test implementation details or internal state." ;
336
+ cs:language "typescript" ;
337
+ cs:code """
324
338
  export const InternalTest: Story = {
325
339
  play: async ({ component }) => {
326
340
  // Bad: Testing internal implementation
327
341
  expect(component._internalState).toBe(true);
328
342
  }
329
343
  };
330
- ```
331
- """ .
344
+ """
345
+ ] .
332
346
 
333
347
  # Story Documentation Standard
334
348
  cs:StoryDocumentation a cs:CodeStandard ;
335
349
  cs:name "storybook/story/documentation" ;
336
350
  cs:hasCategory cs:StorybookCategory ;
337
351
  cs:description "Story documentation must focus on usage patterns and variations, not implementation details. Each story should demonstrate a specific use case or variation." ;
338
- cs:dos """
339
- (Do) Document usage patterns and variations.
340
- ```typescript
352
+ cs:do [
353
+ cs:description "Document usage patterns and variations." ;
354
+ cs:language "typescript" ;
355
+ cs:code """
341
356
  export const WithCustomTrigger: Story = {
342
357
  args: {
343
358
  trigger: <button>Custom Trigger</button>
@@ -350,11 +365,12 @@ export const WithCustomTrigger: Story = {
350
365
  }
351
366
  }
352
367
  };
353
- ```
354
- """ ;
355
- cs:donts """
356
- (Don't) Document implementation details or internal behavior.
357
- ```typescript
368
+ """
369
+ ] ;
370
+ cs:dont [
371
+ cs:description "Document implementation details or internal behavior." ;
372
+ cs:language "typescript" ;
373
+ cs:code """
358
374
  export const Default: Story = {
359
375
  parameters: {
360
376
  docs: {
@@ -364,17 +380,18 @@ export const Default: Story = {
364
380
  }
365
381
  }
366
382
  };
367
- ```
368
- """ .
383
+ """
384
+ ] .
369
385
 
370
386
  # Story Naming Standard
371
387
  cs:StoryNaming a cs:CodeStandard ;
372
388
  cs:name "storybook/story/naming" ;
373
389
  cs:hasCategory cs:StorybookCategory ;
374
390
  cs:description "Story names must be descriptive and follow a consistent pattern. Use PascalCase for story exports and natural language for story titles." ;
375
- cs:dos """
376
- (Do) Use clear, descriptive names that indicate the variation.
377
- ```typescript
391
+ cs:do [
392
+ cs:description "Use clear, descriptive names that indicate the variation." ;
393
+ cs:language "typescript" ;
394
+ cs:code """
378
395
  export const WithCustomStyles: Story = {
379
396
  args: {
380
397
  className: "custom",
@@ -388,16 +405,17 @@ export const WithCustomStyles: Story = {
388
405
  }
389
406
  }
390
407
  };
391
- ```
392
- """ ;
393
- cs:donts """
394
- (Don't) Use technical or implementation-focused names.
395
- ```typescript
408
+ """
409
+ ] ;
410
+ cs:dont [
411
+ cs:description "Use technical or implementation-focused names." ;
412
+ cs:language "typescript" ;
413
+ cs:code """
396
414
  export const TestCase1: Story = { // Bad: Non-descriptive name
397
415
  args: {
398
416
  _testFlag: true, // Bad: Implementation detail
399
417
  children: "Content"
400
418
  }
401
419
  };
402
- ```
403
- """ .
420
+ """
421
+ ] .
package/data/styling.ttl CHANGED
@@ -18,9 +18,9 @@ cs:TokenTypes a cs:CodeStandard ;
18
18
  - Semantic tokens: Map semantic concepts to primitive token values
19
19
  - Component tokens: Map component properties to semantic token values
20
20
  """ ;
21
- cs:dos """
22
- (Do) Define semantic tokens that map to primitive tokens.
23
- ```
21
+ cs:do [
22
+ cs:description "Define semantic tokens that map to primitive tokens." ;
23
+ cs:code """
24
24
  {
25
25
  "color": {
26
26
  "background": {
@@ -31,11 +31,11 @@ cs:TokenTypes a cs:CodeStandard ;
31
31
  }
32
32
  }
33
33
  }
34
- ```
35
- """ ;
36
- cs:donts """
37
- (Don't) Skip the semantic layer by mapping component tokens directly to primitives.
38
- ```
34
+ """
35
+ ] ;
36
+ cs:dont [
37
+ cs:description "Skip the semantic layer by mapping component tokens directly to primitives." ;
38
+ cs:code """
39
39
  {
40
40
  "button": {
41
41
  "padding": {
@@ -46,17 +46,17 @@ cs:TokenTypes a cs:CodeStandard ;
46
46
  }
47
47
  }
48
48
  }
49
- ```
50
- """ .
49
+ """
50
+ ] .
51
51
 
52
52
  # Design Token Creation Standard
53
53
  cs:DesignTokenCreation a cs:CodeStandard ;
54
54
  cs:name "styling/tokens/creation" ;
55
55
  cs:hasCategory cs:StylingCategory ;
56
56
  cs:description """Design tokens must be created for all design decisions in a component. See css/properties/values for how these tokens are used in CSS implementation.""" ;
57
- cs:dos """
58
- (Do) Create component tokens that reference semantic tokens for design decisions.
59
- ```
57
+ cs:do [
58
+ cs:description "Create component tokens that reference semantic tokens for design decisions." ;
59
+ cs:code """
60
60
  {
61
61
  "button": {
62
62
  "background": {
@@ -65,11 +65,11 @@ cs:DesignTokenCreation a cs:CodeStandard ;
65
65
  }
66
66
  }
67
67
  }
68
- ```
69
- """ ;
70
- cs:donts """
71
- (Don't) Use raw values for design decisions.
72
- ```
68
+ """
69
+ ] ;
70
+ cs:dont [
71
+ cs:description "Use raw values for design decisions." ;
72
+ cs:code """
73
73
  {
74
74
  "button": {
75
75
  "background": {
@@ -78,17 +78,17 @@ cs:DesignTokenCreation a cs:CodeStandard ;
78
78
  }
79
79
  }
80
80
  }
81
- ```
82
- """ .
81
+ """
82
+ ] .
83
83
 
84
84
  # Theme Definition Standard
85
85
  cs:ThemeDefinition a cs:CodeStandard ;
86
86
  cs:name "styling/themes/definition" ;
87
87
  cs:hasCategory cs:StylingCategory ;
88
88
  cs:description """Themes are collections of semantic tokens that provide consistent styling across components. See css/themes/activation for implementation details.""" ;
89
- cs:dos """
90
- (Do) Define a theme as a complete set of semantic tokens.
91
- ```
89
+ cs:do [
90
+ cs:description "Define a theme as a complete set of semantic tokens." ;
91
+ cs:code """
92
92
  {
93
93
  "theme": {
94
94
  "canonical": {
@@ -103,11 +103,11 @@ cs:ThemeDefinition a cs:CodeStandard ;
103
103
  }
104
104
  }
105
105
  }
106
- ```
107
- """ ;
108
- cs:donts """
109
- (Don't) Mix implementation details into theme definitions.
110
- ```
106
+ """
107
+ ] ;
108
+ cs:dont [
109
+ cs:description "Mix implementation details into theme definitions." ;
110
+ cs:code """
111
111
  {
112
112
  "theme": {
113
113
  "canonical": {
@@ -116,8 +116,8 @@ cs:ThemeDefinition a cs:CodeStandard ;
116
116
  }
117
117
  }
118
118
  }
119
- ```
120
- """ .
119
+ """
120
+ ] .
121
121
 
122
122
  # Token Scoping Standard
123
123
  cs:TokenScoping a cs:CodeStandard ;
@@ -128,9 +128,9 @@ cs:TokenScoping a cs:CodeStandard ;
128
128
  - Semantic tokens: Theme scope (theme-specific bindings to primitive tokens)
129
129
  - Component tokens: Component scope (bindings to semantic tokens)
130
130
  """ ;
131
- cs:dos """
132
- (Do) Define primitive tokens in global scope.
133
- ```
131
+ cs:do [
132
+ cs:description "Define primitive tokens in global scope." ;
133
+ cs:code """
134
134
  {
135
135
  "color": {
136
136
  "neutral": {
@@ -141,11 +141,11 @@ cs:TokenScoping a cs:CodeStandard ;
141
141
  }
142
142
  }
143
143
  }
144
- ```
145
- """ ;
146
- cs:donts """
147
- (Don't) Define primitive tokens in theme scope.
148
- ```
144
+ """
145
+ ] ;
146
+ cs:dont [
147
+ cs:description "Define primitive tokens in theme scope." ;
148
+ cs:code """
149
149
  {
150
150
  "theme": {
151
151
  "canonical": {
@@ -160,6 +160,6 @@ cs:TokenScoping a cs:CodeStandard ;
160
160
  }
161
161
  }
162
162
  }
163
- ```
164
- """ .
163
+ """
164
+ ] .
165
165