@canonical/react-ds-app-anbox 0.36.0 → 0.38.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.
package/README.md CHANGED
@@ -14,6 +14,20 @@ bun add @canonical/react-ds-app-anbox
14
14
 
15
15
  The package builds on top of `@canonical/react-ds-global`.
16
16
 
17
+ `@canonical/styles` comes with it as a dependency, but installing is not importing. Import it once, in your application's entry point:
18
+
19
+ ```ts
20
+ import "@canonical/styles";
21
+ ```
22
+
23
+ or, from a stylesheet:
24
+
25
+ ```css
26
+ @import url("@canonical/styles");
27
+ ```
28
+
29
+ Then mark your root — `<html class="ds app comfortable">` — as the [`@canonical/styles` README](../../styles/main/README.md) describes. That one import is also what puts this package's stylesheets in a defined order against the rest of the design system's: see [Every component stylesheet is in `ds.components.apps-anbox`](#every-component-stylesheet-is-in-dscomponentsapps-anbox) below.
30
+
17
31
  ## Usage
18
32
 
19
33
  ```tsx
@@ -28,6 +42,44 @@ function AppHeader() {
28
42
  }
29
43
  ```
30
44
 
45
+ ## Styling
46
+
47
+ ### Every component stylesheet is in `ds.components.apps-anbox`
48
+
49
+ Every component stylesheet under `src/lib` is wrapped in one cascade layer:
50
+
51
+ ```css
52
+ @layer ds.components.apps-anbox {
53
+ .ds.button {
54
+ /* … */
55
+ }
56
+ }
57
+ ```
58
+
59
+ The name comes from the tier this package implements. Component layers follow the design system's tier tree, one flat name per tier: `ds.components.global` for the components every application gets, `ds.components.apps` for the ones Canonical applications share, and `ds.components.apps-anbox` for this package, which specialises them. `@canonical/styles` names the tiers one level up, so a name like this one is appended after them and sorts above the tier it specialises.
60
+
61
+ `src/lib/index.css` names the layer as its first rule and then imports every component stylesheet:
62
+
63
+ ```css
64
+ @layer ds.components.apps-anbox;
65
+
66
+ @import url("./Button/styles.css");
67
+ ```
68
+
69
+ A layer takes its place in the order the first time its name is seen, so naming it there — before any component sheet can open a block with it — keeps that place the same whichever sheet a bundler emits first. Importing a component already brings its own stylesheet, so that file is for a consumer who wants every component's CSS in one import.
70
+
71
+ `.storybook/styles.css` is deliberately not wrapped: it is the Storybook harness rather than a component stylesheet, it is not published, and it carries no component rules.
72
+
73
+ Three things follow.
74
+
75
+ `@canonical/react-ds-global` and `@canonical/react-ds-app` are not wrapped yet — at the time of writing neither package's stylesheets carry a layer at all — so today they still beat this package for the opposite reason: unlayered beats layered, whatever the emit order. What the layer guarantees, once those packages land, is that this package's `.ds.button` beats the `.ds.button` in `@canonical/react-ds-global` by cascade layer instead of by whichever bundle a loader emitted last. Where the two rules have the same selector at the same specificity, the emit order used to decide; where the global tier reaches for a longer selector, as its density seat does at (0,3,0) against (0,2,0), specificity did.
76
+
77
+ The order needs `@canonical/styles` on the page, needs its statement first, and needs that statement to name the shared application tier, since this package's name is appended after the names already fixed. Measured in Chromium 151: with the statement as it stands today, a rule here beats the same rule in `ds.components.apps` when the shared package is emitted first and loses when it is emitted second; with the tiers named at the second level, which a change released alongside this one adds, it wins in both orders. Nothing under `src/lib` imports `@canonical/styles` — an application imports it once, as the installation instructions above say.
78
+
79
+ An application's own **unlayered** CSS now beats every rule in this package, whatever the selectors on either side, because an unlayered author rule outranks every layered one. That is CSS working as designed, and it is the deliberate escape hatch: an application that needs to override a component writes a plain rule and it wins. An application that does *not* want to win by accident puts its CSS in `@layer app`.
80
+
81
+ **Rule for contributors:** every component stylesheet under `src/lib` opens with that wrapper, `src/lib/index.css` names the layer and imports the new sheet. `@keyframes` and a component's own `:root` token defaults go inside the wrapper; `@property` and `@font-face` registrations stay outside, above the block, because no layer sorts a registration. Never reach for `!important` to win a fight — an important declaration inverts the layer order, so it cannot be arbitrated by layers at all. The "Cascade Layers" section of the `@canonical/styles` README is the reference for the full order and for what is deliberately left unlayered.
82
+
31
83
  ## Storybook
32
84
 
33
85
  ```bash
@@ -1,63 +1,66 @@
1
- /* component styles */
1
+ /* component styles
2
+ * Layer: ds.components.apps-anbox (@canonical/styles README, "Cascade layers"). */
2
3
 
3
- /* component variables
4
- --button-color-background: background color of the button
5
- --button-color-background-hover: background color of the button on hover
6
- --button-color-background-active: background color of the button on active
7
- --button-color-text: text color of the button
8
- --button-color-border: border color of the button
9
- --button-color-border-hover: border color of the button on hover
10
- --button-color-border-active: border color of the button on active
4
+ @layer ds.components.apps-anbox {
5
+ /* component variables
6
+ --button-color-background: background color of the button
7
+ --button-color-background-hover: background color of the button on hover
8
+ --button-color-background-active: background color of the button on active
9
+ --button-color-text: text color of the button
10
+ --button-color-border: border color of the button
11
+ --button-color-border-hover: border color of the button on hover
12
+ --button-color-border-active: border color of the button on active
11
13
 
12
- --button-margin-left: left margin of the button
13
- --button-margin-bottom: bottom margin of the button
14
- --button-padding-vertical: vertical padding of the button
15
- --button-padding-horizontal: horizontal padding of the button
16
- --button-border-width: border width of the button
17
- --button-font-size: font size of the button
18
- --button-font-weight: font weight of the button
19
- --button-line-height: line height of the button
20
- */
21
- .ds.button {
22
- display: inline-block;
23
- cursor: pointer;
14
+ --button-margin-left: left margin of the button
15
+ --button-margin-bottom: bottom margin of the button
16
+ --button-padding-vertical: vertical padding of the button
17
+ --button-padding-horizontal: horizontal padding of the button
18
+ --button-border-width: border width of the button
19
+ --button-font-size: font size of the button
20
+ --button-font-weight: font weight of the button
21
+ --button-line-height: line height of the button
22
+ */
23
+ .ds.button {
24
+ display: inline-block;
25
+ cursor: pointer;
24
26
 
25
- color: var(--modifier-color-text, var(--button-color-text));
26
- background-color: var(--modifier-color, var(--button-color-background));
27
- border-color: var(--modifier-color-border, var(--button-color-border));
28
- border-style: solid;
29
- border-width: var(--button-border-width);
30
- font-size: var(--button-font-size);
31
- font-weight: var(--button-font-weight);
32
- line-height: var(--button-line-height);
33
- margin-block-end: var(--button-margin-bottom);
34
- margin-inline-end: var(--button-margin-left);
35
- padding-block: var(--button-padding-vertical);
36
- padding-inline: var(--button-padding-horizontal);
27
+ color: var(--modifier-color-text, var(--button-color-text));
28
+ background-color: var(--modifier-color, var(--button-color-background));
29
+ border-color: var(--modifier-color-border, var(--button-color-border));
30
+ border-style: solid;
31
+ border-width: var(--button-border-width);
32
+ font-size: var(--button-font-size);
33
+ font-weight: var(--button-font-weight);
34
+ line-height: var(--button-line-height);
35
+ margin-block-end: var(--button-margin-bottom);
36
+ margin-inline-end: var(--button-margin-left);
37
+ padding-block: var(--button-padding-vertical);
38
+ padding-inline: var(--button-padding-horizontal);
37
39
 
38
- text-align: left;
39
- text-decoration: none;
40
+ text-align: left;
41
+ text-decoration: none;
40
42
 
41
- /* component states */
42
- &:hover {
43
- background-color: var(
44
- --modifier-color-hover,
45
- var(--button-color-background-hover)
46
- );
47
- border-color: var(
48
- --modifier-color-border-hover,
49
- var(--button-color-border-hover)
50
- );
51
- }
43
+ /* component states */
44
+ &:hover {
45
+ background-color: var(
46
+ --modifier-color-hover,
47
+ var(--button-color-background-hover)
48
+ );
49
+ border-color: var(
50
+ --modifier-color-border-hover,
51
+ var(--button-color-border-hover)
52
+ );
53
+ }
52
54
 
53
- &:active {
54
- background-color: var(
55
- --modifier-color-active,
56
- var(--button-color-background-active)
57
- );
58
- border-color: var(
59
- --modifier-color-border-active,
60
- var(--button-color-border-active)
61
- );
55
+ &:active {
56
+ background-color: var(
57
+ --modifier-color-active,
58
+ var(--button-color-background-active)
59
+ );
60
+ border-color: var(
61
+ --modifier-color-border-active,
62
+ var(--button-color-border-active)
63
+ );
64
+ }
62
65
  }
63
66
  }
@@ -0,0 +1,22 @@
1
+ /* @canonical/react-ds-app-anbox — every component stylesheet in one import.
2
+ *
3
+ * The first rule is this package's own cascade layer. A layer takes its place
4
+ * in the order the first time its name is seen, so naming it here — before any
5
+ * component sheet can open a block with it — is what keeps that place the same
6
+ * whichever sheet a bundler emits first.
7
+ *
8
+ * The name comes from the tier this package implements, which is why it is a
9
+ * single flat name and not a nesting of one. `@canonical/styles` names the
10
+ * tiers one level up, so a name like this one is appended after them and sits
11
+ * above the tier it specialises. See "Cascade layers" in the
12
+ * `@canonical/styles` README.
13
+ *
14
+ * The imports below carry no `layer()` keyword on purpose: each sheet opens its
15
+ * own block with the same name, and the keyword would nest it one level deeper.
16
+ *
17
+ * Importing a component already brings its own stylesheet, so this file is for
18
+ * a consumer who wants every component's CSS without importing every component.
19
+ */
20
+ @layer ds.components.apps-anbox;
21
+
22
+ @import url("./Button/styles.css");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/react-ds-app-anbox",
3
3
  "description": "Anbox-specific components for the Pragma design system",
4
- "version": "0.36.0",
4
+ "version": "0.38.0",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -37,26 +37,26 @@
37
37
  "check:biome": "biome check",
38
38
  "check:biome:fix": "biome check --write",
39
39
  "check:ts": "tsc --noEmit",
40
- "storybook": "storybook dev -p 6009 --no-open --host 0.0.0.0",
40
+ "storybook": "storybook dev -p 6008 --no-open --host 0.0.0.0",
41
41
  "test": "bun run test:vitest",
42
42
  "test:vitest": "vitest run",
43
43
  "test:vitest:watch": "vitest"
44
44
  },
45
45
  "dependencies": {
46
- "@canonical/react-ds-global": "^0.36.0",
47
- "@canonical/storybook-config": "^0.36.0",
48
- "@canonical/styles": "^0.36.0",
46
+ "@canonical/react-ds-global": "^0.38.0",
47
+ "@canonical/storybook-config": "^0.38.0",
48
+ "@canonical/styles": "^0.38.0",
49
49
  "react": "^19.2.4",
50
50
  "react-dom": "^19.2.4"
51
51
  },
52
52
  "devDependencies": {
53
- "@biomejs/biome": "2.4.9",
54
- "@canonical/biome-config": "^0.36.0",
55
- "@canonical/design-tokens": "0.8.1",
56
- "@canonical/storybook-helpers": "^0.36.0",
57
- "@canonical/typescript-config-react": "^0.36.0",
58
- "@canonical/vitest-config-react": "^0.36.0",
59
- "@canonical/webarchitect": "^0.36.0",
53
+ "@biomejs/biome": "2.5.13",
54
+ "@canonical/biome-config": "^0.38.0",
55
+ "@canonical/design-tokens": "0.10.0",
56
+ "@canonical/storybook-helpers": "^0.38.0",
57
+ "@canonical/typescript-config-react": "^0.38.0",
58
+ "@canonical/vitest-config-react": "^0.38.0",
59
+ "@canonical/webarchitect": "^0.38.0",
60
60
  "@chromatic-com/storybook": "^5.0.1",
61
61
  "@storybook/addon-docs": "^10.3.1",
62
62
  "@storybook/react-vite": "^10.3.1",
@@ -74,5 +74,5 @@
74
74
  "vite": "^8.0.1",
75
75
  "vitest": "^4.0.18"
76
76
  },
77
- "gitHead": "78eb47ac10104e914eeacd331795e14b832703d4"
77
+ "gitHead": "4d10a68a9b299af6fe3d1d7d053e54ca128944ad"
78
78
  }