oneslash-design-system 2.28.0 → 2.28.1

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.
@@ -47,12 +47,23 @@ export default function ApiKeysList() {
47
47
  // Gives each new key its own id, so no two rows share a key.
48
48
  var keyCount = useRef(0);
49
49
  var toastIds = useRef([]);
50
+ var createButton = useRef(null);
51
+ var cancelRevoke = useRef(null);
52
+ // Each row's Revoke button by key id, so focus can move to one when the button that had it is gone.
53
+ var revokeButtons = useRef({});
54
+ // Where focus goes after the next render, once the element it goes to is on screen.
55
+ var focusNext = useRef();
50
56
  // On unmount it stops every request and closes every toast it opened.
51
57
  useEffect(function () { return function () {
52
58
  timers.current.forEach(clearTimeout);
53
59
  toastIds.current.forEach(function (id) { return dismissToast(id); });
54
60
  toastIds.current = [];
55
61
  }; }, []);
62
+ useEffect(function () {
63
+ var move = focusNext.current;
64
+ focusNext.current = undefined;
65
+ move === null || move === void 0 ? void 0 : move();
66
+ });
56
67
  // Stands in for the request to the server.
57
68
  function later(callback, ms) {
58
69
  timers.current.push(setTimeout(callback, ms));
@@ -92,14 +103,30 @@ export default function ApiKeysList() {
92
103
  setShownKey(madeKey);
93
104
  }, 1200);
94
105
  }
106
+ // The confirm opens in the row, with focus on 'Cancel'.
107
+ function askToRevoke(key) {
108
+ setConfirming(key.id);
109
+ focusNext.current = function () { var _a; return (_a = cancelRevoke.current) === null || _a === void 0 ? void 0 : _a.focus(); };
110
+ }
111
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's Revoke button.
112
+ function keepKey(key) {
113
+ setConfirming(null);
114
+ focusNext.current = function () { var _a; return (_a = revokeButtons.current[key.id]) === null || _a === void 0 ? void 0 : _a.focus(); };
115
+ }
95
116
  function handleRevoke(key) {
117
+ var _a;
96
118
  if (revoking)
97
119
  return;
120
+ var at = keys.findIndex(function (k) { return k.id === key.id; });
121
+ var neighbor = (_a = keys[at + 1]) !== null && _a !== void 0 ? _a : keys[at - 1];
98
122
  setRevoking(key.id);
99
123
  later(function () {
100
124
  setRevoking(null);
101
125
  setConfirming(null);
102
126
  setKeys(function (list) { return list.filter(function (k) { return k.id !== key.id; }); });
127
+ // The row is gone: focus goes to the next row's Revoke, or the one before it when it was the last.
128
+ // With no key left, it goes to 'Create Key'.
129
+ focusNext.current = function () { var _a; return (_a = (neighbor ? revokeButtons.current[neighbor.id] : createButton.current)) === null || _a === void 0 ? void 0 : _a.focus(); };
103
130
  toastIds.current.push(toast({ type: 'success', message: "".concat(key.name, " key revoked.") }));
104
131
  }, 1200);
105
132
  }
@@ -110,7 +137,7 @@ export default function ApiKeysList() {
110
137
  <Stack gap="small">
111
138
  <Cluster justify="between">
112
139
  <Heading level={1} size="h5">API keys</Heading>
113
- <Button size="small" type="primary" state="enabled" label="Create Key" decoIcon="Plus" onClickButton={handleOpen}/>
140
+ <Button ref={createButton} size="small" type="primary" state="enabled" label="Create Key" decoIcon="Plus" onClickButton={handleOpen}/>
114
141
  </Cluster>
115
142
  <Paragraph tone="secondary" size="body2" measure="none">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>
116
143
  </Stack>
@@ -137,10 +164,10 @@ export default function ApiKeysList() {
137
164
  {confirming === k.id ? (<Stack gap="small">
138
165
  <Paragraph size="body2" measure="none">Revoke {k.name}?</Paragraph>
139
166
  <Cluster gap="small">
140
- <Button size="small" type="tertiary" state={revoking === k.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking ".concat(k.name)} onClickButton={function () { return setConfirming(null); }}/>
167
+ <Button ref={cancelRevoke} size="small" type="tertiary" state={revoking === k.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking ".concat(k.name)} onClickButton={function () { return keepKey(k); }}/>
141
168
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={"Revoke ".concat(k.name)} loading={revoking === k.id} onClickButton={function () { return handleRevoke(k); }}/>
142
169
  </Cluster>
143
- </Stack>) : (<Button size="small" type="tertiary" state={revoking ? 'disabled' : 'enabled'} label="Revoke" aria-label={"Revoke ".concat(k.name)} onClickButton={function () { return setConfirming(k.id); }}/>)}
170
+ </Stack>) : (<Button ref={function (el) { revokeButtons.current[k.id] = el; }} size="small" type="tertiary" state={revoking ? 'disabled' : 'enabled'} label="Revoke" aria-label={"Revoke ".concat(k.name)} onClickButton={function () { return askToRevoke(k); }}/>)}
144
171
  </TableCell>
145
172
  </TableRow>); })}
146
173
  </TableContainer>) : (<EmptyBox size="small" icon="KeyRound" text="No API keys" secondText="Keys you create appear here."/>)}
@@ -12,6 +12,7 @@ A person makes keys that let a script or a service use the product as them, and
12
12
  - Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.
13
13
  - Confirm 'Revoke' in the row, as the case 'Delete confirm' does: the row asks 'Revoke CI pipeline?' and shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'CI pipeline key revoked.'
14
14
  - Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the key: 'Revoke CI pipeline' and 'Cancel revoking CI pipeline'.
15
+ - Move focus with the confirm, since the button that had it goes away: to 'Cancel' when the confirm opens, back to the row's 'Revoke' on Cancel, and after a revoke to the next row's 'Revoke', or the one before it on the last row. With no key left, focus goes to 'Create Key'.
15
16
  - Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what will fill it' says.
16
17
  - Disable the name field while the key is made, and show `loading` on the Button without changing its label.
17
18
 
@@ -58,6 +59,8 @@ const firstKeys: Key[] = [
58
59
  const madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';
59
60
  const prefixLength = 14;
60
61
 
62
+ type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
63
+
61
64
  export default function ApiKeysList() {
62
65
  // Opens on the new key, as if the person just chose Create. The list already holds it, without the key.
63
66
  const [keys, setKeys] = useState<Key[]>(() => [
@@ -75,6 +78,12 @@ export default function ApiKeysList() {
75
78
  // Gives each new key its own id, so no two rows share a key.
76
79
  const keyCount = useRef(0);
77
80
  const toastIds = useRef<string[]>([]);
81
+ const createButton = useRef<Focusable>(null);
82
+ const cancelRevoke = useRef<Focusable>(null);
83
+ // Each row's Revoke button by key id, so focus can move to one when the button that had it is gone.
84
+ const revokeButtons = useRef<Record<string, Focusable>>({});
85
+ // Where focus goes after the next render, once the element it goes to is on screen.
86
+ const focusNext = useRef<() => void>();
78
87
 
79
88
  // On unmount it stops every request and closes every toast it opened.
80
89
  useEffect(() => () => {
@@ -83,6 +92,12 @@ export default function ApiKeysList() {
83
92
  toastIds.current = [];
84
93
  }, []);
85
94
 
95
+ useEffect(() => {
96
+ const move = focusNext.current;
97
+ focusNext.current = undefined;
98
+ move?.();
99
+ });
100
+
86
101
  // Stands in for the request to the server.
87
102
  function later(callback: () => void, ms: number) {
88
103
  timers.current.push(setTimeout(callback, ms));
@@ -125,13 +140,30 @@ export default function ApiKeysList() {
125
140
  }, 1200);
126
141
  }
127
142
 
143
+ // The confirm opens in the row, with focus on 'Cancel'.
144
+ function askToRevoke(key: Key) {
145
+ setConfirming(key.id);
146
+ focusNext.current = () => cancelRevoke.current?.focus();
147
+ }
148
+
149
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's Revoke button.
150
+ function keepKey(key: Key) {
151
+ setConfirming(null);
152
+ focusNext.current = () => revokeButtons.current[key.id]?.focus();
153
+ }
154
+
128
155
  function handleRevoke(key: Key) {
129
156
  if (revoking) return;
157
+ const at = keys.findIndex((k) => k.id === key.id);
158
+ const neighbor = keys[at + 1] ?? keys[at - 1];
130
159
  setRevoking(key.id);
131
160
  later(() => {
132
161
  setRevoking(null);
133
162
  setConfirming(null);
134
163
  setKeys((list) => list.filter((k) => k.id !== key.id));
164
+ // The row is gone: focus goes to the next row's Revoke, or the one before it when it was the last.
165
+ // With no key left, it goes to 'Create Key'.
166
+ focusNext.current = () => (neighbor ? revokeButtons.current[neighbor.id] : createButton.current)?.focus();
135
167
  toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));
136
168
  }, 1200);
137
169
  }
@@ -144,7 +176,7 @@ export default function ApiKeysList() {
144
176
  <Stack gap="small">
145
177
  <Cluster justify="between">
146
178
  <Heading level={1} size="h5">API keys</Heading>
147
- <Button size="small" type="primary" state="enabled" label="Create Key" decoIcon="Plus" onClickButton={handleOpen} />
179
+ <Button ref={createButton} size="small" type="primary" state="enabled" label="Create Key" decoIcon="Plus" onClickButton={handleOpen} />
148
180
  </Cluster>
149
181
  <Paragraph tone="secondary" size="body2" measure="none">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>
150
182
  </Stack>
@@ -174,12 +206,12 @@ export default function ApiKeysList() {
174
206
  <Stack gap="small">
175
207
  <Paragraph size="body2" measure="none">Revoke {k.name}?</Paragraph>
176
208
  <Cluster gap="small">
177
- <Button size="small" type="tertiary" state={revoking === k.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => setConfirming(null)} />
209
+ <Button ref={cancelRevoke} size="small" type="tertiary" state={revoking === k.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => keepKey(k)} />
178
210
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />
179
211
  </Cluster>
180
212
  </Stack>
181
213
  ) : (
182
- <Button size="small" type="tertiary" state={revoking ? 'disabled' : 'enabled'} label="Revoke" aria-label={`Revoke ${k.name}`} onClickButton={() => setConfirming(k.id)} />
214
+ <Button ref={(el) => { revokeButtons.current[k.id] = el; }} size="small" type="tertiary" state={revoking ? 'disabled' : 'enabled'} label="Revoke" aria-label={`Revoke ${k.name}`} onClickButton={() => askToRevoke(k)} />
183
215
  )}
184
216
  </TableCell>
185
217
  </TableRow>
@@ -85,6 +85,12 @@ export default function MembersListRows() {
85
85
  var copyTimer = useRef();
86
86
  var mounted = useRef(true);
87
87
  var toastIds = useRef([]);
88
+ var inviteButton = useRef(null);
89
+ var cancelConfirm = useRef(null);
90
+ // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.
91
+ var rowButtons = useRef({});
92
+ // Where focus goes after the next render, once the element it goes to is on screen.
93
+ var focusNext = useRef();
88
94
  // Gives each new invite its own id, so no two rows share a key.
89
95
  var inviteCount = useRef(0);
90
96
  // On unmount it stops every request and closes every toast it opened.
@@ -98,6 +104,11 @@ export default function MembersListRows() {
98
104
  toastIds.current = [];
99
105
  };
100
106
  }, []);
107
+ useEffect(function () {
108
+ var move = focusNext.current;
109
+ focusNext.current = undefined;
110
+ move === null || move === void 0 ? void 0 : move();
111
+ });
101
112
  // Stands in for the request to the server.
102
113
  function later(callback, ms) {
103
114
  timers.current.push(setTimeout(callback, ms));
@@ -134,30 +145,50 @@ export default function MembersListRows() {
134
145
  }
135
146
  }, 900);
136
147
  }
137
- // Starting a confirm on one row cancels the confirm on any other.
148
+ // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.
138
149
  function startConfirm(kind, id) {
139
150
  setConfirmingMember(kind === 'member' ? id : null);
140
151
  setConfirmingInvite(kind === 'invite' ? id : null);
152
+ focusNext.current = function () { var _a; return (_a = cancelConfirm.current) === null || _a === void 0 ? void 0 : _a.focus(); };
153
+ }
154
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's button.
155
+ function cancelConfirmOn(id) {
156
+ setConfirmingMember(null);
157
+ setConfirmingInvite(null);
158
+ focusNext.current = function () { var _a; return (_a = rowButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
159
+ }
160
+ // The row is gone: focus goes to the next row's button, or the one before it when it was the last.
161
+ // With no such row left, it goes to 'Invite Member'.
162
+ function focusAfterRemoving(ids, id) {
163
+ var _a;
164
+ var at = ids.indexOf(id);
165
+ var neighbor = (_a = ids[at + 1]) !== null && _a !== void 0 ? _a : ids[at - 1];
166
+ focusNext.current = function () { var _a; return (_a = (neighbor ? rowButtons.current[neighbor] : inviteButton.current)) === null || _a === void 0 ? void 0 : _a.focus(); };
141
167
  }
142
168
  function handleRemove(member) {
143
169
  if (busyRow)
144
170
  return;
171
+ // Only other people's rows have Remove, in the order they show
172
+ var removable = members.filter(function (m) { return m.id !== youId; }).map(function (m) { return m.id; });
145
173
  setBusyRow(member.id);
146
174
  later(function () {
147
175
  setBusyRow(null);
148
176
  setConfirmingMember(null);
149
177
  setMembers(function (list) { return list.filter(function (m) { return m.id !== member.id; }); });
178
+ focusAfterRemoving(removable, member.id);
150
179
  toastIds.current.push(toast({ type: 'success', message: "".concat(member.name, " removed from Acme.") }));
151
180
  }, 1200);
152
181
  }
153
182
  function handleRevokeInvite(invite) {
154
183
  if (busyRow)
155
184
  return;
185
+ var shown = invites.map(function (i) { return i.id; });
156
186
  setBusyRow(invite.id);
157
187
  later(function () {
158
188
  setBusyRow(null);
159
189
  setConfirmingInvite(null);
160
190
  setInvites(function (list) { return list.filter(function (i) { return i.id !== invite.id; }); });
191
+ focusAfterRemoving(shown, invite.id);
161
192
  toastIds.current.push(toast({ type: 'success', message: "Invite for ".concat(invite.email, " revoked.") }));
162
193
  }, 1200);
163
194
  }
@@ -228,7 +259,7 @@ export default function MembersListRows() {
228
259
  <Stack gap="small">
229
260
  <Cluster justify="between">
230
261
  <Heading level={1} size="h5">Members</Heading>
231
- {canManage && <Button size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember}/>}
262
+ {canManage && <Button ref={inviteButton} size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember}/>}
232
263
  </Cluster>
233
264
  <Paragraph tone="secondary" size="body2" measure="none">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>
234
265
  {!canManage && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change this.</Paragraph>}
@@ -262,9 +293,9 @@ export default function MembersListRows() {
262
293
  <TableCell width="340px">
263
294
  {canManage && !isYou && (confirmingMember === m.id ? (<Cluster gap="small">
264
295
  <Paragraph size="body2" measure="none">Remove {m.name}?</Paragraph>
265
- <Button size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel removing ".concat(m.name)} onClickButton={function () { return setConfirmingMember(null); }}/>
296
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel removing ".concat(m.name)} onClickButton={function () { return cancelConfirmOn(m.id); }}/>
266
297
  <Button size="small" type="primary" color="danger" state="enabled" label="Remove" aria-label={"Remove ".concat(m.name)} loading={busyRow === m.id} onClickButton={function () { return handleRemove(m); }}/>
267
- </Cluster>) : (<Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={"Remove ".concat(m.name)} onClickButton={function () { return startConfirm('member', m.id); }}/>))}
298
+ </Cluster>) : (<Button ref={function (el) { rowButtons.current[m.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={"Remove ".concat(m.name)} onClickButton={function () { return startConfirm('member', m.id); }}/>))}
268
299
  </TableCell>
269
300
  </TableRow>);
270
301
  })}
@@ -284,12 +315,12 @@ export default function MembersListRows() {
284
315
  <TableCell width="340px">
285
316
  {confirmingInvite === i.id ? (<Cluster gap="small">
286
317
  <Paragraph size="body2" measure="none">Revoke this invite?</Paragraph>
287
- <Button size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking the invite for ".concat(i.email)} onClickButton={function () { return setConfirmingInvite(null); }}/>
318
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking the invite for ".concat(i.email)} onClickButton={function () { return cancelConfirmOn(i.id); }}/>
288
319
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={"Revoke invite for ".concat(i.email)} loading={busyRow === i.id} onClickButton={function () { return handleRevokeInvite(i); }}/>
289
320
  </Cluster>) : (<Stack gap="small">
290
321
  <Cluster gap="small">
291
322
  <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={"".concat(copiedInvite === i.id ? 'Copied' : 'Copy Link', " for ").concat(i.email)} onClickButton={function () { return handleCopy(i); }}/>
292
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={"Revoke invite for ".concat(i.email)} onClickButton={function () { return startConfirm('invite', i.id); }}/>
323
+ <Button ref={function (el) { rowButtons.current[i.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={"Revoke invite for ".concat(i.email)} onClickButton={function () { return startConfirm('invite', i.id); }}/>
293
324
  </Cluster>
294
325
  {copyBlocked === i.id && <Paragraph tone="secondary" size="caption" measure="none">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}
295
326
  </Stack>)}
@@ -94,6 +94,12 @@ export default function MembersListTable() {
94
94
  var copyTimer = useRef();
95
95
  var mounted = useRef(true);
96
96
  var toastIds = useRef([]);
97
+ var inviteButton = useRef(null);
98
+ var cancelConfirm = useRef(null);
99
+ // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.
100
+ var rowButtons = useRef({});
101
+ // Where focus goes after the next render, once the element it goes to is on screen.
102
+ var focusNext = useRef();
97
103
  // Gives each new invite its own id, so no two rows share a key.
98
104
  var inviteCount = useRef(0);
99
105
  // On unmount it stops every request and closes every toast it opened.
@@ -107,6 +113,11 @@ export default function MembersListTable() {
107
113
  toastIds.current = [];
108
114
  };
109
115
  }, []);
116
+ useEffect(function () {
117
+ var move = focusNext.current;
118
+ focusNext.current = undefined;
119
+ move === null || move === void 0 ? void 0 : move();
120
+ });
110
121
  // Stands in for the request to the server.
111
122
  function later(callback, ms) {
112
123
  timers.current.push(setTimeout(callback, ms));
@@ -158,30 +169,50 @@ export default function MembersListTable() {
158
169
  }
159
170
  }, 900);
160
171
  }
161
- // Starting a confirm on one row cancels the confirm on any other.
172
+ // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.
162
173
  function startConfirm(kind, id) {
163
174
  setConfirmingMember(kind === 'member' ? id : null);
164
175
  setConfirmingInvite(kind === 'invite' ? id : null);
176
+ focusNext.current = function () { var _a; return (_a = cancelConfirm.current) === null || _a === void 0 ? void 0 : _a.focus(); };
177
+ }
178
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's button.
179
+ function cancelConfirmOn(id) {
180
+ setConfirmingMember(null);
181
+ setConfirmingInvite(null);
182
+ focusNext.current = function () { var _a; return (_a = rowButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
183
+ }
184
+ // The row is gone: focus goes to the next row's button, or the one before it when it was the last.
185
+ // With no such row left, it goes to 'Invite Member'.
186
+ function focusAfterRemoving(ids, id) {
187
+ var _a;
188
+ var at = ids.indexOf(id);
189
+ var neighbor = (_a = ids[at + 1]) !== null && _a !== void 0 ? _a : ids[at - 1];
190
+ focusNext.current = function () { var _a; return (_a = (neighbor ? rowButtons.current[neighbor] : inviteButton.current)) === null || _a === void 0 ? void 0 : _a.focus(); };
165
191
  }
166
192
  function handleRemove(member) {
167
193
  if (busyRow)
168
194
  return;
195
+ // Only other people's rows have Remove, in the order they show
196
+ var removable = sorted.filter(function (m) { return m.id !== youId; }).map(function (m) { return m.id; });
169
197
  setBusyRow(member.id);
170
198
  later(function () {
171
199
  setBusyRow(null);
172
200
  setConfirmingMember(null);
173
201
  setMembers(function (list) { return list.filter(function (m) { return m.id !== member.id; }); });
202
+ focusAfterRemoving(removable, member.id);
174
203
  toastIds.current.push(toast({ type: 'success', message: "".concat(member.name, " removed from Acme.") }));
175
204
  }, 1200);
176
205
  }
177
206
  function handleRevokeInvite(invite) {
178
207
  if (busyRow)
179
208
  return;
209
+ var shown = invites.map(function (i) { return i.id; });
180
210
  setBusyRow(invite.id);
181
211
  later(function () {
182
212
  setBusyRow(null);
183
213
  setConfirmingInvite(null);
184
214
  setInvites(function (list) { return list.filter(function (i) { return i.id !== invite.id; }); });
215
+ focusAfterRemoving(shown, invite.id);
185
216
  toastIds.current.push(toast({ type: 'success', message: "Invite for ".concat(invite.email, " revoked.") }));
186
217
  }, 1200);
187
218
  }
@@ -252,7 +283,7 @@ export default function MembersListTable() {
252
283
  <Stack gap="small">
253
284
  <Cluster justify="between">
254
285
  <Heading level={1} size="h5">Members</Heading>
255
- {canManage && <Button size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember}/>}
286
+ {canManage && <Button ref={inviteButton} size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember}/>}
256
287
  </Cluster>
257
288
  <Paragraph tone="secondary" size="body2" measure="none">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>
258
289
  {!canManage && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change this.</Paragraph>}
@@ -293,9 +324,9 @@ export default function MembersListTable() {
293
324
  <TableCell width="340px">
294
325
  {canManage && !isYou && (confirmingMember === m.id ? (<Cluster gap="small">
295
326
  <Paragraph size="body2" measure="none">Remove {m.name}?</Paragraph>
296
- <Button size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel removing ".concat(m.name)} onClickButton={function () { return setConfirmingMember(null); }}/>
327
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel removing ".concat(m.name)} onClickButton={function () { return cancelConfirmOn(m.id); }}/>
297
328
  <Button size="small" type="primary" color="danger" state="enabled" label="Remove" aria-label={"Remove ".concat(m.name)} loading={busyRow === m.id} onClickButton={function () { return handleRemove(m); }}/>
298
- </Cluster>) : (<Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={"Remove ".concat(m.name)} onClickButton={function () { return startConfirm('member', m.id); }}/>))}
329
+ </Cluster>) : (<Button ref={function (el) { rowButtons.current[m.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={"Remove ".concat(m.name)} onClickButton={function () { return startConfirm('member', m.id); }}/>))}
299
330
  </TableCell>
300
331
  </TableRow>);
301
332
  })}
@@ -315,12 +346,12 @@ export default function MembersListTable() {
315
346
  <TableCell width="340px">
316
347
  {confirmingInvite === i.id ? (<Cluster gap="small">
317
348
  <Paragraph size="body2" measure="none">Revoke this invite?</Paragraph>
318
- <Button size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking the invite for ".concat(i.email)} onClickButton={function () { return setConfirmingInvite(null); }}/>
349
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel revoking the invite for ".concat(i.email)} onClickButton={function () { return cancelConfirmOn(i.id); }}/>
319
350
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={"Revoke invite for ".concat(i.email)} loading={busyRow === i.id} onClickButton={function () { return handleRevokeInvite(i); }}/>
320
351
  </Cluster>) : (<Stack gap="small">
321
352
  <Cluster gap="small">
322
353
  <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={"".concat(copiedInvite === i.id ? 'Copied' : 'Copy Link', " for ").concat(i.email)} onClickButton={function () { return handleCopy(i); }}/>
323
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={"Revoke invite for ".concat(i.email)} onClickButton={function () { return startConfirm('invite', i.id); }}/>
354
+ <Button ref={function (el) { rowButtons.current[i.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={"Revoke invite for ".concat(i.email)} onClickButton={function () { return startConfirm('invite', i.id); }}/>
324
355
  </Cluster>
325
356
  {copyBlocked === i.id && <Paragraph tone="secondary" size="caption" measure="none">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}
326
357
  </Stack>)}
@@ -11,6 +11,7 @@ An admin sees who is in the workspace, changes their roles, removes people and i
11
11
  - Show your own role as text with a 'You' Tag, and give your row no Remove.
12
12
  - Confirm 'Remove' in the row, as the case 'Delete confirm' does: the row asks 'Remove Ben Carter?' and shows 'Cancel' and a danger 'Remove'. Then show a toast: 'Ben Carter removed from Acme.'
13
13
  - Give each row's 'Remove', and the confirm's 'Cancel' and 'Remove', an `aria-label` that names the person: 'Remove Ben Carter' and 'Cancel removing Ben Carter'.
14
+ - Move focus with the confirm, since the button that had it goes away: to 'Cancel' when the confirm opens, back to the row's button on Cancel, and after a remove or revoke to the next row's button, or the one before it on the last row. With no such row left, focus goes to 'Invite Member'.
14
15
  - List pending invites under the members. Each has 'Copy Link', which reads 'Copied' for 2 seconds, and 'Revoke Invite'.
15
16
  - Confirm 'Revoke Invite' in the row before it ends the link: the row shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'Invite for sam@partner.example revoked.'
16
17
  - Name the invite in each `aria-label`: 'Revoke invite for sam@partner.example' and 'Cancel revoking the invite for sam@partner.example'.
@@ -58,6 +59,7 @@ import { formatMoney } from 'oneslash-design-system/components/formatNumber';
58
59
 
59
60
  type Member = { id: string; name: string; email: string; role: string };
60
61
  type Invite = { id: string; email: string; sent: string; link: string };
62
+ type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
61
63
 
62
64
  // A real app reads these from the signed-in person and the plan.
63
65
  const youId = 'dana';
@@ -116,6 +118,12 @@ export default function MembersListRows() {
116
118
  const copyTimer = useRef<ReturnType<typeof setTimeout>>();
117
119
  const mounted = useRef(true);
118
120
  const toastIds = useRef<string[]>([]);
121
+ const inviteButton = useRef<Focusable>(null);
122
+ const cancelConfirm = useRef<Focusable>(null);
123
+ // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.
124
+ const rowButtons = useRef<Record<string, Focusable>>({});
125
+ // Where focus goes after the next render, once the element it goes to is on screen.
126
+ const focusNext = useRef<() => void>();
119
127
  // Gives each new invite its own id, so no two rows share a key.
120
128
  const inviteCount = useRef(0);
121
129
 
@@ -131,6 +139,12 @@ export default function MembersListRows() {
131
139
  };
132
140
  }, []);
133
141
 
142
+ useEffect(() => {
143
+ const move = focusNext.current;
144
+ focusNext.current = undefined;
145
+ move?.();
146
+ });
147
+
134
148
  // Stands in for the request to the server.
135
149
  function later(callback: () => void, ms: number) {
136
150
  timers.current.push(setTimeout(callback, ms));
@@ -157,30 +171,51 @@ export default function MembersListRows() {
157
171
  }, 900);
158
172
  }
159
173
 
160
- // Starting a confirm on one row cancels the confirm on any other.
174
+ // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.
161
175
  function startConfirm(kind: 'member' | 'invite', id: string) {
162
176
  setConfirmingMember(kind === 'member' ? id : null);
163
177
  setConfirmingInvite(kind === 'invite' ? id : null);
178
+ focusNext.current = () => cancelConfirm.current?.focus();
179
+ }
180
+
181
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's button.
182
+ function cancelConfirmOn(id: string) {
183
+ setConfirmingMember(null);
184
+ setConfirmingInvite(null);
185
+ focusNext.current = () => rowButtons.current[id]?.focus();
186
+ }
187
+
188
+ // The row is gone: focus goes to the next row's button, or the one before it when it was the last.
189
+ // With no such row left, it goes to 'Invite Member'.
190
+ function focusAfterRemoving(ids: string[], id: string) {
191
+ const at = ids.indexOf(id);
192
+ const neighbor = ids[at + 1] ?? ids[at - 1];
193
+ focusNext.current = () => (neighbor ? rowButtons.current[neighbor] : inviteButton.current)?.focus();
164
194
  }
165
195
 
166
196
  function handleRemove(member: Member) {
167
197
  if (busyRow) return;
198
+ // Only other people's rows have Remove, in the order they show
199
+ const removable = members.filter((m) => m.id !== youId).map((m) => m.id);
168
200
  setBusyRow(member.id);
169
201
  later(() => {
170
202
  setBusyRow(null);
171
203
  setConfirmingMember(null);
172
204
  setMembers((list) => list.filter((m) => m.id !== member.id));
205
+ focusAfterRemoving(removable, member.id);
173
206
  toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));
174
207
  }, 1200);
175
208
  }
176
209
 
177
210
  function handleRevokeInvite(invite: Invite) {
178
211
  if (busyRow) return;
212
+ const shown = invites.map((i) => i.id);
179
213
  setBusyRow(invite.id);
180
214
  later(() => {
181
215
  setBusyRow(null);
182
216
  setConfirmingInvite(null);
183
217
  setInvites((list) => list.filter((i) => i.id !== invite.id));
218
+ focusAfterRemoving(shown, invite.id);
184
219
  toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));
185
220
  }, 1200);
186
221
  }
@@ -253,7 +288,7 @@ export default function MembersListRows() {
253
288
  <Stack gap="small">
254
289
  <Cluster justify="between">
255
290
  <Heading level={1} size="h5">Members</Heading>
256
- {canManage && <Button size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember} />}
291
+ {canManage && <Button ref={inviteButton} size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember} />}
257
292
  </Cluster>
258
293
  <Paragraph tone="secondary" size="body2" measure="none">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>
259
294
  {!canManage && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change this.</Paragraph>}
@@ -302,11 +337,11 @@ export default function MembersListRows() {
302
337
  confirmingMember === m.id ? (
303
338
  <Cluster gap="small">
304
339
  <Paragraph size="body2" measure="none">Remove {m.name}?</Paragraph>
305
- <Button size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />
340
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel removing ${m.name}`} onClickButton={() => cancelConfirmOn(m.id)} />
306
341
  <Button size="small" type="primary" color="danger" state="enabled" label="Remove" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />
307
342
  </Cluster>
308
343
  ) : (
309
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />
344
+ <Button ref={(el) => { rowButtons.current[m.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />
310
345
  )
311
346
  )}
312
347
  </TableCell>
@@ -332,14 +367,14 @@ export default function MembersListRows() {
332
367
  {confirmingInvite === i.id ? (
333
368
  <Cluster gap="small">
334
369
  <Paragraph size="body2" measure="none">Revoke this invite?</Paragraph>
335
- <Button size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />
370
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => cancelConfirmOn(i.id)} />
336
371
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />
337
372
  </Cluster>
338
373
  ) : (
339
374
  <Stack gap="small">
340
375
  <Cluster gap="small">
341
376
  <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />
342
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />
377
+ <Button ref={(el) => { rowButtons.current[i.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />
343
378
  </Cluster>
344
379
  {copyBlocked === i.id && <Paragraph tone="secondary" size="caption" measure="none">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}
345
380
  </Stack>
@@ -420,6 +455,7 @@ import { formatMoney } from 'oneslash-design-system/components/formatNumber';
420
455
 
421
456
  type Member = { id: string; name: string; email: string; role: string };
422
457
  type Invite = { id: string; email: string; sent: string; link: string };
458
+ type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
423
459
 
424
460
  // A real app reads these from the signed-in person and the plan.
425
461
  const youId = 'dana';
@@ -485,6 +521,12 @@ export default function MembersListTable() {
485
521
  const copyTimer = useRef<ReturnType<typeof setTimeout>>();
486
522
  const mounted = useRef(true);
487
523
  const toastIds = useRef<string[]>([]);
524
+ const inviteButton = useRef<Focusable>(null);
525
+ const cancelConfirm = useRef<Focusable>(null);
526
+ // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.
527
+ const rowButtons = useRef<Record<string, Focusable>>({});
528
+ // Where focus goes after the next render, once the element it goes to is on screen.
529
+ const focusNext = useRef<() => void>();
488
530
  // Gives each new invite its own id, so no two rows share a key.
489
531
  const inviteCount = useRef(0);
490
532
 
@@ -500,6 +542,12 @@ export default function MembersListTable() {
500
542
  };
501
543
  }, []);
502
544
 
545
+ useEffect(() => {
546
+ const move = focusNext.current;
547
+ focusNext.current = undefined;
548
+ move?.();
549
+ });
550
+
503
551
  // Stands in for the request to the server.
504
552
  function later(callback: () => void, ms: number) {
505
553
  timers.current.push(setTimeout(callback, ms));
@@ -553,30 +601,51 @@ export default function MembersListTable() {
553
601
  }, 900);
554
602
  }
555
603
 
556
- // Starting a confirm on one row cancels the confirm on any other.
604
+ // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.
557
605
  function startConfirm(kind: 'member' | 'invite', id: string) {
558
606
  setConfirmingMember(kind === 'member' ? id : null);
559
607
  setConfirmingInvite(kind === 'invite' ? id : null);
608
+ focusNext.current = () => cancelConfirm.current?.focus();
609
+ }
610
+
611
+ // 'Cancel' goes away with the confirm, so focus goes back to the row's button.
612
+ function cancelConfirmOn(id: string) {
613
+ setConfirmingMember(null);
614
+ setConfirmingInvite(null);
615
+ focusNext.current = () => rowButtons.current[id]?.focus();
616
+ }
617
+
618
+ // The row is gone: focus goes to the next row's button, or the one before it when it was the last.
619
+ // With no such row left, it goes to 'Invite Member'.
620
+ function focusAfterRemoving(ids: string[], id: string) {
621
+ const at = ids.indexOf(id);
622
+ const neighbor = ids[at + 1] ?? ids[at - 1];
623
+ focusNext.current = () => (neighbor ? rowButtons.current[neighbor] : inviteButton.current)?.focus();
560
624
  }
561
625
 
562
626
  function handleRemove(member: Member) {
563
627
  if (busyRow) return;
628
+ // Only other people's rows have Remove, in the order they show
629
+ const removable = sorted.filter((m) => m.id !== youId).map((m) => m.id);
564
630
  setBusyRow(member.id);
565
631
  later(() => {
566
632
  setBusyRow(null);
567
633
  setConfirmingMember(null);
568
634
  setMembers((list) => list.filter((m) => m.id !== member.id));
635
+ focusAfterRemoving(removable, member.id);
569
636
  toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));
570
637
  }, 1200);
571
638
  }
572
639
 
573
640
  function handleRevokeInvite(invite: Invite) {
574
641
  if (busyRow) return;
642
+ const shown = invites.map((i) => i.id);
575
643
  setBusyRow(invite.id);
576
644
  later(() => {
577
645
  setBusyRow(null);
578
646
  setConfirmingInvite(null);
579
647
  setInvites((list) => list.filter((i) => i.id !== invite.id));
648
+ focusAfterRemoving(shown, invite.id);
580
649
  toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));
581
650
  }, 1200);
582
651
  }
@@ -649,7 +718,7 @@ export default function MembersListTable() {
649
718
  <Stack gap="small">
650
719
  <Cluster justify="between">
651
720
  <Heading level={1} size="h5">Members</Heading>
652
- {canManage && <Button size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember} />}
721
+ {canManage && <Button ref={inviteButton} size="small" type="primary" state="enabled" label="Invite Member" decoIcon="UserPlus" onClickButton={handleInviteMember} />}
653
722
  </Cluster>
654
723
  <Paragraph tone="secondary" size="body2" measure="none">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>
655
724
  {!canManage && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change this.</Paragraph>}
@@ -705,11 +774,11 @@ export default function MembersListTable() {
705
774
  confirmingMember === m.id ? (
706
775
  <Cluster gap="small">
707
776
  <Paragraph size="body2" measure="none">Remove {m.name}?</Paragraph>
708
- <Button size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />
777
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === m.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel removing ${m.name}`} onClickButton={() => cancelConfirmOn(m.id)} />
709
778
  <Button size="small" type="primary" color="danger" state="enabled" label="Remove" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />
710
779
  </Cluster>
711
780
  ) : (
712
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />
781
+ <Button ref={(el) => { rowButtons.current[m.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Remove" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />
713
782
  )
714
783
  )}
715
784
  </TableCell>
@@ -735,14 +804,14 @@ export default function MembersListTable() {
735
804
  {confirmingInvite === i.id ? (
736
805
  <Cluster gap="small">
737
806
  <Paragraph size="body2" measure="none">Revoke this invite?</Paragraph>
738
- <Button size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />
807
+ <Button ref={cancelConfirm} size="small" type="tertiary" state={busyRow === i.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => cancelConfirmOn(i.id)} />
739
808
  <Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />
740
809
  </Cluster>
741
810
  ) : (
742
811
  <Stack gap="small">
743
812
  <Cluster gap="small">
744
813
  <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />
745
- <Button size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />
814
+ <Button ref={(el) => { rowButtons.current[i.id] = el; }} size="small" type="tertiary" state={busyRow ? 'disabled' : 'enabled'} label="Revoke Invite" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />
746
815
  </Cluster>
747
816
  {copyBlocked === i.id && <Paragraph tone="secondary" size="caption" measure="none">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}
748
817
  </Stack>
package/dist/cases.json CHANGED
@@ -801,6 +801,7 @@
801
801
  "Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.",
802
802
  "Confirm 'Revoke' in the row, as the case 'Delete confirm' does: the row asks 'Revoke CI pipeline?' and shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'CI pipeline key revoked.'",
803
803
  "Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the key: 'Revoke CI pipeline' and 'Cancel revoking CI pipeline'.",
804
+ "Move focus with the confirm, since the button that had it goes away: to 'Cancel' when the confirm opens, back to the row's 'Revoke' on Cancel, and after a revoke to the next row's 'Revoke', or the one before it on the last row. With no key left, focus goes to 'Create Key'.",
804
805
  "Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what will fill it' says.",
805
806
  "Disable the name field while the key is made, and show `loading` on the Button without changing its label."
806
807
  ],
@@ -818,7 +819,7 @@
818
819
  "id": "list",
819
820
  "title": "A list of keys with a create Modal",
820
821
  "useWhen": "Scripts or services act as the person with a key they paste.",
821
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Key = { id: string; name: string; prefix: string; created: string; lastUsed: string };\n\nconst firstKeys: Key[] = [\n { id: 'k1', name: 'CI pipeline', prefix: 'acme_live_7Hd2', created: 'Oct 3, 2026', lastUsed: 'Today' },\n { id: 'k2', name: 'Reporting script', prefix: 'acme_live_Qm4x', created: 'Aug 19, 2026', lastUsed: 'Nov 20, 2026' },\n];\n\n// The key the server made. A real app gets it once, in the reply to the create request, and never again.\nconst madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';\nconst prefixLength = 14;\n\nexport default function ApiKeysList() {\n // Opens on the new key, as if the person just chose Create. The list already holds it, without the key.\n const [keys, setKeys] = useState<Key[]>(() => [\n { id: 'k3', name: 'Deploy bot', prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' },\n ...firstKeys,\n ]);\n const [open, setOpen] = useState(true);\n const [shownKey, setShownKey] = useState<string | null>(madeKey);\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Gives each new key its own id, so no two rows share a key.\n const keyCount = useRef(0);\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleOpen() {\n setName('');\n setNameError('');\n setShownKey(null);\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel close the first step, except while the request runs.\n // Once the key shows, only 'Done' closes it, so a stray click cannot throw the key away.\n function handleClose() {\n if (creating || shownKey) return;\n setOpen(false);\n }\n\n // 'Done' drops the key from the page. It is not kept anywhere else.\n function handleDone() {\n setOpen(false);\n setShownKey(null);\n }\n\n function handleCreate() {\n if (creating) return;\n if (!name.trim()) {\n setNameError('Enter a name for the key.');\n return;\n }\n setNameError('');\n setCreating(true);\n later(() => {\n setCreating(false);\n keyCount.current += 1;\n const id = `new-${keyCount.current}`;\n setKeys((list) => [{ id, name: name.trim(), prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' }, ...list]);\n setShownKey(madeKey);\n }, 1200);\n }\n\n function handleRevoke(key: Key) {\n if (revoking) return;\n setRevoking(key.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setKeys((list) => list.filter((k) => k.id !== key.id));\n toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">API keys</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Key\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>\n </Stack>\n\n {keys.length > 0 ? (\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Name</TableHeaderCell>\n <TableHeaderCell width=\"150px\">Key</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Created</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Last used</TableHeaderCell>\n <TableHeaderCell width=\"200px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {keys.map((k) => (\n <TableRow key={k.id}>\n <TableCell>{k.name}</TableCell>\n <TableCell width=\"150px\">\n <Paragraph mono size=\"body2\" measure=\"none\">{k.prefix}…</Paragraph>\n </TableCell>\n <TableCell width=\"100px\">{k.created}</TableCell>\n <TableCell width=\"100px\">{k.lastUsed}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"200px\">\n {confirming === k.id ? (\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke {k.name}?</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={revoking === k.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => setConfirming(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />\n </Cluster>\n </Stack>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${k.name}`} onClickButton={() => setConfirming(k.id)} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"KeyRound\" text=\"No API keys\" secondText=\"Keys you create appear here.\" />\n )}\n </Stack>\n\n <Modal\n isOpen={open}\n size=\"medium\"\n initialFocus=\"body\"\n title={shownKey ? 'Key Created' : 'Create Key'}\n onClose={handleClose}\n actions={\n shownKey ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n ) : (\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n )\n }\n >\n {shownKey ? (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Use this key where the service asks for one. Anyone who has it can use Acme as you.</Paragraph>\n {/* `reveal=\"once\"` adds the line that says the key will not show again. */}\n <CopyField id=\"api-keys-key\" label=\"API key\" value={shownKey} mono reveal=\"once\" />\n </Stack>\n ) : (\n <Form aria-label=\"Create key\" onSubmit={handleCreate}>\n <TextField id=\"api-keys-name\" label=\"Name\" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} helperText=\"Say what will use it, such as CI pipeline.\" onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n </Form>\n )}\n </Modal>\n </Center>\n );\n}\n",
822
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Key = { id: string; name: string; prefix: string; created: string; lastUsed: string };\n\nconst firstKeys: Key[] = [\n { id: 'k1', name: 'CI pipeline', prefix: 'acme_live_7Hd2', created: 'Oct 3, 2026', lastUsed: 'Today' },\n { id: 'k2', name: 'Reporting script', prefix: 'acme_live_Qm4x', created: 'Aug 19, 2026', lastUsed: 'Nov 20, 2026' },\n];\n\n// The key the server made. A real app gets it once, in the reply to the create request, and never again.\nconst madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';\nconst prefixLength = 14;\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\nexport default function ApiKeysList() {\n // Opens on the new key, as if the person just chose Create. The list already holds it, without the key.\n const [keys, setKeys] = useState<Key[]>(() => [\n { id: 'k3', name: 'Deploy bot', prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' },\n ...firstKeys,\n ]);\n const [open, setOpen] = useState(true);\n const [shownKey, setShownKey] = useState<string | null>(madeKey);\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Gives each new key its own id, so no two rows share a key.\n const keyCount = useRef(0);\n const toastIds = useRef<string[]>([]);\n const createButton = useRef<Focusable>(null);\n const cancelRevoke = useRef<Focusable>(null);\n // Each row's Revoke button by key id, so focus can move to one when the button that had it is gone.\n const revokeButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleOpen() {\n setName('');\n setNameError('');\n setShownKey(null);\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel close the first step, except while the request runs.\n // Once the key shows, only 'Done' closes it, so a stray click cannot throw the key away.\n function handleClose() {\n if (creating || shownKey) return;\n setOpen(false);\n }\n\n // 'Done' drops the key from the page. It is not kept anywhere else.\n function handleDone() {\n setOpen(false);\n setShownKey(null);\n }\n\n function handleCreate() {\n if (creating) return;\n if (!name.trim()) {\n setNameError('Enter a name for the key.');\n return;\n }\n setNameError('');\n setCreating(true);\n later(() => {\n setCreating(false);\n keyCount.current += 1;\n const id = `new-${keyCount.current}`;\n setKeys((list) => [{ id, name: name.trim(), prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' }, ...list]);\n setShownKey(madeKey);\n }, 1200);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToRevoke(key: Key) {\n setConfirming(key.id);\n focusNext.current = () => cancelRevoke.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Revoke button.\n function keepKey(key: Key) {\n setConfirming(null);\n focusNext.current = () => revokeButtons.current[key.id]?.focus();\n }\n\n function handleRevoke(key: Key) {\n if (revoking) return;\n const at = keys.findIndex((k) => k.id === key.id);\n const neighbor = keys[at + 1] ?? keys[at - 1];\n setRevoking(key.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setKeys((list) => list.filter((k) => k.id !== key.id));\n // The row is gone: focus goes to the next row's Revoke, or the one before it when it was the last.\n // With no key left, it goes to 'Create Key'.\n focusNext.current = () => (neighbor ? revokeButtons.current[neighbor.id] : createButton.current)?.focus();\n toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">API keys</Heading>\n <Button ref={createButton} size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Key\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>\n </Stack>\n\n {keys.length > 0 ? (\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Name</TableHeaderCell>\n <TableHeaderCell width=\"150px\">Key</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Created</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Last used</TableHeaderCell>\n <TableHeaderCell width=\"200px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {keys.map((k) => (\n <TableRow key={k.id}>\n <TableCell>{k.name}</TableCell>\n <TableCell width=\"150px\">\n <Paragraph mono size=\"body2\" measure=\"none\">{k.prefix}…</Paragraph>\n </TableCell>\n <TableCell width=\"100px\">{k.created}</TableCell>\n <TableCell width=\"100px\">{k.lastUsed}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"200px\">\n {confirming === k.id ? (\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke {k.name}?</Paragraph>\n <Cluster gap=\"small\">\n <Button ref={cancelRevoke} size=\"small\" type=\"tertiary\" state={revoking === k.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => keepKey(k)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />\n </Cluster>\n </Stack>\n ) : (\n <Button ref={(el) => { revokeButtons.current[k.id] = el; }} size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${k.name}`} onClickButton={() => askToRevoke(k)} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"KeyRound\" text=\"No API keys\" secondText=\"Keys you create appear here.\" />\n )}\n </Stack>\n\n <Modal\n isOpen={open}\n size=\"medium\"\n initialFocus=\"body\"\n title={shownKey ? 'Key Created' : 'Create Key'}\n onClose={handleClose}\n actions={\n shownKey ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n ) : (\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n )\n }\n >\n {shownKey ? (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Use this key where the service asks for one. Anyone who has it can use Acme as you.</Paragraph>\n {/* `reveal=\"once\"` adds the line that says the key will not show again. */}\n <CopyField id=\"api-keys-key\" label=\"API key\" value={shownKey} mono reveal=\"once\" />\n </Stack>\n ) : (\n <Form aria-label=\"Create key\" onSubmit={handleCreate}>\n <TextField id=\"api-keys-name\" label=\"Name\" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} helperText=\"Say what will use it, such as CI pipeline.\" onChange={(e) => { setName(e.target.value); setNameError(''); }} />\n </Form>\n )}\n </Modal>\n </Center>\n );\n}\n",
822
823
  "uses": [
823
824
  "Button",
824
825
  "Center",
@@ -4183,6 +4184,7 @@
4183
4184
  "Show your own role as text with a 'You' Tag, and give your row no Remove.",
4184
4185
  "Confirm 'Remove' in the row, as the case 'Delete confirm' does: the row asks 'Remove Ben Carter?' and shows 'Cancel' and a danger 'Remove'. Then show a toast: 'Ben Carter removed from Acme.'",
4185
4186
  "Give each row's 'Remove', and the confirm's 'Cancel' and 'Remove', an `aria-label` that names the person: 'Remove Ben Carter' and 'Cancel removing Ben Carter'.",
4187
+ "Move focus with the confirm, since the button that had it goes away: to 'Cancel' when the confirm opens, back to the row's button on Cancel, and after a remove or revoke to the next row's button, or the one before it on the last row. With no such row left, focus goes to 'Invite Member'.",
4186
4188
  "List pending invites under the members. Each has 'Copy Link', which reads 'Copied' for 2 seconds, and 'Revoke Invite'.",
4187
4189
  "Confirm 'Revoke Invite' in the row before it ends the link: the row shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'Invite for sam@partner.example revoked.'",
4188
4190
  "Name the invite in each `aria-label`: 'Revoke invite for sam@partner.example' and 'Cancel revoking the invite for sam@partner.example'.",
@@ -4207,7 +4209,7 @@
4207
4209
  "id": "rows",
4208
4210
  "title": "A list of rows",
4209
4211
  "useWhen": "A workspace of a few dozen people, so the whole list fits and a person finds someone by looking.",
4210
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4212
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const inviteButton = useRef<Focusable>(null);\n const cancelConfirm = useRef<Focusable>(null);\n // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.\n const rowButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n focusNext.current = () => cancelConfirm.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's button.\n function cancelConfirmOn(id: string) {\n setConfirmingMember(null);\n setConfirmingInvite(null);\n focusNext.current = () => rowButtons.current[id]?.focus();\n }\n\n // The row is gone: focus goes to the next row's button, or the one before it when it was the last.\n // With no such row left, it goes to 'Invite Member'.\n function focusAfterRemoving(ids: string[], id: string) {\n const at = ids.indexOf(id);\n const neighbor = ids[at + 1] ?? ids[at - 1];\n focusNext.current = () => (neighbor ? rowButtons.current[neighbor] : inviteButton.current)?.focus();\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n // Only other people's rows have Remove, in the order they show\n const removable = members.filter((m) => m.id !== youId).map((m) => m.id);\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n focusAfterRemoving(removable, member.id);\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n const shown = invites.map((i) => i.id);\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n focusAfterRemoving(shown, invite.id);\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button ref={inviteButton} size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button ref={cancelConfirm} size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => cancelConfirmOn(m.id)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button ref={(el) => { rowButtons.current[m.id] = el; }} size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button ref={cancelConfirm} size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => cancelConfirmOn(i.id)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button ref={(el) => { rowButtons.current[i.id] = el; }} size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4211
4213
  "uses": [
4212
4214
  "Alert",
4213
4215
  "Button",
@@ -4235,7 +4237,7 @@
4235
4237
  "id": "table",
4236
4238
  "title": "A table with sorting",
4237
4239
  "useWhen": "More people than a person can scan. The columns Name and Role sort.",
4238
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The sorted column's header cell has `sort`; the other cells leave it unset. The Button is named by its label alone.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer aria-label=\"Members\" minWidth=\"720px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell sort={sort.by === 'name' ? sort.dir : undefined}>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\" sort={sort.by === 'role' ? sort.dir : undefined}>{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer aria-label=\"Pending invites\" minWidth=\"720px\">\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4240
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\nimport { formatMoney } from 'oneslash-design-system/components/formatNumber';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n const inviteButton = useRef<Focusable>(null);\n const cancelConfirm = useRef<Focusable>(null);\n // Each row's Remove or Revoke Invite button by row id, so focus can move to one when the button that had it is gone.\n const rowButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The sorted column's header cell has `sort`; the other cells leave it unset. The Button is named by its label alone.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other. It opens in the row, with focus on 'Cancel'.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n focusNext.current = () => cancelConfirm.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's button.\n function cancelConfirmOn(id: string) {\n setConfirmingMember(null);\n setConfirmingInvite(null);\n focusNext.current = () => rowButtons.current[id]?.focus();\n }\n\n // The row is gone: focus goes to the next row's button, or the one before it when it was the last.\n // With no such row left, it goes to 'Invite Member'.\n function focusAfterRemoving(ids: string[], id: string) {\n const at = ids.indexOf(id);\n const neighbor = ids[at + 1] ?? ids[at - 1];\n focusNext.current = () => (neighbor ? rowButtons.current[neighbor] : inviteButton.current)?.focus();\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n // Only other people's rows have Remove, in the order they show\n const removable = sorted.filter((m) => m.id !== youId).map((m) => m.id);\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n focusAfterRemoving(removable, member.id);\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n const shown = invites.map((i) => i.id);\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n focusAfterRemoving(shown, invite.id);\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button ref={inviteButton} size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer aria-label=\"Members\" minWidth=\"720px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell sort={sort.by === 'name' ? sort.dir : undefined}>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\" sort={sort.by === 'role' ? sort.dir : undefined}>{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button ref={cancelConfirm} size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => cancelConfirmOn(m.id)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button ref={(el) => { rowButtons.current[m.id] = el; }} size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer aria-label=\"Pending invites\" minWidth=\"720px\">\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button ref={cancelConfirm} size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => cancelConfirmOn(i.id)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button ref={(el) => { rowButtons.current[i.id] = el; }} size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for {formatMoney(8)} per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
4239
4241
  "uses": [
4240
4242
  "Alert",
4241
4243
  "Button",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oneslash-design-system",
3
3
  "description": "A design system for the Oneslash projects",
4
- "version": "2.28.0",
4
+ "version": "2.28.1",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "./dist/index.js",