@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,46 @@
1
+ /**
2
+ * `check`: something you agree to or not.
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 styles from "./check.module.css"
10
+
11
+ export const check = <Msg>(h: Html.H<Msg>) => ({
12
+ /** Something you agree to or not, as part of a form. */
13
+ check: (options: {
14
+ readonly name: string
15
+ readonly label: string
16
+ readonly checked: boolean
17
+ readonly onChange: (checked: boolean) => Msg
18
+ /** What is wrong with it as it stands, such as a consent that has to be given. */
19
+ readonly error?: string | null
20
+ readonly disabled?: boolean
21
+ }): Node<"block", Msg> => {
22
+ const error =
23
+ options.error === undefined || options.error === null || options.error === "" ? undefined : options.error
24
+ const id = h.id(`s-ui-check-${options.name}-error`)
25
+ const check = h.label.class(control.control, styles.check).children(
26
+ h.input
27
+ .class(control.native)
28
+ .attr("type", "checkbox")
29
+ .attr("name", options.name)
30
+ .attr("aria-invalid", error === undefined ? undefined : "true")
31
+ .attr("aria-describedby", error === undefined ? undefined : id)
32
+ .checked(options.checked)
33
+ .disabled(options.disabled === true)
34
+ .on("change", options.onChange(!options.checked)),
35
+ h.span.class(styles.box).attr("aria-hidden", "true"),
36
+ h.span.children(options.label)
37
+ )
38
+ return node(
39
+ error === undefined
40
+ ? check
41
+ : h.div
42
+ .class(styles["check-field"])
43
+ .children(check, h.p.class(styles["check-error"]).attr("id", id).attr("role", "alert").children(error))
44
+ )
45
+ }
46
+ })
@@ -0,0 +1,32 @@
1
+ /* `choice`: which value a setting has, by native radio buttons. */
2
+
3
+ @layer standard.ui {
4
+ /* Which value a setting has. */
5
+ .choice {
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ row-gap: var(--s-unit);
9
+ }
10
+
11
+ .segment {
12
+ position: relative;
13
+ display: grid;
14
+ /* Its label starts at its top, at the same inset in every segment, however many lines a neighbour's runs to. */
15
+ align-content: start;
16
+ padding: calc((var(--s-target) - 1.5rem) / 2) calc(2.25 * var(--s-unit));
17
+ background: color-mix(in oklch, var(--s-fg) calc(16% + var(--s-ui-press)), transparent);
18
+ font-weight: 700;
19
+ line-height: 1.5rem;
20
+
21
+ /* Neighbours touch, and are one block; the one that is chosen stands out of it. */
22
+ &:has(:checked) {
23
+ background: var(--s-fg);
24
+ color: var(--s-bg);
25
+ }
26
+
27
+ &:has(:checked:disabled) {
28
+ background: var(--s-muted);
29
+ color: var(--s-bg);
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,6 @@
1
+ declare const styles: {
2
+ readonly "choice": string;
3
+ readonly "segment": string;
4
+ };
5
+ export = styles;
6
+
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `choice`: which of a few values a setting has.
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 "./choice.module.css"
11
+
12
+ export const choice = <Msg>(h: Html.H<Msg>) => ({
13
+ /** Which of a few values a setting has, under a label. The arrow keys move between them. */
14
+ choice: <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.choice, item: styles.segment }, options).attr("aria-labelledby", id)
28
+ )
29
+ )
30
+ }
31
+ })
@@ -0,0 +1,127 @@
1
+ /* What every component shares: the control, the one interaction model there is; a native input under it; a label; a line's colour. */
2
+
3
+ @layer standard.ui {
4
+ .control {
5
+ /* How much of the text's colour is mixed into the control's ground: more on hover, more again while pressed. */
6
+ --s-ui-press: 0%;
7
+
8
+ min-block-size: var(--s-target);
9
+ cursor: pointer;
10
+ user-select: none;
11
+ /* No wait for a second tap, and no double-tap zoom. */
12
+ touch-action: manipulation;
13
+
14
+ /* Pressed is the same for a finger, a button and the space bar. */
15
+ &:active,
16
+ &:has(:active) {
17
+ --s-ui-press: 20%;
18
+ }
19
+
20
+ /* The focus ring is drawn inside, so a scrolling or clipping parent can't cut it off. */
21
+ &:focus-visible,
22
+ &:has(:focus-visible) {
23
+ outline: calc(var(--s-unit) / 4) solid var(--s-read);
24
+ outline-offset: calc(var(--s-unit) / -4);
25
+ }
26
+
27
+ &:disabled,
28
+ &:has(:disabled) {
29
+ --s-ui-press: 0%;
30
+ color: var(--s-muted);
31
+ cursor: not-allowed;
32
+ }
33
+ }
34
+
35
+ /* A native input that fills its control, unseen: the browser keeps its keys, and the label takes the press. */
36
+ .native {
37
+ position: absolute;
38
+ inset: 0;
39
+ inline-size: 100%;
40
+ block-size: 100%;
41
+ opacity: 0;
42
+ cursor: inherit;
43
+ appearance: none;
44
+
45
+ &:focus-visible {
46
+ outline: none;
47
+ }
48
+ }
49
+
50
+ .legend {
51
+ font-size: 0.75rem;
52
+ line-height: 1rem;
53
+ font-weight: 700;
54
+ letter-spacing: 0.08em;
55
+ text-transform: uppercase;
56
+ }
57
+
58
+ .field {
59
+ display: grid;
60
+ row-gap: var(--s-unit);
61
+ justify-items: start;
62
+ }
63
+
64
+ /* A component given a colour takes it as its line's: `--s-line`, and `--s-on-line` for text on it. */
65
+ .lined {
66
+ --s-line: var(--s-accent);
67
+ --s-on-line: var(--s-on-accent);
68
+ }
69
+
70
+ /*
71
+ * The actions of a surface, at its foot: large buttons, touching, with no
72
+ * margin round them. There are two at most, and how wide they are follows
73
+ * from how wide the surface is.
74
+ *
75
+ * A surface up to 36rem wide is one column of a page: a tile, a card, a
76
+ * sheet, a dialog. Its actions share the whole foot: one fills it from
77
+ * edge to edge, two take half each.
78
+ *
79
+ * A surface wider than that is a band across the page, and a button as
80
+ * wide as a band is no longer a button. There each action is 16rem wide,
81
+ * which is half of the widest column, and they stand at the end of the
82
+ * foot, in the corner where the eye ends up.
83
+ *
84
+ * The second number is 16rem while the foot is wider than 36rem, and the
85
+ * whole foot while it is not: the difference is multiplied until it is
86
+ * one or the other.
87
+ */
88
+ .actions {
89
+ display: grid;
90
+ grid-auto-flow: column;
91
+ grid-auto-columns: minmax(0, min(100%, max(16rem, (36rem - 100%) * 9999)));
92
+ justify-content: end;
93
+ }
94
+
95
+ /*
96
+ * One of them: a step from the surface's ground, away from its text.
97
+ * Away, because the text on a block of colour may already be at the
98
+ * lowest contrast that is readable: a step towards it would take it
99
+ * under. So a block with white text goes deeper, and one with black
100
+ * text goes lighter. A surface that is itself a tint of its text sets
101
+ * `--s-ui-step` to that text, and the step goes on the same way.
102
+ */
103
+ .action {
104
+ --s-ui-away: oklch(from var(--s-fg) clamp(0, (0.5 - l) * 1000, 1) 0 0);
105
+
106
+ /* Its label is at its top, a pictogram and its word on one line. */
107
+ display: block;
108
+ min-block-size: calc(8 * var(--s-unit));
109
+ padding: calc(2 * var(--s-unit)) calc(3 * var(--s-unit));
110
+ /* Mixed in a space with no hue to turn: the step is in lightness only. */
111
+ background: color-mix(in oklab, var(--s-ui-step, var(--s-ui-away)) calc(16% + var(--s-ui-press)), var(--s-bg));
112
+ color: var(--s-fg);
113
+ font-weight: 700;
114
+ line-height: 1.5rem;
115
+ text-align: start;
116
+
117
+ /* The one that goes on: a block of the colour the surface's text is in. */
118
+ &.action-primary {
119
+ background: color-mix(in oklch, var(--s-bg) var(--s-ui-press), var(--s-ui-go, var(--s-fg)));
120
+ color: var(--s-ui-on-go, var(--s-bg));
121
+ }
122
+
123
+ &:disabled {
124
+ color: var(--s-muted);
125
+ }
126
+ }
127
+ }
@@ -0,0 +1,12 @@
1
+ declare const styles: {
2
+ readonly "action": string;
3
+ readonly "action-primary": string;
4
+ readonly "actions": string;
5
+ readonly "control": string;
6
+ readonly "field": string;
7
+ readonly "legend": string;
8
+ readonly "lined": string;
9
+ readonly "native": string;
10
+ };
11
+ export = styles;
12
+
@@ -0,0 +1,97 @@
1
+ /**
2
+ * What the components share: a line's colour, native radio buttons, and the actions across the foot of a surface.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+ import type { Html } from "effect/ui/html"
7
+ import { accent } from "../../standard/tokens/classes.ts"
8
+ import type { Colour } from "../../standard/tokens/tokens.ts"
9
+ import { type Icon, leading } from "../../standard/icon/icon.ts"
10
+ import styles from "./control.module.css"
11
+
12
+ /** A colour of the language's, for telling things of one kind apart. It says which one, and nothing else. */
13
+ export const line = (colour: Colour | undefined): string | undefined =>
14
+ colour === undefined ? undefined : `${accent(colour)} ${styles.lined}`
15
+
16
+ /** One of the values a `tabs`, a `choice` or an `options` offers. */
17
+ export interface Item<A extends string> {
18
+ readonly value: A
19
+ readonly label: string
20
+ /** A pictogram before the label. */
21
+ readonly icon?: Icon
22
+ readonly disabled?: boolean
23
+ }
24
+
25
+ /** Native radio buttons under one name: the browser moves between them with the arrow keys. */
26
+ export const radios = <Msg, A extends string>(
27
+ h: Html.H<Msg>,
28
+ look: { readonly group: string; readonly item: string },
29
+ options: {
30
+ readonly name: string
31
+ readonly value: A
32
+ readonly onChange: (value: A) => Msg
33
+ readonly items: ReadonlyArray<Item<A>>
34
+ }
35
+ ) => {
36
+ const name = h.id(`s-ui-${options.name}`)
37
+ return h.div
38
+ .class(look.group)
39
+ .attr("role", "radiogroup")
40
+ .children(
41
+ options.items.map((item) =>
42
+ h.label.class(styles.control, look.item).children(
43
+ h.input
44
+ .class(styles.native)
45
+ .attr("type", "radio")
46
+ .attr("name", name)
47
+ .attr("value", item.value)
48
+ .checked(item.value === options.value)
49
+ .disabled(item.disabled === true)
50
+ .on("change", () => options.onChange(item.value)),
51
+ h.span.children(leading(h, item.icon), item.label)
52
+ )
53
+ )
54
+ )
55
+ }
56
+
57
+ /** One thing to do to what a surface shows or asks: an answer to a `dialog`, or what is done to the thing a `tile` shows. */
58
+ export interface Action<Msg> {
59
+ readonly label: string
60
+ /** What a press sends. Left out, the action submits the form it is in: a card or a sheet inside a `form` ends it this way. */
61
+ readonly onPress?: Msg
62
+ /** A pictogram before the label. */
63
+ readonly icon?: Icon
64
+ readonly disabled?: boolean
65
+ /** The one that goes on: a block of the colour the surface's text is in. There is one at most, and it is last. */
66
+ readonly primary?: boolean
67
+ }
68
+
69
+ /**
70
+ * The actions of one surface: two at most, the one that goes on and the one
71
+ * that doesn't. Alone, either may stand; together, the one that doesn't is
72
+ * first and the `primary` one last. A third thing to do belongs in a `menu`.
73
+ */
74
+ export type Actions<Msg> =
75
+ | readonly []
76
+ | readonly [Action<Msg>]
77
+ | readonly [Action<Msg> & { readonly primary?: false }, Action<Msg> & { readonly primary: true }]
78
+
79
+ /**
80
+ * The actions of a surface, across its foot: large buttons, edge to edge and
81
+ * touching. One fills the foot; two share it, half each. They are part of
82
+ * the surface, so there is no doubt what they act on; and each is a block of
83
+ * its own, a step from the surface, so there is no doubt it can be pressed.
84
+ */
85
+ export const actions = <Msg>(h: Html.H<Msg>, place: string, list: Actions<Msg>) =>
86
+ h.div.class(styles.actions, place).children(
87
+ list.map((action) => {
88
+ const button = h.button
89
+ .class(styles.control, styles.action, action.primary === true && styles["action-primary"])
90
+ .attr("type", action.onPress === undefined ? "submit" : "button")
91
+ .disabled(action.disabled === true)
92
+ return (action.onPress === undefined ? button : button.on("click", action.onPress)).children(
93
+ leading(h, action.icon),
94
+ action.label
95
+ )
96
+ })
97
+ )
@@ -0,0 +1,42 @@
1
+ /* dialog: a question that needs an answer. */
2
+
3
+ @layer standard.ui {
4
+ /* A question that needs an answer. Flush with the page's margin, a block of the accent, and let down from above the window. */
5
+ .dialog {
6
+ inset-block: 12dvb auto;
7
+ inset-inline: var(--s-margin) auto;
8
+ inline-size: min(32rem, 100% - 2 * var(--s-margin));
9
+ max-block-size: 76dvb;
10
+ --s-bg: var(--s-accent);
11
+ --s-fg: var(--s-on-accent);
12
+ --s-mark: var(--s-on-accent);
13
+ --s-on-mark: var(--s-accent);
14
+ --s-read: var(--s-on-accent);
15
+ --s-wrong: var(--s-on-accent);
16
+ --s-muted: var(--s-accent-soft);
17
+ --s-flat: 1;
18
+ translate: 0 calc(-100% - 12dvb);
19
+
20
+ @starting-style {
21
+ &[open] {
22
+ translate: 0 calc(-100% - 12dvb);
23
+ }
24
+ }
25
+
26
+ /*
27
+ * While its question is open, the page behind it steps back: a veil of
28
+ * the page's own ground is drawn over it. So the page gets paler in the
29
+ * light scheme and darker in the dark scheme, and what still stands out
30
+ * is the question. The veil appears the moment the dialog does and goes
31
+ * the moment it does: it does not fade.
32
+ */
33
+ &::backdrop {
34
+ background: color-mix(in oklch, var(--s-paper) 72%, transparent);
35
+ }
36
+ }
37
+
38
+ /* The answers, across the bottom: out to the edges of the dialog, through its padding. */
39
+ .dialog-actions {
40
+ margin: 0 calc(-3 * var(--s-unit)) calc(-3 * var(--s-unit));
41
+ }
42
+ }
@@ -0,0 +1,6 @@
1
+ declare const styles: {
2
+ readonly "dialog": string;
3
+ readonly "dialog-actions": string;
4
+ };
5
+ export = styles;
6
+
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `dialog`: a question that needs an answer before anything else.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+ import type { Html } from "effect/ui/html"
7
+ import { type Child, type Kind, node, type Node } from "../../Node.ts"
8
+ import { type Actions, actions } from "../control/control.ts"
9
+ import { modal } from "../modal/modal.ts"
10
+ import styles from "./dialog.module.css"
11
+
12
+ export const dialog = <Msg>(h: Html.H<Msg>) => ({
13
+ /**
14
+ * A question that needs an answer before anything else. With `alert` a
15
+ * press outside it doesn't dismiss it: only Escape and its buttons do.
16
+ *
17
+ * With `actions` the answers are large buttons across its bottom, edge to
18
+ * edge and touching: the one that goes on, `primary` and last, a block of
19
+ * the colour the dialog's text is in; and before it the one that doesn't.
20
+ * There are two at most, and one alone fills the bottom.
21
+ */
22
+ dialog: <R = never>(
23
+ options: {
24
+ readonly open: boolean
25
+ readonly title: string
26
+ readonly close: { readonly label: string; readonly onPress: Msg }
27
+ readonly alert?: boolean
28
+ readonly actions?: Actions<Msg>
29
+ },
30
+ ...children: ReadonlyArray<Child<Kind, Msg, R>>
31
+ ): Node<"block", Msg, R> => {
32
+ const list = options.actions ?? []
33
+ return node(
34
+ modal(
35
+ h,
36
+ "dialog",
37
+ [styles.dialog],
38
+ options,
39
+ children,
40
+ list.length > 0 && actions(h, styles["dialog-actions"], list)
41
+ )
42
+ )
43
+ }
44
+ })
@@ -0,0 +1,57 @@
1
+ /* disclosure: more, on request. */
2
+
3
+ @layer standard.ui {
4
+ .disclosure {
5
+ /* So a height can travel to `auto`. */
6
+ interpolate-size: allow-keywords;
7
+
8
+ &::details-content {
9
+ block-size: 0;
10
+ overflow: clip;
11
+ transition:
12
+ block-size var(--s-move) var(--s-ease),
13
+ content-visibility var(--s-move) allow-discrete;
14
+ }
15
+
16
+ &[open]::details-content {
17
+ block-size: auto;
18
+ }
19
+ &[open] > .summary > :global(.s-ui-arrow) {
20
+ rotate: 0deg;
21
+ }
22
+
23
+ /* Open, its heading is a block of the text's colour. */
24
+ &[open] > .summary {
25
+ background: color-mix(in oklch, var(--s-bg) var(--s-ui-press), var(--s-fg));
26
+ color: var(--s-bg);
27
+ }
28
+ }
29
+
30
+ .summary {
31
+ display: grid;
32
+ grid-template-columns: minmax(0, 1fr) auto;
33
+ column-gap: var(--s-gutter);
34
+ align-items: baseline;
35
+ padding-block: calc((var(--s-target) - 1.5rem) / 2);
36
+ padding-inline: calc(2 * var(--s-unit));
37
+ background: color-mix(in oklch, var(--s-fg) calc(8% + var(--s-ui-press)), transparent);
38
+ font-weight: 700;
39
+ line-height: 1.5rem;
40
+ list-style: none;
41
+
42
+ &::-webkit-details-marker {
43
+ display: none;
44
+ }
45
+ /* The arrow points to where the content will go, and turns to point back. */
46
+ & > :global(.s-ui-arrow) {
47
+ transition: rotate var(--s-move) var(--s-ease);
48
+ }
49
+ }
50
+
51
+ .disclosure-body {
52
+ display: grid;
53
+ grid-template-columns: minmax(0, 1fr);
54
+ row-gap: calc(2 * var(--s-unit));
55
+ padding: calc(2 * var(--s-unit)) calc(2 * var(--s-unit)) calc(3 * var(--s-unit));
56
+ }
57
+ }
@@ -0,0 +1,7 @@
1
+ declare const styles: {
2
+ readonly "disclosure": string;
3
+ readonly "disclosure-body": string;
4
+ readonly "summary": string;
5
+ };
6
+ export = styles;
7
+
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `disclosure`: more, on request.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+ import type { Html } from "effect/ui/html"
7
+ import { type Child, contents as inner, type Kind, node, type Node } from "../../Node.ts"
8
+ import { arrowOf } from "../arrow/arrow.ts"
9
+ import control from "../control/control.module.css"
10
+ import styles from "./disclosure.module.css"
11
+
12
+ export const disclosure = <Msg>(h: Html.H<Msg>) => ({
13
+ /**
14
+ * More, on request: a heading that opens what is under it. Disclosures
15
+ * with the same `name` are an accordion: opening one closes the
16
+ * others.
17
+ */
18
+ disclosure: <R = never>(
19
+ options: { readonly title: string; readonly name?: string; readonly open?: boolean },
20
+ ...children: ReadonlyArray<Child<Kind, Msg, R>>
21
+ ): Node<"block", Msg, R> =>
22
+ node(
23
+ h.details
24
+ .class(styles.disclosure)
25
+ .attr("name", options.name)
26
+ .attr("open", options.open === true ? "" : undefined)
27
+ .children(
28
+ h.summary.class(control.control, styles.summary).children(h.span.children(options.title), arrowOf(h, "down")),
29
+ h.div.class(styles["disclosure-body"]).children(inner(children))
30
+ )
31
+ )
32
+ })