Skip to content

Commit

Permalink
feat : wrapper for all components
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutesa-Cedric committed Sep 25, 2023
1 parent 61d9613 commit 52be1ca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/HOC/wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
export default function Wrapper() {
import React from 'react'

// @ts-expect-error(type declaration missing)
import RevealBase from '../lib/Base.js'

/**
* this function is a wrapper for all the reveal components
* @param {object} props
* @param {boolean} props.when
* @param {boolean} props.in

Check warning on line 10 in src/HOC/wrapper.tsx

View workflow job for this annotation

GitHub Actions / lint

Syntax error in namepath: props.in
* @param {string} props.inEffect

Check warning on line 11 in src/HOC/wrapper.tsx

View workflow job for this annotation

GitHub Actions / lint

@param "props.inEffect" does not exist on props
* @param {string} props.outEffect

Check warning on line 12 in src/HOC/wrapper.tsx

View workflow job for this annotation

GitHub Actions / lint

@param "props.outEffect" does not exist on props
* @param {React.ReactNode} children
* @returns {React.ReactNode}

Check warning on line 14 in src/HOC/wrapper.tsx

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns description
*/
export default function wrapper(props: { when: any; in: any }, inEffect: any, outEffect: any, children: string | number | boolean |
React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined) {
if ('in' in props)
props.when = props.in
// check if children is a single element
if (React.Children.count(children) < 2)
return <RevealBase {...props} inEffect={inEffect} outEffect={outEffect} children={children} />
// map through elements if children is an array
children = React.Children.map(children, child =>
<RevealBase {...props} inEffect={inEffect} outEffect={outEffect} children={child} />,
)
return 'Fragment' in React ? <React.Fragment>{children}</React.Fragment> : <span>{children}</span>
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es2018",
"lib": ["esnext", "DOM", "ES6"],
"jsx": "react",
"module": "esnext",
"moduleResolution": "node",
"paths": {
Expand Down

0 comments on commit 52be1ca

Please sign in to comment.