@meonode/ui 0.1.34 → 0.1.36

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.
Files changed (2) hide show
  1. package/README.md +72 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -205,6 +205,7 @@ const LoginForm = Component(() =>
205
205
  ```
206
206
 
207
207
  ## Comprehensive Example: Theme-Switching & Conditional Components
208
+
208
209
  ```tsx
209
210
  'use client'
210
211
  /**
@@ -213,7 +214,19 @@ const LoginForm = Component(() =>
213
214
  * approaches, the use of Higher-Order Components (HOCs), and how theme context
214
215
  * is managed and propagated within the @meonode/ui component tree.
215
216
  */
216
- import { Button, Center, Column, Component, Fixed, Node, type NodeInstance, P, Portal, Row, type Theme } from '@meonode/ui'
217
+ import {
218
+ Button,
219
+ Center,
220
+ Column,
221
+ Component,
222
+ Fixed,
223
+ Node,
224
+ type NodeInstance,
225
+ P,
226
+ Portal,
227
+ Row,
228
+ type Theme
229
+ } from '@meonode/ui'
217
230
  import { useState, useEffect, ReactElement, ReactNode } from 'react'
218
231
  import { CssBaseline, FormControlLabel, TextField } from '@meonode/mui'
219
232
  import { Switch as MUISwitch } from '@mui/material'
@@ -602,18 +615,70 @@ const Modal = Portal(({ theme, portal }) => {
602
615
  })
603
616
  ```
604
617
 
618
+ ## Passing Context Wrapper To Portal
619
+ ```ts
620
+ import { Provider, useSelector } from 'react-redux'
621
+ import store from '/path/to/redux/store'
622
+
623
+ /**
624
+ * ReduxProvider
625
+ *
626
+ * A wrapper component that integrates the Redux store with a React application.
627
+ * It utilizes the `Provider` component from `react-redux` to make the Redux store
628
+ * available to the entire component tree.
629
+ *
630
+ * @constant
631
+ * @type {ReactNode}
632
+ * @param {Object} store - The Redux store instance to be passed down to the application.
633
+ */
634
+ const ReduxProvider = Node(Provider, { store })
635
+
636
+ /**
637
+ * Represents a modal component that is implemented using a portal
638
+ * and wrapped with a Redux provider. This component retrieves state
639
+ * from the Redux store and responds to state changes.
640
+ *
641
+ * The `Modal` leverages the Redux `useSelector` hook to access specific
642
+ * Redux state values and ensure dynamic behavior within the modal based
643
+ * on the application's state.
644
+ *
645
+ * Dependencies:
646
+ * - ReduxProvider: Ensures the modal has access to the Redux store.
647
+ * - Portal: Renders the modal outside of its parent hierarchy and provides
648
+ * control methods such as `unmount` for cleaning up the modal.
649
+ * - useSelector: Accesses specific data from the Redux state.
650
+ *
651
+ * Side Effects:
652
+ * - The component logs the specific Redux state changes to the console
653
+ * when the state is updated.
654
+ * - The modal listens for specific user interactions (e.g., clicking outside
655
+ * the modal area) and programmatically unmounts itself using `portal.unmount()`.
656
+ *
657
+ * Props:
658
+ * - portal: Includes a method `unmount` to remove the modal from the DOM.
659
+ */
660
+ const Modal = Portal(ReduxProvider, ({ portal }) => {
661
+ const someReduxState = useSelector(state => state.someReduxState)
662
+
663
+ useEffect(() => {
664
+ console.log('Redux State value: ', someReduxState)
665
+ }, [])
666
+
667
+ // ...
668
+ })
669
+ ```
670
+
605
671
  ---
606
672
 
607
673
  ## API Reference
608
674
 
609
675
  ### Core Functions
610
676
 
611
- | Function | Parameters | Description |
612
- |-------------|--------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
613
- | `Node` | `element: NodeElement \| React.ComponentType`, `baseProps: object` | Constructs a configurable UI node that supports flexible properties and dynamic styling. |
614
- | `Component` | `(props: P) => ComponentNode` | Transforms node trees into reusable React components with built-in type safety and seamless integration. |
615
- | `Portal` | `(props: P) => ComponentNode` | Converts node trees to React components and renders them in a React Portal with advanced DOM placement. |
616
- |
677
+ | Function | Parameters | Description |
678
+ |-------------|---------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
679
+ | `Node` | `element: NodeElement \| React.ComponentType`, `baseProps: object` | Constructs a configurable UI node that supports flexible properties and dynamic styling. |
680
+ | `Component` | `(props: P) => ComponentNode` | Transforms node trees into reusable React components with built-in type safety and seamless integration. |
681
+ | `Portal` | `(component: (props: P) => ComponentNode)` or <br/> `(providers: NodeElement \| NodeElement[], component: (props: P) => ComponentNode)` | Creates a React Portal component. Accepts either a component function directly, or a tuple of providers (e.g. Redux Provider) and the component. The component receives portal controls for mounting/unmounting. |
617
682
 
618
683
  ---
619
684
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meonode/ui",
3
3
  "description": "A structured approach to component composition with built-in theming, prop separation, and dynamic children handling.",
4
- "version": "0.1.34",
4
+ "version": "0.1.36",
5
5
  "type": "module",
6
6
  "main": "./dist/main.js",
7
7
  "types": "./dist/main.d.ts",