@ggmdev/react-native-rating-bar
Version:
A React Native component for generating and displaying interactive Tap or Swipe enabled Ratings.
55 lines (51 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getClonedElement = void 0;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// TODO:- find better solution so we don't need this
const getClonedElement = (children, iconSize, color) => {
let clonedElement = null;
if (children && /*#__PURE__*/_react.default.isValidElement(children)) {
// Current Child component
const childProps = children.props;
const size = childProps.size || iconSize;
// this condition to avoid getting warning, passing tintColor to 'Text' as component could be Icon too
const childStyle = childProps.style ? {
...childProps.style
} : undefined;
// Cloned Child component
const props = color ? {
size,
color,
style: childStyle
} : {
size,
style: childStyle
};
clonedElement = /*#__PURE__*/_react.default.cloneElement(children, props);
let style = clonedElement.props.style;
if (style) {
style.width = style.width || iconSize;
style.height = style.height || iconSize;
if (color) {
style.tintColor = color;
}
}
return clonedElement;
}
return children;
};
/* export const doubleCloneElement = (children: React.ReactNode, style: any) => {
let clonedElement: JSX.Element | null = null;
if (children && React.isValidElement(children)) {
clonedElement = React.cloneElement(children, {
style: { ...children.props.style, ...style },
});
}
return clonedElement;
}; */
exports.getClonedElement = getClonedElement;
//# sourceMappingURL=cloneElement.js.map