@sentry/scraps 0.2.0 → 0.4.0
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/button/buttonBar.js +7 -1
- package/dist/dragHandle/dragHandle.d.ts +34 -0
- package/dist/dragHandle/dragHandle.js +115 -0
- package/dist/dragHandle/index.d.ts +4 -0
- package/dist/dragHandle/index.js +4 -0
- package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
- package/dist/dragHandle/setDocumentDragging.js +6 -0
- package/dist/dragHandle/useDragMove.d.ts +244 -0
- package/dist/dragHandle/useDragMove.js +66 -0
- package/dist/dragHandle/useDragSeparator.d.ts +256 -0
- package/dist/dragHandle/useDragSeparator.js +36 -0
- package/dist/formPresentation/autoSaveContext.d.ts +23 -0
- package/dist/formPresentation/autoSaveContext.js +13 -0
- package/dist/formPresentation/base.d.ts +11 -0
- package/dist/formPresentation/base.js +37 -0
- package/dist/formPresentation/displayField.d.ts +17 -0
- package/dist/formPresentation/displayField.js +69 -0
- package/dist/formPresentation/fieldIds.d.ts +3 -0
- package/dist/formPresentation/fieldIds.js +14 -0
- package/dist/formPresentation/fieldLayout.d.ts +23 -0
- package/dist/formPresentation/fieldLayout.js +76 -0
- package/dist/formPresentation/formContext.d.ts +4 -0
- package/dist/formPresentation/formContext.js +6 -0
- package/dist/formPresentation/groupContext.d.ts +24 -0
- package/dist/formPresentation/groupContext.js +22 -0
- package/dist/formPresentation/icons.d.ts +11 -0
- package/dist/formPresentation/icons.js +61 -0
- package/dist/formPresentation/index.d.ts +8 -0
- package/dist/formPresentation/index.js +8 -0
- package/dist/formPresentation/meta.d.ts +18 -0
- package/dist/formPresentation/meta.js +88 -0
- package/dist/formPresentation/useStackedLayout.d.ts +1 -0
- package/dist/formPresentation/useStackedLayout.js +9 -0
- package/dist/input/index.d.ts +8 -0
- package/dist/input/index.js +6 -0
- package/dist/input/input.d.ts +19 -0
- package/dist/input/input.js +14 -0
- package/dist/input/inputGroup.d.ts +29 -0
- package/dist/input/inputGroup.js +167 -0
- package/dist/input/inputStyles.d.ts +13 -0
- package/dist/input/inputStyles.js +52 -0
- package/dist/input/numberDragInput.d.ts +20 -0
- package/dist/input/numberDragInput.js +97 -0
- package/dist/input/numberInput.d.ts +10 -0
- package/dist/input/numberInput.js +94 -0
- package/dist/input/otpInput.d.ts +28 -0
- package/dist/input/otpInput.js +81 -0
- package/dist/input/useAutosizeInput.d.ts +17 -0
- package/dist/input/useAutosizeInput.js +56 -0
- package/dist/layout/styles.d.ts +1 -1
- package/dist/menu/controlContext.d.ts +32 -0
- package/dist/menu/controlContext.js +7 -0
- package/dist/menu/dropdownButton.d.ts +18 -0
- package/dist/menu/dropdownButton.js +66 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +3 -0
- package/dist/menu/menu.d.ts +159 -0
- package/dist/menu/menu.js +464 -0
- package/dist/menu/selectTypes.d.ts +96 -0
- package/dist/menu/selectTypes.js +0 -0
- package/dist/menu/selectValue.d.ts +13 -0
- package/dist/menu/selectValue.js +0 -0
- package/dist/overlayPositioning.d.ts +10 -1
- package/dist/overlayPositioning.js +15 -2
- package/dist/overlayTrigger.d.ts +22 -0
- package/dist/overlayTrigger.js +30 -0
- package/dist/slot/knownContexts.d.ts +1 -1
- package/dist/spinner/index.d.ts +1 -0
- package/dist/spinner/index.js +1 -0
- package/dist/spinner/spinner.d.ts +14 -0
- package/dist/spinner/spinner.js +126 -0
- package/dist/splitPanel/index.d.ts +1 -0
- package/dist/splitPanel/index.js +1 -0
- package/dist/splitPanel/splitPanel.d.ts +36 -0
- package/dist/splitPanel/splitPanel.js +144 -0
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.js +3 -0
- package/dist/table/sortableHeaderCell.d.ts +36 -0
- package/dist/table/sortableHeaderCell.js +99 -0
- package/dist/table/styles.d.ts +46 -0
- package/dist/table/styles.js +93 -0
- package/dist/table/table.d.ts +64 -0
- package/dist/table/table.js +228 -0
- package/dist/table/useColumnResize.d.ts +27 -0
- package/dist/table/useColumnResize.js +62 -0
- package/dist/table/useObservedColumnSize.d.ts +12 -0
- package/dist/table/useObservedColumnSize.js +74 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/text.d.ts +7 -0
- package/dist/text/text.js +1 -1
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/textarea/textarea.d.ts +22 -0
- package/dist/textarea/textarea.js +77 -0
- package/dist/toast/index.d.ts +5 -0
- package/dist/toast/index.js +4 -0
- package/dist/toast/toast.d.ts +10 -0
- package/dist/toast/toast.js +182 -0
- package/dist/toast/toastApi.d.ts +10 -0
- package/dist/toast/toastApi.js +53 -0
- package/dist/toast/toaster.d.ts +4 -0
- package/dist/toast/toaster.js +42 -0
- package/dist/toast/types.d.ts +17 -0
- package/dist/toast/types.js +2 -0
- package/dist/toggleCard/index.d.ts +1 -0
- package/dist/toggleCard/index.js +1 -0
- package/dist/toggleCard/toggleCard.d.ts +32 -0
- package/dist/toggleCard/toggleCard.js +301 -0
- package/dist/useDimensions.d.ts +12 -0
- package/dist/useDimensions.js +31 -0
- package/dist/useOverlay.js +2 -1
- package/dist/useResizableDrawer.d.ts +72 -0
- package/dist/useResizableDrawer.js +136 -0
- package/package.json +60 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { InputGroup } from '../input/index.js';
|
|
3
|
+
import { type FlexProps } from '../layout/index.js';
|
|
4
|
+
import type { ContainerProps } from '../layout/container.js';
|
|
5
|
+
import type { FormSize } from '../theme/index.js';
|
|
6
|
+
import type { TooltipProps } from '../tooltip/index.js';
|
|
7
|
+
/** Caps a requested menu height by the space available to its overlay. */
|
|
8
|
+
export declare function calculateMenuMinHeight(first: string | number | undefined, second: string | number | undefined): string | undefined;
|
|
9
|
+
/** Container for a menu header, with a divider below it. */
|
|
10
|
+
export declare function MenuHeaderLayout(props: FlexProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
|
+
/** Text style for the menu's main heading. */
|
|
12
|
+
export declare function MenuHeading({ children, padding, }: {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
padding?: ContainerProps['padding'];
|
|
15
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
16
|
+
/** Text style for a heading within a menu section. */
|
|
17
|
+
export declare function MenuSectionLabel({ children, padding, ...props }: Omit<React.HTMLAttributes<HTMLSpanElement>, 'color' | 'style'> & {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
padding?: ContainerProps['padding'];
|
|
20
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
21
|
+
/** Layout for a menu section heading and an optional action beside it. */
|
|
22
|
+
export declare function MenuSectionHeader({ children, trailingAction, ...props }: FlexProps & {
|
|
23
|
+
trailingAction?: React.ReactNode;
|
|
24
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
25
|
+
/** Divider between menu sections. */
|
|
26
|
+
export declare function MenuSectionSeparator(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
27
|
+
/** List item wrapper for a menu section. */
|
|
28
|
+
export declare function MenuSectionGroup(props: ContainerProps<'li'>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
29
|
+
/** List wrapper for the items within a menu section. */
|
|
30
|
+
export declare function MenuSectionList(props: ContainerProps<'ul'>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
31
|
+
/** Container for menu footer actions, with a divider above it. */
|
|
32
|
+
export declare function MenuFooterLayout(props: FlexProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
33
|
+
type SearchInputProps = React.ComponentPropsWithRef<typeof InputGroup.Input> & {
|
|
34
|
+
padding?: ContainerProps['padding'];
|
|
35
|
+
};
|
|
36
|
+
/** Shared search field with a leading icon for menu controls. */
|
|
37
|
+
export declare function SearchInput({ padding, ...props }: SearchInputProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
38
|
+
/**
|
|
39
|
+
* When `reserve` is true, items without leading items render an empty leading
|
|
40
|
+
* slot, so their labels line up with items that have an icon. Menus should set
|
|
41
|
+
* it whenever any of their items renders leading items.
|
|
42
|
+
*/
|
|
43
|
+
export declare function ReserveLeadingSlot({ reserve, children, }: {
|
|
44
|
+
children: React.ReactNode;
|
|
45
|
+
reserve: boolean;
|
|
46
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
47
|
+
/** Whether the surrounding menu reserves a leading slot for every item. */
|
|
48
|
+
export declare function useReserveLeadingSlot(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Menu item priority. Determines the text and background color.
|
|
51
|
+
*/
|
|
52
|
+
type Priority = 'primary' | 'danger' | 'default';
|
|
53
|
+
declare const StyledInnerWrap: import("@emotion/styled").StyledComponent<((FlexProps<import("../layout/container.js").ContainerElement> | import("../layout/flex.js").FlexPropsWithRenderFunction<import("../layout/container.js").ContainerElement>) & {
|
|
54
|
+
theme?: import("@emotion/react").Theme;
|
|
55
|
+
}) & {
|
|
56
|
+
disabled: boolean;
|
|
57
|
+
hasTrailingAction: boolean;
|
|
58
|
+
isFocused: boolean;
|
|
59
|
+
priority: Priority;
|
|
60
|
+
size?: FormSize;
|
|
61
|
+
}, {}, {}>;
|
|
62
|
+
declare const StyledDetails: import("@emotion/styled").StyledComponent<{
|
|
63
|
+
theme?: import("@emotion/react").Theme;
|
|
64
|
+
as?: React.ElementType;
|
|
65
|
+
} & {
|
|
66
|
+
disabled: boolean;
|
|
67
|
+
priority: Priority;
|
|
68
|
+
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
69
|
+
/**
|
|
70
|
+
* A renderable item. Either a React node, or a function that accepts properties
|
|
71
|
+
* of the item, and returns a React node. The function version is useful for
|
|
72
|
+
* lazily rendering supplementary content like training items and tooltips.
|
|
73
|
+
*/
|
|
74
|
+
type ExtraContent = React.ReactNode | ((state: {
|
|
75
|
+
disabled: boolean;
|
|
76
|
+
isFocused: boolean;
|
|
77
|
+
isSelected: boolean;
|
|
78
|
+
}) => React.ReactNode);
|
|
79
|
+
/**
|
|
80
|
+
* An icon-only button rendered beside, rather than inside, the focusable menu
|
|
81
|
+
* item. The item reserves space for exactly one button, so the shape is limited
|
|
82
|
+
* to what that button needs.
|
|
83
|
+
*/
|
|
84
|
+
export interface MenuItemTrailingAction {
|
|
85
|
+
icon: React.ReactNode;
|
|
86
|
+
/** Accessible name for the button, also shown as its tooltip. */
|
|
87
|
+
label: string;
|
|
88
|
+
onAction: () => void;
|
|
89
|
+
}
|
|
90
|
+
export type ListItemProps = {
|
|
91
|
+
/**
|
|
92
|
+
* Optional descriptive text. Like 'label', should preferably be a string or
|
|
93
|
+
* have appropriate aria-labels.
|
|
94
|
+
*/
|
|
95
|
+
details?: ExtraContent;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the item is disabled (if true, the item will be grayed out and
|
|
98
|
+
* non-interactive).
|
|
99
|
+
*/
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Item label. Should preferably be a string. If not, make sure that
|
|
103
|
+
* there are appropriate aria-labels.
|
|
104
|
+
*/
|
|
105
|
+
label?: React.ReactNode;
|
|
106
|
+
/**
|
|
107
|
+
* Items to be added to the left of the label
|
|
108
|
+
*/
|
|
109
|
+
leadingItems?: ExtraContent;
|
|
110
|
+
/**
|
|
111
|
+
* Accented text and background (on hover) colors.
|
|
112
|
+
*/
|
|
113
|
+
priority?: Priority;
|
|
114
|
+
/**
|
|
115
|
+
* Whether to show the details in an overlay when the item is hovered / focused.
|
|
116
|
+
*/
|
|
117
|
+
showDetailsInOverlay?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Determines the item's font sizes and internal paddings.
|
|
120
|
+
*/
|
|
121
|
+
size?: FormSize;
|
|
122
|
+
/**
|
|
123
|
+
* Optional tooltip that appears when the use hovers over the item. This is
|
|
124
|
+
* not very visible - if possible, add additional text via the `details`
|
|
125
|
+
* prop instead.
|
|
126
|
+
*/
|
|
127
|
+
tooltip?: ExtraContent;
|
|
128
|
+
/**
|
|
129
|
+
* Additional props to be passed into <Tooltip />.
|
|
130
|
+
*/
|
|
131
|
+
tooltipOptions?: Omit<TooltipProps, 'children' | 'title' | 'className'>;
|
|
132
|
+
/**
|
|
133
|
+
* Items to be added to the right of the label.
|
|
134
|
+
*/
|
|
135
|
+
trailingItems?: ExtraContent;
|
|
136
|
+
};
|
|
137
|
+
interface OtherProps<T extends React.ElementType> {
|
|
138
|
+
as?: T;
|
|
139
|
+
detailsProps?: Partial<React.ComponentProps<typeof StyledDetails>>;
|
|
140
|
+
innerWrapProps?: Partial<React.ComponentProps<typeof StyledInnerWrap>>;
|
|
141
|
+
isFocused?: boolean;
|
|
142
|
+
isPressed?: boolean;
|
|
143
|
+
isSelected?: boolean;
|
|
144
|
+
labelProps?: {
|
|
145
|
+
as?: 'div' | 'p';
|
|
146
|
+
id?: string;
|
|
147
|
+
};
|
|
148
|
+
trailingAction?: MenuItemTrailingAction;
|
|
149
|
+
/** Ref to the trailing action's button. */
|
|
150
|
+
trailingActionRef?: React.Ref<HTMLButtonElement>;
|
|
151
|
+
/** Props for the wrapper around the trailing action. */
|
|
152
|
+
trailingActionWrapperProps?: React.ComponentPropsWithRef<'div'>;
|
|
153
|
+
}
|
|
154
|
+
interface MenuListItemProps<T extends React.ElementType = 'li'> extends ListItemProps, OtherProps<T> {
|
|
155
|
+
ref?: React.ComponentPropsWithRef<NoInfer<T>>['ref'];
|
|
156
|
+
}
|
|
157
|
+
/** Renders the shared visual shell for menu and select items. */
|
|
158
|
+
export declare function MenuListItem<T extends React.ElementType = 'li'>({ label, details, as, priority, size, disabled, leadingItems, trailingItems, trailingAction, isFocused, isSelected, isPressed, innerWrapProps, labelProps, detailsProps, showDetailsInOverlay, tooltip, tooltipOptions, ref, trailingActionRef, trailingActionWrapperProps, ...props }: MenuListItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useId, useRef } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
5
|
+
import { css, useTheme } from "@emotion/react";
|
|
6
|
+
import styled from "@emotion/styled";
|
|
7
|
+
import { autoUpdate, hide, offset, useFloating } from "@floating-ui/react-dom";
|
|
8
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
9
|
+
import { IconSearch } from "@sentry/icons/search";
|
|
10
|
+
import { Button } from "../button/index.js";
|
|
11
|
+
import { InputGroup } from "../input/index.js";
|
|
12
|
+
import interactionStateLayer from "../interactionStateLayer/index.js";
|
|
13
|
+
import { Container, Flex, Stack } from "../layout/index.js";
|
|
14
|
+
import { Overlay, PositionWrapper } from "../overlay.js";
|
|
15
|
+
import { flipOverlay, shiftOverlay } from "../overlayPositioning.js";
|
|
16
|
+
import { Separator } from "../separator/index.js";
|
|
17
|
+
import { Text } from "../text/index.js";
|
|
18
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
19
|
+
function calculateMenuMinHeight(first, second) {
|
|
20
|
+
if (void 0 === first) return 'number' == typeof second ? `${second}px` : second;
|
|
21
|
+
if (void 0 === second) return 'number' == typeof first ? `${first}px` : first;
|
|
22
|
+
const firstHeight = 'number' == typeof first ? `${first}px` : first;
|
|
23
|
+
const secondHeight = 'number' == typeof second ? `${second}px` : second;
|
|
24
|
+
return `min(${firstHeight}, ${secondHeight})`;
|
|
25
|
+
}
|
|
26
|
+
function MenuHeaderLayout(props) {
|
|
27
|
+
return /*#__PURE__*/ jsx(Stack, {
|
|
28
|
+
borderBottom: "muted",
|
|
29
|
+
gap: "0",
|
|
30
|
+
...props
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function MenuHeading({ children, padding }) {
|
|
34
|
+
const heading = /*#__PURE__*/ jsx(Text, {
|
|
35
|
+
size: "sm",
|
|
36
|
+
density: "fixed",
|
|
37
|
+
bold: true,
|
|
38
|
+
tabular: true,
|
|
39
|
+
children: children
|
|
40
|
+
});
|
|
41
|
+
return padding ? /*#__PURE__*/ jsx(Container, {
|
|
42
|
+
padding: padding,
|
|
43
|
+
children: heading
|
|
44
|
+
}) : heading;
|
|
45
|
+
}
|
|
46
|
+
function MenuSectionLabel({ children, padding, ...props }) {
|
|
47
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
48
|
+
padding: padding,
|
|
49
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
50
|
+
as: "span",
|
|
51
|
+
size: "sm",
|
|
52
|
+
density: "fixed",
|
|
53
|
+
bold: true,
|
|
54
|
+
tabular: true,
|
|
55
|
+
...props,
|
|
56
|
+
children: children
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function MenuSectionHeader({ children, trailingAction, ...props }) {
|
|
61
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
62
|
+
"data-section-header": true,
|
|
63
|
+
justify: "between",
|
|
64
|
+
align: "center",
|
|
65
|
+
minHeight: "1.5em",
|
|
66
|
+
padding: "2xs lg",
|
|
67
|
+
...props,
|
|
68
|
+
children: [
|
|
69
|
+
children,
|
|
70
|
+
trailingAction
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function MenuSectionSeparator() {
|
|
75
|
+
return /*#__PURE__*/ jsx(Separator, {
|
|
76
|
+
orientation: "horizontal",
|
|
77
|
+
border: "muted"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function MenuSectionGroup(props) {
|
|
81
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
82
|
+
as: "li",
|
|
83
|
+
display: "block",
|
|
84
|
+
...props
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function MenuSectionList(props) {
|
|
88
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
89
|
+
as: "ul",
|
|
90
|
+
role: "presentation",
|
|
91
|
+
margin: "0",
|
|
92
|
+
padding: "0",
|
|
93
|
+
...props
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function MenuFooterLayout(props) {
|
|
97
|
+
return /*#__PURE__*/ jsx(Flex, {
|
|
98
|
+
borderTop: "muted",
|
|
99
|
+
align: "center",
|
|
100
|
+
padding: "md lg",
|
|
101
|
+
...props
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function SearchInput({ padding = 'xs', ...props }) {
|
|
105
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
106
|
+
padding: padding,
|
|
107
|
+
children: /*#__PURE__*/ jsxs(InputGroup, {
|
|
108
|
+
children: [
|
|
109
|
+
/*#__PURE__*/ jsx(InputGroup.LeadingItems, {
|
|
110
|
+
disablePointerEvents: true,
|
|
111
|
+
children: /*#__PURE__*/ jsx(Flex, {
|
|
112
|
+
paddingLeft: "2xs",
|
|
113
|
+
align: "center",
|
|
114
|
+
justify: "center",
|
|
115
|
+
children: /*#__PURE__*/ jsx(IconSearch, {
|
|
116
|
+
size: "xs",
|
|
117
|
+
variant: "muted"
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
}),
|
|
121
|
+
/*#__PURE__*/ jsx(InputGroup.Input, {
|
|
122
|
+
size: "xs",
|
|
123
|
+
...props
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const ReserveLeadingSlotContext = /*#__PURE__*/ createContext(false);
|
|
130
|
+
function ReserveLeadingSlot({ reserve, children }) {
|
|
131
|
+
return /*#__PURE__*/ jsx(ReserveLeadingSlotContext, {
|
|
132
|
+
value: reserve,
|
|
133
|
+
children: children
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function useReserveLeadingSlot() {
|
|
137
|
+
return useContext(ReserveLeadingSlotContext);
|
|
138
|
+
}
|
|
139
|
+
const TRAILING_ACTION_INSET = 'lg';
|
|
140
|
+
const TRAILING_ACTION_SPACE = '3xl';
|
|
141
|
+
const ITEM_PADDING_BY_SIZE = {
|
|
142
|
+
xs: 'xs md xs lg',
|
|
143
|
+
sm: 'sm md sm lg',
|
|
144
|
+
md: 'xs sm xs md'
|
|
145
|
+
};
|
|
146
|
+
const LABEL_TEXT_SIZE_BY_SIZE = {
|
|
147
|
+
xs: 'sm',
|
|
148
|
+
sm: 'md',
|
|
149
|
+
md: 'md'
|
|
150
|
+
};
|
|
151
|
+
function getTextColor({ theme, priority, disabled }) {
|
|
152
|
+
if (disabled) return theme.tokens.content.secondary;
|
|
153
|
+
switch(priority){
|
|
154
|
+
case 'primary':
|
|
155
|
+
return theme.tokens.content.accent;
|
|
156
|
+
case 'danger':
|
|
157
|
+
return theme.tokens.content.danger;
|
|
158
|
+
case 'default':
|
|
159
|
+
default:
|
|
160
|
+
return theme.tokens.content.primary;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const StyledInnerWrap = styled(Flex, {
|
|
164
|
+
shouldForwardProp: (prop)=>'string' == typeof prop && (is_prop_valid(prop) || [
|
|
165
|
+
'padding',
|
|
166
|
+
'paddingLeft',
|
|
167
|
+
'paddingRight',
|
|
168
|
+
'align',
|
|
169
|
+
'alignSelf'
|
|
170
|
+
].includes(prop)) && ![
|
|
171
|
+
'disabled',
|
|
172
|
+
'isFocused',
|
|
173
|
+
'hasTrailingAction',
|
|
174
|
+
'priority'
|
|
175
|
+
].includes(prop)
|
|
176
|
+
})`
|
|
177
|
+
gap: ${(p)=>p.theme.space.xs};
|
|
178
|
+
position: relative;
|
|
179
|
+
border-radius: ${(p)=>p.theme.radius.md};
|
|
180
|
+
box-sizing: border-box;
|
|
181
|
+
|
|
182
|
+
font-size: ${(p)=>p.theme.form[p.size ?? 'md'].fontSize};
|
|
183
|
+
|
|
184
|
+
&,
|
|
185
|
+
&:hover,
|
|
186
|
+
&:focus,
|
|
187
|
+
&:focus-visible {
|
|
188
|
+
color: ${getTextColor};
|
|
189
|
+
box-shadow: none;
|
|
190
|
+
outline: none;
|
|
191
|
+
}
|
|
192
|
+
${(p)=>p.disabled && 'cursor: default;'}
|
|
193
|
+
|
|
194
|
+
&::before {
|
|
195
|
+
content: '';
|
|
196
|
+
position: absolute;
|
|
197
|
+
top: 0;
|
|
198
|
+
left: 0;
|
|
199
|
+
width: 100%;
|
|
200
|
+
height: 100%;
|
|
201
|
+
z-index: -1;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
${(p)=>p.isFocused && css`
|
|
205
|
+
${!p.hasTrailingAction && 'z-index: 1;'}
|
|
206
|
+
/* Background to hide the previous item's divider */
|
|
207
|
+
::before {
|
|
208
|
+
background: ${p.theme.tokens.background.overlay};
|
|
209
|
+
}
|
|
210
|
+
`}
|
|
211
|
+
`;
|
|
212
|
+
const StyledContentWrap = styled('div')`
|
|
213
|
+
position: relative;
|
|
214
|
+
width: 100%;
|
|
215
|
+
min-width: 0;
|
|
216
|
+
display: flex;
|
|
217
|
+
gap: ${(p)=>p.theme.space.md};
|
|
218
|
+
justify-content: space-between;
|
|
219
|
+
align-items: center;
|
|
220
|
+
padding: 0;
|
|
221
|
+
`;
|
|
222
|
+
const StyledLeadingItems = styled('div')`
|
|
223
|
+
display: flex;
|
|
224
|
+
gap: ${(p)=>p.theme.space.md};
|
|
225
|
+
min-width: ${(p)=>p.theme.space['2xl']};
|
|
226
|
+
justify-content: center;
|
|
227
|
+
flex-shrink: 0;
|
|
228
|
+
/* Match the label's first line when details appear below it. */
|
|
229
|
+
min-height: ${(p)=>p.hasDetails ? p.theme.font.lineHeight.fixed : '24px'};
|
|
230
|
+
align-self: ${(p)=>p.hasDetails ? 'flex-start' : 'center'};
|
|
231
|
+
align-items: center;
|
|
232
|
+
margin-top: ${(p)=>p.hasDetails ? p.theme.space.xs : '0'};
|
|
233
|
+
|
|
234
|
+
${(p)=>p.disabled && 'opacity: 0.5;'}
|
|
235
|
+
`;
|
|
236
|
+
const StyledDetails = styled('div')`
|
|
237
|
+
font-size: ${(p)=>p.theme.font.size.sm};
|
|
238
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
239
|
+
line-height: 1.4;
|
|
240
|
+
margin-bottom: 0;
|
|
241
|
+
|
|
242
|
+
${(p)=>'default' !== p.priority && css`
|
|
243
|
+
color: ${getTextColor(p)};
|
|
244
|
+
`}
|
|
245
|
+
`;
|
|
246
|
+
function MenuListItem({ label, details, as, priority = 'default', size, disabled = false, leadingItems = false, trailingItems = false, trailingAction, isFocused = false, isSelected = false, isPressed, innerWrapProps = {}, labelProps = {}, detailsProps = {}, showDetailsInOverlay = false, tooltip, tooltipOptions, ref, trailingActionRef, trailingActionWrapperProps, ...props }) {
|
|
247
|
+
const itemRef = useRef(null);
|
|
248
|
+
const theme = useTheme();
|
|
249
|
+
const labelId = useId();
|
|
250
|
+
const detailId = useId();
|
|
251
|
+
const hasInlineDetails = Boolean(details && !showDetailsInOverlay);
|
|
252
|
+
const reserveLeadingSlot = useReserveLeadingSlot();
|
|
253
|
+
const hasLeadingSlot = Boolean(leadingItems) || reserveLeadingSlot;
|
|
254
|
+
return /*#__PURE__*/ jsxs(MenuItemWrap, {
|
|
255
|
+
hasTrailingAction: Boolean(trailingAction),
|
|
256
|
+
isFocused: isFocused,
|
|
257
|
+
"aria-disabled": disabled,
|
|
258
|
+
"aria-labelledby": labelId,
|
|
259
|
+
"aria-describedby": detailId,
|
|
260
|
+
as: as ?? 'li',
|
|
261
|
+
ref: mergeRefs(ref, itemRef),
|
|
262
|
+
...props,
|
|
263
|
+
children: [
|
|
264
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
265
|
+
skipWrapper: true,
|
|
266
|
+
title: 'function' == typeof tooltip ? tooltip({
|
|
267
|
+
disabled,
|
|
268
|
+
isFocused,
|
|
269
|
+
isSelected
|
|
270
|
+
}) : tooltip,
|
|
271
|
+
delay: 500,
|
|
272
|
+
...tooltipOptions,
|
|
273
|
+
children: /*#__PURE__*/ jsxs(StyledInnerWrap, {
|
|
274
|
+
"data-menu-item-content": true,
|
|
275
|
+
padding: ITEM_PADDING_BY_SIZE[size ?? 'md'],
|
|
276
|
+
paddingLeft: hasLeadingSlot ? 'md' : void 0,
|
|
277
|
+
paddingRight: trailingAction ? TRAILING_ACTION_SPACE : void 0,
|
|
278
|
+
isFocused: isFocused,
|
|
279
|
+
hasTrailingAction: Boolean(trailingAction),
|
|
280
|
+
disabled: disabled,
|
|
281
|
+
priority: priority,
|
|
282
|
+
size: size,
|
|
283
|
+
...innerWrapProps,
|
|
284
|
+
children: [
|
|
285
|
+
/*#__PURE__*/ jsx(StyledInteractionStateLayer, {
|
|
286
|
+
isHovered: isFocused,
|
|
287
|
+
isPressed: isPressed,
|
|
288
|
+
higherOpacity: 'default' !== priority
|
|
289
|
+
}),
|
|
290
|
+
hasLeadingSlot && /*#__PURE__*/ jsx(StyledLeadingItems, {
|
|
291
|
+
disabled: disabled,
|
|
292
|
+
hasDetails: hasInlineDetails,
|
|
293
|
+
size: size,
|
|
294
|
+
children: 'function' == typeof leadingItems ? leadingItems({
|
|
295
|
+
disabled,
|
|
296
|
+
isFocused,
|
|
297
|
+
isSelected
|
|
298
|
+
}) : leadingItems
|
|
299
|
+
}),
|
|
300
|
+
/*#__PURE__*/ jsxs(StyledContentWrap, {
|
|
301
|
+
isFocused: isFocused,
|
|
302
|
+
size: size,
|
|
303
|
+
children: [
|
|
304
|
+
/*#__PURE__*/ jsxs(Stack, {
|
|
305
|
+
padding: hasInlineDetails ? 'xs 0' : void 0,
|
|
306
|
+
minHeight: hasInlineDetails ? void 0 : '24px',
|
|
307
|
+
justify: "center",
|
|
308
|
+
align: "start",
|
|
309
|
+
gap: "2xs",
|
|
310
|
+
flex: "1 0 0",
|
|
311
|
+
minWidth: "0",
|
|
312
|
+
children: [
|
|
313
|
+
/*#__PURE__*/ jsx(Text, {
|
|
314
|
+
as: "div",
|
|
315
|
+
size: LABEL_TEXT_SIZE_BY_SIZE[size ?? 'md'],
|
|
316
|
+
density: "fixed",
|
|
317
|
+
variant: disabled ? 'muted' : 'default' === priority ? void 0 : priority,
|
|
318
|
+
bold: false,
|
|
319
|
+
tabular: true,
|
|
320
|
+
ellipsis: true,
|
|
321
|
+
trim: 'string' == typeof label || 'number' == typeof label,
|
|
322
|
+
id: labelId,
|
|
323
|
+
"data-test-id": "menu-list-item-label",
|
|
324
|
+
...labelProps,
|
|
325
|
+
children: label
|
|
326
|
+
}),
|
|
327
|
+
!showDetailsInOverlay && details && /*#__PURE__*/ jsx(StyledDetails, {
|
|
328
|
+
id: detailId,
|
|
329
|
+
disabled: disabled,
|
|
330
|
+
priority: priority,
|
|
331
|
+
...detailsProps,
|
|
332
|
+
children: 'function' == typeof details ? details({
|
|
333
|
+
disabled,
|
|
334
|
+
isFocused,
|
|
335
|
+
isSelected
|
|
336
|
+
}) : details
|
|
337
|
+
})
|
|
338
|
+
]
|
|
339
|
+
}),
|
|
340
|
+
trailingItems && /*#__PURE__*/ jsx(TrailingItems, {
|
|
341
|
+
disabled: disabled,
|
|
342
|
+
children: 'function' == typeof trailingItems ? trailingItems({
|
|
343
|
+
disabled,
|
|
344
|
+
isFocused,
|
|
345
|
+
isSelected
|
|
346
|
+
}) : trailingItems
|
|
347
|
+
})
|
|
348
|
+
]
|
|
349
|
+
})
|
|
350
|
+
]
|
|
351
|
+
})
|
|
352
|
+
}),
|
|
353
|
+
trailingAction && /*#__PURE__*/ jsx(Flex, {
|
|
354
|
+
position: "absolute",
|
|
355
|
+
right: theme.space[TRAILING_ACTION_INSET],
|
|
356
|
+
top: "0",
|
|
357
|
+
height: "100%",
|
|
358
|
+
align: "center",
|
|
359
|
+
...trailingActionWrapperProps,
|
|
360
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
361
|
+
ref: trailingActionRef,
|
|
362
|
+
size: "zero",
|
|
363
|
+
variant: "transparent",
|
|
364
|
+
icon: trailingAction.icon,
|
|
365
|
+
"aria-label": trailingAction.label,
|
|
366
|
+
tooltipProps: {
|
|
367
|
+
title: trailingAction.label
|
|
368
|
+
},
|
|
369
|
+
onClick: trailingAction.onAction
|
|
370
|
+
})
|
|
371
|
+
}),
|
|
372
|
+
showDetailsInOverlay && details && isFocused && /*#__PURE__*/ jsx(DetailsOverlay, {
|
|
373
|
+
size: size,
|
|
374
|
+
id: detailId,
|
|
375
|
+
itemRef: itemRef,
|
|
376
|
+
children: 'function' == typeof details ? details({
|
|
377
|
+
disabled,
|
|
378
|
+
isFocused,
|
|
379
|
+
isSelected
|
|
380
|
+
}) : details
|
|
381
|
+
})
|
|
382
|
+
]
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
const DETAILS_MIDDLEWARE = [
|
|
386
|
+
offset({
|
|
387
|
+
crossAxis: -4,
|
|
388
|
+
mainAxis: 8
|
|
389
|
+
}),
|
|
390
|
+
flipOverlay(),
|
|
391
|
+
shiftOverlay(),
|
|
392
|
+
hide()
|
|
393
|
+
];
|
|
394
|
+
function DetailsOverlay({ children, size, id, itemRef }) {
|
|
395
|
+
const theme = useTheme();
|
|
396
|
+
const { refs: { setReference, setFloating }, floatingStyles, middlewareData } = useFloating({
|
|
397
|
+
placement: 'right-start',
|
|
398
|
+
strategy: 'fixed',
|
|
399
|
+
middleware: DETAILS_MIDDLEWARE,
|
|
400
|
+
whileElementsMounted: autoUpdate
|
|
401
|
+
});
|
|
402
|
+
useEffect(()=>{
|
|
403
|
+
setReference(itemRef.current);
|
|
404
|
+
}, [
|
|
405
|
+
itemRef,
|
|
406
|
+
setReference
|
|
407
|
+
]);
|
|
408
|
+
return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx(StyledPositionWrapper, {
|
|
409
|
+
"data-reference-hidden": middlewareData.hide?.referenceHidden,
|
|
410
|
+
ref: setFloating,
|
|
411
|
+
zIndex: theme.zIndex.tooltip,
|
|
412
|
+
style: floatingStyles,
|
|
413
|
+
children: /*#__PURE__*/ jsx(StyledOverlay, {
|
|
414
|
+
id: id,
|
|
415
|
+
role: "tooltip",
|
|
416
|
+
placement: "right-start",
|
|
417
|
+
size: size,
|
|
418
|
+
children: children
|
|
419
|
+
})
|
|
420
|
+
}), document.body);
|
|
421
|
+
}
|
|
422
|
+
const StyledPositionWrapper = styled(PositionWrapper)`
|
|
423
|
+
&[data-reference-hidden='true'] {
|
|
424
|
+
opacity: 0;
|
|
425
|
+
pointer-events: none;
|
|
426
|
+
}
|
|
427
|
+
`;
|
|
428
|
+
const StyledOverlay = styled(Overlay)`
|
|
429
|
+
padding: 4px;
|
|
430
|
+
font-size: ${(p)=>p.theme.form[p.size ?? 'md'].fontSize};
|
|
431
|
+
cursor: auto;
|
|
432
|
+
user-select: contain;
|
|
433
|
+
max-height: 80vh;
|
|
434
|
+
overflow: auto;
|
|
435
|
+
`;
|
|
436
|
+
const MenuItemWrap = styled('li')`
|
|
437
|
+
position: ${(p)=>p.hasTrailingAction ? 'relative' : 'static'};
|
|
438
|
+
${(p)=>p.hasTrailingAction && p.isFocused && 'z-index: 1;'}
|
|
439
|
+
list-style-type: none;
|
|
440
|
+
margin: 0;
|
|
441
|
+
padding: 0 ${(p)=>p.theme.space.xs};
|
|
442
|
+
cursor: pointer;
|
|
443
|
+
scroll-margin: ${(p)=>p.theme.space.xs} 0;
|
|
444
|
+
|
|
445
|
+
&:focus {
|
|
446
|
+
outline: none;
|
|
447
|
+
}
|
|
448
|
+
&:focus-visible {
|
|
449
|
+
outline: none;
|
|
450
|
+
}
|
|
451
|
+
`;
|
|
452
|
+
const StyledInteractionStateLayer = styled(interactionStateLayer)`
|
|
453
|
+
z-index: -1;
|
|
454
|
+
`;
|
|
455
|
+
const TrailingItems = styled('div')`
|
|
456
|
+
display: flex;
|
|
457
|
+
align-items: center;
|
|
458
|
+
height: 24px;
|
|
459
|
+
gap: ${(p)=>p.theme.space.md};
|
|
460
|
+
margin-right: ${(p)=>p.theme.space.xs};
|
|
461
|
+
|
|
462
|
+
${(p)=>p.disabled && 'opacity: 0.5;'}
|
|
463
|
+
`;
|
|
464
|
+
export { MenuFooterLayout, MenuHeaderLayout, MenuHeading, MenuListItem, MenuSectionGroup, MenuSectionHeader, MenuSectionLabel, MenuSectionList, MenuSectionSeparator, ReserveLeadingSlot, SearchInput, calculateMenuMinHeight, useReserveLeadingSlot };
|