@mirohq/design-system-utils
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -16,2 +16,9 @@ 'use strict'; | ||
const isFragment = (fragment) => (fragment == null ? void 0 : fragment.type) === react.Fragment || fragment === react.Fragment; | ||
const addPropsToChildren = (children, containsComponent, props) => react.Children.map(react.Children.toArray(children), (child) => { | ||
const childElement = child; | ||
if (containsComponent(childElement)) { | ||
return react.cloneElement(childElement, { ...childElement.props, ...props }); | ||
} | ||
return children; | ||
}); | ||
@@ -31,2 +38,3 @@ const mapKeysToVariants = (map, prop) => Object.keys(map).reduce((acc, key) => { | ||
exports.addPropsToChildren = addPropsToChildren; | ||
exports.createConstants = createConstants; | ||
@@ -33,0 +41,0 @@ exports.isFragment = isFragment; |
@@ -1,2 +0,2 @@ | ||
import { Fragment } from 'react'; | ||
import { Fragment, Children, cloneElement } from 'react'; | ||
@@ -12,2 +12,9 @@ const createConstants = (...constants) => constants.reduce( | ||
const isFragment = (fragment) => (fragment == null ? void 0 : fragment.type) === Fragment || fragment === Fragment; | ||
const addPropsToChildren = (children, containsComponent, props) => Children.map(Children.toArray(children), (child) => { | ||
const childElement = child; | ||
if (containsComponent(childElement)) { | ||
return cloneElement(childElement, { ...childElement.props, ...props }); | ||
} | ||
return children; | ||
}); | ||
@@ -27,3 +34,3 @@ const mapKeysToVariants = (map, prop) => Object.keys(map).reduce((acc, key) => { | ||
export { createConstants, isFragment, mapKeysToVariants }; | ||
export { addPropsToChildren, createConstants, isFragment, mapKeysToVariants }; | ||
//# sourceMappingURL=module.js.map |
@@ -0,1 +1,2 @@ | ||
import { ReactNode, ReactElement } from 'react'; | ||
import * as _stitches_react_types_css_util from '@stitches/react/types/css-util'; | ||
@@ -7,2 +8,10 @@ import { CSSProperties } from '@stitches/react'; | ||
declare const isFragment: (fragment: any) => boolean; | ||
/** | ||
* Search a specific component by displayName inside of a children and replaces or adds a set of new props. | ||
* @param children ReactNode where the search for the component by name will take place. | ||
* @param containsComponent Function validating if props should be overridden. | ||
* @param props props to be merged with existing props from the targe component. | ||
* @returns Same children element but with the component and its props replaced if it was found. | ||
*/ | ||
declare const addPropsToChildren: <T>(children: ReactNode, containsComponent: (child: ReactElement) => boolean, props: Partial<T>) => ReactNode; | ||
@@ -25,2 +34,2 @@ declare type KeyVariants<KeyMap, Prop extends keyof CSSProperties> = { | ||
export { createConstants, isFragment, mapKeysToVariants }; | ||
export { addPropsToChildren, createConstants, isFragment, mapKeysToVariants }; |
{ | ||
"name": "@mirohq/design-system-utils", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Miro", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12226
94