@microbit/ui 0.1.0-alpha.3

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.
Files changed (67) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +118 -0
  3. package/lang/ui.ca.json +22 -0
  4. package/lang/ui.en-us.json +22 -0
  5. package/lang/ui.en.json +22 -0
  6. package/lang/ui.es-es.json +22 -0
  7. package/lang/ui.fr.json +22 -0
  8. package/lang/ui.ja.json +22 -0
  9. package/lang/ui.ko.json +22 -0
  10. package/lang/ui.lol.json +22 -0
  11. package/lang/ui.nl.json +22 -0
  12. package/lang/ui.pl.json +22 -0
  13. package/lang/ui.pt-br.json +22 -0
  14. package/lang/ui.zh-tw.json +22 -0
  15. package/package.json +54 -0
  16. package/src/Button.recipe.ts +162 -0
  17. package/src/Button.tsx +84 -0
  18. package/src/ButtonGroup.tsx +63 -0
  19. package/src/Card.recipe.ts +49 -0
  20. package/src/Card.tsx +56 -0
  21. package/src/Checkbox.recipe.ts +71 -0
  22. package/src/Checkbox.tsx +66 -0
  23. package/src/CloseButton.tsx +87 -0
  24. package/src/CloseIcon.tsx +40 -0
  25. package/src/Divider.tsx +21 -0
  26. package/src/Drawer.recipe.ts +98 -0
  27. package/src/Drawer.tsx +138 -0
  28. package/src/Heading.recipe.ts +52 -0
  29. package/src/Heading.tsx +14 -0
  30. package/src/Icon.tsx +55 -0
  31. package/src/IconButton.tsx +39 -0
  32. package/src/Image.tsx +11 -0
  33. package/src/Input.recipe.ts +63 -0
  34. package/src/Input.tsx +33 -0
  35. package/src/InputGroup.tsx +48 -0
  36. package/src/Link.tsx +23 -0
  37. package/src/LinkBox.tsx +88 -0
  38. package/src/List.tsx +27 -0
  39. package/src/Menu.recipe.ts +88 -0
  40. package/src/Menu.tsx +172 -0
  41. package/src/Modal.recipe.ts +163 -0
  42. package/src/Modal.tsx +265 -0
  43. package/src/NativeSelect.tsx +76 -0
  44. package/src/PopoverArrow.tsx +52 -0
  45. package/src/ProgressBar.tsx +61 -0
  46. package/src/SharedUIProvider.tsx +55 -0
  47. package/src/Slide.tsx +54 -0
  48. package/src/Slider.recipe.ts +91 -0
  49. package/src/Slider.tsx +99 -0
  50. package/src/Spinner.tsx +69 -0
  51. package/src/Svg.tsx +23 -0
  52. package/src/Switch.recipe.ts +80 -0
  53. package/src/Switch.tsx +60 -0
  54. package/src/Text.tsx +12 -0
  55. package/src/TextField.recipe.ts +54 -0
  56. package/src/TextField.tsx +72 -0
  57. package/src/Toast.recipe.ts +98 -0
  58. package/src/Toast.tsx +165 -0
  59. package/src/Tooltip.tsx +91 -0
  60. package/src/UnmountCallback.tsx +18 -0
  61. package/src/VisuallyHidden.tsx +14 -0
  62. package/src/base-preset.ts +278 -0
  63. package/src/chakra-tokens.ts +1014 -0
  64. package/src/hooks/useBreakpointValue.ts +63 -0
  65. package/src/index.ts +45 -0
  66. package/src/messages.ts +17 -0
  67. package/src/system.ts +36 -0
@@ -0,0 +1,63 @@
1
+ /**
2
+ * (c) 2026, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { useEffect, useState } from "react";
7
+ import { token } from "styled-system/tokens";
8
+
9
+ // Min-width breakpoints from the preset's token scale (runtime lookup so the
10
+ // hook tracks any preset override rather than duplicating the values).
11
+ const BREAKPOINTS = {
12
+ sm: token("breakpoints.sm"),
13
+ md: token("breakpoints.md"),
14
+ lg: token("breakpoints.lg"),
15
+ xl: token("breakpoints.xl"),
16
+ "2xl": token("breakpoints.2xl"),
17
+ } as const;
18
+
19
+ type Breakpoint = "base" | keyof typeof BREAKPOINTS;
20
+
21
+ const ORDER: Breakpoint[] = ["base", "sm", "md", "lg", "xl", "2xl"];
22
+
23
+ const activeBreakpoint = (): Breakpoint => {
24
+ let current: Breakpoint = "base";
25
+ for (const [name, min] of Object.entries(BREAKPOINTS)) {
26
+ if (window.matchMedia(`(min-width: ${min})`).matches) {
27
+ current = name as Breakpoint;
28
+ }
29
+ }
30
+ return current;
31
+ };
32
+
33
+ /**
34
+ * JS-side responsive value resolver, replacing Chakra's `useBreakpointValue`.
35
+ * Panda handles responsive *styles* in CSS; this is for responsive *logic*
36
+ * (choosing a prop value, branching behaviour). Resolves to the value at the
37
+ * active breakpoint, falling back to the nearest smaller one that is defined.
38
+ */
39
+ export function useBreakpointValue<T>(
40
+ values: Partial<Record<Breakpoint, T>>,
41
+ ): T | undefined {
42
+ const [bp, setBp] = useState<Breakpoint>(() =>
43
+ typeof window === "undefined" ? "base" : activeBreakpoint(),
44
+ );
45
+
46
+ useEffect(() => {
47
+ const update = () => setBp(activeBreakpoint());
48
+ update();
49
+ const lists = Object.values(BREAKPOINTS).map((min) =>
50
+ window.matchMedia(`(min-width: ${min})`),
51
+ );
52
+ lists.forEach((l) => l.addEventListener("change", update));
53
+ return () => lists.forEach((l) => l.removeEventListener("change", update));
54
+ }, []);
55
+
56
+ for (let i = ORDER.indexOf(bp); i >= 0; i--) {
57
+ const value = values[ORDER[i]];
58
+ if (value !== undefined) {
59
+ return value;
60
+ }
61
+ }
62
+ return undefined;
63
+ }
package/src/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * (c) 2026, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ /**
7
+ * shared-ui — react-aria-components + Panda CSS primitives replacing Chakra,
8
+ * designed to be extracted into a library shared across sibling apps. Visuals
9
+ * match the Chakra theme; behaviour follows react-aria patterns.
10
+ */
11
+ export * from "./system";
12
+ export * from "./Button";
13
+ export * from "./ButtonGroup";
14
+ export * from "./Card";
15
+ export * from "./Checkbox";
16
+ export * from "./IconButton";
17
+ export * from "./Image";
18
+ export * from "./Input";
19
+ export * from "./InputGroup";
20
+ export * from "./LinkBox";
21
+ export * from "./NativeSelect";
22
+ export * from "./ProgressBar";
23
+ export * from "./Slide";
24
+ export * from "./Slider";
25
+ export * from "./Spinner";
26
+ export * from "./Svg";
27
+ export * from "./Switch";
28
+ export * from "./Text";
29
+ export * from "./TextField";
30
+ export * from "./Heading";
31
+ export * from "./Link";
32
+ export * from "./Icon";
33
+ export * from "./CloseButton";
34
+ export * from "./CloseIcon";
35
+ export * from "./Divider";
36
+ export * from "./Drawer";
37
+ export * from "./List";
38
+ export * from "./Menu";
39
+ export * from "./Modal";
40
+ export * from "./PopoverArrow";
41
+ export * from "./SharedUIProvider";
42
+ export * from "./Tooltip";
43
+ export * from "./Toast";
44
+ export * from "./VisuallyHidden";
45
+ export { useBreakpointValue } from "./hooks/useBreakpointValue";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * (c) 2026, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import en from "../lang/ui.en.json";
7
+
8
+ /**
9
+ * Descriptor for one of this package's messages. The English text rides along
10
+ * as defaultMessage so components render English without any catalog merging;
11
+ * for other locales apps compile lang/ui.<locale>.json into their per-locale
12
+ * catalogs (see README "Strings").
13
+ */
14
+ export const uiMessage = (id: keyof typeof en) => ({
15
+ id,
16
+ defaultMessage: en[id].defaultMessage,
17
+ });
package/src/system.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * (c) 2026, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ /**
7
+ * Stable re-export of the Panda styling primitives and layout patterns, so
8
+ * shared-ui consumers (and a future extracted library) import from one place
9
+ * rather than reaching into the generated `styled-system` directly.
10
+ */
11
+ export { css, cva, sva, cx } from "styled-system/css";
12
+ export { token } from "styled-system/tokens";
13
+ export type { SystemStyleObject } from "styled-system/types";
14
+ export type {
15
+ BoxProps,
16
+ FlexProps,
17
+ StackProps,
18
+ HstackProps,
19
+ VstackProps,
20
+ GridProps,
21
+ } from "styled-system/jsx";
22
+
23
+ // Layout patterns — the Panda-native equivalents of Chakra's Box/Flex/Stack/etc.
24
+ export {
25
+ AspectRatio,
26
+ Box,
27
+ Flex,
28
+ Stack,
29
+ HStack,
30
+ VStack,
31
+ Grid,
32
+ GridItem,
33
+ Center,
34
+ Wrap,
35
+ styled,
36
+ } from "styled-system/jsx";