@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.
Files changed (260) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +516 -2
  3. package/dist/Extend.d.ts +15 -0
  4. package/dist/Extend.d.ts.map +1 -0
  5. package/dist/Extend.js +1 -0
  6. package/dist/Node.d.ts +71 -0
  7. package/dist/Node.d.ts.map +1 -0
  8. package/dist/Palette-BIJ96BEh.js +84 -0
  9. package/dist/Palette.d.ts +8 -0
  10. package/dist/Palette.d.ts.map +1 -0
  11. package/dist/Palette.js +1 -0
  12. package/dist/Standard-BPpzr5SM.js +488 -0
  13. package/dist/Standard.d.ts +249 -0
  14. package/dist/Standard.d.ts.map +1 -0
  15. package/dist/Standard.js +1 -0
  16. package/dist/Ui-B9xQqqNT.js +468 -0
  17. package/dist/Ui.d.ts +500 -0
  18. package/dist/Ui.d.ts.map +1 -0
  19. package/dist/Ui.js +1 -0
  20. package/dist/index.d.ts +25 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +4 -0
  23. package/dist/rolldown-runtime-BMBA7GOT.js +10 -0
  24. package/dist/standard/button/button.d.ts +21 -0
  25. package/dist/standard/button/button.d.ts.map +1 -0
  26. package/dist/standard/colour/colour.d.ts +93 -0
  27. package/dist/standard/colour/colour.d.ts.map +1 -0
  28. package/dist/standard/field/field.d.ts +91 -0
  29. package/dist/standard/field/field.d.ts.map +1 -0
  30. package/dist/standard/form/form.d.ts +16 -0
  31. package/dist/standard/form/form.d.ts.map +1 -0
  32. package/dist/standard/icon/icon.d.ts +31 -0
  33. package/dist/standard/icon/icon.d.ts.map +1 -0
  34. package/dist/standard/image/image.d.ts +21 -0
  35. package/dist/standard/image/image.d.ts.map +1 -0
  36. package/dist/standard/layout/layout.d.ts +73 -0
  37. package/dist/standard/layout/layout.d.ts.map +1 -0
  38. package/dist/standard/list/list.d.ts +26 -0
  39. package/dist/standard/list/list.d.ts.map +1 -0
  40. package/dist/standard/page/page.d.ts +20 -0
  41. package/dist/standard/page/page.d.ts.map +1 -0
  42. package/dist/standard/table/table.d.ts +18 -0
  43. package/dist/standard/table/table.d.ts.map +1 -0
  44. package/dist/standard/text/text.d.ts +39 -0
  45. package/dist/standard/text/text.d.ts.map +1 -0
  46. package/dist/standard/tokens/classes.d.ts +16 -0
  47. package/dist/standard/tokens/classes.d.ts.map +1 -0
  48. package/dist/standard/tokens/tokens.d.ts +162 -0
  49. package/dist/standard/tokens/tokens.d.ts.map +1 -0
  50. package/dist/standard.css +2 -0
  51. package/dist/ui/arrow/arrow.d.ts +18 -0
  52. package/dist/ui/arrow/arrow.d.ts.map +1 -0
  53. package/dist/ui/avatar/avatar.d.ts +15 -0
  54. package/dist/ui/avatar/avatar.d.ts.map +1 -0
  55. package/dist/ui/board/board.d.ts +34 -0
  56. package/dist/ui/board/board.d.ts.map +1 -0
  57. package/dist/ui/bullet/bullet.d.ts +15 -0
  58. package/dist/ui/bullet/bullet.d.ts.map +1 -0
  59. package/dist/ui/card/card.d.ts +24 -0
  60. package/dist/ui/card/card.d.ts.map +1 -0
  61. package/dist/ui/carousel/carousel.d.ts +17 -0
  62. package/dist/ui/carousel/carousel.d.ts.map +1 -0
  63. package/dist/ui/check/check.d.ts +20 -0
  64. package/dist/ui/check/check.d.ts.map +1 -0
  65. package/dist/ui/choice/choice.d.ts +19 -0
  66. package/dist/ui/choice/choice.d.ts.map +1 -0
  67. package/dist/ui/control/control.d.ts +57 -0
  68. package/dist/ui/control/control.d.ts.map +1 -0
  69. package/dist/ui/dialog/dialog.d.ts +30 -0
  70. package/dist/ui/dialog/dialog.d.ts.map +1 -0
  71. package/dist/ui/disclosure/disclosure.d.ts +20 -0
  72. package/dist/ui/disclosure/disclosure.d.ts.map +1 -0
  73. package/dist/ui/flap/flap.d.ts +18 -0
  74. package/dist/ui/flap/flap.d.ts.map +1 -0
  75. package/dist/ui/item/item.d.ts +21 -0
  76. package/dist/ui/item/item.d.ts.map +1 -0
  77. package/dist/ui/key/key.d.ts +12 -0
  78. package/dist/ui/key/key.d.ts.map +1 -0
  79. package/dist/ui/menu/menu.d.ts +26 -0
  80. package/dist/ui/menu/menu.d.ts.map +1 -0
  81. package/dist/ui/modal/modal.d.ts +22 -0
  82. package/dist/ui/modal/modal.d.ts.map +1 -0
  83. package/dist/ui/navigator/navigator.d.ts +137 -0
  84. package/dist/ui/navigator/navigator.d.ts.map +1 -0
  85. package/dist/ui/notice/notice.d.ts +34 -0
  86. package/dist/ui/notice/notice.d.ts.map +1 -0
  87. package/dist/ui/options/options.d.ts +19 -0
  88. package/dist/ui/options/options.d.ts.map +1 -0
  89. package/dist/ui/pager/pager.d.ts +29 -0
  90. package/dist/ui/pager/pager.d.ts.map +1 -0
  91. package/dist/ui/pagination/pagination.d.ts +14 -0
  92. package/dist/ui/pagination/pagination.d.ts.map +1 -0
  93. package/dist/ui/popover/popover.d.ts +20 -0
  94. package/dist/ui/popover/popover.d.ts.map +1 -0
  95. package/dist/ui/progress/progress.d.ts +17 -0
  96. package/dist/ui/progress/progress.d.ts.map +1 -0
  97. package/dist/ui/route/route.d.ts +27 -0
  98. package/dist/ui/route/route.d.ts.map +1 -0
  99. package/dist/ui/sheet/sheet.d.ts +35 -0
  100. package/dist/ui/sheet/sheet.d.ts.map +1 -0
  101. package/dist/ui/skeleton/skeleton.d.ts +15 -0
  102. package/dist/ui/skeleton/skeleton.d.ts.map +1 -0
  103. package/dist/ui/slider/slider.d.ts +23 -0
  104. package/dist/ui/slider/slider.d.ts.map +1 -0
  105. package/dist/ui/stepper/stepper.d.ts +32 -0
  106. package/dist/ui/stepper/stepper.d.ts.map +1 -0
  107. package/dist/ui/tabs/tabs.d.ts +22 -0
  108. package/dist/ui/tabs/tabs.d.ts.map +1 -0
  109. package/dist/ui/tag/tag.d.ts +17 -0
  110. package/dist/ui/tag/tag.d.ts.map +1 -0
  111. package/dist/ui/tile/tile.d.ts +38 -0
  112. package/dist/ui/tile/tile.d.ts.map +1 -0
  113. package/dist/ui/toasts/toasts.d.ts +17 -0
  114. package/dist/ui/toasts/toasts.d.ts.map +1 -0
  115. package/dist/ui/toggle/toggle.d.ts +17 -0
  116. package/dist/ui/toggle/toggle.d.ts.map +1 -0
  117. package/dist/ui/trail/trail.d.ts +22 -0
  118. package/dist/ui/trail/trail.d.ts.map +1 -0
  119. package/package.json +70 -3
  120. package/src/Extend.ts +14 -0
  121. package/src/Node.ts +44 -0
  122. package/src/Palette.ts +7 -0
  123. package/src/Standard.ts +109 -0
  124. package/src/Ui.ts +156 -0
  125. package/src/index.ts +27 -0
  126. package/src/standard/button/button.module.css +43 -0
  127. package/src/standard/button/button.module.d.css.ts +6 -0
  128. package/src/standard/button/button.ts +38 -0
  129. package/src/standard/colour/colour.ts +197 -0
  130. package/src/standard/field/field.module.css +222 -0
  131. package/src/standard/field/field.module.d.css.ts +13 -0
  132. package/src/standard/field/field.ts +266 -0
  133. package/src/standard/form/form.ts +25 -0
  134. package/src/standard/icon/icon.module.css +349 -0
  135. package/src/standard/icon/icon.module.d.css.ts +112 -0
  136. package/src/standard/icon/icon.ts +148 -0
  137. package/src/standard/image/image.module.css +42 -0
  138. package/src/standard/image/image.module.d.css.ts +12 -0
  139. package/src/standard/image/image.ts +39 -0
  140. package/src/standard/layout/layout.module.css +224 -0
  141. package/src/standard/layout/layout.module.d.css.ts +41 -0
  142. package/src/standard/layout/layout.ts +133 -0
  143. package/src/standard/list/list.module.css +71 -0
  144. package/src/standard/list/list.module.d.css.ts +10 -0
  145. package/src/standard/list/list.ts +53 -0
  146. package/src/standard/page/page.module.css +244 -0
  147. package/src/standard/page/page.module.d.css.ts +9 -0
  148. package/src/standard/page/page.ts +32 -0
  149. package/src/standard/table/table.module.css +40 -0
  150. package/src/standard/table/table.module.d.css.ts +6 -0
  151. package/src/standard/table/table.ts +36 -0
  152. package/src/standard/text/text.module.css +149 -0
  153. package/src/standard/text/text.module.d.css.ts +19 -0
  154. package/src/standard/text/text.ts +77 -0
  155. package/src/standard/tokens/classes.ts +31 -0
  156. package/src/standard/tokens/tokens.module.css +294 -0
  157. package/src/standard/tokens/tokens.module.d.css.ts +40 -0
  158. package/src/standard/tokens/tokens.ts +339 -0
  159. package/src/ui/arrow/arrow.module.css +38 -0
  160. package/src/ui/arrow/arrow.module.d.css.ts +13 -0
  161. package/src/ui/arrow/arrow.ts +35 -0
  162. package/src/ui/avatar/avatar.module.css +25 -0
  163. package/src/ui/avatar/avatar.module.d.css.ts +5 -0
  164. package/src/ui/avatar/avatar.ts +28 -0
  165. package/src/ui/board/board.module.css +94 -0
  166. package/src/ui/board/board.module.d.css.ts +10 -0
  167. package/src/ui/board/board.ts +84 -0
  168. package/src/ui/bullet/bullet.module.css +28 -0
  169. package/src/ui/bullet/bullet.module.d.css.ts +5 -0
  170. package/src/ui/bullet/bullet.ts +16 -0
  171. package/src/ui/card/card.module.css +80 -0
  172. package/src/ui/card/card.module.d.css.ts +6 -0
  173. package/src/ui/card/card.ts +42 -0
  174. package/src/ui/carousel/carousel.module.css +24 -0
  175. package/src/ui/carousel/carousel.module.d.css.ts +5 -0
  176. package/src/ui/carousel/carousel.ts +30 -0
  177. package/src/ui/check/check.module.css +53 -0
  178. package/src/ui/check/check.module.d.css.ts +8 -0
  179. package/src/ui/check/check.ts +46 -0
  180. package/src/ui/choice/choice.module.css +32 -0
  181. package/src/ui/choice/choice.module.d.css.ts +6 -0
  182. package/src/ui/choice/choice.ts +31 -0
  183. package/src/ui/control/control.module.css +127 -0
  184. package/src/ui/control/control.module.d.css.ts +12 -0
  185. package/src/ui/control/control.ts +97 -0
  186. package/src/ui/dialog/dialog.module.css +42 -0
  187. package/src/ui/dialog/dialog.module.d.css.ts +6 -0
  188. package/src/ui/dialog/dialog.ts +44 -0
  189. package/src/ui/disclosure/disclosure.module.css +57 -0
  190. package/src/ui/disclosure/disclosure.module.d.css.ts +7 -0
  191. package/src/ui/disclosure/disclosure.ts +32 -0
  192. package/src/ui/flap/flap.module.css +161 -0
  193. package/src/ui/flap/flap.module.d.css.ts +48 -0
  194. package/src/ui/flap/flap.ts +78 -0
  195. package/src/ui/item/item.module.css +39 -0
  196. package/src/ui/item/item.module.d.css.ts +7 -0
  197. package/src/ui/item/item.ts +33 -0
  198. package/src/ui/key/key.module.css +15 -0
  199. package/src/ui/key/key.module.d.css.ts +5 -0
  200. package/src/ui/key/key.ts +13 -0
  201. package/src/ui/menu/menu.module.css +11 -0
  202. package/src/ui/menu/menu.module.d.css.ts +5 -0
  203. package/src/ui/menu/menu.ts +48 -0
  204. package/src/ui/modal/modal.module.css +66 -0
  205. package/src/ui/modal/modal.module.d.css.ts +8 -0
  206. package/src/ui/modal/modal.ts +55 -0
  207. package/src/ui/navigator/navigator.module.css +658 -0
  208. package/src/ui/navigator/navigator.module.d.css.ts +39 -0
  209. package/src/ui/navigator/navigator.ts +337 -0
  210. package/src/ui/notice/notice.module.css +80 -0
  211. package/src/ui/notice/notice.module.d.css.ts +10 -0
  212. package/src/ui/notice/notice.ts +57 -0
  213. package/src/ui/options/options.module.css +30 -0
  214. package/src/ui/options/options.module.d.css.ts +6 -0
  215. package/src/ui/options/options.ts +31 -0
  216. package/src/ui/pager/pager.module.css +38 -0
  217. package/src/ui/pager/pager.module.d.css.ts +8 -0
  218. package/src/ui/pager/pager.ts +48 -0
  219. package/src/ui/pagination/pagination.module.css +38 -0
  220. package/src/ui/pagination/pagination.module.d.css.ts +7 -0
  221. package/src/ui/pagination/pagination.ts +52 -0
  222. package/src/ui/popover/popover.module.css +94 -0
  223. package/src/ui/popover/popover.module.d.css.ts +8 -0
  224. package/src/ui/popover/popover.ts +139 -0
  225. package/src/ui/progress/progress.module.css +69 -0
  226. package/src/ui/progress/progress.module.d.css.ts +6 -0
  227. package/src/ui/progress/progress.ts +26 -0
  228. package/src/ui/route/route.module.css +116 -0
  229. package/src/ui/route/route.module.d.css.ts +11 -0
  230. package/src/ui/route/route.ts +58 -0
  231. package/src/ui/sheet/sheet.module.css +194 -0
  232. package/src/ui/sheet/sheet.module.d.css.ts +7 -0
  233. package/src/ui/sheet/sheet.ts +47 -0
  234. package/src/ui/skeleton/skeleton.module.css +44 -0
  235. package/src/ui/skeleton/skeleton.module.d.css.ts +6 -0
  236. package/src/ui/skeleton/skeleton.ts +20 -0
  237. package/src/ui/slider/slider.module.css +56 -0
  238. package/src/ui/slider/slider.module.d.css.ts +6 -0
  239. package/src/ui/slider/slider.ts +48 -0
  240. package/src/ui/stepper/stepper.module.css +32 -0
  241. package/src/ui/stepper/stepper.module.d.css.ts +7 -0
  242. package/src/ui/stepper/stepper.ts +62 -0
  243. package/src/ui/tabs/tabs.module.css +38 -0
  244. package/src/ui/tabs/tabs.module.d.css.ts +6 -0
  245. package/src/ui/tabs/tabs.ts +24 -0
  246. package/src/ui/tag/tag.module.css +23 -0
  247. package/src/ui/tag/tag.module.d.css.ts +5 -0
  248. package/src/ui/tag/tag.ts +17 -0
  249. package/src/ui/tile/tile.module.css +137 -0
  250. package/src/ui/tile/tile.module.d.css.ts +13 -0
  251. package/src/ui/tile/tile.ts +69 -0
  252. package/src/ui/toasts/toasts.module.css +38 -0
  253. package/src/ui/toasts/toasts.module.d.css.ts +6 -0
  254. package/src/ui/toasts/toasts.ts +26 -0
  255. package/src/ui/toggle/toggle.module.css +46 -0
  256. package/src/ui/toggle/toggle.module.d.css.ts +6 -0
  257. package/src/ui/toggle/toggle.ts +29 -0
  258. package/src/ui/trail/trail.module.css +42 -0
  259. package/src/ui/trail/trail.module.d.css.ts +5 -0
  260. package/src/ui/trail/trail.ts +28 -0
@@ -0,0 +1,337 @@
1
+ /**
2
+ * `navigator`: everywhere you can go, at the side of the page, along its top, or along its bottom.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+ import { Effect, Schema, Stream } from "effect"
7
+ import { Component, Mount } 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 { type Icon, iconOf, leading } from "../../standard/icon/icon.ts"
11
+ import { tone } from "../../standard/tokens/classes.ts"
12
+ import type { Colour, Tone, Travel } from "../../standard/tokens/tokens.ts"
13
+ import control from "../control/control.module.css"
14
+ import { line } from "../control/control.ts"
15
+ import styles from "./navigator.module.css"
16
+
17
+ /** Where a navigator is: at the side of the page, along its top, or along its bottom. */
18
+ export const Place = Schema.Literals(["side", "top", "bottom"])
19
+ export type Place = typeof Place.Type
20
+
21
+ /**
22
+ * How an open navigator takes its place: with room taken from the page,
23
+ * with the window moved over to it, or with neither, hanging over the page
24
+ * as a menu does. The first two can be asked for, at the side. The third
25
+ * is what a navigator along the top is.
26
+ */
27
+ export const Hold = Schema.Literals(["docked", "sheet", "menu"])
28
+ export type Hold = typeof Hold.Type
29
+
30
+ /**
31
+ * Keeps the current place in view in a navigator whose list is longer than
32
+ * its pane: whenever that place changes, or the pane is opened, its list
33
+ * scrolls just far enough to show it. Only the list scrolls, never the
34
+ * page.
35
+ */
36
+ const ShowCurrentPlace = Mount.make(
37
+ "ShowCurrentPlace",
38
+ { args: { at: Schema.String } },
39
+ (pane: HTMLElement, _args, changes) =>
40
+ Stream.runForEach(changes, () =>
41
+ Effect.sync(() => {
42
+ const place = pane.querySelector(`[aria-current="page"]`)
43
+ const list = place?.closest(`.${styles["nav-list"]}`)
44
+ if (place === null || list === null || list === undefined) return
45
+ const room = list.getBoundingClientRect()
46
+ const row = place.getBoundingClientRect()
47
+ if (row.top < room.top || row.bottom > room.bottom) {
48
+ list.scrollTop += row.top - room.top - (room.height - row.height) / 2
49
+ }
50
+ if (row.left < room.left || row.right > room.right) {
51
+ list.scrollLeft += row.left - room.left - (room.width - row.width) / 2
52
+ }
53
+ })
54
+ ).pipe(Effect.as(Component.noop))
55
+ )
56
+
57
+ /**
58
+ * How far round the arrow that goes back is turned to point the way the
59
+ * window will move: clockwise, in degrees, from pointing back along the line
60
+ * of reading, which is how it is drawn. Never more than half a turn either
61
+ * way.
62
+ */
63
+ const turnOf = (travel: ReadonlyArray<Travel>): 0 | 45 | 90 | 135 | 180 | -45 | -90 | -135 => {
64
+ const up = travel.includes("up")
65
+ const down = travel.includes("down")
66
+ if (travel.includes("back")) return up ? 45 : down ? -45 : 0
67
+ if (travel.includes("forward")) return up ? 135 : down ? -135 : 180
68
+ // With no way at all it stays as it is drawn.
69
+ return up ? 90 : down ? -90 : 0
70
+ }
71
+
72
+ /**
73
+ * Turns the arrow that goes back the short way round. A stylesheet can only
74
+ * turn it from one number to another, which from up and forward to down and
75
+ * forward is three quarters of a turn, by way of back. This turns it on from
76
+ * wherever it is by whatever is least: never more than half a turn.
77
+ */
78
+ const PointTheWay = Mount.make("PointTheWay", { args: { turn: Schema.Number } }, (arrow: HTMLElement, _args, changes) =>
79
+ Stream.runForEach(changes, ({ turn }) =>
80
+ Effect.sync(() => {
81
+ const now = Number.parseFloat(arrow.style.rotate)
82
+ // The first time it is where its class has it already, and nothing moves.
83
+ arrow.style.rotate = `${Number.isNaN(now) ? turn : now + ((((turn - now) % 360) + 540) % 360) - 180}deg`
84
+ })
85
+ ).pipe(Effect.as(Component.noop))
86
+ )
87
+
88
+ export const navigator = <Msg>(h: Html.H<Msg>) => ({
89
+ /**
90
+ * The navigator, and the page it leads you round. It has two layers.
91
+ * First a bar: each group, by its pictogram and its name. Then a pane: the
92
+ * places of the group that is shown. The group shown and its pane are
93
+ * a block of colour: the group's colour if it was given one, the accent if
94
+ * not. A group that is not shown has its pictogram and name written in
95
+ * that colour. The current place is the two colours swapped.
96
+ *
97
+ * `place` says where it is. At the `"side"`, the bar is a rail down the
98
+ * edge where the page starts, as wide as its pictograms until it is
99
+ * opened, and the pane is beside it. Along the `"top"`, the bar is a row
100
+ * and the pane hangs under the group that is shown, its places in a list
101
+ * read downwards. Along the `"bottom"`, where a thumb is, the bar is a
102
+ * row of tabs and the pane rises from behind it. A narrow window always
103
+ * has it along the bottom, whatever is asked for.
104
+ *
105
+ * At the start of the bar is the button that opens and closes it:
106
+ * three bars, or with a `brand`, the app's mark and name. With a `back`,
107
+ * the button that goes back is before it, in the corner where the page
108
+ * starts. Its arrow points the way the window will move: give the `back`
109
+ * its `travel`, and it turns to that as the page changes.
110
+ *
111
+ * Along the bottom the tabs have no room for either. There, and so in
112
+ * every narrow window, a navigator with a `back` or a `brand` has a bar
113
+ * along the top of the page as well, with the two in it.
114
+ *
115
+ * Closed, which is how it is until `open` is true, there is only the bar.
116
+ * Pressing a group shows its places and goes nowhere: have the Model
117
+ * open the navigator on `onShow` as well, because closed there is
118
+ * nowhere to show them. Pressing the group that is shown, while it is
119
+ * open, closes it.
120
+ *
121
+ * `mode` says how it takes its place when open. `"docked"`, it takes its
122
+ * room from the page. As a `"sheet"` it takes none: the window moves over
123
+ * to it, so the page slides out by as much as it slides in. That is for
124
+ * the side: along the bottom it is always a sheet, and along the top it
125
+ * is a `"menu"`: it hangs over the page and moves nothing.
126
+ * `onShow` and `onToggle` are told which of the three the window they
127
+ * were pressed in has, so the Model knows.
128
+ *
129
+ * Going to a place and closing the navigator are two movements; don't
130
+ * make both at once. Docked, leave it open and let the window travel. As
131
+ * a sheet, close it and change the page with no transition: the window
132
+ * coming back from the navigator is the movement. As a menu, close it
133
+ * and let the window travel: a menu closing moves nothing, so the travel
134
+ * is the only movement there is.
135
+ *
136
+ * The Model keeps which group is `shown`, and whether it is `open`. Its
137
+ * children are the page. Give `toasts` as the last of them.
138
+ */
139
+ navigator: <R = never>(
140
+ options: {
141
+ readonly label: string
142
+ readonly groups: ReadonlyArray<{
143
+ readonly label: string
144
+ /** Its pictogram: all there is of it in a rail that is closed. */
145
+ readonly icon: Icon
146
+ readonly colour?: Colour
147
+ readonly links: ReadonlyArray<{
148
+ readonly label: string
149
+ readonly href: string
150
+ readonly icon?: Icon
151
+ readonly current?: boolean
152
+ }>
153
+ }>
154
+ /** The index of the group whose places are in the pane. */
155
+ readonly shown: number
156
+ readonly onShow: (index: number, as: Hold) => Msg
157
+ readonly open?: boolean
158
+ readonly toggle: {
159
+ /** The button's name, for anyone who can't see its pictogram. */
160
+ readonly label: string
161
+ /** What it sends: the state to go to, and how the navigator takes its place in the window it was pressed in. */
162
+ readonly onToggle: (open: boolean, as: Hold) => Msg
163
+ }
164
+ /**
165
+ * Whose app this is: a mark and a name, at the start of the bar, in
166
+ * place of the three bars. It is the button that opens and closes the
167
+ * navigator. The mark is a picture, or a pictogram, or, with neither,
168
+ * a square of colour: its colour if it was given one, the accent if
169
+ * not. Along the bottom it is in the bar along the top, and opens
170
+ * nothing: the tabs do that.
171
+ */
172
+ readonly brand?: { readonly name: string; readonly icon?: Icon; readonly src?: string; readonly colour?: Colour }
173
+ /**
174
+ * The button that goes back: an arrow, in the corner where the page
175
+ * starts. Where it goes is the Model's to say; usually to the page
176
+ * you were on before.
177
+ */
178
+ readonly back?: {
179
+ /** The button's name, for anyone who can't see its pictogram. */
180
+ readonly label: string
181
+ readonly onPress: Msg
182
+ /** True when there is nowhere to go back to: no page before this one, or one that is not the app's. */
183
+ readonly disabled?: boolean
184
+ /**
185
+ * The way the window will move when it is pressed: what
186
+ * `Standard.travel` makes of this route and the one it goes back
187
+ * to. The arrow points that way, and turns to it, the short way
188
+ * round, when it changes. Without one, or with no way at all, it
189
+ * points back along the line of reading.
190
+ */
191
+ readonly travel?: ReadonlyArray<Travel>
192
+ }
193
+ readonly place?: Place
194
+ /** At the side, whether it is docked or a sheet. Anywhere else it is not asked. */
195
+ readonly mode?: Exclude<Hold, "menu">
196
+ readonly tone?: Tone
197
+ },
198
+ ...children: ReadonlyArray<Child<Kind, Msg, R>>
199
+ ): Node<"block", Msg, R> => {
200
+ const id = h.id("s-ui-navigator")
201
+ const open = options.open === true
202
+ const { back, brand } = options
203
+ // The button that goes back: in the bar of a wide window, and in the bar along the top of a narrow one.
204
+ const turn = turnOf(back?.travel ?? [])
205
+ const goBack = () =>
206
+ back !== undefined &&
207
+ h.button
208
+ .class(control.control, styles["nav-back"])
209
+ .attr("type", "button")
210
+ .attr("aria-label", back.label)
211
+ .disabled(back.disabled === true)
212
+ .on("click", back.onPress)
213
+ .children(
214
+ iconOf(h, "arrow-back")
215
+ .class(styles["nav-way"], turn !== 0 && styles[`turn-${turn}`])
216
+ .onMount(PointTheWay({ turn }))
217
+ )
218
+ // The app's mark and its name.
219
+ const sign = (of: NonNullable<typeof brand>) => [
220
+ h.span
221
+ .class(styles["nav-mark"], line(of.colour))
222
+ .attr("aria-hidden", "true")
223
+ .children(
224
+ of.src !== undefined ? h.img.attr("src", of.src).attr("alt", "") : of.icon !== undefined && iconOf(h, of.icon)
225
+ ),
226
+ h.span.class(styles["nav-name"]).children(of.name)
227
+ ]
228
+ const place = options.place ?? "side"
229
+ // Only at the side can it be docked: along the bottom it is a sheet, and along the top it hangs over the page.
230
+ const hold: Hold = place === "side" ? (options.mode ?? "docked") : place === "top" ? "menu" : "sheet"
231
+ // A group, in the bar of a wide window or among the tabs along the bottom. Each says how the window it is in holds the navigator.
232
+ const cells = (as: Hold) =>
233
+ options.groups.map((group, index) =>
234
+ h.button
235
+ .class(control.control, styles["nav-cell"], line(group.colour))
236
+ .attr("type", "button")
237
+ .attr("aria-controls", id)
238
+ .attr("aria-pressed", index === options.shown ? "true" : "false")
239
+ // The group that is shown, pressed while it is open, closes it.
240
+ .on("click", open && index === options.shown ? options.toggle.onToggle(false, as) : options.onShow(index, as))
241
+ // Along the top, once it is open, a mouse that comes onto another group shows it, the way a menu bar does. A finger has to press.
242
+ .on("pointerenter", ({ pointerType }) =>
243
+ as === "menu" && open && index !== options.shown && pointerType === "mouse"
244
+ ? options.onShow(index, as)
245
+ : undefined
246
+ )
247
+ .children(iconOf(h, group.icon), h.span.class(styles["nav-name"]).children(group.label))
248
+ )
249
+ return node(
250
+ h.div
251
+ .class(
252
+ styles.shell,
253
+ // Along the bottom is how the stylesheet has it until told otherwise.
254
+ place !== "bottom" && styles[`place-${place}`],
255
+ hold !== "docked" && styles["mode-sheet"],
256
+ open && styles["state-open"]
257
+ )
258
+ .children(
259
+ h.nav
260
+ .class(styles.navigator, options.tone !== undefined && tone(options.tone))
261
+ .attr("aria-label", options.label)
262
+ .onMount(
263
+ ShowCurrentPlace({
264
+ // Looked for again whenever the place changes, and whenever the pane is opened or shows another group.
265
+ at: `${options.groups.flatMap((group) => group.links).find((link) => link.current === true)?.href ?? ""} ${open} ${options.shown}`
266
+ })
267
+ )
268
+ .children(
269
+ h.div.class(styles["nav-bar"]).children(
270
+ goBack(),
271
+ h.button
272
+ .class(control.control, styles["nav-fold"], brand !== undefined && styles["nav-brand"])
273
+ .attr("type", "button")
274
+ .attr("aria-label", options.toggle.label)
275
+ .attr("aria-controls", id)
276
+ .attr("aria-expanded", open ? "true" : "false")
277
+ .on("click", options.toggle.onToggle(!open, hold))
278
+ .children(brand === undefined ? iconOf(h, "menu") : sign(brand)),
279
+ // The app's mark is not one of the places to go: a rule sets it apart from them.
280
+ brand !== undefined && h.div.class(styles["nav-rule"]).attr("aria-hidden", "true"),
281
+ cells(hold)
282
+ ),
283
+ h.div.class(styles["nav-tabs"]).children(cells("sheet")),
284
+ h.div
285
+ .class(styles["nav-pane"])
286
+ .attr("id", id)
287
+ .children(
288
+ options.groups.map((group, index) => {
289
+ const name = (link: { readonly label: string; readonly icon?: Icon }) =>
290
+ link.icon === undefined ? link.label : h.span.children(leading(h, link.icon), link.label)
291
+ const at = group.links.findIndex((link) => link.current === true)
292
+ return h.div
293
+ .class(
294
+ styles["nav-list"],
295
+ index < options.shown && styles["is-before"],
296
+ index > options.shown && styles["is-after"],
297
+ line(group.colour)
298
+ )
299
+ .children(
300
+ h.div.class(styles["nav-rows"]).children(
301
+ // The group is named once, in the bar. Here its name is only for anyone who can't see that.
302
+ h.ul
303
+ .class(styles["nav-places"])
304
+ .attr("aria-label", group.label)
305
+ .children(
306
+ group.links.map((link) =>
307
+ h.li.children(
308
+ h.a
309
+ .class(control.control, styles["nav-place"])
310
+ .attr("href", link.href)
311
+ .attr("aria-current", link.current === true ? "page" : undefined)
312
+ .children(name(link))
313
+ )
314
+ )
315
+ ),
316
+ // The block that marks the current place: every name again, seen through a window on the row it says.
317
+ at >= 0 &&
318
+ h.div
319
+ .class(styles["nav-here"])
320
+ .attr("aria-hidden", "true")
321
+ .attr("data-at", String(at))
322
+ .children(group.links.map((link) => h.div.class(styles["nav-lit"]).children(name(link))))
323
+ )
324
+ )
325
+ })
326
+ )
327
+ ),
328
+ // The bar along the top of a narrow window. A wide one has what is in it in its own bar.
329
+ (back !== undefined || brand !== undefined) &&
330
+ h.div
331
+ .class(styles["nav-top"], options.tone !== undefined && tone(options.tone))
332
+ .children(goBack(), brand !== undefined && h.div.class(styles["nav-sign"]).children(sign(brand))),
333
+ h.div.class(styles["shell-body"]).children(inner(children))
334
+ )
335
+ )
336
+ }
337
+ })
@@ -0,0 +1,80 @@
1
+ /* notice: something a person should know before going on. */
2
+
3
+ @layer standard.ui {
4
+ .notice {
5
+ display: grid;
6
+ grid-template-columns: minmax(0, 1fr) auto;
7
+ /*
8
+ * As wide as what it says, and no wider. A line of text ends at 68ch, so
9
+ * a notice ends there too, with its margin on each side: a surface that
10
+ * ran on across the page past its last word would be a band of nothing.
11
+ * In a narrower column it is as wide as the column.
12
+ */
13
+ max-inline-size: calc(68ch + 6 * var(--s-unit));
14
+ /* A surface of its own: it is set on the page's own ground, a step towards its text: light in the light scheme, dark in the dark scheme. */
15
+ --s-bg: color-mix(in oklch, var(--s-ink) 10%, var(--s-paper));
16
+ --s-fg: var(--s-ink);
17
+ --s-mark: var(--s-accent);
18
+ --s-on-mark: var(--s-on-accent);
19
+ --s-dark: var(--s-night);
20
+ --s-flat: 0;
21
+
22
+ background: var(--s-bg);
23
+ color: var(--s-fg);
24
+
25
+ /* The yellow and black of a warning sign, whatever the page's accent. */
26
+ &.level-caution {
27
+ --s-bg: #fedd00;
28
+ --s-fg: var(--s-black);
29
+ --s-mark: var(--s-black);
30
+ --s-on-mark: #fedd00;
31
+ --s-read: var(--s-black);
32
+ --s-wrong: var(--s-black);
33
+ --s-muted: #584f20;
34
+ --s-flat: 1;
35
+ }
36
+ }
37
+
38
+ .notice-body {
39
+ display: grid;
40
+ grid-template-columns: minmax(0, 1fr);
41
+ row-gap: calc(var(--s-unit) / 2);
42
+ align-content: start;
43
+ padding: calc(2 * var(--s-unit)) calc(3 * var(--s-unit));
44
+ }
45
+
46
+ /* An info notice is a tint of its text, so what is pressed in it steps on towards the text; a caution is a block of colour, and leaves it to step away. */
47
+ .notice:not(.level-caution) > :is(.notice-dismiss, .notice-actions) {
48
+ --s-ui-step: var(--s-fg);
49
+ }
50
+
51
+ /* The button that dismisses it: at its end, as high as the notice, and out to its edge. */
52
+ .notice-dismiss {
53
+ grid-column: 2;
54
+ /* As wide as its word needs, whatever the width of the notice. */
55
+ grid-auto-columns: auto;
56
+
57
+ & > button {
58
+ min-block-size: var(--s-target);
59
+ padding: calc(2 * var(--s-unit));
60
+ }
61
+ }
62
+
63
+ /* What can be done about it, across its foot, edge to edge: at the foot however high the notice is made. */
64
+ .notice:has(> .notice-actions) {
65
+ grid-template-rows: 1fr auto;
66
+ }
67
+
68
+ .notice-actions {
69
+ grid-column: 1 / -1;
70
+
71
+ & > button {
72
+ min-block-size: var(--s-target);
73
+ padding: calc(1.5 * var(--s-unit)) calc(3 * var(--s-unit));
74
+ }
75
+ }
76
+
77
+ .notice-title {
78
+ font-weight: 700;
79
+ }
80
+ }
@@ -0,0 +1,10 @@
1
+ declare const styles: {
2
+ readonly "level-caution": string;
3
+ readonly "notice": string;
4
+ readonly "notice-actions": string;
5
+ readonly "notice-body": string;
6
+ readonly "notice-dismiss": string;
7
+ readonly "notice-title": string;
8
+ };
9
+ export = styles;
10
+
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `notice`: something a person should know before going on.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+ import { Schema } from "effect"
7
+ import type { Html } from "effect/ui/html"
8
+ import { type Child, contents as inner, type Kind, node, type Node } from "../../Node.ts"
9
+ import { type Icon, leading } from "../../standard/icon/icon.ts"
10
+ import { type Actions, actions } from "../control/control.ts"
11
+ import styles from "./notice.module.css"
12
+
13
+ /** How urgent a notice is. */
14
+ export const Level = Schema.Literals(["info", "caution"])
15
+ export type Level = typeof Level.Type
16
+
17
+ export const notice = <Msg>(h: Html.H<Msg>) => ({
18
+ /**
19
+ * Something a person should know before going on. Its pictogram says
20
+ * how urgent it is, together with the words: `info`, or `warning` for a
21
+ * caution, unless another is given. With `dismiss` it can be dismissed:
22
+ * the button is at its end, as high as the notice. With `actions`, what
23
+ * can be done about it is across its foot, edge to edge, as the answers
24
+ * of a `dialog` are.
25
+ */
26
+ notice: <R = never>(
27
+ options: {
28
+ readonly title: string
29
+ readonly level?: Level
30
+ readonly icon?: Icon
31
+ readonly dismiss?: { readonly label: string; readonly onPress: Msg }
32
+ readonly actions?: Actions<Msg>
33
+ },
34
+ ...children: ReadonlyArray<Child<Kind, Msg, R>>
35
+ ): Node<"block", Msg, R> =>
36
+ node(
37
+ h.div
38
+ .class(styles.notice, options.level === "caution" && styles["level-caution"])
39
+ .attr("role", options.level === "caution" ? "alert" : "status")
40
+ .children(
41
+ h.div
42
+ .class(styles["notice-body"])
43
+ .children(
44
+ h.p
45
+ .class(styles["notice-title"])
46
+ .children(
47
+ leading(h, options.icon ?? (options.level === "caution" ? "warning" : "info")),
48
+ options.title
49
+ ),
50
+ inner(children)
51
+ ),
52
+ options.dismiss !== undefined &&
53
+ actions(h, styles["notice-dismiss"], [{ icon: "close", ...options.dismiss }]),
54
+ (options.actions ?? []).length > 0 && actions(h, styles["notice-actions"], options.actions ?? [])
55
+ )
56
+ )
57
+ })
@@ -0,0 +1,30 @@
1
+ /* options: one of several, as a list. */
2
+
3
+ @layer standard.ui {
4
+ .options {
5
+ display: grid;
6
+ grid-template-columns: minmax(0, 1fr);
7
+ justify-self: stretch;
8
+ }
9
+
10
+ .option {
11
+ position: relative;
12
+ display: grid;
13
+ grid-template-columns: minmax(0, 1fr);
14
+ padding: calc((var(--s-target) - 1.5rem) / 2) calc(2 * var(--s-unit));
15
+ background: color-mix(in oklch, var(--s-fg) var(--s-ui-press), transparent);
16
+ /* One that can be chosen is in the text's colour; only one that can't is muted. */
17
+ color: var(--s-fg);
18
+ line-height: 1.5rem;
19
+
20
+ &:has(:disabled) {
21
+ color: var(--s-muted);
22
+ }
23
+
24
+ &:has(:checked) {
25
+ background: var(--s-mark);
26
+ color: var(--s-on-mark);
27
+ font-weight: 700;
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,6 @@
1
+ declare const styles: {
2
+ readonly "option": string;
3
+ readonly "options": string;
4
+ };
5
+ export = styles;
6
+
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `options`: which of several values, as a list down the page.
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 control from "../control/control.module.css"
9
+ import { type Item, radios } from "../control/control.ts"
10
+ import styles from "./options.module.css"
11
+
12
+ export const options = <Msg>(h: Html.H<Msg>) => ({
13
+ /** Which of several values, as a list down the page. The arrow keys move between them. */
14
+ options: <A extends string>(options: {
15
+ readonly name: string
16
+ readonly label: string
17
+ readonly value: A
18
+ readonly onChange: (value: A) => Msg
19
+ readonly items: ReadonlyArray<Item<A>>
20
+ }): Node<"block", Msg> => {
21
+ const id = h.id(`s-ui-${options.name}-label`)
22
+ return node(
23
+ h.div
24
+ .class(control.field)
25
+ .children(
26
+ h.p.class(control.legend).attr("id", id).children(options.label),
27
+ radios(h, { group: styles.options, item: styles.option }, options).attr("aria-labelledby", id)
28
+ )
29
+ )
30
+ }
31
+ })
@@ -0,0 +1,38 @@
1
+ /* pager: the page before and the page after, by name. */
2
+
3
+ @layer standard.ui {
4
+ /* The page before and the page after, by name. */
5
+ .pager {
6
+ display: grid;
7
+ grid-template-columns: repeat(2, minmax(0, 1fr));
8
+ }
9
+
10
+ /* Two blocks, side by side and touching: the way back in the text's colour, the way on in the accent. */
11
+ .pager-link {
12
+ display: grid;
13
+ text-decoration: none;
14
+ grid-template-columns: minmax(0, 1fr);
15
+ align-content: start;
16
+ row-gap: calc(var(--s-unit) / 2);
17
+ min-block-size: calc(12 * var(--s-unit));
18
+ padding: calc(3 * var(--s-unit));
19
+ background: color-mix(in oklch, var(--s-fg) calc(10% + var(--s-ui-press)), var(--s-bg));
20
+ color: var(--s-fg);
21
+
22
+ & > span {
23
+ display: block;
24
+ }
25
+
26
+ &.pager-next {
27
+ grid-column: 2;
28
+ background: color-mix(in oklch, var(--s-on-mark) var(--s-ui-press), var(--s-mark));
29
+ color: var(--s-on-mark);
30
+ }
31
+ }
32
+
33
+ .pager-title {
34
+ font-size: 1.25rem;
35
+ line-height: 1.5rem;
36
+ font-weight: 700;
37
+ }
38
+ }
@@ -0,0 +1,8 @@
1
+ declare const styles: {
2
+ readonly "pager": string;
3
+ readonly "pager-link": string;
4
+ readonly "pager-next": string;
5
+ readonly "pager-title": string;
6
+ };
7
+ export = styles;
8
+
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `pager`: the page before and the page after.
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 { arrowOf, type Direction } from "../arrow/arrow.ts"
9
+ import control from "../control/control.module.css"
10
+ import styles from "./pager.module.css"
11
+
12
+ export const pager = <Msg>(h: Html.H<Msg>) => ({
13
+ /**
14
+ * Where you can go next: the page before and the page after, each by
15
+ * its name, with an arrow pointing its way. `vertical` when the pages
16
+ * are listed down the page, not across it.
17
+ */
18
+ pager: (options: {
19
+ readonly label: string
20
+ readonly previous?: { readonly label: string; readonly title: string; readonly href: string }
21
+ readonly next?: { readonly label: string; readonly title: string; readonly href: string }
22
+ readonly axis?: "horizontal" | "vertical"
23
+ }): Node<"block", Msg> => {
24
+ const vertical = options.axis === "vertical"
25
+ const link = (
26
+ rel: "prev" | "next",
27
+ direction: Direction,
28
+ to: { readonly label: string; readonly title: string; readonly href: string }
29
+ ) =>
30
+ h.a
31
+ .class(control.control, styles["pager-link"], rel === "next" && styles["pager-next"])
32
+ .attr("href", to.href)
33
+ .attr("rel", rel)
34
+ .children(
35
+ h.span.class(control.legend).children(to.label),
36
+ h.span.class(styles["pager-title"]).children(arrowOf(h, direction), " ", to.title)
37
+ )
38
+ return node(
39
+ h.nav
40
+ .class(styles.pager)
41
+ .attr("aria-label", options.label)
42
+ .children(
43
+ options.previous !== undefined && link("prev", vertical ? "up" : "left", options.previous),
44
+ options.next !== undefined && link("next", vertical ? "down" : "right", options.next)
45
+ )
46
+ )
47
+ }
48
+ })