@latte-macchiat-io/latte-vanilla-components 0.0.234 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@latte-macchiat-io/latte-vanilla-components",
3
- "version": "0.0.234",
3
+ "version": "0.0.236",
4
4
  "description": "Beautiful components for amazing projects, with a touch of Vanilla 🥤",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -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,11 +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 }) => ReactNode;
14
+
13
15
  export type ModalProps = React.HTMLAttributes<HTMLDivElement> &
14
16
  ModalVariants & {
15
17
  triggerLabel: string;
16
18
  withCloseButton?: boolean;
17
- children: React.ReactNode | ((args: { closeModal: () => void }) => React.ReactNode);
19
+ children: ReactNode | ModalRenderProp;
18
20
  };
19
21
 
20
22
  export const Modal = ({ triggerLabel, className, children, align, withCloseButton = false }: ModalProps) => {
@@ -22,6 +24,13 @@ export const Modal = ({ triggerLabel, className, children, align, withCloseButto
22
24
 
23
25
  const closeModal = () => setIsOpen(false);
24
26
 
27
+ const renderChildren = () => {
28
+ if (typeof children === 'function') {
29
+ return (children as ModalRenderProp)({ closeModal });
30
+ }
31
+ return children;
32
+ };
33
+
25
34
  return (
26
35
  <>
27
36
  <Actions align="center">
@@ -37,7 +46,7 @@ export const Modal = ({ triggerLabel, className, children, align, withCloseButto
37
46
  </button>
38
47
  )}
39
48
 
40
- {typeof children === 'function' ? children({ closeModal }) : children}
49
+ {renderChildren()}
41
50
  </div>
42
51
  </div>
43
52
  )}