@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NMNM.CC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,517 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nmnmcc/standard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Standard design language, built on `effect/ui`. It is one package, organised by module, the same way as `effect`:
|
|
4
|
+
|
|
5
|
+
| Module | Entry point | Contents |
|
|
6
|
+
| ---------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| `Standard` | `@nmnmcc/standard`, `@nmnmcc/standard/Standard` | The language itself: the grid, typography, flat colour, text, forms, and the direction of a view change |
|
|
8
|
+
| `Ui` | `@nmnmcc/standard`, `@nmnmcc/standard/Ui` | Interactive components written in this language; its `s` is all the builders of `Standard` plus the components |
|
|
9
|
+
| `Palette` | `@nmnmcc/standard`, `@nmnmcc/standard/Palette` | The colour algorithm: it computes vivid, readable colours from a hue |
|
|
10
|
+
| `Extend` | only `@nmnmcc/standard/Extend` | The door left open for layers built on top. It is not exported from the main entry point: a page that does not import it cannot leave this system |
|
|
11
|
+
|
|
12
|
+
There is only one stylesheet: `@nmnmcc/standard/standard.css`. The language and the components are both in it.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add @nmnmcc/standard effect
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import "@nmnmcc/standard/standard.css"
|
|
20
|
+
import { Standard, Ui } from "@nmnmcc/standard"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The documentation, written with the library itself, is at <https://nmnmcc.github.io/standard/>. The changes of every version are in the [changelog](https://github.com/nmnmcc/standard/blob/main/CHANGELOG.md).
|
|
24
|
+
|
|
25
|
+
## Source layout
|
|
26
|
+
|
|
27
|
+
Every component has its own folder, which holds the builder and its stylesheet together. The folder name is the name that comes after `s.`.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/
|
|
31
|
+
index.ts the main entry point: the two namespaces Standard and Ui
|
|
32
|
+
Standard.ts assembles the builders in standard/ into the s of the language
|
|
33
|
+
Ui.ts adds the components in ui/ on top of that
|
|
34
|
+
Extend.ts the door left open for layers built on top
|
|
35
|
+
Node.ts the nodes that builders take and return
|
|
36
|
+
standard/ the language
|
|
37
|
+
tokens/ tokens.ts: the Schemas of the tokens, and travel; classes.ts: the classes for the tokens; tokens.module.css
|
|
38
|
+
page/ page, plus the reset, the fonts, and how the window moves on a page change
|
|
39
|
+
layout/ section, grid, col, stack, row, rule
|
|
40
|
+
text/ text, em, code, listing, link, br
|
|
41
|
+
colour/ the colour algorithm: it computes the palette from hues
|
|
42
|
+
icon/ icon, and the icon set (Material Symbols)
|
|
43
|
+
list/ image/ table/ button/
|
|
44
|
+
field/ field, textarea, select
|
|
45
|
+
form/
|
|
46
|
+
ui/ the components, one folder each
|
|
47
|
+
control/ what all components share: the interaction model for press, focus and disabled; the native radio group; line colours; the actions across the foot of a dialog, a sheet, a notice, a tile, a card and an item
|
|
48
|
+
modal/ the part shared by sheet and dialog
|
|
49
|
+
arrow/ avatar/ board/ bullet/ card/ carousel/ check/ choice/ dialog/
|
|
50
|
+
disclosure/ flap/ item/ key/ menu/ navigator/ notice/ options/ pager/ pagination/
|
|
51
|
+
popover/ progress/ route/ sheet/ skeleton/ slider/ stepper/ tabs/
|
|
52
|
+
tag/ tile/ toasts/ toggle/ trail/
|
|
53
|
+
test/
|
|
54
|
+
Standard.test.ts Ui.test.ts
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For example, `s.navigator` is in `src/ui/navigator/navigator.ts`, and its styles are next to it in `navigator.module.css`.
|
|
58
|
+
Every file exports one function that takes `h` and returns builders. `Standard.ts` / `Ui.ts` spread them all into `s`.
|
|
59
|
+
|
|
60
|
+
The conventions between stylesheets (the tests check them):
|
|
61
|
+
|
|
62
|
+
- A class is defined in only one stylesheet: the one of the component it belongs to.
|
|
63
|
+
- To refer to the class of another component, use its built name: `:global(.s-ui-toasts)`.
|
|
64
|
+
- The order of the layers is declared only once, in `tokens.module.css`, and `Standard.ts` imports that file first.
|
|
65
|
+
|
|
66
|
+
## `Standard`: the language
|
|
67
|
+
|
|
68
|
+
A thin wrapper over `effect/ui` (Effect 4): a view can only be written with `s`, and `s` accepts nothing but tokens.
|
|
69
|
+
This guarantees the basic rules of Swiss Style (the International Typographic Style). Within the rules, you can combine things freely.
|
|
70
|
+
|
|
71
|
+
### Usage
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import "@nmnmcc/standard/standard.css"
|
|
75
|
+
import { Standard } from "@nmnmcc/standard"
|
|
76
|
+
import { Schema } from "effect"
|
|
77
|
+
import { Component } from "effect/ui"
|
|
78
|
+
|
|
79
|
+
// The logic is plain effect/ui
|
|
80
|
+
const Logic = Component.define({
|
|
81
|
+
name: "Counter",
|
|
82
|
+
model: Schema.Number,
|
|
83
|
+
message: Schema.Literal("ClickedAdd")
|
|
84
|
+
}).logic({
|
|
85
|
+
init: () => 0,
|
|
86
|
+
update: ($) => $.model + 1
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// The view gets s, not h
|
|
90
|
+
export const Counter = Standard.component(Logic, (s, count) =>
|
|
91
|
+
s.page(
|
|
92
|
+
{ accent: "red" },
|
|
93
|
+
s.section(
|
|
94
|
+
{ as: "main", pad: 8 },
|
|
95
|
+
s.grid({}, s.col({ span: 8 }, s.text("display", String(count)), s.button({ onClick: "ClickedAdd" }, "Add one")))
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`Standard.component` returns a plain `effect/ui` HTML component. To mount it, render it on the server,
|
|
102
|
+
route to it or call `Component.provide`, use the API of `effect/ui` itself.
|
|
103
|
+
|
|
104
|
+
### Guarantees
|
|
105
|
+
|
|
106
|
+
| Rule | How it is guaranteed |
|
|
107
|
+
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
108
|
+
| A twelve-column grid | `span` and `start` can only be 1–12; when a start is out of range, CSS shortens the span |
|
|
109
|
+
| A fixed type scale | The `role` of `s.text(role, …)` is one of seven string literals |
|
|
110
|
+
| The same spacing everywhere | `gap` and `pad` can only be values on the spacing scale |
|
|
111
|
+
| Colour is flat and comes from the palette | There is no limit on the number of colours: `accent` can be any colour of the palette, and the page and every `section` can each choose their own. The colour values are only in the stylesheet, and there are no gradients |
|
|
112
|
+
| Flush left, not centred | `align` has no `center`. What is written in a block starts at its top left, however large the block is made: tiles, cards, tabs and segments in a row all start on one line. Only a single glyph in a square of its own (a pictogram in a button, a page number, the letter of a roundel) has the same room on every side |
|
|
113
|
+
| No ornament | There are no rounded corners, shadows or gradients to choose |
|
|
114
|
+
|
|
115
|
+
There is no `class`, `style` or `attr` on `s`. The key of the node type `Standard.Node` is a `symbol` that is
|
|
116
|
+
not exported, so the builders of `s` are the only way to make a node.
|
|
117
|
+
|
|
118
|
+
### What it does not restrict
|
|
119
|
+
|
|
120
|
+
- **Nesting is free.** `grid`, `col`, `stack`, `row` and `section` can be nested in one another in any way.
|
|
121
|
+
Only two kinds of node are kept apart: blocks and inline text. `s.text` takes only inline nodes; all the other containers take both.
|
|
122
|
+
- **Columns inside a column.** An `s.grid` placed directly in an `s.col` continues the twelve columns of the outer grid through `subgrid`,
|
|
123
|
+
so however deep the nesting, everything lands on the same column lines.
|
|
124
|
+
- **Outside components.** `s.child((h) => Chart(h, { props }))` puts in any `effect/ui` component,
|
|
125
|
+
and its dependencies show up among those of the parent component. This is the only way out: that component is responsible for what it draws inside.
|
|
126
|
+
|
|
127
|
+
### Builders
|
|
128
|
+
|
|
129
|
+
| Builder | What it is |
|
|
130
|
+
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| `s.page({ accent? }, …)` | The root of a page: the font, the ground, the accent (one of the eight colours of the palette). It is also the container that the folding of the columns is measured against |
|
|
132
|
+
| `s.section({ as?, tone?, pad?, gap?, label? }, …)` | A full-width region; its children are stacked vertically |
|
|
133
|
+
| `s.grid({ gap?, align? }, …)` | Twelve columns; a child that is not a `col` takes the full row |
|
|
134
|
+
| `s.col({ span, start?, gap?, align? }, …)` | Spans a number of columns; its children are stacked vertically |
|
|
135
|
+
| `s.stack({ gap?, as?, label? }, …)` / `s.row({ gap?, align? }, …)` | Vertical / horizontal (wraps automatically). With `as`, a stack is a landmark inside a column, such as an `article` |
|
|
136
|
+
| `s.rule({ weight?, accent? })` | A horizontal rule |
|
|
137
|
+
| `s.text(role, …)` | A block of text: `display` `title` `heading` `lead` `body` `caption` `label` |
|
|
138
|
+
| `s.em(emphasis, …)` / `s.link({ href, external? }, …)` / `s.br` | Inline |
|
|
139
|
+
| `s.list({ marker?, ruled? }, …)` | A list; every child is one item |
|
|
140
|
+
| `s.facts({ beside? }, { name, value }, …)` | Facts about one thing: each a name and what it is. The names are small labels above their values, or beside them with `beside` |
|
|
141
|
+
| `s.image({ src, alt, ratio?, caption? })` | An image cropped to a ratio; with a `caption`, a figure |
|
|
142
|
+
| `s.quote({ by?, from? }, …)` | A quotation, with who said it and where |
|
|
143
|
+
| `s.table({ columns, rows })` | A table of text; number columns are aligned right, with tabular figures |
|
|
144
|
+
| `s.button({ onClick?, kind?, type?, disabled? }, label)` | A button |
|
|
145
|
+
| `s.field({ name, label, value, onInput, error?, … })` | An input with a label and an error message |
|
|
146
|
+
| `s.form({ onSubmit, gap? }, …)` | A form |
|
|
147
|
+
| `s.child(place)` | Puts in another component |
|
|
148
|
+
| `s.props` | The props of the current component |
|
|
149
|
+
|
|
150
|
+
The tokens are exported as Schemas (`Standard.Span`, `Space`, `Colour`, `Tone`, `Role`, `Emphasis`,
|
|
151
|
+
`Align`, `Ratio`, `Landmark`), so you can use them directly in the Schemas of a Model and of messages.
|
|
152
|
+
|
|
153
|
+
### Styles
|
|
154
|
+
|
|
155
|
+
The visual system is hand-written CSS Modules, one for every component, kept in the component's own folder (see the source layout above). At build time they are merged into one `dist/standard.css`.
|
|
156
|
+
|
|
157
|
+
- **Class names are typed.** `typed-css-modules` generates declaration files from the stylesheets, and what the builders write is
|
|
158
|
+
`styles[`span-${span}`]` and `styles.col`. If a token has no class in the stylesheet,
|
|
159
|
+
or a class name is misspelt, the library does not compile.
|
|
160
|
+
- **The built class names are stable and readable.** The library is built with Vite. The `.col` of the language is built as `s-col`,
|
|
161
|
+
and the `.toggle` of the components is built as `s-ui-toggle`. Users of the library need no CSS Modules configuration:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import "@nmnmcc/standard/standard.css"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The CSS features used in the stylesheets:
|
|
168
|
+
|
|
169
|
+
- `@layer standard.*`: all the styles are in cascade layers, and the order of the layers is fixed
|
|
170
|
+
- `@property`: `--s-span`, `--s-gap` and others are registered as non-inheriting, so the span and the gap of a column do not leak to its descendants
|
|
171
|
+
- `subgrid`: nested grids share the column lines of the outer grid
|
|
172
|
+
- `@container` and `cqi`: when the **page container** (not the viewport) is narrower than 48rem, every column takes the full row;
|
|
173
|
+
the size of the titles and the gutter between columns change with the width of that container
|
|
174
|
+
- `:where()` gives the defaults zero specificity, so the token classes always win
|
|
175
|
+
- `:has()`: when a field has `aria-invalid` in it, the whole field changes colour
|
|
176
|
+
- `color-mix(in oklch, …)`, native nesting, logical properties, `text-wrap: balance / pretty`
|
|
177
|
+
|
|
178
|
+
It needs browsers that support these features (roughly: Chrome, Safari and Firefox from the end of 2023 on).
|
|
179
|
+
|
|
180
|
+
### Type safety
|
|
181
|
+
|
|
182
|
+
The source has no `any`, no type assertions, no non-null assertions (`!`),
|
|
183
|
+
and no `@ts-ignore`. The only `as` is `as const`. The `@ts-expect-error` lines in the tests
|
|
184
|
+
are there to check that code which breaks the rules really does not compile.
|
|
185
|
+
|
|
186
|
+
### Building another layer on top
|
|
187
|
+
|
|
188
|
+
`@nmnmcc/standard/Extend` is the door left open for libraries built on top (the `Ui` module of this package is built this way):
|
|
189
|
+
`node` / `content` / `contents` convert between content built with `h` and nodes; `builders(h)` gives all the builders;
|
|
190
|
+
`component` defines a component whose view returns nodes; `tone` / `accent` / `gap` / `pad` give the class names for the tokens.
|
|
191
|
+
Anyone who imports this entry point is responsible for keeping the result in Swiss Style; a page that does not import it cannot leave this system.
|
|
192
|
+
|
|
193
|
+
### Input
|
|
194
|
+
|
|
195
|
+
There are no hover styles: when the pointer rests on a control, nothing changes. A press gives the `:active` feedback, the same for a mouse and a finger.
|
|
196
|
+
The smallest touch target of a control is `--s-target` (44px for a fine pointer, 48px for a coarse one, `pointer: coarse`). `touch-action: manipulation` removes the tap delay.
|
|
197
|
+
|
|
198
|
+
### The canvas
|
|
199
|
+
|
|
200
|
+
The app is one whole canvas with no edges, and the screen is only a window onto it. Every route has a place on the canvas,
|
|
201
|
+
and a view change is the window moving from one to another:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
Navigated: ($, { route }) => $.evolve({ route }).viewTransition(Standard.travel(AppRoute, $.model.route, route))
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`Standard.travel` takes the route table (a `Route.union` of `effect/ui`) and two of its routes, and returns `forward` / `back` combined with `down` / `up`
|
|
208
|
+
(for the same place it returns an empty array). The app does not say where a route is; the table does, so the addresses have to be written the way the canvas is drawn:
|
|
209
|
+
|
|
210
|
+
An address is `/section/page`, and under a page whatever is under it:
|
|
211
|
+
|
|
212
|
+
- **The section, along the line of reading**: the first segment. Sections lie in the order the table first names them: from `/read/…` to `/settings/…` is forward.
|
|
213
|
+
- **The page, down the page**: the second segment. The pages of a section lie in the order the table declares them, and every section starts at the top.
|
|
214
|
+
So from the second page of one section to the fifth of another is forward and down, at 45 degrees, and to the first of another forward and up.
|
|
215
|
+
- **Under a page, forward again**: each segment after the second is a step forward from its page: `/read/topics/:id` is straight along from `/read/topics`,
|
|
216
|
+
and a checkout that follows the basket is `/order/basket/checkout`. Params that follow one another are one step between them.
|
|
217
|
+
- **Params in order**: a `Schema.Literals` param takes a place for each literal, in the order they are given. A param of any other Schema takes one place, and two of its values
|
|
218
|
+
are in the order a list of them would be read in: numbers as numbers, `B9` before `B10`, `2026-11-24` before `2026-12-02`.
|
|
219
|
+
So a post that should lie in the order of its date is `/read/latest/:date/:id`.
|
|
220
|
+
- **`/` is not a place**: redirect it to the first page, with `Route.redirect("/", …)`.
|
|
221
|
+
|
|
222
|
+
Addresses written like that are not always the ones people expect: `/`, `/posts/:id`, `/settings`. For those, draw the canvas by hand, once, with `Standard.canvas`,
|
|
223
|
+
and leave the addresses as they are:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
const Canvas = Standard.canvas(BlogRoute, [
|
|
227
|
+
// A section: its pages from the top down, and under a page what is a step forward from it.
|
|
228
|
+
[{ at: "Latest", under: ["Post"] }, "Archive", { at: "Topics", under: ["Topic"] }],
|
|
229
|
+
["Saved", "Write"],
|
|
230
|
+
["Display"]
|
|
231
|
+
])
|
|
232
|
+
|
|
233
|
+
Navigated: ($, { route }) => $.evolve({ route }).viewTransition(Canvas.travel($.model.route, route))
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The sections lie along the line of reading, the pages of each down the page from its top, and what is `under` a page a step forward from it, listed downwards.
|
|
237
|
+
A place is the tag of a route, for all its addresses (in the order of their params, as above), or a route, for one address: `BlogRoute.Post({ params: { id } })`.
|
|
238
|
+
An address is at the place that names it, and failing that at the place of its tag. Every route but the catch-all has to be on the canvas, or `canvas` throws.
|
|
239
|
+
A canvas that depends on the Model, such as the posts there are, is drawn in `update`.
|
|
240
|
+
|
|
241
|
+
You do not need to mark which part will move: what moves is the screen seen in the window. The old screen and the new one slide past end to end, over a distance of one window,
|
|
242
|
+
wherever the page is scrolled to. Things that should stay in place (for example the `navigator` of ui) carry a `view-transition-name`.
|
|
243
|
+
**Nothing fades**: state changes instantly, and position really moves.
|
|
244
|
+
The duration tokens are `--s-quick`, `--s-move` and `--s-travel`; with the system's “reduce motion” setting, all of them are 0.
|
|
245
|
+
|
|
246
|
+
### New builders and options in this version
|
|
247
|
+
|
|
248
|
+
`s.code`, `s.listing` (code), `s.textarea`, `s.select`; `hint`, `suggestions`, `date` / `time` on `s.field`;
|
|
249
|
+
`current` on `s.link` (an external link gets an arrow automatically); `only`, `sticky`, `fill` on `s.col` (the first child fills the height left in this row, so cards side by side are the same height); `only` on `s.stack`;
|
|
250
|
+
`accent` on `s.section`.
|
|
251
|
+
|
|
252
|
+
### Added while building the bank example
|
|
253
|
+
|
|
254
|
+
`examples/bank` is a whole banking app written with this package, built to find out what was missing. What it turned up is now in the library:
|
|
255
|
+
|
|
256
|
+
- `s.facts`: names and their values, such as the lines of a payment before it is sent.
|
|
257
|
+
- `href` on `s.tile`: a tile that leads to a place is a link, and looks no different.
|
|
258
|
+
- `dense` on `s.board`, and `only` on its columns: rows of body text for a long list, and columns that are left out of a narrow page so that the last one, the amount, is never pushed out of sight.
|
|
259
|
+
- `colour` on `s.progress`, for telling several apart.
|
|
260
|
+
- `inputMode`, `autoComplete` and `autoFocus` on `s.field`; `hint` and `error` on `s.select` and `s.textarea`.
|
|
261
|
+
- `disabled` on every action of `s.dialog`.
|
|
262
|
+
- 23 more icons, among them `account-balance`, `credit-card`, `payments`, `savings` and `swap-horiz`.
|
|
263
|
+
|
|
264
|
+
And what it found wrong is fixed: a long value no longer breaks out of a tile; a sheet on a narrow screen no longer lets a line of the page show above it; code inside muted text keeps its contrast on a tinted surface.
|
|
265
|
+
|
|
266
|
+
`examples/estate`, an estate agency, was built the same way, and added:
|
|
267
|
+
|
|
268
|
+
- `image` on `s.tile`: a picture across its top, edge to edge, for a tile that leads to a thing to be seen, such as a home.
|
|
269
|
+
- `actions` on `s.tile`: what can be done to the thing the tile shows, such as removing a saved home. They are large buttons across the tile's foot, edge to edge and touching, the same as the answers of a `dialog`, and made by the same code: part of the tile's block, so there is no doubt what they act on, and each a block of its own, a step from the surface, so there is no doubt it can be pressed. A button set under a tile, with a gap between, did not say what it acted on.
|
|
270
|
+
- `actions` on `s.card`, and the new `s.item`: the same list, for the same reason. A card's are across its foot (the sum of an order, and “Check out”). `s.item` is a row of a ruled `s.list` with its actions at the end of the row, as high as the row and out to its edge; on a narrow page they are across its foot. A row of buttons inside a list row, or a button under a card, is no longer needed.
|
|
271
|
+
- **No frames, except on what is active.** Everything that was drawn as an outline is now a solid block, a step from the ground towards the text: the secondary `button`, `field` / `select` / `textarea`, the box of a `check`, the track of a `toggle`, the segments of a `choice`, a `tag` with no colour, a `key`, and the panel of a `popover` and a `menu`. A frame is left for one thing only: what is active. A field is framed while the caret is in it, and whatever has the keyboard's focus keeps its ring. A disabled field is a lighter block (it used to be dashed), a wrong one is a red block, and a read-only one is as light as what is only shown. This replaces “a field is a framed, empty box” below.
|
|
272
|
+
- **Two actions at most, and one alone is as wide as its surface.** A surface has one action that goes on and one that doesn't, and no more: `actions` is `[action]` or `[secondary, primary]`, and the type refuses anything else. How wide they are follows from how wide the surface is. A surface up to 36rem wide is one column of a page (a tile, a card, a sheet, a dialog): its actions share the whole foot, one filling it from edge to edge and two taking half each. A wider surface is a band across the page, such as a notice over the whole measure or a row of a list: there each action is 16rem wide, and they stand at the end of the foot. They are at the foot of the surface however high it is made, not under the last line of what is written. A third thing to do goes in a `menu`, or in the surface itself.
|
|
273
|
+
- **A notice is as wide as what it says.** A line of text ends at 68ch, so a notice ends there too, with its margin on each side; it used to run across the whole page, however short its sentence. In a narrower column it is as wide as the column.
|
|
274
|
+
- `actions` on `s.notice` and on `s.sheet`: the same list again. A notice's are across its foot (“Your basket is empty”, and “Go to the menu”); a sheet's are across its bottom, in view whatever it is scrolled to, and on a narrow screen over the button that closes it. The `dismiss` button of a notice is drawn the same way: at its end, as high as the notice.
|
|
275
|
+
- An action with no `onPress` submits the form it is in, so a card at the end of a form can carry the button that sends it.
|
|
276
|
+
- `actions` on `s.dialog` is now the same list: `[{ label, onPress, icon?, disabled?, primary? }]`, in place of `{ primary, secondary? }`. Mark the one that goes on `primary`, and put it last.
|
|
277
|
+
- `error` on `s.check`, for a consent that has to be given.
|
|
278
|
+
- **An error is red, whatever the accent is.** It used to take the accent, so on a green page what was wrong was said in green. The new `--s-wrong` is the red as text, picked for the ground it is on like `--s-read`; fields, selects, textareas and checks use it.
|
|
279
|
+
- In `s.options`, `s.tabs` and `s.pagination`, what can be chosen is now in the text's colour, and only what can't be is muted. Before, a value that was not chosen and one that could not be chosen looked the same.
|
|
280
|
+
- **A field is a framed, empty box.** It used to be a tinted block, the same as a card or a listing, and could not be told from something that is only shown. Now what is shown is a filled block and what is filled in has a frame; the frame doubles and takes the accent with the caret in it, is dashed when disabled, and goes back to a block when `readOnly`.
|
|
281
|
+
- On `s.field`: `required`, `icon`, `prefix`, `suffix`, `action` (a button at the end of the box, to clear what is typed or show a password), `maxLength` with a count, `min` / `max` / `step`, `readOnly` and `onBlur`. `s.textarea` takes `required`, `maxLength`, `rows`, `readOnly` and `onBlur`; `s.select` takes `required`, `icon` and `placeholder`.
|
|
282
|
+
|
|
283
|
+
`examples/cafe`, a café to order from, added:
|
|
284
|
+
|
|
285
|
+
- `s.stepper`: a small whole number between two buttons, for how many of a thing. A slider is for a wide range, and a field for a number that is typed; neither suits “two flat whites”.
|
|
286
|
+
- 12 more icons, among them `local-cafe`, `bakery-dining`, `shopping-bag`, `takeout-dining` and `redeem`.
|
|
287
|
+
- **Tints don't stack.** A ruled list in a card used to put its tint on the card's, and muted text in it fell below the contrast it is picked for. Now the list's items are cut out of the card, down to the ground the card is on.
|
|
288
|
+
|
|
289
|
+
`examples/blog`, a journal to read and to write for, added what long text needs:
|
|
290
|
+
|
|
291
|
+
- `s.quote({ by?, from? }, …)`: somebody else's words, on a surface of their own and in the size of a lead, with who said it and where under them. It is a `figure` with a `blockquote` in it, so a screen reader is told that the words are quoted.
|
|
292
|
+
- `caption` on `s.image`: the image becomes a figure, with the caption set small under it.
|
|
293
|
+
- `as` and `label` on `s.stack`: a landmark inside a column, such as the `article` of a page that has an aside beside it. A `section` is always as wide as the page, with the page's margin.
|
|
294
|
+
- 6 more icons: `article`, `chat`, `sell`, `rss-feed`, `inventory-2` and `edit-note`.
|
|
295
|
+
|
|
296
|
+
### Text selection
|
|
297
|
+
|
|
298
|
+
An interface is for pressing, not for selecting text by dragging: by default, no text on the page can be selected. To let the text of a region be selected and copied, say so explicitly:
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
s.section({ as: "main", select: true }, …) // the text in this region can be selected
|
|
302
|
+
s.stack({ select: true }, …)
|
|
303
|
+
s.listing({ select: true }, code) // make a single piece of code selectable
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
- Buttons and other controls inside such a region still cannot be selected.
|
|
307
|
+
- What you type into an input can always be selected; these rules do not change that.
|
|
308
|
+
- On the docs site, only the body region (`main`) has `select` on; the header, the navigator and the pager cannot be selected.
|
|
309
|
+
|
|
310
|
+
### Fonts
|
|
311
|
+
|
|
312
|
+
Standard ships no font and does not force any one typeface on you: there are too many to choose from. The app loads its own fonts, then tells Standard which they are with custom properties:
|
|
313
|
+
|
|
314
|
+
```css
|
|
315
|
+
:root {
|
|
316
|
+
--s-font: "Geist Variable"; /* body text and headings */
|
|
317
|
+
--s-font-mono: "Geist Mono Variable"; /* optional: code */
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
- **A neo-grotesque is recommended** (in the line of Helvetica, Univers, Akzidenz-Grotesk): the type scale, the two weights and the icons were all designed against this kind of typeface.
|
|
322
|
+
- **When none is set**, the one that comes with the system is used (Helvetica Neue / Helvetica / Nimbus Sans / Arial).
|
|
323
|
+
- **Only one family.** It is best to have two weights, regular and bold. A family with only one weight works too: the browser then synthesises the bold (`font-synthesis: weight`; italic and `small-caps` are still not synthesised).
|
|
324
|
+
- The docs site uses the variable fonts of [Geist](https://fonts.google.com/specimen/Geist) and its companion [Geist Mono](https://fonts.google.com/specimen/Geist+Mono) (OFL-1.1, self-hosted by the site through `@fontsource-variable/geist` and `@fontsource-variable/geist-mono`): one file holds all the weights 100–900, so the regular and the bold come from the font and are not synthesised.
|
|
325
|
+
|
|
326
|
+
### Light and dark
|
|
327
|
+
|
|
328
|
+
A page is light all over, or dark all over:
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
s.page({ scheme: "auto" }, …) // or "light", "dark"; the default is "auto", which follows the system
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
- **Paper and ink swap**: `paper` is what the page is printed on, `ink` is what it is printed with. In the light scheme it is black on white, and in the dark scheme the two swap; every ground, surface and text colour defined from them changes with them.
|
|
335
|
+
- **Surfaces follow the ground**: cards, notices, sheets, code blocks, table headers and the first level of the navigator are all “the ground, one small step towards the text colour”. So they are light in the light scheme and dark in the dark scheme. The light scheme no longer has whole dark regions, and the reverse is true too.
|
|
336
|
+
- **The palette does not change**: a red block is the same red in both schemes, and the text on it is the same white. What changes is which colour is picked when “a colour is used as text”: the readable one, chosen by the lightness of the ground it is on.
|
|
337
|
+
- **`tone: "ink"`** is the scheme reversed for one region. It appears only when it is asked for explicitly; components no longer use it by default (`navigator`, `tile` and `board` used to be on ink by default, and now follow the page by default).
|
|
338
|
+
- **Buttons and other small blocks** are still filled with the text colour (white on black in the light scheme, black on white in the dark scheme).
|
|
339
|
+
|
|
340
|
+
### The colour algorithm
|
|
341
|
+
|
|
342
|
+
The colours of the palette are not picked by eye: they are computed from hues (`src/standard/colour/colour.ts`, exposed as the `Palette` module), which guarantees that any hue is vivid and readable.
|
|
343
|
+
The computation is done in OKLCH. Readability is measured by WCAG contrast ratio, and the threshold is the 4.5:1 required for body text.
|
|
344
|
+
|
|
345
|
+
1. **The block of colour**: for every lightness, take the highest chroma a screen can show at that hue (capped at 0.22; anything higher is harsh on the eyes). From these, find the most vivid one on which paper-coloured text is readable and the most vivid one on which ink-coloured text is readable. The more vivid of the two is the block of colour, and the text on it is the kind that goes with it; when the two are equally vivid, paper-coloured text is used. So yellow (which is only yellow when it is bright) is bright and has ink-coloured text on it; blue is deep and has paper-coloured text on it.
|
|
346
|
+
2. **A colour used as text**: often the colour of the block cannot be used directly for text (yellow text on paper is not readable). So every hue has two more colours: the most vivid one that is readable on paper, and the most vivid one that is readable on ink. Links, the accent and the focus ring pick between them by the ground they are on (`--s-read`); blocks of colour still use `--s-mark` / `--s-on-mark`.
|
|
347
|
+
3. **Muted text**: the text colour is pushed towards the ground until it is only just readable. A colour that is already at the threshold (such as paper-coloured text on a red block) is not weakened any further.
|
|
348
|
+
|
|
349
|
+
The tests check this for every degree of hue, 0–359:
|
|
350
|
+
|
|
351
|
+
| Guarantee | Measure |
|
|
352
|
+
| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
353
|
+
| The block of colour is vivid | Chroma is at least 0.14, and is the highest possible at that lightness |
|
|
354
|
+
| The text on a block of colour is readable | Contrast ≥ 4.5 |
|
|
355
|
+
| A colour used as text is readable on paper and on ink | Contrast ≥ 4.5, and this also holds on surfaces slightly tinted from the ground, such as cards |
|
|
356
|
+
| Muted text is readable on every ground | Contrast ≥ 4.5 |
|
|
357
|
+
|
|
358
|
+
Every value of the eight colours in the stylesheet must equal the output of the algorithm, and the tests compare them line by line. To use a different hue, change `hues` in `colour.ts`, then copy the computed values into `tokens.module.css`.
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import { Palette } from "@nmnmcc/standard"
|
|
362
|
+
|
|
363
|
+
const orange = Palette.swatch(55)
|
|
364
|
+
Palette.hex(orange.fill) // "#fe8400", the block of colour
|
|
365
|
+
Palette.contrast(orange.on, orange.fill) // ≥ 4.5
|
|
366
|
+
Palette.hex(orange.onPaper) // "#954b00", orange used as text on paper
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Icons
|
|
370
|
+
|
|
371
|
+
The icons are from [Material Symbols](https://fonts.google.com/icons): Sharp, weight 700, filled (`@material-symbols/svg-700`, Apache-2.0).
|
|
372
|
+
The reasons for choosing it: the ends are cut square, not round, which agrees with the rule “no rounded corners”; at weight 700 it does not look thin next to bold sans-serif type; and a filled, flat shape is exactly the pictogram of a signage system.
|
|
373
|
+
Of the others compared, Carbon is too thin; Lucide, Tabler and Phosphor are lines with round ends; and the shapes of Remix and Bootstrap are not consistent enough.
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
s.text("body", s.icon("schedule"), " Leaves in 4 minutes")
|
|
377
|
+
s.button({ icon: "download", onClick }, "Download the report")
|
|
378
|
+
s.icon("lock", "Locked") // when it stands alone, give it a label: that is what a screen reader reads
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
- **An icon is one glyph in a line**: as high as the text, in the colour of the text, one flat shape. It has no colour, size or weight of its own to choose.
|
|
382
|
+
- **Before a word it is half an em from it**: one unit at body size, and less in smaller type such as a `tag`, so it is never further from its word than the two are from the edge of the button, row or tag they are in. Write one space between them (`s.icon("schedule"), " Leaves…"`); the stylesheet adds the rest. An icon with a label stands alone and has no such margin.
|
|
383
|
+
- **It goes next to a word and does not replace the word.** In one list, either every item has an icon or none has.
|
|
384
|
+
- **The icon set is a token**: `Standard.Icon` is a selection of 106, under Material's own names (`open-in-new`). A name that is not among them does not compile. To add one, add one line to `icon.ts` and one to `icon.module.css`, in `src/standard/icon/`.
|
|
385
|
+
- **How it is built**: in the stylesheet every icon is a `mask`, and the SVG is inlined into `dist/standard.css` at build time. Users of the library do not need to install an icon library.
|
|
386
|
+
- **Where they are used now**: before the title of a `notice` (`info` / `warning`; `icon` replaces it); on the close buttons of `sheet`, `dialog` and `notice`; at the end of external links; on the collapse button of the navigator.
|
|
387
|
+
- **`icon` as an option**: on `button`, `tile`, `tag`, the items of `menu`, the items of `tabs` / `choice` / `options`, and the pages of `navigator` (before the name). The groups of `navigator` must have an icon.
|
|
388
|
+
- Directions are not shown with icons: that is still `arrow`, one shape turned in eight directions.
|
|
389
|
+
|
|
390
|
+
## `Ui`: interactive components
|
|
391
|
+
|
|
392
|
+
Interactive components built on top of the `Standard` module.
|
|
393
|
+
|
|
394
|
+
Two starting points:
|
|
395
|
+
|
|
396
|
+
- **Everything is designed around interactive components, not around screen space.** Every builder is a component that “a person does one thing to”: press, choose, switch on and off, follow, close.
|
|
397
|
+
- **The app is one canvas with no edges, and the screen is only a window onto it.** Nothing is fixed to the window. A thing that opens beside the page (`sheet`) is the neighbouring piece of ground on the canvas, and the window moves over to look at it.
|
|
398
|
+
|
|
399
|
+
Like Metro, it learns from the signage of public transport. But what it takes is the **method**, not the **look**: one sign says only one thing and can be read at a glance;
|
|
400
|
+
direction is shown by position and arrows; colour tells things of the same kind apart and never carries the meaning alone; at any time you know where you are and what comes next.
|
|
401
|
+
It does **not** copy lines, stations and maps: an app is not a network of lines.
|
|
402
|
+
|
|
403
|
+
### Usage
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
import "@nmnmcc/standard/standard.css"
|
|
407
|
+
import { Ui } from "@nmnmcc/standard"
|
|
408
|
+
import { Schema } from "effect"
|
|
409
|
+
import { Component } from "effect/ui"
|
|
410
|
+
|
|
411
|
+
const Logic = Component.define({
|
|
412
|
+
name: "StepFree",
|
|
413
|
+
model: Schema.Boolean,
|
|
414
|
+
message: Schema.Literal("Switched")
|
|
415
|
+
}).logic({ init: () => false, update: ($) => !$.model })
|
|
416
|
+
|
|
417
|
+
export const StepFree = Ui.component(Logic, (s, on) =>
|
|
418
|
+
s.page({}, s.section({ as: "main" }, s.toggle({ label: "Step-free routes only", on, onChange: () => "Switched" })))
|
|
419
|
+
)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
`s` is all the builders of `Standard` plus the ones here.
|
|
423
|
+
|
|
424
|
+
### Components
|
|
425
|
+
|
|
426
|
+
| What you do | Builders |
|
|
427
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
428
|
+
| Press | `tile`, and `button` from `Standard` |
|
|
429
|
+
| Choose one of several | `tabs` (switch view), `choice` (segmented), `options` (a list), and `select` from `Standard` |
|
|
430
|
+
| Toggle and check | `toggle`, `check` |
|
|
431
|
+
| Input | `slider`, `stepper` (how many of a thing); from `Standard`, `field` (with `hint`, `suggestions`, `date` and `time`) and `textarea` |
|
|
432
|
+
| Expand and pop up | `disclosure` (those with the same name form an accordion), `menu`, `popover` |
|
|
433
|
+
| Take over the page | `sheet` (at the side / along the bottom), `dialog` (a question that needs an answer) |
|
|
434
|
+
| Inform | `notice`, `toasts`, `progress`, `skeleton` |
|
|
435
|
+
| Wayfinding | `trail` (the way you came), `navigator` (the navigator: a sidebar, top bar or bottom bar), `pager` (the way on), `pagination`, `route` (steps and progress) |
|
|
436
|
+
| Grouped content | `card`, `carousel`, `board`, `item` (a row of a list, and what can be done to it) |
|
|
437
|
+
| Signs | `bullet`, `arrow`, `flap` (a split-flap readout), `tag`, `avatar`, `key` |
|
|
438
|
+
|
|
439
|
+
For the demo of every component, its options and its behaviour under the three kinds of input, see the docs site. For things that are not provided (tooltips, custom-drawn dropdowns, date pickers,
|
|
440
|
+
context menus and so on) and what to use instead, see the Not provided page of the docs site.
|
|
441
|
+
|
|
442
|
+
### The navigator, and a block of colour for “selected”
|
|
443
|
+
|
|
444
|
+
The navigator (`navigator`) is the old sidebar made general: every place in the app that you can go to is in it, on two levels. The first level is the groups (an icon and a name); the second level is the pages of the selected group. It can be placed in three positions:
|
|
445
|
+
|
|
446
|
+
| `place` | First level | Second level |
|
|
447
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
448
|
+
| `"side"` (the default) | A bar against the starting edge of the page. When closed it is only as wide as an icon; when open, the icon and the name are on the same line | A pane beside it, with the page names listed vertically |
|
|
449
|
+
| `"top"` | A row along the top, with icons and names | A list that drops straight down from under the pressed group and hangs over the page like a menu |
|
|
450
|
+
| `"bottom"` | A row of tabs along the bottom (the icon above the name), within reach of the thumb | A pane that rises from behind the tabs, with the page names listed vertically |
|
|
451
|
+
|
|
452
|
+
In a narrow window (a mobile device) it is always the bottom bar, whatever `place` says.
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
s.page({ accent },
|
|
456
|
+
s.navigator(
|
|
457
|
+
{
|
|
458
|
+
label: "Contents",
|
|
459
|
+
brand: { name: "Standard", colour: "red" },
|
|
460
|
+
place: "side", // or "top", "bottom"
|
|
461
|
+
mode: "docked", // or "sheet"
|
|
462
|
+
shown: model.group, onShow: (index, as) => Message.ShowedGroup({ index, as }),
|
|
463
|
+
open: model.pane !== null, // closed by default
|
|
464
|
+
toggle: { label: "Contents", onToggle: (open, as) => Message.ToggledPane({ open, as }) },
|
|
465
|
+
groups // { label, icon, colour?, links: { label, href, icon?, current? }[] }[]
|
|
466
|
+
},
|
|
467
|
+
s.section({ as: "main" }, …),
|
|
468
|
+
s.toasts({ label: "Notifications" })
|
|
469
|
+
)
|
|
470
|
+
)
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
- **The brand mark**: when `brand: { name, icon?, src?, colour? }` is given, the mark and the name of the app come first in the first level. They replace the hamburger button (the `menu` icon), and the brand itself is the button that opens and closes the navigator. The mark can be an image or an icon; when neither is given it is a block of colour (in `colour` if that is given, otherwise in the accent). A divider separates it from the groups after it. When the sidebar is closed, only the mark is left. The bottom bar (and so every narrow window) has no brand mark and no divider.
|
|
474
|
+
- **The back button**: with `back: { label, onPress, disabled?, travel? }`, an arrow sits in the corner where the page starts, before the brand mark. Give it as `travel` what `Standard.travel(Routes, here, before)` or `Canvas.travel(here, before)` returns for this page and the one that back goes to, and the arrow points the way the window will move: up, down, back along the line, or diagonally. In a change of page that moves the window, the arrow leaves with the old page, clipped by its button, and the new page's arrow comes in from the opposite edge already turned (the button has the view-transition name `s-ui-navigator-back`). When the page changes without the window moving, the arrow turns where it is, the short way round. Without `travel` it points back along the line.
|
|
475
|
+
- **Closing and opening**: normally only the first level shows. Pressing the hamburger button (sidebar, top bar) or any group opens it; pressing the selected group closes it, and this is how the bottom bar is closed. Pressing a group only changes what the second level shows. It does not navigate to a page, and it is the Model that opens the pane in the same `onShow`.
|
|
476
|
+
- **Docked (`docked`)**: when open it takes up space in the page, and its edge moves as it opens and closes. On a page change it stays open, and the page moves as a whole screen.
|
|
477
|
+
- **Sheet (`sheet`)**: when open it takes up no space. The window moves over to it, and the sheet slides in by as much as the page slides away: the sidebar goes sideways, the bottom bar goes up. The bottom bar is always a sheet.
|
|
478
|
+
- **The top bar** has no docked and sheet modes: the list is pulled down out of the bar and hangs over the page. It takes up no space and does not move the page; for the Model it counts as a `"sheet"`. After a page is chosen it closes, and the window moving back to the page is the animation of this page change.
|
|
479
|
+
- **`as`**: the last argument of `onShow` and of `onToggle` tells the Model whether, in the window where the press happened, the navigator is docked or a sheet (in a narrow window it is always `"sheet"`). From this the Model decides whether to close it on a page change.
|
|
480
|
+
- **A page change and a close do not happen at the same time**: two animations on top of one another would pull against each other. So when docked only the page moves, and when a sheet only the navigator is pulled back.
|
|
481
|
+
- **Colour**: the selected group and all of its second level are one block of the group's colour. That is the colour of the group if one is given, otherwise the accent. The text on it is the ink or the paper that goes with this colour. The current page is the other way round: its ground is the colour of the text, and its text is the group's colour. In all three positions the list runs vertically, and the block of colour sweeps from the old row to the new one, in step with the page; the names do not move.
|
|
482
|
+
- **A group must have an icon**: when the sidebar is closed, the icon is all there is of the group.
|
|
483
|
+
- **Popover direction**: `menu` and `popover` open downwards by default; they open upwards when there is not enough room below the button and there is more room above it. The arrow on the button points in the direction it will open, even before it is open, and the opening animation is pulled out from the button in that direction. The direction is decided again when the page scrolls and when the window changes.
|
|
484
|
+
- **No lines as markers**: selected, current and emphasised things are always whole blocks of colour. The selected item of `tabs`, `options` and `pagination` is a block of colour; `card` and `tile` are filled completely when a colour is given; `notice` and `sheet` are surfaces one step deeper than the ground, and `dialog` is a block of the accent; `pager` is two blocks side by side; links are in the accent and bold, with no underline.
|
|
485
|
+
|
|
486
|
+
- **Where you are**: the name of the page is the largest text on the page; in the `header`, the current page and the tab it is in are marked.
|
|
487
|
+
- **Where to go**: the `pager` at the foot of the page gives the names of the previous page and the next page. All the others are in the `header`, two taps away at most: the tab, then the page.
|
|
488
|
+
- **Where you came from**: you see the page you are leaving slide away, and on going back the window moves in the opposite direction. When there really are levels, there is `trail`.
|
|
489
|
+
|
|
490
|
+
### Motion
|
|
491
|
+
|
|
492
|
+
**Nothing fades.** State changes instantly; a thing whose position changes moves over as a whole block, so that the eye can follow it.
|
|
493
|
+
|
|
494
|
+
- **A view change is the window moving on the canvas**: every route has a place, and `Standard.travel(Routes, from, to)` computes the direction from the route table alone, or `Standard.canvas(Routes, sections).travel(from, to)` from a canvas drawn by hand (it may be diagonal). What moves is the screen seen in the window (wherever the page is scrolled to); the old one and the new one slide past end to end, over a distance of one window; `navigator` and `toasts` stay in place.
|
|
495
|
+
- **A sheet is not an overlay**: `sheet` is the neighbouring place on the canvas. When it opens the window moves over to it, and the sheet slides in by as much as the page slides away. Nothing is dimmed and nothing is covered.
|
|
496
|
+
- **The large buttons at the bottom of a dialog**: when `dialog` is given `actions` (a list; `tile` takes the same one), the answers are large buttons side by side at the bottom, flush against the left, right and bottom edges of the dialog, with no gap between them (a little like Carbon). The primary button comes last, and is a block of the dialog's text colour with text in the colour of the dialog's ground. The others come before it, and are one step darker or lighter than the ground of the dialog. When there is only one button, it fills the bottom from edge to edge.
|
|
497
|
+
- **A dialog pushes what is behind it further back**: when `dialog` is open, a thin backdrop in the colour of the page's ground is laid over the page. In the light scheme this makes what is behind lighter (whiter), and in the dark scheme darker. The backdrop and the dialog appear and disappear together, and they do not fade.
|
|
498
|
+
- **State changes instantly**: in `tabs` and `options`, the selected item becomes a block of colour at once, with no colour transition.
|
|
499
|
+
- **Readouts flip**: when the value of `flap` changes, it rolls through all the characters in between.
|
|
500
|
+
- `menu` / `popover` are “pulled” out of the button (what moves is the edge); `dialog` is lowered from above the window; `toasts` rise from below the window.
|
|
501
|
+
- Duration tokens: `--s-quick` (parts of a control), `--s-move` (things on the page), `--s-travel` (the window itself); with the system's “reduce motion” setting, all of them are 0.
|
|
502
|
+
|
|
503
|
+
### One interaction model
|
|
504
|
+
|
|
505
|
+
All the components share one `.control` in the stylesheet, so the mouse, the finger and the keyboard get exactly the same states:
|
|
506
|
+
|
|
507
|
+
- **There is no hover state.** When the pointer rests on a control, nothing changes: a finger cannot hover, so a hover state is a state that some people will never see. There is not a single hover rule in the stylesheet.
|
|
508
|
+
- **A press** gives the same `:active` feedback for a finger, a mouse button and the space key, and it shows at once.
|
|
509
|
+
- **The focus** ring shows only with keyboard focus (`:focus-visible`). It is drawn inside the control, so a scroll container does not clip it.
|
|
510
|
+
- **Disabled** looks the same everywhere: grey, and it does not respond.
|
|
511
|
+
- A target is never smaller than `--s-target` (44px for a fine pointer, 48px for a coarse one); `touch-action: manipulation` removes the tap delay.
|
|
512
|
+
- As far as possible, keyboard behaviour is left to native elements: the arrow keys of a radio group, space / enter on a button, and Escape and the focus trap of a dialog.
|
|
513
|
+
|
|
514
|
+
### Still Swiss Style
|
|
515
|
+
|
|
516
|
+
The stylesheet holds the same line as `Standard`: no gradients, no shadows, no centred text. The only curves are the true circles of the line roundels and of the station markers.
|
|
517
|
+
The class names come from typed CSS Modules (and are built as `s-ui-*`); the builders take no `class` / `style`.
|
package/dist/Extend.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The entry point for a layer built on top of the language, as `Ui` is.
|
|
3
|
+
*
|
|
4
|
+
* It makes nodes out of what `h` builds and opens them again, so whoever
|
|
5
|
+
* imports it is responsible for the result being Swiss. A page that
|
|
6
|
+
* doesn't import this entry point can't leave the system.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.3.0
|
|
9
|
+
*/
|
|
10
|
+
export { type Child, component, content, contents, type Kind, node, type Node } from "./Node.ts";
|
|
11
|
+
export { builders } from "./Standard.ts";
|
|
12
|
+
/** The classes of a button, for an element that looks like one and does something else, such as opening a menu. */
|
|
13
|
+
export { look as button } from "./standard/button/button.ts";
|
|
14
|
+
export { accent, gap, pad, tone } from "./standard/tokens/classes.ts";
|
|
15
|
+
//# sourceMappingURL=Extend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extend.d.ts","sourceRoot":"","sources":["../src/Extend.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAA;AAChG,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,mHAAmH;AACnH,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA"}
|
package/dist/Extend.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { v as accent, n as builders, C as button, D as component, O as content, k as contents, y as gap, A as node, b as pad, x as tone } from "./Standard-BPpzr5SM.js";
|