@adrienlcp/styles 0.2.0 → 0.4.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
@@ -13,8 +13,8 @@ pnpm add @adrienlcp/styles
13
13
 
14
14
  | File | Does |
15
15
  | --- | --- |
16
- | `reset.css` | Box sizing, zeroed margins and paddings, inherited fonts on controls, bare buttons and lists, balanced headings, pretty paragraphs. Inside `@layer reset` |
17
- | `reduced-motion.css` | Collapses `--transition-fast`, `--transition-base` and `--transition-slow` to `0ms` under `prefers-reduced-motion: reduce`. Unlayered, so it beats the tokens wherever they are defined |
16
+ | `reset.css` | Box sizing, zeroed margins and paddings, inherited fonts on controls, bare buttons and lists, balanced headings, pretty paragraphs, and `interpolate-size: allow-keywords` so a transition reaches `height: auto` (Chromium; elsewhere the size snaps as before). Inside `@layer reset` |
17
+ | `reduced-motion.css` | Collapses `--transition-fast`, `--transition-base` and `--transition-slow` to `0ms` under `prefers-reduced-motion: reduce`, and stills view transitions, which React's `<ViewTransition>` starts whatever the preference. Unlayered, so it beats the tokens wherever they are defined |
18
18
 
19
19
  Import them once — from JavaScript, or from the global stylesheet in Sass:
20
20
 
@@ -32,14 +32,48 @@ stylesheet loads, so the reset stays under every component rule —
32
32
  Resolved through the `sass` export condition, which Vite reads; with the Sass
33
33
  CLI, use `pkg:@adrienlcp/styles/breakpoints` and `--pkg-importer=node`.
34
34
 
35
+ ### `containers`
36
+
37
+ A component answers the room it is given, not the screen: the same card
38
+ lays out the same way in a sidebar on a desktop and full width on a phone.
39
+
40
+ ```sass
41
+ @use '@adrienlcp/styles/containers'
42
+
43
+ .card
44
+ @include containers.container
45
+
46
+ .card-body
47
+ @include containers.container-wide(30rem)
48
+ grid-template-columns: auto 1fr
49
+ ```
50
+
51
+ - `container($name: null)` sets `container-type: inline-size`, and
52
+ `container-name` when given one.
53
+ - `container-wide($width, $name: null)` is `width >= $width` on the nearest
54
+ container, or on the one named; `container-narrow` is its exact complement.
55
+ - **An element queries an ancestor, never itself** — the container wraps what
56
+ changes.
57
+ - **A container no longer takes its width from its content**: inside a flex row
58
+ without a width, an `auto` grid track or an absolutely positioned box, it
59
+ collapses to zero. Its parent gives it a width.
60
+ - **With no container above, neither mixin matches.** Make `body` one in the
61
+ global stylesheet, so an unwrapped component falls back to the page width;
62
+ `position: fixed` stays on the viewport.
63
+ - The width is Sass interpolated into `@container`, so pass a value, not a
64
+ custom property — `@container` cannot read one either.
65
+
35
66
  ### `breakpoints`
36
67
 
68
+ For what depends on the device rather than the room a component has: the page
69
+ shell, a sidebar that turns into a drawer, an overlay pinned to the viewport.
70
+
37
71
  ```sass
38
72
  @use '@adrienlcp/styles/breakpoints'
39
73
 
40
- .page
74
+ .shell
41
75
  @include breakpoints.wide
42
- grid-template-columns: 1fr 1fr
76
+ grid-template-columns: 16rem 1fr
43
77
  ```
44
78
 
45
79
  `$wide-screen` is `900px`; `wide` is `width >= $wide-screen` and `narrow` its
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Adrien Lacourpaille",
3
3
  "bugs": "https://github.com/AdrienLcp/packages/issues",
4
- "description": "A reset, a reduced-motion switch, and Sass mixins for self-hosted fonts and a breakpoint",
4
+ "description": "A reset, a reduced-motion switch, and Sass mixins for self-hosted fonts, container queries and a breakpoint",
5
5
  "devDependencies": {
6
6
  "sass": "^1.105.0"
7
7
  },
@@ -9,6 +9,9 @@
9
9
  "./breakpoints": {
10
10
  "sass": "./src/_breakpoints.sass"
11
11
  },
12
+ "./containers": {
13
+ "sass": "./src/_containers.sass"
14
+ },
12
15
  "./fonts": {
13
16
  "sass": "./src/_fonts.sass"
14
17
  },
@@ -46,7 +49,7 @@
46
49
  "*.css"
47
50
  ],
48
51
  "type": "module",
49
- "version": "0.2.0",
52
+ "version": "0.4.0",
50
53
  "scripts": {
51
54
  "test": "vitest run",
52
55
  "test:watch": "vitest --watch"
@@ -1,6 +1,8 @@
1
1
  /// Where a screen stops being a phone's. A media query cannot read a custom
2
2
  /// property, so the breakpoint is a Sass value; override it with
3
3
  /// `@use '@adrienlcp/styles/breakpoints' with ($wide-screen: 1024px)`.
4
+ /// Only for what depends on the device — the page shell, a fixed overlay; a
5
+ /// component answers its container through `containers`.
4
6
  $wide-screen: 900px !default
5
7
 
6
8
  /// `wide` and `narrow` are exact complements: every width is one or the other.
@@ -0,0 +1,24 @@
1
+ /// Makes the element a container its descendants query by inline size. It can
2
+ /// no longer take its width from its content, so its parent gives it one —
3
+ /// a block, a stretched flex or grid item, a sized track.
4
+ @mixin container($name: null)
5
+ container-type: inline-size
6
+ @if $name
7
+ container-name: $name
8
+
9
+ /// Matches when the nearest container — or the one named — is at least
10
+ /// `$width` wide. With no container above, neither this nor
11
+ /// `container-narrow` matches.
12
+ @mixin container-wide($width, $name: null)
13
+ @container #{_condition($name, 'width >= #{$width}')}
14
+ @content
15
+
16
+ /// The exact complement of `container-wide` for the same `$width` and `$name`.
17
+ @mixin container-narrow($width, $name: null)
18
+ @container #{_condition($name, 'width < #{$width}')}
19
+ @content
20
+
21
+ @function _condition($name, $feature)
22
+ @if $name
23
+ @return '#{$name} (#{$feature})'
24
+ @return '(#{$feature})'
@@ -5,4 +5,11 @@
5
5
  --transition-base: 0ms;
6
6
  --transition-slow: 0ms;
7
7
  }
8
+
9
+ /* React's <ViewTransition> starts one whatever the preference: it still swaps, without moving. */
10
+ ::view-transition-group(*),
11
+ ::view-transition-old(*),
12
+ ::view-transition-new(*) {
13
+ animation: none;
14
+ }
8
15
  }
package/src/reset.css CHANGED
@@ -11,6 +11,7 @@
11
11
  }
12
12
 
13
13
  html {
14
+ interpolate-size: allow-keywords;
14
15
  -webkit-text-size-adjust: 100%;
15
16
  text-size-adjust: 100%;
16
17
  }