@latte-macchiat-io/latte-vanilla-components 0.0.233 → 0.0.235
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
@@ -10,31 +10,36 @@ import { Actions } from '../Actions';
|
|
10
10
|
import { Button } from '../Button';
|
11
11
|
import { Icon } from '../Icon';
|
12
12
|
|
13
|
+
type ModalRenderProp = (args: { closeModal: () => void }) => React.ReactNode;
|
14
|
+
|
13
15
|
export type ModalProps = React.HTMLAttributes<HTMLDivElement> &
|
14
16
|
ModalVariants & {
|
15
17
|
triggerLabel: string;
|
16
|
-
children: React.ReactNode;
|
17
18
|
withCloseButton?: boolean;
|
19
|
+
children: React.ReactNode | ModalRenderProp;
|
18
20
|
};
|
19
21
|
|
20
22
|
export const Modal = ({ triggerLabel, className, children, align, withCloseButton = false }: ModalProps) => {
|
21
23
|
const [isOpen, setIsOpen] = useState(false);
|
22
24
|
|
25
|
+
const closeModal = () => setIsOpen(false);
|
26
|
+
|
23
27
|
return (
|
24
28
|
<>
|
25
29
|
<Actions align="center">
|
26
|
-
<Button onClick={() => setIsOpen(true)}>
|
30
|
+
<Button onClick={() => setIsOpen(true)}>{triggerLabel}</Button>
|
27
31
|
</Actions>
|
28
32
|
|
29
33
|
{isOpen && (
|
30
34
|
<div className={modal} role="dialog" aria-modal="true">
|
31
35
|
<div className={clsx(modalContentRecipe({ align }), className)}>
|
32
36
|
{withCloseButton && (
|
33
|
-
<button type="button"
|
37
|
+
<button type="button" className={modalContentCloseButton} onClick={closeModal} aria-label="Close modal">
|
34
38
|
<Icon icon="close" color={themeContract.modal.closeButtonColor} />
|
35
39
|
</button>
|
36
40
|
)}
|
37
|
-
|
41
|
+
|
42
|
+
{typeof children === 'function' ? (children as ModalRenderProp)({ closeModal }) : children}
|
38
43
|
</div>
|
39
44
|
</div>
|
40
45
|
)}
|