@ismailnakkar/ui-behaviours 0.7.1 → 0.8.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
@@ -8,8 +8,9 @@ the document, so markup added later works too. A `post()` helper sends a page sc
8
8
  one.
9
9
 
10
10
  A date range picker over [Cally](https://wicky.nillia.ms/cally/) has its own entry, so pages without one never load the
11
- calendar, and an optional stylesheet themed by custom properties. Nothing else ships styles, and nothing ships wording:
12
- the app styles the states the package sets, and every word comes from the app's markup.
11
+ calendar, and an optional stylesheet themed by custom properties. A second optional stylesheet draws
12
+ [scrollbars](#scrollbars) that stay in sight. Nothing else ships styles, and nothing ships wording: the app styles the
13
+ states the package sets, and every word comes from the app's markup.
13
14
 
14
15
  ## Install
15
16
 
@@ -397,6 +398,49 @@ The package sets attributes and the browser's own states; the app styles them:
397
398
  - A `data-dropdown`'s `<summary>` is its button: put the menu's name in it, and a `<details>` says itself whether it is
398
399
  open.
399
400
 
401
+ ## Scrollbars
402
+
403
+ On macOS a scrollbar shows only while the box moves, so a box cut short by a `max-height` reads as the whole list. The
404
+ scrollbar stylesheet draws a slim bar that stays in sight whenever a box with the `scrollbar` class overflows, in
405
+ Chrome, Edge and Safari. Firefox gets a thin bar in the same colours and keeps the system's choice of when to show it.
406
+ Import it once, from the page's script or the app's CSS:
407
+
408
+ ```js
409
+ import '@ismailnakkar/ui-behaviours/scrollbar.css';
410
+ ```
411
+
412
+ ```css
413
+ @import '@ismailnakkar/ui-behaviours/scrollbar.css' layer(components);
414
+ ```
415
+
416
+ Then give the scrolling box the class:
417
+
418
+ ```html
419
+ <div class="scrollbar" style="max-height: 32rem; overflow-y: auto">…</div>
420
+ ```
421
+
422
+ A Sass stylesheet can load it as a module and extend the class onto its own selectors instead of adding it to markup:
423
+
424
+ ```scss
425
+ @use '@ismailnakkar/ui-behaviours/scrollbar.css';
426
+
427
+ .sidebar {
428
+ overflow-y: auto;
429
+ @extend .scrollbar;
430
+ }
431
+ ```
432
+
433
+ Three custom properties theme it, set on `:root` for every bar or on a box for its own:
434
+
435
+ | Property | Default | Is |
436
+ |---|---|---|
437
+ | `--scrollbar-size` | `0.5rem` | the bar's width, or height along the bottom, and its thumb's corner radius |
438
+ | `--scrollbar-thumb-color` | `#b4bac9` | the part that moves |
439
+ | `--scrollbar-track-color` | `transparent` | the groove behind it, and the corner where two bars meet |
440
+
441
+ Set no `scrollbar-width` or `scrollbar-color` of your own on the box: Chrome 121+ draws its plain bar once either is
442
+ set, and ignores the stylesheet's.
443
+
400
444
  ## Range picker
401
445
 
402
446
  A date range for a GET form: a button opens a native popover with the app's preset ranges beside a Cally
@@ -600,6 +644,7 @@ stylesheet does.
600
644
  | `post(url, body)` | `fetch()`es a `FormData` or `URLSearchParams` body to `url` as a POST that Laravel answers as an AJAX request; resolves to the `Response` |
601
645
  | `installRangePicker()`, from `@ismailnakkar/ui-behaviours/range-picker` | listens on the document for range pickers and writes those already on the page; later calls do nothing |
602
646
  | `@ismailnakkar/ui-behaviours/range-picker.css` | the range picker's [stylesheet](#styling-the-picker) |
647
+ | `@ismailnakkar/ui-behaviours/scrollbar.css` | the `scrollbar` class's [stylesheet](#scrollbars) |
603
648
 
604
649
  `copyText()` serves a page's own script, copying a link it just made:
605
650
 
@@ -666,6 +711,11 @@ Run this package's suite with `npm test`: oxlint, then Vitest.
666
711
 
667
712
  ## Upgrading
668
713
 
714
+ ### From 0.7
715
+
716
+ Nothing changes for a page on 0.7. The new [scrollbar stylesheet](#scrollbars) is opt-in: a page that never imports it
717
+ looks the same.
718
+
669
719
  ### From 0.7.0
670
720
 
671
721
  Nothing changes for a page on 0.7.0. `<main>` and a stepper's headings no longer need `tabindex="-1"` in the markup
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ismailnakkar/ui-behaviours",
3
- "version": "0.7.1",
4
- "description": "Page behaviours from plain HTML attributes (copy with a spoken result, confirm, submit once or on a change, native dialogs, steps, show by a radio, checkbox or select, check all, autoselect, dismiss a banner, light-dismiss a details menu), a Laravel-ready post(), and a date range picker over Cally with an optional stylesheet.",
3
+ "version": "0.8.0",
4
+ "description": "Page behaviours from plain HTML attributes (copy with a spoken result, confirm, submit once or on a change, native dialogs, steps, show by a radio, checkbox or select, check all, autoselect, dismiss a banner, light-dismiss a details menu), a Laravel-ready post(), a date range picker over Cally with an optional stylesheet, and an optional scrollbar stylesheet.",
5
5
  "keywords": [
6
6
  "clipboard",
7
7
  "dialog",
@@ -13,7 +13,8 @@
13
13
  "dropdown",
14
14
  "dismiss",
15
15
  "fetch",
16
- "laravel"
16
+ "laravel",
17
+ "scrollbar"
17
18
  ],
18
19
  "homepage": "https://github.com/ismailnakkar/ui-behaviours",
19
20
  "bugs": {
@@ -43,6 +44,10 @@
43
44
  "./range-picker.css": {
44
45
  "types": "./src/range-picker.d.css.ts",
45
46
  "default": "./src/range-picker.css"
47
+ },
48
+ "./scrollbar.css": {
49
+ "types": "./src/scrollbar.d.css.ts",
50
+ "default": "./src/scrollbar.css"
46
51
  }
47
52
  },
48
53
  "files": [
@@ -50,7 +55,8 @@
50
55
  ],
51
56
  "sideEffects": [
52
57
  "./src/range-picker.js",
53
- "./src/range-picker.css"
58
+ "./src/range-picker.css",
59
+ "./src/scrollbar.css"
54
60
  ],
55
61
  "publishConfig": {
56
62
  "access": "public"
@@ -0,0 +1,38 @@
1
+ /*
2
+ * A styled scrollbar (README, "Scrollbars"): on any box with the `scrollbar` class, a slim bar that stays drawn while
3
+ * the box overflows, where macOS would otherwise show one only during a scroll. Every app value is a custom property;
4
+ * the defaults sit in :where(:root), so any rule of the app's wins, and a box may set its own.
5
+ *
6
+ * Chromium and Safari draw the ::-webkit-scrollbar parts. Firefox gets the standard pair, and only there: Chrome 121+
7
+ * reads scrollbar-width and scrollbar-color too, and once either is set it ignores every ::-webkit-scrollbar rule.
8
+ */
9
+ :where(:root) {
10
+ --scrollbar-size: 0.5rem;
11
+ --scrollbar-thumb-color: #b4bac9;
12
+ --scrollbar-track-color: transparent;
13
+ }
14
+
15
+ .scrollbar::-webkit-scrollbar {
16
+ width: var(--scrollbar-size);
17
+ height: var(--scrollbar-size);
18
+ }
19
+
20
+ .scrollbar::-webkit-scrollbar-track {
21
+ background: var(--scrollbar-track-color);
22
+ }
23
+
24
+ .scrollbar::-webkit-scrollbar-thumb {
25
+ border-radius: var(--scrollbar-size);
26
+ background: var(--scrollbar-thumb-color);
27
+ }
28
+
29
+ .scrollbar::-webkit-scrollbar-corner {
30
+ background: var(--scrollbar-track-color);
31
+ }
32
+
33
+ @supports not selector(::-webkit-scrollbar) {
34
+ .scrollbar {
35
+ scrollbar-width: thin;
36
+ scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
37
+ }
38
+ }
@@ -0,0 +1,2 @@
1
+ // Lets TypeScript accept `import '…/scrollbar.css'` without the app declaring *.css modules.
2
+ export {};