@adrienlcp/styles 0.1.0 → 0.3.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,7 +13,7 @@ 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` |
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
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 |
18
18
 
19
19
  Import them once — from JavaScript, or from the global stylesheet in Sass:
@@ -30,45 +30,55 @@ stylesheet loads, so the reset stays under every component rule —
30
30
  ## Sass
31
31
 
32
32
  Resolved through the `sass` export condition, which Vite reads; with the Sass
33
- CLI, use `pkg:@adrienlcp/styles/focus` and `--pkg-importer=node`.
33
+ CLI, use `pkg:@adrienlcp/styles/breakpoints` and `--pkg-importer=node`.
34
34
 
35
- ### `breakpoints`
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.
36
39
 
37
40
  ```sass
38
- @use '@adrienlcp/styles/breakpoints'
41
+ @use '@adrienlcp/styles/containers'
39
42
 
40
- .page
41
- @include breakpoints.wide
42
- grid-template-columns: 1fr 1fr
43
+ .card
44
+ @include containers.container
45
+
46
+ .card-body
47
+ @include containers.container-wide(30rem)
48
+ grid-template-columns: auto 1fr
43
49
  ```
44
50
 
45
- `$wide-screen` is `900px`; `wide` is `width >= $wide-screen` and `narrow` its
46
- exact complement. Another value: `@use '@adrienlcp/styles/breakpoints' with
47
- ($wide-screen: 1024px)`.
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.
48
65
 
49
- ### `focus`
66
+ ### `breakpoints`
50
67
 
51
- `ring` and `ring-inset` draw the outline on `[data-focus-visible]` (react-aria)
52
- and `:focus-visible` (a native element). `hovered` wraps a hover style in
53
- `(hover: hover) and (pointer: fine)`, since a touch screen replays hover after a
54
- tap and leaves it stuck; `$except` skips a state.
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.
55
70
 
56
71
  ```sass
57
- @use '@adrienlcp/styles/focus'
58
-
59
- .button
60
- @include focus.ring
72
+ @use '@adrienlcp/styles/breakpoints'
61
73
 
62
- @include focus.hovered($except: '[data-disabled]')
63
- background: var(--hover)
74
+ .shell
75
+ @include breakpoints.wide
76
+ grid-template-columns: 16rem 1fr
64
77
  ```
65
78
 
66
- Configure the ring once, in the app's own `_focus.sass`, and have components
67
- `@use` that file:
68
-
69
- ```sass
70
- @forward '@adrienlcp/styles/focus' with ($ring-color: var(--focus), $ring-offset: 3px, $ring-width: 3px)
71
- ```
79
+ `$wide-screen` is `900px`; `wide` is `width >= $wide-screen` and `narrow` its
80
+ exact complement. Another value: `@use '@adrienlcp/styles/breakpoints' with
81
+ ($wide-screen: 1024px)`.
72
82
 
73
83
  ### `fonts`
74
84
 
package/package.json CHANGED
@@ -1,58 +1,57 @@
1
- {
2
- "author": "Adrien Lacourpaille",
3
- "bugs": "https://github.com/AdrienLcp/packages/issues",
4
- "description": "A reset, a reduced-motion switch, and Sass mixins for self-hosted fonts, a breakpoint, focus rings and pointer-only hover",
5
- "devDependencies": {
6
- "sass": "^1.105.0"
7
- },
8
- "exports": {
9
- "./breakpoints": {
10
- "sass": "./src/_breakpoints.sass"
11
- },
12
- "./focus": {
13
- "sass": "./src/_focus.sass"
14
- },
15
- "./fonts": {
16
- "sass": "./src/_fonts.sass"
17
- },
18
- "./package.json": "./package.json",
19
- "./reduced-motion.css": "./src/reduced-motion.css",
20
- "./reset.css": "./src/reset.css"
21
- },
22
- "files": [
23
- "src/*.css",
24
- "src/*.sass"
25
- ],
26
- "homepage": "https://github.com/AdrienLcp/packages/tree/main/packages/styles#readme",
27
- "keywords": [
28
- "css",
29
- "focus-visible",
30
- "font-face",
31
- "reset",
32
- "sass"
33
- ],
34
- "license": "MIT",
35
- "name": "@adrienlcp/styles",
36
- "peerDependencies": {
37
- "sass": ">=1.80.0"
38
- },
39
- "peerDependenciesMeta": {
40
- "sass": {
41
- "optional": true
42
- }
43
- },
44
- "repository": {
45
- "directory": "packages/styles",
46
- "type": "git",
47
- "url": "git+https://github.com/AdrienLcp/packages.git"
48
- },
49
- "scripts": {
50
- "test": "vitest run",
51
- "test:watch": "vitest --watch"
52
- },
53
- "sideEffects": [
54
- "*.css"
55
- ],
56
- "type": "module",
57
- "version": "0.1.0"
58
- }
1
+ {
2
+ "author": "Adrien Lacourpaille",
3
+ "bugs": "https://github.com/AdrienLcp/packages/issues",
4
+ "description": "A reset, a reduced-motion switch, and Sass mixins for self-hosted fonts, container queries and a breakpoint",
5
+ "devDependencies": {
6
+ "sass": "^1.105.0"
7
+ },
8
+ "exports": {
9
+ "./breakpoints": {
10
+ "sass": "./src/_breakpoints.sass"
11
+ },
12
+ "./containers": {
13
+ "sass": "./src/_containers.sass"
14
+ },
15
+ "./fonts": {
16
+ "sass": "./src/_fonts.sass"
17
+ },
18
+ "./package.json": "./package.json",
19
+ "./reduced-motion.css": "./src/reduced-motion.css",
20
+ "./reset.css": "./src/reset.css"
21
+ },
22
+ "files": [
23
+ "src/*.css",
24
+ "src/*.sass"
25
+ ],
26
+ "homepage": "https://github.com/AdrienLcp/packages/tree/main/packages/styles#readme",
27
+ "keywords": [
28
+ "css",
29
+ "font-face",
30
+ "reset",
31
+ "sass"
32
+ ],
33
+ "license": "MIT",
34
+ "name": "@adrienlcp/styles",
35
+ "peerDependencies": {
36
+ "sass": ">=1.80.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "sass": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "repository": {
44
+ "directory": "packages/styles",
45
+ "type": "git",
46
+ "url": "git+https://github.com/AdrienLcp/packages.git"
47
+ },
48
+ "sideEffects": [
49
+ "*.css"
50
+ ],
51
+ "type": "module",
52
+ "version": "0.3.0",
53
+ "scripts": {
54
+ "test": "vitest run",
55
+ "test:watch": "vitest --watch"
56
+ }
57
+ }
@@ -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})'
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
  }
package/src/_focus.sass DELETED
@@ -1,32 +0,0 @@
1
- /// Configure once, in the app's own `_focus.sass`:
2
- /// `@forward '@adrienlcp/styles/focus' with ($ring-color: var(--focus) !default)`.
3
- $ring-width: 2px !default
4
- $ring-color: currentColor !default
5
- $ring-offset: 3px !default
6
-
7
- /// react-aria stamps `data-focus-visible` on keyboard focus only; the
8
- /// `:focus-visible` twin covers a native element.
9
- @mixin ring
10
- &[data-focus-visible],
11
- &:focus-visible
12
- outline: $ring-width solid $ring-color
13
- outline-offset: $ring-offset
14
-
15
- /// The ring drawn inside the box, for an element a clipping ancestor would cut.
16
- @mixin ring-inset
17
- &[data-focus-visible],
18
- &:focus-visible
19
- outline: $ring-width solid $ring-color
20
- outline-offset: calc(-1 * $ring-width)
21
-
22
- /// Only a real pointer hovers: a touch screen replays hover after a tap and
23
- /// leaves it stuck until the next one. `$except` skips a state, as in
24
- /// `hovered($except: '[data-disabled]')`.
25
- @mixin hovered($except: null)
26
- @media (hover: hover) and (pointer: fine)
27
- @if $except
28
- &[data-hovered]:not(#{$except})
29
- @content
30
- @else
31
- &[data-hovered]
32
- @content