@aitrien/motifspec 1.26.0 → 1.27.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/dist/tokens.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Generated by npm run build. Do not edit.
2
- export const version = "1.26.0";
2
+ export const version = "1.27.0";
3
3
  export const changelog = "https://github.com/Aitrien/motifspec/blob/main/CHANGELOG.md";
4
4
  export const showcase = "https://motifspec.com";
5
5
  export const tokens = [
@@ -584,6 +584,17 @@ export const tokens = [
584
584
  "valueDark": "#01441f",
585
585
  "description": "Text selection and <mark>. Never for large areas or decoration."
586
586
  },
587
+ {
588
+ "name": "color.surface.selected",
589
+ "css": "--cx-color-surface-selected",
590
+ "tier": "semantic",
591
+ "type": "color",
592
+ "references": "primitive.color.sap.100",
593
+ "referencesDark": "primitive.color.sap.800",
594
+ "value": "#d8f9df",
595
+ "valueDark": "#01441f",
596
+ "description": "The chosen item among options the reader picks from: a calendar's date, month or year (date-picker.md). With color.text.primary. Never for large areas or decoration."
597
+ },
587
598
  {
588
599
  "name": "color.text.primary",
589
600
  "css": "--cx-color-text-primary",
@@ -615,6 +626,10 @@ export const tokens = [
615
626
  "token": "color.surface.highlight",
616
627
  "min": 7
617
628
  },
629
+ {
630
+ "token": "color.surface.selected",
631
+ "min": 7
632
+ },
618
633
  {
619
634
  "token": "color.status.success.surface",
620
635
  "min": 7
@@ -750,6 +765,27 @@ export const tokens = [
750
765
  }
751
766
  ]
752
767
  },
768
+ {
769
+ "name": "color.text.on-danger",
770
+ "css": "--cx-color-text-on-danger",
771
+ "tier": "semantic",
772
+ "type": "color",
773
+ "references": "primitive.color.ash.0",
774
+ "referencesDark": "primitive.color.ash.1000",
775
+ "value": "#fbfefd",
776
+ "valueDark": "#0e100f",
777
+ "description": "Text and icons on color.status.danger.fill and its hover, such as a danger button’s label. Only there.",
778
+ "pairsWith": [
779
+ {
780
+ "token": "color.status.danger.fill",
781
+ "min": 4.5
782
+ },
783
+ {
784
+ "token": "color.status.danger.fill-hover",
785
+ "min": 4.5
786
+ }
787
+ ]
788
+ },
753
789
  {
754
790
  "name": "color.link.rest",
755
791
  "css": "--cx-color-link-rest",
@@ -1137,6 +1173,52 @@ export const tokens = [
1137
1173
  }
1138
1174
  ]
1139
1175
  },
1176
+ {
1177
+ "name": "color.status.danger.fill",
1178
+ "css": "--cx-color-status-danger-fill",
1179
+ "tier": "semantic",
1180
+ "type": "color",
1181
+ "references": "primitive.color.madder.700",
1182
+ "referencesDark": "primitive.color.madder.300",
1183
+ "value": "#942f29",
1184
+ "valueDark": "#feb5ac",
1185
+ "description": "Fill of a button that deletes or stops something, in a dialog asking to confirm it (cx-button--danger, button-and-link.md). Its label says what it does; never the only sign.",
1186
+ "pairsWith": [
1187
+ {
1188
+ "token": "color.surface.base",
1189
+ "min": 3
1190
+ },
1191
+ {
1192
+ "token": "color.surface.raised",
1193
+ "min": 3
1194
+ },
1195
+ {
1196
+ "token": "color.surface.sunken",
1197
+ "min": 3
1198
+ }
1199
+ ]
1200
+ },
1201
+ {
1202
+ "name": "color.status.danger.fill-hover",
1203
+ "css": "--cx-color-status-danger-fill-hover",
1204
+ "tier": "semantic",
1205
+ "type": "color",
1206
+ "references": "primitive.color.madder.800",
1207
+ "referencesDark": "primitive.color.madder.200",
1208
+ "value": "#651916",
1209
+ "valueDark": "#ffd6d1",
1210
+ "description": "Fill of a danger button while hovered or pressed.",
1211
+ "pairsWith": [
1212
+ {
1213
+ "token": "color.surface.raised",
1214
+ "min": 3
1215
+ },
1216
+ {
1217
+ "token": "color.surface.sunken",
1218
+ "min": 3
1219
+ }
1220
+ ]
1221
+ },
1140
1222
  {
1141
1223
  "name": "color.status.info.text",
1142
1224
  "css": "--cx-color-status-info-text",
package/dist/tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.0",
2
+ "version": "1.27.0",
3
3
  "changelog": "https://github.com/Aitrien/motifspec/blob/main/CHANGELOG.md",
4
4
  "showcase": "https://motifspec.com",
5
5
  "tokens": [
@@ -584,6 +584,17 @@
584
584
  "valueDark": "#01441f",
585
585
  "description": "Text selection and <mark>. Never for large areas or decoration."
586
586
  },
587
+ {
588
+ "name": "color.surface.selected",
589
+ "css": "--cx-color-surface-selected",
590
+ "tier": "semantic",
591
+ "type": "color",
592
+ "references": "primitive.color.sap.100",
593
+ "referencesDark": "primitive.color.sap.800",
594
+ "value": "#d8f9df",
595
+ "valueDark": "#01441f",
596
+ "description": "The chosen item among options the reader picks from: a calendar's date, month or year (date-picker.md). With color.text.primary. Never for large areas or decoration."
597
+ },
587
598
  {
588
599
  "name": "color.text.primary",
589
600
  "css": "--cx-color-text-primary",
@@ -615,6 +626,10 @@
615
626
  "token": "color.surface.highlight",
616
627
  "min": 7
617
628
  },
629
+ {
630
+ "token": "color.surface.selected",
631
+ "min": 7
632
+ },
618
633
  {
619
634
  "token": "color.status.success.surface",
620
635
  "min": 7
@@ -750,6 +765,27 @@
750
765
  }
751
766
  ]
752
767
  },
768
+ {
769
+ "name": "color.text.on-danger",
770
+ "css": "--cx-color-text-on-danger",
771
+ "tier": "semantic",
772
+ "type": "color",
773
+ "references": "primitive.color.ash.0",
774
+ "referencesDark": "primitive.color.ash.1000",
775
+ "value": "#fbfefd",
776
+ "valueDark": "#0e100f",
777
+ "description": "Text and icons on color.status.danger.fill and its hover, such as a danger button’s label. Only there.",
778
+ "pairsWith": [
779
+ {
780
+ "token": "color.status.danger.fill",
781
+ "min": 4.5
782
+ },
783
+ {
784
+ "token": "color.status.danger.fill-hover",
785
+ "min": 4.5
786
+ }
787
+ ]
788
+ },
753
789
  {
754
790
  "name": "color.link.rest",
755
791
  "css": "--cx-color-link-rest",
@@ -1137,6 +1173,52 @@
1137
1173
  }
1138
1174
  ]
1139
1175
  },
1176
+ {
1177
+ "name": "color.status.danger.fill",
1178
+ "css": "--cx-color-status-danger-fill",
1179
+ "tier": "semantic",
1180
+ "type": "color",
1181
+ "references": "primitive.color.madder.700",
1182
+ "referencesDark": "primitive.color.madder.300",
1183
+ "value": "#942f29",
1184
+ "valueDark": "#feb5ac",
1185
+ "description": "Fill of a button that deletes or stops something, in a dialog asking to confirm it (cx-button--danger, button-and-link.md). Its label says what it does; never the only sign.",
1186
+ "pairsWith": [
1187
+ {
1188
+ "token": "color.surface.base",
1189
+ "min": 3
1190
+ },
1191
+ {
1192
+ "token": "color.surface.raised",
1193
+ "min": 3
1194
+ },
1195
+ {
1196
+ "token": "color.surface.sunken",
1197
+ "min": 3
1198
+ }
1199
+ ]
1200
+ },
1201
+ {
1202
+ "name": "color.status.danger.fill-hover",
1203
+ "css": "--cx-color-status-danger-fill-hover",
1204
+ "tier": "semantic",
1205
+ "type": "color",
1206
+ "references": "primitive.color.madder.800",
1207
+ "referencesDark": "primitive.color.madder.200",
1208
+ "value": "#651916",
1209
+ "valueDark": "#ffd6d1",
1210
+ "description": "Fill of a danger button while hovered or pressed.",
1211
+ "pairsWith": [
1212
+ {
1213
+ "token": "color.surface.raised",
1214
+ "min": 3
1215
+ },
1216
+ {
1217
+ "token": "color.surface.sunken",
1218
+ "min": 3
1219
+ }
1220
+ ]
1221
+ },
1140
1222
  {
1141
1223
  "name": "color.status.info.text",
1142
1224
  "css": "--cx-color-status-info-text",
@@ -1,5 +1,6 @@
1
1
  [
2
2
  {"key": "actions", "title": "Actions"},
3
+ {"key": "forms", "title": "Forms"},
3
4
  {"key": "navigation", "title": "Navigation"},
4
5
  {"key": "content", "title": "Content"},
5
6
  {"key": "messages", "title": "Messages"},
@@ -14,10 +14,13 @@ tokens:
14
14
  - color.focus.ring
15
15
  - color.link.hover
16
16
  - color.link.rest
17
+ - color.status.danger.fill
18
+ - color.status.danger.fill-hover
17
19
  - color.surface.hover
18
20
  - color.surface.raised
19
21
  - color.text.muted
20
22
  - color.text.on-accent
23
+ - color.text.on-danger
21
24
  - color.text.primary
22
25
  - font.family.body
23
26
  - font.family.mono
@@ -48,6 +51,7 @@ Buttons start actions or journeys; standalone links and back links move between
48
51
 
49
52
  - `cx-button--primary`: the one main action in a view ("View work").
50
53
  - `cx-button`: a secondary action beside it.
54
+ - `cx-button--danger`: the action that deletes or stops something, in a dialog that asks the reader to confirm it ("Remove service"; `dialog.md`).
51
55
  - `cx-link`: a standalone forward link at the end of a section ("All projects" plus a forward arrow).
52
56
  - `cx-back`: the return link at the top of a post or case study (back arrow plus "All writing").
53
57
 
@@ -55,6 +59,7 @@ Buttons start actions or journeys; standalone links and back links move between
55
59
 
56
60
  - For inline links in text; `prose` styles those.
57
61
  - Two primary buttons in one view. Make the second one secondary.
62
+ - `cx-button--danger` on a page or in a table row. A destructive action there opens a dialog, and the danger button is in the dialog.
58
63
  - For navigation between sibling posts; use `pagination`.
59
64
 
60
65
  ## Markup
@@ -69,6 +74,15 @@ Buttons start actions or journeys; standalone links and back links move between
69
74
  <a class="cx-back" href="/writing/"><svg class="cx-icon cx-icon--sm cx-button__arrow" aria-hidden="true" focusable="false"><use href="#cx-icon-arrow-back"></use></svg>All writing</a>
70
75
  ```
71
76
 
77
+ In a dialog that confirms a destructive action, the danger button takes the primary's place, after Cancel:
78
+
79
+ ```html {preview=true}
80
+ <div class="cx-actions">
81
+ <button class="cx-button" type="button">Cancel</button>
82
+ <button class="cx-button cx-button--danger" type="button">Remove service</button>
83
+ </div>
84
+ ```
85
+
72
86
  Add `cx-button--sm` for a compact button in a table row or a toolbar, where full-size buttons would make every row tall:
73
87
 
74
88
  ```html {preview=true}
@@ -94,7 +108,7 @@ Add `cx-button--sm` for a compact button in a table row or a toolbar, where full
94
108
 
95
109
  - Buttons are 40px tall (`size.target.control`); links at least 24px.
96
110
  - Focus shows `color.focus.ring` 2px off the element, so it never sits on the green fill.
97
- - Pairs: `color.text.on-accent` on `color.accent.fill.rest` and `.hover` (4.5:1); `color.accent.fill.rest` against the page (3:1); secondary border `color.border.strong` (3:1); `color.link.rest` (7:1).
111
+ - Pairs: `color.text.on-accent` on `color.accent.fill.rest` and `.hover` (4.5:1); `color.text.on-danger` on `color.status.danger.fill` and `.fill-hover` (4.5:1); `color.accent.fill.rest` against the page (3:1); secondary border `color.border.strong` (3:1); `color.link.rest` (7:1).
98
112
 
99
113
  ## Specimens
100
114
 
@@ -106,6 +120,10 @@ For the Components page: each variant at a glance. Ids start "sp-"; `wide=true`
106
120
  <button class="cx-button" type="button" disabled>Not yet published</button>
107
121
  ```
108
122
 
123
+ ```html {specimen="Danger"}
124
+ <button class="cx-button cx-button--danger" type="button">Remove service</button>
125
+ ```
126
+
109
127
  ```html {specimen="Small"}
110
128
  <a class="cx-button cx-button--sm" href="/reference/changelog/">Changelog</a>
111
129
  ```
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: choice
3
+ status: stable
4
+ layouts: [shared]
5
+ group: forms
6
+ tokens:
7
+ - border.focus.offset
8
+ - border.focus.width
9
+ - border.width.emphasis
10
+ - border.width.hairline
11
+ - color.accent.fill.rest
12
+ - color.border.strong
13
+ - color.focus.ring
14
+ - color.surface.sunken
15
+ - color.text.muted
16
+ - color.text.on-accent
17
+ - color.text.secondary
18
+ - font.line-height.ui
19
+ - font.size.small
20
+ - motion.duration.fast
21
+ - motion.easing.standard
22
+ - radius.pill
23
+ - size.icon.md
24
+ - size.target.min
25
+ - size.target.touch
26
+ - space.inline.sm
27
+ - space.stack.sm
28
+ - space.stack.xs
29
+ ---
30
+
31
+ # Choice
32
+
33
+ A checkbox, radio button or switch, with its label beside it: native inputs in the accent colour.
34
+
35
+ ## When to use
36
+
37
+ - A checkbox for one thing that's on or off when the form is sent ("Start when the node starts"), or for each of several that can all be on.
38
+ - Radio buttons for one choice among two to five, all shown at once.
39
+ - A switch for a setting that takes effect as soon as it's changed ("Send alerts").
40
+
41
+ ## When not to use
42
+
43
+ - For more than five options, or options that don't need to be seen together; use a select (`field.md`).
44
+ - For switching between views of the same content; that's tabs (`tabs.md`).
45
+ - A switch in a form that waits for Save. Use a checkbox there.
46
+
47
+ ## Markup
48
+
49
+ ```html {preview=true}
50
+ <fieldset class="cx-fieldset">
51
+ <legend>When it fails</legend>
52
+ <div class="cx-choices">
53
+ <label class="cx-choice"><input type="radio" name="on-failure" value="restart" checked><span class="cx-choice__text">Restart it<span class="cx-field__hint">Up to 3 times, then stop and raise an alert.</span></span></label>
54
+ <label class="cx-choice"><input type="radio" name="on-failure" value="stop"><span class="cx-choice__text">Leave it stopped</span></label>
55
+ </div>
56
+ <label class="cx-choice"><input type="checkbox" name="start-on-boot" checked><span class="cx-choice__text">Start when the node starts</span></label>
57
+ <label class="cx-choice"><input type="checkbox" role="switch" name="alerts" checked><span class="cx-choice__text">Send alerts</span></label>
58
+ </fieldset>
59
+ ```
60
+
61
+ A switch is a checkbox with `role="switch"`. Its label names the setting, and the switch shows whether it's on.
62
+
63
+ ## Do
64
+
65
+ - Put radio buttons in a `fieldset` whose `legend` asks the question, and give them one `name`.
66
+ - Write each label as what happens when it's chosen, in a few words. A hint can go under it, inside `cx-choice__text`.
67
+ - Pick a sensible default for radio buttons, so one is always chosen.
68
+
69
+ ## Don't
70
+
71
+ - Don't use one checkbox with a negative label ("Don't send alerts").
72
+ - Don't make a switch wait for a Save button.
73
+ - Don't hide a disabled choice's reason; say it in a hint.
74
+
75
+ ## Accessibility
76
+
77
+ - Each input is inside its label, so the whole line can be clicked or tapped, and it's at least `size.target.min` tall.
78
+ - Radio buttons in a fieldset are announced as a group, with the legend; the arrow keys move between them.
79
+ - A switch is announced as a switch, on or off.
80
+ - Focus shows `color.focus.ring` around the input.
81
+ - Pairs: `color.accent.fill.rest` against `color.surface.base` (3:1) for a ticked box or an on switch; `color.text.on-accent` for the switch's knob; `color.border.strong` for an off switch.
82
+
83
+ ## Specimens
84
+
85
+ ```html {specimen="Checkboxes"}
86
+ <div class="cx-choices">
87
+ <label class="cx-choice"><input type="checkbox" checked><span class="cx-choice__text">Start on boot</span></label>
88
+ <label class="cx-choice"><input type="checkbox"><span class="cx-choice__text">Pull a new image nightly</span></label>
89
+ </div>
90
+ ```
91
+
92
+ ```html {specimen="Radio buttons"}
93
+ <div class="cx-choices">
94
+ <label class="cx-choice"><input type="radio" name="sp-choice-r" checked><span class="cx-choice__text">Restart it</span></label>
95
+ <label class="cx-choice"><input type="radio" name="sp-choice-r"><span class="cx-choice__text">Leave it stopped</span></label>
96
+ </div>
97
+ ```
98
+
99
+ ```html {specimen="Switch, on and off"}
100
+ <div class="cx-choices">
101
+ <label class="cx-choice"><input type="checkbox" role="switch" checked><span class="cx-choice__text">Send alerts</span></label>
102
+ <label class="cx-choice"><input type="checkbox" role="switch"><span class="cx-choice__text">Quiet hours</span></label>
103
+ </div>
104
+ ```
@@ -0,0 +1,108 @@
1
+ ---
2
+ name: date-picker
3
+ status: stable
4
+ layouts: [shared]
5
+ group: forms
6
+ tokens:
7
+ - border.focus.width
8
+ - border.width.hairline
9
+ - color.accent.border
10
+ - color.border.strong
11
+ - color.border.subtle
12
+ - color.focus.ring
13
+ - color.surface.hover
14
+ - color.surface.raised
15
+ - color.surface.selected
16
+ - color.text.accent
17
+ - color.text.muted
18
+ - color.text.primary
19
+ - color.text.secondary
20
+ - font.family.mono
21
+ - font.size.label
22
+ - font.size.small
23
+ - font.tracking.label
24
+ - font.weight.strong
25
+ - font.weight.ui
26
+ - motion.duration.fast
27
+ - motion.easing.standard
28
+ - radius.pill
29
+ - size.target.control
30
+ - size.target.touch
31
+ - space.inline.sm
32
+ - space.inline.xs
33
+ - space.inset.sm
34
+ - space.inset.xs
35
+ ---
36
+
37
+ # Date picker
38
+
39
+ A date field with a button that opens a calendar, where the month and the year can each be picked from a grid.
40
+
41
+ ## When to use
42
+
43
+ - When the date matters in relation to the days around it, such as a weekday for maintenance.
44
+ - When the reader may need to go a long way back, as for a date of birth: the year grid goes twenty years at a time.
45
+ - Where the calendar should look like the rest of the page.
46
+
47
+ ## When not to use
48
+
49
+ - When the browser's own date field is enough: `<input type="date">` in a field (`field.md`) gives the reader's own calendar, in their language and date order, and the system's date wheel on a phone. It's the better choice in most forms.
50
+ - For a range of dates, or to grey out dates that can't be chosen; this calendar doesn't do either yet.
51
+ - For a time of day.
52
+
53
+ ## Markup
54
+
55
+ ```html {preview=true}
56
+ <div class="cx-field">
57
+ <div class="cx-field__box cx-field__box--date" data-date-picker>
58
+ <input class="cx-field__control cx-field__control--mono" id="maintenance-date" placeholder="DD/MM/YYYY" inputmode="numeric" autocomplete="off" value="12/12/2026" aria-describedby="maintenance-date-hint">
59
+ <label class="cx-field__label" for="maintenance-date">Maintenance date</label>
60
+ <button class="cx-date__button" type="button" aria-label="Choose a maintenance date" aria-haspopup="dialog" hidden><svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-calendar"></use></svg></button>
61
+ </div>
62
+ <p class="cx-field__hint" id="maintenance-date-hint">Day, month and year, like 12/12/2026.</p>
63
+ </div>
64
+ ```
65
+
66
+ The browser's own date field is a field with `type="date"`:
67
+
68
+ ```html {preview=true}
69
+ <div class="cx-field">
70
+ <div class="cx-field__box">
71
+ <input class="cx-field__control cx-field__control--mono" id="backup-date" type="date" value="2026-12-12">
72
+ <label class="cx-field__label" for="backup-date">Backup date</label>
73
+ </div>
74
+ </div>
75
+ ```
76
+
77
+ ## Do
78
+
79
+ - Keep the text field: typing a date is often quicker than finding it.
80
+ - Say the format in the hint ("Day, month and year, like 12/12/2026"). The calendar reads and writes day first.
81
+ - Name the button for what it chooses ("Choose a date of birth").
82
+
83
+ ## Don't
84
+
85
+ - Don't make the field read-only so that the calendar is the only way in.
86
+ - Don't put two date pickers next to each other for a range. Use two fields with hints until a range picker exists.
87
+
88
+ ## Accessibility
89
+
90
+ - The button is `hidden` until `codex.js` shows it, so without script the field still takes a typed date.
91
+ - The calendar is a non-modal dialog named by its button. Focus moves to the chosen date (or today) when it opens, and back to the button when it closes.
92
+ - The days, months and years are each a grid of buttons with one tab stop. Each day is named in full ("Saturday 12 December 2026"), today has `aria-current="date"`, the chosen date `aria-pressed="true"`, and the shown month is read out when it changes.
93
+ - Days are `size.target.touch` square, and the calendar is a fixed size, so its arrows never move under the pointer.
94
+ - Pairs: `color.text.primary` on `color.surface.selected` (the chosen date) and on `color.surface.raised`; `color.border.strong` outlines today.
95
+
96
+ ## Behaviour
97
+
98
+ `dist/codex.js` does this; an app that renders the date picker itself does the same.
99
+
100
+ - **Opening:** the button opens one calendar for the page (a `popover`), on the field's date if it can read one, or today. Pressing it again closes it.
101
+ - **Placing:** under the field, or above it when there's more room there; left-aligned with it, kept inside the window, and in page coordinates, so it scrolls with the field.
102
+ - **Days:** the arrow keys move a day or a week, Page Up and Page Down a month, Home and End to the ends of the week (Monday to Sunday). Enter, Space or a click chooses the date, writes it as DD/MM/YYYY, fires `input` and `change` on the field, and closes the calendar.
103
+ - **Months and years:** the month and year at the top open a grid of the year's months, or of twenty years. The arrows at the sides then step a year, or twenty years. Choosing a year opens its months; choosing a month opens its days.
104
+ - **Closing:** Escape, a click outside, Close, or choosing a date. Today moves back to today.
105
+
106
+ ## Specimens
107
+
108
+ None: the calendar opens from the field, so its page shows it working.
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: dialog
3
+ status: stable
4
+ layouts: [shared]
5
+ group: messages
6
+ tokens:
7
+ - border.focus.width
8
+ - border.width.hairline
9
+ - color.border.strong
10
+ - color.border.subtle
11
+ - color.focus.ring
12
+ - color.scrim
13
+ - color.surface.hover
14
+ - color.surface.raised
15
+ - color.surface.sunken
16
+ - color.text.primary
17
+ - color.text.secondary
18
+ - color.wash.scrim
19
+ - font.line-height.heading
20
+ - font.size.heading-4
21
+ - font.weight.heading
22
+ - motion.distance.nudge
23
+ - motion.duration.base
24
+ - motion.easing.enter
25
+ - motion.easing.exit
26
+ - radius.pill
27
+ - size.column.card
28
+ - size.measure.caption
29
+ - size.measure.prose
30
+ - size.target.control
31
+ - space.gutter.page
32
+ - space.inline.sm
33
+ - space.inset.lg
34
+ - space.inset.md
35
+ - space.inset.sm
36
+ - space.stack.md
37
+ ---
38
+
39
+ # Dialog
40
+
41
+ A box over the page that asks the reader to confirm something, or to fill in a short form, before they go on.
42
+
43
+ ## When to use
44
+
45
+ - To confirm an action that deletes or stops something, with a danger button (`button-and-link.md`).
46
+ - For a short form that belongs to the page behind it, such as adding an item to a list.
47
+
48
+ ## When not to use
49
+
50
+ - For a message; use an alert (`alert.md`) or a toast (`toast.md`).
51
+ - For a long form or one with steps; give it a page.
52
+ - For something the reader didn't ask for, such as a sign-up when the page loads.
53
+
54
+ ## Markup
55
+
56
+ ```html {preview=true}
57
+ <button class="cx-button" type="button" data-dialog-open="remove-sonarr">Remove service</button>
58
+ <dialog class="cx-dialog" id="remove-sonarr" aria-labelledby="remove-sonarr-title" aria-describedby="remove-sonarr-text">
59
+ <div class="cx-dialog__head">
60
+ <h2 class="cx-dialog__title" id="remove-sonarr-title">Remove Sonarr?</h2>
61
+ <button class="cx-dialog__close" type="button" aria-label="Close" data-dialog-close><svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-close"></use></svg></button>
62
+ </div>
63
+ <div class="cx-dialog__body">
64
+ <p id="remove-sonarr-text">Sonarr stops and its container is deleted from tern. Its settings stay in <code>/srv/sonarr</code>, so you can add it again later.</p>
65
+ </div>
66
+ <div class="cx-dialog__actions">
67
+ <button class="cx-button" type="button" data-dialog-close autofocus>Cancel</button>
68
+ <button class="cx-button cx-button--danger" type="button">Remove service</button>
69
+ </div>
70
+ </dialog>
71
+ ```
72
+
73
+ For a form, add `cx-dialog--wide` and `data-dialog-keep`, and put the parts in a `form` (fields from `field.md`):
74
+
75
+ ```html {preview=true}
76
+ <button class="cx-button" type="button" data-dialog-open="add-node">Add a node</button>
77
+ <dialog class="cx-dialog cx-dialog--wide" id="add-node" aria-labelledby="add-node-title" data-dialog-keep>
78
+ <form method="dialog">
79
+ <div class="cx-dialog__head">
80
+ <h2 class="cx-dialog__title" id="add-node-title">Add a node</h2>
81
+ <button class="cx-dialog__close" type="button" aria-label="Close" data-dialog-close><svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-close"></use></svg></button>
82
+ </div>
83
+ <div class="cx-dialog__body">
84
+ <div class="cx-field">
85
+ <div class="cx-field__box"><input class="cx-field__control" id="add-node-name" placeholder="e.g. tui" required autocomplete="off" autofocus><label class="cx-field__label" for="add-node-name">Name</label></div>
86
+ </div>
87
+ <div class="cx-field">
88
+ <div class="cx-field__box"><input class="cx-field__control cx-field__control--mono" id="add-node-address" placeholder="e.g. 192.168.1.40" inputmode="decimal" autocomplete="off" aria-describedby="add-node-address-hint"><label class="cx-field__label" for="add-node-address">Address</label></div>
89
+ <p class="cx-field__hint" id="add-node-address-hint">Its IP address or host name on your network.</p>
90
+ </div>
91
+ </div>
92
+ <div class="cx-dialog__actions">
93
+ <button class="cx-button" type="button" data-dialog-close>Cancel</button>
94
+ <button class="cx-button cx-button--primary" type="submit">Add node</button>
95
+ </div>
96
+ </form>
97
+ </dialog>
98
+ ```
99
+
100
+ <!-- caption: Dialog parts -->
101
+ | Class | What it is |
102
+ |---|---|
103
+ | `cx-dialog` | A `<dialog>`, opened with `showModal()`; `--wide` for a form |
104
+ | `cx-dialog__head` | The title and the close button, over a rule |
105
+ | `cx-dialog__title` | An `h2` that names the dialog, linked with `aria-labelledby` |
106
+ | `cx-dialog__close` | The close button, top right, named "Close" |
107
+ | `cx-dialog__body` | The question or the form; it scrolls when it's taller than the window |
108
+ | `cx-dialog__actions` | The buttons, in a recessed band: Cancel first, the main action last |
109
+
110
+ ## Do
111
+
112
+ - Ask a question in the title, and say in the body what will happen ("Sonarr stops and its container is deleted").
113
+ - Name the main button for what it does ("Remove service"), never "OK" or "Yes".
114
+ - Start focus on Cancel when the action deletes or stops something (`autofocus`), and on the first field in a form.
115
+ - For something that can't be undone, ask the reader to type its name to turn the button on.
116
+
117
+ ## Don't
118
+
119
+ - Don't open a dialog from a dialog.
120
+ - Don't let a click outside close a form; that's what `data-dialog-keep` is for.
121
+ - Don't put a danger button anywhere but a dialog's actions.
122
+
123
+ ## Accessibility
124
+
125
+ - `showModal()` makes the rest of the page inert, moves focus into the dialog, closes it on Escape, and returns focus to the button that opened it.
126
+ - The title names the dialog (`aria-labelledby`), and a confirmation's text describes it (`aria-describedby`), so both are read when it opens.
127
+ - The page behind it doesn't scroll, and recedes behind `color.scrim` at `color.wash.scrim`.
128
+ - It fades and rises in by `motion.distance.nudge`, at `motion.duration.base`; under `prefers-reduced-motion` it appears at once.
129
+ - On a phone (below `size.breakpoint.md`), a confirmation docks to the bottom with full-width buttons, Cancel below, and a form fills the screen.
130
+ - Pairs: `color.text.primary` and `color.text.secondary` on `color.surface.raised`; the actions on `color.surface.sunken`.
131
+
132
+ ## Behaviour
133
+
134
+ `dist/codex.js` does this; an app that renders dialogs itself does the same, or calls `showModal()` and `close()` itself.
135
+
136
+ - **Opening:** a click on `[data-dialog-open="id"]` calls `showModal()` on the dialog with that id.
137
+ - **Closing:** `[data-dialog-close]` inside the dialog closes it, as does Escape. A click on the backdrop closes it too, unless the dialog has `data-dialog-keep`.
138
+ - **Forms:** with `<form method="dialog">`, sending the form closes the dialog once the fields are valid; the page reads the values on the dialog's `close` event.
139
+
140
+ ## Specimens
141
+
142
+ ```html {specimen="Confirm" wide=true}
143
+ <div class="cx-dialog">
144
+ <div class="cx-dialog__head"><h2 class="cx-dialog__title">Remove Sonarr?</h2><button class="cx-dialog__close" type="button" aria-label="Close"><svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-close"></use></svg></button></div>
145
+ <div class="cx-dialog__body"><p>Sonarr stops and its container is deleted from tern. Its settings stay in <code>/srv/sonarr</code>.</p></div>
146
+ <div class="cx-dialog__actions"><button class="cx-button" type="button">Cancel</button><button class="cx-button cx-button--danger" type="button">Remove service</button></div>
147
+ </div>
148
+ ```