@canonical/styles 0.17.1 → 0.21.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
@@ -1,4 +1,70 @@
1
- ## Canonical Web Team Styles
1
+ # @canonical/styles
2
2
 
3
+ Global stylesheet for the Canonical Design System. Single import that aggregates normalize, typography, and design tokens into a layered cascade.
3
4
 
5
+ ## Installation
4
6
 
7
+ ```bash
8
+ bun add @canonical/styles
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Import once in your application entry point:
14
+
15
+ ```css
16
+ @import url("@canonical/styles");
17
+ ```
18
+
19
+ Or in JavaScript/TypeScript:
20
+
21
+ ```ts
22
+ import "@canonical/styles";
23
+ ```
24
+
25
+ This single import provides:
26
+
27
+ - **CSS reset** via [normalize.css](https://github.com/necolas/normalize.css)
28
+ - **Typography baseline grid** via `@canonical/styles-typography`
29
+ - **Design tokens** (colour, spacing, surfaces, states) via `@canonical/design-tokens`
30
+ - **`color-scheme: light dark`** on `:root` for `light-dark()` support
31
+
32
+ ## Cascade Layers
33
+
34
+ The stylesheet establishes a deterministic layer order:
35
+
36
+ ```css
37
+ @layer normalize, ds.reset, ds.modifiers, ds.components;
38
+ ```
39
+
40
+ This ensures that component styles always override modifier styles, which always override resets, regardless of source order in consuming applications.
41
+
42
+ ## Design Tokens
43
+
44
+ The following token sets from `@canonical/design-tokens` are included:
45
+
46
+ | Token Set | Contents |
47
+ |-----------|----------|
48
+ | `sets.primitive` | Base colour palette, spacing scale, font sizes |
49
+ | `modifiers.theme` | Light/dark theme mappings |
50
+ | `modifiers.surfaces` | Surface elevation tokens |
51
+ | `modifiers.anticipation` | Constructive/destructive/caution intents |
52
+ | `modifiers.criticality` | Error/warning/success/information states |
53
+ | `modifiers.emphasis` | Branded/highlighted/muted emphasis |
54
+ | `modifiers.importance` | Primary/secondary importance levels |
55
+ | `states` | Interactive state tokens (hover, active, focus, disabled) |
56
+
57
+ ## Dependencies
58
+
59
+ | Package | Role |
60
+ |---------|------|
61
+ | `@canonical/design-tokens` | CSS custom properties for colour, spacing, and states |
62
+ | `@canonical/styles-typography` | Baseline grid engine and typographic scale |
63
+ | `normalize.css` | Cross-browser CSS reset |
64
+
65
+ ## Package Structure
66
+
67
+ ```
68
+ src/
69
+ index.css -- entry point, imports all dependencies
70
+ ```
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@canonical/styles",
3
- "description": "Canonical's base styles",
4
- "version": "0.17.1",
3
+ "description": "Canonical Design System global stylesheet. Aggregates normalize, typography, and design tokens.",
4
+ "version": "0.21.0",
5
5
  "main": "src/index.css",
6
+ "exports": {
7
+ ".": "./src/index.css",
8
+ "./fonts": "./src/fonts.css"
9
+ },
6
10
  "files": [
7
11
  "src"
8
12
  ],
@@ -12,13 +16,9 @@
12
16
  },
13
17
  "repository": {
14
18
  "type": "git",
15
- "url": "https://github.com/canonical/ds25"
19
+ "url": "https://github.com/canonical/pragma"
16
20
  },
17
21
  "license": "LGPL-3.0",
18
- "bugs": {
19
- "url": "https://github.com/canonical/ds25/issues"
20
- },
21
- "homepage": "https://github.com/canonical/ds25#readme",
22
22
  "scripts": {
23
23
  "check": "bun run check:biome",
24
24
  "check:fix": "bun run check:biome:fix",
@@ -26,17 +26,21 @@
26
26
  "check:biome:fix": "biome check --write"
27
27
  },
28
28
  "devDependencies": {
29
- "@biomejs/biome": "2.4.5",
30
- "@canonical/biome-config": "^0.17.1"
29
+ "@biomejs/biome": "2.4.9",
30
+ "@canonical/biome-config": "^0.21.0"
31
31
  },
32
32
  "dependencies": {
33
- "@canonical/styles-elements": "^0.17.1",
34
- "@canonical/styles-modes-canonical": "^0.17.1",
35
- "@canonical/styles-modes-density": "^0.17.1",
36
- "@canonical/styles-modes-intents": "^0.17.1",
37
- "@canonical/styles-modes-motion": "^0.17.1",
38
- "@canonical/styles-primitives-canonical": "^0.17.1",
33
+ "@canonical/design-tokens": "^0.6.0",
34
+ "@canonical/styles-typography": "^0.21.0",
39
35
  "normalize.css": "^8.0.1"
40
36
  },
41
- "gitHead": "e3eaaa9efdb58fa72acb8fdd3c7dffa25a1341c4"
37
+ "peerDependencies": {
38
+ "@canonical/ds-assets": ">=0.18.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@canonical/ds-assets": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "gitHead": "4a39c954e7bbad4903397f8371f801982034a26d"
42
46
  }
package/src/fonts.css ADDED
@@ -0,0 +1,48 @@
1
+ /* @canonical/styles — Font loading (Ubuntu Sans, self-hosted)
2
+ *
3
+ * Variable fonts from @canonical/ds-assets.
4
+ * Licensed under Ubuntu Font License v1.0.
5
+ *
6
+ * Opt-in: import this file to load the Ubuntu Sans font family.
7
+ *
8
+ * @import url("@canonical/styles/fonts");
9
+ * @import url("@canonical/styles");
10
+ */
11
+
12
+ @font-face {
13
+ font-family: "Ubuntu Sans";
14
+ src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSans[wdth,wght].woff2")
15
+ format("woff2-variations");
16
+ font-weight: 100 900;
17
+ font-stretch: 62.5% 100%;
18
+ font-style: normal;
19
+ font-display: swap;
20
+ }
21
+
22
+ @font-face {
23
+ font-family: "Ubuntu Sans";
24
+ src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSans-Italic[wdth,wght].woff2")
25
+ format("woff2-variations");
26
+ font-weight: 100 900;
27
+ font-stretch: 62.5% 100%;
28
+ font-style: italic;
29
+ font-display: swap;
30
+ }
31
+
32
+ @font-face {
33
+ font-family: "Ubuntu Sans Mono";
34
+ src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono[wght].woff2")
35
+ format("woff2-variations");
36
+ font-weight: 100 900;
37
+ font-style: normal;
38
+ font-display: swap;
39
+ }
40
+
41
+ @font-face {
42
+ font-family: "Ubuntu Sans Mono";
43
+ src: url("@canonical/ds-assets/fonts/ubuntu-sans/UbuntuSansMono-Italic[wght].woff2")
44
+ format("woff2-variations");
45
+ font-weight: 100 900;
46
+ font-style: italic;
47
+ font-display: swap;
48
+ }
package/src/grid.css ADDED
@@ -0,0 +1,109 @@
1
+ /* @canonical/styles — Grid layout presets
2
+ *
3
+ * ┌─────────────────────────────────────────────────────────────┐
4
+ * │ Three grid modes │
5
+ * ├──────────────┬──────────────────────────────────────────────┤
6
+ * │ .responsive │ Breakpoint-driven: 4-col / 8-col / 12-col │
7
+ * │ .intrinsic │ Fluid auto-fill, groups of 4 columns │
8
+ * │ (bare) │ No preset — bring your own columns │
9
+ * └──────────────┴──────────────────────────────────────────────┘
10
+ *
11
+ * Classes:
12
+ * .grid Base grid context (display: grid)
13
+ * .grid.responsive Breakpoint-driven column grid
14
+ * .grid.intrinsic Fluid auto-fill grid
15
+ * .subgrid CSS subgrid child — inherits parent columns
16
+ *
17
+ * Customization:
18
+ * --grid-gap Shorthand: sets both row-gap and column-gap (default: var(--grid-gutter))
19
+ * --grid-row-gap Block-direction (vertical) gap between rows
20
+ * --grid-column-gap Inline-direction (horizontal) gap between columns
21
+ * --grid-col-min Minimum column width for intrinsic mode (default: 100px)
22
+ * --subgrid-span Column span for subgrid children (default: 1 / -1, full width)
23
+ *
24
+ * Breakpoints (responsive mode):
25
+ * < 768px 4 columns (mobile)
26
+ * 768px – 1279px 8 columns (tablet)
27
+ * ≥ 1280px 12 columns (desktop)
28
+ *
29
+ * Relationship to spacing architecture:
30
+ * The grid provides horizontal structure. Vertical spacing between
31
+ * grid items is handled by the spacing architecture tokens
32
+ * (--container-gap-* for app UI, element margin-bottom for editorial).
33
+ * The --grid-gap property controls both axes unless overridden
34
+ * per-axis with --grid-row-gap or --grid-column-gap.
35
+ *
36
+ * Usage examples:
37
+ *
38
+ * <!-- Responsive 12-column layout -->
39
+ * <div class="grid responsive">
40
+ * <main style="grid-column: span 8">Content</main>
41
+ * <aside style="grid-column: span 4">Sidebar</aside>
42
+ * </div>
43
+ *
44
+ * <!-- Fluid card grid -->
45
+ * <div class="grid intrinsic">
46
+ * <article>Card 1</article>
47
+ * <article>Card 2</article>
48
+ * </div>
49
+ *
50
+ * <!-- Subgrid for aligned form fields -->
51
+ * <div class="grid responsive">
52
+ * <form class="subgrid">
53
+ * <div class="subgrid" style="grid-column: span 6">
54
+ * <label>Name</label>
55
+ * <input />
56
+ * </div>
57
+ * </form>
58
+ * </div>
59
+ *
60
+ * <!-- Custom gap -->
61
+ * <div class="grid responsive" style="--grid-gap: 2rem">...</div>
62
+ *
63
+ * <!-- Separate row/column gaps -->
64
+ * <div class="grid responsive" style="--grid-row-gap: 1.5rem; --grid-column-gap: 1rem">...</div>
65
+ */
66
+
67
+ @layer ds.components {
68
+ :root {
69
+ --grid-col-min: 100px;
70
+
71
+ --grid-intrinsic: repeat(
72
+ auto-fill,
73
+ minmax(var(--grid-col-min), 1fr) minmax(var(--grid-col-min), 1fr)
74
+ minmax(var(--grid-col-min), 1fr) minmax(var(--grid-col-min), 1fr)
75
+ );
76
+ }
77
+
78
+ .grid {
79
+ display: grid;
80
+ grid-template-columns: var(--modifier-grid-template);
81
+ column-gap: var(
82
+ --grid-column-gap,
83
+ var(--grid-gap, var(--grid-gutter, 1.5rem))
84
+ );
85
+ row-gap: var(--grid-row-gap, var(--grid-gap, var(--grid-gutter, 1.5rem)));
86
+ }
87
+
88
+ .responsive {
89
+ --modifier-grid-template: repeat(4, 1fr);
90
+
91
+ @media (min-width: 768px) {
92
+ --modifier-grid-template: repeat(8, 1fr);
93
+ }
94
+
95
+ @media (min-width: 1280px) {
96
+ --modifier-grid-template: repeat(12, 1fr);
97
+ }
98
+ }
99
+
100
+ .intrinsic {
101
+ --modifier-grid-template: var(--grid-intrinsic);
102
+ }
103
+
104
+ .subgrid {
105
+ display: grid;
106
+ grid-template-columns: subgrid;
107
+ grid-column: var(--subgrid-span, 1 / -1);
108
+ }
109
+ }
package/src/index.css CHANGED
@@ -1,13 +1,30 @@
1
- @layer normalize, primitives, modes, elements;
1
+ /* @canonical/styles — Global stylesheet entry point
2
+ *
3
+ * Single import for consumers:
4
+ * @import url("@canonical/styles");
5
+ */
6
+
7
+ /* Layer ordering — deterministic cascade (spec §C.2) */
8
+ @layer normalize, ds.reset, ds.modifiers, ds.components;
2
9
 
3
10
  /* Reset */
4
11
  @import url("normalize.css");
5
- /* Load external files first */
6
- /* TODO Ideally we would load the font-faces before this */
7
-
8
- @import url("@canonical/styles-primitives-canonical");
9
- @import url("@canonical/styles-modes-canonical");
10
- @import url("@canonical/styles-modes-density");
11
- @import url("@canonical/styles-modes-motion");
12
- @import url("@canonical/styles-modes-intents");
13
- @import url("@canonical/styles-elements");
12
+
13
+ /* Typography: interpreter engine + scale tokens */
14
+ @import url("@canonical/styles-typography");
15
+
16
+ /* Design tokens — colour, spacing, surfaces, states */
17
+ @import url("@canonical/design-tokens/dist/sets.primitive.css");
18
+ @import url("@canonical/design-tokens/dist/modifiers.theme.css");
19
+ @import url("@canonical/design-tokens/dist/modifiers.surfaces.css");
20
+ @import url("@canonical/design-tokens/dist/modifiers.anticipation.css");
21
+ @import url("@canonical/design-tokens/dist/modifiers.criticality.css");
22
+ @import url("@canonical/design-tokens/dist/modifiers.emphasis.css");
23
+ @import url("@canonical/design-tokens/dist/modifiers.importance.css");
24
+ @import url("@canonical/design-tokens/dist/states.css");
25
+
26
+ /* Grid layout presets */
27
+ @import url("./grid.css");
28
+
29
+ /* Spacing architecture tokens */
30
+ @import url("./spacing.css");
@@ -0,0 +1,118 @@
1
+ /* @canonical/styles — Spacing architecture tokens
2
+ *
3
+ * Provisional tokens implementing the spacing architecture spec v0.4.
4
+ * Two modes: element-owned (editorial) and container-owned (app UI).
5
+ * Will migrate to @canonical/design-tokens once validated.
6
+ *
7
+ * Terminology:
8
+ * block = vertical axis (block-start = top, block-end = bottom)
9
+ * inline = horizontal axis (inline-start = left in LTR, right in RTL)
10
+ *
11
+ * Convention: ALL available custom properties are listed here.
12
+ * Commented-out properties are valid extension points that consumers
13
+ * or themes may set; they are documented so the full API surface
14
+ * is visible in one place.
15
+ */
16
+
17
+ :root {
18
+ /* ── Baseline grid ──────────────────────────────────────────────── */
19
+ --space-baseline: var(
20
+ --dimension-size-height-baseline,
21
+ 0.5rem
22
+ ); /* 8px — bU */
23
+ --baseline-height: var(
24
+ --space-baseline
25
+ ); /* alias consumed by typography engine */
26
+
27
+ /* ── Spacing scale (semantic aliases) ───────────────────────────── */
28
+ --space-0: 0;
29
+ --space-025: var(--dimension-025); /* 0.125rem / 2px — micro */
30
+ --space-050: var(--dimension-050); /* 0.25rem / 4px — xxs */
31
+ --space-100: var(--dimension-100); /* 0.5rem / 8px — xs (1bU) */
32
+ --space-150: var(--dimension-150); /* 0.75rem / 12px — sm */
33
+ --space-200: var(--dimension-200); /* 1rem / 16px — md (2bU) */
34
+ --space-300: var(--dimension-300); /* 1.5rem / 24px — lg (3bU) */
35
+ --space-400: var(--dimension-400); /* 2rem / 32px — xl (4bU) */
36
+ --space-600: var(--dimension-600); /* 3rem / 48px — 2xl */
37
+ --space-800: var(--dimension-800); /* 4rem / 64px — 3xl */
38
+
39
+ /* ── Element-owned spacing (margin-block-end) ───────────────────── */
40
+ /* Direction: block-end (downward in horizontal writing modes). */
41
+ /* */
42
+ /* For typographic elements (h1-h6, p, .p), space-after is */
43
+ /* implemented in @canonical/styles-typography mapper.css as a */
44
+ /* unitless --space-after variable (in baseline-height units) */
45
+ /* consumed by the baseline engine: */
46
+ /* margin-bottom: calc(bottom-nudge + space-after × baseline-height) */
47
+ /* */
48
+ /* Default: --space-after: 0 on all elements (app UI contexts). */
49
+ /* Editorial/prose contexts opt in via the .editorial class: */
50
+ /* h1, h2: --space-after: 2 (= 2 × 0.5rem = 1rem = 16px) */
51
+ /* h3-h6, p: --space-after: 1 (= 1 × 0.5rem = 0.5rem = 8px) */
52
+ /* */
53
+ /* The tokens below are for NON-typographic elements. */
54
+ /* When the spacing architecture is finalised, the typography */
55
+ /* mapper should read FROM these tokens instead of hardcoding. */
56
+ --spaceAfter-button: var(--space-200); /* 1rem / 16px — block-end margin */
57
+ /* --spaceAfter-figure: var(--space-300); */ /* block-end margin for figures */
58
+ /* --spaceAfter-list: var(--space-200); */ /* block-end margin for ul/ol */
59
+ /* --spaceAfter-table: var(--space-300); */ /* block-end margin for tables */
60
+ /* --spaceAfter-hr: var(--space-400); */ /* block-end margin for <hr> */
61
+
62
+ /* ── Container-owned spacing (gap values) ───────────────────────── */
63
+ /* Used in application UI contexts: forms, dashboards, cards. */
64
+ /* These are axis-agnostic by default — containers apply them to */
65
+ /* whichever axis they need (block-direction gap for stacked forms, */
66
+ /* inline-direction gap for button rows, both for grids). */
67
+ --container-gap-tight: var(--space-050); /* 4px — dense key-value pairs */
68
+ --container-gap-default: var(--space-200); /* 16px — standard card/form gap */
69
+ --container-gap-loose: var(--space-300); /* 24px — sections, visual break */
70
+
71
+ /* Per-axis container gap overrides (set by consumers, not defined here): */
72
+ /* --container-gap-block: … ; */ /* block-direction gap override */
73
+ /* --container-gap-inline: … ; */ /* inline-direction gap override */
74
+
75
+ /* ── Intra-component spacing ────────────────────────────────────── */
76
+ /* Component-owned: internal padding regardless of context. */
77
+ --component-padding-block: var(
78
+ --space-100
79
+ ); /* 8px — block (vertical) padding */
80
+ --component-padding-inline: var(
81
+ --space-200
82
+ ); /* 16px — inline (horizontal) padding */
83
+
84
+ /* Per-side component padding overrides (set by themes/consumers): */
85
+ /* --component-padding-block-start: … ; */ /* top padding override */
86
+ /* --component-padding-block-end: … ; */ /* bottom padding override */
87
+ /* --component-padding-inline-start: … ; */ /* left (LTR) padding */
88
+ /* --component-padding-inline-end: … ; */ /* right (LTR) padding */
89
+
90
+ /* ── Layout grid ────────────────────────────────────────────────── */
91
+ --grid-gutter: var(
92
+ --space-200
93
+ ); /* 16px / 1rem — column gutters (inline-direction) */
94
+ --grid-margin: var(
95
+ --space-400
96
+ ); /* 32px / 2rem — outer page margin (inline-direction) */
97
+
98
+ /* Grid gap axis overrides (consumed by grid.css): */
99
+ /* --grid-gap: … ; */ /* shorthand: sets both row-gap and column-gap */
100
+ /* --grid-row-gap: … ; */ /* block-direction gap between grid rows */
101
+ /* --grid-column-gap: … ; */ /* inline-direction gap between grid columns */
102
+
103
+ /* ── Heading alignment ──────────────────────────────────────────── */
104
+ /* Inline padding for headings to align with padded blocks. */
105
+ /* --heading-padding-inline: … ; */ /* set by layout context, default 0 */
106
+ }
107
+
108
+ /* ── Content-flow container ─────────────────────────────────────── */
109
+
110
+ @layer ds.components {
111
+ /* Content-flow container: establishes element-owned spacing context.
112
+ * Children use their own margin-bottom; last child is reset to 0
113
+ * to prevent double spacing at the container boundary.
114
+ */
115
+ .content-flow > :last-child {
116
+ margin-bottom: 0;
117
+ }
118
+ }