@microbit/ui 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lang/ui.en.json CHANGED
@@ -3,6 +3,10 @@
3
3
  "defaultMessage": "Breadcrumb",
4
4
  "description": "Accessible label for the breadcrumb navigation trail (the WAI-ARIA APG's conventional name)"
5
5
  },
6
+ "ui.cancel-action": {
7
+ "defaultMessage": "Cancel",
8
+ "description": "Cancel button in dialogs"
9
+ },
6
10
  "ui.close-action": {
7
11
  "defaultMessage": "Close",
8
12
  "description": "Close button text or label"
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@microbit/ui",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "micro:bit design-system primitives: react-aria-components + Panda CSS with a design language ported from Chakra UI v2. Ships as source; see README for the consumption setup.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/microbit-foundation/ui.git",
9
+ "directory": "packages/ui"
10
+ },
6
11
  "type": "module",
7
12
  "exports": {
8
13
  ".": "./src/index.ts",
@@ -0,0 +1,66 @@
1
+ /**
2
+ * (c) 2026, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { ReactNode, RefObject } from "react";
7
+ import { FormattedMessage } from "react-intl";
8
+ import { Button } from "./Button";
9
+ import { uiMessage } from "./messages";
10
+ import { Modal, ModalBody, ModalFooter, ModalHeader } from "./Modal";
11
+
12
+ export interface ConfirmDialogProps {
13
+ isOpen: boolean;
14
+ heading: ReactNode;
15
+ body: ReactNode;
16
+ onConfirm: () => void;
17
+ onCancel: () => void;
18
+ /**
19
+ * The verb for what confirming does ("Delete", "Reset"). Required: there
20
+ * is always a better label than "Confirm".
21
+ */
22
+ confirmText: ReactNode;
23
+ /** Defaults to "Cancel". */
24
+ cancelText?: ReactNode;
25
+ finalFocusRef?: RefObject<HTMLElement>;
26
+ onCloseComplete?: () => void;
27
+ }
28
+
29
+ /**
30
+ * An alert dialog for a destructive action. Cancel takes initial focus, as
31
+ * the least destructive choice, and confirm is styled as dangerous.
32
+ */
33
+ export const ConfirmDialog = ({
34
+ isOpen,
35
+ heading,
36
+ body,
37
+ onConfirm,
38
+ onCancel,
39
+ confirmText,
40
+ cancelText,
41
+ finalFocusRef,
42
+ onCloseComplete,
43
+ }: ConfirmDialogProps) => (
44
+ <Modal
45
+ isOpen={isOpen}
46
+ onClose={onCancel}
47
+ role="alertdialog"
48
+ size="md"
49
+ isCentered
50
+ finalFocusRef={finalFocusRef}
51
+ onCloseComplete={onCloseComplete}
52
+ >
53
+ <ModalHeader css={{ fontWeight: "bold", lineHeight: 1.2 }}>
54
+ {heading}
55
+ </ModalHeader>
56
+ <ModalBody>{body}</ModalBody>
57
+ <ModalFooter css={{ gap: 3 }}>
58
+ <Button autoFocus onPress={onCancel}>
59
+ {cancelText ?? <FormattedMessage {...uiMessage("ui.cancel-action")} />}
60
+ </Button>
61
+ <Button variant="solid" tone="danger" onPress={onConfirm}>
62
+ {confirmText}
63
+ </Button>
64
+ </ModalFooter>
65
+ </Modal>
66
+ );
package/src/index.ts CHANGED
@@ -57,6 +57,7 @@ export * from "./ListBox";
57
57
  export * from "./ComboBox";
58
58
  export * from "./Menu";
59
59
  export * from "./Modal";
60
+ export * from "./ConfirmDialog";
60
61
  export * from "./PopoverArrow";
61
62
  export * from "./SharedUIProvider";
62
63
  export * from "./Tooltip";