@nmnmcc/standard 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +516 -2
- package/dist/Extend.d.ts +15 -0
- package/dist/Extend.d.ts.map +1 -0
- package/dist/Extend.js +1 -0
- package/dist/Node.d.ts +71 -0
- package/dist/Node.d.ts.map +1 -0
- package/dist/Palette-BIJ96BEh.js +84 -0
- package/dist/Palette.d.ts +8 -0
- package/dist/Palette.d.ts.map +1 -0
- package/dist/Palette.js +1 -0
- package/dist/Standard-BPpzr5SM.js +488 -0
- package/dist/Standard.d.ts +249 -0
- package/dist/Standard.d.ts.map +1 -0
- package/dist/Standard.js +1 -0
- package/dist/Ui-B9xQqqNT.js +468 -0
- package/dist/Ui.d.ts +500 -0
- package/dist/Ui.d.ts.map +1 -0
- package/dist/Ui.js +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/rolldown-runtime-BMBA7GOT.js +10 -0
- package/dist/standard/button/button.d.ts +21 -0
- package/dist/standard/button/button.d.ts.map +1 -0
- package/dist/standard/colour/colour.d.ts +93 -0
- package/dist/standard/colour/colour.d.ts.map +1 -0
- package/dist/standard/field/field.d.ts +91 -0
- package/dist/standard/field/field.d.ts.map +1 -0
- package/dist/standard/form/form.d.ts +16 -0
- package/dist/standard/form/form.d.ts.map +1 -0
- package/dist/standard/icon/icon.d.ts +31 -0
- package/dist/standard/icon/icon.d.ts.map +1 -0
- package/dist/standard/image/image.d.ts +21 -0
- package/dist/standard/image/image.d.ts.map +1 -0
- package/dist/standard/layout/layout.d.ts +73 -0
- package/dist/standard/layout/layout.d.ts.map +1 -0
- package/dist/standard/list/list.d.ts +26 -0
- package/dist/standard/list/list.d.ts.map +1 -0
- package/dist/standard/page/page.d.ts +20 -0
- package/dist/standard/page/page.d.ts.map +1 -0
- package/dist/standard/table/table.d.ts +18 -0
- package/dist/standard/table/table.d.ts.map +1 -0
- package/dist/standard/text/text.d.ts +39 -0
- package/dist/standard/text/text.d.ts.map +1 -0
- package/dist/standard/tokens/classes.d.ts +16 -0
- package/dist/standard/tokens/classes.d.ts.map +1 -0
- package/dist/standard/tokens/tokens.d.ts +162 -0
- package/dist/standard/tokens/tokens.d.ts.map +1 -0
- package/dist/standard.css +2 -0
- package/dist/ui/arrow/arrow.d.ts +18 -0
- package/dist/ui/arrow/arrow.d.ts.map +1 -0
- package/dist/ui/avatar/avatar.d.ts +15 -0
- package/dist/ui/avatar/avatar.d.ts.map +1 -0
- package/dist/ui/board/board.d.ts +34 -0
- package/dist/ui/board/board.d.ts.map +1 -0
- package/dist/ui/bullet/bullet.d.ts +15 -0
- package/dist/ui/bullet/bullet.d.ts.map +1 -0
- package/dist/ui/card/card.d.ts +24 -0
- package/dist/ui/card/card.d.ts.map +1 -0
- package/dist/ui/carousel/carousel.d.ts +17 -0
- package/dist/ui/carousel/carousel.d.ts.map +1 -0
- package/dist/ui/check/check.d.ts +20 -0
- package/dist/ui/check/check.d.ts.map +1 -0
- package/dist/ui/choice/choice.d.ts +19 -0
- package/dist/ui/choice/choice.d.ts.map +1 -0
- package/dist/ui/control/control.d.ts +57 -0
- package/dist/ui/control/control.d.ts.map +1 -0
- package/dist/ui/dialog/dialog.d.ts +30 -0
- package/dist/ui/dialog/dialog.d.ts.map +1 -0
- package/dist/ui/disclosure/disclosure.d.ts +20 -0
- package/dist/ui/disclosure/disclosure.d.ts.map +1 -0
- package/dist/ui/flap/flap.d.ts +18 -0
- package/dist/ui/flap/flap.d.ts.map +1 -0
- package/dist/ui/item/item.d.ts +21 -0
- package/dist/ui/item/item.d.ts.map +1 -0
- package/dist/ui/key/key.d.ts +12 -0
- package/dist/ui/key/key.d.ts.map +1 -0
- package/dist/ui/menu/menu.d.ts +26 -0
- package/dist/ui/menu/menu.d.ts.map +1 -0
- package/dist/ui/modal/modal.d.ts +22 -0
- package/dist/ui/modal/modal.d.ts.map +1 -0
- package/dist/ui/navigator/navigator.d.ts +137 -0
- package/dist/ui/navigator/navigator.d.ts.map +1 -0
- package/dist/ui/notice/notice.d.ts +34 -0
- package/dist/ui/notice/notice.d.ts.map +1 -0
- package/dist/ui/options/options.d.ts +19 -0
- package/dist/ui/options/options.d.ts.map +1 -0
- package/dist/ui/pager/pager.d.ts +29 -0
- package/dist/ui/pager/pager.d.ts.map +1 -0
- package/dist/ui/pagination/pagination.d.ts +14 -0
- package/dist/ui/pagination/pagination.d.ts.map +1 -0
- package/dist/ui/popover/popover.d.ts +20 -0
- package/dist/ui/popover/popover.d.ts.map +1 -0
- package/dist/ui/progress/progress.d.ts +17 -0
- package/dist/ui/progress/progress.d.ts.map +1 -0
- package/dist/ui/route/route.d.ts +27 -0
- package/dist/ui/route/route.d.ts.map +1 -0
- package/dist/ui/sheet/sheet.d.ts +35 -0
- package/dist/ui/sheet/sheet.d.ts.map +1 -0
- package/dist/ui/skeleton/skeleton.d.ts +15 -0
- package/dist/ui/skeleton/skeleton.d.ts.map +1 -0
- package/dist/ui/slider/slider.d.ts +23 -0
- package/dist/ui/slider/slider.d.ts.map +1 -0
- package/dist/ui/stepper/stepper.d.ts +32 -0
- package/dist/ui/stepper/stepper.d.ts.map +1 -0
- package/dist/ui/tabs/tabs.d.ts +22 -0
- package/dist/ui/tabs/tabs.d.ts.map +1 -0
- package/dist/ui/tag/tag.d.ts +17 -0
- package/dist/ui/tag/tag.d.ts.map +1 -0
- package/dist/ui/tile/tile.d.ts +38 -0
- package/dist/ui/tile/tile.d.ts.map +1 -0
- package/dist/ui/toasts/toasts.d.ts +17 -0
- package/dist/ui/toasts/toasts.d.ts.map +1 -0
- package/dist/ui/toggle/toggle.d.ts +17 -0
- package/dist/ui/toggle/toggle.d.ts.map +1 -0
- package/dist/ui/trail/trail.d.ts +22 -0
- package/dist/ui/trail/trail.d.ts.map +1 -0
- package/package.json +70 -3
- package/src/Extend.ts +14 -0
- package/src/Node.ts +44 -0
- package/src/Palette.ts +7 -0
- package/src/Standard.ts +109 -0
- package/src/Ui.ts +156 -0
- package/src/index.ts +27 -0
- package/src/standard/button/button.module.css +43 -0
- package/src/standard/button/button.module.d.css.ts +6 -0
- package/src/standard/button/button.ts +38 -0
- package/src/standard/colour/colour.ts +197 -0
- package/src/standard/field/field.module.css +222 -0
- package/src/standard/field/field.module.d.css.ts +13 -0
- package/src/standard/field/field.ts +266 -0
- package/src/standard/form/form.ts +25 -0
- package/src/standard/icon/icon.module.css +349 -0
- package/src/standard/icon/icon.module.d.css.ts +112 -0
- package/src/standard/icon/icon.ts +148 -0
- package/src/standard/image/image.module.css +42 -0
- package/src/standard/image/image.module.d.css.ts +12 -0
- package/src/standard/image/image.ts +39 -0
- package/src/standard/layout/layout.module.css +224 -0
- package/src/standard/layout/layout.module.d.css.ts +41 -0
- package/src/standard/layout/layout.ts +133 -0
- package/src/standard/list/list.module.css +71 -0
- package/src/standard/list/list.module.d.css.ts +10 -0
- package/src/standard/list/list.ts +53 -0
- package/src/standard/page/page.module.css +244 -0
- package/src/standard/page/page.module.d.css.ts +9 -0
- package/src/standard/page/page.ts +32 -0
- package/src/standard/table/table.module.css +40 -0
- package/src/standard/table/table.module.d.css.ts +6 -0
- package/src/standard/table/table.ts +36 -0
- package/src/standard/text/text.module.css +149 -0
- package/src/standard/text/text.module.d.css.ts +19 -0
- package/src/standard/text/text.ts +77 -0
- package/src/standard/tokens/classes.ts +31 -0
- package/src/standard/tokens/tokens.module.css +294 -0
- package/src/standard/tokens/tokens.module.d.css.ts +40 -0
- package/src/standard/tokens/tokens.ts +339 -0
- package/src/ui/arrow/arrow.module.css +38 -0
- package/src/ui/arrow/arrow.module.d.css.ts +13 -0
- package/src/ui/arrow/arrow.ts +35 -0
- package/src/ui/avatar/avatar.module.css +25 -0
- package/src/ui/avatar/avatar.module.d.css.ts +5 -0
- package/src/ui/avatar/avatar.ts +28 -0
- package/src/ui/board/board.module.css +94 -0
- package/src/ui/board/board.module.d.css.ts +10 -0
- package/src/ui/board/board.ts +84 -0
- package/src/ui/bullet/bullet.module.css +28 -0
- package/src/ui/bullet/bullet.module.d.css.ts +5 -0
- package/src/ui/bullet/bullet.ts +16 -0
- package/src/ui/card/card.module.css +80 -0
- package/src/ui/card/card.module.d.css.ts +6 -0
- package/src/ui/card/card.ts +42 -0
- package/src/ui/carousel/carousel.module.css +24 -0
- package/src/ui/carousel/carousel.module.d.css.ts +5 -0
- package/src/ui/carousel/carousel.ts +30 -0
- package/src/ui/check/check.module.css +53 -0
- package/src/ui/check/check.module.d.css.ts +8 -0
- package/src/ui/check/check.ts +46 -0
- package/src/ui/choice/choice.module.css +32 -0
- package/src/ui/choice/choice.module.d.css.ts +6 -0
- package/src/ui/choice/choice.ts +31 -0
- package/src/ui/control/control.module.css +127 -0
- package/src/ui/control/control.module.d.css.ts +12 -0
- package/src/ui/control/control.ts +97 -0
- package/src/ui/dialog/dialog.module.css +42 -0
- package/src/ui/dialog/dialog.module.d.css.ts +6 -0
- package/src/ui/dialog/dialog.ts +44 -0
- package/src/ui/disclosure/disclosure.module.css +57 -0
- package/src/ui/disclosure/disclosure.module.d.css.ts +7 -0
- package/src/ui/disclosure/disclosure.ts +32 -0
- package/src/ui/flap/flap.module.css +161 -0
- package/src/ui/flap/flap.module.d.css.ts +48 -0
- package/src/ui/flap/flap.ts +78 -0
- package/src/ui/item/item.module.css +39 -0
- package/src/ui/item/item.module.d.css.ts +7 -0
- package/src/ui/item/item.ts +33 -0
- package/src/ui/key/key.module.css +15 -0
- package/src/ui/key/key.module.d.css.ts +5 -0
- package/src/ui/key/key.ts +13 -0
- package/src/ui/menu/menu.module.css +11 -0
- package/src/ui/menu/menu.module.d.css.ts +5 -0
- package/src/ui/menu/menu.ts +48 -0
- package/src/ui/modal/modal.module.css +66 -0
- package/src/ui/modal/modal.module.d.css.ts +8 -0
- package/src/ui/modal/modal.ts +55 -0
- package/src/ui/navigator/navigator.module.css +658 -0
- package/src/ui/navigator/navigator.module.d.css.ts +39 -0
- package/src/ui/navigator/navigator.ts +337 -0
- package/src/ui/notice/notice.module.css +80 -0
- package/src/ui/notice/notice.module.d.css.ts +10 -0
- package/src/ui/notice/notice.ts +57 -0
- package/src/ui/options/options.module.css +30 -0
- package/src/ui/options/options.module.d.css.ts +6 -0
- package/src/ui/options/options.ts +31 -0
- package/src/ui/pager/pager.module.css +38 -0
- package/src/ui/pager/pager.module.d.css.ts +8 -0
- package/src/ui/pager/pager.ts +48 -0
- package/src/ui/pagination/pagination.module.css +38 -0
- package/src/ui/pagination/pagination.module.d.css.ts +7 -0
- package/src/ui/pagination/pagination.ts +52 -0
- package/src/ui/popover/popover.module.css +94 -0
- package/src/ui/popover/popover.module.d.css.ts +8 -0
- package/src/ui/popover/popover.ts +139 -0
- package/src/ui/progress/progress.module.css +69 -0
- package/src/ui/progress/progress.module.d.css.ts +6 -0
- package/src/ui/progress/progress.ts +26 -0
- package/src/ui/route/route.module.css +116 -0
- package/src/ui/route/route.module.d.css.ts +11 -0
- package/src/ui/route/route.ts +58 -0
- package/src/ui/sheet/sheet.module.css +194 -0
- package/src/ui/sheet/sheet.module.d.css.ts +7 -0
- package/src/ui/sheet/sheet.ts +47 -0
- package/src/ui/skeleton/skeleton.module.css +44 -0
- package/src/ui/skeleton/skeleton.module.d.css.ts +6 -0
- package/src/ui/skeleton/skeleton.ts +20 -0
- package/src/ui/slider/slider.module.css +56 -0
- package/src/ui/slider/slider.module.d.css.ts +6 -0
- package/src/ui/slider/slider.ts +48 -0
- package/src/ui/stepper/stepper.module.css +32 -0
- package/src/ui/stepper/stepper.module.d.css.ts +7 -0
- package/src/ui/stepper/stepper.ts +62 -0
- package/src/ui/tabs/tabs.module.css +38 -0
- package/src/ui/tabs/tabs.module.d.css.ts +6 -0
- package/src/ui/tabs/tabs.ts +24 -0
- package/src/ui/tag/tag.module.css +23 -0
- package/src/ui/tag/tag.module.d.css.ts +5 -0
- package/src/ui/tag/tag.ts +17 -0
- package/src/ui/tile/tile.module.css +137 -0
- package/src/ui/tile/tile.module.d.css.ts +13 -0
- package/src/ui/tile/tile.ts +69 -0
- package/src/ui/toasts/toasts.module.css +38 -0
- package/src/ui/toasts/toasts.module.d.css.ts +6 -0
- package/src/ui/toasts/toasts.ts +26 -0
- package/src/ui/toggle/toggle.module.css +46 -0
- package/src/ui/toggle/toggle.module.d.css.ts +6 -0
- package/src/ui/toggle/toggle.ts +29 -0
- package/src/ui/trail/trail.module.css +42 -0
- package/src/ui/trail/trail.module.d.css.ts +5 -0
- package/src/ui/trail/trail.ts +28 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* pagination: which page of several, by number. */
|
|
2
|
+
|
|
3
|
+
@layer standard.ui {
|
|
4
|
+
/* Which page of several, by number. */
|
|
5
|
+
.pagination {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
list-style: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.page-item {
|
|
12
|
+
display: grid;
|
|
13
|
+
place-items: center;
|
|
14
|
+
min-inline-size: var(--s-target);
|
|
15
|
+
padding-inline: var(--s-unit);
|
|
16
|
+
background: color-mix(in oklch, var(--s-fg) var(--s-ui-press), transparent);
|
|
17
|
+
/* A page that can be gone to is in the text's colour; only an arrow with nowhere to go is muted. */
|
|
18
|
+
color: var(--s-fg);
|
|
19
|
+
font-weight: 700;
|
|
20
|
+
font-variant-numeric: tabular-nums;
|
|
21
|
+
|
|
22
|
+
&[aria-current="page"] {
|
|
23
|
+
background: var(--s-mark);
|
|
24
|
+
color: var(--s-on-mark);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:disabled {
|
|
28
|
+
color: var(--s-muted);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.gap {
|
|
33
|
+
display: grid;
|
|
34
|
+
place-items: center;
|
|
35
|
+
min-inline-size: calc(3 * var(--s-unit));
|
|
36
|
+
color: var(--s-muted);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pagination`: which page of several, by number.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.4.0
|
|
5
|
+
*/
|
|
6
|
+
import type { View } from "effect/ui"
|
|
7
|
+
import type { Html } from "effect/ui/html"
|
|
8
|
+
import { node, type Node } from "../../Node.ts"
|
|
9
|
+
import { arrowOf } from "../arrow/arrow.ts"
|
|
10
|
+
import control from "../control/control.module.css"
|
|
11
|
+
import styles from "./pagination.module.css"
|
|
12
|
+
|
|
13
|
+
export const pagination = <Msg>(h: Html.H<Msg>) => ({
|
|
14
|
+
/** Which page of several, by number, with the pages next to the current one, and both ends. */
|
|
15
|
+
pagination: (options: {
|
|
16
|
+
readonly label: string
|
|
17
|
+
readonly page: number
|
|
18
|
+
readonly count: number
|
|
19
|
+
readonly onChange: (page: number) => Msg
|
|
20
|
+
readonly previous: string
|
|
21
|
+
readonly next: string
|
|
22
|
+
}): Node<"block", Msg> => {
|
|
23
|
+
const { count, page } = options
|
|
24
|
+
const shown = Array.from({ length: count }, (_, index) => index + 1).filter(
|
|
25
|
+
(n) => n === 1 || n === count || Math.abs(n - page) <= 1
|
|
26
|
+
)
|
|
27
|
+
const button = (to: number, content: View.Input<Msg>, label?: string) =>
|
|
28
|
+
h.button
|
|
29
|
+
.class(control.control, styles["page-item"])
|
|
30
|
+
.attr("type", "button")
|
|
31
|
+
.attr("aria-label", label)
|
|
32
|
+
.attr("aria-current", label === undefined && to === page ? "page" : undefined)
|
|
33
|
+
.disabled(to < 1 || to > count)
|
|
34
|
+
.on("click", options.onChange(to))
|
|
35
|
+
.children(content)
|
|
36
|
+
return node(
|
|
37
|
+
h.nav.attr("aria-label", options.label).children(
|
|
38
|
+
h.ol.class(styles.pagination).children(
|
|
39
|
+
h.li.children(button(page - 1, arrowOf(h, "left"), options.previous)),
|
|
40
|
+
shown.flatMap((n, index) => [
|
|
41
|
+
// A run of pages left out is said once, between the pages on either side of it.
|
|
42
|
+
...(index > 0 && n - (shown[index - 1] ?? n) > 1
|
|
43
|
+
? [h.li.class(styles.gap).attr("aria-hidden", "true").children("…")]
|
|
44
|
+
: []),
|
|
45
|
+
h.li.children(button(n, String(n)))
|
|
46
|
+
]),
|
|
47
|
+
h.li.children(button(page + 1, arrowOf(h, "right"), options.next))
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* popover: more about something, next to the button that asked for it. */
|
|
2
|
+
|
|
3
|
+
@layer standard.ui {
|
|
4
|
+
.popover-root {
|
|
5
|
+
justify-self: start;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.trigger > :global(.s-ui-arrow) {
|
|
9
|
+
margin-inline-start: 0.5em;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* A button gives a little under a press. This one doesn't: what it opens
|
|
14
|
+
* is placed against it and is at least as wide as it, so a button that
|
|
15
|
+
* shrank would take its popover with it.
|
|
16
|
+
*/
|
|
17
|
+
.trigger:active:not(:disabled) {
|
|
18
|
+
scale: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Placed against its button by the browser: under it, or over it when
|
|
23
|
+
* that is where the room is. Which of the two is said on the root before
|
|
24
|
+
* it opens, so the arrow already points the way the popover will go, and
|
|
25
|
+
* the popover is drawn out of the button that way: down and back up, or
|
|
26
|
+
* up and back down. An edge moves; nothing fades.
|
|
27
|
+
*/
|
|
28
|
+
.popover {
|
|
29
|
+
inset: auto;
|
|
30
|
+
position-area: block-end span-inline-end;
|
|
31
|
+
position-try-fallbacks: flip-inline;
|
|
32
|
+
min-inline-size: anchor-size(inline);
|
|
33
|
+
max-inline-size: min(24rem, 100vi - 2 * var(--s-unit));
|
|
34
|
+
margin-block: calc(var(--s-unit) / 2);
|
|
35
|
+
/* A block of its own, with no frame: a step from the ground it hangs over, towards the text. */
|
|
36
|
+
background: color-mix(in oklch, var(--s-fg) 16%, var(--s-bg));
|
|
37
|
+
color: var(--s-fg);
|
|
38
|
+
overflow: auto;
|
|
39
|
+
clip-path: inset(0 0 100% 0);
|
|
40
|
+
transition:
|
|
41
|
+
clip-path var(--s-move) var(--s-ease),
|
|
42
|
+
display var(--s-move) allow-discrete,
|
|
43
|
+
overlay var(--s-move) allow-discrete;
|
|
44
|
+
|
|
45
|
+
&:popover-open {
|
|
46
|
+
display: grid;
|
|
47
|
+
grid-template-columns: minmax(0, 1fr);
|
|
48
|
+
clip-path: inset(0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@starting-style {
|
|
52
|
+
&:popover-open {
|
|
53
|
+
clip-path: inset(0 0 100% 0);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* While it is being measured, closed: laid out as it will be, and not seen. Nothing is painted in this state. */
|
|
59
|
+
.popover-root[data-measuring] > .popover {
|
|
60
|
+
display: grid;
|
|
61
|
+
grid-template-columns: minmax(0, 1fr);
|
|
62
|
+
visibility: hidden;
|
|
63
|
+
transition: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Up: over the button, drawn up out of it, and the arrow says so. */
|
|
67
|
+
.popover-root[data-face="up"] {
|
|
68
|
+
& > .trigger > :global(.s-ui-arrow) {
|
|
69
|
+
rotate: 0deg;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
& > .popover {
|
|
73
|
+
position-area: block-start span-inline-end;
|
|
74
|
+
clip-path: inset(100% 0 0 0);
|
|
75
|
+
|
|
76
|
+
&:popover-open {
|
|
77
|
+
clip-path: inset(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@starting-style {
|
|
81
|
+
&:popover-open {
|
|
82
|
+
clip-path: inset(100% 0 0 0);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.popover-body {
|
|
89
|
+
display: grid;
|
|
90
|
+
grid-template-columns: minmax(0, 1fr);
|
|
91
|
+
row-gap: calc(2 * var(--s-unit));
|
|
92
|
+
padding: calc(2 * var(--s-unit));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `popover`: more about something, behind one button, next to it.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.4.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect, Queue, Stream } from "effect"
|
|
7
|
+
import { Component, Mount, type View } from "effect/ui"
|
|
8
|
+
import type { Html } from "effect/ui/html"
|
|
9
|
+
import { type Child, contents as inner, type Kind, node, type Node } from "../../Node.ts"
|
|
10
|
+
import { look } from "../../standard/button/button.ts"
|
|
11
|
+
import { arrowOf } from "../arrow/arrow.ts"
|
|
12
|
+
import styles from "./popover.module.css"
|
|
13
|
+
|
|
14
|
+
/** Every time the size of one of some elements changes: the page growing as a typeface loads, a pane opening beside it. */
|
|
15
|
+
const resized = (...elements: ReadonlyArray<Element>): Stream.Stream<void> =>
|
|
16
|
+
Stream.callback<void>((queue) =>
|
|
17
|
+
Effect.acquireRelease(
|
|
18
|
+
Effect.sync(() => {
|
|
19
|
+
const observer = new ResizeObserver(() => Queue.offerUnsafe(queue, undefined))
|
|
20
|
+
elements.forEach((element) => observer.observe(element))
|
|
21
|
+
return observer
|
|
22
|
+
}),
|
|
23
|
+
(observer) => Effect.sync(() => observer.disconnect())
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
/** Every time something on the page is given another state: a class put on or taken off, as when a pane opens and moves the page. */
|
|
28
|
+
const restated = (within: Element): Stream.Stream<void> =>
|
|
29
|
+
Stream.callback<void>((queue) =>
|
|
30
|
+
Effect.acquireRelease(
|
|
31
|
+
Effect.sync(() => {
|
|
32
|
+
const observer = new MutationObserver(() => Queue.offerUnsafe(queue, undefined))
|
|
33
|
+
observer.observe(within, { attributes: true, attributeFilter: ["class"], subtree: true })
|
|
34
|
+
return observer
|
|
35
|
+
}),
|
|
36
|
+
(observer) => Effect.sync(() => observer.disconnect())
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How high a popover is, open or closed. Closed, it is not laid out at all,
|
|
42
|
+
* so while this function runs the root says it is being measured, and the
|
|
43
|
+
* stylesheet lays it out unseen. Nothing is painted in between.
|
|
44
|
+
*/
|
|
45
|
+
const heightOf = (root: HTMLElement, popover: HTMLElement): number => {
|
|
46
|
+
if (popover.offsetHeight > 0) return popover.offsetHeight
|
|
47
|
+
root.setAttribute("data-measuring", "")
|
|
48
|
+
const height = popover.offsetHeight
|
|
49
|
+
root.removeAttribute("data-measuring")
|
|
50
|
+
return height
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Says which way a popover will open, before it does: `down`, unless there
|
|
55
|
+
* is no room for it under its button and more room over it. The stylesheet
|
|
56
|
+
* reads what it says, and by it places the popover, points the arrow and
|
|
57
|
+
* draws the popover out of its button the way it goes.
|
|
58
|
+
*
|
|
59
|
+
* It measures the popover itself, closed as it is: a guess at its height
|
|
60
|
+
* could point the arrow one way and open the popover the other. And where
|
|
61
|
+
* its button is can change without anyone touching the page, so it looks
|
|
62
|
+
* again whenever anything could have moved it or changed what is in it:
|
|
63
|
+
* the page or the button changing size, the typefaces loading, the page
|
|
64
|
+
* scrolling, the window changing size, the page being slid aside by a
|
|
65
|
+
* navigator or a sheet and coming back; when a pointer or the focus
|
|
66
|
+
* reaches the button; and when the popover opens or closes.
|
|
67
|
+
*/
|
|
68
|
+
const FacePopover = Mount.make("FacePopover", { args: {} }, (root: HTMLElement) =>
|
|
69
|
+
Stream.mergeAll(
|
|
70
|
+
[
|
|
71
|
+
Stream.succeed(undefined),
|
|
72
|
+
// The page is rarely at rest when this starts: its typefaces and its pictures are still loading.
|
|
73
|
+
resized(document.documentElement, document.body, root),
|
|
74
|
+
Stream.fromEffect(Effect.promise(() => document.fonts.ready)),
|
|
75
|
+
Stream.fromEventListener(window, "load", { once: true }),
|
|
76
|
+
Stream.fromEventListener(window, "scroll", { capture: true, passive: true }),
|
|
77
|
+
Stream.fromEventListener(window, "resize", { passive: true }),
|
|
78
|
+
// The page can move without scrolling: a navigator or a sheet opening slides it aside, and closing brings it back.
|
|
79
|
+
// It looks when that starts, and again when the page has come to rest.
|
|
80
|
+
restated(document.body),
|
|
81
|
+
Stream.fromEventListener(window, "transitionend", { capture: true, passive: true }),
|
|
82
|
+
Stream.fromEventListener(window, "transitioncancel", { capture: true, passive: true }),
|
|
83
|
+
Stream.fromEventListener(window, "animationend", { capture: true, passive: true }),
|
|
84
|
+
// And at the last moment, in case all the others missed it.
|
|
85
|
+
Stream.fromEventListener(root, "pointerenter", { capture: true, passive: true }),
|
|
86
|
+
Stream.fromEventListener(root, "focusin", { passive: true }),
|
|
87
|
+
// It doesn't bubble, so it is caught on the way down.
|
|
88
|
+
Stream.fromEventListener(root, "toggle", { capture: true })
|
|
89
|
+
],
|
|
90
|
+
{ concurrency: "unbounded" }
|
|
91
|
+
).pipe(
|
|
92
|
+
Stream.runForEach(() =>
|
|
93
|
+
Effect.sync(() => {
|
|
94
|
+
const button = root.querySelector("button")
|
|
95
|
+
const popover = root.querySelector<HTMLElement>("[popover]")
|
|
96
|
+
if (button === null || popover === null) return
|
|
97
|
+
const at = button.getBoundingClientRect()
|
|
98
|
+
const below = window.innerHeight - at.bottom
|
|
99
|
+
// The room it needs: itself, and the gap it keeps from its button and from the edge of the window.
|
|
100
|
+
const needed = heightOf(root, popover) + 8
|
|
101
|
+
root.setAttribute("data-face", below < needed && at.top > below ? "up" : "down")
|
|
102
|
+
})
|
|
103
|
+
),
|
|
104
|
+
Effect.as(Component.noop)
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
/** A button that opens the popover after it. It opens under the button, or over it when that is where the room is. */
|
|
109
|
+
export const anchored = <Msg, R>(
|
|
110
|
+
h: Html.H<Msg>,
|
|
111
|
+
options: { readonly name: string; readonly label: string; readonly role?: "menu" },
|
|
112
|
+
body: View.Input<Msg, R>
|
|
113
|
+
) => {
|
|
114
|
+
const id = h.id(`s-ui-popover-${options.name}`)
|
|
115
|
+
return {
|
|
116
|
+
id,
|
|
117
|
+
content: h.div
|
|
118
|
+
.class(styles["popover-root"])
|
|
119
|
+
.onMount(FacePopover({}))
|
|
120
|
+
.children(
|
|
121
|
+
h.button
|
|
122
|
+
.class(look("secondary"), styles.trigger)
|
|
123
|
+
.attr("type", "button")
|
|
124
|
+
.attr("popovertarget", id)
|
|
125
|
+
.attr("aria-haspopup", options.role)
|
|
126
|
+
.children(options.label, arrowOf(h, "down")),
|
|
127
|
+
h.div.class(styles.popover).attr("id", id).attr("popover", "auto").attr("role", options.role).children(body)
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const popover = <Msg>(h: Html.H<Msg>) => ({
|
|
133
|
+
/** More about something, behind one button, next to it. */
|
|
134
|
+
popover: <R = never>(
|
|
135
|
+
options: { readonly name: string; readonly label: string },
|
|
136
|
+
...children: ReadonlyArray<Child<Kind, Msg, R>>
|
|
137
|
+
): Node<"block", Msg, R> =>
|
|
138
|
+
node(anchored(h, options, h.div.class(styles["popover-body"]).children(inner(children))).content)
|
|
139
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* progress: how far along something is. */
|
|
2
|
+
|
|
3
|
+
@layer standard.ui {
|
|
4
|
+
.progress {
|
|
5
|
+
display: block;
|
|
6
|
+
inline-size: 100%;
|
|
7
|
+
block-size: var(--s-unit);
|
|
8
|
+
appearance: none;
|
|
9
|
+
background: color-mix(in oklch, var(--s-fg) 14%, transparent);
|
|
10
|
+
color: var(--s-mark);
|
|
11
|
+
overflow: clip;
|
|
12
|
+
|
|
13
|
+
&::-webkit-progress-bar {
|
|
14
|
+
background: transparent;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&::-webkit-progress-value {
|
|
18
|
+
background: var(--s-mark);
|
|
19
|
+
transition: inline-size var(--s-move) var(--s-ease);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&::-moz-progress-bar {
|
|
23
|
+
background: var(--s-mark);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Not yet known how far: a block runs the length of the track. */
|
|
27
|
+
&:indeterminate {
|
|
28
|
+
position: relative;
|
|
29
|
+
|
|
30
|
+
&::after {
|
|
31
|
+
content: "";
|
|
32
|
+
position: absolute;
|
|
33
|
+
inset-block: 0;
|
|
34
|
+
inline-size: 30%;
|
|
35
|
+
background: var(--s-mark);
|
|
36
|
+
animation: progress-run 0.6s var(--s-ease) infinite;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&::-webkit-progress-value {
|
|
40
|
+
background: transparent;
|
|
41
|
+
}
|
|
42
|
+
&::-moz-progress-bar {
|
|
43
|
+
background: transparent;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@layer standard.ui {
|
|
50
|
+
/* Given a colour, what is done is a block of it. */
|
|
51
|
+
.progress:global(.s-ui-lined) {
|
|
52
|
+
--s-mark: var(--s-line);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@keyframes progress-run {
|
|
57
|
+
from {
|
|
58
|
+
inset-inline-start: -30%;
|
|
59
|
+
}
|
|
60
|
+
to {
|
|
61
|
+
inset-inline-start: 100%;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@media (prefers-reduced-motion: reduce) {
|
|
66
|
+
.progress:indeterminate::after {
|
|
67
|
+
animation: none;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `progress`: how far along something is.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.4.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Html } from "effect/ui/html"
|
|
7
|
+
import { node, type Node } from "../../Node.ts"
|
|
8
|
+
import type { Colour } from "../../standard/tokens/tokens.ts"
|
|
9
|
+
import { line } from "../control/control.ts"
|
|
10
|
+
import styles from "./progress.module.css"
|
|
11
|
+
|
|
12
|
+
export const progress = <Msg>(h: Html.H<Msg>) => ({
|
|
13
|
+
/** How far along something is, from 0 to 1. With no value, it is not yet known how far. With a colour, the part that is done is in it. */
|
|
14
|
+
progress: (options: {
|
|
15
|
+
readonly label: string
|
|
16
|
+
readonly value?: number
|
|
17
|
+
readonly colour?: Colour
|
|
18
|
+
}): Node<"block", Msg> =>
|
|
19
|
+
node(
|
|
20
|
+
h.progress
|
|
21
|
+
.class(styles.progress, line(options.colour))
|
|
22
|
+
.attr("aria-label", options.label)
|
|
23
|
+
.attr("max", "1")
|
|
24
|
+
.attr("value", options.value === undefined ? undefined : String(Math.min(1, Math.max(0, options.value))))
|
|
25
|
+
)
|
|
26
|
+
})
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/* route: the steps of something with an order, and the one it has reached. */
|
|
2
|
+
|
|
3
|
+
@layer standard.ui {
|
|
4
|
+
/* Without a colour, its line is in the colour of the text. */
|
|
5
|
+
:where(.route) {
|
|
6
|
+
--s-line: var(--s-fg);
|
|
7
|
+
--s-on-line: var(--s-bg);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.route {
|
|
11
|
+
/* How far down a stop its marker sits: on the first line of its name. */
|
|
12
|
+
--s-ui-at: calc(var(--s-unit) + 0.75rem);
|
|
13
|
+
|
|
14
|
+
display: grid;
|
|
15
|
+
grid-template-columns: minmax(0, 1fr);
|
|
16
|
+
list-style: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.stop {
|
|
20
|
+
position: relative;
|
|
21
|
+
display: grid;
|
|
22
|
+
|
|
23
|
+
/* The line, from this stop's marker to the next stop's. */
|
|
24
|
+
&::before {
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset-block: var(--s-ui-at) calc(-1 * var(--s-ui-at));
|
|
28
|
+
inset-inline-start: calc(0.75 * var(--s-unit));
|
|
29
|
+
inline-size: calc(var(--s-unit) / 2);
|
|
30
|
+
background: var(--s-line);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:last-child::before {
|
|
34
|
+
display: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* The marker. */
|
|
38
|
+
&::after {
|
|
39
|
+
content: "";
|
|
40
|
+
position: absolute;
|
|
41
|
+
inset-block-start: calc(var(--s-ui-at) - var(--s-unit));
|
|
42
|
+
inset-inline-start: 0;
|
|
43
|
+
inline-size: calc(2 * var(--s-unit));
|
|
44
|
+
block-size: calc(2 * var(--s-unit));
|
|
45
|
+
border: calc(0.375 * var(--s-unit)) solid var(--s-fg);
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
background: var(--s-bg);
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&.state-passed {
|
|
52
|
+
color: var(--s-muted);
|
|
53
|
+
|
|
54
|
+
&::before {
|
|
55
|
+
background: var(--s-muted);
|
|
56
|
+
}
|
|
57
|
+
&::after {
|
|
58
|
+
border-color: var(--s-muted);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&.state-current {
|
|
63
|
+
font-weight: 700;
|
|
64
|
+
|
|
65
|
+
&::after {
|
|
66
|
+
background: var(--s-fg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.stop-body {
|
|
72
|
+
display: grid;
|
|
73
|
+
grid-template-columns: minmax(0, 1fr);
|
|
74
|
+
align-content: start;
|
|
75
|
+
inline-size: 100%;
|
|
76
|
+
padding-block: var(--s-unit);
|
|
77
|
+
padding-inline: calc(4 * var(--s-unit)) var(--s-unit);
|
|
78
|
+
background: color-mix(in oklch, var(--s-fg) var(--s-ui-press), transparent);
|
|
79
|
+
line-height: 1.5rem;
|
|
80
|
+
|
|
81
|
+
& > span {
|
|
82
|
+
display: block;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.stop-note {
|
|
87
|
+
font-size: 0.875rem;
|
|
88
|
+
font-weight: 400;
|
|
89
|
+
color: var(--s-muted);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* On a page with the room, a journey's line can run across instead of down. */
|
|
93
|
+
@container s-page (inline-size >= 48rem) {
|
|
94
|
+
.route.axis-horizontal {
|
|
95
|
+
grid-template-columns: none;
|
|
96
|
+
grid-auto-flow: column;
|
|
97
|
+
grid-auto-columns: minmax(0, 1fr);
|
|
98
|
+
|
|
99
|
+
& .stop::before {
|
|
100
|
+
inset-block: calc(0.75 * var(--s-unit)) auto;
|
|
101
|
+
inset-inline: var(--s-unit) calc(-1 * var(--s-unit));
|
|
102
|
+
inline-size: auto;
|
|
103
|
+
block-size: calc(var(--s-unit) / 2);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
& .stop::after {
|
|
107
|
+
inset-block-start: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
& .stop-body {
|
|
111
|
+
padding-block-start: calc(3 * var(--s-unit));
|
|
112
|
+
padding-inline: 0 var(--s-gutter);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const styles: {
|
|
2
|
+
readonly "axis-horizontal": string;
|
|
3
|
+
readonly "route": string;
|
|
4
|
+
readonly "state-current": string;
|
|
5
|
+
readonly "state-passed": string;
|
|
6
|
+
readonly "stop": string;
|
|
7
|
+
readonly "stop-body": string;
|
|
8
|
+
readonly "stop-note": string;
|
|
9
|
+
};
|
|
10
|
+
export = styles;
|
|
11
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `route`: the steps of something with an order, and the one it has reached.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.4.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Html } from "effect/ui/html"
|
|
7
|
+
import { node, type Node } from "../../Node.ts"
|
|
8
|
+
import type { Colour } from "../../standard/tokens/tokens.ts"
|
|
9
|
+
import control from "../control/control.module.css"
|
|
10
|
+
import { line } from "../control/control.ts"
|
|
11
|
+
import styles from "./route.module.css"
|
|
12
|
+
|
|
13
|
+
export const route = <Msg>(h: Html.H<Msg>) => ({
|
|
14
|
+
/**
|
|
15
|
+
* The steps of something with an order, and the one it has reached: the
|
|
16
|
+
* steps of a task, the stages of an order, the events of a day.
|
|
17
|
+
* With `onSelect` each step can be pressed.
|
|
18
|
+
*/
|
|
19
|
+
route: (options: {
|
|
20
|
+
readonly label: string
|
|
21
|
+
readonly stops: ReadonlyArray<{ readonly name: string; readonly note?: string }>
|
|
22
|
+
readonly at?: number
|
|
23
|
+
readonly onSelect?: (index: number) => Msg
|
|
24
|
+
readonly colour?: Colour
|
|
25
|
+
readonly axis?: "vertical" | "horizontal"
|
|
26
|
+
}): Node<"block", Msg> => {
|
|
27
|
+
const { at, onSelect } = options
|
|
28
|
+
return node(
|
|
29
|
+
h.ol
|
|
30
|
+
.class(styles.route, line(options.colour), options.axis === "horizontal" && styles["axis-horizontal"])
|
|
31
|
+
.attr("aria-label", options.label)
|
|
32
|
+
.children(
|
|
33
|
+
options.stops.map((stop, index) => {
|
|
34
|
+
const body = [
|
|
35
|
+
h.span.children(stop.name),
|
|
36
|
+
stop.note !== undefined && h.span.class(styles["stop-note"]).children(stop.note)
|
|
37
|
+
]
|
|
38
|
+
return h.li
|
|
39
|
+
.class(
|
|
40
|
+
styles.stop,
|
|
41
|
+
at !== undefined && index < at && styles["state-passed"],
|
|
42
|
+
index === at && styles["state-current"]
|
|
43
|
+
)
|
|
44
|
+
.attr("aria-current", index === at ? "step" : undefined)
|
|
45
|
+
.children(
|
|
46
|
+
onSelect === undefined
|
|
47
|
+
? h.div.class(styles["stop-body"]).children(body)
|
|
48
|
+
: h.button
|
|
49
|
+
.class(control.control, styles["stop-body"])
|
|
50
|
+
.attr("type", "button")
|
|
51
|
+
.on("click", onSelect(index))
|
|
52
|
+
.children(body)
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
})
|