@latte-macchiat-io/latte-vanilla-components 0.0.235 → 0.0.236
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,7 +1,7 @@
|
|
1
1
|
'use client';
|
2
2
|
|
3
3
|
import { clsx } from 'clsx';
|
4
|
-
import { useState } from 'react';
|
4
|
+
import { ReactNode, useState } from 'react';
|
5
5
|
|
6
6
|
import { modal, modalContentCloseButton, modalContentRecipe, type ModalVariants } from './styles.css';
|
7
7
|
|
@@ -10,13 +10,13 @@ import { Actions } from '../Actions';
|
|
10
10
|
import { Button } from '../Button';
|
11
11
|
import { Icon } from '../Icon';
|
12
12
|
|
13
|
-
type ModalRenderProp = (args: { closeModal: () => void }) =>
|
13
|
+
type ModalRenderProp = (args: { closeModal: () => void }) => ReactNode;
|
14
14
|
|
15
15
|
export type ModalProps = React.HTMLAttributes<HTMLDivElement> &
|
16
16
|
ModalVariants & {
|
17
17
|
triggerLabel: string;
|
18
18
|
withCloseButton?: boolean;
|
19
|
-
children:
|
19
|
+
children: ReactNode | ModalRenderProp;
|
20
20
|
};
|
21
21
|
|
22
22
|
export const Modal = ({ triggerLabel, className, children, align, withCloseButton = false }: ModalProps) => {
|
@@ -24,6 +24,13 @@ export const Modal = ({ triggerLabel, className, children, align, withCloseButto
|
|
24
24
|
|
25
25
|
const closeModal = () => setIsOpen(false);
|
26
26
|
|
27
|
+
const renderChildren = () => {
|
28
|
+
if (typeof children === 'function') {
|
29
|
+
return (children as ModalRenderProp)({ closeModal });
|
30
|
+
}
|
31
|
+
return children;
|
32
|
+
};
|
33
|
+
|
27
34
|
return (
|
28
35
|
<>
|
29
36
|
<Actions align="center">
|
@@ -39,7 +46,7 @@ export const Modal = ({ triggerLabel, className, children, align, withCloseButto
|
|
39
46
|
</button>
|
40
47
|
)}
|
41
48
|
|
42
|
-
{
|
49
|
+
{renderChildren()}
|
43
50
|
</div>
|
44
51
|
</div>
|
45
52
|
)}
|