@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/docs/css.md CHANGED
@@ -8,7 +8,7 @@ Component styles must be encapsulated using the component's root class as a boun
8
8
 
9
9
  ### Do
10
10
 
11
- (Do) Scope internal element styles using the component's namespace.
11
+ Scope internal element styles using the component's namespace.
12
12
  ```css
13
13
  .ds.button {
14
14
  /* Component root styles */
@@ -22,7 +22,7 @@ Component styles must be encapsulated using the component's root class as a boun
22
22
 
23
23
  ### Don't
24
24
 
25
- (Don't) Don't style internal elements without the component namespace.
25
+ Don't style internal elements without the component namespace.
26
26
  ```css
27
27
  /* Bad: Internal element not scoped to component */
28
28
  .icon {
@@ -38,7 +38,7 @@ Component states must be handled using attribute selectors for native states and
38
38
 
39
39
  ### Do
40
40
 
41
- (Do) Use attribute selectors for native element states.
41
+ Use attribute selectors for native element states.
42
42
  ```css
43
43
  .ds.button {
44
44
  &[disabled] {
@@ -49,7 +49,7 @@ Component states must be handled using attribute selectors for native states and
49
49
 
50
50
  ### Don't
51
51
 
52
- (Don't) Use class modifiers for native states.
52
+ Use class modifiers for native states.
53
53
  ```css
54
54
  /* Bad: Using class for native state */
55
55
  .ds.button.disabled {
@@ -65,14 +65,15 @@ CSS properties must use design tokens for design decisions (see styling/tokens/c
65
65
 
66
66
  ### Do
67
67
 
68
- (Do) Use design tokens for design decisions.
68
+ Use design tokens for design decisions.
69
69
  ```css
70
70
  .ds.button {
71
71
  /* Design decision uses token */
72
72
  background: var(--button-background);
73
73
  }
74
74
  ```
75
- (Do) Use raw values for unthemable properties (independent of design decisions).
75
+
76
+ Use raw values for unthemable properties (independent of design decisions).
76
77
  ```css
77
78
  .ds.skip-link {
78
79
  visibility: hidden;
@@ -81,7 +82,7 @@ CSS properties must use design tokens for design decisions (see styling/tokens/c
81
82
 
82
83
  ### Don't
83
84
 
84
- (Don't) Use raw values for design decisions.
85
+ Use raw values for design decisions.
85
86
  ```css
86
87
  .ds.button {
87
88
  /* Bad: Design decision using raw value */
@@ -97,7 +98,7 @@ Child elements within components must use simple, role-based class names (e.g.,
97
98
 
98
99
  ### Do
99
100
 
100
- (Do) Use simple role-based class names scoped by the parent.
101
+ Use simple role-based class names scoped by the parent.
101
102
  ```css
102
103
  .ds.accordion-item {
103
104
  & > .header {
@@ -130,7 +131,7 @@ Child elements within components must use simple, role-based class names (e.g.,
130
131
 
131
132
  ### Don't
132
133
 
133
- (Don't) Use verbose prefixed class names that repeat the component name.
134
+ Use verbose prefixed class names that repeat the component name.
134
135
  ```css
135
136
  /* Bad: Redundant component prefix in child class names */
136
137
  .ds.accordion-item .accordion-item-header {
@@ -154,7 +155,7 @@ All component selectors must be prefixed with the `.ds` namespace (e.g., `.ds.bu
154
155
 
155
156
  ### Do
156
157
 
157
- (Do) Prefix all component selectors with `.ds`.
158
+ Prefix all component selectors with `.ds`.
158
159
  ```css
159
160
  /* Component root with namespace */
160
161
  .ds.button {
@@ -164,7 +165,7 @@ All component selectors must be prefixed with the `.ds` namespace (e.g., `.ds.bu
164
165
 
165
166
  ### Don't
166
167
 
167
- (Don't) Omit the `.ds` namespace from component selectors.
168
+ Omit the `.ds` namespace from component selectors.
168
169
  ```css
169
170
  /* Bad: Missing .ds namespace */
170
171
  .button {
@@ -176,18 +177,21 @@ All component selectors must be prefixed with the `.ds` namespace (e.g., `.ds.bu
176
177
 
177
178
  ## css/selectors/naming-convention
178
179
 
179
- Component CSS class names must be the kebab-case version of the component's PascalCase name.
180
+ Convert PascalCase component names to kebab-case for CSS classes:
181
+ - `MyComponent` -> `.ds.my-component`
182
+ - `UserProfile` -> `.ds.user-profile`
183
+ - `Button` -> `.ds.button`
180
184
 
181
185
  ### Do
182
186
 
183
- (Do) Convert PascalCase component names to kebab-case for CSS classes:
187
+ Convert PascalCase component names to kebab-case for CSS classes:
184
188
  - `MyComponent` -> `.ds.my-component`
185
189
  - `UserProfile` -> `.ds.user-profile`
186
190
  - `Button` -> `.ds.button`
187
191
 
188
192
  ### Don't
189
193
 
190
- (Don't) Use PascalCase or other formats in CSS class names:
194
+ Use PascalCase or other formats in CSS class names:
191
195
  - `.ds.MyComponent` (Bad: Not kebab-case)
192
196
  - `.ds.user_profile` (Bad: Not kebab-case)
193
197
 
@@ -199,7 +203,7 @@ CSS class names must describe the purpose or state of an element, not its appear
199
203
 
200
204
  ### Do
201
205
 
202
- (Do) Use semantic modifier classes to represent component variations.
206
+ Use semantic modifier classes to represent component variations.
203
207
  ```css
204
208
  /* Semantic modifier for a primary button */
205
209
  .ds.button.primary {
@@ -209,7 +213,7 @@ CSS class names must describe the purpose or state of an element, not its appear
209
213
 
210
214
  ### Don't
211
215
 
212
- (Don't) Use non-semantic or presentational class names.
216
+ Use non-semantic or presentational class names.
213
217
  ```css
214
218
  /* Bad: 'big' describes appearance, not purpose */
215
219
  .ds.button.big {
@@ -228,7 +232,7 @@ CSS selectors must follow a strict specificity pattern:
228
232
 
229
233
  ### Do
230
234
 
231
- (Do) Use a single modifier class for component variants.
235
+ Use a single modifier class for component variants.
232
236
  ```css
233
237
  .ds.button.primary {
234
238
  /* Variant: root + modifier (3 classes) */
@@ -238,7 +242,7 @@ CSS selectors must follow a strict specificity pattern:
238
242
 
239
243
  ### Don't
240
244
 
241
- (Don't) Combine multiple modifiers or mix states with variants.
245
+ Combine multiple modifiers or mix states with variants.
242
246
  ```css
243
247
  /* Bad: Mixing variant with state */
244
248
  .ds.button.primary[disabled].large {
@@ -254,7 +258,7 @@ Theme tokens must be activated through CSS classes on container elements. See st
254
258
 
255
259
  ### Do
256
260
 
257
- (Do) Define semantic tokens within theme classes.
261
+ Define semantic tokens within theme classes.
258
262
  ```css
259
263
  .canonical {
260
264
  --spacing-vertical-medium: var(--spacing-unit-2x);
@@ -264,7 +268,7 @@ Theme tokens must be activated through CSS classes on container elements. See st
264
268
 
265
269
  ### Don't
266
270
 
267
- (Don't) Hardcode theme names in component styles.
271
+ Hardcode theme names in component styles.
268
272
  ```css
269
273
  /* Bad: Component locked to specific theme */
270
274
  .ds.button {
package/docs/icons.md CHANGED
@@ -10,7 +10,7 @@ Icon files must:
10
10
 
11
11
  ### Do
12
12
 
13
- (Do) Use kebab-case and a semantic identifier for the icon file name.
13
+ Use kebab-case and a semantic identifier for the icon file name.
14
14
  ```
15
15
  warning.svg
16
16
  user-profile.svg
@@ -19,7 +19,7 @@ arrow-down.svg
19
19
 
20
20
  ### Don't
21
21
 
22
- (Don't) Include size, theme, or redundant suffixes in the file name.
22
+ Include size, theme, or redundant suffixes in the file name.
23
23
  ```
24
24
  warning-16.svg
25
25
  warning-dark.svg
@@ -27,7 +27,7 @@ warning_icon.svg
27
27
  WARNING.svg
28
28
  ```
29
29
 
30
- (Don't) Use non-semantic or ambiguous names that do not describe the icon.
30
+ Use non-semantic or ambiguous names that do not describe the icon.
31
31
  ```
32
32
  icon1.svg
33
33
  shape.svg
@@ -41,7 +41,7 @@ Each icon shall be stored as a single SVG file in the `icons/` directory.
41
41
 
42
42
  ### Do
43
43
 
44
- (Do) Store each icon as an individual SVG file in the designated `icons/` directory.
44
+ Store each icon as an individual SVG file in the designated `icons/` directory.
45
45
  ```
46
46
  icons/
47
47
  ├── warning.svg
@@ -51,7 +51,7 @@ icons/
51
51
 
52
52
  ### Don't
53
53
 
54
- (Don't) Store icons in nested directories or use incorrect file extensions.
54
+ Store icons in nested directories or use incorrect file extensions.
55
55
  ```
56
56
  icons/
57
57
  ├── variants/
@@ -61,7 +61,7 @@ icons/
61
61
  └── warning.svg.txt
62
62
  ```
63
63
 
64
- (Don't) Combine multiple icons into a single SVG file.
64
+ Combine multiple icons into a single SVG file.
65
65
  ```
66
66
  icons/
67
67
  └── all-icons.svg
@@ -75,7 +75,7 @@ Icon must use `fill` with `currentColor` for their paths and shapes.
75
75
 
76
76
  ### Do
77
77
 
78
- (Do) Use `currentColor` for the `fill` of paths in non-branded icons.
78
+ Use `currentColor` for the `fill` of paths in non-branded icons.
79
79
  ```svg
80
80
  <!-- Non-branded icon -->
81
81
  <svg viewBox="0 0 16 16">
@@ -87,12 +87,12 @@ Icon must use `fill` with `currentColor` for their paths and shapes.
87
87
 
88
88
  ### Don't
89
89
 
90
- (Don't) Use hard-coded colors in icons.
90
+ Use hard-coded colors in icons.
91
91
  ```svg
92
92
  <path fill="#000000" d="..." />
93
93
  ```
94
94
 
95
- (Don't) Use `opacity` to create different shades of a color.
95
+ Use `opacity` to create different shades of a color.
96
96
  ```svg
97
97
  <path fill="currentColor" opacity="0.5" d="..." />
98
98
  ```
@@ -105,7 +105,7 @@ Each icon's SVG markup must contain a single `<g>` element with an `id` matching
105
105
 
106
106
  ### Do
107
107
 
108
- (Do) Include a single `<g>` element with an `id` that matches the filename.
108
+ Include a single `<g>` element with an `id` that matches the filename.
109
109
  ```svg
110
110
  <!-- warning.svg -->
111
111
  <svg>
@@ -117,7 +117,7 @@ Each icon's SVG markup must contain a single `<g>` element with an `id` matching
117
117
 
118
118
  ### Don't
119
119
 
120
- (Don't) Use multiple `<g>` elements or an `id` that does not match the filename.
120
+ Use multiple `<g>` elements or an `id` that does not match the filename.
121
121
  ```svg
122
122
  <!-- warning.svg -->
123
123
  <svg>
@@ -134,12 +134,13 @@ Each icon's SVG markup must contain a single `<g>` element with an `id` matching
134
134
 
135
135
  ## icons/svg/mask-usage
136
136
 
137
- Icons may use SVG masks to negate or partially negate paths, enabling advanced visual effects such as cutouts and overlays.
137
+ Use SVG <mask> elements to create negative space or overlays in icons.
138
+ Example
138
139
 
139
140
  ### Do
140
141
 
141
- (Do) Use SVG <mask> elements to create negative space or overlays in icons.
142
- Example:
142
+ Use SVG <mask> elements to create negative space or overlays in icons.
143
+ Example
143
144
  ```svg
144
145
  <svg width='16' height='16' xmlns='http://www.w3.org/2000/svg'>
145
146
  <defs>
@@ -154,8 +155,8 @@ Example:
154
155
  </svg>
155
156
  ```
156
157
 
157
- (Do) Use <rect> with fill="white" to define the mask area, and <path> with fill="black" to subtract shapes.
158
- Example:
158
+ Use <rect> with fill="white" to define the mask area, and <path> with fill="black" to subtract shapes.
159
+ Example
159
160
  ```svg
160
161
  <mask id="mask">
161
162
  <rect width="16" height="16" fill="white"/>
@@ -163,8 +164,8 @@ Example:
163
164
  </mask>
164
165
  ```
165
166
 
166
- (Do) Use opacity on mask paths to achieve partial negation (e.g., faded or semi-transparent cutouts).
167
- Example:
167
+ Use opacity on mask paths to achieve partial negation (e.g., faded or semi-transparent cutouts).
168
+ Example
168
169
  ```svg
169
170
  <mask id="progress-mask">
170
171
  <rect width="16" height="16" fill="white"/>
@@ -172,16 +173,16 @@ Example:
172
173
  </mask>
173
174
  ```
174
175
 
175
- (Do) Reference the mask in the icon's main shape using mask="url(#mask-id)".
176
- Example:
176
+ Reference the mask in the icon's main shape using mask="url(#mask-id)".
177
+ Example
177
178
  ```svg
178
179
  <circle fill='currentColor' cx='8' cy='8' r='7' mask="url(#mask-id)"/>
179
180
  ```
180
181
 
181
182
  ### Don't
182
183
 
183
- (Don't) Use masks without clear purpose or visual benefit.
184
- Example:
184
+ Use masks without clear purpose or visual benefit.
185
+ Example
185
186
  ```svg
186
187
  <!-- Bad: Mask used but has no effect -->
187
188
  <mask id="empty-mask">
@@ -190,8 +191,8 @@ Example:
190
191
  <circle fill='currentColor' cx='8' cy='8' r='7' mask="url(#empty-mask)"/>
191
192
  ```
192
193
 
193
- (Don't) use non-semantic mask ids or omit mask references in the main shape.
194
- Example:
194
+ use non-semantic mask ids or omit mask references in the main shape.
195
+ Example
195
196
  ```svg
196
197
  <!-- Bad: Non-semantic mask id -->
197
198
  <mask id="123">
@@ -200,8 +201,8 @@ Example:
200
201
  </mask>
201
202
  ```
202
203
 
203
- (Don't) rely on masks for simple icons that do not require negative space or overlays.
204
- Example:
204
+ rely on masks for simple icons that do not require negative space or overlays.
205
+ Example
205
206
  ```svg
206
207
  <!-- Bad: Mask used for a simple shape -->
207
208
  <mask id="simple-mask">
@@ -218,7 +219,7 @@ All icon SVGs must use a `viewBox` of `0 0 16 16`.
218
219
 
219
220
  ### Do
220
221
 
221
- (Do) Set the `viewBox` attribute to `0 0 16 16` in the `<svg>` element.
222
+ Set the `viewBox` attribute to `0 0 16 16` in the `<svg>` element.
222
223
  ```svg
223
224
  <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'>
224
225
  <g id="icon">
@@ -229,7 +230,7 @@ All icon SVGs must use a `viewBox` of `0 0 16 16`.
229
230
 
230
231
  ### Don't
231
232
 
232
- (Don't) Use a `viewBox` with dimensions other than `16 16`.
233
+ Use a `viewBox` with dimensions other than `16 16`.
233
234
  ```svg
234
235
  <!-- Bad: Different viewBox size -->
235
236
  <svg viewBox="0 0 24 24">
@@ -237,7 +238,7 @@ All icon SVGs must use a `viewBox` of `0 0 16 16`.
237
238
  </svg>
238
239
  ```
239
240
 
240
- (Don't) Use a non-square `viewBox`.
241
+ Use a non-square `viewBox`.
241
242
  ```svg
242
243
  <!-- Bad: Non-square viewBox -->
243
244
  <svg viewBox="0 0 16 24">
@@ -245,7 +246,7 @@ All icon SVGs must use a `viewBox` of `0 0 16 16`.
245
246
  </svg>
246
247
  ```
247
248
 
248
- (Don't) Omit the `viewBox` attribute.
249
+ Omit the `viewBox` attribute.
249
250
  ```svg
250
251
  <!-- Bad: Missing viewBox -->
251
252
  <svg width="16" height="16">
@@ -264,7 +265,7 @@ Icon names must be:
264
265
 
265
266
  ### Do
266
267
 
267
- (Do) Define a constant array of icon names and derive the `IconName` type from it in the icon exporter package.
268
+ Define a constant array of icon names and derive the `IconName` type from it in the icon exporter package.
268
269
  ```typescript
269
270
  // In the icon exporter package
270
271
  export const ICON_NAMES = [
@@ -276,7 +277,7 @@ export const ICON_NAMES = [
276
277
  export type IconName = typeof ICON_NAMES[number];
277
278
  ```
278
279
 
279
- (Do) Import the `IconName` type in consumer code to ensure type safety.
280
+ Import the `IconName` type in consumer code to ensure type safety.
280
281
  ```typescript
281
282
  // In consumer code
282
283
  import type { IconName } from '@canonical/ds-assets';
@@ -286,8 +287,7 @@ export interface ComponentProps {
286
287
  }
287
288
  ```
288
289
 
289
- (Do) Use `Pick` to restrict choices from `IconName` when necessary.
290
-
290
+ Use `Pick` to restrict choices from `IconName` when necessary.
291
291
  ```typescript
292
292
  // In consumer code
293
293
  import type { IconName } from '@canonical/ds-assets';
@@ -299,7 +299,7 @@ export interface ComponentProps {
299
299
 
300
300
  ### Don't
301
301
 
302
- (Don't) Define icon name types or values on the consumer side.
302
+ Define icon name types or values on the consumer side.
303
303
  ```typescript
304
304
  // Bad: String literal type defined in consumer code
305
305
  type ComponentIconName = "warning" | "search";
@@ -309,7 +309,7 @@ export interface ComponentProps {
309
309
  }
310
310
  ```
311
311
 
312
- (Don't) Use a generic `string` type for icon names.
312
+ Use a generic `string` type for icon names.
313
313
  ```typescript
314
314
  // Bad: No type safety for icon names
315
315
  export interface ComponentProps {
@@ -317,7 +317,7 @@ export interface ComponentProps {
317
317
  }
318
318
  ```
319
319
 
320
- (Don't) Maintain separate type and value definitions.
320
+ Maintain separate type and value definitions.
321
321
  ```typescript
322
322
  // Bad: Duplication of icon names
323
323
  const ICONS = ["warning", "search"];
@@ -332,7 +332,7 @@ Each icon concept must have exactly one SVG file. Size and theme variants are no
332
332
 
333
333
  ### Do
334
334
 
335
- (Do) Use a single SVG file for each icon and control its size and color with CSS.
335
+ Use a single SVG file for each icon and control its size and color with CSS.
336
336
  ```svg
337
337
  <!-- Single icon file -->
338
338
  <svg viewBox="0 0 16 16">
@@ -340,8 +340,7 @@ Each icon concept must have exactly one SVG file. Size and theme variants are no
340
340
  <path fill="currentColor" d="..." />
341
341
  </g>
342
342
  </svg>
343
- ```
344
- ```css
343
+
345
344
  /* CSS usage */
346
345
  .small-icon { font-size: 1em; } /* 16px */
347
346
  .large-icon { font-size: 2em; } /* 32px */
@@ -350,14 +349,14 @@ Each icon concept must have exactly one SVG file. Size and theme variants are no
350
349
 
351
350
  ### Don't
352
351
 
353
- (Don't) Create multiple files for different icon sizes.
352
+ Create multiple files for different icon sizes.
354
353
  ```
355
354
  warning.svg
356
355
  warning-small.svg
357
356
  warning-large.svg
358
357
  ```
359
358
 
360
- (Don't) Create multiple files for different themes.
359
+ Create multiple files for different themes.
361
360
  ```
362
361
  warning.svg
363
362
  warning-dark.svg
package/docs/index.md CHANGED
@@ -4,9 +4,10 @@ Standards documentation generated from the code-standards ontology.
4
4
 
5
5
  ## Categories
6
6
 
7
- - [Code](./code.md) (11)
7
+ - [Code](./code.md) (7)
8
8
  - [CSS](./css.md) (9)
9
9
  - [Icons](./icons.md) (8)
10
+ - [Packaging](./packaging.md) (7)
10
11
  - [React](./react.md) (14)
11
12
  - [Rust](./rust.md) (11)
12
13
  - [Storybook](./storybook.md) (9)