Skip to content

Commit e0af5db

Browse files
authored
AlertDialog Component (#448)
1 parent ac48ceb commit e0af5db

File tree

17 files changed

+1600
-1541
lines changed

17 files changed

+1600
-1541
lines changed

.babelrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
}
1616
}
1717
]
18+
],
19+
"ignore": [
20+
"docs/**"
1821
]
1922
}

package-lock.json

Lines changed: 1320 additions & 1539 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/tools/SandboxEditor/SandboxEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const ColorSelect = ({ color, colorName, changeAccentColor }: ColorSelectProps)
2828
style={{ width: dimensions, height: dimensions, backgroundColor: color.light['900'] }}></div>;
2929
};
3030

31-
type SandboxProps = {className: string} & PropsWithChildren
31+
type SandboxProps = {className?: string} & PropsWithChildren
3232

3333
const SandboxEditor = ({ children, className } : SandboxProps) => {
3434
const [isDarkMode, setIsDarkMode] = useState(false);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useState } from 'react';
2+
import AlertDialogRoot from './shards/AlertDialogRoot';
3+
import AlertDialogContent from './shards/AlertDialogContent';
4+
import AlertDialogTrigger from './shards/AlertDialogTrigger';
5+
import AlertDialogPortal from './shards/AlertDialogPortal';
6+
import AlertDialogOverlay from './shards/AlertDialogOverlay';
7+
import AlertDialogCancel from './shards/AlertDialogCancel';
8+
import AlertDialogAction from './shards/AlertDialogAction';
9+
export type AlertDialogProps = {
10+
children: React.ReactNode;
11+
content: React.ReactNode;
12+
open?: boolean;
13+
onOpenChange?: (open: boolean) => void;
14+
}
15+
16+
const AlertDialog = ({ children, open = false, onOpenChange, content } : AlertDialogProps) => {
17+
const [isOpen, setIsOpen] = useState(open);
18+
return (
19+
<AlertDialogRoot open={isOpen} onOpenChange={onOpenChange} >
20+
<AlertDialogTrigger>
21+
{children}
22+
</AlertDialogTrigger>
23+
24+
<AlertDialogPortal>
25+
<AlertDialogOverlay/>
26+
<AlertDialogContent>
27+
{content}
28+
<AlertDialogCancel>
29+
Cancel
30+
</AlertDialogCancel>
31+
<AlertDialogAction>
32+
Action
33+
</AlertDialogAction>
34+
</AlertDialogContent>
35+
36+
</AlertDialogPortal>
37+
38+
</AlertDialogRoot>
39+
);
40+
};
41+
42+
export default AlertDialog;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createContext } from 'react';
2+
3+
export const AlertDialogContext = createContext({
4+
5+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { useContext } from 'react';
2+
import { AlertDialogContext } from '../contexts/AlertDialogContext';
3+
import ButtonPrimitive from '~/core/primitives/Button';
4+
5+
export type AlertDialogActionProps = {
6+
children: React.ReactNode;
7+
}
8+
9+
const AlertDialogAction = ({ children } : AlertDialogActionProps) => {
10+
const { handleOpenChange } = useContext(AlertDialogContext);
11+
return (
12+
<ButtonPrimitive onClick={() => handleOpenChange(false)}>
13+
{children}
14+
</ButtonPrimitive>
15+
);
16+
};
17+
18+
export default AlertDialogAction;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { useContext } from 'react';
2+
import { AlertDialogContext } from '../contexts/AlertDialogContext';
3+
import ButtonPrimitive from '~/core/primitives/Button';
4+
5+
export type AlertDialogCancelProps = {
6+
children: React.ReactNode;
7+
}
8+
9+
const AlertDialogCancel = ({ children } : AlertDialogCancelProps) => {
10+
const { handleOpenChange } = useContext(AlertDialogContext);
11+
return (
12+
<ButtonPrimitive onClick={() => handleOpenChange(false)}>
13+
{children}
14+
</ButtonPrimitive>
15+
);
16+
};
17+
18+
export default AlertDialogCancel;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { useContext } from 'react';
2+
import { AlertDialogContext } from '../contexts/AlertDialogContext';
3+
4+
export type AlertDialogContentProps = {
5+
children: React.ReactNode;
6+
}
7+
8+
const AlertDialogContent = ({ children } : AlertDialogContentProps) => {
9+
const { isOpen, rootClass } = useContext(AlertDialogContext);
10+
11+
return (
12+
<>
13+
{isOpen && (
14+
<div className={`${rootClass}-content`}>
15+
{children}
16+
</div>
17+
)}
18+
</>
19+
);
20+
};
21+
22+
export default AlertDialogContent;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useContext } from 'react';
2+
import Floater from '~/core/primitives/Floater';
3+
import { AlertDialogContext } from '../contexts/AlertDialogContext';
4+
5+
const AlertDialogOverlay = () => {
6+
const { isOpen, rootClass, handleOverlayClick } = useContext(AlertDialogContext);
7+
return (
8+
<>
9+
{isOpen && (
10+
<Floater.Overlay
11+
className={`${rootClass}-overlay`} onClick={handleOverlayClick}>
12+
13+
</Floater.Overlay>
14+
)}
15+
</>
16+
);
17+
};
18+
19+
export default AlertDialogOverlay;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import Floater from '~/core/primitives/Floater';
3+
4+
export type AlertDialogPortalProps = {
5+
children: React.ReactNode;
6+
}
7+
8+
const AlertDialogPortal = ({ children } : AlertDialogPortalProps) => {
9+
return (
10+
<Floater.Portal>
11+
{children}
12+
</Floater.Portal>
13+
);
14+
};
15+
16+
export default AlertDialogPortal;

0 commit comments

Comments
 (0)