@rpxl/recast
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -31,16 +31,22 @@ "use strict"; | ||
function recast(Component, styles, mergeFn) { | ||
const ComponentWithThemedProps = (0, react_1.forwardRef)(({ ...props }, ref) => { | ||
const ComponentWithThemedProps = (0, react_1.forwardRef)((props, ref) => { | ||
const { className, ...restProps } = props; | ||
// Get keys of all modifier props and construct a `modifier` array | ||
const modifierKeys = Object.keys(styles.modifiers || {}); | ||
const modifierProps = modifierKeys.filter((x) => !!props[x]); | ||
const modifierProps = modifierKeys.filter((x) => { | ||
const key = x; | ||
return key in restProps && restProps[key] !== undefined && restProps[key] !== false; | ||
}); | ||
// Get keys of all variant props and construct a `variants` object | ||
const variantKeys = Object.keys(styles.variants || {}); | ||
const variantProps = variantKeys.reduce((acc, curr) => ({ | ||
...acc, | ||
...(props[curr] ? { [curr]: props[curr] } : {}), | ||
}), {}); | ||
const variantProps = variantKeys.reduce((acc, curr) => { | ||
if (curr in restProps && restProps[curr] !== undefined) { | ||
acc[curr] = restProps[curr]; | ||
} | ||
return acc; | ||
}, {}); | ||
// Remove `modifierKeys` and `variantKeys` from props | ||
// to avoid passing them to the underlying component | ||
const propsWithoutModifiersAndVariants = (0, omit_js_1.omit)([...modifierKeys, ...variantKeys, "className"], props); | ||
const { className, rcx } = (0, getRecastClasses_js_1.getRecastClasses)({ | ||
const propsWithoutModifiersAndVariants = (0, omit_js_1.omit)([...modifierKeys, ...variantKeys, "className"], restProps); | ||
const { className: recastClassesClassName, rcx } = (0, getRecastClasses_js_1.getRecastClasses)({ | ||
styles, | ||
@@ -51,4 +57,4 @@ variants: variantProps, | ||
const mergedClassNames = mergeFn | ||
? mergeFn(className, props.className) | ||
: className.concat(" ", props.className || ""); | ||
? mergeFn(recastClassesClassName, className) | ||
: recastClassesClassName.concat(" ", className || ""); | ||
return (react_1.default.createElement(Component, { ref: ref, className: mergedClassNames, ...(Object.keys(rcx).length > 0 && { rcx }), ...propsWithoutModifiersAndVariants })); | ||
@@ -55,0 +61,0 @@ }); |
@@ -5,16 +5,22 @@ import React, { forwardRef } from "react"; | ||
export function recast(Component, styles, mergeFn) { | ||
const ComponentWithThemedProps = forwardRef(({ ...props }, ref) => { | ||
const ComponentWithThemedProps = forwardRef((props, ref) => { | ||
const { className, ...restProps } = props; | ||
// Get keys of all modifier props and construct a `modifier` array | ||
const modifierKeys = Object.keys(styles.modifiers || {}); | ||
const modifierProps = modifierKeys.filter((x) => !!props[x]); | ||
const modifierProps = modifierKeys.filter((x) => { | ||
const key = x; | ||
return key in restProps && restProps[key] !== undefined && restProps[key] !== false; | ||
}); | ||
// Get keys of all variant props and construct a `variants` object | ||
const variantKeys = Object.keys(styles.variants || {}); | ||
const variantProps = variantKeys.reduce((acc, curr) => ({ | ||
...acc, | ||
...(props[curr] ? { [curr]: props[curr] } : {}), | ||
}), {}); | ||
const variantProps = variantKeys.reduce((acc, curr) => { | ||
if (curr in restProps && restProps[curr] !== undefined) { | ||
acc[curr] = restProps[curr]; | ||
} | ||
return acc; | ||
}, {}); | ||
// Remove `modifierKeys` and `variantKeys` from props | ||
// to avoid passing them to the underlying component | ||
const propsWithoutModifiersAndVariants = omit([...modifierKeys, ...variantKeys, "className"], props); | ||
const { className, rcx } = getRecastClasses({ | ||
const propsWithoutModifiersAndVariants = omit([...modifierKeys, ...variantKeys, "className"], restProps); | ||
const { className: recastClassesClassName, rcx } = getRecastClasses({ | ||
styles, | ||
@@ -25,4 +31,4 @@ variants: variantProps, | ||
const mergedClassNames = mergeFn | ||
? mergeFn(className, props.className) | ||
: className.concat(" ", props.className || ""); | ||
? mergeFn(recastClassesClassName, className) | ||
: recastClassesClassName.concat(" ", className || ""); | ||
return (React.createElement(Component, { ref: ref, className: mergedClassNames, ...(Object.keys(rcx).length > 0 && { rcx }), ...propsWithoutModifiersAndVariants })); | ||
@@ -29,0 +35,0 @@ }); |
{ | ||
"name": "@rpxl/recast", | ||
"license": "MIT", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"type": "module", | ||
@@ -45,7 +45,7 @@ "sideEffects": false, | ||
"devDependencies": { | ||
"@testing-library/react": "^14.1.2", | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^20.11.6", | ||
"@types/react": "^18.2.48", | ||
"@types/react-dom": "^18.2.18", | ||
"@testing-library/react": "^14.3.1", | ||
"@types/jest": "^29.5.13", | ||
"@types/node": "^20.16.5", | ||
"@types/react": "^18.3.5", | ||
"@types/react-dom": "^18.3.0", | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
@@ -55,15 +55,15 @@ "@typescript-eslint/parser": "^6.19.1", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-import-resolver-typescript": "^3.6.3", | ||
"eslint-plugin-import": "^2.30.0", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"eslint-plugin-promise": "^6.6.0", | ||
"eslint-plugin-react": "^7.36.1", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"prettier": "^3.2.4", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.2", | ||
"prettier": "^3.3.3", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"rimraf": "^5.0.10", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "5.3.3" | ||
@@ -70,0 +70,0 @@ }, |
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
89189
1299