oneslash-design-system 2.27.1 → 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.
@@ -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",
@@ -2436,7 +2437,7 @@
2436
2437
  "Pass `min` or `max` as an ISO day when only some days can be chosen. Days outside them cannot be picked in the calendar.",
2437
2438
  "Let the field say why a date cannot be used: 'Choose Nov 16, 2026 or later.' for a day before `min`, and 'Choose Dec 31, 2026 or earlier.' for a day after `max`.",
2438
2439
  "Let the field say how to fix a date that is not real, such as '02/30/2026': 'Enter a real date as MM/DD/YYYY.' A two-digit year says 'Enter the year in four digits, like 2026.'",
2439
- "Name the format in the helper text, and say what an empty field means: 'MM/DD/YYYY. Leave empty for no end date.'",
2440
+ "Name the format in the helper text, and say what an empty field means: 'MM/DD/YYYY, or empty for no end date.'",
2440
2441
  "Pass `calendar={false}` for a date years away, such as a date of birth. Paging a calendar back 30 years takes too long.",
2441
2442
  "Read the second argument of `onChange`: `''` with `error: null` is an empty field, and `''` with an error is a date typed wrong. Do not submit while `error` is set. The field already shows why under itself.",
2442
2443
  "Treat an empty optional date as no date, such as no end date for a token.",
@@ -2457,7 +2458,7 @@
2457
2458
  "id": "calendar",
2458
2459
  "title": "Typed or picked from a calendar",
2459
2460
  "useWhen": "The date is near today and the person picks it, such as when a token expires.",
2460
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport DateField from 'oneslash-design-system/components/dateField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// In an app, these fields sit in the 'Create Key' Modal of the case 'API keys'.\n// \"Today\" in this example. A real app passes its own today as `min`, as 'YYYY-MM-DD'.\nconst today = '2026-11-16';\n// The token the server made. A real app gets it once, in the reply to the create request.\nconst madeToken = 'acme_tok_9Rk2vQ7mXa4LwT8cZp1Hd6Ns';\n\nconst months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n// '2026-12-16' as 'Dec 16, 2026', for the line under the new token\nfunction formatDay(day: string) {\n const [year, month, date] = day.split('-').map(Number);\n return `${months[month - 1]} ${date}, ${year}`;\n}\n\nexport default function DateFieldCalendar() {\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n // The day as 'YYYY-MM-DD', or '' for no end date\n const [expires, setExpires] = useState('');\n // The field's own message for a date typed wrong. While it is set, the token is not created.\n const [expiresError, setExpiresError] = useState<string | null>(null);\n const [creating, setCreating] = useState(false);\n const [made, setMade] = useState<{ name: string; expires: string } | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleCreate() {\n if (creating) return;\n setNameError(name.trim() ? '' : 'Enter a name for the token.');\n // A date typed wrong shows its message under the field. An empty date means no end date.\n if (!name.trim() || expiresError) return;\n setCreating(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCreating(false);\n setMade({ name: name.trim(), expires });\n }, 1200);\n }\n\n function handleDone() {\n setMade(null);\n setName('');\n setExpires('');\n setExpiresError(null);\n }\n\n return (\n <Center width=\"form\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">New access token</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">A token lets a script use Acme as you until the day it expires.</Paragraph>\n </Stack>\n {made ? (\n <Stack gap=\"large\">\n <CopyField id=\"date-field-token\" label={made.name} value={madeToken} mono reveal=\"once\" />\n <Paragraph size=\"body2\" measure=\"none\">{made.expires ? `Expires ${formatDay(made.expires)}.` : 'Never expires.'}</Paragraph>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n </Cluster>\n </Stack>\n ) : (\n <Form aria-label=\"New access token\" gap=\"large\" onSubmit={handleCreate}>\n <FormField id=\"date-field-name\" label=\"Name\" help=\"Say what will use it, such as Deploy script.\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={creating}\n autoComplete=\"off\"\n onChange={(e) => { setName(e.target.value); setNameError(''); }}\n />\n )}\n </FormField>\n {/* Typed as MM/DD/YYYY or picked from the calendar. A day before today says 'Choose Nov 16, 2026 or later.'\n The second argument of onChange tells an empty field (no error) from a date typed wrong. */}\n <DateField\n id=\"date-field-expires\"\n label=\"Expires on\"\n value={expires}\n onChange={(day, detail) => { setExpires(day); setExpiresError(detail.error); }}\n min={today}\n disabled={creating}\n helperText=\"MM/DD/YYYY. Leave empty for no end date.\"\n />\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Create Token\" htmlType=\"submit\" loading={creating} />\n </Cluster>\n </Form>\n )}\n </Stack>\n </Center>\n );\n}\n",
2461
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport DateField from 'oneslash-design-system/components/dateField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// In an app, these fields sit in the 'Create Key' Modal of the case 'API keys'.\n// \"Today\" in this example. A real app passes its own today as `min`, as 'YYYY-MM-DD'.\nconst today = '2026-11-16';\n// The token the server made. A real app gets it once, in the reply to the create request.\nconst madeToken = 'acme_tok_9Rk2vQ7mXa4LwT8cZp1Hd6Ns';\n\nconst months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n// '2026-12-16' as 'Dec 16, 2026', for the line under the new token\nfunction formatDay(day: string) {\n const [year, month, date] = day.split('-').map(Number);\n return `${months[month - 1]} ${date}, ${year}`;\n}\n\nexport default function DateFieldCalendar() {\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n // The day as 'YYYY-MM-DD', or '' for no end date\n const [expires, setExpires] = useState('');\n // The field's own message for a date typed wrong. While it is set, the token is not created.\n const [expiresError, setExpiresError] = useState<string | null>(null);\n const [creating, setCreating] = useState(false);\n const [made, setMade] = useState<{ name: string; expires: string } | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n function handleCreate() {\n if (creating) return;\n setNameError(name.trim() ? '' : 'Enter a name for the token.');\n // A date typed wrong shows its message under the field. An empty date means no end date.\n if (!name.trim() || expiresError) return;\n setCreating(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setCreating(false);\n setMade({ name: name.trim(), expires });\n }, 1200);\n }\n\n function handleDone() {\n setMade(null);\n setName('');\n setExpires('');\n setExpiresError(null);\n }\n\n return (\n <Center width=\"form\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">New access token</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">A token lets a script use Acme as you until the day it expires.</Paragraph>\n </Stack>\n {made ? (\n <Stack gap=\"large\">\n <CopyField id=\"date-field-token\" label={made.name} value={madeToken} mono reveal=\"once\" />\n <Paragraph size=\"body2\" measure=\"none\">{made.expires ? `Expires ${formatDay(made.expires)}.` : 'Never expires.'}</Paragraph>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n </Cluster>\n </Stack>\n ) : (\n <Form aria-label=\"New access token\" gap=\"large\" onSubmit={handleCreate}>\n <FormField id=\"date-field-name\" label=\"Name\" help=\"Say what will use it, such as Deploy script.\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={creating}\n autoComplete=\"off\"\n onChange={(e) => { setName(e.target.value); setNameError(''); }}\n />\n )}\n </FormField>\n {/* Typed as MM/DD/YYYY or picked from the calendar. A day before today says 'Choose Nov 16, 2026 or later.'\n The second argument of onChange tells an empty field (no error) from a date typed wrong. */}\n <DateField\n id=\"date-field-expires\"\n label=\"Expires on\"\n value={expires}\n onChange={(day, detail) => { setExpires(day); setExpiresError(detail.error); }}\n min={today}\n disabled={creating}\n helperText=\"MM/DD/YYYY, or empty for no end date.\"\n />\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Create Token\" htmlType=\"submit\" loading={creating} />\n </Cluster>\n </Form>\n )}\n </Stack>\n </Center>\n );\n}\n",
2461
2462
  "uses": [
2462
2463
  "Button",
2463
2464
  "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",