@sonardigital/carbon-ui 1.1.36 → 1.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/form/fields/form-list/FormList.tsx +1 -1
- package/src/components/layout/Dropdown/components/DropdownItem.tsx +12 -0
- package/src/components/layout/Dropdown/components/DropdownPopover.tsx +20 -28
- package/src/components/layout/Dropdown/components/DropdownTrigger.tsx +28 -17
- package/src/components/layout/Dropdown/components/index.ts +1 -1
- package/src/components/layout/Dropdown/hooks/useDropdown.ts +13 -13
- package/src/components/layout/Dropdown/hooks/useDropdownContext.ts +8 -6
- package/src/components/layout/Dropdown/provider/DropdownProvider.tsx +35 -0
- package/src/components/layout/Dropdown/provider/index.ts +2 -0
- package/src/theme/constants/components.ts +1 -0
- package/src/components/layout/Dropdown/components/DropdownProvider.tsx +0 -28
- /package/src/components/layout/Dropdown/{context → provider}/DropdownContext.ts +0 -0
package/package.json
CHANGED
|
@@ -77,7 +77,7 @@ export function FormList({
|
|
|
77
77
|
<IconButton
|
|
78
78
|
size="large"
|
|
79
79
|
disabled={arrayFields.length === maxItems}
|
|
80
|
-
sx={{ marginTop:
|
|
80
|
+
sx={{ marginTop: 3, cursor: 'default' }}
|
|
81
81
|
>
|
|
82
82
|
<CheckOutlined sx={{ width: 20, height: 20 }} />
|
|
83
83
|
</IconButton>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MenuItem } from '@mui/material';
|
|
2
|
+
import { useDropdown } from 'src/components/layout';
|
|
3
|
+
|
|
4
|
+
export function DropdownItem({
|
|
5
|
+
children,
|
|
6
|
+
}: {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}): React.ReactElement {
|
|
9
|
+
const methods = useDropdown();
|
|
10
|
+
|
|
11
|
+
return <MenuItem onClick={methods.close}>{children}</MenuItem>;
|
|
12
|
+
}
|
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collapse, Menu, MenuProps } from '@mui/material';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useDropdownContext } from '../hooks/useDropdownContext';
|
|
4
4
|
|
|
5
|
-
interface PopoverProviderProps extends Omit<
|
|
6
|
-
|
|
5
|
+
interface PopoverProviderProps extends Omit<MenuProps, 'open'> {
|
|
6
|
+
children: React.ReactNode;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function DropdownPopover({
|
|
10
|
-
|
|
9
|
+
export function DropdownPopover({
|
|
10
|
+
children,
|
|
11
|
+
...props
|
|
12
|
+
}: PopoverProviderProps): React.ReactElement {
|
|
13
|
+
const methods = useDropdownContext();
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
horizontal: 'right',
|
|
25
|
-
}}
|
|
26
|
-
anchorOrigin={{
|
|
27
|
-
vertical: 'bottom',
|
|
28
|
-
horizontal: 'right',
|
|
29
|
-
}}
|
|
30
|
-
{...props}
|
|
31
|
-
>
|
|
32
|
-
{children}
|
|
33
|
-
</Popover>
|
|
34
|
-
);
|
|
15
|
+
return (
|
|
16
|
+
<Menu
|
|
17
|
+
anchorEl={methods.anchorEl}
|
|
18
|
+
open={methods.isOpen}
|
|
19
|
+
onClose={methods.close}
|
|
20
|
+
sx={{ mt: 1, gap: 1, ...props?.sx }}
|
|
21
|
+
slots={{ transition: Collapse }}
|
|
22
|
+
{...props}
|
|
23
|
+
>
|
|
24
|
+
{children}
|
|
25
|
+
</Menu>
|
|
26
|
+
);
|
|
35
27
|
}
|
|
@@ -3,25 +3,36 @@ import React from 'react';
|
|
|
3
3
|
import { useDropdownContext } from '../hooks/useDropdownContext';
|
|
4
4
|
|
|
5
5
|
interface DropdownTriggerProps {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
onClick?: () => void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function DropdownTrigger({
|
|
11
|
-
|
|
10
|
+
export function DropdownTrigger({
|
|
11
|
+
children,
|
|
12
|
+
onClick,
|
|
13
|
+
}: DropdownTriggerProps): React.ReactElement {
|
|
14
|
+
const { open, setAnchorEl } = useDropdownContext();
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => {
|
|
17
|
+
if (event.detail === 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setAnchorEl(event.currentTarget);
|
|
21
|
+
open();
|
|
22
|
+
if (onClick) onClick();
|
|
23
|
+
};
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
return (
|
|
26
|
+
<ButtonBase
|
|
27
|
+
sx={{
|
|
28
|
+
position: 'relative',
|
|
29
|
+
width: '100%',
|
|
30
|
+
justifyContent: 'start',
|
|
31
|
+
}}
|
|
32
|
+
disableRipple
|
|
33
|
+
onClick={handleClick}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</ButtonBase>
|
|
37
|
+
);
|
|
27
38
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { DropdownContextType } from '../
|
|
2
|
+
import { DropdownContextType } from '../provider/DropdownContext';
|
|
3
3
|
|
|
4
4
|
interface DropdownHookProps {
|
|
5
|
-
|
|
5
|
+
onClose?: () => void;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export const useDropdown = (props?: DropdownHookProps): DropdownContextType => {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const toggle = (): void => setIsOpen(prev => !prev);
|
|
13
|
+
const open = (): void => {
|
|
14
|
+
setIsOpen(true);
|
|
15
|
+
};
|
|
16
|
+
const close = (): void => {
|
|
17
|
+
setIsOpen(false);
|
|
18
|
+
if (props?.onClose) props.onClose();
|
|
19
|
+
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
return { isOpen, toggle, open, close, anchorEl, setAnchorEl };
|
|
22
22
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import DropdownContext, {
|
|
2
|
+
import DropdownContext, {
|
|
3
|
+
DropdownContextType,
|
|
4
|
+
} from '../provider/DropdownContext';
|
|
3
5
|
|
|
4
6
|
export const useDropdownContext = (): DropdownContextType => {
|
|
5
|
-
|
|
7
|
+
const context = useContext(DropdownContext);
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useDropdown must be used within a DropdownProvider');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
11
13
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ClickAwayListener, Stack } from '@mui/material';
|
|
3
|
+
import { useDropdown } from '../hooks/useDropdown';
|
|
4
|
+
import DropdownContext from '../provider/DropdownContext';
|
|
5
|
+
|
|
6
|
+
interface DropdownProviderProps {
|
|
7
|
+
methods?: ReturnType<typeof useDropdown>;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function DropdownProvider({
|
|
13
|
+
methods,
|
|
14
|
+
children,
|
|
15
|
+
onClose,
|
|
16
|
+
}: DropdownProviderProps): React.ReactElement<DropdownProviderProps> {
|
|
17
|
+
const defaultMethods = useDropdown({ onClose: onClose });
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<DropdownContext.Provider value={methods ?? defaultMethods}>
|
|
21
|
+
<ClickAwayListener
|
|
22
|
+
onClickAway={methods ? methods.close : defaultMethods.close}
|
|
23
|
+
>
|
|
24
|
+
<Stack
|
|
25
|
+
flexDirection="column"
|
|
26
|
+
position="relative"
|
|
27
|
+
width="auto"
|
|
28
|
+
height="auto"
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</Stack>
|
|
32
|
+
</ClickAwayListener>
|
|
33
|
+
</DropdownContext.Provider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ClickAwayListener, Stack } from '@mui/material';
|
|
3
|
-
import { useDropdown } from '../hooks/useDropdown';
|
|
4
|
-
import DropdownContext from '../context/DropdownContext';
|
|
5
|
-
|
|
6
|
-
interface DropdownProviderProps {
|
|
7
|
-
methods?: ReturnType<typeof useDropdown>;
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
onClose?: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function DropdownProvider({
|
|
13
|
-
methods,
|
|
14
|
-
children,
|
|
15
|
-
onClose,
|
|
16
|
-
}: DropdownProviderProps): React.ReactElement<DropdownProviderProps> {
|
|
17
|
-
const defaultMethods = useDropdown({ onClose: onClose });
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<DropdownContext.Provider value={methods ?? defaultMethods}>
|
|
21
|
-
<ClickAwayListener onClickAway={methods ? methods.close : defaultMethods.close}>
|
|
22
|
-
<Stack flexDirection="column" position="relative" width="auto" height="auto">
|
|
23
|
-
{children}
|
|
24
|
-
</Stack>
|
|
25
|
-
</ClickAwayListener>
|
|
26
|
-
</DropdownContext.Provider>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
File without changes
|