@sonardigital/carbon-ui 1.1.38 → 1.1.40

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonardigital/carbon-ui",
3
- "version": "1.1.38",
3
+ "version": "1.1.40",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,12 +1,8 @@
1
1
  import { MenuItem } from '@mui/material';
2
- import { useDropdown } from 'src/components/layout';
2
+ import { useDropdown } from '../hooks';
3
3
 
4
- export function DropdownItem({
5
- children,
6
- }: {
7
- children: React.ReactNode;
8
- }): React.ReactElement {
9
- const methods = useDropdown();
4
+ export function DropdownItem({ children }: { children: React.ReactNode }): React.ReactElement {
5
+ const methods = useDropdown();
10
6
 
11
- return <MenuItem onClick={methods.close}>{children}</MenuItem>;
7
+ return <MenuItem onClick={methods.close}>{children}</MenuItem>;
12
8
  }
@@ -3,25 +3,22 @@ import React from 'react';
3
3
  import { useDropdownContext } from '../hooks/useDropdownContext';
4
4
 
5
5
  interface PopoverProviderProps extends Omit<MenuProps, 'open'> {
6
- children: React.ReactNode;
6
+ children: React.ReactNode;
7
7
  }
8
8
 
9
- export function DropdownPopover({
10
- children,
11
- ...props
12
- }: PopoverProviderProps): React.ReactElement {
13
- const methods = useDropdownContext();
9
+ export function DropdownPopover({ children, ...props }: PopoverProviderProps): React.ReactElement {
10
+ const methods = useDropdownContext();
14
11
 
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
- );
12
+ return (
13
+ <Menu
14
+ anchorEl={methods.anchorEl}
15
+ open={methods.isOpen}
16
+ onClose={methods.close}
17
+ sx={{ mt: 1, gap: 1, ...props?.sx }}
18
+ slots={{ transition: Collapse }}
19
+ {...props}
20
+ >
21
+ {children}
22
+ </Menu>
23
+ );
27
24
  }
@@ -3,36 +3,33 @@ import React from 'react';
3
3
  import { useDropdownContext } from '../hooks/useDropdownContext';
4
4
 
5
5
  interface DropdownTriggerProps {
6
- children: React.ReactNode;
7
- onClick?: () => void;
6
+ children: React.ReactNode;
7
+ onClick?: () => void;
8
8
  }
9
9
 
10
- export function DropdownTrigger({
11
- children,
12
- onClick,
13
- }: DropdownTriggerProps): React.ReactElement {
14
- const { open, setAnchorEl } = useDropdownContext();
10
+ export function DropdownTrigger({ children, onClick }: DropdownTriggerProps): React.ReactElement {
11
+ const { open, setAnchorEl } = useDropdownContext();
15
12
 
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
- };
13
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => {
14
+ if (event.detail === 0) {
15
+ return;
16
+ }
17
+ setAnchorEl(event.currentTarget);
18
+ open();
19
+ if (onClick) onClick();
20
+ };
24
21
 
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
- );
22
+ return (
23
+ <ButtonBase
24
+ sx={{
25
+ position: 'relative',
26
+ width: '100%',
27
+ justifyContent: 'start',
28
+ }}
29
+ disableRipple
30
+ onClick={handleClick}
31
+ >
32
+ {children}
33
+ </ButtonBase>
34
+ );
38
35
  }
@@ -2,21 +2,21 @@ import { useState } from 'react';
2
2
  import { DropdownContextType } from '../provider/DropdownContext';
3
3
 
4
4
  interface DropdownHookProps {
5
- onClose?: () => void;
5
+ onClose?: () => void;
6
6
  }
7
7
 
8
8
  export const useDropdown = (props?: DropdownHookProps): DropdownContextType => {
9
- const [isOpen, setIsOpen] = useState(false);
10
- const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
9
+ const [isOpen, setIsOpen] = useState(false);
10
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
11
11
 
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
- };
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
- return { isOpen, toggle, open, close, anchorEl, setAnchorEl };
21
+ return { isOpen, toggle, open, close, anchorEl, setAnchorEl };
22
22
  };
@@ -1,13 +1,11 @@
1
1
  import { useContext } from 'react';
2
- import DropdownContext, {
3
- DropdownContextType,
4
- } from '../provider/DropdownContext';
2
+ import DropdownContext, { DropdownContextType } from '../provider/DropdownContext';
5
3
 
6
4
  export const useDropdownContext = (): DropdownContextType => {
7
- const context = useContext(DropdownContext);
5
+ const context = useContext(DropdownContext);
8
6
 
9
- if (!context) {
10
- throw new Error('useDropdown must be used within a DropdownProvider');
11
- }
12
- return context;
7
+ if (!context) {
8
+ throw new Error('useDropdown must be used within a DropdownProvider');
9
+ }
10
+ return context;
13
11
  };
@@ -1,2 +1,3 @@
1
1
  export * from './components';
2
2
  export * from './hooks';
3
+ export * from './provider';
@@ -4,32 +4,25 @@ import { useDropdown } from '../hooks/useDropdown';
4
4
  import DropdownContext from '../provider/DropdownContext';
5
5
 
6
6
  interface DropdownProviderProps {
7
- methods?: ReturnType<typeof useDropdown>;
8
- children: React.ReactNode;
9
- onClose?: () => void;
7
+ methods?: ReturnType<typeof useDropdown>;
8
+ children: React.ReactNode;
9
+ onClose?: () => void;
10
10
  }
11
11
 
12
12
  export function DropdownProvider({
13
- methods,
14
- children,
15
- onClose,
13
+ methods,
14
+ children,
15
+ onClose,
16
16
  }: DropdownProviderProps): React.ReactElement<DropdownProviderProps> {
17
- const defaultMethods = useDropdown({ onClose: onClose });
17
+ const defaultMethods = useDropdown({ onClose: onClose });
18
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
- );
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
+ );
35
28
  }