@canonical/styles 0.43.0 → 0.44.0

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.
Files changed (3) hide show
  1. package/README.md +27 -40
  2. package/package.json +3 -3
  3. package/src/layers.css +14 -15
package/README.md CHANGED
@@ -17,7 +17,7 @@ bun add @canonical/styles
17
17
 
18
18
  ## Usage
19
19
 
20
- Import once, in your application's entry point:
20
+ Import once, as the first import of your application's entry point, before any component:
21
21
 
22
22
  ```css
23
23
  @import url("@canonical/styles");
@@ -64,8 +64,8 @@ package or the markup of a page that does not need it.
64
64
  ## Entry points
65
65
 
66
66
  Five. `@canonical/styles` is the one an ordinary page wants: the whole stylesheet, in the order
67
- above. Three more are that stylesheet in parts, and the fifth is the order statement on its own, for a
68
- package rather than a page.
67
+ above. Three more are that stylesheet in parts, and the fifth is the order statement on its own, which
68
+ the other four import.
69
69
 
70
70
  | Entry | What it is |
71
71
  | --- | --- |
@@ -73,7 +73,7 @@ package rather than a page.
73
73
  | `@canonical/styles/tokens.css` | every custom property the design system declares, and not one rule that selects an element. Nothing here changes the page until something reads a value from it, with one exception noted below. |
74
74
  | `@canonical/styles/elements.css` | every rule the design system applies to a plain element: the reset, the root's baseline, and the typography with its baseline engine. |
75
75
  | `@canonical/styles/layout.css` | the layout presets — `grid`, `subgrid`, `responsive`, `intrinsic` and `content-flow` — which claim those five class names in a page's namespace. |
76
- | `@canonical/styles/layers.css` | the order statement and nothing else: no rule, no import, no declaration. The same statement the four above open with, for a package that needs the order fixed before it declares a layer of its own. A page never needs it. |
76
+ | `@canonical/styles/layers.css` | the order statement and nothing else: no rule, no import, no declaration. The same statement the four above open with; each imports it as its first rule. A page never needs it on its own. |
77
77
 
78
78
  One exception to "changes nothing", and it is worth knowing before you import `tokens.css`. The design
79
79
  tokens' generated theme sheet declares `color-scheme` on `:root`, `.light` and `.dark` alongside the
@@ -116,7 +116,8 @@ layers:
116
116
  ```css
117
117
  @layer normalize, ds.tokens, ds.reset, ds.typography, ds.modifiers, ds.surfaces,
118
118
  ds.states, ds.components, ds.components.global, ds.components.sites,
119
- ds.components.documentation, ds.components.stores, ds.components.apps;
119
+ ds.components.documentation, ds.components.stores, ds.components.apps,
120
+ lib, app;
120
121
  ```
121
122
 
122
123
  Read it from the bottom up — each position is an argument.
@@ -130,16 +131,19 @@ Read it from the bottom up — each position is an argument.
130
131
  | `ds.modifiers` | Theme, the typographic scale, the intent families (anticipation, criticality, emphasis, importance) and their shims, and the context and density classes. | Above typography, because a modifier's job is to shift what the layers below produced. |
131
132
  | `ds.surfaces` | The surface families: `surface`, `contrasted`, `modal`. | Above the modifiers, because a surface re-points colour channels the modifiers set. |
132
133
  | `ds.states` | The derived hover, active and disabled channels. | Above the surfaces, because a state is derived from whatever the surface resolved to. |
133
- | `ds.components` | Nothing, by rule. It is the parent of the tier layers below and holds no rule of its own. | Highest of the eight top-level layers, so a component is the final word on its own box. A rule written *directly* into a parent layer sits in that layer's implicit final sublayer, which is above every named sublayer — so such a rule would outrank every tier and no component package could override it by layer. Everything this package puts in `ds.components` therefore sits in a tier. |
134
+ | `ds.components` | Nothing, by rule. It is the parent of the tier layers below and holds no rule of its own. | Highest of the design system's eight top-level layers, so a component is the final word on its own box. A rule written *directly* into a parent layer sits in that layer's implicit final sublayer, which is above every named sublayer — so such a rule would outrank every tier and no component package could override it by layer. Everything this package puts in `ds.components` therefore sits in a tier. |
134
135
  | `ds.components.global` | The stylesheets of the shared component packages, and this package's own layout presets. | The base of the tier tree: what every other tier refines. |
135
136
  | `ds.components.sites` | The stylesheets of the sites tier. | The four second-level tiers never appear on the same page, so their order among themselves decides nothing. It is fixed here anyway, so that it can never come to depend on which package a bundler emits first. |
136
137
  | `ds.components.documentation` | The stylesheets of the documentation tier. | As above. |
137
138
  | `ds.components.stores` | The stylesheets of the stores tier. | As above. |
138
139
  | `ds.components.apps` | The stylesheets of the shared applications tier; one application's own tier declares a layer of its own above it. | As above. |
140
+ | `lib` | The stylesheets of libraries that are not part of the design system, such as documentation tooling (`@canonical/react-tokens`, `@canonical/storybook-helpers`). | Above the design system, so a tool's own rules win over the components it displays. |
141
+ | `app` | The application's own CSS. | Highest, so the application has the last word on its page. |
139
142
 
140
- An order statement fixes the relative order of layers the first time they appear. A later statement
141
- may introduce new names but can never reorder the ones already fixed, so an application that needs to
142
- interleave a layer of its own puts its statement before this import.
143
+ `lib` and `app` are the only layer names outside `normalize` and `ds.*`. An order statement fixes the
144
+ relative order of layers the first time they appear, and a later statement can never reorder them, so
145
+ an application imports this package first and writes its own CSS in `@layer app`, with no statement of
146
+ its own.
143
147
 
144
148
  This section is the reference: what is in each layer, and where. The reasoning behind the order — how
145
149
  a browser decides, why a rule in no layer beats every layered one, why the confinement a mixed page
@@ -158,31 +162,20 @@ order. A package in one of those tiers wraps its stylesheets in its own name and
158
162
  else.
159
163
 
160
164
  **A sub-tier declares its own layer, and that is what sorts it above.** One application's own package
161
- — the LXD tier, say — writes its CSS entry in this order, and the order is the whole recipe:
165
+ — the LXD tier, say — writes its CSS entry in two steps:
162
166
 
163
167
  ```css
164
- @import url("@canonical/styles/layers.css");
165
- @layer ds.components.apps-lxd;
168
+ @layer ds.components.apps-lxd; /* 1. name your layer */
166
169
 
167
- @import url("./Button/styles.css");
170
+ @import url("./Button/styles.css"); /* 2. then import your stylesheets */
168
171
  /* … the rest of the package's sheets, each wrapped in that layer … */
169
172
  ```
170
173
 
171
- The first line is what makes the second mean the same thing every time. A layer name is placed the
172
- moment the browser first meets it, so a name met *before* this package's statement is read is placed
173
- **below** the tier names that statement declares — and the sub-tier would sit under the very tiers it
174
- is meant to beat. Whether that happened depended on which file the application's bundler emitted
175
- first, which is not something the package can control from inside itself. Reading the statement first
176
- settles it: the thirteen names are fixed, and `ds.components.apps-lxd`, being new, is appended after
177
- them inside `ds.components`, where it sorts above every tier. That is the tree's own rule — the more
178
- specific tier wins — and it means this stylesheet never has to know which applications exist.
179
-
180
- Importing `layers.css` costs a page nothing: it is the same statement the other four entries open
181
- with, and a second identical statement names no layer the first has not already fixed.
182
-
183
- Measured on a scratch package entry in all four emission orders a bundler can produce: with the import
184
- first, a rule in `ds.components.apps-lxd` beats the same rule in `ds.components.apps` and in
185
- `ds.components.global` in 4 of 4; without it, in 1 of 4.
174
+ The order statement comes from the application loading `@canonical/styles` first (see
175
+ [Usage](#usage)). A layer name is placed the moment the browser first meets it, so with the fifteen
176
+ names already fixed, `ds.components.apps-lxd`, being new, is appended after them inside
177
+ `ds.components`, where it sorts above every tier. That is the tree's own rule — the more specific tier
178
+ wins — and it means this stylesheet never has to know which applications exist.
186
179
 
187
180
  **Nothing is ever written directly into `ds.components`.** A declaration in a parent layer sits in
188
181
  that layer's implicit final sublayer, which is above every named sublayer, so a rule written there
@@ -256,7 +249,7 @@ it installs it; a page that does not never hears about it.
256
249
 
257
250
  | Guarantee | The check behind it |
258
251
  | --- | --- |
259
- | Every rule the package itself ships is in one of the thirteen declared layers, and the statement reaches the browser before any of them, through the import every entry opens with. The typographic engine it imports is in them too. | The order fixtures that arrive with the Vanilla adapter package read the statement out of the resolved stylesheet and check every layer name the package opens against it. A check inside this package — that the set of layers used equals the set declared — is being added separately. |
252
+ | Every rule the package itself ships is in one of the thirteen design-system layers, and the statement reaches the browser before any of them, through the import every entry opens with. The typographic engine it imports is in them too. | The order fixtures that arrive with the Vanilla adapter package read the statement out of the resolved stylesheet and check every layer name the package opens against it. A check inside this package — that the set of layers used equals the set declared — is being added separately. |
260
253
  | An application tier's rule for a component beats the global tier's rule for the same component, whichever of the two a bundler loads first. | The two sublayers are named in the statement, so their order is fixed there rather than at first appearance, and the same order fixture reads it back. The component packages move into them when their stylesheets are wrapped, which is a separate change; until then both sublayers are empty and the guarantee is vacuous. |
261
254
  | The package ships no `!important`. | The same fixture file. An important declaration inverts the layer order and cannot be arbitrated by layers at all, so one of them would undo the guarantee above. |
262
255
  | Under `prefers-reduced-motion: reduce`, every motion duration this package defines is `0s`. | `src/motion.css`, and the reduced-motion fixture arriving with the adapter package. Zeroing the token is the mechanism: a component reads the token, so nothing has to out-rank the component's own declaration. Whether a given component honours the tokens is that package's guarantee, not this one's. Sheets that still hard-code a duration, and so still animate under the preference, are being moved onto the tokens separately: in the form package the shared input chrome (`src/index.css`) and eight component sheets (`ChoicesField`, `RichChoicesField`, `CheckboxInput`, `RadioInput`, `ColorInput`, `ComboboxInput` and its list, `FileUploadInput`, `SwitchInput`); in the global package `Tooltip`, `ContextualMenu` and `Popover`, which set their own duration property; and one application-tier sheet, the launchpad diff viewer's file header. |
@@ -271,7 +264,7 @@ reaches a bare element outside such a region. `@canonical/styles-vanilla-adapter
271
264
  - **Unlayered application CSS beats every rule here.** That is how the cascade is defined: a rule in no
272
265
  layer outranks a rule in any layer. It is not a defect, and it is the escape hatch — but it also
273
266
  means an application that wants this package's layer order to hold for its own CSS has to put that
274
- CSS in a layer too. See "Migrating" below.
267
+ CSS in `@layer app`. See "Migrating" below.
275
268
  - **`!important` in application or third-party CSS beats every rule here**, and for important
276
269
  declarations the layer order runs backwards, so the lowest layer wins. Nothing this package can do
277
270
  changes that.
@@ -315,15 +308,10 @@ to add to your root, and the reset applies exactly where it did before.
315
308
  specificity, and sometimes lost. They no longer can. If you were relying on a rule of ours to win,
316
309
  it will not any more.
317
310
 
318
- 2. **Put your own CSS in a layer, or accept that it wins.** Either is a valid choice, and the second
319
- needs no work. To take the first, wrap your application's stylesheet and name your layer after the
320
- package's own:
311
+ 2. **Put your own CSS in `@layer app`.** Import this package first, then wrap your application's
312
+ stylesheet:
321
313
 
322
314
  ```css
323
- @layer normalize, ds.tokens, ds.reset, ds.typography, ds.modifiers,
324
- ds.surfaces, ds.states, ds.components, ds.components.global,
325
- ds.components.sites, ds.components.documentation, ds.components.stores,
326
- ds.components.apps, app;
327
315
  @import url("@canonical/styles");
328
316
 
329
317
  @layer app {
@@ -331,9 +319,8 @@ to add to your root, and the reset applies exactly where it did before.
331
319
  }
332
320
  ```
333
321
 
334
- Your statement comes first and fixes `app` above every design-system layer, so your rules win by
335
- layer rather than by accident of order — and a rule of yours that you later want overridden by a
336
- component can simply be moved down.
322
+ The package's statement already names `app`, above every design-system layer, so your rules win by
323
+ layer rather than by accident of order, and you write no statement of your own.
337
324
 
338
325
  If you import a subpath rather than the package entry — `@canonical/styles/spacing.css` and the five
339
326
  other subpaths this package exports — note that a subpath carries no order statement, so the layers it
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/styles",
3
3
  "description": "Canonical Design System global stylesheet. The reset, typography, and design tokens, in named cascade layers.",
4
- "version": "0.43.0",
4
+ "version": "0.44.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./src/index.css",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@canonical/design-tokens": "0.43.0",
49
- "@canonical/styles-typography": "^0.43.0"
49
+ "@canonical/styles-typography": "^0.44.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@canonical/ds-assets": ">=0.18.0"
@@ -56,5 +56,5 @@
56
56
  "optional": true
57
57
  }
58
58
  },
59
- "gitHead": "581682464ef71de3f77dc2dc8bbe2b7e493bb05e"
59
+ "gitHead": "c1f2abc7f04aa29a88f0e6036645469e82a5dd33"
60
60
  }
package/src/layers.css CHANGED
@@ -6,28 +6,25 @@
6
6
  * a second identical statement names no layer the first has not already fixed,
7
7
  * and a statement can only append names, never reorder them.
8
8
  *
9
- * It exists for one reader: a package whose components belong to a tier below
10
- * the second level, one application's own tier. Such a package declares its own
11
- * layer and wraps its sheets in it:
9
+ * Every entry imports it as its first rule. A package whose components belong
10
+ * to a tier below the second level, one application's own tier, does not import
11
+ * it: it names its own layer, then imports its sheets:
12
12
  *
13
- * @import url("@canonical/styles/layers.css");
14
13
  * @layer ds.components.apps-lxd;
15
14
  *
16
15
  * @import url("./Button/styles.css");
17
16
  * … the rest of the package's sheets …
18
17
  *
19
- * The import on the first line is what makes the second line mean the same
20
- * thing every time. A layer name is placed the moment the browser first meets
21
- * it, and a name met before this statement is read is placed BELOW the tier
22
- * names it declares — so the sub-tier would sit under the very tiers it is
23
- * meant to beat. Whether that happened used to depend on which file a bundler
24
- * emitted first, which is not something a package can control from inside
25
- * itself. Reading the statement first settles it: the thirteen names are fixed,
26
- * and the sub-tier's name, being new, is appended after them inside
27
- * `ds.components`, where it sorts above every tier — the tier tree's own rule,
28
- * the more specific tier wins.
18
+ * The order statement comes from the application loading `@canonical/styles`
19
+ * first. The fifteen names are then fixed, and the sub-tier's name, being new,
20
+ * is appended after them inside `ds.components`, where it sorts above every
21
+ * tier — the tier tree's own rule, the more specific tier wins.
29
22
  *
30
23
  * A page that loads `@canonical/styles`, or the parts, does not need this file.
24
+ *
25
+ * `lib` and `app` are the only names outside `normalize` and `ds.*`: `lib` for
26
+ * a library outside the design system, such as documentation tooling, and
27
+ * `app` for an application's own CSS. Both sit above every design-system layer.
31
28
  */
32
29
 
33
30
  @layer normalize,
@@ -42,4 +39,6 @@
42
39
  ds.components.sites,
43
40
  ds.components.documentation,
44
41
  ds.components.stores,
45
- ds.components.apps;
42
+ ds.components.apps,
43
+ lib,
44
+ app;