@soul-refiner/design-system 0.2.49 → 0.2.51

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.
@@ -1,13 +1,19 @@
1
1
  import React from 'react';
2
2
  export interface ModalProps extends React.PropsWithChildren {
3
+ /**
4
+ * This will always render the content, but not display it
5
+ * Defaults to true
6
+ */
7
+ alwaysRender?: boolean;
3
8
  /**
4
9
  * This is to make the Modal a controlled component,
5
10
  * instead of it managing its own state
6
11
  */
7
12
  controlledOpen?: boolean;
13
+ onChange?: (open?: boolean) => void;
8
14
  }
9
15
  declare const Modal: {
10
- ({ controlledOpen, ...props }: ModalProps): React.JSX.Element;
16
+ ({ alwaysRender, controlledOpen, onChange, children, ...props }: ModalProps): React.JSX.Element;
11
17
  Trigger: {
12
18
  ({ children: child, }: {
13
19
  children: React.ReactElement;
@@ -5,14 +5,30 @@ import { Button } from '../../';
5
5
  import { Close } from '../../../icons';
6
6
  import { callAll } from '../../../utils';
7
7
  const ModalContext = React.createContext([false, (() => undefined)]);
8
- const Modal = ({ controlledOpen, ...props }) => {
8
+ const Modal = ({ alwaysRender = true, controlledOpen, onChange, children, ...props }) => {
9
9
  const [open, setOpen] = React.useState(controlledOpen || false);
10
10
  React.useEffect(() => {
11
11
  if (controlledOpen !== undefined) {
12
12
  setOpen(controlledOpen);
13
13
  }
14
14
  }, [controlledOpen]);
15
- return React.createElement(ModalContext.Provider, { value: [open, setOpen], ...props });
15
+ React.useEffect(() => {
16
+ onChange && onChange(open);
17
+ }, [open]);
18
+ let trigger;
19
+ const rest = [];
20
+ React.Children.forEach(children, (child) => {
21
+ const type = React.isValidElement(child) && child.type?.displayName;
22
+ if (type && type.toLowerCase().includes('trigger')) {
23
+ trigger = child;
24
+ }
25
+ else {
26
+ rest.push(child);
27
+ }
28
+ });
29
+ return (React.createElement(ModalContext.Provider, { value: [open, setOpen], ...props },
30
+ trigger,
31
+ (open || alwaysRender) && rest));
16
32
  };
17
33
  const ModalTrigger = ({ children: child, }) => {
18
34
  const [, setOpen] = React.useContext(ModalContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.49",
3
+ "version": "0.2.51",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {