@microbit/ui 0.1.0-alpha.3 → 0.1.0-alpha.5
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/LICENSE.md +32 -0
- package/README.md +104 -15
- package/lang/ui.de.json +22 -0
- package/lang/ui.ga-ie.json +22 -0
- package/lang/ui.zh-cn.json +22 -0
- package/package.json +6 -4
- package/postcss-legacy-safari.cjs +96 -0
- package/src/Code.tsx +20 -0
- package/src/Collapse.tsx +168 -0
- package/src/Divider.tsx +39 -8
- package/src/Fade.tsx +48 -0
- package/src/IconButton.tsx +6 -1
- package/src/Kbd.tsx +26 -0
- package/src/List.tsx +7 -3
- package/src/Menu.recipe.ts +32 -1
- package/src/Menu.tsx +89 -0
- package/src/Modal.tsx +15 -1
- package/src/NumberField.recipe.ts +67 -0
- package/src/NumberField.tsx +86 -0
- package/src/PopoverArrow.tsx +18 -3
- package/src/Slider.tsx +64 -0
- package/src/TextField.tsx +17 -2
- package/src/Toast.tsx +7 -1
- package/src/base-preset.ts +5 -3
- package/src/{chakra-tokens.ts → base-tokens.ts} +7 -4
- package/src/hooks/useClipboard.ts +27 -0
- package/src/hooks/useMediaQuery.ts +28 -0
- package/src/hooks/usePrevious.ts +18 -0
- package/src/index.ts +8 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
3
|
*
|
|
4
|
+
* Token values (c) 2019, Segun Adebayo — Chakra UI's @chakra-ui/theme
|
|
5
|
+
* defaults, used under the MIT License (see LICENSE.md third-party notices).
|
|
6
|
+
*
|
|
4
7
|
* SPDX-License-Identifier: MIT
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
9
|
+
// The base token scales, in Panda token format. Began as a mechanical
|
|
10
|
+
// snapshot of Chakra UI v2's @chakra-ui/theme defaults; hand-maintained.
|
|
11
|
+
// Deliberately absent: `fonts` (foundation-owned, defined in base-preset.ts)
|
|
12
|
+
// and `transition.property` (no Panda token category; inlined at use sites).
|
|
10
13
|
|
|
11
14
|
export const colors = {
|
|
12
15
|
transparent: {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Copy a value to the clipboard with a transient `hasCopied` flag for
|
|
10
|
+
* "Copied!" feedback. Replaces Chakra's `useClipboard`.
|
|
11
|
+
*/
|
|
12
|
+
export function useClipboard(
|
|
13
|
+
value: string,
|
|
14
|
+
timeoutMs = 1500,
|
|
15
|
+
): { onCopy: () => void; hasCopied: boolean } {
|
|
16
|
+
const [hasCopied, setHasCopied] = useState(false);
|
|
17
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
|
18
|
+
const onCopy = useCallback(() => {
|
|
19
|
+
navigator.clipboard.writeText(value).then(() => {
|
|
20
|
+
setHasCopied(true);
|
|
21
|
+
clearTimeout(timeoutRef.current);
|
|
22
|
+
timeoutRef.current = setTimeout(() => setHasCopied(false), timeoutMs);
|
|
23
|
+
});
|
|
24
|
+
}, [value, timeoutMs]);
|
|
25
|
+
useEffect(() => () => clearTimeout(timeoutRef.current), []);
|
|
26
|
+
return { onCopy, hasCopied };
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tracks a raw CSS media query, replacing Chakra's `useMediaQuery` for
|
|
10
|
+
* queries that aren't breakpoint-based (custom widths, height-based
|
|
11
|
+
* queries). For the preset's breakpoint scale prefer `useBreakpointValue`.
|
|
12
|
+
* Returns false during SSR.
|
|
13
|
+
*/
|
|
14
|
+
export function useMediaQuery(query: string): boolean {
|
|
15
|
+
const subscribe = useCallback(
|
|
16
|
+
(onChange: () => void) => {
|
|
17
|
+
const list = window.matchMedia(query);
|
|
18
|
+
list.addEventListener("change", onChange);
|
|
19
|
+
return () => list.removeEventListener("change", onChange);
|
|
20
|
+
},
|
|
21
|
+
[query],
|
|
22
|
+
);
|
|
23
|
+
return useSyncExternalStore(
|
|
24
|
+
subscribe,
|
|
25
|
+
() => window.matchMedia(query).matches,
|
|
26
|
+
() => false,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The value from the previous render (undefined on the first render).
|
|
10
|
+
* Replaces Chakra's `usePrevious`.
|
|
11
|
+
*/
|
|
12
|
+
export function usePrevious<T>(value: T): T | undefined {
|
|
13
|
+
const ref = useRef<T>();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
ref.current = value;
|
|
16
|
+
});
|
|
17
|
+
return ref.current;
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from "./Input";
|
|
|
19
19
|
export * from "./InputGroup";
|
|
20
20
|
export * from "./LinkBox";
|
|
21
21
|
export * from "./NativeSelect";
|
|
22
|
+
export * from "./NumberField";
|
|
22
23
|
export * from "./ProgressBar";
|
|
23
24
|
export * from "./Slide";
|
|
24
25
|
export * from "./Slider";
|
|
@@ -32,6 +33,10 @@ export * from "./Link";
|
|
|
32
33
|
export * from "./Icon";
|
|
33
34
|
export * from "./CloseButton";
|
|
34
35
|
export * from "./CloseIcon";
|
|
36
|
+
export * from "./Code";
|
|
37
|
+
export * from "./Collapse";
|
|
38
|
+
export * from "./Fade";
|
|
39
|
+
export * from "./Kbd";
|
|
35
40
|
export * from "./Divider";
|
|
36
41
|
export * from "./Drawer";
|
|
37
42
|
export * from "./List";
|
|
@@ -43,3 +48,6 @@ export * from "./Tooltip";
|
|
|
43
48
|
export * from "./Toast";
|
|
44
49
|
export * from "./VisuallyHidden";
|
|
45
50
|
export { useBreakpointValue } from "./hooks/useBreakpointValue";
|
|
51
|
+
export { useClipboard } from "./hooks/useClipboard";
|
|
52
|
+
export { useMediaQuery } from "./hooks/useMediaQuery";
|
|
53
|
+
export { usePrevious } from "./hooks/usePrevious";
|