@microbit/ui 0.1.0-alpha.5 → 0.1.0-alpha.6
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/package.json +1 -1
- package/src/Button.tsx +2 -17
- package/src/LinkButton.tsx +80 -0
- package/src/base-preset.ts +10 -7
- package/src/button-icon.ts +23 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microbit/ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
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
6
|
"type": "module",
|
package/src/Button.tsx
CHANGED
|
@@ -8,25 +8,10 @@ import {
|
|
|
8
8
|
Button as RACButton,
|
|
9
9
|
ButtonProps as RACButtonProps,
|
|
10
10
|
} from "react-aria-components";
|
|
11
|
-
import { css,
|
|
11
|
+
import { css, cx } from "styled-system/css";
|
|
12
12
|
import { button, ButtonVariantProps } from "styled-system/recipes";
|
|
13
13
|
import { SystemStyleObject } from "styled-system/types";
|
|
14
|
-
|
|
15
|
-
// Chakra's ButtonIcon: keeps the glyph centred and spaced from the label
|
|
16
|
-
// (iconSpacing 0.5rem).
|
|
17
|
-
const buttonIcon = cva({
|
|
18
|
-
base: {
|
|
19
|
-
display: "inline-flex",
|
|
20
|
-
alignSelf: "center",
|
|
21
|
-
flexShrink: 0,
|
|
22
|
-
},
|
|
23
|
-
variants: {
|
|
24
|
-
side: {
|
|
25
|
-
left: { marginEnd: "2" },
|
|
26
|
-
right: { marginStart: "2" },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
});
|
|
14
|
+
import { buttonIcon } from "./button-icon";
|
|
30
15
|
|
|
31
16
|
export interface ButtonProps
|
|
32
17
|
extends Omit<RACButtonProps, "className" | "children">,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { forwardRef, ReactNode } from "react";
|
|
7
|
+
import {
|
|
8
|
+
Link as RACLink,
|
|
9
|
+
LinkProps as RACLinkProps,
|
|
10
|
+
} from "react-aria-components";
|
|
11
|
+
import { css, cx } from "styled-system/css";
|
|
12
|
+
import { button, ButtonVariantProps } from "styled-system/recipes";
|
|
13
|
+
import { SystemStyleObject } from "styled-system/types";
|
|
14
|
+
import { buttonIcon } from "./button-icon";
|
|
15
|
+
|
|
16
|
+
export interface LinkButtonProps
|
|
17
|
+
extends Omit<RACLinkProps, "className" | "children">,
|
|
18
|
+
ButtonVariantProps {
|
|
19
|
+
/** Per-instance style overrides, merged after the recipe. */
|
|
20
|
+
css?: SystemStyleObject;
|
|
21
|
+
className?: string;
|
|
22
|
+
/** Icon rendered before the label, matching Chakra's `leftIcon`. */
|
|
23
|
+
leftIcon?: ReactNode;
|
|
24
|
+
/** Icon rendered after the label, matching Chakra's `rightIcon`. */
|
|
25
|
+
rightIcon?: ReactNode;
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Anchors pick up underline styling that buttons never have.
|
|
30
|
+
const linkReset = css.raw({
|
|
31
|
+
textDecoration: "none",
|
|
32
|
+
_hover: { textDecoration: "none" },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* LinkButton — a navigation link that looks like a Button (Chakra's
|
|
37
|
+
* `Button as="a"`). react-aria-components <Link> renders a real anchor
|
|
38
|
+
* (`href`, `target`, new-tab/middle-click semantics preserved) with the same
|
|
39
|
+
* interaction data attributes as Button, so the `button` recipe's
|
|
40
|
+
* hover/press/focus/disabled states apply unchanged.
|
|
41
|
+
*
|
|
42
|
+
* Use for navigation that should read as a call to action (e.g. an external
|
|
43
|
+
* help page presented as a dialog's primary action); use Button for
|
|
44
|
+
* in-page actions.
|
|
45
|
+
*/
|
|
46
|
+
export const LinkButton = forwardRef<HTMLAnchorElement, LinkButtonProps>(
|
|
47
|
+
function LinkButton(
|
|
48
|
+
{
|
|
49
|
+
variant,
|
|
50
|
+
size,
|
|
51
|
+
css: cssProp,
|
|
52
|
+
className,
|
|
53
|
+
leftIcon,
|
|
54
|
+
rightIcon,
|
|
55
|
+
children,
|
|
56
|
+
...rest
|
|
57
|
+
},
|
|
58
|
+
ref,
|
|
59
|
+
) {
|
|
60
|
+
return (
|
|
61
|
+
<RACLink
|
|
62
|
+
ref={ref}
|
|
63
|
+
className={cx(
|
|
64
|
+
button({ variant, size }),
|
|
65
|
+
css(linkReset, cssProp),
|
|
66
|
+
className,
|
|
67
|
+
)}
|
|
68
|
+
{...rest}
|
|
69
|
+
>
|
|
70
|
+
{leftIcon ? (
|
|
71
|
+
<span className={buttonIcon({ side: "left" })}>{leftIcon}</span>
|
|
72
|
+
) : null}
|
|
73
|
+
{children}
|
|
74
|
+
{rightIcon ? (
|
|
75
|
+
<span className={buttonIcon({ side: "right" })}>{rightIcon}</span>
|
|
76
|
+
) : null}
|
|
77
|
+
</RACLink>
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
);
|
package/src/base-preset.ts
CHANGED
|
@@ -146,13 +146,16 @@ export const basePreset = definePreset({
|
|
|
146
146
|
600: { value: "{colors.red.600}" },
|
|
147
147
|
700: { value: "{colors.red.700}" },
|
|
148
148
|
},
|
|
149
|
-
// The `language` button variant's text colour
|
|
150
|
-
//
|
|
151
|
-
// CreateAI
|
|
152
|
-
//
|
|
153
|
-
// overrides only
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
// The `language` button variant's text colour follows the primary
|
|
150
|
+
// interactive brand: every consumer resolves it to its `brand` ramp
|
|
151
|
+
// (CreateAI privately to brand.600 with no hover change,
|
|
152
|
+
// python-editor to brand.500/600 — the default). Semantic tokens so
|
|
153
|
+
// the recipe stays shared and a brand preset overrides only values.
|
|
154
|
+
// (Was brand2.* — the grey ml-trainer OSS Chakra look — but both
|
|
155
|
+
// apps' final values sit on their primary brand, so the default
|
|
156
|
+
// follows; OSS language buttons are brand blue.)
|
|
157
|
+
languageText: { value: "{colors.brand.500}" },
|
|
158
|
+
languageTextHover: { value: "{colors.brand.600}" },
|
|
156
159
|
// Toast status colours: the Chakra-era toast Alert restyle (teal for
|
|
157
160
|
// every status except error) shared across the app family.
|
|
158
161
|
toastInfoBg: { value: "{colors.teal.800}" },
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { cva } from "styled-system/css";
|
|
7
|
+
|
|
8
|
+
// Chakra's ButtonIcon: keeps the glyph centred and spaced from the label
|
|
9
|
+
// (iconSpacing 0.5rem). Shared by Button and LinkButton; deliberately not
|
|
10
|
+
// exported from the package index.
|
|
11
|
+
export const buttonIcon = cva({
|
|
12
|
+
base: {
|
|
13
|
+
display: "inline-flex",
|
|
14
|
+
alignSelf: "center",
|
|
15
|
+
flexShrink: 0,
|
|
16
|
+
},
|
|
17
|
+
variants: {
|
|
18
|
+
side: {
|
|
19
|
+
left: { marginEnd: "2" },
|
|
20
|
+
right: { marginStart: "2" },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|