@sonardigital/carbon-ui 1.1.49 → 1.1.52

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.49",
3
+ "version": "1.1.52",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -0,0 +1,44 @@
1
+ import { Modal, Stack, SxProps } from '@mui/material';
2
+ import React from 'react';
3
+ import { useModalContext } from '../hooks/useModalContext';
4
+
5
+ interface ModalContentProps {
6
+ children: React.ReactElement;
7
+ sx?: SxProps;
8
+ }
9
+
10
+ export function ModalContent({ children, sx }: ModalContentProps): React.ReactElement {
11
+ const { isOpen, close } = useModalContext();
12
+
13
+ return (
14
+ <Modal onClose={close} open={isOpen}>
15
+ <Stack
16
+ bgcolor="background.default"
17
+ paddingY={1}
18
+ zIndex={1200}
19
+ border="none"
20
+ sx={{
21
+ borderRadius: 2,
22
+ position: 'absolute',
23
+ top: '50%',
24
+ left: '50%',
25
+ outline: 'none',
26
+ transform: 'translate(-50%, -50%)',
27
+ boxSizing: 'border-box',
28
+ padding: 5,
29
+ minHeight: {
30
+ sx: 500,
31
+ sm: 300,
32
+ },
33
+ minWidth: {
34
+ xs: '100%',
35
+ sm: 600,
36
+ },
37
+ ...sx,
38
+ }}
39
+ >
40
+ {children}
41
+ </Stack>
42
+ </Modal>
43
+ );
44
+ }
@@ -0,0 +1,17 @@
1
+ import { Stack } from '@mui/material';
2
+ import React from 'react';
3
+ import { useModalContext } from '../hooks/useModalContext';
4
+
5
+ interface ModalTriggerProps {
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ export function ModalTrigger({ children }: ModalTriggerProps): React.ReactElement {
10
+ const { open } = useModalContext();
11
+
12
+ return (
13
+ <Stack sx={{ position: 'relative' }} onClick={open}>
14
+ {children}
15
+ </Stack>
16
+ );
17
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ModalTrigger';
2
+ export * from './ModalContent';
@@ -0,0 +1,2 @@
1
+ export * from './useModal';
2
+ export * from './useModalContext';
@@ -0,0 +1,19 @@
1
+ import { useState } from 'react';
2
+ import { ModalContextType } from '../provider/ModalContext';
3
+
4
+ export const useModal = (props?: { isOpen?: boolean }): ModalContextType => {
5
+ const [isOpen, setIsOpen] = useState(props?.isOpen || false);
6
+
7
+ const open = (): void => {
8
+ setIsOpen(true);
9
+ };
10
+ const close = (): void => {
11
+ setIsOpen(false);
12
+ };
13
+
14
+ return {
15
+ isOpen,
16
+ open,
17
+ close,
18
+ };
19
+ };
@@ -0,0 +1,11 @@
1
+ import { useContext } from 'react';
2
+ import ModalContext, { ModalContextType } from '../provider/ModalContext';
3
+
4
+ export const useModalContext = (): ModalContextType => {
5
+ const context = useContext(ModalContext);
6
+
7
+ if (!context) {
8
+ throw new Error('useModal must be used within a DialogProvider');
9
+ }
10
+ return context;
11
+ };
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from './provider';
@@ -0,0 +1,15 @@
1
+ import { Context, createContext } from 'react';
2
+
3
+ export interface ModalContextType {
4
+ isOpen: boolean;
5
+ open: () => void;
6
+ close: () => void;
7
+ }
8
+
9
+ const ModalContext: Context<ModalContextType> = createContext<ModalContextType>({
10
+ isOpen: false,
11
+ open: () => {},
12
+ close: () => {},
13
+ });
14
+
15
+ export default ModalContext;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { useModal } from '../hooks/useModal';
3
+ import ModalContext from './ModalContext';
4
+
5
+ interface ModalProviderProps {
6
+ children: React.ReactNode;
7
+ methods: ReturnType<typeof useModal>;
8
+ }
9
+
10
+ export function ModalProvider({
11
+ methods,
12
+ children,
13
+ }: ModalProviderProps): React.ReactElement<ModalProviderProps> {
14
+ return <ModalContext.Provider value={methods}>{children}</ModalContext.Provider>;
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ModalProvider';
2
+ export * from './ModalContext';
@@ -3,3 +3,4 @@ export * from './Dropdown';
3
3
  export * from './ScrollToTop/ScrollToTop';
4
4
  export * from './error-boundary';
5
5
  export * from './delay';
6
+ export * from './Modal';