@microbit/ui 0.1.0-alpha.3 → 0.1.0-alpha.31
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 +40 -0
- package/README.md +279 -26
- package/lang/ui.ar.json +62 -0
- package/lang/ui.ca.json +43 -3
- package/lang/ui.cy.json +62 -0
- package/lang/ui.de.json +62 -0
- package/lang/ui.en-us.json +40 -0
- package/lang/ui.en.json +40 -0
- package/lang/ui.es-es.json +43 -3
- package/lang/ui.fr.json +44 -4
- package/lang/ui.ga-ie.json +62 -0
- package/lang/ui.it.json +62 -0
- package/lang/ui.ja.json +44 -4
- package/lang/ui.ko.json +44 -4
- package/lang/ui.lo.json +62 -0
- package/lang/ui.lol.json +40 -0
- package/lang/ui.nl.json +44 -4
- package/lang/ui.pl.json +44 -4
- package/lang/ui.pt-br.json +44 -4
- package/lang/ui.vi.json +62 -0
- package/lang/ui.zh-cn.json +62 -0
- package/lang/ui.zh-tw.json +44 -4
- package/package.json +19 -10
- package/postcss-legacy-safari.cjs +96 -0
- package/reset.css +35 -0
- package/src/Avatar.recipe.ts +191 -0
- package/src/Avatar.tsx +278 -0
- package/src/Breadcrumb.recipe.ts +45 -0
- package/src/Breadcrumb.tsx +114 -0
- package/src/Button.recipe.ts +88 -50
- package/src/Button.tsx +68 -30
- package/src/ButtonGroup.tsx +37 -15
- package/src/Card.recipe.ts +1 -2
- package/src/Card.tsx +2 -1
- package/src/Checkbox.recipe.ts +49 -14
- package/src/Checkbox.tsx +111 -32
- package/src/CheckboxGroup.tsx +70 -0
- package/src/CloseButton.tsx +3 -3
- package/src/CloseIcon.tsx +6 -4
- package/src/Code.tsx +20 -0
- package/src/Collapse.tsx +179 -0
- package/src/ComboBox.tsx +246 -0
- package/src/Divider.tsx +72 -8
- package/src/Drawer.recipe.ts +21 -10
- package/src/Drawer.tsx +3 -4
- package/src/ExternalLink.tsx +43 -0
- package/src/Fade.tsx +62 -0
- package/src/Field.recipe.ts +114 -0
- package/src/Field.tsx +187 -0
- package/src/GridList.recipe.ts +57 -0
- package/src/GridList.tsx +81 -0
- package/src/Heading.recipe.ts +20 -1
- package/src/Heading.tsx +3 -3
- package/src/Icon.tsx +23 -7
- package/src/IconButton.tsx +8 -13
- package/src/Image.tsx +1 -1
- package/src/Input.recipe.ts +41 -28
- package/src/Input.tsx +23 -7
- package/src/InputGroup.tsx +26 -12
- package/src/Kbd.tsx +26 -0
- package/src/Link.tsx +3 -3
- package/src/LinkBox.tsx +2 -3
- package/src/LinkButton.tsx +81 -0
- package/src/List.tsx +8 -6
- package/src/ListBox.recipe.ts +43 -0
- package/src/ListBox.tsx +88 -0
- package/src/Menu.recipe.ts +51 -17
- package/src/Menu.tsx +117 -2
- package/src/Modal.recipe.ts +17 -9
- package/src/Modal.tsx +137 -24
- package/src/MoreMenuButton.tsx +63 -0
- package/src/NativeSelect.tsx +41 -14
- package/src/NativeSelectField.tsx +84 -0
- package/src/NumberField.recipe.ts +108 -0
- package/src/NumberField.tsx +138 -0
- package/src/PopoverArrow.tsx +19 -5
- package/src/ProgressBar.tsx +3 -5
- package/src/Radio.recipe.ts +108 -0
- package/src/Radio.tsx +62 -0
- package/src/RadioGroup.tsx +68 -0
- package/src/Select.recipe.ts +211 -0
- package/src/Select.tsx +194 -0
- package/src/SharedUIProvider.tsx +63 -7
- package/src/Skeleton.tsx +146 -0
- package/src/Slide.tsx +2 -2
- package/src/Slider.recipe.ts +27 -16
- package/src/Slider.tsx +78 -6
- package/src/Spinner.tsx +11 -9
- package/src/Svg.tsx +2 -3
- package/src/Switch.recipe.ts +57 -11
- package/src/Switch.tsx +39 -7
- package/src/Text.recipe.ts +26 -0
- package/src/Text.tsx +6 -2
- package/src/TextField.tsx +54 -40
- package/src/Toast.recipe.ts +52 -15
- package/src/Toast.tsx +151 -46
- package/src/Tooltip.recipe.ts +32 -0
- package/src/Tooltip.tsx +68 -28
- package/src/TooltipButton.tsx +229 -0
- package/src/UnmountCallback.tsx +2 -2
- package/src/VisuallyHidden.tsx +1 -1
- package/src/base-preset.ts +336 -84
- package/src/{chakra-tokens.ts → base-tokens.ts} +7 -7
- package/src/button-icon.ts +22 -0
- package/src/data-attrs.ts +16 -0
- package/src/dense-preset.ts +107 -0
- package/src/hooks/useBreakpointValue.ts +4 -4
- package/src/hooks/useClipboard.ts +63 -0
- package/src/hooks/useDisclosure.ts +31 -0
- package/src/hooks/useMediaQuery.ts +27 -0
- package/src/hooks/usePrevious.ts +15 -0
- package/src/index.ts +29 -3
- package/src/rac-locale.ts +33 -0
- package/src/system.ts +22 -1
- package/src/TextField.recipe.ts +0 -54
package/src/InputGroup.tsx
CHANGED
|
@@ -7,8 +7,8 @@ import { styled } from "styled-system/jsx";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* InputGroup — relative wrapper for an Input with addon elements. Pad the
|
|
10
|
-
* input (`
|
|
11
|
-
*
|
|
10
|
+
* input (`ps`/`pe`) to make room for the elements; the elements sit on the
|
|
11
|
+
* reading-order sides, so physical padding lands opposite them in RTL.
|
|
12
12
|
*/
|
|
13
13
|
export const InputGroup = styled("div", {
|
|
14
14
|
base: { position: "relative", width: "100%", display: "flex" },
|
|
@@ -16,33 +16,47 @@ export const InputGroup = styled("div", {
|
|
|
16
16
|
|
|
17
17
|
// The element styles are written out twice rather than shared via a spread:
|
|
18
18
|
// Panda's extractor only reliably evaluates inline literals.
|
|
19
|
+
// The size variants are square boxes matching the input recipe's height per
|
|
20
|
+
// size; pass the same `size` as the grouped Input.
|
|
19
21
|
|
|
20
|
-
/** Element overlaying the start of an InputGroup
|
|
21
|
-
export const
|
|
22
|
+
/** Element overlaying the start of an InputGroup. */
|
|
23
|
+
export const InputStartElement = styled("div", {
|
|
22
24
|
base: {
|
|
23
25
|
position: "absolute",
|
|
24
26
|
top: 0,
|
|
25
|
-
|
|
26
|
-
width: "10",
|
|
27
|
-
height: "10",
|
|
27
|
+
insetStart: 0,
|
|
28
28
|
display: "flex",
|
|
29
29
|
alignItems: "center",
|
|
30
30
|
justifyContent: "center",
|
|
31
31
|
zIndex: 2,
|
|
32
32
|
},
|
|
33
|
+
variants: {
|
|
34
|
+
size: {
|
|
35
|
+
lg: { width: "12", height: "12" },
|
|
36
|
+
md: { width: "10", height: "10" },
|
|
37
|
+
sm: { width: "8", height: "8" },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: { size: "md" },
|
|
33
41
|
});
|
|
34
42
|
|
|
35
|
-
/** Element overlaying the end of an InputGroup
|
|
36
|
-
export const
|
|
43
|
+
/** Element overlaying the end of an InputGroup. */
|
|
44
|
+
export const InputEndElement = styled("div", {
|
|
37
45
|
base: {
|
|
38
46
|
position: "absolute",
|
|
39
47
|
top: 0,
|
|
40
|
-
|
|
41
|
-
width: "10",
|
|
42
|
-
height: "10",
|
|
48
|
+
insetEnd: 0,
|
|
43
49
|
display: "flex",
|
|
44
50
|
alignItems: "center",
|
|
45
51
|
justifyContent: "center",
|
|
46
52
|
zIndex: 2,
|
|
47
53
|
},
|
|
54
|
+
variants: {
|
|
55
|
+
size: {
|
|
56
|
+
lg: { width: "12", height: "12" },
|
|
57
|
+
md: { width: "10", height: "10" },
|
|
58
|
+
sm: { width: "8", height: "8" },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: { size: "md" },
|
|
48
62
|
});
|
package/src/Kbd.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { styled } from "styled-system/jsx";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Kbd — a keyboard-key chip (light mode).
|
|
10
|
+
*/
|
|
11
|
+
export const Kbd = styled("kbd", {
|
|
12
|
+
base: {
|
|
13
|
+
bg: "gray.100",
|
|
14
|
+
borderRadius: "md",
|
|
15
|
+
borderWidth: "1px",
|
|
16
|
+
borderStyle: "solid",
|
|
17
|
+
borderColor: "gray.200",
|
|
18
|
+
borderBottomWidth: "3px",
|
|
19
|
+
fontFamily: "mono",
|
|
20
|
+
fontSize: "0.8em",
|
|
21
|
+
fontWeight: "bold",
|
|
22
|
+
lineHeight: "normal",
|
|
23
|
+
px: "0.4em",
|
|
24
|
+
whiteSpace: "nowrap",
|
|
25
|
+
},
|
|
26
|
+
});
|
package/src/Link.tsx
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import { styled } from "styled-system/jsx";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Link —
|
|
10
|
-
* focus
|
|
9
|
+
* Link — a styled anchor (no underline until hover, focus ring on keyboard
|
|
10
|
+
* focus). Accepts Panda style props for colour etc.
|
|
11
11
|
*/
|
|
12
12
|
export const Link = styled("a", {
|
|
13
13
|
base: {
|
|
@@ -18,6 +18,6 @@ export const Link = styled("a", {
|
|
|
18
18
|
"background-color, border-color, color, fill, stroke, opacity, box-shadow, transform",
|
|
19
19
|
transitionDuration: "normal",
|
|
20
20
|
_hover: { textDecoration: "underline" },
|
|
21
|
-
_focusVisible: {
|
|
21
|
+
_focusVisible: { focusRing: "outline" },
|
|
22
22
|
},
|
|
23
23
|
});
|
package/src/LinkBox.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { SystemStyleObject } from "styled-system/types";
|
|
|
12
12
|
/**
|
|
13
13
|
* LinkBox — makes a whole box clickable via a nested LinkOverlay (or any
|
|
14
14
|
* element with an inset `_before` overlay). Other interactive children must
|
|
15
|
-
* be raised with `zIndex: 1`.
|
|
15
|
+
* be raised with `zIndex: 1`.
|
|
16
16
|
*/
|
|
17
17
|
export const LinkBox = styled("div", {
|
|
18
18
|
base: { position: "relative" },
|
|
@@ -54,8 +54,7 @@ export interface LinkOverlayButtonProps
|
|
|
54
54
|
* Deliberately a plain button, not a react-aria one: react-aria's usePress
|
|
55
55
|
* cancels presses that land outside the button's bounding rect, which defeats
|
|
56
56
|
* the overlay. `position: static` overrides the button recipe's base so the
|
|
57
|
-
* overlay anchors to the LinkBox
|
|
58
|
-
* Button).
|
|
57
|
+
* overlay anchors to the LinkBox.
|
|
59
58
|
*/
|
|
60
59
|
export const LinkOverlayButton = forwardRef<
|
|
61
60
|
HTMLButtonElement,
|
|
@@ -0,0 +1,81 @@
|
|
|
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. */
|
|
23
|
+
startIcon?: ReactNode;
|
|
24
|
+
/** Icon rendered after the label. */
|
|
25
|
+
endIcon?: 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.
|
|
37
|
+
* 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
|
+
tone,
|
|
52
|
+
css: cssProp,
|
|
53
|
+
className,
|
|
54
|
+
startIcon,
|
|
55
|
+
endIcon,
|
|
56
|
+
children,
|
|
57
|
+
...rest
|
|
58
|
+
},
|
|
59
|
+
ref,
|
|
60
|
+
) {
|
|
61
|
+
return (
|
|
62
|
+
<RACLink
|
|
63
|
+
ref={ref}
|
|
64
|
+
className={cx(
|
|
65
|
+
button({ variant, size, tone }),
|
|
66
|
+
css(linkReset, cssProp),
|
|
67
|
+
className,
|
|
68
|
+
)}
|
|
69
|
+
{...rest}
|
|
70
|
+
>
|
|
71
|
+
{startIcon ? (
|
|
72
|
+
<span className={buttonIcon({ side: "start" })}>{startIcon}</span>
|
|
73
|
+
) : null}
|
|
74
|
+
{children}
|
|
75
|
+
{endIcon ? (
|
|
76
|
+
<span className={buttonIcon({ side: "end" })}>{endIcon}</span>
|
|
77
|
+
) : null}
|
|
78
|
+
</RACLink>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
);
|
package/src/List.tsx
CHANGED
|
@@ -6,22 +6,24 @@
|
|
|
6
6
|
import { styled } from "styled-system/jsx";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Unstyled list
|
|
10
|
-
*
|
|
9
|
+
* Unstyled list. The marker removal is explicit rather than relying on a
|
|
10
|
+
* reset.
|
|
11
11
|
*/
|
|
12
|
-
export const List = styled("ul"
|
|
12
|
+
export const List = styled("ul", {
|
|
13
|
+
base: { listStyleType: "none" },
|
|
14
|
+
});
|
|
13
15
|
|
|
14
|
-
/** List item
|
|
16
|
+
/** List item. */
|
|
15
17
|
export const ListItem = styled("li", {
|
|
16
18
|
base: {},
|
|
17
19
|
});
|
|
18
20
|
|
|
19
|
-
/** Bulleted list
|
|
21
|
+
/** Bulleted list. */
|
|
20
22
|
export const UnorderedList = styled("ul", {
|
|
21
23
|
base: { listStyleType: "disc", marginStart: "1em" },
|
|
22
24
|
});
|
|
23
25
|
|
|
24
|
-
/** Numbered list
|
|
26
|
+
/** Numbered list. */
|
|
25
27
|
export const OrderedList = styled("ol", {
|
|
26
28
|
base: { listStyleType: "decimal", marginStart: "1em" },
|
|
27
29
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { defineSlotRecipe } from "@pandacss/dev";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ListBox slot recipe — a standalone list of choosable options, single or
|
|
10
|
+
* multiple. Distinct from the `select` recipe's `list`/`option` slots, which
|
|
11
|
+
* style the same react-aria primitive inside a dropdown card: this one sits
|
|
12
|
+
* inline on the page, so it carries no surface of its own.
|
|
13
|
+
*
|
|
14
|
+
* An option is a leaf — if the rows need their own buttons or menus, they
|
|
15
|
+
* want `GridList` instead.
|
|
16
|
+
*
|
|
17
|
+
* Registered in the base preset (base-preset.ts), which also has the
|
|
18
|
+
* `staticCss` entry that keeps the runtime-prop variants generated.
|
|
19
|
+
*/
|
|
20
|
+
export const listBox = defineSlotRecipe({
|
|
21
|
+
className: "list-box",
|
|
22
|
+
slots: ["root", "option"],
|
|
23
|
+
base: {
|
|
24
|
+
root: {
|
|
25
|
+
// The listbox holds the roving tab index, so it is focusable itself and
|
|
26
|
+
// would otherwise draw the platform ring around the whole list.
|
|
27
|
+
outline: "none",
|
|
28
|
+
},
|
|
29
|
+
option: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
cursor: "pointer",
|
|
33
|
+
outline: "none",
|
|
34
|
+
transitionProperty: "background",
|
|
35
|
+
transitionDuration: "ultra-fast",
|
|
36
|
+
transitionTimingFunction: "ease-in",
|
|
37
|
+
_hover: { bg: "gray.50" },
|
|
38
|
+
"&[data-selected]": { bg: "gray.100", _hover: { bg: "gray.100" } },
|
|
39
|
+
"&[data-focus-visible]": { focusRing: "outline" },
|
|
40
|
+
"&[data-disabled]": { opacity: 0.4, cursor: "not-allowed" },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
package/src/ListBox.tsx
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
ListBox as RACListBox,
|
|
8
|
+
ListBoxItem as RACListBoxItem,
|
|
9
|
+
ListBoxItemProps as RACListBoxItemProps,
|
|
10
|
+
ListBoxProps as RACListBoxProps,
|
|
11
|
+
} from "react-aria-components";
|
|
12
|
+
import { css, cx } from "styled-system/css";
|
|
13
|
+
import { listBox } from "styled-system/recipes";
|
|
14
|
+
import { SystemStyleObject } from "styled-system/types";
|
|
15
|
+
|
|
16
|
+
export interface ListBoxProps<T extends object>
|
|
17
|
+
extends Omit<RACListBoxProps<T>, "className" | "style" | "children"> {
|
|
18
|
+
/** `ListBoxOption`s, or a render function when `items` is given. */
|
|
19
|
+
children: RACListBoxProps<T>["children"];
|
|
20
|
+
/** Per-instance style overrides for the list, merged after the recipe. */
|
|
21
|
+
css?: SystemStyleObject;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ListBox — react-aria-components' <ListBox>, standing on the page rather
|
|
27
|
+
* than inside a dropdown (that is `Select`/`ComboBox`, which share their own
|
|
28
|
+
* recipe).
|
|
29
|
+
*
|
|
30
|
+
* Options are leaves: a button inside one is unreachable by keyboard, so rows
|
|
31
|
+
* carrying their own controls want `GridList`.
|
|
32
|
+
*/
|
|
33
|
+
export const ListBox = <T extends object>({
|
|
34
|
+
css: cssProp,
|
|
35
|
+
className,
|
|
36
|
+
children,
|
|
37
|
+
...rest
|
|
38
|
+
}: ListBoxProps<T>) => {
|
|
39
|
+
const slots = listBox();
|
|
40
|
+
return (
|
|
41
|
+
<RACListBox
|
|
42
|
+
{...rest}
|
|
43
|
+
className={cx(slots.root, cssProp ? css(cssProp) : undefined, className)}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</RACListBox>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export interface ListBoxOptionProps<T extends object = object>
|
|
51
|
+
extends Omit<RACListBoxItemProps<T>, "className" | "style" | "children"> {
|
|
52
|
+
/**
|
|
53
|
+
* The option's content. A function receives the option's state, for a row
|
|
54
|
+
* that draws its own selected marker rather than taking the recipe's
|
|
55
|
+
* background.
|
|
56
|
+
*/
|
|
57
|
+
children?: RACListBoxItemProps<T>["children"];
|
|
58
|
+
/** Per-instance style overrides for the option, merged after the recipe. */
|
|
59
|
+
css?: SystemStyleObject;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* An option in a `ListBox`.
|
|
65
|
+
*
|
|
66
|
+
* Give it a `textValue` where its children aren't a plain string: react-aria
|
|
67
|
+
* derives typeahead text from string children only.
|
|
68
|
+
*/
|
|
69
|
+
export const ListBoxOption = <T extends object = object>({
|
|
70
|
+
css: cssProp,
|
|
71
|
+
className,
|
|
72
|
+
children,
|
|
73
|
+
...rest
|
|
74
|
+
}: ListBoxOptionProps<T>) => {
|
|
75
|
+
const slots = listBox();
|
|
76
|
+
return (
|
|
77
|
+
<RACListBoxItem
|
|
78
|
+
{...rest}
|
|
79
|
+
className={cx(
|
|
80
|
+
slots.option,
|
|
81
|
+
cssProp ? css(cssProp) : undefined,
|
|
82
|
+
className,
|
|
83
|
+
)}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</RACListBoxItem>
|
|
87
|
+
);
|
|
88
|
+
};
|
package/src/Menu.recipe.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import { defineSlotRecipe } from "@pandacss/dev";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Menu slot recipe
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Menu slot recipe. `content` is the dropdown card (react-aria-components'
|
|
10
|
+
* Popover), `list` the RAC Menu, `item` a MenuItem, `icon` the leading-icon
|
|
11
|
+
* wrapper.
|
|
12
12
|
*
|
|
13
13
|
* A config slot recipe (rather than an atomic `sva`) for consistency with
|
|
14
14
|
* `dialog` and so presets can override it later if brands diverge.
|
|
@@ -18,20 +18,34 @@ import { defineSlotRecipe } from "@pandacss/dev";
|
|
|
18
18
|
*/
|
|
19
19
|
export const menu = defineSlotRecipe({
|
|
20
20
|
className: "menu",
|
|
21
|
-
slots: [
|
|
21
|
+
slots: [
|
|
22
|
+
"content",
|
|
23
|
+
"list",
|
|
24
|
+
"item",
|
|
25
|
+
"icon",
|
|
26
|
+
"label",
|
|
27
|
+
"divider",
|
|
28
|
+
"group",
|
|
29
|
+
"groupTitle",
|
|
30
|
+
"itemIndicator",
|
|
31
|
+
],
|
|
22
32
|
base: {
|
|
23
33
|
content: {
|
|
24
34
|
bg: "white",
|
|
25
35
|
color: "inherit",
|
|
26
36
|
minWidth: "3xs",
|
|
27
37
|
py: "2",
|
|
28
|
-
|
|
38
|
+
// `popover` (1500), not `dropdown` (1000): a RAC Popover always portals
|
|
39
|
+
// to the body, so a menu opened from inside a Modal (zIndex `modal`,
|
|
40
|
+
// 1400) escapes the modal's stacking context and would paint behind it.
|
|
41
|
+
// Nothing else lives between 1400 and the toast/tooltip layer.
|
|
42
|
+
zIndex: "popover",
|
|
29
43
|
borderRadius: "md",
|
|
30
44
|
borderWidth: "1px",
|
|
31
45
|
borderColor: "gray.200",
|
|
32
46
|
boxShadow: "sm",
|
|
33
|
-
//
|
|
34
|
-
//
|
|
47
|
+
// Fade/scale enter/exit. RAC toggles data-entering/data-exiting on the
|
|
48
|
+
// Popover and waits for the transition before unmount.
|
|
35
49
|
transformOrigin: "top",
|
|
36
50
|
opacity: 1,
|
|
37
51
|
transform: "scale(1)",
|
|
@@ -52,19 +66,18 @@ export const menu = defineSlotRecipe({
|
|
|
52
66
|
color: "inherit",
|
|
53
67
|
textDecoration: "none",
|
|
54
68
|
outline: "none",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// RAC highlights the active item (keyboard or pointer) with data-focused;
|
|
59
|
-
// data-pressed is the pressed state — mirrors Chakra's _focus/_active.
|
|
69
|
+
// data-focused is RAC's active item, either modality. The highlight
|
|
70
|
+
// is focus indication: no transition (it snaps with the ring, which
|
|
71
|
+
// keyboard nav adds; inset, the rows being full-bleed).
|
|
60
72
|
"&[data-focused]": { bg: "gray.100" },
|
|
73
|
+
"&[data-focus-visible]": { focusRing: "outlineInset" },
|
|
61
74
|
"&[data-pressed]": { bg: "gray.200" },
|
|
62
75
|
"&[data-disabled]": { opacity: 0.4, cursor: "not-allowed" },
|
|
63
76
|
},
|
|
64
77
|
label: {
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
78
|
+
// A flex:1 wrapper around an icon-item's children, so block children
|
|
79
|
+
// (e.g. two stacked <Text>s) lay out vertically rather than as flex-row
|
|
80
|
+
// siblings of the icon.
|
|
68
81
|
flex: "1",
|
|
69
82
|
},
|
|
70
83
|
icon: {
|
|
@@ -73,8 +86,8 @@ export const menu = defineSlotRecipe({
|
|
|
73
86
|
justifyContent: "center",
|
|
74
87
|
flexShrink: 0,
|
|
75
88
|
marginEnd: "0.75rem",
|
|
76
|
-
//
|
|
77
|
-
//
|
|
89
|
+
// Glyphs shrink to 0.8em; items passing an explicitly sized icon
|
|
90
|
+
// (e.g. h/w) override this.
|
|
78
91
|
fontSize: "0.8em",
|
|
79
92
|
},
|
|
80
93
|
divider: {
|
|
@@ -84,5 +97,26 @@ export const menu = defineSlotRecipe({
|
|
|
84
97
|
my: "2",
|
|
85
98
|
opacity: 0.6,
|
|
86
99
|
},
|
|
100
|
+
group: {},
|
|
101
|
+
// Title for a menu group or option group.
|
|
102
|
+
groupTitle: {
|
|
103
|
+
display: "block",
|
|
104
|
+
mx: "4",
|
|
105
|
+
my: "2",
|
|
106
|
+
fontWeight: "semibold",
|
|
107
|
+
fontSize: "sm",
|
|
108
|
+
},
|
|
109
|
+
// Check glyph slot for MenuItemOption: space always reserved, visible
|
|
110
|
+
// only on the selected item (RAC sets data-selected on it).
|
|
111
|
+
itemIndicator: {
|
|
112
|
+
display: "inline-flex",
|
|
113
|
+
alignItems: "center",
|
|
114
|
+
justifyContent: "center",
|
|
115
|
+
flexShrink: 0,
|
|
116
|
+
marginEnd: "0.75rem",
|
|
117
|
+
fontSize: "0.8em",
|
|
118
|
+
opacity: 0,
|
|
119
|
+
"[data-selected] &": { opacity: 1 },
|
|
120
|
+
},
|
|
87
121
|
},
|
|
88
122
|
});
|
package/src/Menu.tsx
CHANGED
|
@@ -5,17 +5,21 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ReactNode, useCallback, useState } from "react";
|
|
7
7
|
import {
|
|
8
|
+
Header as RACHeader,
|
|
8
9
|
Menu as RACMenu,
|
|
9
10
|
MenuItem as RACMenuItem,
|
|
10
11
|
MenuItemProps as RACMenuItemProps,
|
|
12
|
+
MenuSection as RACMenuSection,
|
|
11
13
|
MenuTrigger as RACMenuTrigger,
|
|
12
14
|
Popover,
|
|
13
15
|
PopoverProps,
|
|
14
16
|
Separator,
|
|
15
17
|
} from "react-aria-components";
|
|
18
|
+
import { RiCheckLine } from "react-icons/ri";
|
|
16
19
|
import { css, cx } from "styled-system/css";
|
|
17
20
|
import { menu } from "styled-system/recipes";
|
|
18
21
|
import { SystemStyleObject } from "styled-system/types";
|
|
22
|
+
import { Icon } from "./Icon";
|
|
19
23
|
import { useOverlayCloseRegistrar } from "./SharedUIProvider";
|
|
20
24
|
|
|
21
25
|
export interface MenuTriggerProps {
|
|
@@ -93,7 +97,6 @@ export interface MenuListProps {
|
|
|
93
97
|
*/
|
|
94
98
|
export const MenuList = ({
|
|
95
99
|
children,
|
|
96
|
-
// Matches Chakra Menu's default "bottom-start".
|
|
97
100
|
placement = "bottom start",
|
|
98
101
|
css: cssProp,
|
|
99
102
|
className,
|
|
@@ -115,7 +118,7 @@ export const MenuList = ({
|
|
|
115
118
|
|
|
116
119
|
export interface MenuItemProps
|
|
117
120
|
extends Omit<RACMenuItemProps, "className" | "children"> {
|
|
118
|
-
/** Icon rendered before the label
|
|
121
|
+
/** Icon rendered before the label. */
|
|
119
122
|
icon?: ReactNode;
|
|
120
123
|
/** Per-instance style overrides, merged after the recipe. */
|
|
121
124
|
css?: SystemStyleObject;
|
|
@@ -152,6 +155,118 @@ export const MenuItem = ({
|
|
|
152
155
|
);
|
|
153
156
|
};
|
|
154
157
|
|
|
158
|
+
interface MenuOptionGroupBaseProps {
|
|
159
|
+
/** Group heading shown above the options. */
|
|
160
|
+
title?: ReactNode;
|
|
161
|
+
/** `MenuItemOption` children. */
|
|
162
|
+
children: ReactNode;
|
|
163
|
+
css?: SystemStyleObject;
|
|
164
|
+
className?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface MenuOptionGroupRadioProps extends MenuOptionGroupBaseProps {
|
|
168
|
+
type?: "radio";
|
|
169
|
+
/** The selected `MenuItemOption`'s value. */
|
|
170
|
+
value?: string;
|
|
171
|
+
/** Called with the newly selected option's value. */
|
|
172
|
+
onChange?: (value: string) => void;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface MenuOptionGroupCheckboxProps extends MenuOptionGroupBaseProps {
|
|
176
|
+
type: "checkbox";
|
|
177
|
+
/** The checked `MenuItemOption`s' values. */
|
|
178
|
+
value?: string[];
|
|
179
|
+
/** Called with the full set of checked values after a toggle. */
|
|
180
|
+
onChange?: (value: string[]) => void;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type MenuOptionGroupProps =
|
|
184
|
+
| MenuOptionGroupRadioProps
|
|
185
|
+
| MenuOptionGroupCheckboxProps;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* MenuOptionGroup — a group of checkable `MenuItemOption`s within a menu.
|
|
189
|
+
* `type="radio"` (the default) is single-select and renders `menuitemradio`;
|
|
190
|
+
* `type="checkbox"` is multi-select and renders `menuitemcheckbox`, each
|
|
191
|
+
* option toggling independently.
|
|
192
|
+
*
|
|
193
|
+
* Selection is section-scoped (RAC MenuSection), so a menu can mix action items
|
|
194
|
+
* and option groups. An option's own `onAction` still fires on every press,
|
|
195
|
+
* including the press that deselects it — so a lone toggle can be driven either
|
|
196
|
+
* by the group's `onChange` or by the item's `onAction`.
|
|
197
|
+
*
|
|
198
|
+
* Choosing an option leaves the menu open (a plain `MenuItem` closes it).
|
|
199
|
+
*/
|
|
200
|
+
export const MenuOptionGroup = (props: MenuOptionGroupProps) => {
|
|
201
|
+
const { title, children, css: cssProp, className } = props;
|
|
202
|
+
const slots = menu();
|
|
203
|
+
const selectedKeys =
|
|
204
|
+
props.type === "checkbox"
|
|
205
|
+
? props.value ?? []
|
|
206
|
+
: props.value != null
|
|
207
|
+
? [props.value]
|
|
208
|
+
: [];
|
|
209
|
+
return (
|
|
210
|
+
<RACMenuSection
|
|
211
|
+
className={cx(slots.group, cssProp ? css(cssProp) : undefined, className)}
|
|
212
|
+
selectionMode={props.type === "checkbox" ? "multiple" : "single"}
|
|
213
|
+
selectedKeys={selectedKeys}
|
|
214
|
+
onSelectionChange={(keys) => {
|
|
215
|
+
if (keys === "all") {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const values = [...keys].map(String);
|
|
219
|
+
if (props.type === "checkbox") {
|
|
220
|
+
props.onChange?.(values);
|
|
221
|
+
} else if (values.length > 0) {
|
|
222
|
+
// Radio: a press that clears the selection reports nothing.
|
|
223
|
+
props.onChange?.(values[0]);
|
|
224
|
+
}
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
{title != null && (
|
|
228
|
+
<RACHeader className={slots.groupTitle}>{title}</RACHeader>
|
|
229
|
+
)}
|
|
230
|
+
{children}
|
|
231
|
+
</RACMenuSection>
|
|
232
|
+
);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export interface MenuItemOptionProps
|
|
236
|
+
extends Omit<RACMenuItemProps, "className" | "children" | "id" | "value"> {
|
|
237
|
+
/** This option's value within its `MenuOptionGroup`. */
|
|
238
|
+
value: string;
|
|
239
|
+
css?: SystemStyleObject;
|
|
240
|
+
className?: string;
|
|
241
|
+
children?: ReactNode;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* MenuItemOption — a selectable option inside a `MenuOptionGroup`, with a
|
|
246
|
+
* check indicator on the selected item.
|
|
247
|
+
*/
|
|
248
|
+
export const MenuItemOption = ({
|
|
249
|
+
value,
|
|
250
|
+
css: cssProp,
|
|
251
|
+
className,
|
|
252
|
+
children,
|
|
253
|
+
...rest
|
|
254
|
+
}: MenuItemOptionProps) => {
|
|
255
|
+
const slots = menu();
|
|
256
|
+
return (
|
|
257
|
+
<RACMenuItem
|
|
258
|
+
id={value}
|
|
259
|
+
className={cx(slots.item, cssProp ? css(cssProp) : undefined, className)}
|
|
260
|
+
{...rest}
|
|
261
|
+
>
|
|
262
|
+
<span className={slots.itemIndicator} aria-hidden>
|
|
263
|
+
<Icon as={RiCheckLine} />
|
|
264
|
+
</span>
|
|
265
|
+
<span className={slots.label}>{children}</span>
|
|
266
|
+
</RACMenuItem>
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
|
|
155
270
|
export interface MenuDividerProps {
|
|
156
271
|
css?: SystemStyleObject;
|
|
157
272
|
className?: string;
|