@vygruppen/spor-react 12.24.14 → 12.24.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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-postinstall.log +2 -2
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +447 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -15
- package/dist/index.d.ts +79 -15
- package/dist/index.mjs +438 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/calendar/CalendarCell.tsx +58 -32
- package/src/calendar/CalendarContext.tsx +9 -0
- package/src/calendar/ScrollCalendar.tsx +14 -4
- package/src/input/Autocomplete.tsx +105 -98
- package/src/input/Menu.tsx +234 -0
- package/src/input/index.ts +1 -0
- package/src/theme/slot-recipes/anatomy.ts +14 -0
- package/src/theme/slot-recipes/index.ts +2 -0
- package/src/theme/slot-recipes/menu.ts +111 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vygruppen/spor-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.24.
|
|
4
|
+
"version": "12.24.16",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"react-stately": "^3.31.1",
|
|
47
47
|
"react-swipeable": "^7.0.1",
|
|
48
48
|
"usehooks-ts": "^3.1.0",
|
|
49
|
-
"@vygruppen/spor-design-tokens": "4.3.3",
|
|
50
49
|
"@vygruppen/spor-icon-react": "4.5.3",
|
|
50
|
+
"@vygruppen/spor-design-tokens": "4.3.3",
|
|
51
51
|
"@vygruppen/spor-loader": "0.7.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"vitest": "^0.26.3",
|
|
69
69
|
"vitest-axe": "^0.1.0",
|
|
70
70
|
"vitest-canvas-mock": "^0.2.2",
|
|
71
|
-
"@vygruppen/
|
|
72
|
-
"@vygruppen/
|
|
71
|
+
"@vygruppen/eslint-config": "2.1.0",
|
|
72
|
+
"@vygruppen/tsconfig": "0.1.1"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"react": ">=18.0.0 <19.0.0",
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { CalendarDate, isSameDay, isSameMonth } from "@internationalized/date";
|
|
2
|
-
import { useRef } from "react";
|
|
2
|
+
import { PointerEvent as ReactPointerEvent, useRef } from "react";
|
|
3
3
|
import { mergeProps, useCalendarCell, useFocusRing } from "react-aria";
|
|
4
4
|
|
|
5
5
|
import { useCalendar } from "@/calendar/CalendarContext";
|
|
6
6
|
import { Box } from "@/layout";
|
|
7
7
|
import { Text } from "@/typography";
|
|
8
8
|
|
|
9
|
+
const IS_TOUCH_PRIMARY =
|
|
10
|
+
globalThis.window !== undefined &&
|
|
11
|
+
globalThis.window.matchMedia?.("(pointer: coarse)").matches;
|
|
12
|
+
|
|
13
|
+
function isPhantomPointer(event: ReactPointerEvent) {
|
|
14
|
+
return IS_TOUCH_PRIMARY && event.pointerType === "mouse";
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
type Props = {
|
|
10
18
|
date: CalendarDate;
|
|
11
19
|
currentMonth: CalendarDate;
|
|
@@ -29,10 +37,28 @@ export function CalendarCell({ date, currentMonth }: Props) {
|
|
|
29
37
|
? isSameDay(date, state.highlightedRange.end)
|
|
30
38
|
: false;
|
|
31
39
|
|
|
32
|
-
const
|
|
40
|
+
const isEdge =
|
|
41
|
+
(mode === "single" && isSelected) || isSelectionStart || isSelectionEnd;
|
|
42
|
+
const isMiddle = isSelected && !isEdge && mode === "range";
|
|
33
43
|
|
|
34
44
|
const { focusProps, isFocusVisible } = useFocusRing();
|
|
35
45
|
|
|
46
|
+
const merged = mergeProps(buttonProps, focusProps);
|
|
47
|
+
|
|
48
|
+
// iOS 26 bug with pointer events: https://bugs.webkit.org/show_bug.cgi?id=214609
|
|
49
|
+
const interactionProps =
|
|
50
|
+
mode === "range" && IS_TOUCH_PRIMARY
|
|
51
|
+
? {
|
|
52
|
+
...merged,
|
|
53
|
+
onPointerEnter: (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
54
|
+
if (!isPhantomPointer(event)) merged.onPointerEnter?.(event);
|
|
55
|
+
},
|
|
56
|
+
onPointerMove: (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
57
|
+
if (!isPhantomPointer(event)) merged.onPointerMove?.(event);
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
: merged;
|
|
61
|
+
|
|
36
62
|
return (
|
|
37
63
|
<td
|
|
38
64
|
{...cellProps}
|
|
@@ -42,7 +68,7 @@ export function CalendarCell({ date, currentMonth }: Props) {
|
|
|
42
68
|
}}
|
|
43
69
|
>
|
|
44
70
|
<Box
|
|
45
|
-
{...
|
|
71
|
+
{...interactionProps}
|
|
46
72
|
ref={ref}
|
|
47
73
|
hidden={isOutsideMonth}
|
|
48
74
|
width={["54px", null, "70px"]}
|
|
@@ -57,35 +83,10 @@ export function CalendarCell({ date, currentMonth }: Props) {
|
|
|
57
83
|
alignItems="center"
|
|
58
84
|
justifyContent="center"
|
|
59
85
|
borderRadius="sm"
|
|
60
|
-
css={
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...(isSingleModeSelected && {
|
|
65
|
-
backgroundColor: "brand.surface",
|
|
66
|
-
color: "text.inverted",
|
|
67
|
-
}),
|
|
68
|
-
// Range mode: Selection start/end styling
|
|
69
|
-
...((isSelectionStart || isSelectionEnd) && {
|
|
70
|
-
backgroundColor: "brand.surface",
|
|
71
|
-
color: "text.inverted",
|
|
72
|
-
}),
|
|
73
|
-
// Range mode: Middle range styling
|
|
74
|
-
...(isSelected &&
|
|
75
|
-
!(isSelectionStart || isSelectionEnd) &&
|
|
76
|
-
mode === "range" && {
|
|
77
|
-
backgroundColor: "surface.secondary",
|
|
78
|
-
color: "text",
|
|
79
|
-
}),
|
|
80
|
-
// Non-selected hover state
|
|
81
|
-
...(!isSelected &&
|
|
82
|
-
!isDisabled && {
|
|
83
|
-
"&:hover": {
|
|
84
|
-
backgroundColor: "surface.secondary",
|
|
85
|
-
color: "text",
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
}}
|
|
86
|
+
css={cellStyles}
|
|
87
|
+
data-disabled={isDisabled || undefined}
|
|
88
|
+
data-edge={isEdge || undefined}
|
|
89
|
+
data-middle={isMiddle || undefined}
|
|
89
90
|
>
|
|
90
91
|
<Text variant="sm">{formattedDate}</Text>
|
|
91
92
|
</Box>
|
|
@@ -93,3 +94,28 @@ export function CalendarCell({ date, currentMonth }: Props) {
|
|
|
93
94
|
</td>
|
|
94
95
|
);
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
const cellStyles = {
|
|
99
|
+
cursor: "pointer",
|
|
100
|
+
// Disabled
|
|
101
|
+
"&[data-disabled]": {
|
|
102
|
+
color: "text.disabled",
|
|
103
|
+
},
|
|
104
|
+
// Selection edge (single-mode selected OR range start/end)
|
|
105
|
+
"&[data-edge]": {
|
|
106
|
+
backgroundColor: "brand.surface",
|
|
107
|
+
color: "text.inverted",
|
|
108
|
+
},
|
|
109
|
+
// Range middle
|
|
110
|
+
"&[data-middle]": {
|
|
111
|
+
backgroundColor: "surface.secondary",
|
|
112
|
+
color: "text",
|
|
113
|
+
},
|
|
114
|
+
// Hover for non-selected, non-disabled cells on devices that support hover
|
|
115
|
+
"@media (hover: hover)": {
|
|
116
|
+
"&:not([data-edge]):not([data-middle]):not([data-disabled]):hover": {
|
|
117
|
+
backgroundColor: "surface.secondary",
|
|
118
|
+
color: "text",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
@@ -173,6 +173,15 @@ export function CalendarProvider(props: Props) {
|
|
|
173
173
|
|
|
174
174
|
const getRangeEndValue = () => {
|
|
175
175
|
if (rangeState.highlightedRange?.end) {
|
|
176
|
+
if (
|
|
177
|
+
rangeState.anchorDate &&
|
|
178
|
+
rangeState.highlightedRange.start &&
|
|
179
|
+
rangeState.highlightedRange.end.compare(
|
|
180
|
+
rangeState.highlightedRange.start,
|
|
181
|
+
) === 0
|
|
182
|
+
) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
176
185
|
return toCalendarDate(rangeState.highlightedRange.end);
|
|
177
186
|
}
|
|
178
187
|
if (rangeState?.value?.end) {
|
|
@@ -38,10 +38,20 @@ export function ScrollCalendar(boxProps: BoxProps) {
|
|
|
38
38
|
if (monthIndex > 0 && monthIndex < monthCount) {
|
|
39
39
|
const element = monthReferences.current[monthIndex];
|
|
40
40
|
if (element) {
|
|
41
|
-
element.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const selectedCell = element.querySelector<HTMLElement>(
|
|
42
|
+
'[aria-selected="true"]',
|
|
43
|
+
);
|
|
44
|
+
if (selectedCell) {
|
|
45
|
+
selectedCell.scrollIntoView({
|
|
46
|
+
behavior: "instant",
|
|
47
|
+
block: "center",
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
element.scrollIntoView({
|
|
51
|
+
behavior: "instant",
|
|
52
|
+
block: "start",
|
|
53
|
+
});
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
|
|
@@ -30,107 +30,114 @@ type Props = {
|
|
|
30
30
|
} & Omit<ComboboxRootProps, "collection"> &
|
|
31
31
|
FieldProps;
|
|
32
32
|
|
|
33
|
-
export const Autocomplete = (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const extractedItems = React.useMemo(
|
|
56
|
-
() => extractItemsFromChildren(children),
|
|
57
|
-
[children],
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const { collection, filter, reset } = useListCollection({
|
|
61
|
-
initialItems: extractedItems,
|
|
62
|
-
filter: filteredExternally ? undefined : contains,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
React.useEffect(() => {
|
|
66
|
-
if (filteredExternally) reset();
|
|
67
|
-
}, [extractedItems, reset, filteredExternally]);
|
|
68
|
-
|
|
69
|
-
const filteredChildren = React.useMemo(
|
|
70
|
-
() => filterChildren(children, collection.items),
|
|
71
|
-
[children, collection.items],
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const combobox = useCombobox({
|
|
75
|
-
collection,
|
|
76
|
-
openOnClick: filteredChildren.length > 0 ? openOnClick : false,
|
|
77
|
-
onInputValueChange: (event) => {
|
|
78
|
-
if (!filteredExternally) {
|
|
79
|
-
filter(event.inputValue);
|
|
80
|
-
}
|
|
81
|
-
onInputValueChange?.(event);
|
|
33
|
+
export const Autocomplete = forwardRef<HTMLInputElement, Props>(
|
|
34
|
+
function Autocomplete(
|
|
35
|
+
{
|
|
36
|
+
variant = "core",
|
|
37
|
+
children,
|
|
38
|
+
css,
|
|
39
|
+
label,
|
|
40
|
+
leftIcon,
|
|
41
|
+
onInputValueChange,
|
|
42
|
+
invalid,
|
|
43
|
+
helperText,
|
|
44
|
+
errorText,
|
|
45
|
+
required,
|
|
46
|
+
filteredExternally,
|
|
47
|
+
loading,
|
|
48
|
+
disabled,
|
|
49
|
+
emptyLabel,
|
|
50
|
+
onFocus,
|
|
51
|
+
openOnClick = true,
|
|
52
|
+
openOnFocus = true,
|
|
53
|
+
...rest
|
|
82
54
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
55
|
+
ref,
|
|
56
|
+
) {
|
|
57
|
+
const { contains } = useFilter({ sensitivity: "base" });
|
|
58
|
+
const { t } = useTranslation();
|
|
59
|
+
|
|
60
|
+
const extractedItems = React.useMemo(
|
|
61
|
+
() => extractItemsFromChildren(children),
|
|
62
|
+
[children],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const { collection, filter, reset } = useListCollection({
|
|
66
|
+
initialItems: extractedItems,
|
|
67
|
+
filter: filteredExternally ? undefined : contains,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (filteredExternally) reset();
|
|
72
|
+
}, [extractedItems, reset, filteredExternally]);
|
|
73
|
+
|
|
74
|
+
const filteredChildren = React.useMemo(
|
|
75
|
+
() => filterChildren(children, collection.items),
|
|
76
|
+
[children, collection.items],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const combobox = useCombobox({
|
|
80
|
+
collection,
|
|
81
|
+
openOnClick: filteredChildren.length > 0 ? openOnClick : false,
|
|
82
|
+
onInputValueChange: (event) => {
|
|
83
|
+
if (!filteredExternally) {
|
|
84
|
+
filter(event.inputValue);
|
|
85
|
+
}
|
|
86
|
+
onInputValueChange?.(event);
|
|
88
87
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
positioning: {
|
|
89
|
+
placement: "bottom",
|
|
90
|
+
offset: {
|
|
91
|
+
mainAxis: 3,
|
|
92
|
+
crossAxis: -1,
|
|
93
|
+
},
|
|
94
|
+
flip: false,
|
|
95
|
+
},
|
|
96
|
+
disabled,
|
|
97
|
+
...rest,
|
|
98
|
+
});
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
onFocus
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<Combobox.
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<Combobox.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
100
|
+
return (
|
|
101
|
+
<Combobox.RootProvider value={combobox}>
|
|
102
|
+
<Combobox.Control css={css}>
|
|
103
|
+
<Combobox.Input asChild>
|
|
104
|
+
<Input
|
|
105
|
+
ref={ref}
|
|
106
|
+
label={<Combobox.Label>{label}</Combobox.Label>}
|
|
107
|
+
variant={variant}
|
|
108
|
+
labelAsChild
|
|
109
|
+
startElement={leftIcon}
|
|
110
|
+
invalid={invalid}
|
|
111
|
+
helperText={helperText}
|
|
112
|
+
errorText={errorText}
|
|
113
|
+
required={required}
|
|
114
|
+
onFocus={(event) => {
|
|
115
|
+
onFocus?.(event);
|
|
116
|
+
if (openOnFocus && filteredChildren.length > 0)
|
|
117
|
+
combobox.setOpen(true);
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
</Combobox.Input>
|
|
121
|
+
<Combobox.IndicatorGroup>
|
|
122
|
+
<Combobox.ClearTrigger asChild aria-label={t(texts.clearValue)}>
|
|
123
|
+
<CloseButton size="xs" tabIndex={0} />
|
|
124
|
+
</Combobox.ClearTrigger>
|
|
125
|
+
</Combobox.IndicatorGroup>
|
|
126
|
+
</Combobox.Control>
|
|
127
|
+
<Combobox.Positioner>
|
|
128
|
+
<Combobox.Content>
|
|
129
|
+
{!loading && (
|
|
130
|
+
<Combobox.Empty>
|
|
131
|
+
{emptyLabel ?? t(texts.noItemsFound)}
|
|
132
|
+
</Combobox.Empty>
|
|
133
|
+
)}
|
|
134
|
+
{loading ? <ColorSpinner width="1.5rem" p="2" /> : filteredChildren}
|
|
135
|
+
</Combobox.Content>
|
|
136
|
+
</Combobox.Positioner>
|
|
137
|
+
</Combobox.RootProvider>
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
);
|
|
134
141
|
|
|
135
142
|
export const AutocompleteItemGroup = Combobox.ItemGroup;
|
|
136
143
|
export const AutocompleteItemGroupLabel = Combobox.ItemGroupLabel;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Flex,
|
|
4
|
+
Menu as ChakraMenu,
|
|
5
|
+
MenuCheckboxItemProps,
|
|
6
|
+
MenuContentProps,
|
|
7
|
+
MenuItemGroupProps as ChakraMenuItemGroupProps,
|
|
8
|
+
MenuItemProps as ChakraMenuItemProps,
|
|
9
|
+
MenuRadioItemGroupProps,
|
|
10
|
+
MenuRadioItemProps,
|
|
11
|
+
MenuRootProps,
|
|
12
|
+
MenuSeparatorProps,
|
|
13
|
+
MenuTriggerItemProps as ChakraMenuTriggerItemProps,
|
|
14
|
+
Portal,
|
|
15
|
+
useMenuContext as useChakraMenuContext,
|
|
16
|
+
} from "@chakra-ui/react";
|
|
17
|
+
import {
|
|
18
|
+
DropdownDownFill18Icon,
|
|
19
|
+
DropdownDownFill24Icon,
|
|
20
|
+
} from "@vygruppen/spor-icon-react";
|
|
21
|
+
import { forwardRef, ReactNode } from "react";
|
|
22
|
+
import { createContext, useContext } from "react";
|
|
23
|
+
|
|
24
|
+
import { Button, ButtonProps, Checkbox } from "..";
|
|
25
|
+
|
|
26
|
+
type Variant = Pick<MenuRootProps, "variant">;
|
|
27
|
+
|
|
28
|
+
const CustomMenuContext = createContext<Variant>({
|
|
29
|
+
variant: "core",
|
|
30
|
+
});
|
|
31
|
+
export const useMenuContext = () => useContext(CustomMenuContext);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Menu component.
|
|
35
|
+
*
|
|
36
|
+
* Used to create an accessible dropdown menu.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
<Menu>
|
|
41
|
+
<MenuTrigger> Menu </MenuTrigger>
|
|
42
|
+
<MenuContent>
|
|
43
|
+
<MenuItem value="1"> Item 1 </MenuItem>
|
|
44
|
+
<MenuItem value="2"> Item 2 </MenuItem>
|
|
45
|
+
<MenuItem value="3"> Item 3 </MenuItem>
|
|
46
|
+
</MenuContent>
|
|
47
|
+
</Menu>
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
export const Menu = ({ children, ...props }: MenuRootProps) => {
|
|
53
|
+
return (
|
|
54
|
+
<CustomMenuContext.Provider
|
|
55
|
+
value={{
|
|
56
|
+
variant: props.variant,
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<ChakraMenu.Root {...props}>{children}</ChakraMenu.Root>
|
|
60
|
+
</CustomMenuContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const MenuContent = forwardRef<HTMLDivElement, MenuContentProps>(
|
|
65
|
+
({ children, ...props }, ref) => {
|
|
66
|
+
return (
|
|
67
|
+
<Portal>
|
|
68
|
+
<ChakraMenu.Positioner>
|
|
69
|
+
<ChakraMenu.Content ref={ref} {...props}>
|
|
70
|
+
{children}
|
|
71
|
+
</ChakraMenu.Content>
|
|
72
|
+
</ChakraMenu.Positioner>
|
|
73
|
+
</Portal>
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
MenuContent.displayName = "MenuContent";
|
|
78
|
+
|
|
79
|
+
export type MenuTriggerProps = {
|
|
80
|
+
/** An optional trigger button icon, rendered to the left of the label */
|
|
81
|
+
icon?: ReactNode;
|
|
82
|
+
} & Omit<ButtonProps, "variant" | "rightIcon" | "leftIcon">;
|
|
83
|
+
|
|
84
|
+
export const MenuTrigger = forwardRef<HTMLButtonElement, MenuTriggerProps>(
|
|
85
|
+
({ icon, size, children, ...props }, ref) => {
|
|
86
|
+
const { variant } = useMenuContext();
|
|
87
|
+
const { open } = useChakraMenuContext();
|
|
88
|
+
const ChevronIcon =
|
|
89
|
+
size === "sm" ? DropdownDownFill18Icon : DropdownDownFill24Icon;
|
|
90
|
+
|
|
91
|
+
const getButtonVariant = (): ButtonProps["variant"] => {
|
|
92
|
+
if (variant === "floating") return "floating";
|
|
93
|
+
if (variant === "accent") return "secondary";
|
|
94
|
+
return "tertiary";
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<ChakraMenu.Trigger asChild ref={ref}>
|
|
99
|
+
<Button
|
|
100
|
+
leftIcon={icon}
|
|
101
|
+
variant={getButtonVariant()}
|
|
102
|
+
size={size}
|
|
103
|
+
{...props}
|
|
104
|
+
rightIcon={
|
|
105
|
+
<ChevronIcon
|
|
106
|
+
transform={open ? "rotate(180deg)" : undefined}
|
|
107
|
+
transition="transform 0.3s"
|
|
108
|
+
/>
|
|
109
|
+
}
|
|
110
|
+
>
|
|
111
|
+
{children}
|
|
112
|
+
</Button>
|
|
113
|
+
</ChakraMenu.Trigger>
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
MenuTrigger.displayName = "MenuTrigger";
|
|
118
|
+
|
|
119
|
+
export type MenuItemProps = {
|
|
120
|
+
/** Display a command in the menu */
|
|
121
|
+
itemCommand?: string;
|
|
122
|
+
/* Display icon to the left */
|
|
123
|
+
leftIcon?: React.ReactNode;
|
|
124
|
+
/* Display icon to the right */
|
|
125
|
+
rightIcon?: React.ReactNode;
|
|
126
|
+
} & ChakraMenuItemProps;
|
|
127
|
+
|
|
128
|
+
export const MenuItem = forwardRef<HTMLDivElement, MenuItemProps>(
|
|
129
|
+
({ itemCommand, children, value, leftIcon, rightIcon, ...props }, ref) => {
|
|
130
|
+
return (
|
|
131
|
+
<ChakraMenu.Item value={value} {...props} ref={ref}>
|
|
132
|
+
{leftIcon}
|
|
133
|
+
{children}
|
|
134
|
+
{itemCommand && (
|
|
135
|
+
<ChakraMenu.ItemCommand>{itemCommand}</ChakraMenu.ItemCommand>
|
|
136
|
+
)}
|
|
137
|
+
{rightIcon}
|
|
138
|
+
</ChakraMenu.Item>
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
MenuItem.displayName = "MenuItem";
|
|
143
|
+
|
|
144
|
+
export type MenuTriggerItemProps = {
|
|
145
|
+
/* Display icon to the left */
|
|
146
|
+
leftIcon?: React.ReactNode;
|
|
147
|
+
/* Display icon to the right */
|
|
148
|
+
rightIcon?: React.ReactNode;
|
|
149
|
+
} & ChakraMenuTriggerItemProps;
|
|
150
|
+
|
|
151
|
+
export const MenuTriggerItem = forwardRef<HTMLDivElement, MenuTriggerItemProps>(
|
|
152
|
+
({ children, leftIcon, rightIcon, ...props }, ref) => {
|
|
153
|
+
return (
|
|
154
|
+
<ChakraMenu.TriggerItem {...props} ref={ref}>
|
|
155
|
+
{leftIcon}
|
|
156
|
+
{children}
|
|
157
|
+
{rightIcon}
|
|
158
|
+
</ChakraMenu.TriggerItem>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
MenuTriggerItem.displayName = "MenuTriggerItem";
|
|
163
|
+
|
|
164
|
+
export const MenuRadioItemGroup = forwardRef<
|
|
165
|
+
HTMLDivElement,
|
|
166
|
+
MenuRadioItemGroupProps
|
|
167
|
+
>(({ children, ...props }) => {
|
|
168
|
+
return (
|
|
169
|
+
<ChakraMenu.RadioItemGroup {...props}>{children}</ChakraMenu.RadioItemGroup>
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
MenuRadioItemGroup.displayName = "MenuRadioItemGroup";
|
|
173
|
+
|
|
174
|
+
export const MenuRadioItem = forwardRef<HTMLDivElement, MenuRadioItemProps>(
|
|
175
|
+
({ children, ...props }, ref) => {
|
|
176
|
+
return (
|
|
177
|
+
<ChakraMenu.RadioItem {...props} ref={ref}>
|
|
178
|
+
{children}
|
|
179
|
+
<Flex w="1.25rem" justify="center" align="center">
|
|
180
|
+
<ChakraMenu.ItemIndicator />
|
|
181
|
+
</Flex>
|
|
182
|
+
</ChakraMenu.RadioItem>
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
MenuRadioItem.displayName = "MenuRadioItem";
|
|
187
|
+
|
|
188
|
+
export type MenuItemGroupProps = {
|
|
189
|
+
/** Display group label */
|
|
190
|
+
label?: string;
|
|
191
|
+
} & ChakraMenuItemGroupProps;
|
|
192
|
+
|
|
193
|
+
export const MenuItemGroup = forwardRef<HTMLDivElement, MenuItemGroupProps>(
|
|
194
|
+
({ children, label, ...props }, ref) => {
|
|
195
|
+
return (
|
|
196
|
+
<ChakraMenu.ItemGroup {...props} ref={ref}>
|
|
197
|
+
{label && (
|
|
198
|
+
<ChakraMenu.ItemGroupLabel>{label}</ChakraMenu.ItemGroupLabel>
|
|
199
|
+
)}
|
|
200
|
+
{children}
|
|
201
|
+
</ChakraMenu.ItemGroup>
|
|
202
|
+
);
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
MenuItemGroup.displayName = "MenuItemGroup";
|
|
206
|
+
|
|
207
|
+
export const MenuCheckboxItem = forwardRef<
|
|
208
|
+
HTMLDivElement,
|
|
209
|
+
MenuCheckboxItemProps
|
|
210
|
+
>(({ children, closeOnSelect = false, ...props }, ref) => {
|
|
211
|
+
return (
|
|
212
|
+
<ChakraMenu.CheckboxItem
|
|
213
|
+
{...props}
|
|
214
|
+
ref={ref}
|
|
215
|
+
closeOnSelect={closeOnSelect}
|
|
216
|
+
checked={props.checked}
|
|
217
|
+
onCheckedChange={props.onCheckedChange}
|
|
218
|
+
>
|
|
219
|
+
<Checkbox
|
|
220
|
+
checked={props.checked}
|
|
221
|
+
onCheckedChange={() => props.onCheckedChange}
|
|
222
|
+
>
|
|
223
|
+
{children}
|
|
224
|
+
</Checkbox>
|
|
225
|
+
</ChakraMenu.CheckboxItem>
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
MenuCheckboxItem.displayName = "MenuCheckboxItem";
|
|
230
|
+
|
|
231
|
+
export const MenuSeparator = forwardRef<MenuSeparatorProps>(({ ...props }) => {
|
|
232
|
+
return <ChakraMenu.Separator {...props} />;
|
|
233
|
+
});
|
|
234
|
+
MenuSeparator.displayName = "MenuSeparator";
|
package/src/input/index.ts
CHANGED
|
@@ -285,3 +285,17 @@ export const comboboxAnatomy = arkComboboxAnatomy.extendWith(
|
|
|
285
285
|
"indicatorGroup",
|
|
286
286
|
"empty",
|
|
287
287
|
);
|
|
288
|
+
|
|
289
|
+
export const menuAnatomy = createAnatomy("menu").parts(
|
|
290
|
+
"trigger",
|
|
291
|
+
"content",
|
|
292
|
+
"item",
|
|
293
|
+
"itemGroup",
|
|
294
|
+
"triggerItem",
|
|
295
|
+
"itemCommand",
|
|
296
|
+
"itemGroupLabel",
|
|
297
|
+
"separator",
|
|
298
|
+
"radioItem",
|
|
299
|
+
"triggerItem",
|
|
300
|
+
"checkboxItem",
|
|
301
|
+
);
|
|
@@ -17,6 +17,7 @@ import { lineIconSlotRecipe } from "./line-icon";
|
|
|
17
17
|
import { listSlotRecipe } from "./list";
|
|
18
18
|
import { listBoxSlotRecipe } from "./listbox";
|
|
19
19
|
import { mediaControllerSlotRecipe } from "./media-controller-button";
|
|
20
|
+
import { menuSlotRecipe } from "./menu";
|
|
20
21
|
import { nativeSelectSlotRecipe } from "./native-select";
|
|
21
22
|
import { numericStepperRecipe } from "./numeric-stepper";
|
|
22
23
|
import { paginationSlotRecipe } from "./pagination";
|
|
@@ -69,4 +70,5 @@ export const slotRecipes = {
|
|
|
69
70
|
checkboxCard: choiceChipSlotRecipe,
|
|
70
71
|
collapsible: collapsibleSlotRecipe,
|
|
71
72
|
tooltip: popoverSlotRecipe,
|
|
73
|
+
menu: menuSlotRecipe,
|
|
72
74
|
};
|