@guardian/stand 0.0.15 → 0.0.16
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/dist/components/avatar/Avatar.cjs +2 -2
- package/dist/components/button/styles.cjs +7 -4
- package/dist/components/button/styles.js +7 -4
- package/dist/components/byline/Byline.cjs +15 -15
- package/dist/components/favicon/Favicon.cjs +2 -2
- package/dist/components/icon-button/IconButton.cjs +3 -3
- package/dist/components/icon-link-button/IconLinkButton.cjs +3 -3
- package/dist/components/menu/Menu.cjs +204 -0
- package/dist/components/menu/Menu.js +77 -0
- package/dist/components/menu/styles.cjs +103 -0
- package/dist/components/menu/styles.js +88 -0
- package/dist/components/tag-picker/TagTable.cjs +11 -11
- package/dist/index.cjs +4 -0
- package/dist/index.js +2 -0
- package/dist/menu.cjs +13 -0
- package/dist/menu.js +2 -0
- package/dist/styleD/build/css/component/menu.css +82 -0
- package/dist/styleD/build/css/semantic/shadow.css +7 -0
- package/dist/styleD/build/typescript/component/menu.cjs +140 -0
- package/dist/styleD/build/typescript/component/menu.js +138 -0
- package/dist/styleD/build/typescript/semantic/shadow.cjs +7 -0
- package/dist/styleD/build/typescript/semantic/shadow.js +5 -0
- package/dist/types/TopBar.d.ts +1 -1
- package/dist/types/avatar.d.ts +1 -1
- package/dist/types/button.d.ts +1 -1
- package/dist/types/byline.d.ts +1 -1
- package/dist/types/components/avatar/styles.d.ts +2 -1
- package/dist/types/components/button/styles.d.ts +2 -1
- package/dist/types/components/favicon/styles.d.ts +2 -1
- package/dist/types/components/icon/styles.d.ts +2 -1
- package/dist/types/components/icon-button/styles.d.ts +2 -1
- package/dist/types/components/icon-link-button/styles.d.ts +2 -1
- package/dist/types/components/link-button/styles.d.ts +2 -1
- package/dist/types/components/menu/Menu.d.ts +7 -0
- package/dist/types/components/menu/sandbox.d.ts +5 -0
- package/dist/types/components/menu/styles.d.ts +28 -0
- package/dist/types/components/menu/types.d.ts +63 -0
- package/dist/types/components/topbar/toolName/styles.d.ts +2 -1
- package/dist/types/components/typography/styles.d.ts +2 -1
- package/dist/types/favicon.d.ts +1 -1
- package/dist/types/icon-button.d.ts +1 -1
- package/dist/types/icon-link-button.d.ts +1 -1
- package/dist/types/icon.d.ts +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/link-button.d.ts +1 -1
- package/dist/types/menu.d.ts +21 -0
- package/dist/types/styleD/build/typescript/component/menu.d.ts +140 -0
- package/dist/types/styleD/build/typescript/semantic/shadow.d.ts +7 -0
- package/dist/types/styleD/stories/semantic/Shadow.d.ts +1 -0
- package/dist/types/typography.d.ts +1 -1
- package/package.json +17 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var mergeDeep = require('../../util/mergeDeep.cjs');
|
|
6
6
|
var styles = require('./styles.cjs');
|
|
7
7
|
var types = require('./types.cjs');
|
|
@@ -22,7 +22,7 @@ function Avatar({
|
|
|
22
22
|
...props
|
|
23
23
|
}) {
|
|
24
24
|
const mergedTheme = mergeDeep.mergeDeep(styles.defaultAvatarTheme, theme);
|
|
25
|
-
const [imageError, setImageError] =
|
|
25
|
+
const [imageError, setImageError] = React.useState(false);
|
|
26
26
|
const handleImageError = () => {
|
|
27
27
|
setImageError(true);
|
|
28
28
|
};
|
|
@@ -38,22 +38,25 @@ const buttonStyles = (theme, { size, variant }, hasIcon = false, isIconButton =
|
|
|
38
38
|
padding: 0;
|
|
39
39
|
`}
|
|
40
40
|
|
|
41
|
-
&[data-hovered] {
|
|
41
|
+
&[data-hovered], &:hover {
|
|
42
42
|
background: ${theme[variant].shared[":hover"].backgroundColor};
|
|
43
43
|
border: ${theme[variant].shared[":hover"].border};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
&[data-pressed]
|
|
46
|
+
&[data-pressed],
|
|
47
|
+
&:active {
|
|
47
48
|
background: ${theme[variant].shared[":active"].backgroundColor};
|
|
48
49
|
border: ${theme[variant].shared[":active"].border};
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
&[data-focus-visible]
|
|
52
|
+
&[data-focus-visible],
|
|
53
|
+
&:focus-visible {
|
|
52
54
|
outline: ${theme.shared[":focus-visible"].outline};
|
|
53
55
|
outline-offset: ${theme.shared[":focus-visible"]["outline-offset"]};
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
&[data-disabled]
|
|
58
|
+
&[data-disabled],
|
|
59
|
+
&:disabled {
|
|
57
60
|
cursor: ${theme.shared[":disabled"].cursor};
|
|
58
61
|
color: ${theme[variant].shared[":disabled"].color};
|
|
59
62
|
background: ${theme[variant].shared[":disabled"].backgroundColor};
|
|
@@ -36,22 +36,25 @@ const buttonStyles = (theme, { size, variant }, hasIcon = false, isIconButton =
|
|
|
36
36
|
padding: 0;
|
|
37
37
|
`}
|
|
38
38
|
|
|
39
|
-
&[data-hovered] {
|
|
39
|
+
&[data-hovered], &:hover {
|
|
40
40
|
background: ${theme[variant].shared[":hover"].backgroundColor};
|
|
41
41
|
border: ${theme[variant].shared[":hover"].border};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
&[data-pressed]
|
|
44
|
+
&[data-pressed],
|
|
45
|
+
&:active {
|
|
45
46
|
background: ${theme[variant].shared[":active"].backgroundColor};
|
|
46
47
|
border: ${theme[variant].shared[":active"].border};
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
&[data-focus-visible]
|
|
50
|
+
&[data-focus-visible],
|
|
51
|
+
&:focus-visible {
|
|
50
52
|
outline: ${theme.shared[":focus-visible"].outline};
|
|
51
53
|
outline-offset: ${theme.shared[":focus-visible"]["outline-offset"]};
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
&[data-disabled]
|
|
56
|
+
&[data-disabled],
|
|
57
|
+
&:disabled {
|
|
55
58
|
cursor: ${theme.shared[":disabled"].cursor};
|
|
56
59
|
color: ${theme[variant].shared[":disabled"].color};
|
|
57
60
|
background: ${theme[variant].shared[":disabled"].backgroundColor};
|
|
@@ -6,7 +6,7 @@ var prosemirrorDropcursor = require('prosemirror-dropcursor');
|
|
|
6
6
|
var prosemirrorHistory = require('prosemirror-history');
|
|
7
7
|
var prosemirrorState = require('prosemirror-state');
|
|
8
8
|
var prosemirrorView = require('prosemirror-view');
|
|
9
|
-
var
|
|
9
|
+
var React = require('react');
|
|
10
10
|
var lib = require('./lib.cjs');
|
|
11
11
|
var placeholder = require('./placeholder.cjs');
|
|
12
12
|
var plugins = require('./plugins.cjs');
|
|
@@ -26,15 +26,15 @@ const Byline = ({
|
|
|
26
26
|
searchContributors,
|
|
27
27
|
onBlur
|
|
28
28
|
}) => {
|
|
29
|
-
const editorRef =
|
|
30
|
-
const viewRef =
|
|
31
|
-
const dropdownRef =
|
|
32
|
-
const [currentText, setCurrentText] =
|
|
33
|
-
const [currentOptionIndex, setCurrentOptionIndex] =
|
|
34
|
-
const [taggedContributors, setTaggedContributors] =
|
|
35
|
-
const [currentDoc, setCurrentDoc] =
|
|
36
|
-
const [showDropdown, setShowDropdown] =
|
|
37
|
-
const isTypingFromStartRange =
|
|
29
|
+
const editorRef = React.useRef(null);
|
|
30
|
+
const viewRef = React.useRef(null);
|
|
31
|
+
const dropdownRef = React.useRef(null);
|
|
32
|
+
const [currentText, setCurrentText] = React.useState("");
|
|
33
|
+
const [currentOptionIndex, setCurrentOptionIndex] = React.useState(0);
|
|
34
|
+
const [taggedContributors, setTaggedContributors] = React.useState([]);
|
|
35
|
+
const [currentDoc, setCurrentDoc] = React.useState(null);
|
|
36
|
+
const [showDropdown, setShowDropdown] = React.useState(false);
|
|
37
|
+
const isTypingFromStartRange = React.useRef(
|
|
38
38
|
void 0
|
|
39
39
|
);
|
|
40
40
|
const trackTypingFromStart = (tr) => {
|
|
@@ -82,7 +82,7 @@ const Byline = ({
|
|
|
82
82
|
}
|
|
83
83
|
return selectedText.trim() !== "" && showDropdownBasedOnProps;
|
|
84
84
|
};
|
|
85
|
-
const [enterHit, setEnterHit] =
|
|
85
|
+
const [enterHit, setEnterHit] = React.useState(false);
|
|
86
86
|
const checkDropdownVisibility = () => {
|
|
87
87
|
if (dropdownRef.current?.checkVisibility) {
|
|
88
88
|
return dropdownRef.current.checkVisibility();
|
|
@@ -90,7 +90,7 @@ const Byline = ({
|
|
|
90
90
|
return dropdownRef.current?.offsetParent !== null;
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
React.useEffect(() => {
|
|
94
94
|
if (!editorRef.current) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
@@ -219,7 +219,7 @@ const Byline = ({
|
|
|
219
219
|
viewRef.current?.destroy();
|
|
220
220
|
};
|
|
221
221
|
}, []);
|
|
222
|
-
|
|
222
|
+
React.useEffect(() => {
|
|
223
223
|
const numberOfOptions = taggedContributors.length + (allowUntaggedContributors ? 1 : 0);
|
|
224
224
|
if (numberOfOptions) {
|
|
225
225
|
if (currentOptionIndex < 0) {
|
|
@@ -242,7 +242,7 @@ const Byline = ({
|
|
|
242
242
|
taggedContributors.length,
|
|
243
243
|
allowUntaggedContributors
|
|
244
244
|
]);
|
|
245
|
-
|
|
245
|
+
React.useEffect(() => {
|
|
246
246
|
if (showDropdown && currentOptionIndex >= 0) {
|
|
247
247
|
const selectedOption = document.getElementById(
|
|
248
248
|
`contributor-option-${currentOptionIndex}`
|
|
@@ -255,7 +255,7 @@ const Byline = ({
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
}, [currentOptionIndex, showDropdown]);
|
|
258
|
-
|
|
258
|
+
React.useEffect(() => {
|
|
259
259
|
if (enterHit) {
|
|
260
260
|
if (allowUntaggedContributors && currentOptionIndex === taggedContributors.length) {
|
|
261
261
|
lib.addUntaggedContributor(
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var mergeDeep = require('../../util/mergeDeep.cjs');
|
|
6
6
|
var Icon = require('../icon/Icon.cjs');
|
|
7
7
|
var styles = require('./styles.cjs');
|
|
8
8
|
|
|
9
9
|
const Favicon = (props) => {
|
|
10
10
|
const mergedTheme = mergeDeep.mergeDeep(styles.defaultFaviconTheme, props.theme ?? {});
|
|
11
|
-
const [imageError, setImageError] =
|
|
11
|
+
const [imageError, setImageError] = React.useState(false);
|
|
12
12
|
const handleImageError = () => {
|
|
13
13
|
setImageError(true);
|
|
14
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var reactAriaComponents = require('react-aria-components');
|
|
6
6
|
var mergeDeep = require('../../util/mergeDeep.cjs');
|
|
7
7
|
var Icon = require('../icon/Icon.cjs');
|
|
@@ -17,8 +17,8 @@ function IconButton({
|
|
|
17
17
|
...props
|
|
18
18
|
}) {
|
|
19
19
|
const mergedTheme = mergeDeep.mergeDeep(styles.defaultIconButtonTheme, theme);
|
|
20
|
-
const buttonRef =
|
|
21
|
-
|
|
20
|
+
const buttonRef = React.useRef(null);
|
|
21
|
+
React.useEffect(() => {
|
|
22
22
|
if (buttonRef.current) {
|
|
23
23
|
buttonRef.current.title = ariaLabel;
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var reactAriaComponents = require('react-aria-components');
|
|
6
6
|
var mergeDeep = require('../../util/mergeDeep.cjs');
|
|
7
7
|
var Icon = require('../icon/Icon.cjs');
|
|
@@ -17,8 +17,8 @@ function IconLinkButton({
|
|
|
17
17
|
...props
|
|
18
18
|
}) {
|
|
19
19
|
const mergedTheme = mergeDeep.mergeDeep(styles.defaultIconLinkButtonTheme, theme);
|
|
20
|
-
const linkRef =
|
|
21
|
-
|
|
20
|
+
const linkRef = React.useRef(null);
|
|
21
|
+
React.useEffect(() => {
|
|
22
22
|
if (linkRef.current) {
|
|
23
23
|
linkRef.current.title = ariaLabel;
|
|
24
24
|
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
4
|
+
var focus = require('@react-aria/focus');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactAriaComponents = require('react-aria-components');
|
|
7
|
+
var mergeDeep = require('../../util/mergeDeep.cjs');
|
|
8
|
+
var styles = require('./styles.cjs');
|
|
9
|
+
var Icon = require('../icon/Icon.cjs');
|
|
10
|
+
|
|
11
|
+
function Popover({
|
|
12
|
+
size = "md",
|
|
13
|
+
children,
|
|
14
|
+
theme = {},
|
|
15
|
+
cssOverrides,
|
|
16
|
+
...props
|
|
17
|
+
}) {
|
|
18
|
+
const mergedTheme = mergeDeep.mergeDeep(styles.defaultMenuPopoverTheme, theme);
|
|
19
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
20
|
+
reactAriaComponents.Popover,
|
|
21
|
+
{
|
|
22
|
+
css: [styles.menuPopoverStyles(mergedTheme, { size }), cssOverrides],
|
|
23
|
+
...props,
|
|
24
|
+
children
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function MenuSeparator({
|
|
29
|
+
theme = {},
|
|
30
|
+
cssOverrides,
|
|
31
|
+
...props
|
|
32
|
+
}) {
|
|
33
|
+
const mergedTheme = mergeDeep.mergeDeep(styles.defaultMenuSeparatorTheme, theme);
|
|
34
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
35
|
+
reactAriaComponents.Separator,
|
|
36
|
+
{
|
|
37
|
+
orientation: "horizontal",
|
|
38
|
+
css: [styles.menuSeparatorStyles(mergedTheme), cssOverrides],
|
|
39
|
+
...props
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function MenuToggle({ children }) {
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
45
|
+
}
|
|
46
|
+
function MenuSection({
|
|
47
|
+
name,
|
|
48
|
+
size = "md",
|
|
49
|
+
theme = {},
|
|
50
|
+
cssOverrides,
|
|
51
|
+
children,
|
|
52
|
+
...props
|
|
53
|
+
}) {
|
|
54
|
+
const mergedTheme = mergeDeep.mergeDeep(styles.defaultMenuSectionTheme, theme);
|
|
55
|
+
const items = [];
|
|
56
|
+
React.Children.forEach(children, (child, i) => {
|
|
57
|
+
if (!React.isValidElement(child)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (child.type === MenuItem) {
|
|
61
|
+
items.push(
|
|
62
|
+
React.cloneElement(child, {
|
|
63
|
+
size,
|
|
64
|
+
key: `${child.key}-${i}`
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactAriaComponents.MenuSection, { css: [cssOverrides], ...props, children: [
|
|
70
|
+
name && /* @__PURE__ */ jsxRuntime.jsx(reactAriaComponents.Header, { css: styles.menuSectionHeaderStyles(mergedTheme, { size }), children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: name }) }),
|
|
71
|
+
items
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
function MenuItem({
|
|
75
|
+
label,
|
|
76
|
+
description,
|
|
77
|
+
aside,
|
|
78
|
+
icon,
|
|
79
|
+
size = "md",
|
|
80
|
+
theme = {},
|
|
81
|
+
cssOverrides,
|
|
82
|
+
...props
|
|
83
|
+
}) {
|
|
84
|
+
const mergedTheme = mergeDeep.mergeDeep(styles.defaultMenuItemTheme, theme);
|
|
85
|
+
const textValue = props.textValue ?? (typeof label === "string" ? label : void 0);
|
|
86
|
+
const { isFocusVisible, focusProps } = focus.useFocusRing();
|
|
87
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
reactAriaComponents.MenuItem,
|
|
89
|
+
{
|
|
90
|
+
...focusProps,
|
|
91
|
+
css: [
|
|
92
|
+
styles.menuItemStyles(mergedTheme, { description }, isFocusVisible),
|
|
93
|
+
cssOverrides
|
|
94
|
+
],
|
|
95
|
+
...props,
|
|
96
|
+
textValue,
|
|
97
|
+
children: ({ isSelected, selectionMode }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
98
|
+
icon && selectionMode === "none" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
99
|
+
Icon.Icon,
|
|
100
|
+
{
|
|
101
|
+
size,
|
|
102
|
+
cssOverrides: styles.menuItemIconStyles(mergedTheme, { size }),
|
|
103
|
+
children: icon
|
|
104
|
+
}
|
|
105
|
+
) : null,
|
|
106
|
+
isSelected && selectionMode === "multiple" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
107
|
+
Icon.Icon,
|
|
108
|
+
{
|
|
109
|
+
size,
|
|
110
|
+
symbol: "check_box",
|
|
111
|
+
cssOverrides: styles.menuItemIconStyles(mergedTheme, { size })
|
|
112
|
+
}
|
|
113
|
+
) : null,
|
|
114
|
+
!isSelected && selectionMode === "multiple" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
115
|
+
Icon.Icon,
|
|
116
|
+
{
|
|
117
|
+
size,
|
|
118
|
+
symbol: "check_box_outline_blank",
|
|
119
|
+
cssOverrides: styles.menuItemIconStyles(mergedTheme, { size })
|
|
120
|
+
}
|
|
121
|
+
) : null,
|
|
122
|
+
isSelected && selectionMode === "single" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
123
|
+
Icon.Icon,
|
|
124
|
+
{
|
|
125
|
+
size,
|
|
126
|
+
symbol: "radio_button_checked",
|
|
127
|
+
cssOverrides: styles.menuItemIconStyles(mergedTheme, { size })
|
|
128
|
+
}
|
|
129
|
+
) : null,
|
|
130
|
+
!isSelected && selectionMode === "single" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
+
Icon.Icon,
|
|
132
|
+
{
|
|
133
|
+
size,
|
|
134
|
+
symbol: "radio_button_unchecked",
|
|
135
|
+
cssOverrides: styles.menuItemIconStyles(mergedTheme, { size })
|
|
136
|
+
}
|
|
137
|
+
) : null,
|
|
138
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { css: styles.menuItemLabelStyles(mergedTheme), children: label }),
|
|
139
|
+
description && /* @__PURE__ */ jsxRuntime.jsx("div", { css: styles.menuItemDescriptionStyles(mergedTheme), children: description }),
|
|
140
|
+
aside && /* @__PURE__ */ jsxRuntime.jsx("div", { css: styles.menuItemAsideStyles(mergedTheme), children: aside })
|
|
141
|
+
] })
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
function Menu({
|
|
146
|
+
theme = {},
|
|
147
|
+
size = "md",
|
|
148
|
+
popoverProps,
|
|
149
|
+
menuTriggerProps,
|
|
150
|
+
children,
|
|
151
|
+
cssOverrides,
|
|
152
|
+
...props
|
|
153
|
+
}) {
|
|
154
|
+
const mergedTheme = mergeDeep.mergeDeep(styles.defaultMenuTheme, theme);
|
|
155
|
+
let trigger = null;
|
|
156
|
+
const menu = [];
|
|
157
|
+
React.Children.forEach(children, (child, i) => {
|
|
158
|
+
if (!React.isValidElement(child)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (child.type === MenuToggle) {
|
|
162
|
+
trigger ?? (trigger = child);
|
|
163
|
+
} else if (child.type === MenuItem) {
|
|
164
|
+
menu.push(
|
|
165
|
+
React.cloneElement(child, {
|
|
166
|
+
size,
|
|
167
|
+
key: `${child.key}-${i}`
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
} else if (child.type === MenuSection) {
|
|
171
|
+
menu.push(
|
|
172
|
+
React.cloneElement(child, {
|
|
173
|
+
size,
|
|
174
|
+
key: `${child.key}-${i}`
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
} else if (child.type === MenuSeparator) {
|
|
178
|
+
menu.push(
|
|
179
|
+
React.cloneElement(child, {
|
|
180
|
+
key: `${child.key}-${i}`
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactAriaComponents.MenuTrigger, { ...menuTriggerProps, children: [
|
|
186
|
+
trigger,
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
188
|
+
Popover,
|
|
189
|
+
{
|
|
190
|
+
containerPadding: 0,
|
|
191
|
+
placement: "bottom start",
|
|
192
|
+
size,
|
|
193
|
+
...popoverProps,
|
|
194
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactAriaComponents.Menu, { css: [styles.menuStyles(mergedTheme), cssOverrides], ...props, children: menu })
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
] });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
exports.Menu = Menu;
|
|
201
|
+
exports.MenuItem = MenuItem;
|
|
202
|
+
exports.MenuSection = MenuSection;
|
|
203
|
+
exports.MenuSeparator = MenuSeparator;
|
|
204
|
+
exports.MenuToggle = MenuToggle;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from '@emotion/react/jsx-runtime';
|
|
2
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { MenuTrigger, Menu as Menu$1, MenuItem as MenuItem$1, MenuSection as MenuSection$1, Header, Separator, Popover as Popover$1 } from 'react-aria-components';
|
|
5
|
+
import { mergeDeep } from '../../util/mergeDeep.js';
|
|
6
|
+
import { menuStyles, menuItemIconStyles, menuItemLabelStyles, menuItemDescriptionStyles, menuItemAsideStyles, menuItemStyles, menuSectionHeaderStyles, menuSeparatorStyles, defaultMenuPopoverTheme, menuPopoverStyles, defaultMenuSeparatorTheme, defaultMenuSectionTheme, defaultMenuItemTheme, defaultMenuTheme } from './styles.js';
|
|
7
|
+
import { Icon } from '../icon/Icon.js';
|
|
8
|
+
|
|
9
|
+
function Popover({ size = "md", children, theme = {}, cssOverrides, ...props }) {
|
|
10
|
+
const mergedTheme = mergeDeep(defaultMenuPopoverTheme, theme);
|
|
11
|
+
return jsx(Popover$1, { css: [menuPopoverStyles(mergedTheme, { size }), cssOverrides], ...props, children });
|
|
12
|
+
}
|
|
13
|
+
function MenuSeparator({ theme = {}, cssOverrides, ...props }) {
|
|
14
|
+
const mergedTheme = mergeDeep(defaultMenuSeparatorTheme, theme);
|
|
15
|
+
return jsx(Separator, { orientation: "horizontal", css: [menuSeparatorStyles(mergedTheme), cssOverrides], ...props });
|
|
16
|
+
}
|
|
17
|
+
function MenuToggle({ children }) {
|
|
18
|
+
return jsx(Fragment, { children });
|
|
19
|
+
}
|
|
20
|
+
function MenuSection({ name, size = "md", theme = {}, cssOverrides, children, ...props }) {
|
|
21
|
+
const mergedTheme = mergeDeep(defaultMenuSectionTheme, theme);
|
|
22
|
+
const items = [];
|
|
23
|
+
React.Children.forEach(children, (child, i) => {
|
|
24
|
+
if (!React.isValidElement(child)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (child.type === MenuItem) {
|
|
28
|
+
items.push(React.cloneElement(child, {
|
|
29
|
+
size,
|
|
30
|
+
key: `${child.key}-${i}`
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return jsxs(MenuSection$1, { css: [cssOverrides], ...props, children: [name && jsx(Header, { css: menuSectionHeaderStyles(mergedTheme, { size }), children: jsx("span", { children: name }) }), items] });
|
|
35
|
+
}
|
|
36
|
+
function MenuItem({ label, description, aside, icon, size = "md", theme = {}, cssOverrides, ...props }) {
|
|
37
|
+
const mergedTheme = mergeDeep(defaultMenuItemTheme, theme);
|
|
38
|
+
const textValue = props.textValue ?? (typeof label === "string" ? label : void 0);
|
|
39
|
+
const { isFocusVisible, focusProps } = useFocusRing();
|
|
40
|
+
return jsx(
|
|
41
|
+
MenuItem$1,
|
|
42
|
+
{ ...focusProps, css: [
|
|
43
|
+
menuItemStyles(mergedTheme, { description }, isFocusVisible),
|
|
44
|
+
cssOverrides
|
|
45
|
+
], ...props, textValue, children: ({ isSelected, selectionMode }) => jsxs(Fragment, { children: [icon && selectionMode === "none" ? jsx(Icon, { size, cssOverrides: menuItemIconStyles(mergedTheme, { size }), children: icon }) : null, isSelected && selectionMode === "multiple" ? jsx(Icon, { size, symbol: "check_box", cssOverrides: menuItemIconStyles(mergedTheme, { size }) }) : null, !isSelected && selectionMode === "multiple" ? jsx(Icon, { size, symbol: "check_box_outline_blank", cssOverrides: menuItemIconStyles(mergedTheme, { size }) }) : null, isSelected && selectionMode === "single" ? jsx(Icon, { size, symbol: "radio_button_checked", cssOverrides: menuItemIconStyles(mergedTheme, { size }) }) : null, !isSelected && selectionMode === "single" ? jsx(Icon, { size, symbol: "radio_button_unchecked", cssOverrides: menuItemIconStyles(mergedTheme, { size }) }) : null, jsx("div", { css: menuItemLabelStyles(mergedTheme), children: label }), description && jsx("div", { css: menuItemDescriptionStyles(mergedTheme), children: description }), aside && jsx("div", { css: menuItemAsideStyles(mergedTheme), children: aside })] }) }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function Menu({ theme = {}, size = "md", popoverProps, menuTriggerProps, children, cssOverrides, ...props }) {
|
|
49
|
+
const mergedTheme = mergeDeep(defaultMenuTheme, theme);
|
|
50
|
+
let trigger = null;
|
|
51
|
+
const menu = [];
|
|
52
|
+
React.Children.forEach(children, (child, i) => {
|
|
53
|
+
if (!React.isValidElement(child)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (child.type === MenuToggle) {
|
|
57
|
+
trigger ?? (trigger = child);
|
|
58
|
+
} else if (child.type === MenuItem) {
|
|
59
|
+
menu.push(React.cloneElement(child, {
|
|
60
|
+
size,
|
|
61
|
+
key: `${child.key}-${i}`
|
|
62
|
+
}));
|
|
63
|
+
} else if (child.type === MenuSection) {
|
|
64
|
+
menu.push(React.cloneElement(child, {
|
|
65
|
+
size,
|
|
66
|
+
key: `${child.key}-${i}`
|
|
67
|
+
}));
|
|
68
|
+
} else if (child.type === MenuSeparator) {
|
|
69
|
+
menu.push(React.cloneElement(child, {
|
|
70
|
+
key: `${child.key}-${i}`
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return jsxs(MenuTrigger, { ...menuTriggerProps, children: [trigger, jsx(Popover, { containerPadding: 0, placement: "bottom start", size, ...popoverProps, children: jsx(Menu$1, { css: [menuStyles(mergedTheme), cssOverrides], ...props, children: menu }) })] });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { Menu, MenuItem, MenuSection, MenuSeparator, MenuToggle };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@emotion/react');
|
|
4
|
+
var menu = require('../../styleD/build/typescript/component/menu.cjs');
|
|
5
|
+
var typography = require('../../styleD/utils/semantic/typography.cjs');
|
|
6
|
+
|
|
7
|
+
const defaultMenuTheme = menu.componentMenu.menu;
|
|
8
|
+
const menuStyles = (theme) => react.css`
|
|
9
|
+
display: ${theme.shared.display};
|
|
10
|
+
flex-direction: ${theme.shared["flex-direction"]};
|
|
11
|
+
border: ${theme.shared.border};
|
|
12
|
+
background: ${theme.shared["background-color"]};
|
|
13
|
+
`;
|
|
14
|
+
const defaultMenuSectionTheme = menu.componentMenu.menuSection;
|
|
15
|
+
const menuSectionHeaderStyles = (theme, { size }) => react.css`
|
|
16
|
+
display: ${theme.header.shared.display};
|
|
17
|
+
align-items: ${theme.header.shared["align-items"]};
|
|
18
|
+
padding: ${theme.header.shared.padding.top}
|
|
19
|
+
${theme.header.shared.padding.right} ${theme.header.shared.padding.bottom}
|
|
20
|
+
${theme.header.shared.padding.left};
|
|
21
|
+
height: ${theme.header[size].height};
|
|
22
|
+
background: ${theme.header.shared["background-color"]};
|
|
23
|
+
color: ${theme.header.shared.color};
|
|
24
|
+
${typography.convertTypographyToEmotionStringStyle(theme.header[size].typography)}
|
|
25
|
+
`;
|
|
26
|
+
const defaultMenuItemTheme = menu.componentMenu.menuItem;
|
|
27
|
+
const menuItemStyles = (theme, { description }, isFocusVisible = false) => react.css`
|
|
28
|
+
display: ${theme.shared.display};
|
|
29
|
+
grid-template-columns: ${theme.shared["grid-template-columns"]};
|
|
30
|
+
grid-template-areas: ${description ? theme.shared["grid-template-areas-with-description"] : theme.shared["grid-template-areas"]};
|
|
31
|
+
gap: ${theme.shared.gap};
|
|
32
|
+
align-items: ${theme.shared["align-items"]};
|
|
33
|
+
padding: ${theme.shared.padding.top} ${theme.shared.padding.right}
|
|
34
|
+
${theme.shared.padding.bottom} ${theme.shared.padding.left};
|
|
35
|
+
border-bottom: ${theme.shared["border-bottom"]};
|
|
36
|
+
&:last-child {
|
|
37
|
+
border-bottom: ${theme.shared[":last-child"]["border-bottom"]};
|
|
38
|
+
}
|
|
39
|
+
&[data-hovered],
|
|
40
|
+
&:hover {
|
|
41
|
+
background: ${theme.shared[":hover"]["background-color"]};
|
|
42
|
+
}
|
|
43
|
+
${isFocusVisible ? react.css`
|
|
44
|
+
outline: ${theme.shared[":focus-visible"]["outline"]};
|
|
45
|
+
outline-offset: ${theme.shared[":focus-visible"]["outline-offset"]};
|
|
46
|
+
background: ${theme.shared[":hover"]["background-color"]};
|
|
47
|
+
` : react.css`
|
|
48
|
+
outline: none;
|
|
49
|
+
`}
|
|
50
|
+
`;
|
|
51
|
+
const menuItemIconStyles = (theme, { size }) => react.css`
|
|
52
|
+
grid-area: ${theme.shared.icon["grid-area"]};
|
|
53
|
+
align-self: ${theme.shared.icon["align-self"]};
|
|
54
|
+
color: ${theme.shared.icon.color};
|
|
55
|
+
/* Ensure the line-height matches the font line-height of the label for alignment */
|
|
56
|
+
line-height: ${theme[size].icon["line-height"]};
|
|
57
|
+
`;
|
|
58
|
+
const menuItemLabelStyles = (theme) => react.css`
|
|
59
|
+
grid-area: ${theme.shared.label["grid-area"]};
|
|
60
|
+
color: ${theme.shared.label.color};
|
|
61
|
+
${typography.convertTypographyToEmotionStringStyle(theme.shared.label.typography)}
|
|
62
|
+
)}
|
|
63
|
+
`;
|
|
64
|
+
const menuItemDescriptionStyles = (theme) => react.css`
|
|
65
|
+
grid-area: ${theme.shared.description["grid-area"]};
|
|
66
|
+
color: ${theme.shared.description.color};
|
|
67
|
+
${typography.convertTypographyToEmotionStringStyle(theme.shared.description.typography)}
|
|
68
|
+
`;
|
|
69
|
+
const menuItemAsideStyles = (theme) => react.css`
|
|
70
|
+
grid-area: ${theme.shared.aside["grid-area"]};
|
|
71
|
+
justify-self: ${theme.shared.aside["justify-self"]};
|
|
72
|
+
align-self: ${theme.shared.aside["align-self"]};
|
|
73
|
+
color: ${theme.shared.aside.color};
|
|
74
|
+
${typography.convertTypographyToEmotionStringStyle(theme.shared.aside.typography)}
|
|
75
|
+
`;
|
|
76
|
+
const defaultMenuSeparatorTheme = menu.componentMenu.menuSeparator;
|
|
77
|
+
const menuSeparatorStyles = (theme) => react.css`
|
|
78
|
+
background-color: ${theme.shared["background-color"]};
|
|
79
|
+
height: ${theme.shared.height};
|
|
80
|
+
width: ${theme.shared.width};
|
|
81
|
+
`;
|
|
82
|
+
const defaultMenuPopoverTheme = menu.componentMenu.menuPopover;
|
|
83
|
+
const menuPopoverStyles = (theme, { size }) => react.css`
|
|
84
|
+
overflow: ${theme.shared.overflow};
|
|
85
|
+
max-width: ${theme[size]["max-width"]};
|
|
86
|
+
width: ${theme[size].width};
|
|
87
|
+
box-shadow: ${theme.shared.shadow};
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
exports.defaultMenuItemTheme = defaultMenuItemTheme;
|
|
91
|
+
exports.defaultMenuPopoverTheme = defaultMenuPopoverTheme;
|
|
92
|
+
exports.defaultMenuSectionTheme = defaultMenuSectionTheme;
|
|
93
|
+
exports.defaultMenuSeparatorTheme = defaultMenuSeparatorTheme;
|
|
94
|
+
exports.defaultMenuTheme = defaultMenuTheme;
|
|
95
|
+
exports.menuItemAsideStyles = menuItemAsideStyles;
|
|
96
|
+
exports.menuItemDescriptionStyles = menuItemDescriptionStyles;
|
|
97
|
+
exports.menuItemIconStyles = menuItemIconStyles;
|
|
98
|
+
exports.menuItemLabelStyles = menuItemLabelStyles;
|
|
99
|
+
exports.menuItemStyles = menuItemStyles;
|
|
100
|
+
exports.menuPopoverStyles = menuPopoverStyles;
|
|
101
|
+
exports.menuSectionHeaderStyles = menuSectionHeaderStyles;
|
|
102
|
+
exports.menuSeparatorStyles = menuSeparatorStyles;
|
|
103
|
+
exports.menuStyles = menuStyles;
|